From 394f7394ff1e8eb821a34681257eb6acbc553fd3 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 20 May 2015 15:18:00 +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]) - Fix encrypt toolbar action set/get according to new method --- etemplate/js/et2_widget_toolbar.js | 43 ++++++++++++++++++++++++++---- mail/js/app.js | 10 +++---- 2 files changed, 42 insertions(+), 11 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]; diff --git a/mail/js/app.js b/mail/js/app.js index 4a205b6f3e..d15f19adb8 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -4430,11 +4430,10 @@ app.classes.mail = AppJS.extend( predefinedText: options.predefinedText.slice(end_pgp+this.end_pgp_message.length+1).replace(/^> \s*/m,'') }; // set encrypted checkbox, if not already set - var pgp_action = this.et2.getWidgetById('composeToolbar')._actionManager.getActionById('pgp'); - if (pgp_action && !pgp_action.checked) + var composeToolbar = this.et2.getWidgetById('composeToolbar'); + if (composeToolbar.checkbox('pgp')) { - pgp_action.set_checked(true); - jQuery('button#composeToolbar-pgp').toggleClass('toolbar_toggled'); + composeToolbar.checkbox('pgp',true); } } } @@ -4491,8 +4490,7 @@ app.classes.mail = AppJS.extend( } else { - self.et2.getWidgetById('composeToolbar')._actionManager.getActionById('pgp').set_checked(true); - jQuery('button#composeToolbar-pgp').toggleClass('toolbar_toggled'); + self.et2.getWidgetById('composeToolbar').checkbox('pgp',true); } }, this.egw.lang('You will loose current message body, unless you save it to your clipboard!'),