forked from 0x2620/pandora
fix for replace groups
This commit is contained in:
parent
f2b60633b4
commit
405c72099a
1 changed files with 65 additions and 50 deletions
|
@ -771,7 +771,13 @@ var pandora = new Ox.App({
|
||||||
return that;
|
return that;
|
||||||
},
|
},
|
||||||
group: function(id, query) {
|
group: function(id, query) {
|
||||||
Ox.print('group', id, query)
|
Ox.print('group', id, query);
|
||||||
|
/*
|
||||||
|
query && query.conditions.length && alert($.map(query.conditions, function(v) {
|
||||||
|
return v.value;
|
||||||
|
}));
|
||||||
|
*/
|
||||||
|
//alert(id + ' ' + JSON.stringify(Query.toObject(id)))
|
||||||
var i = app.user.ui.groups.indexOf(id),
|
var i = app.user.ui.groups.indexOf(id),
|
||||||
panelWidth = app.$ui.document.width() - app.user.ui.listsSize - 1,
|
panelWidth = app.$ui.document.width() - app.user.ui.listsSize - 1,
|
||||||
title = Ox.getObjectById(app.config.groups, id).title,
|
title = Ox.getObjectById(app.config.groups, id).title,
|
||||||
|
@ -800,13 +806,14 @@ var pandora = new Ox.App({
|
||||||
request: function(data, callback) {
|
request: function(data, callback) {
|
||||||
Ox.print('sending request', data)
|
Ox.print('sending request', data)
|
||||||
delete data.keys;
|
delete data.keys;
|
||||||
|
//alert(id + " Query.toObject " + JSON.stringify(Query.toObject(id)) + ' ' + JSON.stringify(data))
|
||||||
return pandora.api.find($.extend(data, {
|
return pandora.api.find($.extend(data, {
|
||||||
group: id,
|
group: id,
|
||||||
query: Query.toObject(id)
|
query: Query.toObject(id)
|
||||||
}), callback);
|
}), callback);
|
||||||
},
|
},
|
||||||
selected: query ? $.map(query.conditions, function(v) {
|
selected: query ? $.map(query.conditions, function(v) {
|
||||||
return v.key;
|
return v.value;
|
||||||
}) : [],
|
}) : [],
|
||||||
sort: [
|
sort: [
|
||||||
{
|
{
|
||||||
|
@ -825,7 +832,7 @@ var pandora = new Ox.App({
|
||||||
operator: '='
|
operator: '='
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
reloadGroups();
|
reloadGroups(i);
|
||||||
});
|
});
|
||||||
new Ox.Select({
|
new Ox.Select({
|
||||||
items: $.map(app.config.groups, function(v) {
|
items: $.map(app.config.groups, function(v) {
|
||||||
|
@ -842,36 +849,42 @@ var pandora = new Ox.App({
|
||||||
.bindEvent('change', function(event, data) {
|
.bindEvent('change', function(event, data) {
|
||||||
var id_ = data.selected[0].id,
|
var id_ = data.selected[0].id,
|
||||||
i_ = app.user.ui.groups.indexOf(id_);
|
i_ = app.user.ui.groups.indexOf(id_);
|
||||||
i_ == -1 ? replaceGroup(i, id_) : swapGroups();
|
if (i_ == -1) {
|
||||||
function replaceGroup(i, id, query) {
|
// new group was not part of old group set
|
||||||
var isOuter = i % 4 == 0;
|
if (app.ui.groups[i].query.conditions.length) {
|
||||||
if (i_ == -1) {
|
// if group with selection gets replaced, reload
|
||||||
if (app.ui.groups[i].query.conditions.length) {
|
app.ui.groups[i].query.conditions = [];
|
||||||
app.ui.groups[i].query.conditions = [];
|
reloadGroups(i);
|
||||||
reloadGroups();
|
|
||||||
}
|
|
||||||
app.ui.groups[i] = getGroupObject(id);
|
|
||||||
}
|
}
|
||||||
app.user.ui.groups[i] = id;
|
app.ui.groups[i] = getGroupObject(id_);
|
||||||
app.$ui[isOuter ? 'browser' : 'groupsInnerPanel'].replace(
|
app.user.ui.groups[i] = id_;
|
||||||
isOuter ? i / 2 : i - 1,
|
replaceGroup(i, id_);
|
||||||
app.$ui.groups[i] = ui.group(id, query)
|
} else {
|
||||||
);
|
// swap two existing groups
|
||||||
}
|
var group = $.extend({}, app.ui.groups[i]);
|
||||||
function swapGroups() {
|
|
||||||
var group = $.extend({}, app.ui.groups[i]),
|
|
||||||
query = app.ui.groups[i].query;
|
|
||||||
query_ = app.ui.groups[i_].query;
|
|
||||||
app.ui.groups[i] = app.ui.groups[i_];
|
app.ui.groups[i] = app.ui.groups[i_];
|
||||||
app.ui.groups[i_] = group;
|
app.ui.groups[i_] = group;
|
||||||
app.user.ui.groups[i] = id_;
|
app.user.ui.groups[i] = id_;
|
||||||
app.user.ui.groups[i_] = id;
|
app.user.ui.groups[i_] = id;
|
||||||
replaceGroup(i, id_, query_);
|
replaceGroup(i, id_, app.ui.groups[i].query);
|
||||||
replaceGroup(i_, id, query);
|
replaceGroup(i_, id, app.ui.groups[i_].query);
|
||||||
|
}
|
||||||
|
function replaceGroup(i, id, query) {
|
||||||
|
// if query is passed, selected items will be derived from it
|
||||||
|
var isOuter = i % 4 == 0;
|
||||||
|
//foo = app.$ui.groups[i];
|
||||||
|
app.$ui[isOuter ? 'browser' : 'groupsInnerPanel'].replace(
|
||||||
|
isOuter ? i / 2 : i - 1,
|
||||||
|
app.$ui.groups[i] = ui.group(id, query)
|
||||||
|
);
|
||||||
|
//foo.remove();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.appendTo(that.$bar.$element);
|
.appendTo(that.$bar.$element);
|
||||||
app.ui.groups[i] = getGroupObject(id);
|
if (!query) {
|
||||||
|
// if query is set, group object has already been taken care of
|
||||||
|
app.ui.groups[i] = getGroupObject(id);
|
||||||
|
}
|
||||||
function getGroupObject(id) {
|
function getGroupObject(id) {
|
||||||
var i = app.user.ui.groups.indexOf(id),
|
var i = app.user.ui.groups.indexOf(id),
|
||||||
title = Ox.getObjectById(app.config.groups, id).title,
|
title = Ox.getObjectById(app.config.groups, id).title,
|
||||||
|
@ -887,31 +900,6 @@ var pandora = new Ox.App({
|
||||||
title: title
|
title: title
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function reloadGroups() {
|
|
||||||
var query = Query.toObject();
|
|
||||||
app.$ui.list.options({
|
|
||||||
request: function(data, callback) {
|
|
||||||
return pandora.api.find($.extend(data, {
|
|
||||||
query: query
|
|
||||||
}), callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$.each(app.ui.groups, function(i_, group_) {
|
|
||||||
if (i_ != i) {
|
|
||||||
Ox.print('setting groups request', i, i_)
|
|
||||||
app.$ui.groups[i_].options({
|
|
||||||
request: function(data, callback) {
|
|
||||||
delete data.keys;
|
|
||||||
return pandora.api.find($.extend(data, {
|
|
||||||
group: group_.id,
|
|
||||||
query: Query.toObject(group_.id)
|
|
||||||
}), callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
history.pushState({}, '', Query.toString(query));
|
|
||||||
}
|
|
||||||
return that;
|
return that;
|
||||||
},
|
},
|
||||||
groups: function() {
|
groups: function() {
|
||||||
|
@ -2323,6 +2311,33 @@ var pandora = new Ox.App({
|
||||||
) > -1 ? '' : '-';
|
) > -1 ? '' : '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reloadGroups(i) {
|
||||||
|
var query = Query.toObject();
|
||||||
|
app.$ui.list.options({
|
||||||
|
request: function(data, callback) {
|
||||||
|
return pandora.api.find($.extend(data, {
|
||||||
|
query: query
|
||||||
|
}), callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$.each(app.ui.groups, function(i_, group_) {
|
||||||
|
if (i_ != i) {
|
||||||
|
Ox.print('setting groups request', i, i_)
|
||||||
|
app.$ui.groups[i_].options({
|
||||||
|
request: function(data, callback) {
|
||||||
|
delete data.keys;
|
||||||
|
//alert(i_ + " Query.toObject " + JSON.stringify(Query.toObject(group_.id)))
|
||||||
|
return pandora.api.find($.extend(data, {
|
||||||
|
group: group_.id,
|
||||||
|
query: Query.toObject(group_.id)
|
||||||
|
}), callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
history.pushState({}, '', Query.toString(query));
|
||||||
|
}
|
||||||
|
|
||||||
function resizeGroups(width) {
|
function resizeGroups(width) {
|
||||||
var widths = $.map(app.ui.groups, function(v, i) {
|
var widths = $.map(app.ui.groups, function(v, i) {
|
||||||
return getGroupWidth(i, width);
|
return getGroupWidth(i, width);
|
||||||
|
|
Loading…
Reference in a new issue