2011-05-25 19:42:45 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=js
|
|
|
|
pandora.ui.group = function(id, query) {
|
|
|
|
//Ox.print('group', id, query);
|
|
|
|
/*
|
|
|
|
query && query.conditions.length && alert($.map(query.conditions, function(v) {
|
|
|
|
return v.value;
|
|
|
|
}));
|
|
|
|
*/
|
|
|
|
//alert(id + ' ' + JSON.stringify(pandora.Query.toObject(id)))
|
2011-06-06 15:48:11 +00:00
|
|
|
var i = pandora.user.ui.groups.indexOf(id),
|
|
|
|
panelWidth = pandora.$ui.document.width() - (pandora.user.ui.showSidebar * pandora.user.ui.sidebarSize) - 1,
|
|
|
|
title = Ox.getObjectById(pandora.site.groups, id).title,
|
2011-05-25 19:42:45 +00:00
|
|
|
width = pandora.getGroupWidth(i, panelWidth),
|
|
|
|
that = new Ox.TextList({
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
align: 'left',
|
|
|
|
id: 'name',
|
|
|
|
operator: id == 'year' ? '-' : '+',
|
|
|
|
title: title,
|
|
|
|
unique: true,
|
|
|
|
visible: true,
|
|
|
|
width: width.column
|
|
|
|
},
|
|
|
|
{
|
|
|
|
align: 'right',
|
|
|
|
id: 'items',
|
|
|
|
operator: '-',
|
|
|
|
title: '#',
|
|
|
|
visible: true,
|
|
|
|
width: 40
|
|
|
|
}
|
|
|
|
],
|
|
|
|
columnsVisible: true,
|
|
|
|
id: 'group_' + id,
|
|
|
|
items: function(data, callback) {
|
|
|
|
//Ox.print('sending request', data)
|
|
|
|
delete data.keys;
|
|
|
|
//alert(id + " pandora.Query.toObject " + JSON.stringify(pandora.Query.toObject(id)) + ' ' + JSON.stringify(data))
|
|
|
|
return pandora.api.find($.extend(data, {
|
|
|
|
group: id,
|
|
|
|
query: pandora.Query.toObject(id)
|
|
|
|
}), callback);
|
|
|
|
},
|
|
|
|
scrollbarVisible: true,
|
|
|
|
selected: query ? $.map(query.conditions, function(v) {
|
|
|
|
return v.value;
|
|
|
|
}) : [],
|
|
|
|
sort: [
|
|
|
|
{
|
|
|
|
key: id == 'year' ? 'name' : 'items',
|
|
|
|
operator: '-'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
paste: function(event, data) {
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.list.triggerEvent('paste', data);
|
2011-05-25 19:42:45 +00:00
|
|
|
},
|
|
|
|
select: function(event, data) {
|
2011-06-06 15:48:11 +00:00
|
|
|
var group = pandora.user.queryGroups[i],
|
2011-05-25 19:42:45 +00:00
|
|
|
query;
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.user.queryGroups[i].query.conditions = $.map(data.ids, function(v) {
|
2011-05-25 19:42:45 +00:00
|
|
|
return {
|
|
|
|
key: id,
|
|
|
|
value: v,
|
|
|
|
operator: '='
|
|
|
|
};
|
|
|
|
});
|
2011-05-25 19:50:04 +00:00
|
|
|
pandora.reloadGroups(i);
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
new Ox.Select({
|
2011-06-06 16:08:33 +00:00
|
|
|
items: $.map(pandora.site.groups, function(v) {
|
2011-05-25 19:42:45 +00:00
|
|
|
return {
|
|
|
|
checked: v.id == id,
|
|
|
|
id: v.id,
|
|
|
|
title: v.title
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
max: 1,
|
|
|
|
min: 1,
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.bindEvent('change', function(event, data) {
|
|
|
|
var id_ = data.selected[0].id,
|
2011-06-06 15:48:11 +00:00
|
|
|
i_ = pandora.user.ui.groups.indexOf(id_);
|
2011-05-25 19:42:45 +00:00
|
|
|
if (i_ == -1) {
|
|
|
|
// new group was not part of old group set
|
2011-06-06 15:48:11 +00:00
|
|
|
if (pandora.user.queryGroups[i].query.conditions.length) {
|
2011-05-25 19:42:45 +00:00
|
|
|
// if group with selection gets replaced, reload
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.user.queryGroups[i].query.conditions = [];
|
2011-05-25 19:50:04 +00:00
|
|
|
pandora.reloadGroups(i);
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.user.queryGroups[i] = getGroupObject(id_);
|
|
|
|
pandora.user.ui.groups[i] = id_;
|
|
|
|
pandora.UI.set({groups: pandora.user.ui.groups});
|
2011-05-25 19:42:45 +00:00
|
|
|
replaceGroup(i, id_);
|
|
|
|
} else {
|
|
|
|
// swap two existing groups
|
2011-06-06 15:48:11 +00:00
|
|
|
var group = $.extend({}, pandora.user.queryGroups[i]);
|
|
|
|
pandora.user.queryGroups[i] = pandora.user.queryGroups[i_];
|
|
|
|
pandora.user.queryGroups[i_] = group;
|
|
|
|
pandora.user.ui.groups[i] = id_;
|
|
|
|
pandora.user.ui.groups[i_] = id;
|
|
|
|
pandora.UI.set({groups: pandora.user.ui.groups});
|
|
|
|
replaceGroup(i, id_, pandora.user.queryGroups[i].query);
|
|
|
|
replaceGroup(i_, id, pandora.user.queryGroups[i_].query);
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
function replaceGroup(i, id, query) {
|
|
|
|
// if query is passed, selected items will be derived from it
|
|
|
|
var isOuter = i % 4 == 0;
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui[isOuter ? 'browser' : 'groupsInnerPanel'].replaceElement(
|
2011-05-25 19:42:45 +00:00
|
|
|
isOuter ? i / 2 : i - 1,
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.$ui.groups[i] = pandora.ui.group(id, query)
|
2011-05-25 19:42:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(that.$bar.$element);
|
|
|
|
if (!query) {
|
|
|
|
// if query is set, group object has already been taken care of
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.user.queryGroups[i] = getGroupObject(id);
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
function getGroupObject(id) {
|
2011-06-06 15:48:11 +00:00
|
|
|
var i = pandora.user.ui.groups.indexOf(id),
|
|
|
|
title = Ox.getObjectById(pandora.site.groups, id).title,
|
2011-05-25 19:42:45 +00:00
|
|
|
width = pandora.getGroupWidth(i, panelWidth);
|
|
|
|
return {
|
|
|
|
id: id,
|
|
|
|
element: that,
|
|
|
|
query: {
|
|
|
|
conditions: [],
|
|
|
|
operator: '|'
|
|
|
|
},
|
|
|
|
size: width.list,
|
|
|
|
title: title
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
|
|
|
pandora.ui.groups = function() {
|
|
|
|
var $groups = [];
|
2011-06-06 15:48:11 +00:00
|
|
|
pandora.user.queryGroups = [];
|
|
|
|
pandora.user.ui.groups.forEach(function(id, i) {
|
2011-05-25 19:42:45 +00:00
|
|
|
$groups[i] = pandora.ui.group(id);
|
|
|
|
});
|
|
|
|
return $groups;
|
|
|
|
};
|
|
|
|
|
|
|
|
pandora.ui.groupsInnerPanel = function() {
|
|
|
|
var that = new Ox.SplitPanel({
|
|
|
|
elements: [
|
|
|
|
{
|
2011-06-06 15:48:11 +00:00
|
|
|
element: pandora.$ui.groups[1],
|
|
|
|
size: pandora.user.queryGroups[1].size
|
2011-05-25 19:42:45 +00:00
|
|
|
},
|
|
|
|
{
|
2011-06-06 15:48:11 +00:00
|
|
|
element: pandora.$ui.groups[2],
|
2011-05-25 19:42:45 +00:00
|
|
|
},
|
|
|
|
{
|
2011-06-06 15:48:11 +00:00
|
|
|
element: pandora.$ui.groups[3],
|
|
|
|
size: pandora.user.queryGroups[3].size
|
2011-05-25 19:42:45 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
orientation: 'horizontal'
|
|
|
|
});
|
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|