Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ajax.js

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 9.92 KiB


001  /* global phpbb */
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: 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('&amp;', '&'),
089              type: 'POST',
090              data: 'systemdata=' + encodeURIComponent($this.find('input[name=systemdata]').val()),
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   
178      if ($submitAllButton !== $submitButton) {
179          fieldsetList = $form.find('fieldset#' + $submitButton.closest('fieldset.permissions').id);
180      }
181   
182      $.each(fieldsetList, function (key, value) {
183          dataSetIndex = Math.floor(key / 5);
184          var $fieldset = $('fieldset#' + value.id);
185          if (key % 5 === 0) {
186              formDataSets[dataSetIndex] = $fieldset.find('select:visible, input:not([data-name])').serialize();
187          } else {
188              formDataSets[dataSetIndex] += '&' + $fieldset.find('select:visible, input:not([data-name])').serialize();
189          }
190   
191          // Find proper role value
192          var roleInput = $fieldset.find('input[name^=role][data-name]');
193          if (roleInput.val()) {
194              formDataSets[dataSetIndex] += '&' + roleInput.attr('name') + '=' + roleInput.val();
195          } else {
196              formDataSets[dataSetIndex] += '&' + roleInput.attr('name') + '=' +
197                  $fieldset.find('select[name="' + roleInput.attr('name') + '"]').val();
198          }
199      });
200   
201      permissionSubmitSize = formDataSets.length;
202   
203      // Add each forum ID to forum ID list to preserve selected forums
204      $.each($form.find('input[type=hidden][name^=forum_id]'), function (key, value) {
205          if (value.name.match(/^forum_id\[([0-9]+)\]$/)) {
206              forumIds.push(value.value);
207          }
208      });
209   
210      /**
211       * Handler for submitted permissions form chunk
212       *
213       * @param {object} res Object returned by AJAX call
214       */
215      function handlePermissionReturn(res) {
216          permissionRequestCount++;
217          var $dark = $('#darkenwrapper');
218   
219          if (res.S_USER_WARNING) {
220              phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
221              permissionSubmitFailed = true;
222          } else if (!permissionSubmitFailed && res.S_USER_NOTICE) {
223              // Display success message at the end of submitting the form
224              if (permissionRequestCount >= permissionSubmitSize) {
225                  var $alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT);
226                  var $alertBoxLink = $alert.find('p.alert_text > a');
227   
228                  // Create form to submit instead of normal "Back to previous page" link
229                  if ($alertBoxLink) {
230                      // Remove forum_id[] from URL
231                      $alertBoxLink.attr('href', $alertBoxLink.attr('href').replace(/(&forum_id\[\]=[0-9]+)/g, ''));
232                      var previousPageForm = '<form action="' + $alertBoxLink.attr('href') + '" method="post">';
233                      $.each(forumIds, function (key, value) {
234                          previousPageForm += '<input type="text" name="forum_id[]" value="' + value + '" />';
235                      });
236                      previousPageForm += '</form>';
237   
238                      $alertBoxLink.on('click', function (e) {
239                          var $previousPageForm = $(previousPageForm);
240                          $('body').append($previousPageForm);
241                          e.preventDefault();
242                          $previousPageForm.submit();
243                      });
244                  }
245   
246                  // Do not allow closing alert
247                  $dark.off('click');
248                  $alert.find('.alert_close').hide();
249   
250                  if (typeof res.REFRESH_DATA !== 'undefined') {
251                      setTimeout(function () {
252                          // Create forum to submit using POST. This will prevent
253                          // exceeding the maximum length of URLs
254                          var form = '<form action="' + res.REFRESH_DATA.url.replace(/(&forum_id\[\]=[0-9]+)/g, '') + '" method="post">';
255                          $.each(forumIds, function (key, value) {
256                              form += '<input type="text" name="forum_id[]" value="' + value + '" />';
257                          });
258                          form += '</form>';
259                          $form = $(form);
260                          $('body').append($form);
261   
262                          // Hide the alert even if we refresh the page, in case the user
263                          // presses the back button.
264                          $dark.fadeOut(phpbb.alertTime, function () {
265                              if (typeof $alert !== 'undefined') {
266                                  $alert.hide();
267                              }
268                          });
269   
270                          // Submit form
271                          $form.submit();
272                      }, res.REFRESH_DATA.time * 1000); // Server specifies time in seconds
273                  }
274              }
275          }
276      }
277   
278      // Create AJAX request for each form data set
279      $.each(formDataSets, function (key, formData) {
280          $.ajax({
281              url: $form.action,
282              type: 'POST',
283              data: formData + '&' + $submitAllButton.name + '=' + encodeURIComponent($submitAllButton.value) +
284                  '&creation_time=' + $form.find('input[type=hidden][name=creation_time]')[0].value +
285                  '&form_token=' + $form.find('input[type=hidden][name=form_token]')[0].value +
286                  '&' + $form.children('input[type=hidden]').serialize(),
287              success: handlePermissionReturn,
288              error: handlePermissionReturn
289          });
290      });
291  }
292   
293  $('[data-ajax]').each(function() {
294      var $this = $(this),
295          ajax = $this.attr('data-ajax');
296   
297      if (ajax !== 'false') {
298          var fn = (ajax !== 'true') ? ajax : null;
299          phpbb.ajaxify({
300              selector: this,
301              refresh: $this.attr('data-refresh') !== undefined,
302              callback: fn
303          });
304      }
305  });
306   
307  /**
308  * Automatically resize textarea
309  */
310  $(function() {
311      phpbb.resizeTextArea($('textarea:not(.no-auto-resize)'), {minHeight: 75});
312   
313      var $setPermissionsForm = $('form#set-permissions');
314      if ($setPermissionsForm.length) {
315          $setPermissionsForm.on('submit', function (e) {
316              submitPermissions();
317              e.preventDefault();
318          });
319          $setPermissionsForm.find('input[type=submit]').click(function() {
320              $('input[type=submit]', $(this).parents($('form#set-permissions'))).removeAttr('data-clicked');
321              $(this).attr('data-clicked', true);
322          });
323      }
324   
325      if ($('#acp_help_phpbb')) {
326          phpbb.prepareSendStats();
327      }
328  });
329   
330   
331  })(jQuery); // Avoid conflicts with other libraries
332