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 |
ajax.js
001 /* global phpbb, statsData */
002
003 (function($) { // Avoid conflicts with other libraries
004
005 'use strict';
006
007
008 phpbb.prepareSendStats = function () {
009 var $form = $('#acp_help_phpbb');
010 var $dark = $('#darkenwrapper');
011 var $loadingIndicator;
012
013 $form.on('submit', function (event) {
014 var $this = $(this),
015 currentTime = Math.floor(new Date().getTime() / 1000),
016 statsTime = parseInt($this.find('input[name=help_send_statistics_time]').val(), 10);
017
018 event.preventDefault();
019 $this.unbind('submit');
020
021 // Skip ajax request if form is submitted too early or send stats
022 // checkbox is not checked
023 if (!$this.find('input[name=help_send_statistics]').is(':checked') ||
024 statsTime > currentTime) {
025 $form.find('input[type=submit]').click();
026 setTimeout(function () {
027 $form.find('input[type=submit]').click();
028 }, 300);
029 return;
030 }
031
032 /**
033 * Handler for AJAX errors
034 */
035 function errorHandler(jqXHR, textStatus, errorThrown) {
036 if (typeof console !== 'undefined' && console.log) {
037 console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown);
038 }
039 phpbb.clearLoadingTimeout();
040 var errorText = '';
041
042 if (typeof errorThrown === 'string' && errorThrown.length > 0) {
043 errorText = errorThrown;
044 } else {
045 errorText = $dark.attr('data-ajax-error-text-' + textStatus);
046 if (typeof errorText !== 'string' || !errorText.length) {
047 errorText = $dark.attr('data-ajax-error-text');
048 }
049 }
050 phpbb.alert($dark.attr('data-ajax-error-title'), errorText);
051 }
052
053 /**
054 * This is a private function used to handle the callbacks, refreshes
055 * and alert. It calls the callback, refreshes the page if necessary, and
056 * displays an alert to the user and removes it after an amount of time.
057 *
058 * It cannot be called from outside this function, and is purely here to
059 * avoid repetition of code.
060 *
061 * @param {object} res The object sent back by the server.
062 */
063 function returnHandler(res) {
064 phpbb.clearLoadingTimeout();
065
066 // If a confirmation is not required, display an alert and call the
067 // callbacks.
068 $dark.fadeOut(phpbb.alertTime);
069
070 if ($loadingIndicator) {
071 $loadingIndicator.fadeOut(phpbb.alertTime);
072 }
073
074 var $sendStatisticsSuccess = $('<input />', {
075 type: 'hidden',
076 name: 'send_statistics_response',
077 value: JSON.stringify(res)
078 });
079 $sendStatisticsSuccess.appendTo('p.submit-buttons');
080
081 // Finish actual form submission
082 $form.find('input[type=submit]').click();
083 }
084
085 $loadingIndicator = phpbb.loadingIndicator();
086
087 $.ajax({
088 url: $this.attr('data-ajax-action').replace('&', '&'),
089 type: 'POST',
090 data: statsData,
091 success: returnHandler,
092 error: errorHandler,
093 cache: false
094 }).always(function() {
095 if ($loadingIndicator && $loadingIndicator.is(':visible')) {
096 $loadingIndicator.fadeOut(phpbb.alertTime);
097 }
098 });
099 });
100 };
101
102 /**
103 * The following callbacks are for reording items. row_down
104 * is triggered when an item is moved down, and row_up is triggered when
105 * an item is moved up. It moves the row up or down, and deactivates /
106 * activates any up / down icons that require it (the ones at the top or bottom).
107 */
108 phpbb.addAjaxCallback('row_down', function(res) {
109 if (typeof res.success === 'undefined' || !res.success) {
110 return;
111 }
112
113 var $firstTr = $(this).parents('tr'),
114 $secondTr = $firstTr.next();
115
116 $firstTr.insertAfter($secondTr);
117 });
118
119 phpbb.addAjaxCallback('row_up', function(res) {
120 if (typeof res.success === 'undefined' || !res.success) {
121 return;
122 }
123
124 var $secondTr = $(this).parents('tr'),
125 $firstTr = $secondTr.prev();
126
127 $secondTr.insertBefore($firstTr);
128 });
129
130 /**
131 * This callback replaces activate links with deactivate links and vice versa.
132 * It does this by replacing the text, and replacing all instances of "activate"
133 * in the href with "deactivate", and vice versa.
134 */
135 phpbb.addAjaxCallback('activate_deactivate', function(res) {
136 var $this = $(this),
137 newHref = $this.attr('href');
138
139 $this.text(res.text);
140
141 if (newHref.indexOf('deactivate') !== -1) {
142 newHref = newHref.replace('deactivate', 'activate');
143 } else {
144 newHref = newHref.replace('activate', 'deactivate');
145 }
146
147 $this.attr('href', newHref);
148 });
149
150 /**
151 * The removes the parent row of the link or form that triggered the callback,
152 * and is good for stuff like the removal of forums.
153 */
154 phpbb.addAjaxCallback('row_delete', function(res) {
155 if (res.SUCCESS !== false) {
156 $(this).parents('tr').remove();
157 }
158 });
159
160 /**
161 * Handler for submitting permissions form in chunks
162 * This call will submit permissions forms in chunks of 5 fieldsets.
163 */
164 function submitPermissions() {
165 var $form = $('form#set-permissions'),
166 fieldsetList = $form.find('fieldset[id^=perm]'),
167 formDataSets = [],
168 dataSetIndex = 0,
169 $submitAllButton = $form.find('input[type=submit][name^=action]')[0],
170 $submitButton = $form.find('input[type=submit][data-clicked=true]')[0];
171
172 // Set proper start values for handling refresh of page
173 var permissionSubmitSize = 0,
174 permissionRequestCount = 0,
175 forumIds = [],
176 permissionSubmitFailed = false,
177 clearIndicator = true,
178 $loadingIndicator;
179
180 if ($submitAllButton !== $submitButton) {
181 fieldsetList = $form.find('fieldset#' + $submitButton.closest('fieldset.permissions').id);
182 }
183
184 $.each(fieldsetList, function (key, value) {
185 dataSetIndex = Math.floor(key / 5);
186 var $fieldset = $('fieldset#' + value.id);
187 if (key % 5 === 0) {
188 formDataSets[dataSetIndex] = $fieldset.find('select:visible, input:not([data-name])').serialize();
189 } else {
190 formDataSets[dataSetIndex] += '&' + $fieldset.find('select:visible, input:not([data-name])').serialize();
191 }
192
193 // Find proper role value
194 var roleInput = $fieldset.find('input[name^=role][data-name]');
195 if (roleInput.val()) {
196 formDataSets[dataSetIndex] += '&' + roleInput.attr('name') + '=' + roleInput.val();
197 } else {
198 formDataSets[dataSetIndex] += '&' + roleInput.attr('name') + '=' +
199 $fieldset.find('select[name="' + roleInput.attr('name') + '"]').val();
200 }
201 });
202
203 permissionSubmitSize = formDataSets.length;
204
205 // Add each forum ID to forum ID list to preserve selected forums
206 $.each($form.find('input[type=hidden][name^=forum_id]'), function (key, value) {
207 if (value.name.match(/^forum_id\[([0-9]+)\]$/)) {
208 forumIds.push(value.value);
209 }
210 });
211
212 $loadingIndicator = phpbb.loadingIndicator();
213
214 /**
215 * Handler for submitted permissions form chunk
216 *
217 * @param {object} res Object returned by AJAX call
218 */
219 function handlePermissionReturn(res) {
220 permissionRequestCount++;
221 var $dark = $('#darkenwrapper');
222
223 if (res.S_USER_WARNING) {
224 phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
225 permissionSubmitFailed = true;
226 } else if (!permissionSubmitFailed && res.S_USER_NOTICE) {
227 // Display success message at the end of submitting the form
228 if (permissionRequestCount >= permissionSubmitSize) {
229 clearIndicator = true;
230
231 var $alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
232 var $alertBoxLink = $alert.find('p.alert_text > a');
233
234 // Create form to submit instead of normal "Back to previous page" link
235 if ($alertBoxLink) {
236 // Remove forum_id[] from URL
237 $alertBoxLink.attr('href', $alertBoxLink.attr('href').replace(/(&forum_id\[\]=[0-9]+)/g, ''));
238 const $previousPageForm = $('<form>').attr({
239 action: $alertBoxLink.attr('href'),
240 method: 'post'
241 });
242
243 $.each(forumIds, function (key, value) {
244 $previousPageForm.append($('<input>').attr({
245 type: 'text',
246 name: 'forum_id[]',
247 value: value
248 }));
249 });
250
251 $alertBoxLink.on('click', function (e) {
252 $('body').append($previousPageForm);
253 e.preventDefault();
254 $previousPageForm.submit();
255 });
256 }
257
258 // Do not allow closing alert
259 $dark.off('click');
260 $alert.find('.alert_close').hide();
261
262 if (typeof res.REFRESH_DATA !== 'undefined') {
263 setTimeout(function () {
264 // Create forum to submit using POST. This will prevent
265 // exceeding the maximum length of URLs
266 const $form = $('<form>').attr({
267 action: res.REFRESH_DATA.url.replace(/(&forum_id\[\]=[0-9]+)/g, ''),
268 method: 'post'
269 });
270
271 $.each(forumIds, function (key, value) {
272 $form.append($('<input>').attr({
273 type: 'text',
274 name: 'forum_id[]',
275 value: value
276 }));
277 });
278
279 $('body').append($form);
280
281 // Hide the alert even if we refresh the page, in case the user
282 // presses the back button.
283 $dark.fadeOut(phpbb.alertTime, function () {
284 if (typeof $alert !== 'undefined') {
285 $alert.hide();
286 }
287 });
288
289 // Submit form
290 $form.submit();
291 }, res.REFRESH_DATA.time * 1000); // Server specifies time in seconds
292 }
293 } else {
294 // Still more forms to submit, so do not clear indicator
295 clearIndicator = false;
296 }
297 }
298
299 if (clearIndicator) {
300 phpbb.clearLoadingTimeout();
301
302 if ($loadingIndicator) {
303 $loadingIndicator.fadeOut(phpbb.alertTime);
304 }
305 }
306 }
307
308 // Create AJAX request for each form data set
309 $.each(formDataSets, function (key, formData) {
310 $.ajax({
311 url: $form.action,
312 type: 'POST',
313 data: formData + '&' + $submitButton.name + '=' + encodeURIComponent($submitButton.value) +
314 '&creation_time=' + $form.find('input[type=hidden][name=creation_time]')[0].value +
315 '&form_token=' + $form.find('input[type=hidden][name=form_token]')[0].value +
316 '&' + $form.children('input[type=hidden]').serialize() +
317 '&' + $form.find('input[type=checkbox][name^=inherit]').serialize(),
318 success: handlePermissionReturn,
319 error: handlePermissionReturn
320 });
321 });
322 }
323
324 $('[data-ajax]').each(function() {
325 var $this = $(this),
326 ajax = $this.attr('data-ajax');
327
328 if (ajax !== 'false') {
329 var fn = (ajax !== 'true') ? ajax : null;
330 phpbb.ajaxify({
331 selector: this,
332 refresh: $this.attr('data-refresh') !== undefined,
333 callback: fn
334 });
335 }
336 });
337
338 /**
339 * Automatically resize textarea
340 */
341 $(function() {
342 phpbb.resizeTextArea($('textarea:not(.no-auto-resize)'), {minHeight: 75});
343
344 var $setPermissionsForm = $('form#set-permissions');
345 if ($setPermissionsForm.length) {
346 $setPermissionsForm.on('submit', function (e) {
347 submitPermissions();
348 e.preventDefault();
349 });
350 $setPermissionsForm.find('input[type=submit]').click(function() {
351 $('input[type=submit]', $(this).parents($('form#set-permissions'))).removeAttr('data-clicked');
352 $(this).attr('data-clicked', true);
353 });
354 }
355
356 if ($('#acp_help_phpbb')) {
357 phpbb.prepareSendStats();
358 }
359 });
360
361
362 })(jQuery); // Avoid conflicts with other libraries
363