[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/adm/style/ -> permissions.js (source)

   1  /**
   2  * Hide and show all checkboxes
   3  * status = true (show boxes), false (hide boxes)
   4  */
   5  function display_checkboxes(status) 
   6  {
   7      var form = document.getElementById('set-permissions');
   8      var cb = document.getElementsByTagName('input');
   9      var display;
  10  
  11      //show
  12      if (status)
  13      {
  14          display = 'inline';
  15      }
  16      //hide
  17      else
  18      {
  19          display = 'none';
  20      }
  21      
  22      for (var i = 0; i < cb.length; i++ )
  23      {
  24          if (cb[i].className == 'permissions-checkbox')
  25          {
  26              cb[i].style.display = display;
  27          }
  28          
  29      }    
  30      
  31  }
  32  
  33  
  34  /**
  35  * Change opacity of element
  36  * e = element
  37  * value = 0 (hidden) till 10 (fully visible)
  38  */
  39  function set_opacity(e, value) {
  40      e.style.opacity = value/10;
  41      
  42      //IE opacity currently turned off, because of its astronomical stupidity
  43      //e.style.filter = 'alpha(opacity=' + value*10 + ')';
  44  }
  45  
  46  /**
  47  * Reset the opacity and checkboxes
  48  * block_id = id of the element that needs to be toggled
  49  */
  50  function toggle_opacity(block_id) {
  51      var cb = document.getElementById('checkbox' + block_id);
  52      var fs = document.getElementById('perm' + block_id);
  53      
  54      if (cb.checked) 
  55      {
  56          set_opacity(fs, 5);
  57      } 
  58      else 
  59      {
  60          set_opacity(fs, 10);
  61      }
  62  }
  63  
  64  /**
  65  * Reset the opacity and checkboxes
  66  * value = 0 (checked) and 1 (unchecked)
  67  * except_id = id of the element not to hide
  68  */
  69  function reset_opacity(status, except_id) {
  70      var perm = document.getElementById('set-permissions');
  71      var fs = perm.getElementsByTagName('fieldset');
  72      var opacity = 5;
  73  
  74      if (status)
  75      {
  76          opacity = 10;    
  77      }
  78      
  79      for (var i = 0; i < fs.length; i++ )
  80      {
  81          if (fs[i].className != 'quick')
  82          {
  83              set_opacity(fs[i], opacity);
  84          }
  85      }
  86  
  87      if (typeof(except_id) != 'undefined')
  88      {
  89          set_opacity(document.getElementById('perm' + except_id), 10);
  90      }
  91  
  92      //reset checkboxes too
  93      marklist('set-permissions', 'inherit', !status);
  94  }
  95  
  96  
  97  /**
  98  * Check whether we have a full radiobutton row of true
  99  * index = offset for the row of inputs (0 == first row, 1 == second, 2 == third),
 100  * rb = array of radiobuttons
 101  */
 102  function get_radio_status(index, rb) 
 103  {
 104      for (var i = index; i < rb.length; i = i + 3 )
 105      {
 106          if (rb[i].checked != true)
 107          {
 108              if (i > index)
 109              {
 110                  //at least one is true, but not all (custom)
 111                  return 2;
 112              }
 113              //first one is not true
 114              return 0;
 115          }
 116      }
 117  
 118      // all radiobuttons true
 119      return 1;
 120  }
 121  
 122  /**
 123  * Set tab colours
 124  * id = panel the tab needs to be set for, 
 125  * init = initialising on open, 
 126  * quick = If no calculation needed, this contains the colour
 127  */
 128  function set_colours(id, init, quick)
 129  {
 130      var table = document.getElementById('table' + id);
 131      var tab = document.getElementById('tab' + id);
 132  
 133      if (typeof(quick) != 'undefined') 
 134      {
 135          tab.className = 'permissions-preset-' + quick + ' activetab';
 136          return;
 137      }
 138  
 139      var rb = table.getElementsByTagName('input');
 140      var colour = 'custom';
 141  
 142      var status = get_radio_status(0, rb);
 143  
 144      if (status == 1)
 145      {
 146          colour = 'yes';
 147      }
 148      else if (status == 0) 
 149      {
 150          // We move on to No
 151          status = get_radio_status(1, rb);
 152  
 153          if (status == 1)
 154          {
 155              colour = 'no';
 156          }
 157          else if (status == 0) 
 158          {
 159              // We move on to Never
 160              status = get_radio_status(2, rb);
 161  
 162              if (status == 1)
 163              {
 164                  colour = 'never';
 165              }
 166          }
 167      }
 168  
 169      if (init)
 170      {
 171          tab.className = 'permissions-preset-' + colour;
 172      }
 173      else
 174      {
 175          tab.className = 'permissions-preset-' + colour + ' activetab';
 176      }
 177  }
 178  
 179  /**
 180  * Initialise advanced tab colours on first load
 181  * block_id = block that is opened
 182  */
 183  function init_colours(block_id)
 184  {    
 185      var block = document.getElementById('advanced' + block_id);
 186      var panels = block.getElementsByTagName('div');
 187      var tab = document.getElementById('tab' + id);
 188  
 189      for (var i = 0; i < panels.length; i++)
 190      {
 191          if(panels[i].className == 'permissions-panel')
 192          {
 193              set_colours(panels[i].id.replace(/options/, ''), true);
 194          }
 195      }
 196  
 197      tab.className = tab.className + ' activetab';
 198  }
 199  
 200  /**
 201  * Show/hide option panels
 202  * value = suffix for ID to show
 203  * adv = we are opening advanced permissions
 204  * view = called from view permissions
 205  */
 206  function swap_options(pmask, fmask, cat, adv, view)
 207  {
 208      id = pmask + fmask + cat;
 209      active_option = active_pmask + active_fmask + active_cat;
 210  
 211      var    old_tab = document.getElementById('tab' + active_option);    
 212      var new_tab = document.getElementById('tab' + id);
 213      var adv_block = document.getElementById('advanced' + pmask + fmask);
 214  
 215      if (adv_block.style.display == 'block' && adv == true)
 216      {
 217          dE('advanced' + pmask + fmask, -1);
 218          reset_opacity(1);
 219          display_checkboxes(false);
 220          return;
 221      }
 222  
 223      // no need to set anything if we are clicking on the same tab again
 224      if (new_tab == old_tab && !adv)
 225      {
 226          return;
 227      }
 228  
 229      // init colours
 230      if (adv && (pmask + fmask) != (active_pmask + active_fmask))
 231      {
 232          init_colours(pmask + fmask);
 233          display_checkboxes(true);
 234          reset_opacity(1);
 235      } 
 236      else if (adv) 
 237      {
 238          //Checkbox might have been clicked, but we need full visibility
 239          display_checkboxes(true);
 240          reset_opacity(1);
 241      }
 242  
 243      // set active tab
 244      old_tab.className = old_tab.className.replace(/\ activetab/g, '');
 245      new_tab.className = new_tab.className + ' activetab';
 246  
 247      if (id == active_option && adv != true)
 248      {
 249          return;
 250      }
 251  
 252      dE('options' + active_option, -1);
 253      
 254      //hiding and showing the checkbox
 255      if (document.getElementById('checkbox' + active_pmask + active_fmask))
 256      {
 257          dE('checkbox' + pmask + fmask, -1);    
 258          
 259          if ((pmask + fmask) != (active_pmask + active_fmask))
 260          {
 261              document.getElementById('checkbox' + active_pmask + active_fmask).style.display = 'inline';
 262          }
 263      }
 264  
 265      if (!view)
 266      {
 267          dE('advanced' + active_pmask + active_fmask, -1);
 268      }
 269  
 270      if (!view)
 271      {
 272          dE('advanced' + pmask + fmask, 1);
 273      }
 274      dE('options' + id, 1);
 275  
 276      active_pmask = pmask;
 277      active_fmask = fmask;
 278      active_cat = cat;
 279  }
 280  
 281  /**
 282  * Mark all radio buttons in one panel
 283  * id = table ID container, s = status ['y'/'u'/'n']
 284  */
 285  function mark_options(id, s)
 286  {
 287      var t = document.getElementById(id);
 288  
 289      if (!t)
 290      {
 291          return;
 292      }
 293  
 294      var rb = t.getElementsByTagName('input');
 295  
 296      for (var r = 0; r < rb.length; r++)
 297      {
 298          if (rb[r].id.substr(rb[r].id.length-1) == s)
 299          {
 300              rb[r].checked = true;
 301          }
 302      }
 303  }
 304  
 305  function mark_one_option(id, field_name, s)
 306  {
 307      var t = document.getElementById(id);
 308  
 309      if (!t)
 310      {
 311          return;
 312      }
 313  
 314      var rb = t.getElementsByTagName('input');
 315  
 316      for (var r = 0; r < rb.length; r++)
 317      {
 318          if (rb[r].id.substr(rb[r].id.length-field_name.length-3, field_name.length) == field_name && rb[r].id.substr(rb[r].id.length-1) == s)
 319          {
 320              rb[r].checked = true;
 321          }
 322      }
 323  }
 324  
 325  /**
 326  * Reset role dropdown field to Select role... if an option gets changed
 327  */
 328  function reset_role(id)
 329  {
 330      var t = document.getElementById(id);
 331  
 332      if (!t)
 333      {
 334          return;
 335      }
 336  
 337      t.options[0].selected = true;
 338  }
 339  
 340  /**
 341  * Load role and set options accordingly
 342  */
 343  function set_role_settings(role_id, target_id)
 344  {
 345      settings = role_options[role_id];
 346  
 347      if (!settings)
 348      {
 349          return;
 350      }
 351  
 352      // Mark all options to no (unset) first...
 353      mark_options(target_id, 'u');
 354  
 355      for (var r in settings)
 356      {
 357          mark_one_option(target_id, r, (settings[r] == 1) ? 'y' : 'n');
 358      }
 359  }


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1