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:
parent
fbd7eb2bbc
commit
ffde4b423d
@ -4,7 +4,11 @@ Changelog
|
|||||||
1.0RC1 (unreleased)
|
1.0RC1 (unreleased)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
- Disable all commenting options in the discussion control panel when comments
|
- Do not allow to change the mail settings in the discussion control panel, if
|
||||||
|
there is no valid mail setup.
|
||||||
|
[timo]
|
||||||
|
|
||||||
|
- Disable all commenting options in the discussion control panel if comments
|
||||||
are disabled globally.
|
are disabled globally.
|
||||||
|
|
||||||
- Check for the 'review comments' permission instead of 'manage' to decide
|
- Check for the 'review comments' permission instead of 'manage' to decide
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="content"
|
<div id="content"
|
||||||
tal:attributes="class python: view.invalid_mail_setup and 'invalid_mail_setup'"
|
tal:attributes="class view/settings"
|
||||||
metal:fill-slot="prefs_configlet_content">
|
metal:fill-slot="prefs_configlet_content">
|
||||||
|
|
||||||
<script type="text/javascript"
|
<script type="text/javascript"
|
||||||
|
@ -8,7 +8,7 @@ from plone.app.registry.browser import controlpanel
|
|||||||
|
|
||||||
from plone.registry.interfaces import IRegistry
|
from plone.registry.interfaces import IRegistry
|
||||||
|
|
||||||
from zope.component import getMultiAdapter
|
from zope.component import getMultiAdapter, queryUtility
|
||||||
|
|
||||||
from z3c.form import button
|
from z3c.form import button
|
||||||
from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
|
from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
|
||||||
@ -77,17 +77,23 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
|
|||||||
form = DiscussionSettingsEditForm
|
form = DiscussionSettingsEditForm
|
||||||
index = ViewPageTemplateFile('controlpanel.pt')
|
index = ViewPageTemplateFile('controlpanel.pt')
|
||||||
|
|
||||||
def anonymous_discussion_allowed(self):
|
def settings(self):
|
||||||
"""Return true if anonymous comments are allowed in the registry.
|
"""Compose a string that contains all registry settings that are
|
||||||
|
needed for the discussion control panel.
|
||||||
"""
|
"""
|
||||||
registry = queryUtility(IRegistry)
|
registry = queryUtility(IRegistry)
|
||||||
settings = registry.forInterface(IDiscussionSettings, check=False)
|
settings = registry.forInterface(IDiscussionSettings, check=False)
|
||||||
return settings.anonymous_comments
|
|
||||||
|
output = []
|
||||||
def invalid_mail_setup(self):
|
if settings.globally_enabled:
|
||||||
"""Return true if the Plone site has a valid mail setup.
|
output.append("globally_enabled")
|
||||||
"""
|
|
||||||
|
if settings.anonymous_comments:
|
||||||
|
output.append("anonymous_comments")
|
||||||
|
|
||||||
ctrlOverview = getMultiAdapter((self.context, self.request),
|
ctrlOverview = getMultiAdapter((self.context, self.request),
|
||||||
name='overview-controlpanel')
|
name='overview-controlpanel')
|
||||||
return ctrlOverview.mailhost_warning()
|
if ctrlOverview.mailhost_warning():
|
||||||
|
output.append("invalid_mail_setup")
|
||||||
|
|
||||||
|
return ' '.join(output)
|
||||||
|
@ -7,11 +7,8 @@
|
|||||||
// This unnamed function allows us to use $ inside of a block of code
|
// This unnamed function allows us to use $ inside of a block of code
|
||||||
// without permanently overwriting $.
|
// without permanently overwriting $.
|
||||||
// http://docs.jquery.com/Using_jQuery_with_Other_Libraries
|
// http://docs.jquery.com/Using_jQuery_with_Other_Libraries
|
||||||
|
|
||||||
/**************************************************************************
|
/* Disable a control panel setting */
|
||||||
* Disable a control panel setting. Grey out the setting and disable all
|
|
||||||
* form elements.
|
|
||||||
**************************************************************************/
|
|
||||||
$.disableSettings = function (settings) {
|
$.disableSettings = function (settings) {
|
||||||
$.each(settings, function (intIndex, setting) {
|
$.each(settings, function (intIndex, setting) {
|
||||||
setting.addClass('unclickable');
|
setting.addClass('unclickable');
|
||||||
@ -20,6 +17,7 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Enable a control panel setting */
|
||||||
$.enableSettings = function (settings) {
|
$.enableSettings = function (settings) {
|
||||||
$.each(settings, function (intIndex, setting) {
|
$.each(settings, function (intIndex, setting) {
|
||||||
setting.removeClass('unclickable');
|
setting.removeClass('unclickable');
|
||||||
@ -27,32 +25,25 @@
|
|||||||
setting_field.removeAttr('disabled');
|
setting_field.removeAttr('disabled');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//#JSCOVERAGE_IF 0
|
/* Update settings */
|
||||||
|
$.updateSettings = function () {
|
||||||
/**************************************************************************
|
|
||||||
* Window Load Function: Executes when complete page is fully loaded,
|
var globally_enabled = $("#content").hasClass("globally_enabled");
|
||||||
* including all frames,
|
var anonymous_comments = $("#content").hasClass("anonymous_comments");
|
||||||
**************************************************************************/
|
|
||||||
$(window).load(function () {
|
|
||||||
|
|
||||||
/**********************************************************************
|
|
||||||
* Do not allow to change the mail settings if there is no valid mail
|
|
||||||
* setup.
|
|
||||||
**********************************************************************/
|
|
||||||
var invalid_mail_setup = $("#content").hasClass("invalid_mail_setup");
|
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-moderator_notification_enabled'),
|
||||||
$('#formfield-form-widgets-user_notification_enabled')
|
$('#formfield-form-widgets-user_notification_enabled')
|
||||||
]);
|
]);
|
||||||
};
|
} else {
|
||||||
|
|
||||||
/**********************************************************************
|
|
||||||
* 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) {
|
|
||||||
$.disableSettings([
|
$.disableSettings([
|
||||||
$('#formfield-form-widgets-anonymous_comments'),
|
$('#formfield-form-widgets-anonymous_comments'),
|
||||||
$('#formfield-form-widgets-text_transform'),
|
$('#formfield-form-widgets-text_transform'),
|
||||||
@ -61,45 +52,56 @@
|
|||||||
$('#formfield-form-widgets-moderator_notification_enabled'),
|
$('#formfield-form-widgets-moderator_notification_enabled'),
|
||||||
$('#formfield-form-widgets-user_notification_enabled')
|
$('#formfield-form-widgets-user_notification_enabled')
|
||||||
]);
|
]);
|
||||||
};
|
}
|
||||||
$("input[name='form.widgets.globally_enabled:list']").live("click", function (e) {
|
|
||||||
if ($(this).attr("checked")) {
|
/* If the mail setup is invalid, disable the mail settings. */
|
||||||
// commenting globally enabled
|
if (invalid_mail_setup === true) {
|
||||||
$.enableSettings([
|
$.disableSettings([
|
||||||
$('#formfield-form-widgets-anonymous_comments'),
|
$('#formfield-form-widgets-moderator_notification_enabled'),
|
||||||
$('#formfield-form-widgets-text_transform'),
|
$('#formfield-form-widgets-user_notification_enabled')
|
||||||
$('#formfield-form-widgets-captcha'),
|
]);
|
||||||
$('#formfield-form-widgets-show_commenter_image'),
|
} else {
|
||||||
$('#formfield-form-widgets-moderator_notification_enabled'),
|
$.enableSettings([
|
||||||
$('#formfield-form-widgets-user_notification_enabled')
|
$('#formfield-form-widgets-moderator_notification_enabled'),
|
||||||
]);
|
$('#formfield-form-widgets-user_notification_enabled')
|
||||||
} else {
|
]);
|
||||||
// commenting globally disabled
|
}
|
||||||
$.disableSettings([
|
};
|
||||||
$('#formfield-form-widgets-anonymous_comments'),
|
//#JSCOVERAGE_IF 0
|
||||||
$('#formfield-form-widgets-text_transform'),
|
|
||||||
$('#formfield-form-widgets-captcha'),
|
/**************************************************************************
|
||||||
$('#formfield-form-widgets-show_commenter_image'),
|
* Window Load Function: Executes when complete page is fully loaded,
|
||||||
$('#formfield-form-widgets-moderator_notification_enabled'),
|
* including all frames,
|
||||||
$('#formfield-form-widgets-user_notification_enabled')
|
**************************************************************************/
|
||||||
]);
|
$(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
|
* Remove the disabled attribute from all form elements before
|
||||||
* submitting the form. Otherwise the z3c.form will raise errors on
|
* submitting the form. Otherwise the z3c.form will raise errors on
|
||||||
* the required attributes.
|
* the required attributes.
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
$("input[name='form.buttons.save']").live("click", function (e) {
|
$("input[name='form.buttons.save']").bind("click", function (e) {
|
||||||
e.preventDefault();
|
//e.preventDefault();
|
||||||
$('#formfield-form-widgets-anonymous_comments').removeAttr('disabled');
|
var form = $(this).parents("form");
|
||||||
$('#formfield-form-widgets-text_transform').removeAttr('disabled');
|
$(form).find("input,select").removeAttr('disabled');
|
||||||
$('#formfield-form-widgets-captcha').removeAttr('disabled');
|
$(form).submit();
|
||||||
$('#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();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user