Promote some useful common functionality to the app.js parent class

This commit is contained in:
Nathan Gray 2013-08-20 19:20:10 +00:00
parent 62d42c83da
commit dca0c40418

View File

@ -53,6 +53,11 @@ var AppJS = Class.extend({
* Internal application name - override this
*/
appname: '',
/**
* Internal reference to etemplate2 widget tree
*/
et2: null,
/**
* Initialization and setup goes here, but the etemplate2 object
@ -66,6 +71,7 @@ var AppJS = Class.extend({
* Clean up any created objects & references
*/
destroy: function() {
delete this.et2;
delete window.app[this.appname];
},
@ -77,5 +83,83 @@ var AppJS = Class.extend({
* @param et2 etemplate2 Newly ready object
*/
et2_ready: function(et2) {
if(this.et2 === null)
{
this.et2 = et2.widgetContainer;
}
else
{
egw.debug('warn', "Tried to overwrite et2 object");
}
},
/**
* Open an entry.
*
* Designed to be used with the action system as a callback
* eg: onExecute => app.<appname>.open
*
* @param _action
* @param _senders
*/
open: function(_action, _senders) {
var id_app = _senders[0].id.split('::')
egw.open(id_app[1], this.appname);
},
/**
* A generic method to action to server asynchronously
*
* Designed to be used with the action system as a callback.
* In the PHP side, set the action
* 'onExecute' => 'javaScript:app.<appname>.action', and
* implement _do_action(action_id, selected)
*
* @param {egwAction} _action
* @param {egwActionObject[]} _elems
*/
action: function(_action, _elems)
{
// let user confirm select-all
var select_all = _action.getManager().getActionById("select_all");
var confirm_msg = (_elems.length > 1 || select_all && select_all.checked) &&
typeof _action.data.confirm_multiple != 'undefined' ?
_action.data.confirm_multiple : _action.data.confirm;
if (typeof confirm_msg != 'undefined')
{
var that = this;
var action_id = _action.id;
et2_dialog.show_dialog(function(button_id,value)
{
if (button_id != et2_dialog.NO_BUTTON)
{
that._do_action(action_id, _elems);
}
}, confirm_msg, egw.lang('Confirmation required'), et2_dialog.BUTTONS_YES_NO, et2_dialog.QUESTION_MESSAGE);
}
else if (typeof this._do_action == 'function')
{
this._do_action(_action.id, _elems);
}
else
{
// If this is a nextmatch action, do an ajax submit setting the action
var nm = null;
var action = _action;
while(nm == null && action.parent != null)
{
if(action.data.nextmatch) nm = action.data.nextmatch;
action = action.parent;
}
if(nm != null)
{
var value = {};
value[nm.options.settings.action_var] = _action.id;
nm.set_value(value);
nm.getInstanceManager().submit();
}
}
}
});