From f97c17e62af2dae0a1a78344258530dab33cd614 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Thu, 2 Dec 2010 18:50:21 +0000 Subject: [PATCH] Factor out enable/disable settings function. svn path=/plone.app.discussion/trunk/; revision=46086 --- .../browser/javascripts/controlpanel.js | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/plone/app/discussion/browser/javascripts/controlpanel.js b/plone/app/discussion/browser/javascripts/controlpanel.js index b7ae7d2..8743c21 100644 --- a/plone/app/discussion/browser/javascripts/controlpanel.js +++ b/plone/app/discussion/browser/javascripts/controlpanel.js @@ -7,7 +7,25 @@ // This unnamed function allows us to use $ inside of a block of code // without permanently overwriting $. // http://docs.jquery.com/Using_jQuery_with_Other_Libraries - + + /************************************************************************** + * Disable a control panel setting. Grey out the setting and disable all + * form elements. + **************************************************************************/ + $.disableSettings = function (settings) { + $.each(settings, + function(intIndex, objValue){ + objValue.removeClass('unclickable'); + }); + }; + + $.enableSettings = function (settings) { + $.each(settings, + function(intIndex, objValue){ + objValue.addClass('unclickable'); + }); + }; + //#JSCOVERAGE_IF 0 /************************************************************************** @@ -17,25 +35,29 @@ $(window).load(function () { /********************************************************************** - * If the user hits the "clear" button of an open reply-to-comment form, - * remove the form and show the "reply" button again. + * If commenting is globally disabled, disable all commenting options. **********************************************************************/ $("input[name='form.widgets.globally_enabled:list']").bind("change", function (e) { if ($(this).attr("checked")) { - // enable commenting globally - $('#formfield-form-widgets-anonymous_comments').removeClass('unclickable'); - $('#formfield-form-widgets-text_transform').removeClass('unclickable'); - $('#formfield-form-widgets-captcha').removeClass('unclickable'); - $('#formfield-form-widgets-show_commenter_image').removeClass('unclickable'); - $('#formfield-form-widgets-moderator_notification_enabled').removeClass('unclickable'); - $('#formfield-form-widgets-user_notification_enabled').removeClass('unclickable'); + // commenting globally enable + $.disableSettings([ + $('#formfield-form-widgets-anonymous_comments'), + $('#formfield-form-widgets-text_transform'), + $('#formfield-form-widgets-captcha'), + $('#formfield-form-widgets-show_commenter_image'), + $('#formfield-form-widgets-moderator_notification_enabled'), + $('#formfield-form-widgets-user_notification_enabled') + ]); } else { - $('#formfield-form-widgets-anonymous_comments').addClass('unclickable'); - $('#formfield-form-widgets-text_transform').addClass('unclickable'); - $('#formfield-form-widgets-captcha').addClass('unclickable'); - $('#formfield-form-widgets-show_commenter_image').addClass('unclickable'); - $('#formfield-form-widgets-moderator_notification_enabled').addClass('unclickable'); - $('#formfield-form-widgets-user_notification_enabled').addClass('unclickable'); + // commenting globally disabled + $.enableSettings([ + $('#formfield-form-widgets-anonymous_comments'), + $('#formfield-form-widgets-text_transform'), + $('#formfield-form-widgets-captcha'), + $('#formfield-form-widgets-show_commenter_image'), + $('#formfield-form-widgets-moderator_notification_enabled'), + $('#formfield-form-widgets-user_notification_enabled'), + ]); } });