2010-12-02 19:15:47 +01:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* jQuery functions for the plone.app.discussion comment viewlet and form.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
(function ($) {
|
2011-04-22 17:41:45 +02:00
|
|
|
// 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
|
2010-12-03 00:02:00 +01:00
|
|
|
|
|
|
|
/* Disable a control panel setting */
|
2010-12-02 19:50:21 +01:00
|
|
|
$.disableSettings = function (settings) {
|
2010-12-02 20:49:49 +01:00
|
|
|
$.each(settings, function (intIndex, setting) {
|
|
|
|
setting.addClass('unclickable');
|
|
|
|
var setting_field = $(setting).find("input,select");
|
|
|
|
setting_field.attr('disabled', 'disabled');
|
|
|
|
});
|
2010-12-02 19:50:21 +01:00
|
|
|
};
|
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
/* Enable a control panel setting */
|
2010-12-02 19:50:21 +01:00
|
|
|
$.enableSettings = function (settings) {
|
2010-12-02 20:49:49 +01:00
|
|
|
$.each(settings, function (intIndex, setting) {
|
|
|
|
setting.removeClass('unclickable');
|
|
|
|
var setting_field = $(setting).find("input,select");
|
|
|
|
setting_field.removeAttr('disabled');
|
|
|
|
});
|
2010-12-02 19:50:21 +01:00
|
|
|
};
|
2010-12-03 00:02:00 +01:00
|
|
|
|
|
|
|
/* Update settings */
|
2010-12-12 09:13:03 +01:00
|
|
|
$.updateSettings = function () {
|
2010-12-11 22:30:18 +01:00
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
var globally_enabled = $("#content").hasClass("globally_enabled");
|
|
|
|
var anonymous_comments = $("#content").hasClass("anonymous_comments");
|
2010-12-11 22:30:18 +01:00
|
|
|
var moderation_enabled = $("#content").hasClass("moderation_enabled");
|
|
|
|
var moderation_custom = $("#content").hasClass("moderation_custom");
|
2010-12-02 22:07:58 +01:00
|
|
|
var invalid_mail_setup = $("#content").hasClass("invalid_mail_setup");
|
2010-12-03 00:02:00 +01:00
|
|
|
|
|
|
|
/* If commenting is globally disabled, disable all settings. */
|
|
|
|
if (globally_enabled === true) {
|
2010-12-12 09:13:03 +01:00
|
|
|
$.enableSettings([
|
|
|
|
$('#formfield-form-widgets-anonymous_comments'),
|
|
|
|
$('#formfield-form-widgets-moderation_enabled'),
|
|
|
|
$('#formfield-form-widgets-text_transform'),
|
|
|
|
$('#formfield-form-widgets-captcha'),
|
|
|
|
$('#formfield-form-widgets-show_commenter_image'),
|
2011-04-22 17:41:45 +02:00
|
|
|
$('#formfield-form-widgets-moderator_notification_enabled'),
|
|
|
|
$('#formfield-form-widgets-moderator_email'),
|
2010-12-12 09:13:03 +01:00
|
|
|
$('#formfield-form-widgets-user_notification_enabled')
|
|
|
|
]);
|
2010-12-03 00:02:00 +01:00
|
|
|
}
|
2010-12-11 22:30:18 +01:00
|
|
|
else {
|
2010-12-12 09:13:03 +01:00
|
|
|
$.disableSettings([
|
|
|
|
$('#formfield-form-widgets-anonymous_comments'),
|
|
|
|
$('#formfield-form-widgets-moderation_enabled'),
|
|
|
|
$('#formfield-form-widgets-text_transform'),
|
|
|
|
$('#formfield-form-widgets-captcha'),
|
|
|
|
$('#formfield-form-widgets-show_commenter_image'),
|
|
|
|
$('#formfield-form-widgets-moderator_notification_enabled'),
|
2011-04-22 17:41:45 +02:00
|
|
|
$('#formfield-form-widgets-moderator_email'),
|
2010-12-12 09:13:03 +01:00
|
|
|
$('#formfield-form-widgets-user_notification_enabled')
|
|
|
|
]);
|
2010-12-11 22:30:18 +01:00
|
|
|
}
|
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
/* If the mail setup is invalid, disable the mail settings. */
|
|
|
|
if (invalid_mail_setup === true) {
|
2011-04-22 17:41:45 +02:00
|
|
|
$.disableSettings([
|
|
|
|
$('#formfield-form-widgets-moderator_notification_enabled'),
|
|
|
|
$('#formfield-form-widgets-moderator_email'),
|
|
|
|
$('#formfield-form-widgets-user_notification_enabled')
|
|
|
|
]);
|
2010-12-03 00:02:00 +01:00
|
|
|
}
|
2010-12-11 22:30:18 +01:00
|
|
|
else {
|
2011-04-22 17:41:45 +02:00
|
|
|
/* Enable mail setup only if discussion is enabled. */
|
|
|
|
if (globally_enabled === true) {
|
|
|
|
$.enableSettings([
|
|
|
|
$('#formfield-form-widgets-moderator_notification_enabled'),
|
|
|
|
$('#formfield-form-widgets-moderator_email'),
|
|
|
|
$('#formfield-form-widgets-user_notification_enabled')
|
|
|
|
]);
|
|
|
|
}
|
2010-12-11 22:30:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If a custom workflow for comments is enabled, disable the moderation
|
|
|
|
switch. */
|
|
|
|
if (moderation_custom === true) {
|
2011-04-22 17:41:45 +02:00
|
|
|
$.disableSettings([
|
|
|
|
$('#formfield-form-widgets-moderation_enabled')
|
|
|
|
]);
|
2010-12-11 22:30:18 +01:00
|
|
|
}
|
2010-12-12 09:13:03 +01:00
|
|
|
};
|
2010-12-03 00:02:00 +01:00
|
|
|
//#JSCOVERAGE_IF 0
|
2011-04-22 17:41:45 +02:00
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* Window Load Function: Executes when complete page is fully loaded,
|
|
|
|
* including all frames,
|
|
|
|
**************************************************************************/
|
|
|
|
$(window).load(function () {
|
2011-04-22 17:41:45 +02:00
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
// Update settings on page load
|
|
|
|
$.updateSettings();
|
2011-04-22 17:41:45 +02:00
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
// 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();
|
2010-12-02 19:15:47 +01:00
|
|
|
}
|
2010-12-02 20:49:49 +01:00
|
|
|
});
|
2010-12-03 00:02:00 +01:00
|
|
|
|
2010-12-02 22:07:58 +01:00
|
|
|
/**********************************************************************
|
2010-12-02 20:49:49 +01:00
|
|
|
* Remove the disabled attribute from all form elements before
|
|
|
|
* submitting the form. Otherwise the z3c.form will raise errors on
|
|
|
|
* the required attributes.
|
2010-12-02 22:07:58 +01:00
|
|
|
**********************************************************************/
|
2011-07-15 10:23:08 +02:00
|
|
|
$("form#DiscussionSettingsEditForm").bind("submit", function (e) {
|
|
|
|
$(this).find("input,select").removeAttr('disabled');
|
|
|
|
$(this).submit();
|
|
|
|
});
|
2011-04-22 17:41:45 +02:00
|
|
|
|
|
|
|
});
|
2010-12-02 19:15:47 +01:00
|
|
|
|
|
|
|
//#JSCOVERAGE_ENDIF
|
|
|
|
|
|
|
|
}(jQuery));
|