Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
permissions.js
001 /**
002 * Hide and show all checkboxes
003 * status = true (show boxes), false (hide boxes)
004 */
005 function display_checkboxes(status) {
006 var form = document.getElementById('set-permissions');
007 var cb = document.getElementsByTagName('input');
008 var display;
009
010 //show
011 if (status) {
012 display = 'inline';
013 }
014 //hide
015 else {
016 display = 'none';
017 }
018
019 for (var i = 0; i < cb.length; i++ ) {
020 if (cb[i].className === 'permissions-checkbox') {
021 cb[i].style.display = display;
022 }
023 }
024 }
025
026 /**
027 * Change opacity of element
028 * e = element
029 * value = 0 (hidden) till 10 (fully visible)
030 */
031 function set_opacity(e, value) {
032 e.style.opacity = value/10;
033
034 //IE opacity currently turned off, because of its astronomical stupidity
035 //e.style.filter = 'alpha(opacity=' + value*10 + ')';
036 }
037
038 /**
039 * Reset the opacity and checkboxes
040 * block_id = id of the element that needs to be toggled
041 */
042 function toggle_opacity(block_id) {
043 var cb = document.getElementById('checkbox' + block_id);
044 var fs = document.getElementById('perm' + block_id);
045
046 if (cb.checked) {
047 set_opacity(fs, 5);
048 } else {
049 set_opacity(fs, 10);
050 }
051 }
052
053 /**
054 * Reset the opacity and checkboxes
055 * value = 0 (checked) and 1 (unchecked)
056 * except_id = id of the element not to hide
057 */
058 function reset_opacity(status, except_id) {
059 var perm = document.getElementById('set-permissions');
060 var fs = perm.getElementsByTagName('fieldset');
061 var opacity = 5;
062
063 if (status) {
064 opacity = 10;
065 }
066
067 for (var i = 0; i < fs.length; i++ ) {
068 if (fs[i].className !== 'quick') {
069 set_opacity(fs[i], opacity);
070 }
071 }
072
073 if (typeof(except_id) !== 'undefined') {
074 set_opacity(document.getElementById('perm' + except_id), 10);
075 }
076
077 //reset checkboxes too
078 marklist('set-permissions', 'inherit', !status);
079 }
080
081 /**
082 * Check whether we have a full radiobutton row of true
083 * index = offset for the row of inputs (0 == first row, 1 == second, 2 == third),
084 * rb = array of radiobuttons
085 */
086 function get_radio_status(index, rb) {
087 for (var i = index; i < rb.length; i = i + 3 ) {
088 if (rb[i].checked !== true) {
089 if (i > index) {
090 //at least one is true, but not all (custom)
091 return 2;
092 }
093 //first one is not true
094 return 0;
095 }
096 }
097
098 // all radiobuttons true
099 return 1;
100 }
101
102 /**
103 * Set tab colours
104 * id = panel the tab needs to be set for,
105 * init = initialising on open,
106 * quick = If no calculation needed, this contains the colour
107 */
108 function set_colours(id, init, quick) {
109 var table = document.getElementById('table' + id);
110 var tab = document.getElementById('tab' + id);
111
112 if (typeof(quick) !== 'undefined') {
113 tab.className = 'permissions-preset-' + quick + ' activetab';
114 return;
115 }
116
117 var rb = table.getElementsByTagName('input');
118 var colour = 'custom';
119
120 var status = get_radio_status(0, rb);
121
122 if (status === 1) {
123 colour = 'yes';
124 } else if (status === 0) {
125 // We move on to No
126 status = get_radio_status(1, rb);
127
128 if (status === 1) {
129 colour = 'no';
130 } else if (status === 0) {
131 // We move on to Never
132 status = get_radio_status(2, rb);
133
134 if (status === 1) {
135 colour = 'never';
136 }
137 }
138 }
139
140 if (init) {
141 tab.className = 'permissions-preset-' + colour;
142 } else {
143 tab.className = 'permissions-preset-' + colour + ' activetab';
144 }
145 }
146
147 /**
148 * Initialise advanced tab colours on first load
149 * block_id = block that is opened
150 */
151 function init_colours(block_id) {
152 var block = document.getElementById('advanced' + block_id);
153 var panels = block.getElementsByTagName('div');
154 var tab = document.getElementById('tab' + id);
155
156 for (var i = 0; i < panels.length; i++) {
157 if (panels[i].className === 'permissions-panel') {
158 set_colours(panels[i].id.replace(/options/, ''), true);
159 }
160 }
161
162 tab.className = tab.className + ' activetab';
163 }
164
165 /**
166 * Show/hide option panels
167 * value = suffix for ID to show
168 * adv = we are opening advanced permissions
169 * view = called from view permissions
170 */
171 function swap_options(pmask, fmask, cat, adv, view) {
172 id = pmask + fmask + cat;
173 active_option = active_pmask + active_fmask + active_cat;
174
175 var old_tab = document.getElementById('tab' + active_option);
176 var new_tab = document.getElementById('tab' + id);
177 var adv_block = document.getElementById('advanced' + pmask + fmask);
178
179 if (adv_block.style.display === 'block' && adv === true) {
180 phpbb.toggleDisplay('advanced' + pmask + fmask, -1);
181 reset_opacity(1);
182 display_checkboxes(false);
183 return;
184 }
185
186 // no need to set anything if we are clicking on the same tab again
187 if (new_tab === old_tab && !adv) {
188 return;
189 }
190
191 // init colours
192 if (adv && (pmask + fmask) !== (active_pmask + active_fmask)) {
193 init_colours(pmask + fmask);
194 display_checkboxes(true);
195 reset_opacity(1);
196 } else if (adv) {
197 //Checkbox might have been clicked, but we need full visibility
198 display_checkboxes(true);
199 reset_opacity(1);
200 }
201
202 // set active tab
203 old_tab.className = old_tab.className.replace(/\ activetab/g, '');
204 new_tab.className = new_tab.className + ' activetab';
205
206 if (id === active_option && adv !== true) {
207 return;
208 }
209
210 phpbb.toggleDisplay('options' + active_option, -1);
211
212 //hiding and showing the checkbox
213 if (document.getElementById('checkbox' + active_pmask + active_fmask)) {
214 phpbb.toggleDisplay('checkbox' + pmask + fmask, -1);
215
216 if ((pmask + fmask) !== (active_pmask + active_fmask)) {
217 document.getElementById('checkbox' + active_pmask + active_fmask).style.display = 'inline';
218 }
219 }
220
221 if (!view) {
222 phpbb.toggleDisplay('advanced' + active_pmask + active_fmask, -1);
223 }
224
225 if (!view) {
226 phpbb.toggleDisplay('advanced' + pmask + fmask, 1);
227 }
228 phpbb.toggleDisplay('options' + id, 1);
229
230 active_pmask = pmask;
231 active_fmask = fmask;
232 active_cat = cat;
233 }
234
235 /**
236 * Mark all radio buttons in one panel
237 * id = table ID container, s = status ['y'/'u'/'n']
238 */
239 function mark_options(id, s) {
240 var t = document.getElementById(id);
241
242 if (!t) {
243 return;
244 }
245
246 var rb = t.getElementsByTagName('input');
247
248 for (var r = 0; r < rb.length; r++) {
249 if (rb[r].id.substr(rb[r].id.length-1) === s) {
250 rb[r].checked = true;
251 }
252 }
253 }
254
255 function mark_one_option(id, field_name, s) {
256 var t = document.getElementById(id);
257
258 if (!t) {
259 return;
260 }
261
262 var rb = t.getElementsByTagName('input');
263
264 for (var r = 0; r < rb.length; r++) {
265 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) {
266 rb[r].checked = true;
267 }
268 }
269 }
270
271 /**
272 * (Re)set the permission role dropdown.
273 *
274 * Try and match the set permissions to an existing role.
275 * Otherwise reset the dropdown to "Select a role.."
276 *
277 * @param {string} id The fieldset identifier
278 * @returns {void}
279 */
280 function reset_role(id) {
281 var t = document.getElementById(id);
282
283 if (!t) {
284 return;
285 }
286
287 // Before resetting the role dropdown, try and match any permission role
288 var parent = t.parentNode,
289 roleId = match_role_settings(id.replace('role', 'perm')),
290 text = no_role_assigned,
291 index = 0;
292
293 // If a role permissions was matched, grab that option's value and index
294 if (roleId) {
295 for (var i = 0; i < t.options.length; i++) {
296 if (parseInt(t.options[i].value, 10) === roleId) {
297 text = t.options[i].text;
298 index = i;
299 break;
300 }
301 }
302 }
303
304 // Update the select's value and selected index
305 t.value = roleId;
306 t.options[index].selected = true;
307
308 // Update the dropdown trigger to show the new value
309 parent.querySelector('span.dropdown-trigger').innerText = text;
310 parent.querySelector('input[data-name^=role]').value = roleId;
311 }
312
313 /**
314 * Load role and set options accordingly
315 */
316 function set_role_settings(role_id, target_id) {
317 var settings = role_options[role_id];
318
319 if (!settings) {
320 return;
321 }
322
323 // Mark all options to no (unset) first...
324 mark_options(target_id, 'u');
325
326 for (var r in settings) {
327 mark_one_option(target_id, r, (settings[r] === 1) ? 'y' : 'n');
328 }
329 }
330
331 /**
332 * Match the set permissions against the available roles.
333 *
334 * @param {string} id The parent fieldset identifier
335 * @return {number} The permission role identifier
336 */
337 function match_role_settings(id) {
338 var fieldset = document.getElementById(id),
339 radios = fieldset.getElementsByTagName('input'),
340 set = {};
341
342 // Iterate over all the radio buttons
343 for (var i = 0; i < radios.length; i++) {
344 var matches = radios[i].id.match(/setting\[\d+]\[\d+]\[([a-z_]+)]/);
345
346 // Make sure the name attribute matches, the radio is checked and it is not the "No" (-1) value.
347 if (matches !== null && radios[i].checked && radios[i].value !== '-1') {
348 set[matches[1]] = parseInt(radios[i].value, 10);
349 }
350 }
351
352 // Sort and stringify the 'set permissions' object
353 set = sort_and_stringify(set);
354
355 // Iterate over the available role options and return the first match
356 for (var r in role_options)
357 {
358 if (sort_and_stringify(role_options[r]) === set) {
359 return parseInt(r, 10);
360 }
361 }
362
363 return 0;
364 }
365
366 /**
367 * Sort and stringify an Object so it can be easily compared against another object.
368 *
369 * @param {object} obj The object to sort (by key) and stringify
370 * @return {string} The sorted object as a string
371 */
372 function sort_and_stringify(obj) {
373 return JSON.stringify(Object.keys(obj).sort().reduce(function (result, key) {
374 result[key] = obj[key];
375 return result;
376 }, {}));
377 }
378