openmedialibrary/static/js/findForm.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-05-14 09:57:11 +00:00
'use strict';
oml.ui.findForm = function(list) {
var ui = oml.user.ui,
that = Ox.Element(),
$filter = Ox.Filter({
findKeys: oml.config.itemKeys.map(function(key) {
return Ox.extend({}, key, {
title: Ox._(key.title),
type: key.id == 'mediastate' ? 'item' : key.type
});
}).concat([{
id: 'list',
title: Ox._('List'),
type: 'item',
values: ui._lists.filter(function(list) {
2014-05-18 23:24:04 +00:00
return Ox.contains(['library', 'static'], list.type);
2014-05-14 09:57:11 +00:00
}).map(function(list) {
return {id: list.id, title: list.title};
})
}]),
list: list ? null : {
sort: ui.listSort,
view: ui.listView
},
sortKeys: oml.config.sortKeys,
value: Ox.clone(list ? list.query : ui.find, true),
viewKeys: oml.config.listViews
})
.bindEvent({
change: function(data) {
(list ? oml.api.editList : Ox.noop)(list ? {
id: list.id,
query: data.value
} : {}, function(result) {
if (ui.updateAdvancedFindResults) {
updateResults();
}
});
}
})
.appendTo(that);
function updateResults() {
if (list) {
Ox.Request.clearCache(list.id);
oml.$ui.list.reloadList();
oml.$ui.filters.forEach(function($filter) {
$filter.reloadList();
});
} else {
oml.UI.set({find: Ox.clone($filter.options('value'), true)});
oml.$ui.findElement.updateElement();
}
}
that.getList = $filter.getList;
that.value = $filter.value;
return that;
};