pandora/static/js/filterForm.js

110 lines
4.2 KiB
JavaScript
Raw Normal View History

2011-11-06 08:28:10 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.filterForm = function(options) {
2014-02-17 06:14:49 +00:00
// mode can be find, list, embed
var list = options.list,
mode = options.mode,
that = Ox.Element();
2011-11-10 22:48:32 +00:00
pandora.api.findLists({
query: {
conditions: [{key: 'type', value: 'static', operator: '='}],
operator: '&'
},
keys: ['id'],
range: [0, 1000],
sort: [{key: 'user', operator: '+'}, {key: 'name', operator: '+'}]
}, function(result) {
that.append(
that.$filter = Ox.Filter({
2012-05-24 08:22:56 +00:00
findKeys: pandora.site.itemKeys.map(function(itemKey) {
var key = Ox.clone(itemKey, true),
layerType;
if (key.type == 'layer') {
layerType = Ox.getObjectById(pandora.site.layers, key.id).type;
}
2013-05-09 10:13:58 +00:00
key.title = Ox._(key.title);
2011-11-10 22:48:32 +00:00
key.type = key.type == 'layer'
? (layerType == 'entity' ? 'string' : layerType)
2011-11-10 22:48:32 +00:00
: key.type;
if (key.format && key.format.type == 'ColorPercent') {
key.format.type = 'percent';
}
2011-11-10 22:48:32 +00:00
return key;
2012-05-24 08:22:56 +00:00
}).concat([{
2011-11-10 22:48:32 +00:00
id: 'list',
2013-05-09 10:13:58 +00:00
title: Ox._('List'),
2011-11-10 22:48:32 +00:00
type: 'list',
values: result.data.items.map(function(item) {
return item.id;
})
2012-05-24 08:22:56 +00:00
}]),
list: mode == 'find' ? {
2011-11-10 22:48:32 +00:00
sort: pandora.user.ui.listSort,
view: pandora.user.ui.listView
} : null,
2011-11-10 22:48:32 +00:00
sortKeys: pandora.site.sortKeys,
value: Ox.clone(mode == 'list' ? list.query : pandora.user.ui.find, true),
2011-11-10 22:48:32 +00:00
viewKeys: pandora.site.listViews
})
.css(mode == 'embed' ? {} : {padding: '16px'})
2011-11-10 22:48:32 +00:00
.bindEvent({
change: function(data) {
2014-02-17 06:14:49 +00:00
if (mode == 'find') {
if (pandora.user.ui.updateAdvancedFindResults) {
that.updateResults();
}
} else if (mode == 'list') {
2011-11-10 22:48:32 +00:00
pandora.api.editList({
id: list.id,
query: data.value
2011-11-10 22:48:32 +00:00
}, function(result) {
if (pandora.user.ui.updateAdvancedFindResults) {
that.updateResults();
}
2011-11-06 08:28:10 +00:00
});
2011-11-10 22:48:32 +00:00
}
that.triggerEvent('change', data);
2011-11-06 08:28:10 +00:00
}
2011-11-10 22:48:32 +00:00
})
);
that.getList = that.$filter.getList;
2014-02-17 08:23:24 +00:00
that.value = that.$filter.value;
2011-11-10 22:48:32 +00:00
});
that.updateResults = function() {
if (mode == 'list') {
Ox.Request.clearCache(list.id);
2014-02-06 10:52:10 +00:00
if (pandora.user.ui.section == 'edits') {
pandora.$ui.folderList[
pandora.getListData().folder
2014-02-17 08:13:01 +00:00
].value(list.id, 'query', that.$filter.options('value'));
2014-02-06 10:52:10 +00:00
pandora.api.editEdit({
id: list.id,
2014-02-17 08:13:01 +00:00
query: that.$filter.options('value')
2014-02-06 10:52:10 +00:00
}, function(result) {
pandora.$ui.editPanel.updatePanel();
});
} else {
2014-02-17 08:23:24 +00:00
pandora.$ui.list && pandora.$ui.list
.bindEventOnce({
init: function(data) {
pandora.$ui.folderList[
pandora.getListData().folder
].value(list.id, 'query', that.$filter.options('value'));
}
})
.reloadList();
2014-02-06 10:52:10 +00:00
pandora.$ui.filters && pandora.$ui.filters.forEach(function($filter) {
$filter.reloadList();
});
}
} else {
2014-02-17 08:13:01 +00:00
pandora.UI.set({find: Ox.clone(that.$filter.options('value'), true)});
pandora.$ui.findElement.updateElement();
}
};
2011-11-06 08:28:10 +00:00
return that;
};