From 54d4d66f72e47da63508183973d7864238ddbe63 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 22 Feb 2010 05:27:17 +0000 Subject: [PATCH] BUGFIX: Debugged and simplified Access tab javascript git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@99594 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/SitetreeAccess.js | 66 ++++++------------------------------ 1 file changed, 11 insertions(+), 55 deletions(-) diff --git a/javascript/SitetreeAccess.js b/javascript/SitetreeAccess.js index 2652b256..d25d70dc 100644 --- a/javascript/SitetreeAccess.js +++ b/javascript/SitetreeAccess.js @@ -1,63 +1,19 @@ /** * UI behaviour for the "Access" tab - * - * Adapted from the forum module "ForumAccess.js" file. - * - * @author Markus Lanthaler */ -ViewersGroupHide = function() { - $('ViewerGroups').style.display = "none"; -} -EditorsGroupHide = function() { - $('EditorGroups').style.display = "none"; -} - -Behaviour.register({ - '#Form_EditForm_CanViewType_OnlyTheseUsers': { - - onclick: function() { - $('ViewerGroups').style.display = "block"; - }, - +var siteTreeAccessHandler = function(canField, groupsField) { + var output = {} + output['#Form_EditForm_' + canField + ' input'] = { initialize: function() { - if($('Form_EditForm_CanViewType_OnlyTheseUsers')) { - if($('Form_EditForm_CanViewType_OnlyTheseUsers').checked) - $('ViewerGroups').style.display = "block"; - else - $('ViewerGroups').style.display = "none"; - } - } - }, - '#Form_EditForm_CanViewType_Anyone': { - onclick: ViewersGroupHide - }, - '#Form_EditForm_CanViewType_LoggedInUsers': { - onclick: ViewersGroupHide - }, - '#Form_EditForm_CanViewType_Inherit': { - onclick: ViewersGroupHide - }, - - '#Form_EditForm_CanEditType_OnlyTheseUsers': { - - onclick: function() { - $('EditorGroups').style.display = "block"; + if(this.checked) this.click(); }, - - initialize: function() { - if($('Form_EditForm_CanEditType_OnlyTheseUsers')) { - if($('Form_EditForm_CanEditType_OnlyTheseUsers').checked) - $('EditorGroups').style.display = "block"; - else - $('EditorGroups').style.display = "none"; - } + onclick: function() { + $(groupsField).style.display = (this.value == 'OnlyTheseUsers') ? 'block' : 'none'; } - }, - '#Form_EditForm_CanEditType_LoggedInUsers': { - onclick: EditorsGroupHide - }, - '#Form_EditForm_CanEditType_Inherit': { - onclick: EditorsGroupHide } -}); \ No newline at end of file + return output; +}; + +Behaviour.register(siteTreeAccessHandler('CanViewType', 'ViewerGroups')); +Behaviour.register(siteTreeAccessHandler('CanEditType', 'EditorGroups')); \ No newline at end of file