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
|
2012-10-25 21:46:57 +02:00
|
|
|
|
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');
|
2012-10-25 21:46:57 +02:00
|
|
|
});
|
2010-12-02 19:50:21 +01:00
|
|
|
};
|
2012-10-25 21:46:57 +02: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');
|
2012-10-25 21:46:57 +02:00
|
|
|
});
|
2010-12-02 19:50:21 +01:00
|
|
|
};
|
2012-10-25 21:46:57 +02:00
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
/* Update settings */
|
2010-12-12 09:13:03 +01:00
|
|
|
$.updateSettings = function () {
|
2012-10-25 21:46:57 +02: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");
|
2012-10-25 21:46:57 +02:00
|
|
|
|
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'),
|
2013-09-17 14:03:46 +02:00
|
|
|
$('#formfield-form-widgets-edit_comment_enabled'),
|
2014-09-20 16:02:48 +02:00
|
|
|
$('#formfield-form-widgets-delete_own_comment_enabled'),
|
2010-12-12 09:13:03 +01:00
|
|
|
$('#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'),
|
2013-09-17 14:03:46 +02:00
|
|
|
$('#formfield-form-widgets-edit_comment_enabled'),
|
2014-09-20 16:02:48 +02:00
|
|
|
$('#formfield-form-widgets-delete_own_comment_enabled'),
|
2010-12-12 09:13:03 +01:00
|
|
|
$('#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
|
|
|
}
|
2012-10-25 21:46:57 +02: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([
|
2012-10-25 21:46:57 +02:00
|
|
|
$('#formfield-form-widgets-moderator_notification_enabled'),
|
|
|
|
$('#formfield-form-widgets-moderator_email'),
|
2011-04-22 17:41:45 +02:00
|
|
|
$('#formfield-form-widgets-user_notification_enabled')
|
|
|
|
]);
|
|
|
|
}
|
2010-12-11 22:30:18 +01:00
|
|
|
}
|
2012-10-25 21:46:57 +02:00
|
|
|
|
|
|
|
/* If a custom workflow for comments is enabled, disable the moderation
|
2010-12-11 22:30:18 +01:00
|
|
|
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
|
2012-10-25 21:46:57 +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 () {
|
2012-10-25 21:46:57 +02:00
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
// Update settings on page load
|
|
|
|
$.updateSettings();
|
2012-10-25 21:46:57 +02:00
|
|
|
|
2010-12-03 00:02:00 +01:00
|
|
|
// Set #content class and update settings afterwards
|
2014-03-14 16:51:57 +01:00
|
|
|
$("input,select").on("change", function (e) {
|
2010-12-03 00:02:00 +01:00
|
|
|
var id = $(this).attr("id");
|
2012-10-25 21:46:57 +02:00
|
|
|
if (id === "form-widgets-globally_enabled-0") {
|
2013-02-03 21:01:46 +01:00
|
|
|
if ($(this).attr("checked")) {
|
2010-12-03 00:02:00 +01:00
|
|
|
$("#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
|
|
|
});
|
2012-10-25 21:46:57 +02:00
|
|
|
|
2010-12-02 22:07:58 +01:00
|
|
|
/**********************************************************************
|
2012-10-25 21:46:57 +02:00
|
|
|
* Remove the disabled attribute from all form elements before
|
2010-12-02 20:49:49 +01:00
|
|
|
* 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');
|
|
|
|
});
|
2012-10-25 21:46:57 +02:00
|
|
|
|
2011-04-22 17:41:45 +02:00
|
|
|
});
|
2010-12-02 19:15:47 +01:00
|
|
|
|
|
|
|
//#JSCOVERAGE_ENDIF
|
|
|
|
|
|
|
|
}(jQuery));
|