includes/clientside/static/acl.js
changeset 729 ebac7eeb89eb
parent 694 43367c66d869
child 730 b09cb1dab505
equal deleted inserted replaced
728:067a6173820c 729:ebac7eeb89eb
   163   editbtn_wrapper.style.fontSize = 'smaller';
   163   editbtn_wrapper.style.fontSize = 'smaller';
   164   var editbtn = document.createElement('a');
   164   var editbtn = document.createElement('a');
   165   editbtn.href = '#';
   165   editbtn.href = '#';
   166   editbtn.innerHTML = $lang.get('acl_btn_show_existing');
   166   editbtn.innerHTML = $lang.get('acl_btn_show_existing');
   167   editbtn_wrapper.appendChild(editbtn);
   167   editbtn_wrapper.appendChild(editbtn);
       
   168   
       
   169   // tracer button
       
   170   var tracebtn = document.createElement('a');
       
   171   tracebtn.href = '#';
       
   172   tracebtn.innerHTML = $lang.get('acl_btn_view_effective');
       
   173   editbtn_wrapper.appendChild(document.createElement('br'));
       
   174   editbtn_wrapper.appendChild(tracebtn);
       
   175   
   168   main.appendChild(editbtn_wrapper);
   176   main.appendChild(editbtn_wrapper);
   169   
   177   
   170   editbtn.onclick = function()
   178   editbtn.onclick = function()
   171   {
   179   {
   172     aclSetViewListExisting();
   180     aclSetViewListExisting();
       
   181     return false;
       
   182   }
       
   183   
       
   184   tracebtn.onclick = function()
       
   185   {
       
   186     aclSetViewDebugTools();
   173     return false;
   187     return false;
   174   }
   188   }
   175   
   189   
   176   selector = document.createElement('div');
   190   selector = document.createElement('div');
   177   
   191   
   523             aclDebug(data.text);
   537             aclDebug(data.text);
   524             break;
   538             break;
   525           case 'list_existing':
   539           case 'list_existing':
   526             aclSetViewListExistingRespond(data);
   540             aclSetViewListExistingRespond(data);
   527             break;
   541             break;
       
   542           case 'trace':
       
   543             aclDrawTraceWrapper(data);
       
   544             break;
   528           default:
   545           default:
   529             handle_invalid_json(ajax.responseText);
   546             handle_invalid_json(ajax.responseText);
   530             break;
   547             break;
   531         }
   548         }
   532       }
   549       }
   656   return select;
   673   return select;
   657 }
   674 }
   658 
   675 
   659 function __aclBuildWizardWindow()
   676 function __aclBuildWizardWindow()
   660 {
   677 {
   661   darken(aclDisableTransitionFX);
   678   darken(aclDisableTransitionFX, 70, 'acldarkener');
   662   box = document.createElement('div');
   679   box = document.createElement('div');
   663   box.style.width = '640px'
   680   box.style.width = '640px'
   664   box.style.height = '440px';
   681   box.style.height = '440px';
   665   box.style.position = 'fixed';
   682   box.style.position = 'fixed';
   666   width = getWidth();
   683   width = getWidth();
   779   el = document.getElementById(aclManagerID);
   796   el = document.getElementById(aclManagerID);
   780   if(el)
   797   if(el)
   781   {
   798   {
   782     if ( aclDisableTransitionFX )
   799     if ( aclDisableTransitionFX )
   783     {
   800     {
   784       enlighten(true);
   801       enlighten(true, 'acldarkener');
   785       el.parentNode.removeChild(el);
   802       el.parentNode.removeChild(el);
   786     }
   803     }
   787     else
   804     else
   788     {
   805     {
   789       opacity(aclManagerID, 100, 0, 500);
   806       opacity(aclManagerID, 100, 0, 500);
   790       setTimeout('var el = document.getElementById(aclManagerID); el.parentNode.removeChild(el); enlighten();', 750);
   807       setTimeout('var el = document.getElementById(aclManagerID); el.parentNode.removeChild(el); enlighten(false, "acldarkener");', 750);
   791     }
   808     }
   792   }
   809   }
   793 }
   810 }
   794 
   811 
   795 function __aclSubmitManager(form)
   812 function __aclSubmitManager(form)
   894       obj['target_name'] = aclDataCache.target_name;
   911       obj['target_name'] = aclDataCache.target_name;
   895       obj['page_id'] = aclDataCache.page_id;
   912       obj['page_id'] = aclDataCache.page_id;
   896       obj['namespace'] = aclDataCache.namespace;
   913       obj['namespace'] = aclDataCache.namespace;
   897       __aclJSONSubmitAjaxHandler(obj);
   914       __aclJSONSubmitAjaxHandler(obj);
   898       break;
   915       break;
       
   916     case 'trace':
       
   917       var params = {
       
   918         mode: 'trace',
       
   919         user: document.getElementById(aclManagerID + 'trace_user').value,
       
   920         page: document.getElementById(aclManagerID + 'trace_page').value
       
   921       };
       
   922       __aclJSONSubmitAjaxHandler(params);
       
   923       break;
   899     default:
   924     default:
   900       alert("JSON form submit: invalid mode string "+mode+", stopping execution");
   925       alert("JSON form submit: invalid mode string "+mode+", stopping execution");
   901       return false;
   926       return false;
   902       break;
   927       break;
   903   }
   928   }
  1071       ajaxOpenDirectACLRule(parseInt(this.rule_id));
  1096       ajaxOpenDirectACLRule(parseInt(this.rule_id));
  1072     }
  1097     }
  1073     div.innerHTML = rule.score_string;
  1098     div.innerHTML = rule.score_string;
  1074     main.appendChild(div);
  1099     main.appendChild(div);
  1075   }
  1100   }
       
  1101 }
       
  1102 
       
  1103 function aclSetViewDebugTools()
       
  1104 {
       
  1105   // selection window for viewing effective permissions
       
  1106   var main = document.getElementById(aclManagerID + '_main');
       
  1107   main.innerHTML = '';
       
  1108  
       
  1109   // set the submission handler to trace
       
  1110   var thefrm = document.forms[form.name];
       
  1111   var modeobj = form_fetch_field(thefrm, 'mode');
       
  1112   modeobj.value = 'trace';
       
  1113   
       
  1114   // show the back button
       
  1115   document.getElementById(aclManagerID + '_back').style.display = 'inline';
       
  1116   
       
  1117   //
       
  1118   // start building
       
  1119   //
       
  1120   
       
  1121   // selection interface
       
  1122   var selector = document.createElement('div');
       
  1123   
       
  1124     var table = document.createElement('table');
       
  1125     
       
  1126     // username
       
  1127     var tr_user = document.createElement('tr');
       
  1128     var td_user_l = document.createElement('td');
       
  1129     var lbl_user = document.createElement('label');
       
  1130     lbl_user.setAttribute('for', aclManagerID + 'trace_user');
       
  1131     lbl_user.appendChild(document.createTextNode($lang.get('acl_lbl_trace_user')));
       
  1132     td_user_l.appendChild(lbl_user);
       
  1133     tr_user.appendChild(td_user_l);
       
  1134     
       
  1135     var td_user_i = document.createElement('td');
       
  1136     var i_user = document.createElement('input');
       
  1137     i_user.type = 'text';
       
  1138     i_user.id = aclManagerID + 'trace_user';
       
  1139     i_user.onkeyup = function() { new AutofillUsername(this); };
       
  1140     i_user.size = '20';
       
  1141     td_user_i.appendChild(i_user);
       
  1142     tr_user.appendChild(td_user_i);
       
  1143     
       
  1144     table.appendChild(tr_user);
       
  1145     
       
  1146     // page
       
  1147     var tr_page = document.createElement('tr');
       
  1148     var td_page_l = document.createElement('td');
       
  1149     var lbl_page = document.createElement('label');
       
  1150     lbl_page.setAttribute('for', aclManagerID + 'trace_page');
       
  1151     lbl_page.appendChild(document.createTextNode($lang.get('acl_lbl_trace_page')));
       
  1152     td_page_l.appendChild(lbl_page);
       
  1153     tr_page.appendChild(td_page_l);
       
  1154     
       
  1155     var td_page_i = document.createElement('td');
       
  1156     var i_page = document.createElement('input');
       
  1157     i_page.type = 'text';
       
  1158     i_page.id = aclManagerID + 'trace_page';
       
  1159     i_page.onkeyup = function() { new AutofillPage(this); };
       
  1160     i_page.size = '20';
       
  1161     td_page_i.appendChild(i_page);
       
  1162     tr_page.appendChild(td_page_i);
       
  1163     
       
  1164     table.appendChild(tr_page);
       
  1165     
       
  1166     selector.appendChild(table);
       
  1167   
       
  1168   // wrapper
       
  1169   
       
  1170   var container = document.createElement('div');
       
  1171   
       
  1172     container.style.margin = 'auto';
       
  1173     container.style.width = '360px';
       
  1174     container.style.paddingTop = '90px';
       
  1175     
       
  1176     var head = document.createElement('h2');
       
  1177     head.appendChild(document.createTextNode($lang.get('acl_lbl_trace_title')));
       
  1178     
       
  1179     var desc = document.createElement('p');
       
  1180     desc.innerHTML = $lang.get('acl_lbl_trace_body');
       
  1181     
       
  1182     container.appendChild(head);
       
  1183     container.appendChild(desc);
       
  1184     container.appendChild(selector);
       
  1185   
       
  1186   main.appendChild(container);
       
  1187 }
       
  1188 
       
  1189 function aclTraceKey()
       
  1190 {
       
  1191   var div = document.createElement('div');
       
  1192   $(div).addClass('tblholder');
       
  1193   var table = document.createElement('table');
       
  1194   $(table).attr('cellspacing', '1').attr('cellpadding', '4');
       
  1195   
       
  1196   var inherit_list = ['enano_default', 'global_everyone', 'global_group', 'global_user', 'pg_everyone', 'pg_group', 'pg_user', 'local_everyone', 'local_group', 'local_user'];
       
  1197   for ( var i = 0; i < inherit_list.length; i++ )
       
  1198   {
       
  1199     var t = inherit_list[i];
       
  1200     var tr = document.createElement('tr');
       
  1201     var td_key = document.createElement('td');
       
  1202     $(td_key).addClass('acl_' + t).addClass('acl_inherit_key');
       
  1203     tr.appendChild(td_key);
       
  1204     var td_explain = document.createElement('td');
       
  1205     $(td_explain).addClass(i % 2 == 0 ? 'row1' : 'row2');
       
  1206     td_explain.appendChild(document.createTextNode($lang.get('acl_inherit_key_' + t)));
       
  1207     tr.appendChild(td_explain);
       
  1208     table.appendChild(tr);
       
  1209   }
       
  1210   div.appendChild(table);
       
  1211   return div;
       
  1212 }
       
  1213 
       
  1214 function aclTraceModalKey()
       
  1215 {
       
  1216   load_component('messagebox');
       
  1217   miniPrompt(function(parent)
       
  1218     {
       
  1219       // heading
       
  1220       var h3 = document.createElement('h3');
       
  1221       h3.appendChild(document.createTextNode($lang.get('acl_msg_trace_key')));
       
  1222       parent.appendChild(h3);
       
  1223       
       
  1224       var key = aclTraceKey();
       
  1225       parent.appendChild(key);
       
  1226       
       
  1227       var p = document.createElement('p');
       
  1228       $(p).css('text-align', 'center');
       
  1229       
       
  1230       var closer = document.createElement('a');
       
  1231       $(closer).addClass('abutton').addClass('abutton_red').css('font-weight', 'bold');
       
  1232       closer.appendChild(document.createTextNode($lang.get('etc_close')));
       
  1233       closer.href = '#';
       
  1234       $(closer).click(function(e)
       
  1235         {
       
  1236           miniPromptDestroy(this);
       
  1237           return false;
       
  1238         });
       
  1239       
       
  1240       p.appendChild(closer);
       
  1241       parent.appendChild(p);
       
  1242     });
       
  1243 }
       
  1244 
       
  1245 function aclDrawTraceWrapper(data)
       
  1246 {
       
  1247   var trace_by_perm = aclDrawTraceByPerm(data);
       
  1248   var trace_by_rule = aclDrawTraceByRule(data);
       
  1249   
       
  1250   trace_by_perm.id = 'aclDebugTraceViewPerm';
       
  1251   trace_by_rule.id = 'aclDebugTraceViewRule';
       
  1252   
       
  1253   var start_with_rule = ( readCookie('acl_trace_view') == 'rule' );
       
  1254   
       
  1255   if ( start_with_rule )
       
  1256   {
       
  1257     trace_by_perm.style.display = 'none';
       
  1258   }
       
  1259   else
       
  1260   {
       
  1261     trace_by_rule.style.display = 'none';
       
  1262   }
       
  1263   
       
  1264   // selection window for viewing effective permissions
       
  1265   var main = document.getElementById(aclManagerID + '_main');
       
  1266   main.innerHTML = '';
       
  1267   
       
  1268   var wrapper = document.createElement('div');
       
  1269   $(wrapper).css('padding-bottom', '20px');
       
  1270   
       
  1271   var floatlink = document.createElement('div');
       
  1272   $(floatlink).css('float', 'right').css('margin-left', '20px').css('margin-bottom', '20px').css('text-align', 'right');
       
  1273   var a_toggle = document.createElement('a');
       
  1274   $(a_toggle).attr('id', 'aclDebugTraceViewToggle');
       
  1275   a_toggle.innerHTML = '&raquo; ';
       
  1276   a_toggle.innerHTML += start_with_rule ? $lang.get('acl_btn_sort_perm') : $lang.get('acl_btn_sort_rule');
       
  1277   a_toggle.href = '#';
       
  1278   floatlink.appendChild(a_toggle);
       
  1279   floatlink.appendChild(document.createElement('br'));
       
  1280   var a_key = document.createElement('a');
       
  1281   $(a_key).css('font-size', 'smaller');
       
  1282   a_key.innerHTML = '&raquo; ';
       
  1283   a_key.innerHTML += $lang.get('acl_btn_view_key');
       
  1284   a_key.href = '#';
       
  1285   floatlink.appendChild(a_key);
       
  1286   wrapper.appendChild(floatlink);
       
  1287   
       
  1288   var h3 = document.createElement('h3');
       
  1289   h3.appendChild(document.createTextNode($lang.get('acl_msg_debug_main_title')));
       
  1290   wrapper.appendChild(h3);
       
  1291   var p = document.createElement('p');
       
  1292   p.appendChild(document.createTextNode($lang.get('acl_msg_debug_main_body')));
       
  1293   wrapper.appendChild(p);
       
  1294   
       
  1295   wrapper.appendChild(trace_by_perm);
       
  1296   wrapper.appendChild(trace_by_rule);
       
  1297   
       
  1298   main.appendChild(wrapper);
       
  1299   
       
  1300   $(a_toggle).click(function(e)
       
  1301     {
       
  1302       aclTraceToggleViews();
       
  1303       return false;
       
  1304     });
       
  1305   
       
  1306   $(a_key).click(function(e)
       
  1307     {
       
  1308       aclTraceModalKey();
       
  1309       return false;
       
  1310     });
       
  1311 }
       
  1312 
       
  1313 function aclTraceToggleViews()
       
  1314 {
       
  1315   var trace_by_perm = document.getElementById('aclDebugTraceViewPerm');
       
  1316   var trace_by_rule = document.getElementById('aclDebugTraceViewRule');
       
  1317   
       
  1318   var toggler = document.getElementById('aclDebugTraceViewToggle');
       
  1319   var newtext;
       
  1320   
       
  1321   if ( trace_by_perm.style.display == 'none' )
       
  1322   {
       
  1323     newtext = $lang.get('acl_btn_sort_rule');
       
  1324     $(trace_by_rule).hide('blind', {}, 750, function()
       
  1325       {
       
  1326         $(trace_by_perm).show('blind', {}, 750);
       
  1327       });
       
  1328     createCookie('acl_trace_view', 'perm');
       
  1329   }
       
  1330   else
       
  1331   {
       
  1332     newtext = $lang.get('acl_btn_sort_perm');
       
  1333     $(trace_by_perm).hide('blind', {}, 750, function()
       
  1334       {
       
  1335         $(trace_by_rule).show('blind', {}, 750);
       
  1336       });
       
  1337     createCookie('acl_trace_view', 'rule');
       
  1338   }
       
  1339   $(toggler).fadeOut(500, function()
       
  1340     {
       
  1341       this.innerHTML = '&raquo; ' + newtext;
       
  1342       $(this).fadeIn(500);
       
  1343     });
       
  1344 }
       
  1345 
       
  1346 function aclDrawTraceByPerm(data)
       
  1347 {
       
  1348   var wrapper = document.createElement('div');
       
  1349   // wrapper.style.display = 'none';
       
  1350   
       
  1351   // temporarily append wrapper to body to allow onclick to work
       
  1352   // var body = document.getElementsByTagName('body')[0];
       
  1353   // body.appendChild(wrapper);  
       
  1354   
       
  1355   for ( var i in data.perms )
       
  1356   {
       
  1357     var perm = data.perms[i];
       
  1358     var item = document.createElement('div');
       
  1359     item.className = perm.divclass;
       
  1360     
       
  1361     // first row - permission name + current setting
       
  1362     // use innerHTML here to allow for HTML in localized permission types
       
  1363     item.innerHTML += '<b>' + perm.perm_name + ' - ' + perm.perm_value + '</b>';
       
  1364     item.appendChild(document.createElement('br'));
       
  1365     
       
  1366     // second row - permission localized name + rule ID
       
  1367     var sm = document.createElement('small');
       
  1368     sm.innerHTML = perm.perm_src;
       
  1369     
       
  1370     item.appendChild(sm);
       
  1371     
       
  1372     wrapper.appendChild(item);
       
  1373     
       
  1374     // whole row is now in the document
       
  1375     if ( perm.rule_id != -1 )
       
  1376     {
       
  1377       sm.innerHTML += ' [';
       
  1378       // rule is editable
       
  1379       var editlink = document.createElement('a');
       
  1380       editlink.href = 'javascript:ajaxOpenDirectACLRule(' + perm.rule_id + ');';
       
  1381       editlink.appendChild(document.createTextNode($lang.get('acl_btn_edit_rule')));
       
  1382       sm.appendChild(editlink);
       
  1383       sm.innerHTML += ']';
       
  1384     }
       
  1385   }
       
  1386   
       
  1387   // var ret = wrapper.cloneNode(true);
       
  1388   // body.removeChild(wrapper);
       
  1389   // wrapper = false;
       
  1390   // ret.style.display = 'block';
       
  1391   // console.debug(ret);
       
  1392   // return ret;
       
  1393   return wrapper;
       
  1394 }
       
  1395 
       
  1396 function aclDrawTraceByRule(data)
       
  1397 {
       
  1398   var wrapper = document.createElement('div');
       
  1399   var groupdata = {};
       
  1400   
       
  1401   for ( var i in data.perms )
       
  1402   {
       
  1403     var perm = data.perms[i];
       
  1404     if ( !groupdata[perm['rule_id']] )
       
  1405     {
       
  1406       groupdata[perm['rule_id']] = {
       
  1407         meta: {
       
  1408           divclass: perm.divclass,
       
  1409           perm_src: perm.perm_src,
       
  1410           rule_id: perm.rule_id
       
  1411         },
       
  1412         rules: {}
       
  1413       };
       
  1414     }
       
  1415     groupdata[perm['rule_id']]['rules'][i] = perm;
       
  1416   }
       
  1417   
       
  1418   console.debug('draw by rule - group data: ', groupdata);
       
  1419   
       
  1420   for ( var i in groupdata )
       
  1421   {
       
  1422     var group = groupdata[i];
       
  1423     var grp = document.createElement('div');
       
  1424     var head = document.createElement('div');
       
  1425     head.className = group.meta.divclass;
       
  1426     var span = document.createElement('span');
       
  1427     span.style.fontSize = 'larger';
       
  1428     span.appendChild(document.createTextNode(group.meta.perm_src));
       
  1429     head.appendChild(span);
       
  1430     if ( group.meta.rule_id != -1 )
       
  1431     {
       
  1432       head.innerHTML += ' [';
       
  1433       // rule is editable
       
  1434       var editlink = document.createElement('a');
       
  1435       editlink.href = 'javascript:ajaxOpenDirectACLRule(' + group.meta.rule_id + ');';
       
  1436       editlink.appendChild(document.createTextNode($lang.get('acl_btn_edit_rule')));
       
  1437       head.appendChild(editlink);
       
  1438       head.innerHTML += ']';
       
  1439     }
       
  1440     grp.appendChild(head);
       
  1441     for ( var i in group.rules )
       
  1442     {
       
  1443       var rule = group.rules[i];
       
  1444       var rulediv = document.createElement('div');
       
  1445       rulediv.style.padding = '3px 12px';
       
  1446       rulediv.innerHTML += rule.perm_name + ': ';
       
  1447       var b = document.createElement('strong');
       
  1448       b.appendChild(document.createTextNode(rule.perm_value));
       
  1449       rulediv.appendChild(b);
       
  1450       grp.appendChild(rulediv);
       
  1451     }
       
  1452     wrapper.appendChild(grp);
       
  1453   }
       
  1454   
       
  1455   return wrapper;
  1076 }
  1456 }
  1077 
  1457 
  1078 function aclShowPresetLoader()
  1458 function aclShowPresetLoader()
  1079 {
  1459 {
  1080   var prompt = miniPrompt(function(parent)
  1460   var prompt = miniPrompt(function(parent)