includes/clientside/static/acl.js
changeset 513 c15fbf197a54
parent 512 13532b0a223f
child 535 b31eb2b6c137
equal deleted inserted replaced
512:13532b0a223f 513:c15fbf197a54
    77           handle_invalid_json(response);
    77           handle_invalid_json(response);
    78         }
    78         }
    79         if ( !document.getElementById(aclManagerID) )
    79         if ( !document.getElementById(aclManagerID) )
    80         {
    80         {
    81           __aclBuildWizardWindow();
    81           __aclBuildWizardWindow();
       
    82           var main = document.getElementById(aclManagerID + '_main');
       
    83           main.style.padding = '10px';
       
    84         }
       
    85         else
       
    86         {
       
    87           var main = document.getElementById(aclManagerID + '_main');
       
    88           main.style.backgroundImage = 'none';
    82         }
    89         }
    83         if ( response.mode == 'error' )
    90         if ( response.mode == 'error' )
    84         {
    91         {
    85           alert(response.error);
    92           alert(response.error);
    86           killACLManager();
    93           killACLManager();
    87           return false;
    94           return false;
    88         }
    95         }
    89         aclDataCache = response;
    96         aclDataCache = response;
    90         aclBuildRuleEditor(response);
    97         aclBuildRuleEditor(response, true);
    91       }
    98       }
    92     }, true);
    99     }, true);
    93 }
   100 }
    94 
   101 
    95 function ajaxACLSwitchToSelector()
   102 function ajaxACLSwitchToSelector()
   129 function __aclBuildSelector(groups)
   136 function __aclBuildSelector(groups)
   130 {
   137 {
   131   thispage = strToPageID(title);
   138   thispage = strToPageID(title);
   132   do_scopesel = ( thispage[0] == groups.page_id && thispage[1] == groups.namespace );
   139   do_scopesel = ( thispage[0] == groups.page_id && thispage[1] == groups.namespace );
   133   
   140   
       
   141   document.getElementById(aclManagerID + '_next').style.display = 'inline';
       
   142   
   134   seed = Math.floor(Math.random() * 1000000);
   143   seed = Math.floor(Math.random() * 1000000);
   135         
   144         
   136   main = document.getElementById(aclManagerID + '_main');
   145   main = document.getElementById(aclManagerID + '_main');
   137   main.style.padding = '10px';
   146   main.style.padding = '10px';
       
   147   main.style.backgroundImage = 'none';
       
   148   
       
   149   // the "edit existing" button
       
   150   var editbtn_wrapper = document.createElement('div');
       
   151   editbtn_wrapper.style.styleFloat = 'right';
       
   152   editbtn_wrapper.style.cssFloat = 'right';
       
   153   editbtn_wrapper.style.fontSize = 'smaller';
       
   154   var editbtn = document.createElement('a');
       
   155   editbtn.href = '#';
       
   156   editbtn.innerHTML = $lang.get('acl_btn_show_existing');
       
   157   editbtn_wrapper.appendChild(editbtn);
       
   158   main.appendChild(editbtn_wrapper);
       
   159   
       
   160   editbtn.onclick = function()
       
   161   {
       
   162     aclSetViewListExisting();
       
   163     return false;
       
   164   }
   138   
   165   
   139   selector = document.createElement('div');
   166   selector = document.createElement('div');
   140   
   167   
   141   grpsel = __aclBuildGroupsHTML(groups);
   168   grpsel = __aclBuildGroupsHTML(groups);
   142   grpsel.name = 'group_id';
   169   grpsel.name = 'group_id';
   361         if ( response.substr(0, 1) != '{' )
   388         if ( response.substr(0, 1) != '{' )
   362         {
   389         {
   363           handle_invalid_json(ajax.responseText);
   390           handle_invalid_json(ajax.responseText);
   364           return false;
   391           return false;
   365         }
   392         }
   366         try {
   393         try
   367           data = parseJSON(ajax.responseText);
   394         {
   368         } catch(e) {
   395           var data = parseJSON(ajax.responseText);
       
   396         }
       
   397         catch(e)
       
   398         {
   369           handle_invalid_json(ajax.responseText);
   399           handle_invalid_json(ajax.responseText);
       
   400           return false;
   370         }
   401         }
   371         aclDataCache = data;
   402         aclDataCache = data;
   372         switch(data.mode)
   403         switch(data.mode)
   373         {
   404         {
   374           case 'seltarget':
   405           case 'seltarget':
   418             
   449             
   419             if ( !document.getElementById(aclManagerID+'_deletelnk') )
   450             if ( !document.getElementById(aclManagerID+'_deletelnk') )
   420               document.getElementById(aclManagerID + '_main').innerHTML += '<p id="'+aclManagerID+'_deletelnk" style="text-align: right;"><a href="#delete_acl_rule" onclick="if(confirm(\'' + $lang.get('acl_msg_deleterule_confirm') + '\')) __aclDeleteRule(); return false;" style="color: red;">' + $lang.get('acl_lbl_deleterule') + '</a></p>';
   451               document.getElementById(aclManagerID + '_main').innerHTML += '<p id="'+aclManagerID+'_deletelnk" style="text-align: right;"><a href="#delete_acl_rule" onclick="if(confirm(\'' + $lang.get('acl_msg_deleterule_confirm') + '\')) __aclDeleteRule(); return false;" style="color: red;">' + $lang.get('acl_lbl_deleterule') + '</a></p>';
   421             
   452             
   422             document.getElementById(aclManagerID+'_main').scrollTop = 0;
   453             document.getElementById(aclManagerID+'_main').scrollTop = 0;
       
   454             document.getElementById(aclManagerID+'_main').style.backgroundImage = 'none';
   423                         
   455                         
   424             aclDataCache.mode = 'save_edit';
   456             aclDataCache.mode = 'save_edit';
   425             break;
   457             break;
   426           case 'delete':
   458           case 'delete':
   427             
   459             
   474             alert("Server side processing error:\n"+data.error);
   506             alert("Server side processing error:\n"+data.error);
   475             break;
   507             break;
   476           case 'debug':
   508           case 'debug':
   477             aclDebug(data.text);
   509             aclDebug(data.text);
   478             break;
   510             break;
       
   511           case 'list_existing':
       
   512             aclSetViewListExistingRespond(data);
       
   513             break;
   479           default:
   514           default:
   480             handle_invalid_json(ajax.responseText);
   515             handle_invalid_json(ajax.responseText);
   481             break;
   516             break;
   482         }
   517         }
   483       }
   518       }
   484     }, true);
   519     }, true);
   485 }
   520 }
   486 
   521 
   487 function aclBuildRuleEditor(data)
   522 function aclBuildRuleEditor(data, from_direct)
   488 {
   523 {
   489   var act_desc = ( data.type == 'new' ) ? $lang.get('acl_lbl_editwin_title_create') : $lang.get('acl_lbl_editwin_title_edit');
   524   var act_desc = ( data.type == 'new' ) ? $lang.get('acl_lbl_editwin_title_create') : $lang.get('acl_lbl_editwin_title_edit');
   490   var target_type_t = ( data.target_type == 1 ) ? $lang.get('acl_target_type_group') : $lang.get('acl_target_type_user');
   525   var target_type_t = ( data.target_type == 1 ) ? $lang.get('acl_target_type_group') : $lang.get('acl_target_type_user');
   491   var target_name_t = data.target_name;
   526   var target_name_t = data.target_name;
   492   var scope_type = ( data.page_id == false && data.namespace == false ) ? $lang.get('acl_scope_type_wholesite') : ( data.namespace == '__PageGroup' ) ? $lang.get('acl_scope_type_pagegroup') : $lang.get('acl_scope_type_thispage');
   527   var scope_type = ( data.page_id == false && data.namespace == false ) ? $lang.get('acl_scope_type_wholesite') : ( data.namespace == '__PageGroup' ) ? $lang.get('acl_scope_type_pagegroup') : $lang.get('acl_scope_type_thispage');
       
   528   
       
   529   document.getElementById(aclManagerID + '_next').style.display = 'inline';
   493   
   530   
   494   html = '<h2>'+act_desc+'</h2>';
   531   html = '<h2>'+act_desc+'</h2>';
   495   html += '<p>' + $lang.get('acl_lbl_editwin_body', { target_type: target_type_t, target: target_name_t, scope_type: scope_type }) + '</p>';
   532   html += '<p>' + $lang.get('acl_lbl_editwin_body', { target_type: target_type_t, target: target_name_t, scope_type: scope_type }) + '</p>';
   496   parser = new templateParser(data.template.acl_field_begin);
   533   parser = new templateParser(data.template.acl_field_begin);
   497   html += parser.run();
   534   html += parser.run();
   556   var main = document.getElementById(aclManagerID + '_main');
   593   var main = document.getElementById(aclManagerID + '_main');
   557   main.innerHTML = html;
   594   main.innerHTML = html;
   558   
   595   
   559   var form = document.getElementById(aclManagerID + '_formobj_id');
   596   var form = document.getElementById(aclManagerID + '_formobj_id');
   560   
   597   
   561   var modeobj = form_fetch_field(form, 'mode');
   598   if ( from_direct )
   562   if ( modeobj )
   599   {
   563     modeobj.value = 'save_' + data.type;
   600     var modeobj = document.getElementById(aclManagerID + '_mode');
       
   601     modeobj.value = 'save_edit';
       
   602   }
   564   else
   603   else
   565     alert('modeobj is invalid: '+modeobj);
   604   {
       
   605     var modeobj = form_fetch_field(form, 'mode');
       
   606     if ( modeobj )
       
   607       modeobj.value = 'save_' + data.type;
       
   608     else
       
   609       alert('modeobj is invalid: '+modeobj);
       
   610   }
   566   
   611   
   567   aclPermList = array_keys(data.acl_types);
   612   aclPermList = array_keys(data.acl_types);
   568   
   613   
   569   document.getElementById(aclManagerID + '_back').style.display = 'inline';
   614   document.getElementById(aclManagerID + '_back').style.display = 'inline';
   570   document.getElementById(aclManagerID + '_next').value = $lang.get('etc_save_changes');
   615   document.getElementById(aclManagerID + '_next').value = $lang.get('etc_save_changes');
   916     'mode' : 'delete'
   961     'mode' : 'delete'
   917   };
   962   };
   918   __aclJSONSubmitAjaxHandler(parms);
   963   __aclJSONSubmitAjaxHandler(parms);
   919 }
   964 }
   920 
   965 
       
   966 function aclSetViewListExisting()
       
   967 {
       
   968   if ( !document.getElementById(aclManagerID) )
       
   969   {
       
   970     return false;
       
   971   }
       
   972   
       
   973   var main = document.getElementById(aclManagerID + '_main');
       
   974   main.innerHTML = '';
       
   975   main.style.backgroundImage = 'url(' + scriptPath + '/images/loading-big.gif)';
       
   976   main.style.backgroundRepeat = 'no-repeat';
       
   977   main.style.backgroundPosition = 'center center';
       
   978   
       
   979   var parms = {
       
   980     'mode' : 'list_existing'
       
   981   };
       
   982   __aclJSONSubmitAjaxHandler(parms);
       
   983 }
       
   984 
       
   985 function aclSetViewListExistingRespond(data)
       
   986 {
       
   987   var main = document.getElementById(aclManagerID + '_main');
       
   988   main.style.padding = '10px';
       
   989   main.innerHTML = '';
       
   990   
       
   991   var heading = document.createElement('h3');
       
   992   heading.appendChild(document.createTextNode($lang.get('acl_msg_scale_intro_title')));
       
   993   main.appendChild(heading);
       
   994   
       
   995   var p = document.createElement('p');
       
   996   p.appendChild(document.createTextNode($lang.get('acl_msg_scale_intro_body')));
       
   997   main.appendChild(p);
       
   998   
       
   999   
       
  1000   main.innerHTML += data.key;
       
  1001   main.style.backgroundImage = 'none';
       
  1002   
       
  1003   document.getElementById(aclManagerID + '_back').style.display = 'inline';
       
  1004   document.getElementById(aclManagerID + '_next').style.display = 'none';
       
  1005   
       
  1006   for ( var i = 0; i < data.rules.length; i++ )
       
  1007   {
       
  1008     var rule = data.rules[i];
       
  1009     // build the rule, this is just more boring DOM crap.
       
  1010     var div = document.createElement('div');
       
  1011     div.style.padding = '5px 3px';
       
  1012     div.style.backgroundColor = '#' + rule.color;
       
  1013     div.style.cursor = 'pointer';
       
  1014     div.rule_id = rule.rule_id;
       
  1015     div.onclick = function()
       
  1016     {
       
  1017       var main = document.getElementById(aclManagerID + '_main');
       
  1018       main.innerHTML = '';
       
  1019       main.style.backgroundImage = 'url(' + scriptPath + '/images/loading-big.gif)';
       
  1020       ajaxOpenDirectACLRule(parseInt(this.rule_id));
       
  1021     }
       
  1022     div.innerHTML = rule.score_string;
       
  1023     main.appendChild(div);
       
  1024   }
       
  1025 }
       
  1026 
   921 function array_keys(obj)
  1027 function array_keys(obj)
   922 {
  1028 {
   923   keys = new Array();
  1029   keys = new Array();
   924   for(var i in obj)
  1030   for(var i in obj)
   925     keys.push(i);
  1031     keys.push(i);