From dc3e6c12c2430f666355121e5dd6ba7623442343 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 20 May 2015 15:48:08 +0000 Subject: [PATCH] Introduce a checkbox method for toolbar widget in order to be able to get/set checkbox actions - Function pattern: widget.checkbox(action_id,[value]) --- etemplate/js/et2_widget_toolbar.js | 43 ++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/etemplate/js/et2_widget_toolbar.js b/etemplate/js/et2_widget_toolbar.js index 93daa16d52..f7327df425 100644 --- a/etemplate/js/et2_widget_toolbar.js +++ b/etemplate/js/et2_widget_toolbar.js @@ -405,8 +405,7 @@ var et2_toolbar = et2_DOMWidget.extend([et2_IInput], if (action && action.checkbox) { - var action_event = typeof this._actionManager != 'undefined'?this._actionManager.getActionById(action.id):null; - if (action_event && action_event.checked) button.addClass('toolbar_toggled'); + if (this.checkbox(action.id)) button.addClass('toolbar_toggled'); } if ( action.iconUrl) { @@ -429,6 +428,7 @@ var et2_toolbar = et2_DOMWidget.extend([et2_IInput], { button.button(button_options); } + var self = this; // Set up the click action var click = function(e) { @@ -437,8 +437,7 @@ var et2_toolbar = et2_DOMWidget.extend([et2_IInput], { if (action.checkbox) { - action.set_checked(!action.checked); - jQuery(button).toggleClass('toolbar_toggled'); + self.checkbox(action.id, !action.checked); } this.value = action.id; action.data.event = e; @@ -458,7 +457,41 @@ var et2_toolbar = et2_DOMWidget.extend([et2_IInput], { this._build_menu(actions); }, - + + /** + * Set/Get the checkbox toolbar action + * + * @param {string} _action action name of the selected toolbar + * @param {boolean} _value value that needs to be set for the action true|false + * - if no value means checkbox value returns the current value + * + * @returns {boolean} returns boolean result of get checkbox value + * or returns undefined as Set result or failure + */ + checkbox: function (_action, _value) + { + if (!_action || typeof this._actionManager == 'undefined') return undefined; + var action_event = this._actionManager.getActionById(_action); + + if (action_event && typeof _value !='undefined') + { + var btn = jQuery('#'+this.id+'-'+_action); + if (btn.length > 0) + { + action_event.set_checked(_value); + btn.toggleClass('toolbar_toggled'); + } + } + else if (action_event) + { + return action_event.checked; + } + else + { + return undefined; + } + }, + getDOMNode: function(asker) { return this.div[0];