includes/clientside/static/acl.js
changeset 40 723bb7acf914
parent 1 fe660c52c48f
child 42 45ebe475ff75
equal deleted inserted replaced
39:c83ff194977a 40:723bb7acf914
    24   ajaxPost(stdAjaxPrefix+'&_mode=acljson', 'acl_params='+params, function() {
    24   ajaxPost(stdAjaxPrefix+'&_mode=acljson', 'acl_params='+params, function() {
    25       if(ajax.readyState == 4)
    25       if(ajax.readyState == 4)
    26       {
    26       {
    27         __aclBuildWizardWindow();
    27         __aclBuildWizardWindow();
    28         groups = parseJSON(ajax.responseText);
    28         groups = parseJSON(ajax.responseText);
       
    29         if ( groups.mode == 'error' )
       
    30         {
       
    31           alert(groups.error);
       
    32           killACLManager();
       
    33           return false;
       
    34         }
    29         aclDataCache = groups;
    35         aclDataCache = groups;
    30         __aclBuildSelector(groups);
    36         __aclBuildSelector(groups);
    31       }
    37       }
    32     });
    38     });
    33   return false;
    39   return false;
    50       {
    56       {
    51         document.getElementById(aclManagerID+'_main').innerHTML = '';
    57         document.getElementById(aclManagerID+'_main').innerHTML = '';
    52         document.getElementById(aclManagerID + '_back').style.display = 'none';
    58         document.getElementById(aclManagerID + '_back').style.display = 'none';
    53         document.getElementById(aclManagerID + '_next').value = 'Next >';
    59         document.getElementById(aclManagerID + '_next').value = 'Next >';
    54         groups = parseJSON(ajax.responseText);
    60         groups = parseJSON(ajax.responseText);
       
    61         if ( groups.mode == 'error' )
       
    62         {
       
    63           alert(groups.error);
       
    64           killACLManager();
       
    65           return false;
       
    66         }
    55         aclDataCache = groups;
    67         aclDataCache = groups;
    56         thispage = strToPageID(title);
    68         thispage = strToPageID(title);
    57         groups.page_id = thispage[0];
    69         groups.page_id = thispage[0];
    58         groups.namespace = thispage[1];
    70         groups.namespace = thispage[1];
    59         __aclBuildSelector(groups);
    71         __aclBuildSelector(groups);
    81   
    93   
    82   // Build the selector
    94   // Build the selector
    83   grpb = document.createElement('input');
    95   grpb = document.createElement('input');
    84   grpb.type = 'radio';
    96   grpb.type = 'radio';
    85   grpb.name  = 'target_type';
    97   grpb.name  = 'target_type';
    86   grpb.value = 1; // ACL_TYPE_GROUP
    98   grpb.value = '1'; // ACL_TYPE_GROUP
    87   grpb.checked = 'checked';
    99   grpb.checked = 'checked';
    88   grpb.className = seed;
   100   grpb.className = seed;
    89   grpb.onclick = function() { seed = this.className; document.getElementById('enACL_grpbox_'+seed).style.display = 'block'; document.getElementById('enACL_usrbox_'+seed).style.display = 'none'; };
   101   grpb.onclick = function() { seed = this.className; document.getElementById('enACL_grpbox_'+seed).style.display = 'block'; document.getElementById('enACL_usrbox_'+seed).style.display = 'none'; };
    90   lbl = document.createElement('label');
   102   lbl = document.createElement('label');
    91   lbl.appendChild(grpb);
   103   lbl.appendChild(grpb);
    94   span.appendChild(grpsel);
   106   span.appendChild(grpsel);
    95   
   107   
    96   usrb = document.createElement('input');
   108   usrb = document.createElement('input');
    97   usrb.type = 'radio';
   109   usrb.type = 'radio';
    98   usrb.name  = 'target_type';
   110   usrb.name  = 'target_type';
    99   usrb.value = 2; // ACL_TYPE_USER
   111   usrb.value = '2'; // ACL_TYPE_USER
   100   usrb.className = seed;
   112   usrb.className = seed;
   101   usrb.onclick = function() { seed = this.className; document.getElementById('enACL_grpbox_'+seed).style.display = 'none'; document.getElementById('enACL_usrbox_'+seed).style.display = 'block'; };
   113   usrb.onclick = function() { seed = this.className; document.getElementById('enACL_grpbox_'+seed).style.display = 'none'; document.getElementById('enACL_usrbox_'+seed).style.display = 'block'; };
   102   lbl2 = document.createElement('label');
   114   lbl2 = document.createElement('label');
   103   lbl2.appendChild(usrb);
   115   lbl2.appendChild(usrb);
   104   lbl2.appendChild(document.createTextNode('A specific user'));
   116   lbl2.appendChild(document.createTextNode('A specific user'));
   352             note.appendChild(a2);
   364             note.appendChild(a2);
   353             document.getElementById(aclManagerID + '_main').insertBefore(note, document.getElementById(aclManagerID + '_main').firstChild);
   365             document.getElementById(aclManagerID + '_main').insertBefore(note, document.getElementById(aclManagerID + '_main').firstChild);
   354             if(!document.getElementById(aclManagerID+'_deletelnk'))
   366             if(!document.getElementById(aclManagerID+'_deletelnk'))
   355               document.getElementById(aclManagerID + '_main').innerHTML += '<p id="'+aclManagerID+'_deletelnk" style="text-align: right;"><a href="#delete_acl_rule" onclick="if(confirm(\'Do you really want to delete this rule?\')) __aclDeleteRule(); return false;" style="color: red;">Delete this rule</a></p>';
   367               document.getElementById(aclManagerID + '_main').innerHTML += '<p id="'+aclManagerID+'_deletelnk" style="text-align: right;"><a href="#delete_acl_rule" onclick="if(confirm(\'Do you really want to delete this rule?\')) __aclDeleteRule(); return false;" style="color: red;">Delete this rule</a></p>';
   356             //fadeInfoBoxes();
   368             //fadeInfoBoxes();
       
   369             document.getElementById(aclManagerID+'_main').scrollTop = 0;
   357             break;
   370             break;
   358           case 'delete':
   371           case 'delete':
   359             
   372             
   360             params = {
   373             params = {
   361               'mode' : 'listgroups'
   374               'mode' : 'listgroups'
   515 function killACLManager()
   528 function killACLManager()
   516 {
   529 {
   517   el = document.getElementById(aclManagerID);
   530   el = document.getElementById(aclManagerID);
   518   if(el)
   531   if(el)
   519   {
   532   {
   520     el.parentNode.removeChild(el);
   533     opacity(aclManagerID, 100, 0, 500);
   521     enlighten();
   534     setTimeout('var el = document.getElementById(aclManagerID); el.parentNode.removeChild(el); enlighten();', 750);
   522   }
   535   }
   523 }
   536 }
   524 
   537 
   525 function __aclSubmitManager(form)
   538 function __aclSubmitManager(form)
   526 {
   539 {
   538   {
   551   {
   539     case 'cant_get':
   552     case 'cant_get':
   540       alert('BUG: can\'t get the state value from the form field.');
   553       alert('BUG: can\'t get the state value from the form field.');
   541       break;
   554       break;
   542     case 'seltarget':
   555     case 'seltarget':
   543       var target_type = parseInt(getRadioState(thefrm, 'target_type'));
   556       var target_type = parseInt(getRadioState(thefrm, 'target_type', ['1', '2']));
   544       if(isNaN(target_type))
   557       if(isNaN(target_type))
   545       {
   558       {
   546         alert('Please select a target type.');
   559         alert('Please select a target type.');
   547         return false;
   560         return false;
   548       }
   561       }
   553       thispage = strToPageID(title);
   566       thispage = strToPageID(title);
   554       do_scopesel = ( thispage[0] == aclDataCache.page_id && thispage[1] == aclDataCache.namespace );
   567       do_scopesel = ( thispage[0] == aclDataCache.page_id && thispage[1] == aclDataCache.namespace );
   555       
   568       
   556       if(do_scopesel)
   569       if(do_scopesel)
   557       {
   570       {
   558         scope = getRadioState(thefrm, 'scope');
   571         scope = getRadioState(thefrm, 'scope', ['page', 'global']);
   559         if(scope == 'page')
   572         if(scope == 'page')
   560         {
   573         {
   561           pageid = strToPageID(title);
   574           pageid = strToPageID(title);
   562           obj['page_id'] = pageid[0];
   575           obj['page_id'] = pageid[0];
   563           obj['namespace'] = pageid[1];
   576           obj['namespace'] = pageid[1];
   587       break;
   600       break;
   588     case 'save_edit':
   601     case 'save_edit':
   589     case 'save_new':
   602     case 'save_new':
   590       var form = document.forms[aclManagerID + '_formobj'];
   603       var form = document.forms[aclManagerID + '_formobj'];
   591       selections = new Object();
   604       selections = new Object();
       
   605       var dbg = '';
   592       for(var i in aclPermList)
   606       for(var i in aclPermList)
   593       {
   607       {
   594         if(i != 'toJSONString' && i != aclPermList.length-1)
   608         selections[aclPermList[i]] = getRadioState(form, aclPermList[i], [1, 2, 3, 4]);
   595         {
   609         dbg += aclPermList[i] + ': ' + selections[aclPermList[i]] + "\n";
   596           selections[aclPermList[i]] = getRadioState(form, aclPermList[i]);
   610         if(!selections[aclPermList[i]])
   597           if(!selections[aclPermList[i]])
   611         {
   598           {
   612           alert("Invalid return from getRadioState: "+i+": "+selections[i]+" ("+typeof(selections[i])+")");
   599             alert("Invalid return from getRadioState: "+i+": "+selections[i]+" ("+typeof(selections[i])+")");
   613           return false;
   600             return false;
       
   601           }
       
   602         }
   614         }
   603       }
   615       }
   604       obj = new Object();
   616       obj = new Object();
   605       obj['perms'] = selections;
   617       obj['perms'] = selections;
   606       obj['mode'] = mode;
   618       obj['mode'] = mode;
   616       return false;
   628       return false;
   617       break;
   629       break;
   618   }
   630   }
   619 }
   631 }
   620 
   632 
   621 function getRadioState(form, name)
   633 function getRadioState(form, name, valArray)
   622 {
   634 {
       
   635   // Konqueror/Safari fix
       
   636   if ( form[name] )
       
   637   {
       
   638     var formitem = form[name];
       
   639     if ( String(formitem) == '[object DOMNamedNodesCollection]' || is_Safari )
       
   640     {
       
   641       var i = 0;
       
   642       var radios = new Array();
       
   643       var radioids = new Array();
       
   644       while(true)
       
   645       {
       
   646         var elem = formitem[i];
       
   647         if ( !elem )
       
   648           break;
       
   649         radios.push(elem);
       
   650         if ( !elem.id )
       
   651         {
       
   652           elem.id = 'autoRadioBtn_' + Math.floor(Math.random() * 1000000);
       
   653         }
       
   654         radioids.push(elem.id);
       
   655         i++;
       
   656       }
       
   657       var cr;
       
   658       for ( var i = 0; i < radios.length; i++ )
       
   659       {
       
   660         cr = document.getElementById(radioids[i]);
       
   661         if ( cr.value == 'on' || cr.checked == true )
       
   662         {
       
   663           try {
       
   664             return ( typeof ( valArray[i] ) != 'undefined' ) ? valArray[i] : false;
       
   665           } catch(e) {
       
   666             // alert('Didn\'t get value for index: ' + i);
       
   667             return false;
       
   668           }
       
   669         }
       
   670       }
       
   671       return false;
       
   672     }
       
   673   }
   623   inputs = form.getElementsByTagName('input');
   674   inputs = form.getElementsByTagName('input');
   624   radios = new Array();
   675   radios = new Array();
   625   for(var i in inputs)
   676   for(var i in inputs)
   626   {
   677   {
   627     if(inputs[i]) if(inputs[i].type == 'radio')
   678     if(inputs[i]) if(inputs[i].type == 'radio')
   633       return radios[i].value;
   684       return radios[i].value;
   634   }
   685   }
   635   return false;
   686   return false;
   636 }
   687 }
   637 
   688 
   638 function __aclSetAllRadios(val)
   689 function __aclSetAllRadios(val, valArray)
   639 {
   690 {
   640   val = val+'';
   691   val = String(val);
   641   form = document.forms[aclManagerID + '_formobj'];
   692   var form = document.forms[aclManagerID + '_formobj'];
   642   if (!form)
   693   if (!form)
       
   694   {
   643     return false;
   695     return false;
   644   inputs = form.getElementsByTagName('input');
   696   }
   645   radios = new Array();
   697   var inputs = form.getElementsByTagName('input');
   646   for(var i in inputs)
   698   var radios = new Array();
   647   {
   699   var dbg = '';
       
   700   for(var i = 0; i < inputs.length; i++)
       
   701   {
       
   702     dbg += String(inputs[i]) + "\n";
   648     if(inputs[i].type == 'radio')
   703     if(inputs[i].type == 'radio')
   649       radios.push(inputs[i]);
   704       radios.push(inputs[i]);
   650   }
   705   }
   651   for(var i in radios)
   706   for(var i in radios)
   652   {
   707   {