Move to sane directory structure. Don't make 'cms' the top level of the silverstripe...
[silverstripe-elijah.git] / silverstripe-gsoc / cms / javascript / ForumAdmin.js
blobd316d18a50e96fb1fd1c85620e6210ee4bb8b487
1 var _GroupID;
2 Behaviour.register({
3         '#Form_EditForm_Type input':{
4                 onclick:function(){
5                         var requiredlogin = $('Form_EditForm_RequiredLogin');
6                         var usersTab = $('Form_EditForm').getElementsByTagName('ul')[0].getElementsByTagName('li')[2];
7                         if(this.value == 'consultation'){
8                                 if(requiredlogin.checked != 'checked')
9                                         requiredlogin.checked = 'checked';
10                                 usersTab.style.display = 'block';
11                                 if(_GroupID)
12                                         this.recoverGroupID();
13                                 Element.disable(requiredlogin);
14                         }else{ // this.value == 'open'
15                                 usersTab.style.display = 'none';
16                                 this.treatGroupIDAs0();
17                                 Element.enable(requiredlogin);
18                         }
19                 },
21                 treatGroupIDAs0:function(){
22                         var groupIDDiv = $('GroupID');
23                         var groupIDs = groupIDDiv.getElementsByTagName('option');
24                         for(var i=0; i<groupIDs.length; i++){
25                                 if(groupIDs[i].selected == true){
26                                         groupIDs[i].selected = false;
27                                         break;
28                                 }
29                         }
30                         _GroupID = groupIDs[i].value;
31                         groupIDs[0].selected = true;
32                 },
33                 
34                 recoverGroupID:function(){
35                         var groupIDDiv = $('GroupID');
36                         var groupIDs = groupIDDiv.getElementsByTagName('option');
37                         groupIDs[0].selected = false;
38                         for(var i=0; i<groupIDs.length; i++){
39                                 if(groupIDs[i].value == _GroupID){
40                                         groupIDs[i].selected = true;
41                                         break;
42                                 }
43                         }
44                         _GrouipID = null;
45                 }
46         },
47         
48         '#Root_Users #GroupID select':{
49                 onchange:function() {
50                         var source = this.getElementsByTagName('option');
51                         
52                         for(var i=0; i<source.length; i++){
53                                 if(source[i].selected == true){
54                                         break;
55                                 }
56                         }
57                         
58                         var action=getAjaxURL('getMembersByGroup', source[i].value, 'ajax=1');
59                         new Ajax.Updater(
60                                 {success: 'MemberList'},
61                                 action,
62                                 {
63                                         method: 'get',
64                                         onFailure: function(response) {errorMessage("Error getting data", response);},
65                                         onComplete: function() {Behaviour.apply($('MemberList'));}
66                                 }
67                         );
68                         
69                         return false;
70                 }
71         }
72 });
74 function getAjaxURL(action, param, getvars) {
75         var base = document.getElementsByTagName('base')[0].href;
76         var url = window.location.href.substr(base.length);
77         if(url.match(/^([^?]+)(\?.*)/)){
78                 url=RegExp.$1;
79         }
80         if(!url.match(/^([^\/]+\/)$/)){
81                 url = url+"/";
82         }
83         
84         if(getvars) getvars = "?" + getvars;
85         else getvars = "";
86         return base + url.replace(/^([^\/]+\/).*/, '$1' + action + '/' + param + getvars);
89 Element.disable = function(el){
90         el.disabled = true;
93 Element.enable = function(el){
94         el.disabled = false;
97 initialiseCMSIfAForumLoaded = function(){
98         if($('Form_EditForm_Type')) {
99                 var types=($('Form_EditForm_Type').getElementsByTagName('input'));
100                 for(var i=0; i<types.length; i++){
101         
102                         if(types[i].checked)
103                         {
104                                 if(types[i].onclick) types[i].onclick();
105                         }
106                 }
107         }
110 Behaviour.addLoader(function(){
111         if($('Form_EditForm').observeMethod) {
112                 $('Form_EditForm').observeMethod('PageLoaded', initialiseCMSIfAForumLoaded());
113         }
114