update entities dialog (selection on load, add, delete)

This commit is contained in:
rolux 2014-11-21 14:35:16 +00:00
parent fb5a5c5cf7
commit d74bbcba60

View file

@ -83,13 +83,18 @@ pandora.ui.entitiesDialog = function(options) {
} }
}), callback); }), callback);
}, },
selected: ui.entitiesSelection[type] || [],
sort: [{key: 'name', operator: '+'}], sort: [{key: 'name', operator: '+'}],
scrollbarVisible: true, scrollbarVisible: true,
unique: 'id', unique: 'id',
width: 256 - Ox.SCROLLBAR_SIZE width: 256 - Ox.SCROLLBAR_SIZE
}) })
.bindEvent({ .bindEvent({
add: function() {
addEntity();
},
'delete': function() {
deleteEntities();
},
init: function(data) { init: function(data) {
var text = Ox.formatCount( var text = Ox.formatCount(
data.items, data.items,
@ -131,12 +136,12 @@ pandora.ui.entitiesDialog = function(options) {
$itemMenu = Ox.MenuButton({ $itemMenu = Ox.MenuButton({
items: [ items: [
{ {
'id': 'add', id: 'add',
title: Ox._('Add Entity'), title: Ox._('Add Entity'),
keyboard: 'control n' keyboard: 'control n'
}, },
{ {
'id': 'delete', id: 'delete',
title: Ox._('Delete Entity...'), title: Ox._('Delete Entity...'),
disabled: true, disabled: true,
keyboard: 'delete' keyboard: 'delete'
@ -153,14 +158,7 @@ pandora.ui.entitiesDialog = function(options) {
.bindEvent({ .bindEvent({
click: function(data) { click: function(data) {
if (data.id == 'add') { if (data.id == 'add') {
pandora.api.addEntity({ addEntity();
type: type
}, function(result) {
Ox.Request.clearCache('findEntities');
$list.reloadList().options({
selected: [result.data.id]
});
})
} else if (data.id == 'delete') { } else if (data.id == 'delete') {
deleteEntities(); deleteEntities();
} }
@ -202,8 +200,7 @@ pandora.ui.entitiesDialog = function(options) {
fontSize: '9px', fontSize: '9px',
marginTop: '2px', marginTop: '2px',
textAlign: 'center' textAlign: 'center'
}) }),
.html(Ox._('No entity selected')),
$itemStatusbar = Ox.Bar({size: 16}) $itemStatusbar = Ox.Bar({size: 16})
.append($itemStatus), .append($itemStatus),
@ -283,6 +280,18 @@ pandora.ui.entitiesDialog = function(options) {
} }
}); });
selectEntities();
function addEntity() {
pandora.api.addEntity({
type: type
}, function(result) {
Ox.Request.clearCache('findEntities');
$list.reloadList();
pandora.UI.set('entitiesSelection.' + type, data.ids);
});
}
function deleteEntities() { function deleteEntities() {
pandora.ui.deleteEntityDialog( pandora.ui.deleteEntityDialog(
$list.options('selected').map(function(id) { $list.options('selected').map(function(id) {
@ -290,8 +299,8 @@ pandora.ui.entitiesDialog = function(options) {
}), }),
function() { function() {
Ox.Request.clearCache(); Ox.Request.clearCache();
// ...
$list.reloadList(); $list.reloadList();
pandora.UI.set('entitiesSelection.' + type, []);
} }
).open(); ).open();
} }
@ -387,6 +396,7 @@ pandora.ui.entitiesDialog = function(options) {
Ox._('entity'), Ox._('entity'),
Ox._('entities') Ox._('entities')
) + ' ' + Ox._('selected'); ) + ' ' + Ox._('selected');
$list.options({selected: ui.entitiesSelection[type] || []})
renderEntity(); renderEntity();
$itemMenu[ $itemMenu[
ui.entitiesSelection[type].length ? 'enableItem' : 'disableItem' ui.entitiesSelection[type].length ? 'enableItem' : 'disableItem'