Do not allow to change the mail settings in the discussion control panel, if there is no valid mail setup. Refactor js code to use class settings of #content.

svn path=/plone.app.discussion/trunk/; revision=46090
This commit is contained in:
Timo Stollenwerk
2010-12-02 23:02:00 +00:00
parent fbd7eb2bbc
commit ffde4b423d
4 changed files with 83 additions and 71 deletions
@@ -7,11 +7,8 @@
// 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.
**************************************************************************/
/* Disable a control panel setting */
$.disableSettings = function (settings) {
$.each(settings, function (intIndex, setting) {
setting.addClass('unclickable');
@@ -20,6 +17,7 @@
});
};
/* Enable a control panel setting */
$.enableSettings = function (settings) {
$.each(settings, function (intIndex, setting) {
setting.removeClass('unclickable');
@@ -27,32 +25,25 @@
setting_field.removeAttr('disabled');
});
};
//#JSCOVERAGE_IF 0
/**************************************************************************
* Window Load Function: Executes when complete page is fully loaded,
* including all frames,
**************************************************************************/
$(window).load(function () {
/**********************************************************************
* Do not allow to change the mail settings if there is no valid mail
* setup.
**********************************************************************/
/* Update settings */
$.updateSettings = function () {
var globally_enabled = $("#content").hasClass("globally_enabled");
var anonymous_comments = $("#content").hasClass("anonymous_comments");
var invalid_mail_setup = $("#content").hasClass("invalid_mail_setup");
if (invalid_mail_setup === true) {
$.disableSettings([
/* If commenting is globally disabled, disable all settings. */
if (globally_enabled === true) {
$.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')
]);
};
/**********************************************************************
* If commenting is disabled globally, disable all commenting options.
**********************************************************************/
var commenting_enabled_globally = $("#form-widgets-globally_enabled-0").attr("checked");
if (commenting_enabled_globally === false) {
} else {
$.disableSettings([
$('#formfield-form-widgets-anonymous_comments'),
$('#formfield-form-widgets-text_transform'),
@@ -61,45 +52,56 @@
$('#formfield-form-widgets-moderator_notification_enabled'),
$('#formfield-form-widgets-user_notification_enabled')
]);
};
$("input[name='form.widgets.globally_enabled:list']").live("click", function (e) {
if ($(this).attr("checked")) {
// commenting globally enabled
$.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')
]);
} else {
// commenting globally disabled
$.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')
]);
}
/* If the mail setup is invalid, disable the mail settings. */
if (invalid_mail_setup === true) {
$.disableSettings([
$('#formfield-form-widgets-moderator_notification_enabled'),
$('#formfield-form-widgets-user_notification_enabled')
]);
} else {
$.enableSettings([
$('#formfield-form-widgets-moderator_notification_enabled'),
$('#formfield-form-widgets-user_notification_enabled')
]);
}
};
//#JSCOVERAGE_IF 0
/**************************************************************************
* Window Load Function: Executes when complete page is fully loaded,
* including all frames,
**************************************************************************/
$(window).load(function () {
// Update settings on page load
$.updateSettings();
// Set #content class and update settings afterwards
$("input,select").live("change", function (e) {
var id = $(this).attr("id");
if (id === "form-widgets-globally_enabled-0") {
if ($(this).attr("checked") === true) {
$("#content").addClass("globally_enabled");
}
else {
$("#content").removeClass("globally_enabled");
}
$.updateSettings();
}
});
/**********************************************************************
* Remove the disabled attribute from all form elements before
* submitting the form. Otherwise the z3c.form will raise errors on
* the required attributes.
**********************************************************************/
$("input[name='form.buttons.save']").live("click", function (e) {
e.preventDefault();
$('#formfield-form-widgets-anonymous_comments').removeAttr('disabled');
$('#formfield-form-widgets-text_transform').removeAttr('disabled');
$('#formfield-form-widgets-captcha').removeAttr('disabled');
$('#formfield-form-widgets-show_commenter_image').removeAttr('disabled');
$('#formfield-form-widgets-moderator_notification_enabled').removeAttr('disabled');
$('#formfield-form-widgets-user_notification_enabled').removeAttr('disabled');
$(this).parents().filter("form").submit();
$("input[name='form.buttons.save']").bind("click", function (e) {
//e.preventDefault();
var form = $(this).parents("form");
$(form).find("input,select").removeAttr('disabled');
$(form).submit();
});
});