[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 /* global phpbb, statsData */ 2 3 (function($) { // Avoid conflicts with other libraries 4 5 'use strict'; 6 7 8 phpbb.prepareSendStats = function () { 9 var $form = $('#acp_help_phpbb'); 10 var $dark = $('#darkenwrapper'); 11 var $loadingIndicator; 12 13 $form.on('submit', function (event) { 14 var $this = $(this), 15 currentTime = Math.floor(new Date().getTime() / 1000), 16 statsTime = parseInt($this.find('input[name=help_send_statistics_time]').val(), 10); 17 18 event.preventDefault(); 19 $this.unbind('submit'); 20 21 // Skip ajax request if form is submitted too early or send stats 22 // checkbox is not checked 23 if (!$this.find('input[name=help_send_statistics]').is(':checked') || 24 statsTime > currentTime) { 25 $form.find('input[type=submit]').click(); 26 setTimeout(function () { 27 $form.find('input[type=submit]').click(); 28 }, 300); 29 return; 30 } 31 32 /** 33 * Handler for AJAX errors 34 */ 35 function errorHandler(jqXHR, textStatus, errorThrown) { 36 if (typeof console !== 'undefined' && console.log) { 37 console.log('AJAX error. status: ' + textStatus + ', message: ' + errorThrown); 38 } 39 phpbb.clearLoadingTimeout(); 40 var errorText = ''; 41 42 if (typeof errorThrown === 'string' && errorThrown.length > 0) { 43 errorText = errorThrown; 44 } else { 45 errorText = $dark.attr('data-ajax-error-text-' + textStatus); 46 if (typeof errorText !== 'string' || !errorText.length) { 47 errorText = $dark.attr('data-ajax-error-text'); 48 } 49 } 50 phpbb.alert($dark.attr('data-ajax-error-title'), errorText); 51 } 52 53 /** 54 * This is a private function used to handle the callbacks, refreshes 55 * and alert. It calls the callback, refreshes the page if necessary, and 56 * displays an alert to the user and removes it after an amount of time. 57 * 58 * It cannot be called from outside this function, and is purely here to 59 * avoid repetition of code. 60 * 61 * @param {object} res The object sent back by the server. 62 */ 63 function returnHandler(res) { 64 phpbb.clearLoadingTimeout(); 65 66 // If a confirmation is not required, display an alert and call the 67 // callbacks. 68 $dark.fadeOut(phpbb.alertTime); 69 70 if ($loadingIndicator) { 71 $loadingIndicator.fadeOut(phpbb.alertTime); 72 } 73 74 var $sendStatisticsSuccess = $('<input />', { 75 type: 'hidden', 76 name: 'send_statistics_response', 77 value: JSON.stringify(res) 78 }); 79 $sendStatisticsSuccess.appendTo('p.submit-buttons'); 80 81 // Finish actual form submission 82 $form.find('input[type=submit]').click(); 83 } 84 85 $loadingIndicator = phpbb.loadingIndicator(); 86 87 $.ajax({ 88 url: $this.attr('data-ajax-action').replace('&', '&'), 89 type: 'POST', 90 data: statsData, 91 success: returnHandler, 92 error: errorHandler, 93 cache: false 94 }).always(function() { 95 if ($loadingIndicator && $loadingIndicator.is(':visible')) { 96 $loadingIndicator.fadeOut(phpbb.alertTime); 97 } 98 }); 99 }); 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 var previousPageForm = '<form action="' + $alertBoxLink.attr('href') + '" method="post">'; 239 $.each(forumIds, function (key, value) { 240 previousPageForm += '<input type="text" name="forum_id[]" value="' + value + '" />'; 241 }); 242 previousPageForm += '</form>'; 243 244 $alertBoxLink.on('click', function (e) { 245 var $previousPageForm = $(previousPageForm); 246 $('body').append($previousPageForm); 247 e.preventDefault(); 248 $previousPageForm.submit(); 249 }); 250 } 251 252 // Do not allow closing alert 253 $dark.off('click'); 254 $alert.find('.alert_close').hide(); 255 256 if (typeof res.REFRESH_DATA !== 'undefined') { 257 setTimeout(function () { 258 // Create forum to submit using POST. This will prevent 259 // exceeding the maximum length of URLs 260 var form = '<form action="' + res.REFRESH_DATA.url.replace(/(&forum_id\[\]=[0-9]+)/g, '') + '" method="post">'; 261 $.each(forumIds, function (key, value) { 262 form += '<input type="text" name="forum_id[]" value="' + value + '" />'; 263 }); 264 form += '</form>'; 265 $form = $(form); 266 $('body').append($form); 267 268 // Hide the alert even if we refresh the page, in case the user 269 // presses the back button. 270 $dark.fadeOut(phpbb.alertTime, function () { 271 if (typeof $alert !== 'undefined') { 272 $alert.hide(); 273 } 274 }); 275 276 // Submit form 277 $form.submit(); 278 }, res.REFRESH_DATA.time * 1000); // Server specifies time in seconds 279 } 280 } else { 281 // Still more forms to submit, so do not clear indicator 282 clearIndicator = false; 283 } 284 } 285 286 if (clearIndicator) { 287 phpbb.clearLoadingTimeout(); 288 289 if ($loadingIndicator) { 290 $loadingIndicator.fadeOut(phpbb.alertTime); 291 } 292 } 293 } 294 295 // Create AJAX request for each form data set 296 $.each(formDataSets, function (key, formData) { 297 $.ajax({ 298 url: $form.action, 299 type: 'POST', 300 data: formData + '&' + $submitButton.name + '=' + encodeURIComponent($submitButton.value) + 301 '&creation_time=' + $form.find('input[type=hidden][name=creation_time]')[0].value + 302 '&form_token=' + $form.find('input[type=hidden][name=form_token]')[0].value + 303 '&' + $form.children('input[type=hidden]').serialize() + 304 '&' + $form.find('input[type=checkbox][name^=inherit]').serialize(), 305 success: handlePermissionReturn, 306 error: handlePermissionReturn 307 }); 308 }); 309 } 310 311 $('[data-ajax]').each(function() { 312 var $this = $(this), 313 ajax = $this.attr('data-ajax'); 314 315 if (ajax !== 'false') { 316 var fn = (ajax !== 'true') ? ajax : null; 317 phpbb.ajaxify({ 318 selector: this, 319 refresh: $this.attr('data-refresh') !== undefined, 320 callback: fn 321 }); 322 } 323 }); 324 325 /** 326 * Automatically resize textarea 327 */ 328 $(function() { 329 phpbb.resizeTextArea($('textarea:not(.no-auto-resize)'), {minHeight: 75}); 330 331 var $setPermissionsForm = $('form#set-permissions'); 332 if ($setPermissionsForm.length) { 333 $setPermissionsForm.on('submit', function (e) { 334 submitPermissions(); 335 e.preventDefault(); 336 }); 337 $setPermissionsForm.find('input[type=submit]').click(function() { 338 $('input[type=submit]', $(this).parents($('form#set-permissions'))).removeAttr('data-clicked'); 339 $(this).attr('data-clicked', true); 340 }); 341 } 342 343 if ($('#acp_help_phpbb')) { 344 phpbb.prepareSendStats(); 345 } 346 }); 347 348 349 })(jQuery); // Avoid conflicts with other libraries
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |