make jslint happy; disable settings onload;

svn path=/plone.app.discussion/trunk/; revision=46088
This commit is contained in:
Timo Stollenwerk 2010-12-02 19:49:49 +00:00
parent 2a7a65293e
commit 1b36f99a7a

View File

@ -13,21 +13,19 @@
* form elements. * form elements.
**************************************************************************/ **************************************************************************/
$.disableSettings = function (settings) { $.disableSettings = function (settings) {
$.each(settings, $.each(settings, function (intIndex, setting) {
function(intIndex, setting){ setting.addClass('unclickable');
setting.addClass('unclickable'); var setting_field = $(setting).find("input,select");
setting_field = $(setting).find("input,select"); setting_field.attr('disabled', 'disabled');
setting_field.attr('disabled', 'disabled'); });
});
}; };
$.enableSettings = function (settings) { $.enableSettings = function (settings) {
$.each(settings, $.each(settings, function (intIndex, setting) {
function(intIndex, setting){ setting.removeClass('unclickable');
setting.removeClass('unclickable'); var setting_field = $(setting).find("input,select");
setting_field = $(setting).find("input,select"); setting_field.removeAttr('disabled');
setting_field.removeAttr('disabled'); });
});
}; };
//#JSCOVERAGE_IF 0 //#JSCOVERAGE_IF 0
@ -38,10 +36,22 @@
**************************************************************************/ **************************************************************************/
$(window).load(function () { $(window).load(function () {
var commenting_enabled_globally = $("#form-widgets-globally_enabled-0").attr("checked");
if (commenting_enabled_globally === false) {
$.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 commenting is disabled globally, disable all commenting options. * If commenting is disabled globally, disable all commenting options.
**********************************************************************/ **********************************************************************/
$("input[name='form.widgets.globally_enabled:list']").bind("change", function (e) { $("input[name='form.widgets.globally_enabled:list']").live("click", function (e) {
if ($(this).attr("checked")) { if ($(this).attr("checked")) {
// commenting globally enabled // commenting globally enabled
$.enableSettings([ $.enableSettings([
@ -51,7 +61,7 @@
$('#formfield-form-widgets-show_commenter_image'), $('#formfield-form-widgets-show_commenter_image'),
$('#formfield-form-widgets-moderator_notification_enabled'), $('#formfield-form-widgets-moderator_notification_enabled'),
$('#formfield-form-widgets-user_notification_enabled') $('#formfield-form-widgets-user_notification_enabled')
]); ]);
} else { } else {
// commenting globally disabled // commenting globally disabled
$.disableSettings([ $.disableSettings([
@ -60,10 +70,26 @@
$('#formfield-form-widgets-captcha'), $('#formfield-form-widgets-captcha'),
$('#formfield-form-widgets-show_commenter_image'), $('#formfield-form-widgets-show_commenter_image'),
$('#formfield-form-widgets-moderator_notification_enabled'), $('#formfield-form-widgets-moderator_notification_enabled'),
$('#formfield-form-widgets-user_notification_enabled'), $('#formfield-form-widgets-user_notification_enabled')
]); ]);
} }
}); });
/*
* 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();
});
}); });