1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/adm/style/permissions.js Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,359 @@
1.4 +/**
1.5 +* Hide and show all checkboxes
1.6 +* status = true (show boxes), false (hide boxes)
1.7 +*/
1.8 +function display_checkboxes(status)
1.9 +{
1.10 + var form = document.getElementById('set-permissions');
1.11 + var cb = document.getElementsByTagName('input');
1.12 + var display;
1.13 +
1.14 + //show
1.15 + if (status)
1.16 + {
1.17 + display = 'inline';
1.18 + }
1.19 + //hide
1.20 + else
1.21 + {
1.22 + display = 'none';
1.23 + }
1.24 +
1.25 + for (var i = 0; i < cb.length; i++ )
1.26 + {
1.27 + if (cb[i].className == 'permissions-checkbox')
1.28 + {
1.29 + cb[i].style.display = display;
1.30 + }
1.31 +
1.32 + }
1.33 +
1.34 +}
1.35 +
1.36 +
1.37 +/**
1.38 +* Change opacity of element
1.39 +* e = element
1.40 +* value = 0 (hidden) till 10 (fully visible)
1.41 +*/
1.42 +function set_opacity(e, value) {
1.43 + e.style.opacity = value/10;
1.44 +
1.45 + //IE opacity currently turned off, because of its astronomical stupidity
1.46 + //e.style.filter = 'alpha(opacity=' + value*10 + ')';
1.47 +}
1.48 +
1.49 +/**
1.50 +* Reset the opacity and checkboxes
1.51 +* block_id = id of the element that needs to be toggled
1.52 +*/
1.53 +function toggle_opacity(block_id) {
1.54 + var cb = document.getElementById('checkbox' + block_id);
1.55 + var fs = document.getElementById('perm' + block_id);
1.56 +
1.57 + if (cb.checked)
1.58 + {
1.59 + set_opacity(fs, 5);
1.60 + }
1.61 + else
1.62 + {
1.63 + set_opacity(fs, 10);
1.64 + }
1.65 +}
1.66 +
1.67 +/**
1.68 +* Reset the opacity and checkboxes
1.69 +* value = 0 (checked) and 1 (unchecked)
1.70 +* except_id = id of the element not to hide
1.71 +*/
1.72 +function reset_opacity(status, except_id) {
1.73 + var perm = document.getElementById('set-permissions');
1.74 + var fs = perm.getElementsByTagName('fieldset');
1.75 + var opacity = 5;
1.76 +
1.77 + if (status)
1.78 + {
1.79 + opacity = 10;
1.80 + }
1.81 +
1.82 + for (var i = 0; i < fs.length; i++ )
1.83 + {
1.84 + if (fs[i].className != 'quick')
1.85 + {
1.86 + set_opacity(fs[i], opacity);
1.87 + }
1.88 + }
1.89 +
1.90 + if (typeof(except_id) != 'undefined')
1.91 + {
1.92 + set_opacity(document.getElementById('perm' + except_id), 10);
1.93 + }
1.94 +
1.95 + //reset checkboxes too
1.96 + marklist('set-permissions', 'inherit', !status);
1.97 +}
1.98 +
1.99 +
1.100 +/**
1.101 +* Check whether we have a full radiobutton row of true
1.102 +* index = offset for the row of inputs (0 == first row, 1 == second, 2 == third),
1.103 +* rb = array of radiobuttons
1.104 +*/
1.105 +function get_radio_status(index, rb)
1.106 +{
1.107 + for (var i = index; i < rb.length; i = i + 3 )
1.108 + {
1.109 + if (rb[i].checked != true)
1.110 + {
1.111 + if (i > index)
1.112 + {
1.113 + //at least one is true, but not all (custom)
1.114 + return 2;
1.115 + }
1.116 + //first one is not true
1.117 + return 0;
1.118 + }
1.119 + }
1.120 +
1.121 + // all radiobuttons true
1.122 + return 1;
1.123 +}
1.124 +
1.125 +/**
1.126 +* Set tab colours
1.127 +* id = panel the tab needs to be set for,
1.128 +* init = initialising on open,
1.129 +* quick = If no calculation needed, this contains the colour
1.130 +*/
1.131 +function set_colours(id, init, quick)
1.132 +{
1.133 + var table = document.getElementById('table' + id);
1.134 + var tab = document.getElementById('tab' + id);
1.135 +
1.136 + if (typeof(quick) != 'undefined')
1.137 + {
1.138 + tab.className = 'permissions-preset-' + quick + ' activetab';
1.139 + return;
1.140 + }
1.141 +
1.142 + var rb = table.getElementsByTagName('input');
1.143 + var colour = 'custom';
1.144 +
1.145 + var status = get_radio_status(0, rb);
1.146 +
1.147 + if (status == 1)
1.148 + {
1.149 + colour = 'yes';
1.150 + }
1.151 + else if (status == 0)
1.152 + {
1.153 + // We move on to No
1.154 + status = get_radio_status(1, rb);
1.155 +
1.156 + if (status == 1)
1.157 + {
1.158 + colour = 'no';
1.159 + }
1.160 + else if (status == 0)
1.161 + {
1.162 + // We move on to Never
1.163 + status = get_radio_status(2, rb);
1.164 +
1.165 + if (status == 1)
1.166 + {
1.167 + colour = 'never';
1.168 + }
1.169 + }
1.170 + }
1.171 +
1.172 + if (init)
1.173 + {
1.174 + tab.className = 'permissions-preset-' + colour;
1.175 + }
1.176 + else
1.177 + {
1.178 + tab.className = 'permissions-preset-' + colour + ' activetab';
1.179 + }
1.180 +}
1.181 +
1.182 +/**
1.183 +* Initialise advanced tab colours on first load
1.184 +* block_id = block that is opened
1.185 +*/
1.186 +function init_colours(block_id)
1.187 +{
1.188 + var block = document.getElementById('advanced' + block_id);
1.189 + var panels = block.getElementsByTagName('div');
1.190 + var tab = document.getElementById('tab' + id);
1.191 +
1.192 + for (var i = 0; i < panels.length; i++)
1.193 + {
1.194 + if(panels[i].className == 'permissions-panel')
1.195 + {
1.196 + set_colours(panels[i].id.replace(/options/, ''), true);
1.197 + }
1.198 + }
1.199 +
1.200 + tab.className = tab.className + ' activetab';
1.201 +}
1.202 +
1.203 +/**
1.204 +* Show/hide option panels
1.205 +* value = suffix for ID to show
1.206 +* adv = we are opening advanced permissions
1.207 +* view = called from view permissions
1.208 +*/
1.209 +function swap_options(pmask, fmask, cat, adv, view)
1.210 +{
1.211 + id = pmask + fmask + cat;
1.212 + active_option = active_pmask + active_fmask + active_cat;
1.213 +
1.214 + var old_tab = document.getElementById('tab' + active_option);
1.215 + var new_tab = document.getElementById('tab' + id);
1.216 + var adv_block = document.getElementById('advanced' + pmask + fmask);
1.217 +
1.218 + if (adv_block.style.display == 'block' && adv == true)
1.219 + {
1.220 + dE('advanced' + pmask + fmask, -1);
1.221 + reset_opacity(1);
1.222 + display_checkboxes(false);
1.223 + return;
1.224 + }
1.225 +
1.226 + // no need to set anything if we are clicking on the same tab again
1.227 + if (new_tab == old_tab && !adv)
1.228 + {
1.229 + return;
1.230 + }
1.231 +
1.232 + // init colours
1.233 + if (adv && (pmask + fmask) != (active_pmask + active_fmask))
1.234 + {
1.235 + init_colours(pmask + fmask);
1.236 + display_checkboxes(true);
1.237 + reset_opacity(1);
1.238 + }
1.239 + else if (adv)
1.240 + {
1.241 + //Checkbox might have been clicked, but we need full visibility
1.242 + display_checkboxes(true);
1.243 + reset_opacity(1);
1.244 + }
1.245 +
1.246 + // set active tab
1.247 + old_tab.className = old_tab.className.replace(/\ activetab/g, '');
1.248 + new_tab.className = new_tab.className + ' activetab';
1.249 +
1.250 + if (id == active_option && adv != true)
1.251 + {
1.252 + return;
1.253 + }
1.254 +
1.255 + dE('options' + active_option, -1);
1.256 +
1.257 + //hiding and showing the checkbox
1.258 + if (document.getElementById('checkbox' + active_pmask + active_fmask))
1.259 + {
1.260 + dE('checkbox' + pmask + fmask, -1);
1.261 +
1.262 + if ((pmask + fmask) != (active_pmask + active_fmask))
1.263 + {
1.264 + document.getElementById('checkbox' + active_pmask + active_fmask).style.display = 'inline';
1.265 + }
1.266 + }
1.267 +
1.268 + if (!view)
1.269 + {
1.270 + dE('advanced' + active_pmask + active_fmask, -1);
1.271 + }
1.272 +
1.273 + if (!view)
1.274 + {
1.275 + dE('advanced' + pmask + fmask, 1);
1.276 + }
1.277 + dE('options' + id, 1);
1.278 +
1.279 + active_pmask = pmask;
1.280 + active_fmask = fmask;
1.281 + active_cat = cat;
1.282 +}
1.283 +
1.284 +/**
1.285 +* Mark all radio buttons in one panel
1.286 +* id = table ID container, s = status ['y'/'u'/'n']
1.287 +*/
1.288 +function mark_options(id, s)
1.289 +{
1.290 + var t = document.getElementById(id);
1.291 +
1.292 + if (!t)
1.293 + {
1.294 + return;
1.295 + }
1.296 +
1.297 + var rb = t.getElementsByTagName('input');
1.298 +
1.299 + for (var r = 0; r < rb.length; r++)
1.300 + {
1.301 + if (rb[r].id.substr(rb[r].id.length-1) == s)
1.302 + {
1.303 + rb[r].checked = true;
1.304 + }
1.305 + }
1.306 +}
1.307 +
1.308 +function mark_one_option(id, field_name, s)
1.309 +{
1.310 + var t = document.getElementById(id);
1.311 +
1.312 + if (!t)
1.313 + {
1.314 + return;
1.315 + }
1.316 +
1.317 + var rb = t.getElementsByTagName('input');
1.318 +
1.319 + for (var r = 0; r < rb.length; r++)
1.320 + {
1.321 + 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)
1.322 + {
1.323 + rb[r].checked = true;
1.324 + }
1.325 + }
1.326 +}
1.327 +
1.328 +/**
1.329 +* Reset role dropdown field to Select role... if an option gets changed
1.330 +*/
1.331 +function reset_role(id)
1.332 +{
1.333 + var t = document.getElementById(id);
1.334 +
1.335 + if (!t)
1.336 + {
1.337 + return;
1.338 + }
1.339 +
1.340 + t.options[0].selected = true;
1.341 +}
1.342 +
1.343 +/**
1.344 +* Load role and set options accordingly
1.345 +*/
1.346 +function set_role_settings(role_id, target_id)
1.347 +{
1.348 + settings = role_options[role_id];
1.349 +
1.350 + if (!settings)
1.351 + {
1.352 + return;
1.353 + }
1.354 +
1.355 + // Mark all options to no (unset) first...
1.356 + mark_options(target_id, 'u');
1.357 +
1.358 + for (var r in settings)
1.359 + {
1.360 + mark_one_option(target_id, r, (settings[r] == 1) ? 'y' : 'n');
1.361 + }
1.362 +}