PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 3.3.9
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v3.3.9
3.3.9 3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 All 67 releases
← All changes | assets/app.js +207 -131 1.20.0 → 3.3.9 View file →
@@ -1,188 +1,264 @@
1 -var LogtivityLogIndex = {
2 -
3 - init: function() {
4 - this.container = jQuery('#logtivity-log-index');
1 +jQuery(function($) {
2 + let LogtivityLogIndex = {
3 + init: function() {
4 + this.container = $('#logtivity-log-index');
5 5
6 - if (!this.container.length) {
7 - return;
8 - }
9 -
10 - this.form = jQuery('#logtivity-log-index-search-form');
6 + if (this.container.length) {
7 + this.form = $('#logtivity-log-index-search-form');
8 + this.listenForPagination();
9 + this.listenForChange();
10 + this.filter();
11 + this.listenForViewLog()
12 + this.listenForCloseModal();
13 + }
14 + },
11 15
12 - this.listenForPagination();
16 + listenForCloseModal: function() {
17 + let listenForCloseModal = this;
13 18
14 - this.listenForChange();
19 + $('body').on('click', '.js-logtivity-notice-dismiss', function(e) {
20 + e.preventDefault();
15 21
16 - this.filter();
22 + listenForCloseModal.hideModal();
23 + });
17 24
18 - this.listenForViewLog()
25 + $(document).on('keyup', function(e) {
26 + if (e.key === 'Escape' && listenForCloseModal.modalOpen) {
27 + listenForCloseModal.hideModal();
28 + }
19 29
20 - this.listenForCloseModal();
21 - },
30 + });
22 31
23 - listenForCloseModal: function() {
32 + $(document).on('keydown', function(e) {
33 + if (e.key !== 'Tab' || !listenForCloseModal.modalOpen) {
34 + return;
35 + }
24 36
25 - var $this = this;
37 + let $focusable = $('#logtivity-log-modal')
38 + .find('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')
39 + .filter(':visible');
26 40
27 - jQuery("body").on( "click", ".js-logtivity-notice-dismiss", function(e) {
28 - e.preventDefault();
41 + if (!$focusable.length) {
42 + return;
43 + }
29 44
30 - $this.hideModal();
45 + let firstFocusable = $focusable[0],
46 + lastFocusable = $focusable[$focusable.length - 1];
31 47
32 - });
48 + if (e.shiftKey && document.activeElement === firstFocusable) {
49 + e.preventDefault();
50 + lastFocusable.focus();
51 + } else if (!e.shiftKey && document.activeElement === lastFocusable) {
52 + e.preventDefault();
53 + firstFocusable.focus();
54 + }
55 + });
33 56
34 - jQuery(document).on('keyup', function(e) {
57 + $(document).mouseup(function(e) {
58 + if (!listenForCloseModal.modalOpen) {
59 + return;
60 + }
35 61
36 - if (e.key == "Escape") {
37 - $this.hideModal();
38 - }
62 + let $container = $('.logtivity-modal-dialog');
39 63
40 - });
64 + // if the target of the click isn't the container nor a descendant of the container
65 + if (!$container.is(e.target) && $container.has(e.target).length === 0) {
66 + listenForCloseModal.hideModal();
67 + }
68 + });
69 + },
41 70
42 - jQuery(document).mouseup(function(e) {
71 + listenForViewLog: function() {
72 + let listenForViewLog = this;
43 73
44 - if (!$this.modalOpen) {
45 - return;
46 - }
74 + $('body').on('click', '.js-logtivity-view-log', function(e) {
75 + e.preventDefault();
47 76
48 - var container = jQuery('.logtivity-modal-dialog');
77 + listenForViewLog.lastFocusedElement = this;
78 + listenForViewLog.showLogModal($(this).next().html());
79 + });
80 + },
49 81
50 - // if the target of the click isn't the container nor a descendant of the container
51 - if (!container.is(e.target) && container.has(e.target).length === 0) {
52 - $this.hideModal();
53 - }
82 + showLogModal: function(modalContent) {
83 + $('.logtivity-modal').attr('aria-hidden', 'false').addClass('active');
54 84
55 - });
85 + this.modalOpen = true;
56 86
57 - },
87 + $('.logtivity-modal-content').html(modalContent);
88 + $('.js-logtivity-notice-dismiss').trigger('focus');
89 + },
58 90
59 - listenForViewLog: function() {
91 + hideModal: function() {
92 + $('.logtivity-modal').attr('aria-hidden', 'true').removeClass('active');
60 93
61 - var $this = this;
94 + this.modalOpen = false;
62 95
63 - jQuery("body").on( "click", ".js-logtivity-view-log", function(e) {
64 - e.preventDefault();
96 + if (this.lastFocusedElement) {
97 + this.lastFocusedElement.focus();
98 + }
99 + },
65 100
66 - $this.showLogModal(jQuery(this).next().html());
67 - });
101 + listenForChange: function() {
102 + let listenForChange = this,
103 + timeout = null;
68 104
69 - },
105 + $('body').on('input', '#logtivity-log-index-search-form input', function(e) {
106 + e.preventDefault();
70 107
71 - showLogModal: function(modalContent) {
108 + $('#logtivity_page').val('');
72 109
73 - jQuery('.logtivity-modal').addClass('active');
110 + // Clear the timeout if it has already been set.
111 + // This will prevent the previous task from executing
112 + // if it has been less than <MILLISECONDS>
113 + clearTimeout(timeout);
74 114
75 - this.modalOpen = true;
115 + // Make a new timeout set to go off in 1000ms
116 + timeout = setTimeout(function() {
117 + listenForChange.filter();
118 + }, 1000);
119 + });
120 + },
76 121
77 - jQuery('.logtivity-modal-content').html(modalContent);
122 + loading: function() {
123 + let $loading = $('<div role="status" style="text-align: center; padding-bottom: 20px">');
78 124
79 - },
125 + $loading.append(
126 + '<div class="spinner is-active" style="float:none;width:auto;height:auto;padding:10px 0 10px 50px;background-position:20px 0;"></div>'
127 + );
128 + $loading.append(
129 + $('<span class="screen-reader-text">').text(logtivityAdminA11y.loadingLogs)
130 + );
80 131
81 - hideModal: function() {
132 + this.container.attr('aria-busy', 'true').empty().append($loading);
133 + },
82 134
83 - jQuery('.logtivity-modal').removeClass('active');
135 + listenForPagination: function() {
136 + let listenForPagination = this;
84 137
85 - this.modalOpen = false;
138 + $('body').on('click', '.js-logtivity-pagination', function(e) {
139 + e.preventDefault();
86 140
87 - },
141 + $('#logtivity_page').val($(this).attr('data-page'));
88 142
89 - listenForChange: function() {
143 + listenForPagination.filter();
144 + });
145 + },
90 146
91 - var $this = this;
147 + filter: function() {
148 + let filter = this;
92 149
93 - var timeout = null;
150 + this.loading();
94 151
95 - jQuery("body").on( "input", "#logtivity-log-index-search-form input", function(e) {
96 - e.preventDefault();
152 + $.ajax({
153 + url : filter.form.attr('action'),
154 + type : 'GET',
155 + data : filter.form.serialize(),
156 + success: function(result) {
157 + filter.container.attr('aria-busy', 'false').html(result.view);
158 + },
159 + error : function(error) {
160 + let $error = $('<div class="notice notice-error" role="alert"><p></p></div>');
97 161
98 - jQuery('#logtivity_page').val('');
162 + $error.find('p').text(logtivityAdminA11y.loadLogsError);
163 + filter.container.attr('aria-busy', 'false').empty().append($error);
164 + }
165 + });
166 + }
167 + };
99 168
100 - // Clear the timeout if it has already been set.
101 - // This will prevent the previous task from executing
102 - // if it has been less than <MILLISECONDS>
103 - clearTimeout(timeout);
169 + let DismissUrlHasChanged = {
170 + init: function() {
171 + $(document).on('click', '.notice-dismiss', function() {
172 + let type = $(this).closest('.is-dismissible').attr('notice'),
173 + dismissUntil = $(this).closest('.is-dismissible').attr('dismiss-until');
104 174
105 - // Make a new timeout set to go off in 1000ms
106 - timeout = setTimeout(function () {
107 -
108 - $this.filter();
175 + if (type) {
176 + $.ajax(ajaxurl, {
177 + type: 'POST',
178 + data: {
179 + action : 'logtivity_dismiss_notice',
180 + _ajax_nonce : logtivityAdmin.dismissNonce,
181 + postType : type,
182 + dismissUntil: dismissUntil,
183 + }
184 + });
185 + }
186 + });
187 + }
188 + };
109 189
110 - }, 1000);
190 + LogtivityLogIndex.init();
191 + DismissUrlHasChanged.init();
111 192
112 - });
193 + let registerMessage = function(message, type) {
194 + type = type || 'info';
113 195
114 - },
196 + let $messaging = $('#logtivity-register-response')
197 + .removeClass()
198 + .addClass('logtivity-notice logtivity-notice-' + type)
199 + .css('width', 'fit-content');
115 200
116 - loading: function() {
201 + if (message) {
202 + $messaging
203 + .css('display', 'block')
204 + .html('<div>' + message + '</div>');
205 + } else {
206 + $messaging
207 + .css('display', 'none')
208 + .html();
209 + }
210 + };
117 211
118 - this.container.html(
119 - '<div style="text-align: center; padding-bottom: 20px"><div class="spinner is-active" style="float:none;width:auto;height:auto;padding:10px 0 10px 50px;background-position:20px 0;"></div></div>'
120 - );
121 -
122 - },
212 + $('#logtivity-register-site').on('submit', function(evt) {
213 + evt.preventDefault();
123 214
124 - listenForPagination: function() {
215 + registerMessage();
125 216
126 - var $this = this;
217 + $.post(this.getAttribute('action'), $(this).serialize())
218 + .success(function(response) {
219 + let success = response.success || false,
220 + responseData = response.data || [],
221 + code = responseData.code || 200;
127 222
128 - jQuery("body").on( "click", ".js-logtivity-pagination", function(e) {
129 - e.preventDefault();
223 + console.log(responseData);
224 + console.log(response);
130 225
131 - jQuery('#logtivity_page').val(jQuery(this).attr('data-page'));
226 + if (success && code === 200) {
227 + registerMessage(responseData.message);
132 228
133 - $this.filter();
134 - });
229 + } else if (success) {
230 + let message = '<h2>' + code + ': ' + responseData.error + '<h2>';
231 + if (responseData.error !== responseData.message) {
232 + message += responseData.message;
233 + }
135 234
136 - },
235 + registerMessage(message, 'danger');
137 236
138 - filter: function() {
237 + } else if (typeof responseData == 'string') {
238 + registerMessage(responseData, 'danger');
139 239
140 - this.loading();
240 + } else if (typeof responseData.forEach !== 'undefined') {
241 + let message = '';
242 + responseData.forEach(function(error) {
243 + message += '<p>' + error.message + '</p>';
244 + });
245 + registerMessage(message, 'danger');
141 246
142 - var $this = this;
247 + } else {
248 + console.log(response);
249 + registerMessage('Unknown Response', 'danger')
250 + }
143 251
144 - jQuery.ajax({
145 - url: $this.form.attr('action'),
146 - type: 'GET',
147 - data: $this.form.serialize(),
148 - success: function(result) {
149 - $this.container.html(result.view);
150 - },
151 - error: function(error) {
152 - console.log(error);
153 - }
154 - });
252 + })
253 + .error(function($xhr) {
254 + let message = 'Unknown Error'
255 + if ($xhr.responseJSON) {
256 + message = $xhr.responseJSON.data || message;
257 + } else if ($xhr.responseText) {
258 + message = $xhr.responseText;
259 + }
155 260
156 - }
157 -
158 -};
159 -
160 -var DismissUrlHasChanged = {
161 -
162 - init: function() {
163 -
164 - jQuery( document ).on( 'click', '.notice-dismiss', function () {
165 - var type = jQuery(this).closest('.is-dismissible').attr('notice');
166 - var dismissUntil = jQuery(this).closest('.is-dismissible').attr('dismiss-until');
167 -
168 - if (type) {
169 - jQuery.ajax( ajaxurl, {
170 - type: 'POST',
171 - data: {
172 - action: 'logtivity_dismiss_notice',
173 - type: type,
174 - dismiss_until: dismissUntil,
175 - }
176 - });
177 - }
178 -
179 - });
180 -
181 - }
182 -
183 -};
184 -
185 -jQuery(function() {
186 - LogtivityLogIndex.init();
187 - DismissUrlHasChanged.init();
188 -});
261 + registerMessage(message, 'danger');
262 + });
263 + });
264 +});