2010-12-02 19:15:47 +01:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* jQuery functions for the plone.app.discussion comment viewlet and form.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2015-02-10 23:41:00 +01:00
|
|
|
/* global require */
|
|
|
|
|
|
|
|
if(require === undefined){
|
|
|
|
require = function(reqs, torun){ // jshint ignore:line
|
|
|
|
'use strict';
|
|
|
|
return torun(window.jQuery);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
require([ // jshint ignore:line
|
|
|
|
'jquery'
|
|
|
|
], function ($) {
|
|
|
|
'use strict';
|
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');
|
2015-02-10 23:41:00 +01:00
|
|
|
var setting_field = $(setting).find('input,select');
|
2010-12-02 20:49:49 +01:00
|
|
|
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');
|
2015-02-10 23:41:00 +01:00
|
|
|
var setting_field = $(setting).find('input,select');
|
2010-12-02 20:49:49 +01:00
|
|
|
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
|
|
|
|
2021-02-15 17:06:49 +01:00
|
|
|
var globally_enabled = $('#content-core').hasClass('globally_enabled');
|
|
|
|
var moderation_custom = $('#content-core').hasClass('moderation_custom');
|
|
|
|
var invalid_mail_setup = $('#content-core').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'),
|
2015-09-13 15:38:46 +02:00
|
|
|
$('#formfield-form-widgets-anonymous_email_enabled'),
|
2010-12-12 09:13:03 +01:00
|
|
|
$('#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'),
|
2015-09-13 15:38:46 +02:00
|
|
|
$('#formfield-form-widgets-anonymous_email_enabled'),
|
2010-12-12 09:13:03 +01:00
|
|
|
$('#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,
|
|
|
|
**************************************************************************/
|
2015-02-11 23:30:03 +01:00
|
|
|
$(document).ready(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
|
|
|
|
2021-02-15 17:06:49 +01:00
|
|
|
// Set #content-core class and update settings afterwards
|
2015-02-10 23:41:00 +01:00
|
|
|
$('#form-widgets-globally_enabled-0').on('change', function(){
|
|
|
|
if (this.checked) {
|
2021-02-15 17:06:49 +01:00
|
|
|
$('#content-core').addClass('globally_enabled');
|
2015-02-10 23:41:00 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-02-15 17:06:49 +01:00
|
|
|
$('#content-core').removeClass('globally_enabled');
|
2010-12-02 19:15:47 +01:00
|
|
|
}
|
2015-02-10 23:41:00 +01:00
|
|
|
$.updateSettings();
|
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
|
|
|
**********************************************************************/
|
2015-02-10 23:41:00 +01:00
|
|
|
$('form#DiscussionSettingsEditForm').bind('submit', function () {
|
|
|
|
$(this).find('input,select').removeAttr('disabled');
|
2011-07-15 10:23:08 +02:00
|
|
|
});
|
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
|
|
|
|
|
2015-02-10 23:41:00 +01:00
|
|
|
});
|