[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 /* global phpbb */ 2 3 (function($) { // Avoid conflicts with other libraries 4 5 'use strict'; 6 7 /** 8 * The following callbacks are for reording items. row_down 9 * is triggered when an item is moved down, and row_up is triggered when 10 * an item is moved up. It moves the row up or down, and deactivates / 11 * activates any up / down icons that require it (the ones at the top or bottom). 12 */ 13 phpbb.addAjaxCallback('row_down', function(res) { 14 if (typeof res.success === 'undefined' || !res.success) { 15 return; 16 } 17 18 var $firstTr = $(this).parents('tr'), 19 $secondTr = $firstTr.next(); 20 21 $firstTr.insertAfter($secondTr); 22 }); 23 24 phpbb.addAjaxCallback('row_up', function(res) { 25 if (typeof res.success === 'undefined' || !res.success) { 26 return; 27 } 28 29 var $secondTr = $(this).parents('tr'), 30 $firstTr = $secondTr.prev(); 31 32 $secondTr.insertBefore($firstTr); 33 }); 34 35 /** 36 * This callback replaces activate links with deactivate links and vice versa. 37 * It does this by replacing the text, and replacing all instances of "activate" 38 * in the href with "deactivate", and vice versa. 39 */ 40 phpbb.addAjaxCallback('activate_deactivate', function(res) { 41 var $this = $(this), 42 newHref = $this.attr('href'); 43 44 $this.text(res.text); 45 46 if (newHref.indexOf('deactivate') !== -1) { 47 newHref = newHref.replace('deactivate', 'activate'); 48 } else { 49 newHref = newHref.replace('activate', 'deactivate'); 50 } 51 52 $this.attr('href', newHref); 53 }); 54 55 /** 56 * The removes the parent row of the link or form that triggered the callback, 57 * and is good for stuff like the removal of forums. 58 */ 59 phpbb.addAjaxCallback('row_delete', function(res) { 60 if (res.SUCCESS !== false) { 61 $(this).parents('tr').remove(); 62 } 63 }); 64 65 /** 66 * Handler for submitting permissions form in chunks 67 * This call will submit permissions forms in chunks of 5 fieldsets. 68 */ 69 function submitPermissions() { 70 var $form = $('form#set-permissions'), 71 fieldsetList = $form.find('fieldset[id^=perm]'), 72 formDataSets = [], 73 $submitAllButton = $form.find('input[type=submit][name^=action]')[0], 74 $submitButton = $form.find('input[type=submit][data-clicked=true]')[0]; 75 76 // Set proper start values for handling refresh of page 77 var permissionSubmitSize = 0, 78 permissionRequestCount = 0, 79 forumIds = [], 80 permissionSubmitFailed = false; 81 82 if ($submitAllButton !== $submitButton) { 83 fieldsetList = $form.find('fieldset#' + $submitButton.closest('fieldset.permissions').id); 84 } 85 86 $.each(fieldsetList, function (key, value) { 87 if (key % 5 === 0) { 88 formDataSets[Math.floor(key / 5)] = $form.find('fieldset#' + value.id).serialize(); 89 } else { 90 formDataSets[Math.floor(key / 5)] += '&' + $form.find('fieldset#' + value.id).serialize(); 91 } 92 }); 93 94 permissionSubmitSize = formDataSets.length; 95 96 // Add each forum ID to forum ID list to preserve selected forums 97 $.each($form.find('input[type=hidden][name^=forum_id]'), function (key, value) { 98 if (value.name.match(/^forum_id\[([0-9]+)\]$/)) { 99 forumIds.push(value.value); 100 } 101 }); 102 103 /** 104 * Handler for submitted permissions form chunk 105 * 106 * @param {object} res Object returned by AJAX call 107 */ 108 function handlePermissionReturn(res) { 109 permissionRequestCount++; 110 var $dark = $('#darkenwrapper'); 111 112 if (res.S_USER_WARNING) { 113 phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); 114 permissionSubmitFailed = true; 115 } else if (!permissionSubmitFailed && res.S_USER_NOTICE) { 116 // Display success message at the end of submitting the form 117 if (permissionRequestCount >= permissionSubmitSize) { 118 var $alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); 119 var $alertBoxLink = $alert.find('p.alert_text > a'); 120 121 // Create form to submit instead of normal "Back to previous page" link 122 if ($alertBoxLink) { 123 // Remove forum_id[] from URL 124 $alertBoxLink.attr('href', $alertBoxLink.attr('href').replace(/(&forum_id\[\]=[0-9]+)/g, '')); 125 var previousPageForm = '<form action="' + $alertBoxLink.attr('href') + '" method="post">'; 126 $.each(forumIds, function (key, value) { 127 previousPageForm += '<input type="text" name="forum_id[]" value="' + value + '" />'; 128 }); 129 previousPageForm += '</form>'; 130 131 $alertBoxLink.on('click', function (e) { 132 var $previousPageForm = $(previousPageForm); 133 $('body').append($previousPageForm); 134 e.preventDefault(); 135 $previousPageForm.submit(); 136 }); 137 } 138 139 // Do not allow closing alert 140 $dark.off('click'); 141 $alert.find('.alert_close').hide(); 142 143 if (typeof res.REFRESH_DATA !== 'undefined') { 144 setTimeout(function () { 145 // Create forum to submit using POST. This will prevent 146 // exceeding the maximum length of URLs 147 var form = '<form action="' + res.REFRESH_DATA.url.replace(/(&forum_id\[\]=[0-9]+)/g, '') + '" method="post">'; 148 $.each(forumIds, function (key, value) { 149 form += '<input type="text" name="forum_id[]" value="' + value + '" />'; 150 }); 151 form += '</form>'; 152 $form = $(form); 153 $('body').append($form); 154 155 // Hide the alert even if we refresh the page, in case the user 156 // presses the back button. 157 $dark.fadeOut(phpbb.alertTime, function () { 158 if (typeof $alert !== 'undefined') { 159 $alert.hide(); 160 } 161 }); 162 163 // Submit form 164 $form.submit(); 165 }, res.REFRESH_DATA.time * 1000); // Server specifies time in seconds 166 } 167 } 168 } 169 } 170 171 // Create AJAX request for each form data set 172 $.each(formDataSets, function (key, formData) { 173 $.ajax({ 174 url: $form.action, 175 type: 'POST', 176 data: formData + '&' + $submitButton.name + '=' + encodeURIComponent($submitButton.value) + 177 '&creation_time=' + $form.find('input[type=hidden][name=creation_time]')[0].value + 178 '&form_token=' + $form.find('input[type=hidden][name=form_token]')[0].value + 179 '&' + $form.children('input[type=hidden]').serialize() + 180 '&' + $form.find('input[type=checkbox][name^=inherit]').serialize(), 181 success: handlePermissionReturn, 182 error: handlePermissionReturn 183 }); 184 }); 185 } 186 187 $('[data-ajax]').each(function() { 188 var $this = $(this), 189 ajax = $this.attr('data-ajax'); 190 191 if (ajax !== 'false') { 192 var fn = (ajax !== 'true') ? ajax : null; 193 phpbb.ajaxify({ 194 selector: this, 195 refresh: $this.attr('data-refresh') !== undefined, 196 callback: fn 197 }); 198 } 199 }); 200 201 /** 202 * Automatically resize textarea 203 */ 204 $(function() { 205 phpbb.resizeTextArea($('textarea:not(.no-auto-resize)'), {minHeight: 75}); 206 207 var $setPermissionsForm = $('form#set-permissions'); 208 if ($setPermissionsForm.length) { 209 $setPermissionsForm.on('submit', function (e) { 210 submitPermissions(); 211 e.preventDefault(); 212 }); 213 $setPermissionsForm.find('input[type=submit]').click(function() { 214 $('input[type=submit]', $(this).parents($('form#set-permissions'))).removeAttr('data-clicked'); 215 $(this).attr('data-clicked', true); 216 }); 217 } 218 }); 219 220 221 })(jQuery); // Avoid conflicts with other libraries
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |