includes/clientside/static/acl.js
changeset 512 13532b0a223f
parent 511 f88c8c79d784
child 513 c15fbf197a54
equal deleted inserted replaced
511:f88c8c79d784 512:13532b0a223f
    32         {
    32         {
    33           handle_invalid_json(ajax.responseText);
    33           handle_invalid_json(ajax.responseText);
    34           return false;
    34           return false;
    35         }
    35         }
    36         try {
    36         try {
    37           data = parseJSON(ajax.responseText);
    37           var groups = parseJSON(ajax.responseText);
    38         } catch(e) {
    38         } catch(e) {
    39           handle_invalid_json(ajax.responseText);
    39           handle_invalid_json(ajax.responseText);
    40         }
    40         }
    41         __aclBuildWizardWindow();
    41         __aclBuildWizardWindow();
    42         groups = parseJSON(ajax.responseText);
       
    43         if ( groups.mode == 'error' )
    42         if ( groups.mode == 'error' )
    44         {
    43         {
    45           alert(groups.error);
    44           alert(groups.error);
    46           killACLManager();
    45           killACLManager();
    47           return false;
    46           return false;
    49         aclDataCache = groups;
    48         aclDataCache = groups;
    50         __aclBuildSelector(groups);
    49         __aclBuildSelector(groups);
    51       }
    50       }
    52     }, true);
    51     }, true);
    53   return false;
    52   return false;
       
    53 }
       
    54 
       
    55 function ajaxOpenDirectACLRule(rule_id)
       
    56 {
       
    57   var params = {
       
    58     target_id: rule_id,
       
    59     mode: 'seltarget_id'
       
    60   };
       
    61   params = ajaxEscape(toJSONString(params));
       
    62   ajaxPost(stdAjaxPrefix+'&_mode=acljson', 'acl_params='+params, function() {
       
    63       if ( ajax.readyState == 4 && ajax.status == 200 )
       
    64       {
       
    65         var response = String(ajax.responseText + '');
       
    66         if ( response.substr(0, 1) != '{' )
       
    67         {
       
    68           handle_invalid_json(ajax.responseText);
       
    69           return false;
       
    70         }
       
    71         try
       
    72         {
       
    73           response = parseJSON(response);
       
    74         }
       
    75         catch(e)
       
    76         {
       
    77           handle_invalid_json(response);
       
    78         }
       
    79         if ( !document.getElementById(aclManagerID) )
       
    80         {
       
    81           __aclBuildWizardWindow();
       
    82         }
       
    83         if ( response.mode == 'error' )
       
    84         {
       
    85           alert(response.error);
       
    86           killACLManager();
       
    87           return false;
       
    88         }
       
    89         aclDataCache = response;
       
    90         aclBuildRuleEditor(response);
       
    91       }
       
    92     }, true);
    54 }
    93 }
    55 
    94 
    56 function ajaxACLSwitchToSelector()
    95 function ajaxACLSwitchToSelector()
    57 {
    96 {
    58   params = {
    97   params = {
   333         switch(data.mode)
   372         switch(data.mode)
   334         {
   373         {
   335           case 'seltarget':
   374           case 'seltarget':
   336             
   375             
   337             // Build the ACL edit form
   376             // Build the ACL edit form
   338             // try {
   377             aclBuildRuleEditor(data);
   339             
       
   340               var act_desc = ( data.type == 'new' ) ? $lang.get('acl_lbl_editwin_title_create') : $lang.get('acl_lbl_editwin_title_edit');
       
   341               var target_type_t = ( data.target_type == 1 ) ? $lang.get('acl_target_type_group') : $lang.get('acl_target_type_user');
       
   342               var target_name_t = data.target_name;
       
   343               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');
       
   344               
       
   345               html = '<h2>'+act_desc+'</h2>';
       
   346               html += '<p>' + $lang.get('acl_lbl_editwin_body', { target_type: target_type_t, target: target_name_t, scope_type: scope_type }) + '</p>';
       
   347               parser = new templateParser(data.template.acl_field_begin);
       
   348               html += parser.run();
       
   349               
       
   350               cls = 'row2';
       
   351               for(var i in data.acl_types)
       
   352               {
       
   353                 if(typeof(data.acl_types[i]) == 'number')
       
   354                 {
       
   355                   cls = ( cls == 'row1' ) ? 'row2' : 'row1';
       
   356                   p = new templateParser(data.template.acl_field_item);
       
   357                   vars = new Object();
       
   358                   if ( data.acl_descs[i].match(/^([a-z0-9_]+)$/) )
       
   359                   {
       
   360                     vars['FIELD_DESC'] = $lang.get(data.acl_descs[i]);
       
   361                   }
       
   362                   else
       
   363                   {
       
   364                     vars['FIELD_DESC'] = data.acl_descs[i];
       
   365                   }
       
   366                   vars['FIELD_INHERIT_CHECKED'] = '';
       
   367                   vars['FIELD_DENY_CHECKED'] = '';
       
   368                   vars['FIELD_DISALLOW_CHECKED'] = '';
       
   369                   vars['FIELD_WIKIMODE_CHECKED'] = '';
       
   370                   vars['FIELD_ALLOW_CHECKED'] = '';
       
   371                   vars['FIELD_NAME'] = i;
       
   372                   if ( !data.current_perms[i] )
       
   373                   {
       
   374                     data.current_perms[i] = 'i';
       
   375                   }
       
   376                   switch(data.current_perms[i])
       
   377                   {
       
   378                     case 'i':
       
   379                     default:
       
   380                       vars['FIELD_INHERIT_CHECKED'] = 'checked="checked"';
       
   381                       break;
       
   382                     case 1:
       
   383                       vars['FIELD_DENY_CHECKED'] = 'checked="checked"';
       
   384                       break;
       
   385                     case 2:
       
   386                       vars['FIELD_DISALLOW_CHECKED'] = 'checked="checked"';
       
   387                       break;
       
   388                     case 3:
       
   389                       vars['FIELD_WIKIMODE_CHECKED'] = 'checked="checked"';
       
   390                       break;
       
   391                     case 4:
       
   392                       vars['FIELD_ALLOW_CHECKED'] = 'checked="checked"';
       
   393                       break;
       
   394                   }
       
   395                   vars['ROW_CLASS'] = cls;
       
   396                   p.assign_vars(vars);
       
   397                   html += p.run();
       
   398                 }
       
   399               }
       
   400               
       
   401               var parser = new templateParser(data.template.acl_field_end);
       
   402               html += parser.run();
       
   403               
       
   404               if(data.type == 'edit')
       
   405                 html += '<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>';
       
   406               
       
   407               var main = document.getElementById(aclManagerID + '_main');
       
   408               main.innerHTML = html;
       
   409               
       
   410               var form = document.getElementById(aclManagerID + '_formobj_id');
       
   411               
       
   412               var modeobj = form_fetch_field(form, 'mode');
       
   413               if ( modeobj )
       
   414                 modeobj.value = 'save_' + data.type;
       
   415               else
       
   416                 alert('modeobj is invalid: '+modeobj);
       
   417               
       
   418               aclPermList = array_keys(data.acl_types);
       
   419               
       
   420               document.getElementById(aclManagerID + '_back').style.display = 'inline';
       
   421               document.getElementById(aclManagerID + '_next').value = $lang.get('etc_save_changes');
       
   422               
       
   423             // } catch(e) { alert(e); aclDebug(ajax.responseText); }
       
   424             
   378             
   425             break;
   379             break;
   426           case 'success':
   380           case 'success':
   427             var note = document.createElement('div');
   381             var note = document.createElement('div');
   428             note.className = 'info-box';
   382             note.className = 'info-box';
   528         }
   482         }
   529       }
   483       }
   530     }, true);
   484     }, true);
   531 }
   485 }
   532 
   486 
       
   487 function aclBuildRuleEditor(data)
       
   488 {
       
   489   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');
       
   491   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');
       
   493   
       
   494   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>';
       
   496   parser = new templateParser(data.template.acl_field_begin);
       
   497   html += parser.run();
       
   498   
       
   499   cls = 'row2';
       
   500   for(var i in data.acl_types)
       
   501   {
       
   502     if(typeof(data.acl_types[i]) == 'number')
       
   503     {
       
   504       cls = ( cls == 'row1' ) ? 'row2' : 'row1';
       
   505       p = new templateParser(data.template.acl_field_item);
       
   506       vars = new Object();
       
   507       if ( data.acl_descs[i].match(/^([a-z0-9_]+)$/) )
       
   508       {
       
   509         vars['FIELD_DESC'] = $lang.get(data.acl_descs[i]);
       
   510       }
       
   511       else
       
   512       {
       
   513         vars['FIELD_DESC'] = data.acl_descs[i];
       
   514       }
       
   515       vars['FIELD_INHERIT_CHECKED'] = '';
       
   516       vars['FIELD_DENY_CHECKED'] = '';
       
   517       vars['FIELD_DISALLOW_CHECKED'] = '';
       
   518       vars['FIELD_WIKIMODE_CHECKED'] = '';
       
   519       vars['FIELD_ALLOW_CHECKED'] = '';
       
   520       vars['FIELD_NAME'] = i;
       
   521       if ( !data.current_perms[i] )
       
   522       {
       
   523         data.current_perms[i] = 'i';
       
   524       }
       
   525       switch(data.current_perms[i])
       
   526       {
       
   527         case 'i':
       
   528         default:
       
   529           vars['FIELD_INHERIT_CHECKED'] = 'checked="checked"';
       
   530           break;
       
   531         case 1:
       
   532           vars['FIELD_DENY_CHECKED'] = 'checked="checked"';
       
   533           break;
       
   534         case 2:
       
   535           vars['FIELD_DISALLOW_CHECKED'] = 'checked="checked"';
       
   536           break;
       
   537         case 3:
       
   538           vars['FIELD_WIKIMODE_CHECKED'] = 'checked="checked"';
       
   539           break;
       
   540         case 4:
       
   541           vars['FIELD_ALLOW_CHECKED'] = 'checked="checked"';
       
   542           break;
       
   543       }
       
   544       vars['ROW_CLASS'] = cls;
       
   545       p.assign_vars(vars);
       
   546       html += p.run();
       
   547     }
       
   548   }
       
   549   
       
   550   var parser = new templateParser(data.template.acl_field_end);
       
   551   html += parser.run();
       
   552   
       
   553   if(data.type == 'edit')
       
   554     html += '<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>';
       
   555   
       
   556   var main = document.getElementById(aclManagerID + '_main');
       
   557   main.innerHTML = html;
       
   558   
       
   559   var form = document.getElementById(aclManagerID + '_formobj_id');
       
   560   
       
   561   var modeobj = form_fetch_field(form, 'mode');
       
   562   if ( modeobj )
       
   563     modeobj.value = 'save_' + data.type;
       
   564   else
       
   565     alert('modeobj is invalid: '+modeobj);
       
   566   
       
   567   aclPermList = array_keys(data.acl_types);
       
   568   
       
   569   document.getElementById(aclManagerID + '_back').style.display = 'inline';
       
   570   document.getElementById(aclManagerID + '_next').value = $lang.get('etc_save_changes');
       
   571 }
       
   572 
   533 function __aclBuildGroupsHTML(groups)
   573 function __aclBuildGroupsHTML(groups)
   534 {
   574 {
   535   groups = groups.groups;
   575   groups = groups.groups;
   536   select = document.createElement('select');
   576   select = document.createElement('select');
   537   for(var i in groups)
   577   for(var i in groups)