Manage client actions from button and wizard

issue3343
review3221003
This commit is contained in:
Cédric Krier committed 2014-02-15 18:33:11 +01:00
1 parent 46c8157150
commit fe45fa6a1e
3 files changed
+61 -22

No files matched your search

+51 -17
View File
@@ -339,7 +339,9 @@
if (index < group.length - 1) {
record = group[index + 1];
break;
} else if (group.parent) {
} else if (group.parent &&
(record.group.model_name ==
group.parent.group.model_name)) {
record = group.parent;
group = group.parent.group;
} else {
@@ -366,7 +368,9 @@
if (index > 0) {
record = group[index - 1];
break;
} else if (group.parent) {
} else if (group.parent &&
(record.group.model_name ==
group.parent.group.model_name)) {
record = group.parent;
group = group.parent.group;
} else {
@@ -697,24 +701,54 @@
},
button: function(attributes) {
// TODO confirm
var process_action = function(action) {
this.reload(ids, true);
if (typeof action == 'string') {
var access = Sao.common.MODELACCESS.get(this.model_name);
if (action == 'new') {
if (access.create) {
this.new_();
}
} else if (action == 'delete') {
if (access['delete']) {
this.remove(!this.parent, false, !this.parent);
}
} else if (action == 'remove') {
if (access.write && access.read && this.parent) {
this.remove(false, true, false);
}
} else if (action == 'copy') {
if (access.create) {
this.copy();
}
} else if (action == 'next') {
this.display_next();
} else if (action == 'previous') {
this.display_previous();
} else if (action == 'close') {
Sao.Tab.close_current();
} else if (action.startsWith('switch')) {
var view_type = action.split(' ')[1];
this.switch_view(view_type);
}
}
else if (action) {
Sao.Action.execute(action, {
model: this.model_name,
id: record.id,
ids: ids
}, null, this.context);
}
};
var record = this.current_record;
var ids = this.current_view.selected_records().map(
function(record) {
return record.id;
});
record.save().done(function() {
var ids = this.current_view.selected_records().map(
function(record) {
return record.id;
});
record.model.execute(attributes.name,
[ids], this.context).then(
function(action_id) {
if (action_id) {
Sao.Action.execute(action_id, {
model: this.model_name,
id: record.id,
ids: [record.id]
}, null, this.context);
}
this.reload(ids, true);
}.bind(this),
[ids], this.context).then(process_action.bind(this),
function() {
this.reload(ids, true);
}.bind(this));
+5
View File
@@ -139,6 +139,11 @@
}
return jQuery.when();
};
Sao.Tab.tabs.close_current = function() {
var tabs = jQuery('#tabs > div');
var tab = Sao.Tab.tabs[tabs.tabs('option', 'active')];
tab.close();
};
Sao.Tab.create = function(attributes) {
if (attributes.context === undefined) {
+5 -5
View File
@@ -103,7 +103,7 @@
// TODO
},
end: function() {
Sao.rpc({
return Sao.rpc({
'method': 'wizard.' + this.action + '.delete',
'params': [this.session_id, this.session.context]
}, this.session);
@@ -202,15 +202,15 @@
// TODO set size
this.dialog.dialog('open');
},
destroy: function() {
destroy: function(action) {
Sao.Wizard.Dialog._super.destroy.call(this);
this.dialog.dialog('destroy');
// TODO other dialogs
// TODO reload under screen
// TODO reload under screen and action
},
end: function() {
Sao.Wizard.Dialog._super.end.call(this);
this.destroy();
Sao.Wizard.Dialog._super.end.call(this).then(
this.destroy.bind(this));
},
show: function() {
this.dialog.dialog('open');