Move to sane directory structure. Don't make 'cms' the top level of the silverstripe...
[silverstripe-elijah.git] / javascript / SecurityAdmin_left.js
blob0ee9c94d3c3f8f9e23f861a737d6d12937f3b824
1 SiteTreeHandlers.parentChanged_url = 'admin/security/ajaxupdateparent';
2 SiteTreeHandlers.orderChanged_url = 'admin/security/ajaxupdatesort';
3 SiteTreeHandlers.loadPage_url = 'admin/security/getitem';
5 _HANDLER_FORMS['deletegroup'] = 'deletegroup_options';
7 /**
8  * Add page action
9  * @todo Remove duplication between this and the CMSMain Add page action
10  */
11 addgroup = {
12         button_onclick : function() {
13                 addgroup.form_submit();
14                 return false;
15         },
16         
17         form_submit : function() {
18                 var st = $('sitetree');
19                 $('addgroup_options').elements.ParentID.value = st.firstSelected() ? st.getIdxOf(st.firstSelected()) : 0;
20                 Ajax.SubmitForm('addgroup_options', null, {
21                         onSuccess : Ajax.Evaluator,
22                         onFailure : function(response) {
23                                 errorMessage('Error adding page', response);
24                         }
25                 });
26                 
27                 return false;
28         }
31 /**
32  * Delete page action
33  */
34 deletegroup = {
35         button_onclick : function() {
36                 /*if( $('deletegroup_options').style.display == 'none' )
37                         $('deletegroup_options').style.display = 'block';
38                 else
39                         $('deletegroup_options').style.display = 'none';*/
40                 
41                 if(treeactions.toggleSelection(this)) {
42                         $('deletegroup_options').style.display = 'block';
43                         
44                         deletegroup.o1 = $('sitetree').observeMethod('SelectionChanged', deletegroup.treeSelectionChanged);
45                         deletegroup.o2 = $('deletegroup_options').observeMethod('Close', deletegroup.popupClosed);
46                         addClass($('sitetree'),'multiselect');
48                         deletegroup.selectedNodes = { };
49                         
50                         var sel = $('sitetree').firstSelected();
51                         if(sel && sel.className.indexOf('nodelete') == -1) {
52                                 var selIdx = $('sitetree').getIdxOf(sel);
53                                 deletegroup.selectedNodes[selIdx] = true;
54                                 sel.removeNodeClass('current');
55                                 sel.addNodeClass('selected');           
56                         }
57                 } else 
58                         $('deletegroup_options').style.display = 'none';
59                         
60                 return false;
61         },
63         treeSelectionChanged : function(selectedNode) {
64                 var idx = $('sitetree').getIdxOf(selectedNode);
66                 if(selectedNode.className.indexOf('nodelete') == -1) {
67                         if(selectedNode.selected) {
68                                 selectedNode.removeNodeClass('selected');
69                                 selectedNode.selected = false;
70                                 deletegroup.selectedNodes[idx] = false;
71         
72                         } else {
73                                 selectedNode.addNodeClass('selected');
74                                 selectedNode.selected = true;
75                                 deletegroup.selectedNodes[idx] = true;
76                         }
77                 }
78                 
79                 return false;
80         },
81         
82         popupClosed : function() {
83                 removeClass($('sitetree'),'multiselect');
84                 $('sitetree').stopObserving(deletegroup.o1);
85                 $('deletegroup_options').stopObserving(deletegroup.o2);
87                 for(var idx in deletegroup.selectedNodes) {
88                         if(deletegroup.selectedNodes[idx]) {
89                                 node = $('sitetree').getTreeNodeByIdx(idx);
90                                 if(node) {
91                                         node.removeNodeClass('selected');
92                                         node.selected = false;
93                                 }
94                         }
95                 }
96         },
98         form_submit : function() {
99                 var csvIDs = "";
100                 for(var idx in deletegroup.selectedNodes) {
101                         if(deletegroup.selectedNodes[idx]) csvIDs += (csvIDs ? "," : "") + idx;
102                 }
103                 if(csvIDs) {
104                         if(confirm("Do you really want to these groups?")) {
105                                 $('deletegroup_options').elements.csvIDs.value = csvIDs;
106         
107                                 Ajax.SubmitForm('deletegroup_options', null, {
108                                         onSuccess : function(response) {
109                                                 Ajax.Evaluator(response);
110         
111                                                 var sel;
112                                                 if((sel = $('sitetree').firstSelected()) && sel.parentNode) sel.addNodeClass('current');
113                                                 else $('Form_EditForm').innerHTML = "";
114         
115                                                 treeactions.closeSelection($('deletegroup'));
116                                         },
117                                         onFailure : function(response) {
118                                                 errorMessage('Error deleting pages', response);
119                                         }
120                                 });
121         
122                                 $('deletegroup').getElementsByTagName('button')[0].onclick();
123                         }
124                 } else {
125                         alert("Please select at least 1 group.");
126                 }
128                 return false;
129         }
133 /** 
134  * Initialisation function to set everything up
135  */
136 Behaviour.addLoader(function () {
137         // Set up add page
138         Observable.applyTo($('addgroup_options'));
139         $('addgroup').onclick = addgroup.button_onclick;
140         $('addgroup').getElementsByTagName('button')[0].onclick = function() {return false;};
141         $('addgroup_options').onsubmit = addgroup.form_submit;
143         // Set up delete page
144         Observable.applyTo($('deletegroup_options'));
145         $('deletegroup').onclick = deletegroup.button_onclick;
146         $('deletegroup').getElementsByTagName('button')[0].onclick = function() {return false;};
147         $('deletegroup_options').onsubmit = deletegroup.form_submit;