Advanced Access Manager - Version 4.9.5

Version Description

  • Improved user experience with AAM UI
  • Removed Welcome message
  • Fixed bug with media access
  • Added filter for AAM shordcodes so other plugins can hook to AAM
  • Optimized AAM javascript
  • Removed subscription box to reduce "UI noise" as more features are coming
Download this release

Release Info

Developer vasyl_m
Plugin Icon 128x128 Advanced Access Manager
Version 4.9.5
Comparing to
See all releases

Code changes from version 4.9.4 to 4.9.5

Application/Backend/Manager.php CHANGED
@@ -425,7 +425,6 @@ class AAM_Backend_Manager {
425
  'ajaxurl' => admin_url('admin-ajax.php'),
426
  'url' => array(
427
  'site' => admin_url('index.php'),
428
- 'jsbase' => AAM_MEDIA . '/js',
429
  'editUser' => admin_url('user-edit.php'),
430
  'addUser' => admin_url('user-new.php')
431
  ),
425
  'ajaxurl' => admin_url('admin-ajax.php'),
426
  'url' => array(
427
  'site' => admin_url('index.php'),
 
428
  'editUser' => admin_url('user-edit.php'),
429
  'addUser' => admin_url('user-new.php')
430
  ),
Application/Backend/View.php CHANGED
@@ -221,32 +221,6 @@ class AAM_Backend_View {
221
  return $this->getSubject()->resetObject(AAM_Core_Request::post('object'));
222
  }
223
 
224
- /**
225
- *
226
- * @return type
227
- */
228
- public function subscribe() {
229
- $email = filter_var(
230
- AAM_Core_Request::post('email'), FILTER_VALIDATE_EMAIL
231
- );
232
-
233
- if ($email) {
234
- $response = AAM_Core_Server::subscribe($email);
235
- } else {
236
- $response = array(
237
- 'status' => 'failure', 'reason' => __('Invalid Email', AAM_KEY)
238
- );
239
- }
240
-
241
- if (is_wp_error($response)) {
242
- $response = array(
243
- 'status' => 'failure', 'reason' => $response->get_error_message()
244
- );
245
- }
246
-
247
- return json_encode($response);
248
- }
249
-
250
  /**
251
  *
252
  * @return type
221
  return $this->getSubject()->resetObject(AAM_Core_Request::post('object'));
222
  }
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  /**
225
  *
226
  * @return type
Application/Backend/phtml/index.phtml CHANGED
@@ -15,7 +15,9 @@
15
  <span class="aam-help-menu" data-target="#access-manager-inside"><i class="icon-help-circled"></i></span>
16
  </h3>
17
  <div class="inside" id="access-manager-inside">
18
- <div class="aam-postbox-inside" id="aam-content"></div>
 
 
19
  <div class="aam-help-context" >
20
  <div class="text-justify aam-large-padding">
21
  <p class="text-larger"><?php echo __('Appreciate your interest in Advanced Access Manager (AAM). With strong knowledge and experience in WordPress, AAM becomes a very powerful tool to manage access to your frontend and backend.', AAM_KEY); ?></p>
@@ -269,21 +271,6 @@
269
  <p class="aam-promo"><strong>NEED HELP FASTER?</strong><br/>Get in touch with Google Hangouts.<br/><b>It is free.</b></p>
270
  <a href="mailto:support@aamplugin.com" class="btn btn-success" target="_blank"><i class="icon-chat-empty"></i> support@aamplugin.com</a>
271
  </div>
272
-
273
- <hr/>
274
-
275
- <label for="extension-key"><?php echo __('Subscribe to updates', AAM_KEY); ?></label><a href="#" data-toggle="tooltip" title="<?php echo __('Get once a month the email with the latest AAM features and promo-codes', AAM_KEY) ?>"><i class="icon-help-circled"></i></a>
276
- <div class="row">
277
- <div class="col-xs-8">
278
- <div class="form-group">
279
- <input type="text" class="form-control" id="subscribe-email" placeholder="<?php echo __('Your Email Address', AAM_KEY); ?>" />
280
- </div>
281
- </div>
282
- <div class="col-xs-4">
283
- <button class="btn btn-primary btn-block" id="subscribe"><i class="icon-rss"></i> <?php echo __('Submit', AAM_KEY); ?></button>
284
- </div>
285
- </div>
286
-
287
  </div>
288
  </div>
289
  </div>
15
  <span class="aam-help-menu" data-target="#access-manager-inside"><i class="icon-help-circled"></i></span>
16
  </h3>
17
  <div class="inside" id="access-manager-inside">
18
+ <div class="aam-postbox-inside" id="aam-content">
19
+ <p class="alert alert-info text-larger text-center" id="aam-initial-load"><?php echo AAM_Backend_View_Helper::preparePhrase('[Loading AAM UI]. Please wait few seconds. If content will not load within next 30 seconds, clear your browser cache and reload the page. If still nothing, it is most likely some sort of JavaScript or CSS conflict with one your active plugins or theme. [Contact as immediately if you are having troubles with loading AAM].', 'strong', 'strong'); ?></p>
20
+ </div>
21
  <div class="aam-help-context" >
22
  <div class="text-justify aam-large-padding">
23
  <p class="text-larger"><?php echo __('Appreciate your interest in Advanced Access Manager (AAM). With strong knowledge and experience in WordPress, AAM becomes a very powerful tool to manage access to your frontend and backend.', AAM_KEY); ?></p>
271
  <p class="aam-promo"><strong>NEED HELP FASTER?</strong><br/>Get in touch with Google Hangouts.<br/><b>It is free.</b></p>
272
  <a href="mailto:support@aamplugin.com" class="btn btn-success" target="_blank"><i class="icon-chat-empty"></i> support@aamplugin.com</a>
273
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  </div>
275
  </div>
276
  </div>
Application/Core/Media.php CHANGED
@@ -45,14 +45,6 @@ class AAM_Core_Media {
45
  */
46
  protected function __construct() {
47
  if (AAM_Core_Request::get('aam-media')) {
48
- if (AAM_Core_Request::get('debug')) {
49
- file_put_contents(
50
- dirname(__FILE__) . '/debug.log',
51
- print_r(AAM_Core_Request::server(), 1) . "\n",
52
- FILE_APPEND
53
- );
54
- }
55
-
56
  $this->initialize();
57
 
58
  if (AAM_Core_Config::get('media-access-control', false)) {
@@ -142,16 +134,20 @@ class AAM_Core_Media {
142
  }
143
 
144
  //normalize path and strip all unexpected trails. Thanks to Antonius Hegyes
145
- $path = preg_replace('/\?.*$/', '', $path);
 
 
 
 
146
 
147
  if (empty($mime)) {
148
  if (function_exists('mime_content_type')) {
149
- $mime = mime_content_type($path);
150
  }
151
  }
152
 
153
  @header('Content-Type: ' . (empty($mime) ? $type : $mime));
154
- echo file_get_contents($path);
155
  exit;
156
  }
157
 
45
  */
46
  protected function __construct() {
47
  if (AAM_Core_Request::get('aam-media')) {
 
 
 
 
 
 
 
 
48
  $this->initialize();
49
 
50
  if (AAM_Core_Config::get('media-access-control', false)) {
134
  }
135
 
136
  //normalize path and strip all unexpected trails. Thanks to Antonius Hegyes
137
+ $path = preg_replace('/\?.*$/', '', $path);
138
+ $rpath = preg_replace('/\?.*$/', '', $this->request_uri);
139
+
140
+ //finally replace the filename with requested filename
141
+ $request = str_replace(basename($path), basename($rpath), $path);
142
 
143
  if (empty($mime)) {
144
  if (function_exists('mime_content_type')) {
145
+ $mime = mime_content_type($request);
146
  }
147
  }
148
 
149
  @header('Content-Type: ' . (empty($mime) ? $type : $mime));
150
+ echo file_get_contents($request);
151
  exit;
152
  }
153
 
Application/Core/Server.php CHANGED
@@ -62,8 +62,7 @@ final class AAM_Core_Server {
62
  $params = array(
63
  'domain' => parse_url(site_url(), PHP_URL_HOST),
64
  'version' => AAM_Core_API::version(),
65
- 'uid' => AAM_Core_API::getOption('aam-uid', null, 'site'),
66
- 'email' => AAM_Core_API::getOption('admin_email')
67
  );
68
 
69
  $response = self::send('/check', $params);
@@ -113,31 +112,6 @@ final class AAM_Core_Server {
113
  return $result;
114
  }
115
 
116
- /**
117
- * Subscribe to updates
118
- *
119
- * @param string $email
120
- *
121
- * @return array
122
- *
123
- * @access public
124
- */
125
- public static function subscribe($email) {
126
- $response = self::send('/subscribe', array('email' => $email));
127
-
128
- if (!is_wp_error($response)) {
129
- if ($response->error === true) {
130
- $result = new WP_Error($response->code, $response->message);
131
- } else {
132
- $result = $response;
133
- }
134
- } else {
135
- $result = $response;
136
- }
137
-
138
- return $result;
139
- }
140
-
141
  /**
142
  * Send request
143
  *
62
  $params = array(
63
  'domain' => parse_url(site_url(), PHP_URL_HOST),
64
  'version' => AAM_Core_API::version(),
65
+ 'uid' => AAM_Core_API::getOption('aam-uid', null, 'site')
 
66
  );
67
 
68
  $response = self::send('/check', $params);
112
  return $result;
113
  }
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  /**
116
  * Send request
117
  *
Application/Shortcode/Factory.php CHANGED
@@ -36,7 +36,7 @@ class AAM_Shortcode_Factory {
36
  $this->strategy = new $classname($args, $content);
37
  } else {
38
  $this->strategy = apply_filters(
39
- 'aam-shortcode-context-filter', null, $args, $content
40
  );
41
  }
42
  }
36
  $this->strategy = new $classname($args, $content);
37
  } else {
38
  $this->strategy = apply_filters(
39
+ 'aam-shortcode-filter', null, $context, $args, $content
40
  );
41
  }
42
  }
aam.php CHANGED
@@ -3,7 +3,7 @@
3
  /**
4
  Plugin Name: Advanced Access Manager
5
  Description: All you need to manage access to your WordPress website
6
- Version: 4.9.4
7
  Author: Vasyl Martyniuk <vasyl@vasyltech.com>
8
  Author URI: https://vasyltech.com
9
 
3
  /**
4
  Plugin Name: Advanced Access Manager
5
  Description: All you need to manage access to your WordPress website
6
+ Version: 4.9.5
7
  Author: Vasyl Martyniuk <vasyl@vasyltech.com>
8
  Author URI: https://vasyltech.com
9
 
media/js/aam-interface.js DELETED
@@ -1,2712 +0,0 @@
1
- /**
2
- * ======================================================================
3
- * LICENSE: This file is subject to the terms and conditions defined in *
4
- * file 'license.txt', which is part of this source code package. *
5
- * ======================================================================
6
- */
7
-
8
- /**
9
- * Role List Interface
10
- *
11
- * @param {jQuery} $
12
- *
13
- * @returns {void}
14
- */
15
- (function ($) {
16
-
17
- /**
18
- *
19
- * @param {type} id
20
- * @returns {Boolean}
21
- */
22
- function isCurrent(id) {
23
- var subject = aam.getSubject();
24
-
25
- return (subject.type === 'role' && subject.id === id);
26
- }
27
-
28
- /**
29
- *
30
- * @returns {undefined}
31
- */
32
- function fetchRoleList(exclude) {
33
- $.ajax(aamLocal.ajaxurl, {
34
- type: 'POST',
35
- dataType: 'json',
36
- data: {
37
- action: 'aam',
38
- sub_action: 'Role.getList',
39
- _ajax_nonce: aamLocal.nonce,
40
- exclude: exclude
41
- },
42
- beforeSend: function () {
43
- $('.inherit-role-list').html(
44
- '<option value="">' + aam.__('Loading...') + '</option>'
45
- );
46
- },
47
- success: function (response) {
48
- $('.inherit-role-list').html(
49
- '<option value="">' + aam.__('No Role') + '</option>'
50
- );
51
- for (var i in response) {
52
- $('.inherit-role-list').append(
53
- '<option value="' + i + '">' + response[i].name + '</option>'
54
- );
55
- }
56
- if ($.aamEditRole) {
57
- $('#inherit-role').val($.aamEditRole[0]);
58
- }
59
- aam.triggerHook('post-get-role-list', {
60
- list : response
61
- });
62
- //TODO - Rerwite JavaScript to support $.aam
63
- $.aamEditRole = null;
64
- }
65
- });
66
- }
67
-
68
- //initialize the role list table
69
- $('#role-list').DataTable({
70
- autoWidth: false,
71
- ordering: false,
72
- dom: 'ftrip',
73
- pagingType: 'simple',
74
- processing: true,
75
- serverSide: false,
76
- ajax: {
77
- url: aamLocal.ajaxurl,
78
- type: 'POST',
79
- dataType: 'json',
80
- data: {
81
- action: 'aam',
82
- sub_action: 'Role.getTable',
83
- _ajax_nonce: aamLocal.nonce
84
- }
85
- },
86
- columnDefs: [
87
- {visible: false, targets: [0, 1, 4, 5]}
88
- ],
89
- language: {
90
- search: '_INPUT_',
91
- searchPlaceholder: aam.__('Search Role'),
92
- info: aam.__('_TOTAL_ role(s)'),
93
- infoFiltered: ''
94
- },
95
- initComplete: function () {
96
- if (!aam.isUI() && parseInt(aamLocal.caps.create_roles)) {
97
- var create = $('<a/>', {
98
- 'href': '#',
99
- 'class': 'btn btn-primary'
100
- }).html('<i class="icon-plus"></i> ' + aam.__('Create'))
101
- .bind('click', function () {
102
- $('#add-role-modal').modal('show');
103
- });
104
-
105
- $('.dataTables_filter', '#role-list_wrapper').append(create);
106
- }
107
- },
108
- createdRow: function (row, data) {
109
- if (isCurrent(data[0])) {
110
- $('td:eq(0)', row).html('<strong class="aam-highlight">' + data[2] + '</strong>');
111
- } else {
112
- $('td:eq(0)', row).html('<span>' + data[2] + '</span>');
113
- }
114
-
115
- $(row).attr('data-id', data[0]);
116
-
117
- //add subtitle
118
- var expire = (data[5] ? '; <i class="icon-clock"></i>' : '');
119
- $('td:eq(0)', row).append(
120
- $('<i/>', {'class': 'aam-row-subtitle'}).html(
121
- aam.__('Users') + ': <b>' + parseInt(data[1]) + '</b>; ID: <b>' + data[0] + '</b>' + expire
122
- )
123
- );
124
-
125
- var actions = data[3].split(',');
126
-
127
- var container = $('<div/>', {'class': 'aam-row-actions'});
128
- $.each(actions, function (i, action) {
129
- switch (action) {
130
- case 'manage':
131
- $(container).append($('<i/>', {
132
- 'class': 'aam-row-action icon-cog ' + (isCurrent(data[0]) ? 'text-muted': 'text-info')
133
- }).bind('click', function () {
134
- if (!$(this).prop('disabled')) {
135
- $(this).prop('disabled', true);
136
- var title = $('td:eq(0) span', row).html();
137
- aam.setSubject('role', data[0], title, data[4]);
138
- $('td:eq(0) span', row).replaceWith(
139
- '<strong class="aam-highlight">' + title + '</strong>'
140
- );
141
- $('i.icon-cog', container).attr(
142
- 'class', 'aam-row-action icon-cog text-muted'
143
- );
144
- if (!aam.isUI()) {
145
- $('i.icon-cog', container).attr(
146
- 'class', 'aam-row-action icon-spin4 animate-spin'
147
- );
148
- aam.fetchContent();
149
- $('i.icon-spin4', container).attr(
150
- 'class', 'aam-row-action icon-cog text-muted'
151
- );
152
- } else {
153
- $.aam.loadAccessForm($('#load-post-object-type').val(), $('#load-post-object').val(), $(this));
154
- }
155
- }
156
- }).attr({
157
- 'data-toggle': "tooltip",
158
- 'title': aam.__('Manage Role')
159
- }).prop('disabled', (isCurrent(data[0]) ? true: false)));
160
- break;
161
-
162
- case 'edit':
163
- if (!aam.isUI()) {
164
- $(container).append($('<i/>', {
165
- 'class': 'aam-row-action icon-pencil text-warning'
166
- }).bind('click', function () {
167
- $('#edit-role-btn').data('role', data[0]);
168
- $('#edit-role-name').val(data[2]);
169
- $('#edit-role-expiration').val(data[5]);
170
- $('#edit-role-modal').modal('show');
171
- fetchRoleList(data[0]);
172
- //TODO - Rerwite JavaScript to support $.aam
173
- $.aamEditRole = data;
174
- }).attr({
175
- 'data-toggle': "tooltip",
176
- 'title': aam.__('Edit Role')
177
- }));
178
- }
179
- break;
180
-
181
- case 'clone':
182
- if (!aam.isUI()) {
183
- $(container).append($('<i/>', {
184
- 'class': 'aam-row-action icon-clone text-success'
185
- }).bind('click', function () {
186
- //TODO - Rerwite JavaScript to support $.aam
187
- $.aamEditRole = data;
188
- $('#clone-role').prop('checked', true);
189
- $('#add-role-modal').modal('show');
190
- }).attr({
191
- 'data-toggle': "tooltip",
192
- 'title': aam.__('Clone Role')
193
- }));
194
- }
195
- break;
196
-
197
- case 'delete':
198
- if (!aam.isUI()) {
199
- $(container).append($('<i/>', {
200
- 'class': 'aam-row-action icon-trash-empty text-danger'
201
- }).bind('click', {role: data}, function (event) {
202
- $('#delete-role-btn').data('role', data[0]);
203
- var message = $('#delete-role-modal .aam-confirm-message').data('message');
204
- $('#delete-role-modal .aam-confirm-message').html(
205
- message.replace(
206
- '%s', '<strong>' + event.data.role[2] + '</strong>'
207
- )
208
- );
209
-
210
- $('#delete-role-modal').modal('show');
211
- }).attr({
212
- 'data-toggle': "tooltip",
213
- 'title': aam.__('Delete Role')
214
- }));
215
- }
216
- break;
217
-
218
- default:
219
- if (!aam.isUI()) {
220
- aam.triggerHook('role-action', {
221
- container: container,
222
- action : action,
223
- data : data
224
- });
225
- }
226
- break;
227
- }
228
- });
229
- $('td:eq(1)', row).html(container);
230
-
231
- aam.triggerHook('decorate-role-row', {
232
- row : row,
233
- data: data
234
- });
235
- }
236
- });
237
-
238
- $('#role-list').on( 'draw.dt', function () {
239
- $('tr', '#role-list tbody').each(function() {
240
- if (!isCurrent($(this).data('id'))) {
241
- $('td:eq(0) strong', this).replaceWith(
242
- '<span>' + $('td:eq(0) strong', this).text() + '</span>'
243
- );
244
- $('.text-muted', this).attr('disabled', false);
245
- $('.text-muted', this).toggleClass('text-muted text-info');
246
- }
247
- });
248
- } );
249
-
250
- $('#add-role-modal').on('shown.bs.modal', function (e) {
251
- fetchRoleList();
252
- //clear add role form first
253
- $('input[name="name"]', '#add-role-modal').val('').focus();
254
- });
255
-
256
- $('#edit-role-modal').on('shown.bs.modal', function (e) {
257
- $('input[name="name"]', '#edit-role-modal').focus();
258
- });
259
-
260
- //add role button
261
- $('#add-role-btn').bind('click', function () {
262
- var _this = this;
263
-
264
- $('input[name="name"]', '#add-role-modal').parent().removeClass('has-error');
265
-
266
- var data = {
267
- action: 'aam',
268
- sub_action: 'Role.add',
269
- _ajax_nonce: aamLocal.nonce
270
- };
271
-
272
- $('input,select', '#add-role-modal .modal-body').each(function() {
273
- if ($(this).attr('type') === 'checkbox') {
274
- data[$(this).attr('name')] = $(this).prop('checked') ? 1 : 0;
275
- } else {
276
- data[$(this).attr('name')] = $.trim($(this).val());
277
- }
278
- });
279
-
280
- if (data.name) {
281
- $.ajax(aamLocal.ajaxurl, {
282
- type: 'POST',
283
- dataType: 'json',
284
- data: data,
285
- beforeSend: function () {
286
- $(_this).text(aam.__('Saving...')).attr('disabled', true);
287
- },
288
- success: function (response) {
289
- if (response.status === 'success') {
290
- $('#role-list').DataTable().ajax.reload();
291
- aam.setSubject(
292
- 'role',
293
- response.role.id,
294
- response.role.name,
295
- response.role.level
296
- );
297
- aam.fetchContent();
298
- $('#add-role-modal').modal('hide');
299
- } else {
300
- aam.notification(
301
- 'danger', aam.__('Failed to add new role')
302
- );
303
- }
304
- },
305
- error: function () {
306
- aam.notification('danger', aam.__('Application error'));
307
- },
308
- complete: function () {
309
- $(_this).text(aam.__('Add Role')).attr('disabled', false);
310
- }
311
- });
312
- } else {
313
- $('input,select', '#add-role-modal .modal-body').focus().parent().addClass('has-error');
314
- }
315
- });
316
-
317
- //edit role button
318
- $('#edit-role-btn').bind('click', function (event) {
319
- var _this = this;
320
-
321
- $('#edit-role-name').parent().removeClass('has-error');
322
-
323
- var data = {
324
- action: 'aam',
325
- sub_action: 'Role.edit',
326
- _ajax_nonce: aamLocal.nonce,
327
- subject: 'role',
328
- subjectId: $(_this).data('role')
329
- };
330
-
331
- $('input,select', '#edit-role-modal .modal-body').each(function() {
332
- data[$(this).attr('name')] = $.trim($(this).val());
333
- });
334
-
335
- if (data.name) {
336
- $.ajax(aamLocal.ajaxurl, {
337
- type: 'POST',
338
- dataType: 'json',
339
- data: data,
340
- beforeSend: function () {
341
- $(_this).text(aam.__('Saving...')).attr('disabled', true);
342
- },
343
- success: function (response) {
344
- if (response.status === 'success') {
345
- $('#role-list').DataTable().ajax.reload();
346
- } else {
347
- aam.notification(
348
- 'danger', aam.__('Failed to update role')
349
- );
350
- }
351
- },
352
- error: function () {
353
- aam.notification('danger', aam.__('Application error'));
354
- },
355
- complete: function () {
356
- $('#edit-role-modal').modal('hide');
357
- $(_this).text(aam.__('Update')).attr('disabled', false);
358
- }
359
- });
360
- } else {
361
- $('#edit-role-name').focus().parent().addClass('has-error');
362
- }
363
- });
364
-
365
- //edit role button
366
- $('#delete-role-btn').bind('click', function (event) {
367
- var _this = this;
368
-
369
- $.ajax(aamLocal.ajaxurl, {
370
- type: 'POST',
371
- dataType: 'json',
372
- data: {
373
- action: 'aam',
374
- sub_action: 'Role.delete',
375
- _ajax_nonce: aamLocal.nonce,
376
- subject: 'role',
377
- subjectId: $(_this).data('role')
378
- },
379
- beforeSend: function () {
380
- $(_this).text(aam.__('Deleting...')).attr('disabled', true);
381
- },
382
- success: function (response) {
383
- if (response.status === 'success') {
384
- $('#role-list').DataTable().ajax.reload();
385
- } else {
386
- aam.notification('danger', aam.__('Failed to delete role'));
387
- }
388
- },
389
- error: function () {
390
- aam.notification('danger', aam.__('Application error'));
391
- },
392
- complete: function () {
393
- $('#delete-role-modal').modal('hide');
394
- $(_this).text(aam.__('Delete Role')).attr('disabled', false);
395
- }
396
- });
397
- });
398
-
399
- //add setSubject hook
400
- aam.addHook('setSubject', function () {
401
- //clear highlight
402
- $('tbody tr', '#role-list').each(function () {
403
- if ($('strong', $(this)).length) {
404
- var highlight = $('strong', $(this));
405
- $('.icon-cog', $(this)).toggleClass('text-muted text-info');
406
- $('.icon-cog', $(this)).prop('disabled', false);
407
- highlight.replaceWith($('<span/>').text(highlight.text()));
408
- }
409
- });
410
- //show post & pages access control groups that belong to backend
411
- $('.aam-backend-post-access').show();
412
- });
413
-
414
- //in case interface needed to be reloaded
415
- aam.addHook('refresh', function () {
416
- $('#role-list').DataTable().ajax.url(aamLocal.ajaxurl).load();
417
- });
418
-
419
- })(jQuery);
420
-
421
-
422
- /**
423
- * User List Interface
424
- *
425
- * @param {jQuery} $
426
- *
427
- * @returns {void}
428
- */
429
- (function ($) {
430
-
431
- /**
432
- *
433
- * @param {type} id
434
- * @returns {Boolean}
435
- */
436
- function isCurrent(id) {
437
- var subject = aam.getSubject();
438
-
439
- return (subject.type === 'user' && parseInt(subject.id) === id);
440
- }
441
-
442
- /**
443
- *
444
- * @param {type} id
445
- * @param {type} btn
446
- * @returns {undefined}
447
- */
448
- function blockUser(id, btn) {
449
- var state = ($(btn).hasClass('icon-lock') ? 0 : 1);
450
-
451
- $.ajax(aamLocal.ajaxurl, {
452
- type: 'POST',
453
- dataType: 'json',
454
- data: {
455
- action: 'aam',
456
- sub_action: 'User.block',
457
- _ajax_nonce: aamLocal.nonce,
458
- subject: 'user',
459
- subjectId: id
460
- },
461
- beforeSend: function () {
462
- $(btn).attr('class', 'aam-row-action icon-spin4 animate-spin');
463
- },
464
- success: function (response) {
465
- if (response.status === 'success') {
466
- if (state === 1) {
467
- $(btn).attr({
468
- 'class': 'aam-row-action icon-lock text-danger',
469
- 'title': aam.__('Unlock User'),
470
- 'data-original-title': aam.__('Unlock User')
471
- });
472
- } else {
473
- $(btn).attr({
474
- 'class': 'aam-row-action icon-lock-open-alt text-warning',
475
- 'title': aam.__('Lock User'),
476
- 'data-original-title': aam.__('Lock User')
477
- });
478
- }
479
- } else {
480
- aam.notification('danger', aam.__('Failed to block user'));
481
- }
482
- },
483
- error: function () {
484
- aam.notification('danger', aam.__('Application error'));
485
- }
486
- });
487
- }
488
-
489
- /**
490
- *
491
- * @param {type} id
492
- * @param {type} btn
493
- * @returns {undefined}
494
- */
495
- function switchToUser(id, btn) {
496
- $.ajax(aamLocal.ajaxurl, {
497
- type: 'POST',
498
- dataType: 'json',
499
- data: {
500
- action: 'aam',
501
- sub_action: 'switchToUser',
502
- _ajax_nonce: aamLocal.nonce,
503
- user: id
504
- },
505
- beforeSend: function () {
506
- $(btn).attr('class', 'aam-row-action icon-spin4 animate-spin');
507
- },
508
- success: function (response) {
509
- if (response.status === 'success') {
510
- location.href = response.redirect;
511
- } else {
512
- aam.notification('danger', response.reason);
513
- }
514
- },
515
- error: function () {
516
- aam.notification('danger', aam.__('Application error'));
517
- },
518
- complete: function () {
519
- $(btn).attr('class', 'aam-row-action icon-exchange text-success');
520
- }
521
- });
522
- }
523
-
524
- //initialize the user list table
525
- $('#user-list').DataTable({
526
- autoWidth: false,
527
- ordering: false,
528
- dom: 'ftrip',
529
- pagingType: 'simple',
530
- serverSide: true,
531
- processing: true,
532
- ajax: {
533
- url: aamLocal.ajaxurl,
534
- type: 'POST',
535
- dataType: 'json',
536
- data: {
537
- action: 'aam',
538
- sub_action: 'User.getTable',
539
- _ajax_nonce: aamLocal.nonce
540
- }
541
- },
542
- columnDefs: [
543
- {visible: false, targets: [0, 1, 4]}
544
- ],
545
- language: {
546
- search: '_INPUT_',
547
- searchPlaceholder: aam.__('Search User'),
548
- info: aam.__('_TOTAL_ user(s)'),
549
- infoFiltered: ''
550
- },
551
- initComplete: function () {
552
- if (!aam.isUI() && parseInt(aamLocal.caps.create_users)) {
553
- var create = $('<a/>', {
554
- 'href': '#',
555
- 'class': 'btn btn-primary'
556
- }).html('<i class="icon-plus"></i> ' + aam.__('Create')).bind('click', function () {
557
- window.open(aamLocal.url.addUser, '_blank');
558
- });
559
-
560
- $('.dataTables_filter', '#user-list_wrapper').append(create);
561
- }
562
- },
563
- createdRow: function (row, data) {
564
- if (isCurrent(data[0])) {
565
- $('td:eq(0)', row).html('<strong class="aam-highlight">' + data[2] + '</strong>');
566
- } else {
567
- $('td:eq(0)', row).html('<span>' + data[2] + '</span>');
568
- }
569
-
570
- //add subtitle
571
- $('td:eq(0)', row).append(
572
- $('<i/>', {'class': 'aam-row-subtitle'}).html(
573
- aam.__('Role') + ': ' + data[1] + '; ID: <b>' + data[0] + '</b>'
574
- )
575
- );
576
-
577
- var actions = data[3].split(',');
578
- var container = $('<div/>', {'class': 'aam-row-actions'});
579
-
580
- if ($.trim(data[3])) {
581
- $.each(actions, function (i, action) {
582
- switch (action) {
583
- case 'manage':
584
- $(container).append($('<i/>', {
585
- 'class': 'aam-row-action icon-cog ' + (isCurrent(data[0]) ? 'text-muted': 'text-info')
586
- }).bind('click', function () {
587
- if (!$(this).prop('disabled')) {
588
- $(this).prop('disabled', true);
589
- aam.setSubject('user', data[0], data[2], data[4]);
590
- $('td:eq(0) span', row).replaceWith(
591
- '<strong class="aam-highlight">' + data[2] + '</strong>'
592
- );
593
- $('i.icon-cog', container).attr('class', 'aam-row-action icon-cog text-muted');
594
-
595
- if (!aam.isUI()) {
596
- $('i.icon-cog', container).attr('class', 'aam-row-action icon-spin4 animate-spin');
597
- aam.fetchContent();
598
- $('i.icon-spin4', container).attr('class', 'aam-row-action icon-cog text-muted');
599
- } else {
600
- $.aam.loadAccessForm($('#load-post-object-type').val(), $('#load-post-object').val(), $(this));
601
- }
602
- }
603
- }).attr({
604
- 'data-toggle': "tooltip",
605
- 'title': aam.__('Manage User')
606
- })).prop('disabled', (isCurrent(data[0]) ? true: false));
607
- break;
608
-
609
- case 'edit':
610
- if (!aam.isUI()) {
611
- $(container).append($('<i/>', {
612
- 'class': 'aam-row-action icon-pencil text-info'
613
- }).bind('click', function () {
614
- window.open(
615
- aamLocal.url.editUser + '?user_id=' + data[0], '_blank'
616
- );
617
- }).attr({
618
- 'data-toggle': "tooltip",
619
- 'title': aam.__('Edit User')
620
- }));
621
- }
622
- break;
623
-
624
- case 'lock':
625
- if (!aam.isUI()) {
626
- $(container).append($('<i/>', {
627
- 'class': 'aam-row-action icon-lock-open-alt text-warning'
628
- }).bind('click', function () {
629
- blockUser(data[0], $(this));
630
- }).attr({
631
- 'data-toggle': "tooltip",
632
- 'title': aam.__('Lock User')
633
- }));
634
- }
635
- break;
636
-
637
- case 'unlock':
638
- if (!aam.isUI()) {
639
- $(container).append($('<i/>', {
640
- 'class': 'aam-row-action icon-lock text-danger'
641
- }).bind('click', function () {
642
- blockUser(data[0], $(this));
643
- }).attr({
644
- 'data-toggle': "tooltip",
645
- 'title': aam.__('Unlock User')
646
- }));
647
- }
648
- break;
649
-
650
- case 'switch':
651
- if (!aam.isUI()) {
652
- $(container).append($('<i/>', {
653
- 'class': 'aam-row-action icon-exchange text-success'
654
- }).bind('click', function () {
655
- switchToUser(data[0], $(this));
656
- }).attr({
657
- 'data-toggle': "tooltip",
658
- 'title': aam.__('Switch To User')
659
- }));
660
- }
661
- break;
662
-
663
- default:
664
- break;
665
- }
666
- });
667
- } else {
668
- $(container).append($('<i/>', {
669
- 'class': 'aam-row-action text-muted'
670
- }).text('---'));
671
- }
672
- $('td:eq(1)', row).html(container);
673
- }
674
- });
675
-
676
- //add setSubject hook
677
- aam.addHook('setSubject', function () {
678
- //clear highlight
679
- $('tbody tr', '#user-list').each(function () {
680
- if ($('strong', $(this)).length) {
681
- var highlight = $('strong', $(this));
682
- $('.icon-cog', $(this)).toggleClass('text-muted text-info');
683
- $('.icon-cog', $(this)).prop('disabled', false);
684
- highlight.replaceWith('<span>' + highlight.text() + '</span>');
685
- }
686
- });
687
- //show post & pages access control groups that belong to backend
688
- $('.aam-backend-post-access').show();
689
- });
690
-
691
- //in case interface needed to be reloaded
692
- aam.addHook('refresh', function () {
693
- $('#user-list').DataTable().ajax.url(aamLocal.ajaxurl).load();
694
- });
695
-
696
- })(jQuery);
697
-
698
-
699
- /**
700
- * Visitor Interface
701
- *
702
- * @param {jQuery} $
703
- *
704
- * @returns {void}
705
- */
706
- (function ($) {
707
-
708
- $('document').ready(function() {
709
- $('#manage-visitor').bind('click', function () {
710
- var _this = this;
711
-
712
- aam.setSubject('visitor', null, aam.__('Anonymous'), 0);
713
- $('i.icon-cog', $(this)).attr('class', 'icon-spin4 animate-spin');
714
-
715
- if (!aam.isUI()) {
716
- aam.fetchContent();
717
- $('i.icon-spin4', $(this)).attr('class', 'icon-cog');
718
- } else {
719
- $.aam.loadAccessForm($('#load-post-object-type').val(), $('#load-post-object').val(), null, function () {
720
- $('i.icon-spin4', $(_this)).attr('class', 'icon-cog');
721
- });
722
- }
723
- //hide post & pages access control groups that belong to backend
724
- $('.aam-backend-post-access').hide();
725
- });
726
- });
727
-
728
- })(jQuery);
729
-
730
- /**
731
- * Default Interface
732
- *
733
- * @param {jQuery} $
734
- *
735
- * @returns {void}
736
- */
737
- (function ($) {
738
-
739
- $('document').ready(function() {
740
- $('#manage-default').bind('click', function () {
741
- var _this = this;
742
-
743
- aam.setSubject('default', null, aam.__('All Users, Roles and Visitor'), 0);
744
- $('i.icon-cog', $(this)).attr('class', 'icon-spin4 animate-spin');
745
- if (!aam.isUI()) {
746
- aam.fetchContent();
747
- $('i.icon-spin4', $(this)).attr('class', 'icon-cog');
748
- } else {
749
- $.aam.loadAccessForm($('#load-post-object-type').val(), $('#load-post-object').val(), null, function () {
750
- $('i.icon-spin4', $(_this)).attr('class', 'icon-cog');
751
- });
752
- }
753
- });
754
- });
755
-
756
- })(jQuery);
757
-
758
-
759
- /**
760
- * Admin Menu Interface
761
- *
762
- * @param {jQuery} $
763
- *
764
- * @returns {void}
765
- */
766
- (function ($) {
767
-
768
- /**
769
- *
770
- * @param {type} param
771
- * @param {type} value
772
- * @returns {undefined}
773
- */
774
- function save(items, status, successCallback) {
775
- $.ajax(aamLocal.ajaxurl, {
776
- type: 'POST',
777
- dataType: 'json',
778
- data: {
779
- action: 'aam',
780
- sub_action: 'Menu.save',
781
- subject: aam.getSubject().type,
782
- subjectId: aam.getSubject().id,
783
- _ajax_nonce: aamLocal.nonce,
784
- items: items,
785
- status: status
786
- },
787
- success: function(response) {
788
- successCallback(response);
789
- },
790
- error: function () {
791
- aam.notification('danger', aam.__('Application Error'));
792
- }
793
- });
794
- }
795
-
796
- /**
797
- *
798
- * @returns {undefined}
799
- */
800
- function initialize() {
801
- if ($('#admin_menu-content').length) {
802
- $('.aam-restrict-menu').each(function () {
803
- $(this).bind('click', function () {
804
- var _this = $(this);
805
- var status = ($('i', $(this)).hasClass('icon-eye-off') ? 1 : 0);
806
- var target = _this.data('target');
807
-
808
- $('i', _this).attr('class', 'icon-spin4 animate-spin');
809
-
810
- var items = new Array(_this.data('menu-id'));
811
-
812
- $('input', target).each(function () {
813
- $(this).attr('checked', status ? true : false);
814
- items.push($(this).data('menu-id'));
815
- });
816
-
817
- save(items, status, function(result) {
818
- if (result.status === 'success') {
819
- $('#aam-menu-overwrite').show();
820
-
821
- if (status) { //locked the menu
822
- $('.aam-bordered', target).append(
823
- $('<div/>', {'class': 'aam-lock'})
824
- );
825
- _this.removeClass('btn-danger').addClass('btn-primary');
826
- _this.html('<i class="icon-eye"></i>' + aam.__('Show Menu'));
827
- //add menu restricted indicator
828
- var ind = $('<i/>', {
829
- 'class': 'aam-panel-title-icon icon-eye-off text-danger'
830
- });
831
- $('.panel-title', target + '-heading').append(ind);
832
- } else {
833
- $('.aam-lock', target).remove();
834
- _this.removeClass('btn-primary').addClass('btn-danger');
835
- _this.html(
836
- '<i class="icon-eye-off"></i>' + aam.__('Restrict Menu')
837
- );
838
- $('.panel-title .icon-eye-off', target + '-heading').remove();
839
- }
840
- } else {
841
- _this.attr('checked', !status);
842
- }
843
- });
844
- });
845
- });
846
-
847
- $('input[type="checkbox"]', '#admin-menu').each(function () {
848
- $(this).bind('click', function () {
849
- aam.save(
850
- $(this).data('menu-id'),
851
- $(this).attr('checked') ? 1 : 0,
852
- 'menu',
853
- null,
854
- function(result) {
855
- if (result.status === 'success') {
856
- $('#aam-menu-overwrite').show();
857
- }
858
- }
859
- );
860
- });
861
- });
862
-
863
- //reset button
864
- $('#menu-reset').bind('click', function () {
865
- aam.reset('menu');
866
- });
867
- }
868
- }
869
-
870
- aam.addHook('init', initialize);
871
-
872
- })(jQuery);
873
-
874
-
875
- /**
876
- * Metaboxes & Widgets Interface
877
- *
878
- * @param {jQuery} $
879
- *
880
- * @returns {void}
881
- */
882
- (function ($) {
883
-
884
- /**
885
- *
886
- * @returns {undefined}
887
- */
888
- function getContent() {
889
- $.ajax(aamLocal.ajaxurl, {
890
- type: 'POST',
891
- dataType: 'html',
892
- data: {
893
- action: 'aam',
894
- sub_action: 'Metabox.getContent',
895
- _ajax_nonce: aamLocal.nonce,
896
- subject: aam.getSubject().type,
897
- subjectId: aam.getSubject().id
898
- },
899
- success: function (response) {
900
- $('#metabox-content').replaceWith(response);
901
- $('#metabox-content').addClass('active');
902
- initialize();
903
- },
904
- error: function () {
905
- aam.notification('danger', aam.__('Application error'));
906
- }
907
- });
908
- }
909
-
910
- /**
911
- *
912
- * @returns {undefined}
913
- */
914
- function initialize() {
915
- if ($('#metabox-content').length) {
916
- //init refresh list button
917
- $('#refresh-metabox-list').bind('click', function () {
918
- $.ajax(aamLocal.ajaxurl, {
919
- type: 'POST',
920
- dataType: 'json',
921
- data: {
922
- action: 'aam',
923
- sub_action: 'Metabox.refreshList',
924
- _ajax_nonce: aamLocal.nonce
925
- },
926
- beforeSend: function () {
927
- $('i', '#refresh-metabox-list').attr(
928
- 'class', 'icon-spin4 animate-spin'
929
- );
930
- },
931
- success: function (response) {
932
- if (response.status === 'success') {
933
- getContent();
934
- } else {
935
- aam.notification(
936
- 'danger', aam.__('Failed to retrieve mataboxes')
937
- );
938
- }
939
- },
940
- error: function () {
941
- aam.notification('danger', aam.__('Application error'));
942
- },
943
- complete: function () {
944
- $('i', '#refresh-metabox-list').attr(
945
- 'class', 'icon-arrows-cw'
946
- );
947
- }
948
- });
949
- });
950
-
951
- $('#init-url-btn').bind('click', function () {
952
- $.ajax(aamLocal.ajaxurl, {
953
- type: 'POST',
954
- dataType: 'json',
955
- data: {
956
- action: 'aam',
957
- sub_action: 'Metabox.initURL',
958
- _ajax_nonce: aamLocal.nonce,
959
- url: $('#init-url').val()
960
- },
961
- beforeSend: function () {
962
- $('#init-url-btn').text(aam.__('Processing'));
963
- },
964
- success: function (response) {
965
- if (response.status === 'success') {
966
- $('#init-url-modal').modal('hide');
967
- getContent();
968
- } else {
969
- aam.notification(
970
- 'danger', aam.__('Failed to initialize URL')
971
- );
972
- }
973
- },
974
- error: function () {
975
- aam.notification('danger', aam.__('Application error'));
976
- },
977
- complete: function () {
978
- $('#init-url-btn').text(aam.__('Initialize'));
979
- $('#init-url-modal').modal('hide');
980
- }
981
- });
982
- });
983
-
984
- //reset button
985
- $('#metabox-reset').bind('click', function () {
986
- aam.reset('metabox');
987
- });
988
-
989
- $('input[type="checkbox"]', '#metabox-list').each(function () {
990
- $(this).bind('click', function () {
991
- aam.save(
992
- $(this).data('metabox'),
993
- $(this).attr('checked') ? 1 : 0,
994
- 'metabox',
995
- null,
996
- function(result) {
997
- if (result.status === 'success') {
998
- $('#aam-metabox-overwrite').show();
999
- }
1000
- }
1001
- );
1002
- });
1003
- });
1004
- }
1005
- }
1006
-
1007
- aam.addHook('init', initialize);
1008
-
1009
- })(jQuery);
1010
-
1011
-
1012
- /**
1013
- * Capabilities Interface
1014
- *
1015
- * @param {jQuery} $
1016
- *
1017
- * @returns {void}
1018
- */
1019
- (function ($) {
1020
-
1021
- /**
1022
- *
1023
- * @param {type} capability
1024
- * @param {type} btn
1025
- * @returns {undefined}
1026
- */
1027
- function save(capability, btn) {
1028
- var granted = $(btn).hasClass('icon-check-empty') ? 1 : 0;
1029
-
1030
- //show indicator
1031
- $(btn).attr('class', 'aam-row-action icon-spin4 animate-spin');
1032
-
1033
- aam.save(capability, granted, 'capability', null, function(result) {
1034
- if (result.status === 'success') {
1035
- if (granted) {
1036
- $(btn).attr('class', 'aam-row-action text-success icon-check');
1037
- } else {
1038
- $(btn).attr('class', 'aam-row-action text-muted icon-check-empty');
1039
- }
1040
- } else {
1041
- if (granted) {
1042
- aam.notification(
1043
- 'danger', aam.__('WordPress core does not allow to grant this capability')
1044
- );
1045
- $(btn).attr('class', 'aam-row-action text-muted icon-check-empty');
1046
- } else {
1047
- $(btn).attr('class', 'aam-row-action text-success icon-check');
1048
- }
1049
- }
1050
- });
1051
- }
1052
- /**
1053
- *
1054
- * @returns {undefined}
1055
- */
1056
- function initialize() {
1057
- if ($('#capability-content').length) {
1058
- //initialize the role list table
1059
- $('#capability-list').DataTable({
1060
- autoWidth: false,
1061
- ordering: false,
1062
- pagingType: 'simple',
1063
- serverSide: false,
1064
- ajax: {
1065
- url: aamLocal.ajaxurl,
1066
- type: 'POST',
1067
- data: {
1068
- action: 'aam',
1069
- sub_action: 'Capability.getTable',
1070
- _ajax_nonce: aamLocal.nonce,
1071
- subject: aam.getSubject().type,
1072
- subjectId: aam.getSubject().id
1073
- }
1074
- },
1075
- columnDefs: [
1076
- {visible: false, targets: [0]}
1077
- ],
1078
- language: {
1079
- search: '_INPUT_',
1080
- searchPlaceholder: aam.__('Search Capability'),
1081
- info: aam.__('_TOTAL_ capability(s)'),
1082
- infoFiltered: '',
1083
- infoEmpty: aam.__('Nothing to show'),
1084
- lengthMenu: '_MENU_'
1085
- },
1086
- createdRow: function (row, data) {
1087
- var actions = data[3].split(',');
1088
-
1089
- var container = $('<div/>', {'class': 'aam-row-actions'});
1090
- $.each(actions, function (i, action) {
1091
- switch (action) {
1092
- case 'unchecked':
1093
- $(container).append($('<i/>', {
1094
- 'class': 'aam-row-action text-muted icon-check-empty'
1095
- }).bind('click', function () {
1096
- save(data[0], this);
1097
- }));
1098
- break;
1099
-
1100
- case 'checked':
1101
- $(container).append($('<i/>', {
1102
- 'class': 'aam-row-action text-success icon-check'
1103
- }).bind('click', function () {
1104
- save(data[0], this);
1105
- }));
1106
- break;
1107
-
1108
- case 'edit':
1109
- $(container).append($('<i/>', {
1110
- 'class': 'aam-row-action icon-pencil text-warning'
1111
- }).bind('click', function () {
1112
- $('#capability-id').val(data[0]);
1113
- $('#update-capability-btn').attr('data-cap', data[0]);
1114
- $('#edit-capability-modal').modal('show');
1115
- }));
1116
- break;
1117
-
1118
- case 'delete':
1119
- $(container).append($('<i/>', {
1120
- 'class': 'aam-row-action icon-trash-empty text-danger'
1121
- }).bind('click', function () {
1122
- var message = $('.aam-confirm-message', '#delete-capability-modal');
1123
- $(message).html(message.data('message').replace(
1124
- '%s', '<b>' + data[0] + '</b>')
1125
- );
1126
- $('#capability-id').val(data[0]);
1127
- $('#delete-capability-btn').attr('data-cap', data[0]);
1128
- $('#delete-capability-modal').modal('show');
1129
- }));
1130
- break;
1131
-
1132
- default:
1133
- aam.triggerHook('decorate-capability-row', {
1134
- action: action,
1135
- container: container,
1136
- data: data
1137
- });
1138
- break;
1139
- }
1140
- });
1141
- $('td:eq(2)', row).html(container);
1142
- }
1143
- });
1144
-
1145
- $('a', '#capability-groups').each(function () {
1146
- $(this).bind('click', function () {
1147
- var table = $('#capability-list').DataTable();
1148
- if ($(this).data('clear') !== true) {
1149
- table.column(1).search($(this).text()).draw();
1150
- } else {
1151
- table.column(1).search('').draw();
1152
- }
1153
- });
1154
- });
1155
-
1156
- $('#add-capability-modal').on('shown.bs.modal', function (e) {
1157
- $('#new-capability-name').val('');
1158
- });
1159
-
1160
- $('#add-capability').bind('click', function () {
1161
- $('#add-capability-modal').modal('show');
1162
- });
1163
-
1164
- $('#add-capability-btn').bind('click', function () {
1165
- var _this = this;
1166
-
1167
- var capability = $.trim($('#new-capability-name').val());
1168
- $('#new-capability-name').parent().removeClass('has-error');
1169
-
1170
- if (capability) {
1171
- $.ajax(aamLocal.ajaxurl, {
1172
- type: 'POST',
1173
- dataType: 'json',
1174
- data: {
1175
- action: 'aam',
1176
- sub_action: 'Capability.add',
1177
- _ajax_nonce: aamLocal.nonce,
1178
- capability: capability,
1179
- subject: aam.getSubject().type,
1180
- subjectId: aam.getSubject().id
1181
- },
1182
- beforeSend: function () {
1183
- $(_this).text(aam.__('Saving...')).attr('disabled', true);
1184
- },
1185
- success: function (response) {
1186
- if (response.status === 'success') {
1187
- $('#add-capability-modal').modal('hide');
1188
- $('#capability-list').DataTable().ajax.reload();
1189
- } else {
1190
- aam.notification(
1191
- 'danger', aam.__('Failed to add new capability')
1192
- );
1193
- }
1194
- },
1195
- error: function () {
1196
- aam.notification('danger', aam.__('Application error'));
1197
- },
1198
- complete: function () {
1199
- $(_this).text(aam.__('Add Capability')).attr('disabled', false);
1200
- }
1201
- });
1202
- } else {
1203
- $('#new-capability-name').parent().addClass('has-error');
1204
- }
1205
- });
1206
-
1207
- $('#add-capability-modal').on('shown.bs.modal', function (e) {
1208
- $('#new-capability-name').focus();
1209
- });
1210
-
1211
- $('#update-capability-btn').bind('click', function () {
1212
- var btn = this;
1213
- var cap = $.trim($('#capability-id').val());
1214
-
1215
- if (cap) {
1216
- $.ajax(aamLocal.ajaxurl, {
1217
- type: 'POST',
1218
- dataType: 'json',
1219
- data: {
1220
- action: 'aam',
1221
- sub_action: 'Capability.update',
1222
- _ajax_nonce: aamLocal.nonce,
1223
- capability: $(this).attr('data-cap'),
1224
- updated: cap
1225
- },
1226
- beforeSend: function () {
1227
- $(btn).text(aam.__('Saving...')).attr('disabled', true);
1228
- },
1229
- success: function (response) {
1230
- if (response.status === 'success') {
1231
- $('#edit-capability-modal').modal('hide');
1232
- $('#capability-list').DataTable().ajax.reload();
1233
- } else {
1234
- aam.notification(
1235
- 'danger', aam.__('Failed to update capability')
1236
- );
1237
- }
1238
- },
1239
- error: function () {
1240
- aam.notification('danger', aam.__('Application error'));
1241
- },
1242
- complete: function () {
1243
- $(btn).text(aam.__('Update Capability')).attr(
1244
- 'disabled', false
1245
- );
1246
- }
1247
- });
1248
- }
1249
- });
1250
-
1251
- $('#delete-capability-btn').bind('click', function () {
1252
- var btn = this;
1253
-
1254
- $.ajax(aamLocal.ajaxurl, {
1255
- type: 'POST',
1256
- dataType: 'json',
1257
- data: {
1258
- action: 'aam',
1259
- sub_action: 'Capability.delete',
1260
- _ajax_nonce: aamLocal.nonce,
1261
- subject: aam.getSubject().type,
1262
- subjectId: aam.getSubject().id,
1263
- capability: $(this).attr('data-cap')
1264
- },
1265
- beforeSend: function () {
1266
- $(btn).text(aam.__('Deleting...')).attr('disabled', true);
1267
- },
1268
- success: function (response) {
1269
- if (response.status === 'success') {
1270
- $('#delete-capability-modal').modal('hide');
1271
- $('#capability-list').DataTable().ajax.reload();
1272
- } else {
1273
- aam.notification(
1274
- 'danger', aam.__('Failed to delete capability')
1275
- );
1276
- }
1277
- },
1278
- error: function () {
1279
- aam.notification('danger', aam.__('Application error'));
1280
- },
1281
- complete: function () {
1282
- $(btn).text(aam.__('Delete Capability')).attr(
1283
- 'disabled', false
1284
- );
1285
- }
1286
- });
1287
- });
1288
-
1289
- //reset button
1290
- $('#capability-reset').bind('click', function () {
1291
- aam.reset('capability');
1292
- });
1293
- }
1294
- }
1295
-
1296
- aam.addHook('init', initialize);
1297
-
1298
- })(jQuery);
1299
-
1300
-
1301
- /**
1302
- * Posts & Pages Interface
1303
- *
1304
- * @param {jQuery} $
1305
- *
1306
- * @returns {void}
1307
- */
1308
- (function ($) {
1309
-
1310
- /**
1311
- * Table extra filter
1312
- *
1313
- * @type Object
1314
- */
1315
- var filter = {
1316
- type: null
1317
- };
1318
-
1319
- /**
1320
- *
1321
- * @param {*} param
1322
- * @param {*} value
1323
- * @param {*} object
1324
- * @param {*} object_id
1325
- * @param {*} successCallback
1326
- */
1327
- function save(param, value, object, object_id, successCallback) {
1328
- $.ajax(aamLocal.ajaxurl, {
1329
- type: 'POST',
1330
- dataType: 'json',
1331
- data: {
1332
- action: 'aam',
1333
- sub_action: 'Post.save',
1334
- _ajax_nonce: aamLocal.nonce,
1335
- subject: aam.getSubject().type,
1336
- subjectId: aam.getSubject().id,
1337
- param: param,
1338
- value: value,
1339
- object: object,
1340
- objectId: object_id
1341
- },
1342
- success: function (response) {
1343
- if (response.status === 'failure') {
1344
- aam.notification('danger', response.error);
1345
- } else {
1346
- $('#post-overwritten').removeClass('hidden');
1347
- //add some specific attributes to reset button
1348
- $('#post-reset').attr({
1349
- 'data-type': object,
1350
- 'data-id': object_id
1351
- });
1352
- }
1353
- successCallback(response);
1354
- },
1355
- error: function () {
1356
- aam.notification('danger', aam.__('Application error'));
1357
- }
1358
- });
1359
- }
1360
-
1361
- /**
1362
- *
1363
- * @param {type} type
1364
- * @param {type} id
1365
- * @param {type} title
1366
- * @returns {undefined}
1367
- */
1368
- function addBreadcrumbLevel(type, id, title) {
1369
- var level = $((type === 'type' ? '<a/>' : '<span/>')).attr({
1370
- 'href': '#',
1371
- 'data-level': type,
1372
- 'data-id': id
1373
- }).html('<i class="icon-angle-double-right"></i>' + title);
1374
- $('.aam-post-breadcrumb').append(level);
1375
- }
1376
-
1377
- /**
1378
- *
1379
- * @param {type} object
1380
- * @param {type} id
1381
- * @param {type} btn
1382
- * @param {type} callback
1383
- * @returns {undefined}
1384
- */
1385
- $.aam.loadAccessForm = function(object, id, btn, callback) {
1386
- //reset the form first
1387
- var container = $('.aam-access-form[data-type="' + object + '"]');
1388
- $('#post-overwritten').addClass('hidden');
1389
-
1390
- //show overlay if present
1391
- $('.aam-overlay', container).show();
1392
-
1393
- //reset data preview elements
1394
- $('[data-preview]', container).text('');
1395
-
1396
- $('.aam-row-action', container).each(function () {
1397
- $(this).attr({
1398
- 'class': 'aam-row-action text-muted icon-check-empty',
1399
- 'data-type': object,
1400
- 'data-id': id
1401
- });
1402
-
1403
- //initialize each access property
1404
- $(this).unbind('click').bind('click', function () {
1405
- var _this = $(this);
1406
- var checked = !_this.hasClass('icon-check');
1407
-
1408
- _this.attr('class', 'aam-row-action icon-spin4 animate-spin');
1409
- var response = save(
1410
- _this.data('property'),
1411
- (checked ? 1 : 0),
1412
- object,
1413
- id,
1414
- function(response) {
1415
- if (response.status === 'success') {
1416
- if (checked) {
1417
- _this.attr(
1418
- 'class', 'aam-row-action text-danger icon-check'
1419
- );
1420
- } else {
1421
- _this.attr(
1422
- 'class', 'aam-row-action text-muted icon-check-empty'
1423
- );
1424
- }
1425
- }
1426
- }
1427
- );
1428
- });
1429
-
1430
- });
1431
-
1432
- $.ajax(aamLocal.ajaxurl, {
1433
- type: 'POST',
1434
- dataType: 'json',
1435
- data: {
1436
- action: 'aam',
1437
- sub_action: 'Post.getAccess',
1438
- _ajax_nonce: aamLocal.nonce,
1439
- type: object,
1440
- id: id,
1441
- subject: aam.getSubject().type,
1442
- subjectId: aam.getSubject().id
1443
- },
1444
- beforeSend: function () {
1445
- $(btn).attr('data-class', $(btn).attr('class'));
1446
- $(btn).attr('class', 'aam-row-action icon-spin4 animate-spin');
1447
- },
1448
- success: function (response) {
1449
- //iterate through each property
1450
- for (var property in response.access) {
1451
- var checked = (parseInt(response.access[property]) ? 'text-danger icon-check' : 'text-muted icon-check-empty');
1452
- var checkbox = $('[data-property="' + property + '"]', container);
1453
-
1454
- if (checkbox.length) {
1455
- checkbox.attr({
1456
- 'class': 'aam-row-action ' + checked
1457
- });
1458
- } else {
1459
- $('[data-preview="' + property + '"]', container).prop('data-original-value', response.access[property]);
1460
- $('[data-preview="' + property + '"]', container).html(
1461
- preparePreview(response.access[property])
1462
- );
1463
- }
1464
- }
1465
-
1466
- //check metadata and show message if necessary
1467
- if (response.meta.overwritten === true) {
1468
- $('#post-overwritten').removeClass('hidden');
1469
- //add some specific attributes to reset button
1470
- $('#post-reset').attr({
1471
- 'data-type': object,
1472
- 'data-id': id
1473
- });
1474
- }
1475
-
1476
- $('.extended-post-access-btn').attr({
1477
- 'data-type': object,
1478
- 'data-id': id
1479
- });
1480
-
1481
- $('#post-list_wrapper').addClass('aam-hidden');
1482
- container.addClass('active');
1483
-
1484
- if (typeof callback === 'function') {
1485
- callback.call();
1486
- }
1487
-
1488
- //update dynamic labels
1489
- if ($('#load-post-object-title').length) {
1490
- var marker = $('#load-post-object-title').val();
1491
- } else {
1492
- marker = $('.aam-post-breadcrumb span').text();
1493
- }
1494
- $('[data-dynamic-post-label]').each(function() {
1495
- $(this).html(
1496
- $(this).attr('data-dynamic-post-label').replace(/%s/g, '<b>' + marker + '</b>')
1497
- );
1498
- });
1499
- },
1500
- error: function () {
1501
- aam.notification('danger', aam.__('Application error'));
1502
- },
1503
- complete: function () {
1504
- $(btn).attr('class', $(btn).attr('data-class')).removeAttr('data-class');
1505
- //show overlay if present
1506
- $('.aam-overlay', container).hide();
1507
- }
1508
- });
1509
- };
1510
-
1511
- /**
1512
- *
1513
- * @param {type} text
1514
- * @returns {String}
1515
- */
1516
- function preparePreview(preview) {
1517
- if (typeof preview === 'string') {
1518
- preview = preview.replace(/<\/?[^>]+(>|$)/g, "");
1519
-
1520
- if (preview.length > 25) {
1521
- preview = preview.substring(0, 22) + '...';
1522
- }
1523
- }
1524
-
1525
- return preview;
1526
- }
1527
-
1528
- /**
1529
- *
1530
- * @returns {undefined}
1531
- */
1532
- function initialize() {
1533
- if ($('#post-content').length) {
1534
- //reset filter to default list of post types
1535
- filter.type = null;
1536
-
1537
- //initialize the role list table
1538
- $('#post-list').DataTable({
1539
- autoWidth: false,
1540
- ordering: false,
1541
- pagingType: 'simple',
1542
- processing: true,
1543
- serverSide: true,
1544
- ajax: {
1545
- url: aamLocal.ajaxurl,
1546
- type: 'POST',
1547
- data: function (data) {
1548
- data.action = 'aam';
1549
- data.sub_action = 'Post.getTable';
1550
- data._ajax_nonce = aamLocal.nonce;
1551
- data.subject = aam.getSubject().type;
1552
- data.subjectId = aam.getSubject().id;
1553
- data.type = filter.type;
1554
- }
1555
- },
1556
- columnDefs: [
1557
- {visible: false, targets: [0, 1]}
1558
- ],
1559
- language: {
1560
- search: '_INPUT_',
1561
- searchPlaceholder: aam.__('Search'),
1562
- info: aam.__('_TOTAL_ object(s)'),
1563
- infoFiltered: '',
1564
- lengthMenu: '_MENU_'
1565
- },
1566
- initComplete: function () {
1567
- $('#post-list_filter .form-control').bind('change', function() {
1568
- if ($(this).val()) {
1569
- $(this).addClass('highlight');
1570
- } else {
1571
- $(this).removeClass('highlight');
1572
- }
1573
- });
1574
- },
1575
- rowCallback: function (row, data) {
1576
- //object type icon
1577
- switch (data[2]) {
1578
- case 'type':
1579
- $('td:eq(0)', row).html('<i class="icon-box"></i>');
1580
- break;
1581
-
1582
- case 'term':
1583
- $('td:eq(0)', row).html('<i class="icon-folder"></i>');
1584
- break;
1585
-
1586
- default:
1587
- $('td:eq(0)', row).html('<i class="icon-doc-text-inv"></i>');
1588
- break;
1589
- }
1590
-
1591
- //update the title to a link
1592
- if (data[2] === 'type') {
1593
- var link = $('<a/>', {
1594
- href: '#'
1595
- }).bind('click', function () {
1596
- //visual feedback - show loading icon
1597
- $('td:eq(0)', row).html(
1598
- '<i class="icon-spin4 animate-spin"></i>'
1599
- );
1600
- //set filter
1601
- filter[data[2]] = data[0];
1602
-
1603
- //finally reload the data
1604
- $('#post-list').DataTable().ajax.reload();
1605
-
1606
- //update the breadcrumb
1607
- addBreadcrumbLevel('type', data[0], data[3]);
1608
-
1609
- }).html(data[3]);
1610
- $('td:eq(1)', row).html(link);
1611
- } else { //reset the post/term title
1612
- $('td:eq(1)', row).html(data[3]);
1613
- }
1614
-
1615
- //update the actions
1616
- var actions = data[4].split(',');
1617
-
1618
- var container = $('<div/>', {'class': 'aam-row-actions'});
1619
- $.each(actions, function (i, action) {
1620
- switch (action) {
1621
- case 'drilldown':
1622
- $(container).append($('<i/>', {
1623
- 'class': 'aam-row-action text-success icon-level-down'
1624
- }).bind('click', function () {
1625
- if (!$(this).prop('disabled')) {
1626
- $(this).prop('disabled', true);
1627
- //set filter
1628
- filter[data[2]] = data[0];
1629
- //finally reload the data
1630
- $('#post-list').DataTable().ajax.reload();
1631
- //update the breadcrumb
1632
- addBreadcrumbLevel('type', data[0], data[3]);
1633
- }
1634
- }).attr({
1635
- 'data-toggle': "tooltip",
1636
- 'title': aam.__('Drill-Down')
1637
- }));
1638
- $('.tooltip').remove();
1639
- break;
1640
-
1641
- case 'manage':
1642
- $(container).append($('<i/>', {
1643
- 'class': 'aam-row-action text-info icon-cog'
1644
- }).bind('click', function () {
1645
- $.aam.loadAccessForm(data[2], data[0], $(this), function () {
1646
- addBreadcrumbLevel('edit', data[2], data[3]);
1647
- });
1648
- }).attr({
1649
- 'data-toggle': "tooltip",
1650
- 'title': aam.__('Manage Access')
1651
- }));
1652
- $('.tooltip').remove();
1653
- break;
1654
-
1655
- case 'edit' :
1656
- $(container).append($('<i/>', {
1657
- 'class': 'aam-row-action text-warning icon-pencil'
1658
- }).bind('click', function () {
1659
- window.open(data[1], '_blank');
1660
- }).attr({
1661
- 'data-toggle': "tooltip",
1662
- 'title': aam.__('Edit')
1663
- }));
1664
- break;
1665
-
1666
- default:
1667
- aam.triggerHook('post-action', {
1668
- container: container,
1669
- action : action,
1670
- data : data
1671
- });
1672
- break;
1673
- }
1674
- });
1675
- $('td:eq(2)', row).html(container);
1676
- }
1677
- });
1678
-
1679
- //initialize the breadcrumb
1680
- $('.aam-post-breadcrumb').delegate('a', 'click', function () {
1681
- filter.type = $(this).data('id');
1682
- $('#post-list').DataTable().ajax.reload();
1683
- $(this).nextAll().remove();
1684
- $('.aam-slide-form').removeClass('active');
1685
- $('#post-list_wrapper').removeClass('aam-hidden');
1686
- $('#post-overwritten').addClass('hidden');
1687
- });
1688
-
1689
- //reset button
1690
- $('#post-reset').bind('click', function () {
1691
- var type = $(this).attr('data-type');
1692
- var id = $(this).attr('data-id');
1693
-
1694
- $.ajax(aamLocal.ajaxurl, {
1695
- type: 'POST',
1696
- dataType: 'json',
1697
- data: {
1698
- action: 'aam',
1699
- sub_action: 'Post.reset',
1700
- _ajax_nonce: aamLocal.nonce,
1701
- type: type,
1702
- id: id,
1703
- subject: aam.getSubject().type,
1704
- subjectId: aam.getSubject().id
1705
- },
1706
- beforeSend: function () {
1707
- },
1708
- success: function (response) {
1709
- if (response.status === 'success') {
1710
- $('#post-overwritten').addClass('hidden');
1711
- $.aam.loadAccessForm(type, id);
1712
- }
1713
- }
1714
- });
1715
- });
1716
-
1717
- //go back button
1718
- $('.aam-slide-form').delegate('.post-back', 'click', function () {
1719
- var type = $(this).parent().data('type');
1720
-
1721
- $('.aam-slide-form[data-type="' + type + '"]').removeClass('active');
1722
- $('#post-list_wrapper').removeClass('aam-hidden');
1723
- $('.aam-post-breadcrumb span:last').remove();
1724
- $('#post-overwritten').addClass('hidden');
1725
- });
1726
-
1727
- //load referenced post
1728
- if ($('#load-post-object').val()) {
1729
- $.aam.loadAccessForm(
1730
- $('#load-post-object-type').val(),
1731
- $('#load-post-object').val()
1732
- );
1733
- }
1734
-
1735
- $('.change-password').each(function() {
1736
- $(this).bind('click', function() {
1737
- var password = $('#' + $(this).attr('data-preview-id')).text();
1738
-
1739
- if (password !== '') {
1740
- $('#password-value').val(password);
1741
- } else {
1742
- $('#password-value').val('');
1743
- }
1744
-
1745
- $('#change-password-btn').attr({
1746
- 'data-ref': $(this).attr('data-ref'),
1747
- 'data-preview-id': $(this).attr('data-preview-id')
1748
- });
1749
-
1750
- $('#password-modal').modal('show');
1751
- });
1752
- });
1753
-
1754
- $('#change-password-btn').bind('click', function() {
1755
- var _this = $(this);
1756
- _this.text(aam.__('Saving...'));
1757
-
1758
- var password = $('#password-value').val();
1759
- save(
1760
- _this.attr('data-ref'),
1761
- password,
1762
- _this.attr('data-type'),
1763
- _this.attr('data-id'),
1764
- function(response) {
1765
- if (response.status === 'success') {
1766
- var preview = $('#' + _this.attr('data-preview-id'));
1767
- var action = $('.aam-row-action', preview.parent().parent().parent());
1768
-
1769
- preview.html(password ? password : '');
1770
-
1771
- if ($(action).hasClass('icon-check-empty')) {
1772
- action.trigger('click');
1773
- }
1774
- }
1775
- $('#password-modal').modal('hide');
1776
-
1777
- _this.text(aam.__('Set'));
1778
- }
1779
- );
1780
- });
1781
-
1782
- $('.change-location').each(function() {
1783
- $(this).bind('click', function() {
1784
- var location = $('#' + $(this).attr('data-preview-id')).text();
1785
-
1786
- if (location !== '') {
1787
- $('#location-value').val(location);
1788
- } else {
1789
- $('#location-value').val('');
1790
- }
1791
-
1792
- $('#change-location-btn').attr({
1793
- 'data-ref': $(this).attr('data-ref'),
1794
- 'data-preview-id': $(this).attr('data-preview-id')
1795
- });
1796
-
1797
- $('#location-modal').modal('show');
1798
- });
1799
- });
1800
-
1801
- $('#change-location-btn').bind('click', function() {
1802
- var _this = $(this);
1803
- _this.text(aam.__('Saving...'));
1804
-
1805
- var redirect = $('#location-value').val();
1806
- save(
1807
- _this.attr('data-ref'),
1808
- redirect,
1809
- _this.attr('data-type'),
1810
- _this.attr('data-id'),
1811
- function(response) {
1812
- if (response.status === 'success') {
1813
- var preview = $('#' + _this.attr('data-preview-id'));
1814
- var action = $('.aam-row-action', preview.parent().parent().parent());
1815
-
1816
- preview.html(redirect ? redirect : '');
1817
-
1818
- if ($(action).hasClass('icon-check-empty')) {
1819
- action.trigger('click');
1820
- }
1821
- }
1822
- $('#location-modal').modal('hide');
1823
- _this.text(aam.__('Set'));
1824
- }
1825
- );
1826
- });
1827
-
1828
- $('.change-expiration').each(function() {
1829
- $(this).bind('click', function() {
1830
- var expiration = $('#' + $(this).attr('data-preview-id')).text();
1831
-
1832
- if (expiration !== '') {
1833
- $('#expiration-value').val(expiration);
1834
- } else {
1835
- $('#expiration-value').val('');
1836
- }
1837
-
1838
- $('#change-expiration-btn').attr({
1839
- 'data-ref': $(this).attr('data-ref'),
1840
- 'data-preview-id': $(this).attr('data-preview-id')
1841
- });
1842
-
1843
- $('#expiration-modal').modal('show');
1844
- });
1845
- });
1846
-
1847
- $('#change-expiration-btn').bind('click', function() {
1848
- var _this = $(this);
1849
- _this.text(aam.__('Saving...'));
1850
-
1851
- var expires = $('#expiration-value').val();
1852
- save(
1853
- _this.attr('data-ref'),
1854
- expires,
1855
- _this.attr('data-type'),
1856
- _this.attr('data-id'),
1857
- function(response) {
1858
- if (response.status === 'success') {
1859
- var preview = $('#' + _this.attr('data-preview-id'));
1860
- var action = $('.aam-row-action', preview.parent().parent().parent());
1861
- preview.html(response.value);
1862
-
1863
- if ($(action).hasClass('icon-check-empty')) {
1864
- action.trigger('click');
1865
- }
1866
- }
1867
- $('#expiration-modal').modal('hide');
1868
- _this.text(aam.__('Set'));
1869
- }
1870
- );
1871
- });
1872
-
1873
- $('.change-teaser').each(function() {
1874
- $(this).bind('click', function() {
1875
- var teaser = $('#' + $(this).attr('data-preview-id')).prop('data-original-value');
1876
- $('#teaser-value').val(teaser);
1877
-
1878
- $('#change-teaser-btn').attr({
1879
- 'data-ref': $(this).attr('data-ref'),
1880
- 'data-preview-id': $(this).attr('data-preview-id')
1881
- });
1882
-
1883
- $('#teaser-modal').modal('show');
1884
- });
1885
- });
1886
-
1887
- $('#change-teaser-btn').bind('click', function() {
1888
- var _this = $(this);
1889
- _this.text(aam.__('Saving...'));
1890
-
1891
- var teaser = $('#teaser-value').val();
1892
- save(
1893
- _this.attr('data-ref'),
1894
- teaser,
1895
- _this.attr('data-type'),
1896
- _this.attr('data-id'),
1897
- function(response) {
1898
- if (response.status === 'success') {
1899
- var preview = $('#' + _this.attr('data-preview-id'));
1900
- var action = $('.aam-row-action', preview.parent().parent().parent());
1901
-
1902
- preview.prop('data-original-value', teaser);
1903
- preview.html(preparePreview(teaser));
1904
-
1905
- if ($(action).hasClass('icon-check-empty')) {
1906
- action.trigger('click');
1907
- }
1908
- }
1909
- $('#teaser-modal').modal('hide');
1910
- _this.text(aam.__('Save'));
1911
- }
1912
- );
1913
- });
1914
- }
1915
- }
1916
-
1917
- aam.addHook('init', initialize);
1918
-
1919
- })(jQuery);
1920
-
1921
- /**
1922
- * Redirect Interface
1923
- *
1924
- * @param {jQuery} $
1925
- *
1926
- * @returns {void}
1927
- */
1928
- (function ($) {
1929
-
1930
- /**
1931
- *
1932
- * @returns {undefined}
1933
- */
1934
- function initialize() {
1935
- var container = '#redirect-content';
1936
-
1937
- if ($(container).length) {
1938
- $('input[type="radio"]', container).each(function () {
1939
- $(this).bind('click', function () {
1940
- //hide group
1941
- $('.' + $(this).data('group')).hide();
1942
-
1943
- //show the specific one
1944
- $($(this).data('action')).show();
1945
-
1946
- //save redirect type
1947
- aam.save(
1948
- $(this).attr('name'),
1949
- $(this).val(),
1950
- 'redirect',
1951
- null,
1952
- function(result) {
1953
- if (result.status === 'success') {
1954
- $('#aam-redirect-overwrite').show();
1955
- }
1956
- }
1957
- );
1958
- });
1959
- });
1960
-
1961
- $('input[type="text"],select,textarea', container).each(function () {
1962
- $(this).bind('change', function () {
1963
- //save redirect type
1964
- aam.save(
1965
- $(this).attr('name'),
1966
- $(this).val(),
1967
- 'redirect',
1968
- null,
1969
- function(result) {
1970
- if (result.status === 'success') {
1971
- $('#aam-redirect-overwrite').show();
1972
- }
1973
- }
1974
- );
1975
- });
1976
- });
1977
-
1978
- $('#redirect-reset').bind('click', function () {
1979
- aam.reset('redirect');
1980
- });
1981
- }
1982
- }
1983
-
1984
- aam.addHook('init', initialize);
1985
-
1986
- })(jQuery);
1987
-
1988
- /**
1989
- * Login Redirect Interface
1990
- *
1991
- * @param {jQuery} $
1992
- *
1993
- * @returns {void}
1994
- */
1995
- (function ($) {
1996
-
1997
- /**
1998
- *
1999
- * @returns {undefined}
2000
- */
2001
- function initialize() {
2002
- var container = '#login_redirect-content';
2003
-
2004
- if ($(container).length) {
2005
- $('input[type="radio"]', container).each(function () {
2006
- $(this).bind('click', function () {
2007
- //hide all fields
2008
- $('.login-redirect-action').hide();
2009
-
2010
- //show the specific one
2011
- $($(this).data('action')).show();
2012
-
2013
- //save redirect type
2014
- aam.save(
2015
- $(this).attr('name'),
2016
- $(this).val(),
2017
- 'loginRedirect',
2018
- null,
2019
- function(result) {
2020
- if (result.status === 'success') {
2021
- $('#aam-login-redirect-overwrite').show();
2022
- }
2023
- }
2024
- );
2025
- });
2026
- });
2027
-
2028
- $('input[type="text"],select,textarea', container).each(function () {
2029
- $(this).bind('change', function () {
2030
- if ($(this).is('input[type="checkbox"]')) {
2031
- var val = $(this).prop('checked') ? $(this).val() : 0;
2032
- } else {
2033
- val = $.trim($(this).val());
2034
- }
2035
-
2036
- //save redirect type
2037
- aam.save(
2038
- $(this).attr('name'),
2039
- val,
2040
- 'loginRedirect',
2041
- null,
2042
- function(result) {
2043
- if (result.status === 'success') {
2044
- $('#aam-login-redirect-overwrite').show();
2045
- }
2046
- }
2047
- );
2048
- });
2049
- });
2050
-
2051
- $('#login-redirect-reset').bind('click', function () {
2052
- aam.reset('loginRedirect');
2053
- });
2054
- }
2055
- }
2056
-
2057
- aam.addHook('init', initialize);
2058
-
2059
- })(jQuery);
2060
-
2061
- /**
2062
- * Logout Redirect Interface
2063
- *
2064
- * @param {jQuery} $
2065
- *
2066
- * @returns {void}
2067
- */
2068
- (function ($) {
2069
-
2070
- /**
2071
- *
2072
- * @returns {undefined}
2073
- */
2074
- function initialize() {
2075
- var container = '#logout_redirect-content';
2076
-
2077
- if ($(container).length) {
2078
- $('input[type="radio"]', container).each(function () {
2079
- $(this).bind('click', function () {
2080
- //hide all fields
2081
- $('.logout-redirect-action').hide();
2082
-
2083
- //show the specific one
2084
- $($(this).data('action')).show();
2085
-
2086
- //save redirect type
2087
- aam.save(
2088
- $(this).attr('name'),
2089
- $(this).val(),
2090
- 'logoutRedirect',
2091
- null,
2092
- function(result) {
2093
- if (result.status === 'success') {
2094
- $('#aam-logout-redirect-overwrite').show();
2095
- }
2096
- }
2097
- );
2098
- });
2099
- });
2100
-
2101
- $('input[type="text"],select,textarea', container).each(function () {
2102
- $(this).bind('change', function () {
2103
- //save redirect type
2104
- aam.save(
2105
- $(this).attr('name'),
2106
- $(this).val(),
2107
- 'logoutRedirect',
2108
- null,
2109
- function(result) {
2110
- if (result.status === 'success') {
2111
- $('#aam-logout-redirect-overwrite').show();
2112
- }
2113
- }
2114
- );
2115
- });
2116
- });
2117
-
2118
- $('#logout-redirect-reset').bind('click', function () {
2119
- aam.reset('logoutRedirect');
2120
- });
2121
- }
2122
- }
2123
-
2124
- aam.addHook('init', initialize);
2125
-
2126
- })(jQuery);
2127
-
2128
- /**
2129
- * Teaser Interface
2130
- *
2131
- * @param {jQuery} $
2132
- *
2133
- * @returns {void}
2134
- */
2135
- (function ($) {
2136
-
2137
- /**
2138
- *
2139
- * @returns {undefined}
2140
- */
2141
- function initialize() {
2142
- var container = '#teaser-content';
2143
-
2144
- if ($(container).length) {
2145
- $('input, textarea', container).each(function () {
2146
- $(this).bind('change', function () {
2147
- if ($(this).is('input[type="checkbox"]')) {
2148
- var val = $(this).prop('checked') ? $(this).val() : 0;
2149
- } else {
2150
- val = $.trim($(this).val());
2151
- }
2152
- //save redirect type
2153
- aam.save(
2154
- $(this).attr('name'),
2155
- val,
2156
- 'teaser',
2157
- null,
2158
- function(result) {
2159
- if (result.status === 'success') {
2160
- $('#aam-teaser-overwrite').show();
2161
- }
2162
- }
2163
- );
2164
- });
2165
- });
2166
-
2167
- $('#teaser-reset').bind('click', function () {
2168
- aam.reset('teaser');
2169
- });
2170
- }
2171
- }
2172
-
2173
- aam.addHook('init', initialize);
2174
-
2175
- })(jQuery);
2176
-
2177
- /**
2178
- * 404 Redirect Interface
2179
- *
2180
- * @param {jQuery} $
2181
- *
2182
- * @returns {void}
2183
- */
2184
- (function ($) {
2185
-
2186
- /**
2187
- *
2188
- * @param {type} param
2189
- * @param {type} value
2190
- * @returns {undefined}
2191
- */
2192
- function save(param, value) {
2193
- $.ajax(aamLocal.ajaxurl, {
2194
- type: 'POST',
2195
- dataType: 'json',
2196
- data: {
2197
- action: 'aam',
2198
- sub_action: '404Redirect.save',
2199
- _ajax_nonce: aamLocal.nonce,
2200
- subject: aam.getSubject().type,
2201
- subjectId: aam.getSubject().id,
2202
- param: param,
2203
- value: value
2204
- },
2205
- error: function () {
2206
- aam.notification('danger', aam.__('Application error'));
2207
- }
2208
- });
2209
- }
2210
-
2211
- /**
2212
- *
2213
- * @returns {undefined}
2214
- */
2215
- function initialize() {
2216
- var container = '#404redirect-content';
2217
-
2218
- if ($(container).length) {
2219
- $('input[type="radio"]', container).each(function () {
2220
- $(this).bind('click', function () {
2221
- //hide group
2222
- $('.aam-404redirect-action').hide();
2223
-
2224
- //show the specific one
2225
- $($(this).data('action')).show();
2226
-
2227
- //save redirect type
2228
- save($(this).attr('name'), $(this).val());
2229
- });
2230
- });
2231
-
2232
- $('input[type="text"],select,textarea', container).each(function () {
2233
- $(this).bind('change', function () {
2234
- //save redirect type
2235
- save($(this).attr('name'), $(this).val());
2236
- });
2237
- });
2238
- }
2239
- }
2240
-
2241
- aam.addHook('init', initialize);
2242
-
2243
- })(jQuery);
2244
-
2245
- /**
2246
- * Extensions Interface
2247
- *
2248
- * @param {jQuery} $
2249
- *
2250
- * @returns {void}
2251
- */
2252
- (function ($) {
2253
-
2254
- var dump = null;
2255
-
2256
- /**
2257
- *
2258
- * @param {*} data
2259
- * @param {*} completeCallback
2260
- */
2261
- function downloadExtension(data, completeCallback) {
2262
- $.ajax(aamLocal.ajaxurl, {
2263
- type: 'POST',
2264
- dataType: 'json',
2265
- data: data,
2266
- success: function (response) {
2267
- if (response.status === 'success') {
2268
- setTimeout(function () {
2269
- location.reload();
2270
- }, 500);
2271
- } else {
2272
- aam.notification('danger', aam.__(response.error));
2273
- if (typeof response.content !== 'undefined') {
2274
- dump = response;
2275
- $('#installation-error').html(response.error);
2276
- $('#extension-notification-modal').modal('show');
2277
- }
2278
- }
2279
- },
2280
- error: function () {
2281
- aam.notification('danger', aam.__('Application error'));
2282
- },
2283
- complete: function() {
2284
- completeCallback();
2285
- }
2286
- });
2287
- }
2288
-
2289
- /**
2290
- *
2291
- * @returns {undefined}
2292
- */
2293
- function initialize() {
2294
- if ($('#extension-content').length) {
2295
- //check for updates
2296
- $('#aam-update-check').bind('click', function() {
2297
- $.ajax(aamLocal.ajaxurl, {
2298
- type: 'POST',
2299
- dataType: 'json',
2300
- data: {
2301
- action: 'aam',
2302
- sub_action: 'Extension.check',
2303
- _ajax_nonce: aamLocal.nonce,
2304
- },
2305
- beforeSend: function () {
2306
- $('#aam-update-check i').attr('class', 'icon-spin4 animate-spin');
2307
- },
2308
- complete: function () {
2309
- location.reload();
2310
- }
2311
- });
2312
- });
2313
-
2314
- //init refresh list button
2315
- $('#install-extension').bind('click', function () {
2316
- $('#extension-key').parent().removeClass('error');
2317
-
2318
- var _this = $(this);
2319
- var license = $.trim($('#extension-key').val());
2320
-
2321
- if (!license) {
2322
- $('#extension-key').parent().addClass('error');
2323
- $('#extension-key').focus();
2324
- return;
2325
- }
2326
-
2327
- $('i', _this).attr('class', 'icon-spin4 animate-spin');
2328
- downloadExtension({
2329
- action: 'aam',
2330
- sub_action: 'Extension.install',
2331
- _ajax_nonce: aamLocal.nonce,
2332
- license: $('#extension-key').val(),
2333
- function() {
2334
- $('i', _this).attr('class', 'icon-download-cloud');
2335
- }
2336
- });
2337
- });
2338
-
2339
- //update extension
2340
- $('.aam-update-extension').each(function () {
2341
- $(this).bind('click', function () {
2342
- var _this = $(this);
2343
-
2344
- $('i', _this).attr('class', 'icon-spin4 animate-spin');
2345
- downloadExtension({
2346
- action: 'aam',
2347
- sub_action: 'Extension.update',
2348
- _ajax_nonce: aamLocal.nonce,
2349
- extension: _this.data('product'),
2350
- function() {
2351
- $('i', _this).attr('class', 'icon-arrows-cw');
2352
- }
2353
- });
2354
- });
2355
- });
2356
-
2357
- //download extension
2358
- $('.aam-download-extension').each(function () {
2359
- $(this).bind('click', function () {
2360
- var _this = $(this);
2361
-
2362
- $('i', _this).attr('class', 'icon-spin4 animate-spin');
2363
- downloadExtension({
2364
- action: 'aam',
2365
- sub_action: 'Extension.install',
2366
- _ajax_nonce: aamLocal.nonce,
2367
- license: _this.data('license'),
2368
- function() {
2369
- $('i', _this).attr('class', 'icon-download-cloud');
2370
- }
2371
- });
2372
- });
2373
- });
2374
-
2375
- //bind the download handler
2376
- $('#download-extension').bind('click', function () {
2377
- download(
2378
- 'data:application/zip;base64,' + dump.content,
2379
- dump.title + '.zip',
2380
- 'application/zip'
2381
- );
2382
- $('#extension-notification-modal').modal('hide');
2383
- });
2384
-
2385
- if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) {
2386
- $('#safari-download-notification').removeClass('hidden');
2387
- }
2388
- }
2389
- }
2390
-
2391
- aam.addHook('init', initialize);
2392
-
2393
- })(jQuery);
2394
-
2395
-
2396
- /**
2397
- * Utilities Interface
2398
- *
2399
- * @param {type} $
2400
- *
2401
- * @returns {undefined}
2402
- */
2403
- (function ($) {
2404
-
2405
- /**
2406
- *
2407
- * @param {type} param
2408
- * @param {type} value
2409
- * @returns {undefined}
2410
- */
2411
- function save(param, value) {
2412
- $.ajax(aamLocal.ajaxurl, {
2413
- type: 'POST',
2414
- dataType: 'json',
2415
- data: {
2416
- action: 'aam',
2417
- sub_action: 'Utility.save',
2418
- _ajax_nonce: aamLocal.nonce,
2419
- param: param,
2420
- value: value
2421
- },
2422
- error: function () {
2423
- aam.notification('danger', aam.__('Application Error'));
2424
- }
2425
- });
2426
- }
2427
-
2428
- /**
2429
- *
2430
- * @returns {undefined}
2431
- */
2432
- function initialize() {
2433
- if ($('#utilities-content').length) {
2434
- $('[data-toggle="toggle"]').bootstrapToggle();
2435
-
2436
- $('input[type="checkbox"]', '#utilities-content').bind('change', function () {
2437
- save($(this).attr('name'), ($(this).prop('checked') ? 1 : 0));
2438
- });
2439
-
2440
- $('input[type="text"]', '#utilities-content').bind('change', function() {
2441
- save($(this).attr('name'), $(this).val());
2442
- });
2443
-
2444
- $('#clear-settings').bind('click', function () {
2445
- $.ajax(aamLocal.ajaxurl, {
2446
- type: 'POST',
2447
- dataType: 'json',
2448
- data: {
2449
- action: 'aam',
2450
- sub_action: 'Utility.clear',
2451
- _ajax_nonce: aamLocal.nonce
2452
- },
2453
- beforeSend: function() {
2454
- $('#clear-settings').prop('disabled', true);
2455
- },
2456
- success: function (response) {
2457
- if (response.status === 'success') {
2458
- location.reload();
2459
- }
2460
- },
2461
- error: function () {
2462
- aam.notification('danger', aam.__('Application Error'));
2463
- },
2464
- complete: function() {
2465
- $('#clear-settings').prop('disabled', false);
2466
- }
2467
- });
2468
- });
2469
-
2470
- $('#clear-cache').bind('click', function () {
2471
- $.ajax(aamLocal.ajaxurl, {
2472
- type: 'POST',
2473
- dataType: 'json',
2474
- data: {
2475
- action: 'aam',
2476
- sub_action: 'Utility.clearCache',
2477
- _ajax_nonce: aamLocal.nonce
2478
- },
2479
- beforeSend: function() {
2480
- $('#clear-cache').prop('disabled', true);
2481
- },
2482
- success: function (response) {
2483
- if (response.status === 'success') {
2484
- location.reload();
2485
- }
2486
- },
2487
- error: function () {
2488
- aam.notification('danger', aam.__('Application Error'));
2489
- },
2490
- complete: function() {
2491
- $('#clear-cache').prop('disabled', false);
2492
- }
2493
- });
2494
- });
2495
-
2496
- $('#export-aam').bind('click', function () {
2497
- $.ajax(aamLocal.ajaxurl, {
2498
- type: 'POST',
2499
- dataType: 'json',
2500
- data: {
2501
- action: 'aam',
2502
- sub_action: 'Utility.export',
2503
- _ajax_nonce: aamLocal.nonce
2504
- },
2505
- beforeSend: function () {
2506
- $('#export-aam').attr('data-lable', $('#export-aam').text());
2507
- $('#export-aam').html('<i class="icon-spin4 animate-spin"></i>');
2508
- },
2509
- success: function(response) {
2510
- if (response.status === 'success') {
2511
- download(
2512
- 'data:text/plain;base64,' + response.content,
2513
- 'aam-export.json',
2514
- 'text/plain'
2515
- );
2516
- }
2517
- },
2518
- error: function () {
2519
- aam.notification('danger', aam.__('Application Error'));
2520
- },
2521
- complete: function () {
2522
- $('#export-aam').html($('#export-aam').attr('data-lable'));
2523
- }
2524
- });
2525
- });
2526
-
2527
- $('#import-aam').bind('click', function () {
2528
- if (typeof FileReader !== 'undefined') {
2529
- $('#aam-import-file').trigger('click');
2530
- } else {
2531
- aam.notification('danger', 'Your browser does not support FileReader functionality');
2532
- }
2533
- });
2534
-
2535
- $('#aam-import-file').bind('change', function () {
2536
- var file = $(this)[0].files[0];
2537
- var json = null;
2538
-
2539
- var reader = new FileReader();
2540
- reader.onload = function(e) {
2541
- json = reader.result;
2542
-
2543
- try {
2544
- //validate the content
2545
- var loaded = JSON.parse(json);
2546
- if (loaded.plugin && loaded.plugin == 'advanced-access-manager') {
2547
- $.ajax(aamLocal.ajaxurl, {
2548
- type: 'POST',
2549
- dataType: 'json',
2550
- data: {
2551
- action: 'aam',
2552
- sub_action: 'Utility.import',
2553
- _ajax_nonce: aamLocal.nonce,
2554
- json: json
2555
- },
2556
- beforeSend: function () {
2557
- $('#import-aam').attr('data-lable', $('#import-aam').text());
2558
- $('#import-aam').html('<i class="icon-spin4 animate-spin"></i>');
2559
- },
2560
- success: function(response) {
2561
- if (response.status === 'success') {
2562
- aam.notification('success', 'Data Imported Successfully');
2563
- // location.reload();
2564
- } else {
2565
- aam.notification('danger', aam.__('Invalid data format'));
2566
- }
2567
- },
2568
- error: function () {
2569
- aam.notification('danger', aam.__('Application Error'));
2570
- },
2571
- complete: function () {
2572
- $('#import-aam').html($('#import-aam').attr('data-lable'));
2573
- }
2574
- });
2575
- } else {
2576
- throw 'Invalid format';
2577
- }
2578
- } catch (e) {
2579
- aam.notification('danger', 'Invalid file format');
2580
- }
2581
- };
2582
- reader.readAsText(file);
2583
-
2584
- });
2585
- }
2586
- }
2587
-
2588
- aam.addHook('init', initialize);
2589
-
2590
- })(jQuery);
2591
-
2592
- /**
2593
- * Main Panel Interface
2594
- *
2595
- * @param {jQuery} $
2596
- *
2597
- * @returns {void}
2598
- */
2599
- (function ($) {
2600
-
2601
- /**
2602
- *
2603
- * @returns {undefined}
2604
- */
2605
- function initializeMenu() {
2606
- //initialize the menu switch
2607
- $('li', '#feature-list').each(function () {
2608
- $(this).bind('click', function () {
2609
- $('.aam-feature').removeClass('active');
2610
- //highlight active feature
2611
- $('li', '#feature-list').removeClass('active');
2612
- $(this).addClass('active');
2613
- //show feature content
2614
- $('#' + $(this).data('feature') + '-content').addClass('active');
2615
- location.hash = $(this).data('feature');
2616
- //trigger hook
2617
- aam.triggerHook('menu-feature-click', $(this).data('feature'));
2618
- });
2619
- });
2620
- }
2621
-
2622
- /**
2623
- *
2624
- * @returns {undefined}
2625
- */
2626
- aam.fetchContent = function () {
2627
- //referred object ID like post, page or any custom post type
2628
- var object = window.location.search.match(/&oid\=([^&]*)/);
2629
- var type = window.location.search.match(/&otype\=([^&]*)/);
2630
-
2631
- $.ajax(aamLocal.url.site, {
2632
- type: 'POST',
2633
- dataType: 'html',
2634
- data: {
2635
- action: 'aamc',
2636
- _ajax_nonce: aamLocal.nonce,
2637
- subject: this.getSubject().type,
2638
- subjectId: this.getSubject().id,
2639
- oid: object ? object[1] : null,
2640
- otype: type ? type[1] : null
2641
- },
2642
- beforeSend: function () {
2643
- var loader = $('<div/>', {'class': 'aam-loading'}).html(
2644
- '<i class="icon-spin4 animate-spin"></i>'
2645
- );
2646
- $('#aam-content').html(loader);
2647
- },
2648
- success: function (response) {
2649
- $('#aam-content').html(response);
2650
- //init menu
2651
- initializeMenu();
2652
- //trigger initialization hook
2653
- aam.triggerHook('init');
2654
- //activate one of the menu items
2655
- var item = $('li:eq(0)', '#feature-list');
2656
-
2657
- if (location.hash !== '') {
2658
- var hash = location.hash.substr(1);
2659
- if ($('li[data-feature="' + hash + '"]', '#feature-list').length) {
2660
- item = $('li[data-feature="' + hash + '"]', '#feature-list');
2661
- }
2662
- }
2663
-
2664
- item.trigger('click');
2665
- }
2666
- });
2667
- };
2668
-
2669
- aam.fetchContent(); //fetch default AAM content
2670
-
2671
- })(jQuery);
2672
-
2673
- /**
2674
- * Miscellenious features
2675
- *
2676
- */
2677
- (function ($) {
2678
- $('#subscribe').bind('click', function() {
2679
- var email = $('#subscribe-email').val();
2680
-
2681
- if (email) {
2682
- $.ajax(aamLocal.ajaxurl, {
2683
- type: 'POST',
2684
- dataType: 'json',
2685
- data: {
2686
- action: 'aam',
2687
- sub_action: 'subscribe',
2688
- _ajax_nonce: aamLocal.nonce,
2689
- email: email
2690
- },
2691
- beforeSend: function () {
2692
- $('#subscribe i').attr('class', 'icon-spin4 animate-spin');
2693
- },
2694
- success: function(response) {
2695
- if (response.status === 'success') {
2696
- aam.notification('success', aam.__('Your are subscribed now!'));
2697
- $('#subscribe-email').val('');
2698
- } else {
2699
- aam.notification('danger', response.reason);
2700
- }
2701
- },
2702
- error: function () {
2703
- aam.notification('danger', aam.__('Application Error'));
2704
- },
2705
- complete: function() {
2706
- $('#subscribe i').attr('class', 'icon-rss');
2707
- }
2708
- });
2709
- }
2710
- });
2711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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
media/js/aam.js CHANGED
@@ -5,12 +5,2601 @@
5
  * ======================================================================
6
  */
7
 
 
8
  /**
9
  *
10
  * @param {type} $
11
  * @returns {undefined}
12
  */
13
  (function ($) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  /**
16
  * Main AAM class
@@ -18,7 +2607,6 @@
18
  * @returns void
19
  */
20
  function AAM() {
21
-
22
  /**
23
  * Current Subject
24
  */
@@ -28,8 +2616,81 @@
28
  * Different UI hooks
29
  */
30
  this.hooks = {};
31
-
32
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  /**
35
  * Add UI hook
@@ -78,7 +2739,7 @@
78
  );
79
 
80
  //load the UI javascript support
81
- $.getScript(aamLocal.url.jsbase + '/aam-interface.js');
82
 
83
  //initialize help context
84
  $('.aam-help-menu').each(function() {
@@ -124,12 +2785,14 @@
124
  return (aamLocal.translation[label] ? aamLocal.translation[label] : label);
125
  };
126
 
127
- /**
128
- *
129
- * @param {type} type
130
- * @param {type} id
131
- * @returns {undefined}
132
- */
 
 
133
  AAM.prototype.setSubject = function (type, id, name, level) {
134
  this.subject = {
135
  type: type,
@@ -183,6 +2846,12 @@
183
 
184
  /**
185
  *
 
 
 
 
 
 
186
  */
187
  AAM.prototype.save = function(param, value, object, object_id, successCallback) {
188
  $.ajax(aamLocal.ajaxurl, {
@@ -212,7 +2881,7 @@
212
 
213
  /**
214
  *
215
- * @param {type} option
216
  * @returns {undefined}
217
  */
218
  AAM.prototype.reset = function(object) {
@@ -251,6 +2920,10 @@
251
  }));
252
  };
253
 
 
 
 
 
254
  AAM.prototype.isUI = function() {
255
  return (typeof aamLocal.ui !== 'undefined');
256
  };
@@ -260,8 +2933,8 @@
260
  */
261
  $(document).ready(function () {
262
  aam = new AAM();
263
- aam.initialize();
264
  $.aam = aam;
 
265
  });
266
 
267
  })(jQuery);
5
  * ======================================================================
6
  */
7
 
8
+
9
  /**
10
  *
11
  * @param {type} $
12
  * @returns {undefined}
13
  */
14
  (function ($) {
15
+
16
+ /**
17
+ *
18
+ * @returns {undefined}
19
+ */
20
+ function UI() {
21
+ /**
22
+ * Role List Interface
23
+ *
24
+ * @param {jQuery} $
25
+ *
26
+ * @returns {void}
27
+ */
28
+ (function ($) {
29
+
30
+ /**
31
+ *
32
+ * @param {type} id
33
+ * @returns {Boolean}
34
+ */
35
+ function isCurrent(id) {
36
+ var subject = aam.getSubject();
37
+
38
+ return (subject.type === 'role' && subject.id === id);
39
+ }
40
+
41
+ /**
42
+ *
43
+ * @returns {undefined}
44
+ */
45
+ function fetchRoleList(exclude) {
46
+ $.ajax(aamLocal.ajaxurl, {
47
+ type: 'POST',
48
+ dataType: 'json',
49
+ data: {
50
+ action: 'aam',
51
+ sub_action: 'Role.getList',
52
+ _ajax_nonce: aamLocal.nonce,
53
+ exclude: exclude
54
+ },
55
+ beforeSend: function () {
56
+ $('.inherit-role-list').html(
57
+ '<option value="">' + aam.__('Loading...') + '</option>'
58
+ );
59
+ },
60
+ success: function (response) {
61
+ $('.inherit-role-list').html(
62
+ '<option value="">' + aam.__('No Role') + '</option>'
63
+ );
64
+ for (var i in response) {
65
+ $('.inherit-role-list').append(
66
+ '<option value="' + i + '">' + response[i].name + '</option>'
67
+ );
68
+ }
69
+ if ($.aamEditRole) {
70
+ $('#inherit-role').val($.aamEditRole[0]);
71
+ }
72
+ aam.triggerHook('post-get-role-list', {
73
+ list : response
74
+ });
75
+ //TODO - Rerwite JavaScript to support $.aam
76
+ $.aamEditRole = null;
77
+ }
78
+ });
79
+ }
80
+
81
+ //initialize the role list table
82
+ $('#role-list').DataTable({
83
+ autoWidth: false,
84
+ ordering: false,
85
+ dom: 'ftrip',
86
+ pagingType: 'simple',
87
+ processing: true,
88
+ serverSide: false,
89
+ ajax: {
90
+ url: aamLocal.ajaxurl,
91
+ type: 'POST',
92
+ dataType: 'json',
93
+ data: {
94
+ action: 'aam',
95
+ sub_action: 'Role.getTable',
96
+ _ajax_nonce: aamLocal.nonce
97
+ }
98
+ },
99
+ columnDefs: [
100
+ {visible: false, targets: [0, 1, 4, 5]}
101
+ ],
102
+ language: {
103
+ search: '_INPUT_',
104
+ searchPlaceholder: aam.__('Search Role'),
105
+ info: aam.__('_TOTAL_ role(s)'),
106
+ infoFiltered: ''
107
+ },
108
+ initComplete: function () {
109
+ if (!aam.isUI() && parseInt(aamLocal.caps.create_roles)) {
110
+ var create = $('<a/>', {
111
+ 'href': '#',
112
+ 'class': 'btn btn-primary'
113
+ }).html('<i class="icon-plus"></i> ' + aam.__('Create'))
114
+ .bind('click', function () {
115
+ $('#add-role-modal').modal('show');
116
+ });
117
+
118
+ $('.dataTables_filter', '#role-list_wrapper').append(create);
119
+ }
120
+ },
121
+ createdRow: function (row, data) {
122
+ if (isCurrent(data[0])) {
123
+ $('td:eq(0)', row).html('<strong class="aam-highlight">' + data[2] + '</strong>');
124
+ } else {
125
+ $('td:eq(0)', row).html('<span>' + data[2] + '</span>');
126
+ }
127
+
128
+ $(row).attr('data-id', data[0]);
129
+
130
+ //add subtitle
131
+ var expire = (data[5] ? '; <i class="icon-clock"></i>' : '');
132
+ $('td:eq(0)', row).append(
133
+ $('<i/>', {'class': 'aam-row-subtitle'}).html(
134
+ aam.__('Users') + ': <b>' + parseInt(data[1]) + '</b>; ID: <b>' + data[0] + '</b>' + expire
135
+ )
136
+ );
137
+
138
+ var actions = data[3].split(',');
139
+
140
+ var container = $('<div/>', {'class': 'aam-row-actions'});
141
+ $.each(actions, function (i, action) {
142
+ switch (action) {
143
+ case 'manage':
144
+ $(container).append($('<i/>', {
145
+ 'class': 'aam-row-action icon-cog ' + (isCurrent(data[0]) ? 'text-muted': 'text-info')
146
+ }).bind('click', function () {
147
+ if (!$(this).prop('disabled')) {
148
+ $(this).prop('disabled', true);
149
+ var title = $('td:eq(0) span', row).html();
150
+ aam.setSubject('role', data[0], title, data[4]);
151
+ $('td:eq(0) span', row).replaceWith(
152
+ '<strong class="aam-highlight">' + title + '</strong>'
153
+ );
154
+ $('i.icon-cog', container).attr(
155
+ 'class', 'aam-row-action icon-cog text-muted'
156
+ );
157
+ if (!aam.isUI()) {
158
+ $('i.icon-cog', container).attr(
159
+ 'class', 'aam-row-action icon-spin4 animate-spin'
160
+ );
161
+ aam.fetchContent();
162
+ $('i.icon-spin4', container).attr(
163
+ 'class', 'aam-row-action icon-cog text-muted'
164
+ );
165
+ } else {
166
+ $.aam.loadAccessForm($('#load-post-object-type').val(), $('#load-post-object').val(), $(this));
167
+ }
168
+ }
169
+ }).attr({
170
+ 'data-toggle': "tooltip",
171
+ 'title': aam.__('Manage Role')
172
+ }).prop('disabled', (isCurrent(data[0]) ? true: false)));
173
+ break;
174
+
175
+ case 'edit':
176
+ if (!aam.isUI()) {
177
+ $(container).append($('<i/>', {
178
+ 'class': 'aam-row-action icon-pencil text-warning'
179
+ }).bind('click', function () {
180
+ $('#edit-role-btn').data('role', data[0]);
181
+ $('#edit-role-name').val(data[2]);
182
+ $('#edit-role-expiration').val(data[5]);
183
+ $('#edit-role-modal').modal('show');
184
+ fetchRoleList(data[0]);
185
+ //TODO - Rerwite JavaScript to support $.aam
186
+ $.aamEditRole = data;
187
+ }).attr({
188
+ 'data-toggle': "tooltip",
189
+ 'title': aam.__('Edit Role')
190
+ }));
191
+ }
192
+ break;
193
+
194
+ case 'clone':
195
+ if (!aam.isUI()) {
196
+ $(container).append($('<i/>', {
197
+ 'class': 'aam-row-action icon-clone text-success'
198
+ }).bind('click', function () {
199
+ //TODO - Rerwite JavaScript to support $.aam
200
+ $.aamEditRole = data;
201
+ $('#clone-role').prop('checked', true);
202
+ $('#add-role-modal').modal('show');
203
+ }).attr({
204
+ 'data-toggle': "tooltip",
205
+ 'title': aam.__('Clone Role')
206
+ }));
207
+ }
208
+ break;
209
+
210
+ case 'delete':
211
+ if (!aam.isUI()) {
212
+ $(container).append($('<i/>', {
213
+ 'class': 'aam-row-action icon-trash-empty text-danger'
214
+ }).bind('click', {role: data}, function (event) {
215
+ $('#delete-role-btn').data('role', data[0]);
216
+ var message = $('#delete-role-modal .aam-confirm-message').data('message');
217
+ $('#delete-role-modal .aam-confirm-message').html(
218
+ message.replace(
219
+ '%s', '<strong>' + event.data.role[2] + '</strong>'
220
+ )
221
+ );
222
+
223
+ $('#delete-role-modal').modal('show');
224
+ }).attr({
225
+ 'data-toggle': "tooltip",
226
+ 'title': aam.__('Delete Role')
227
+ }));
228
+ }
229
+ break;
230
+
231
+ default:
232
+ if (!aam.isUI()) {
233
+ aam.triggerHook('role-action', {
234
+ container: container,
235
+ action : action,
236
+ data : data
237
+ });
238
+ }
239
+ break;
240
+ }
241
+ });
242
+ $('td:eq(1)', row).html(container);
243
+
244
+ aam.triggerHook('decorate-role-row', {
245
+ row : row,
246
+ data: data
247
+ });
248
+ }
249
+ });
250
+
251
+ $('#role-list').on( 'draw.dt', function () {
252
+ $('tr', '#role-list tbody').each(function() {
253
+ if (!isCurrent($(this).data('id'))) {
254
+ $('td:eq(0) strong', this).replaceWith(
255
+ '<span>' + $('td:eq(0) strong', this).text() + '</span>'
256
+ );
257
+ $('.text-muted', this).attr('disabled', false);
258
+ $('.text-muted', this).toggleClass('text-muted text-info');
259
+ }
260
+ });
261
+ } );
262
+
263
+ $('#add-role-modal').on('shown.bs.modal', function (e) {
264
+ fetchRoleList();
265
+ //clear add role form first
266
+ $('input[name="name"]', '#add-role-modal').val('').focus();
267
+ });
268
+
269
+ $('#edit-role-modal').on('shown.bs.modal', function (e) {
270
+ $('input[name="name"]', '#edit-role-modal').focus();
271
+ });
272
+
273
+ //add role button
274
+ $('#add-role-btn').bind('click', function () {
275
+ var _this = this;
276
+
277
+ $('input[name="name"]', '#add-role-modal').parent().removeClass('has-error');
278
+
279
+ var data = {
280
+ action: 'aam',
281
+ sub_action: 'Role.add',
282
+ _ajax_nonce: aamLocal.nonce
283
+ };
284
+
285
+ $('input,select', '#add-role-modal .modal-body').each(function() {
286
+ if ($(this).attr('type') === 'checkbox') {
287
+ data[$(this).attr('name')] = $(this).prop('checked') ? 1 : 0;
288
+ } else {
289
+ data[$(this).attr('name')] = $.trim($(this).val());
290
+ }
291
+ });
292
+
293
+ if (data.name) {
294
+ $.ajax(aamLocal.ajaxurl, {
295
+ type: 'POST',
296
+ dataType: 'json',
297
+ data: data,
298
+ beforeSend: function () {
299
+ $(_this).text(aam.__('Saving...')).attr('disabled', true);
300
+ },
301
+ success: function (response) {
302
+ if (response.status === 'success') {
303
+ $('#role-list').DataTable().ajax.reload();
304
+ aam.setSubject(
305
+ 'role',
306
+ response.role.id,
307
+ response.role.name,
308
+ response.role.level
309
+ );
310
+ aam.fetchContent();
311
+ $('#add-role-modal').modal('hide');
312
+ } else {
313
+ aam.notification(
314
+ 'danger', aam.__('Failed to add new role')
315
+ );
316
+ }
317
+ },
318
+ error: function () {
319
+ aam.notification('danger', aam.__('Application error'));
320
+ },
321
+ complete: function () {
322
+ $(_this).text(aam.__('Add Role')).attr('disabled', false);
323
+ }
324
+ });
325
+ } else {
326
+ $('input,select', '#add-role-modal .modal-body').focus().parent().addClass('has-error');
327
+ }
328
+ });
329
+
330
+ //edit role button
331
+ $('#edit-role-btn').bind('click', function () {
332
+ var _this = this;
333
+
334
+ $('#edit-role-name').parent().removeClass('has-error');
335
+
336
+ var data = {
337
+ action: 'aam',
338
+ sub_action: 'Role.edit',
339
+ _ajax_nonce: aamLocal.nonce,
340
+ subject: 'role',
341
+ subjectId: $(_this).data('role')
342
+ };
343
+
344
+ $('input,select', '#edit-role-modal .modal-body').each(function() {
345
+ data[$(this).attr('name')] = $.trim($(this).val());
346
+ });
347
+
348
+ if (data.name) {
349
+ $.ajax(aamLocal.ajaxurl, {
350
+ type: 'POST',
351
+ dataType: 'json',
352
+ data: data,
353
+ beforeSend: function () {
354
+ $(_this).text(aam.__('Saving...')).attr('disabled', true);
355
+ },
356
+ success: function (response) {
357
+ if (response.status === 'success') {
358
+ $('#role-list').DataTable().ajax.reload();
359
+ } else {
360
+ aam.notification(
361
+ 'danger', aam.__('Failed to update role')
362
+ );
363
+ }
364
+ },
365
+ error: function () {
366
+ aam.notification('danger', aam.__('Application error'));
367
+ },
368
+ complete: function () {
369
+ $('#edit-role-modal').modal('hide');
370
+ $(_this).text(aam.__('Update')).attr('disabled', false);
371
+ }
372
+ });
373
+ } else {
374
+ $('#edit-role-name').focus().parent().addClass('has-error');
375
+ }
376
+ });
377
+
378
+ //edit role button
379
+ $('#delete-role-btn').bind('click', function () {
380
+ var _this = this;
381
+
382
+ $.ajax(aamLocal.ajaxurl, {
383
+ type: 'POST',
384
+ dataType: 'json',
385
+ data: {
386
+ action: 'aam',
387
+ sub_action: 'Role.delete',
388
+ _ajax_nonce: aamLocal.nonce,
389
+ subject: 'role',
390
+ subjectId: $(_this).data('role')
391
+ },
392
+ beforeSend: function () {
393
+ $(_this).text(aam.__('Deleting...')).attr('disabled', true);
394
+ },
395
+ success: function (response) {
396
+ if (response.status === 'success') {
397
+ $('#role-list').DataTable().ajax.reload();
398
+ } else {
399
+ aam.notification('danger', aam.__('Failed to delete role'));
400
+ }
401
+ },
402
+ error: function () {
403
+ aam.notification('danger', aam.__('Application error'));
404
+ },
405
+ complete: function () {
406
+ $('#delete-role-modal').modal('hide');
407
+ $(_this).text(aam.__('Delete Role')).attr('disabled', false);
408
+ }
409
+ });
410
+ });
411
+
412
+ //add setSubject hook
413
+ aam.addHook('setSubject', function () {
414
+ //clear highlight
415
+ $('tbody tr', '#role-list').each(function () {
416
+ if ($('strong', $(this)).length) {
417
+ var highlight = $('strong', $(this));
418
+ $('.icon-cog', $(this)).toggleClass('text-muted text-info');
419
+ $('.icon-cog', $(this)).prop('disabled', false);
420
+ highlight.replaceWith($('<span/>').text(highlight.text()));
421
+ }
422
+ });
423
+ //show post & pages access control groups that belong to backend
424
+ $('.aam-backend-post-access').show();
425
+ });
426
+
427
+ //in case interface needed to be reloaded
428
+ aam.addHook('refresh', function () {
429
+ $('#role-list').DataTable().ajax.url(aamLocal.ajaxurl).load();
430
+ });
431
+
432
+ })(jQuery);
433
+
434
+
435
+ /**
436
+ * User List Interface
437
+ *
438
+ * @param {jQuery} $
439
+ *
440
+ * @returns {void}
441
+ */
442
+ (function ($) {
443
+
444
+ /**
445
+ *
446
+ * @param {type} id
447
+ * @returns {Boolean}
448
+ */
449
+ function isCurrent(id) {
450
+ var subject = aam.getSubject();
451
+
452
+ return (subject.type === 'user' && parseInt(subject.id) === id);
453
+ }
454
+
455
+ /**
456
+ *
457
+ * @param {type} id
458
+ * @param {type} btn
459
+ * @returns {undefined}
460
+ */
461
+ function blockUser(id, btn) {
462
+ var state = ($(btn).hasClass('icon-lock') ? 0 : 1);
463
+
464
+ $.ajax(aamLocal.ajaxurl, {
465
+ type: 'POST',
466
+ dataType: 'json',
467
+ data: {
468
+ action: 'aam',
469
+ sub_action: 'User.block',
470
+ _ajax_nonce: aamLocal.nonce,
471
+ subject: 'user',
472
+ subjectId: id
473
+ },
474
+ beforeSend: function () {
475
+ $(btn).attr('class', 'aam-row-action icon-spin4 animate-spin');
476
+ },
477
+ success: function (response) {
478
+ if (response.status === 'success') {
479
+ if (state === 1) {
480
+ $(btn).attr({
481
+ 'class': 'aam-row-action icon-lock text-danger',
482
+ 'title': aam.__('Unlock User'),
483
+ 'data-original-title': aam.__('Unlock User')
484
+ });
485
+ } else {
486
+ $(btn).attr({
487
+ 'class': 'aam-row-action icon-lock-open-alt text-warning',
488
+ 'title': aam.__('Lock User'),
489
+ 'data-original-title': aam.__('Lock User')
490
+ });
491
+ }
492
+ } else {
493
+ aam.notification('danger', aam.__('Failed to block user'));
494
+ }
495
+ },
496
+ error: function () {
497
+ aam.notification('danger', aam.__('Application error'));
498
+ }
499
+ });
500
+ }
501
+
502
+ /**
503
+ *
504
+ * @param {type} id
505
+ * @param {type} btn
506
+ * @returns {undefined}
507
+ */
508
+ function switchToUser(id, btn) {
509
+ $.ajax(aamLocal.ajaxurl, {
510
+ type: 'POST',
511
+ dataType: 'json',
512
+ data: {
513
+ action: 'aam',
514
+ sub_action: 'switchToUser',
515
+ _ajax_nonce: aamLocal.nonce,
516
+ user: id
517
+ },
518
+ beforeSend: function () {
519
+ $(btn).attr('class', 'aam-row-action icon-spin4 animate-spin');
520
+ },
521
+ success: function (response) {
522
+ if (response.status === 'success') {
523
+ location.href = response.redirect;
524
+ } else {
525
+ aam.notification('danger', response.reason);
526
+ }
527
+ },
528
+ error: function () {
529
+ aam.notification('danger', aam.__('Application error'));
530
+ },
531
+ complete: function () {
532
+ $(btn).attr('class', 'aam-row-action icon-exchange text-success');
533
+ }
534
+ });
535
+ }
536
+
537
+ //initialize the user list table
538
+ $('#user-list').DataTable({
539
+ autoWidth: false,
540
+ ordering: false,
541
+ dom: 'ftrip',
542
+ pagingType: 'simple',
543
+ serverSide: true,
544
+ processing: true,
545
+ ajax: {
546
+ url: aamLocal.ajaxurl,
547
+ type: 'POST',
548
+ dataType: 'json',
549
+ data: {
550
+ action: 'aam',
551
+ sub_action: 'User.getTable',
552
+ _ajax_nonce: aamLocal.nonce
553
+ }
554
+ },
555
+ columnDefs: [
556
+ {visible: false, targets: [0, 1, 4]}
557
+ ],
558
+ language: {
559
+ search: '_INPUT_',
560
+ searchPlaceholder: aam.__('Search User'),
561
+ info: aam.__('_TOTAL_ user(s)'),
562
+ infoFiltered: ''
563
+ },
564
+ initComplete: function () {
565
+ if (!aam.isUI() && parseInt(aamLocal.caps.create_users)) {
566
+ var create = $('<a/>', {
567
+ 'href': '#',
568
+ 'class': 'btn btn-primary'
569
+ }).html('<i class="icon-plus"></i> ' + aam.__('Create')).bind('click', function () {
570
+ window.open(aamLocal.url.addUser, '_blank');
571
+ });
572
+
573
+ $('.dataTables_filter', '#user-list_wrapper').append(create);
574
+ }
575
+ },
576
+ createdRow: function (row, data) {
577
+ if (isCurrent(data[0])) {
578
+ $('td:eq(0)', row).html('<strong class="aam-highlight">' + data[2] + '</strong>');
579
+ } else {
580
+ $('td:eq(0)', row).html('<span>' + data[2] + '</span>');
581
+ }
582
+
583
+ //add subtitle
584
+ $('td:eq(0)', row).append(
585
+ $('<i/>', {'class': 'aam-row-subtitle'}).html(
586
+ aam.__('Role') + ': ' + data[1] + '; ID: <b>' + data[0] + '</b>'
587
+ )
588
+ );
589
+
590
+ var actions = data[3].split(',');
591
+ var container = $('<div/>', {'class': 'aam-row-actions'});
592
+
593
+ if ($.trim(data[3])) {
594
+ $.each(actions, function (i, action) {
595
+ switch (action) {
596
+ case 'manage':
597
+ $(container).append($('<i/>', {
598
+ 'class': 'aam-row-action icon-cog ' + (isCurrent(data[0]) ? 'text-muted': 'text-info')
599
+ }).bind('click', function () {
600
+ if (!$(this).prop('disabled')) {
601
+ $(this).prop('disabled', true);
602
+ aam.setSubject('user', data[0], data[2], data[4]);
603
+ $('td:eq(0) span', row).replaceWith(
604
+ '<strong class="aam-highlight">' + data[2] + '</strong>'
605
+ );
606
+ $('i.icon-cog', container).attr('class', 'aam-row-action icon-cog text-muted');
607
+
608
+ if (!aam.isUI()) {
609
+ $('i.icon-cog', container).attr('class', 'aam-row-action icon-spin4 animate-spin');
610
+ aam.fetchContent();
611
+ $('i.icon-spin4', container).attr('class', 'aam-row-action icon-cog text-muted');
612
+ } else {
613
+ $.aam.loadAccessForm($('#load-post-object-type').val(), $('#load-post-object').val(), $(this));
614
+ }
615
+ }
616
+ }).attr({
617
+ 'data-toggle': "tooltip",
618
+ 'title': aam.__('Manage User')
619
+ })).prop('disabled', (isCurrent(data[0]) ? true: false));
620
+ break;
621
+
622
+ case 'edit':
623
+ if (!aam.isUI()) {
624
+ $(container).append($('<i/>', {
625
+ 'class': 'aam-row-action icon-pencil text-info'
626
+ }).bind('click', function () {
627
+ window.open(
628
+ aamLocal.url.editUser + '?user_id=' + data[0], '_blank'
629
+ );
630
+ }).attr({
631
+ 'data-toggle': "tooltip",
632
+ 'title': aam.__('Edit User')
633
+ }));
634
+ }
635
+ break;
636
+
637
+ case 'lock':
638
+ if (!aam.isUI()) {
639
+ $(container).append($('<i/>', {
640
+ 'class': 'aam-row-action icon-lock-open-alt text-warning'
641
+ }).bind('click', function () {
642
+ blockUser(data[0], $(this));
643
+ }).attr({
644
+ 'data-toggle': "tooltip",
645
+ 'title': aam.__('Lock User')
646
+ }));
647
+ }
648
+ break;
649
+
650
+ case 'unlock':
651
+ if (!aam.isUI()) {
652
+ $(container).append($('<i/>', {
653
+ 'class': 'aam-row-action icon-lock text-danger'
654
+ }).bind('click', function () {
655
+ blockUser(data[0], $(this));
656
+ }).attr({
657
+ 'data-toggle': "tooltip",
658
+ 'title': aam.__('Unlock User')
659
+ }));
660
+ }
661
+ break;
662
+
663
+ case 'switch':
664
+ if (!aam.isUI()) {
665
+ $(container).append($('<i/>', {
666
+ 'class': 'aam-row-action icon-exchange text-success'
667
+ }).bind('click', function () {
668
+ switchToUser(data[0], $(this));
669
+ }).attr({
670
+ 'data-toggle': "tooltip",
671
+ 'title': aam.__('Switch To User')
672
+ }));
673
+ }
674
+ break;
675
+
676
+ default:
677
+ break;
678
+ }
679
+ });
680
+ } else {
681
+ $(container).append($('<i/>', {
682
+ 'class': 'aam-row-action text-muted'
683
+ }).text('---'));
684
+ }
685
+ $('td:eq(1)', row).html(container);
686
+ }
687
+ });
688
+
689
+ //add setSubject hook
690
+ aam.addHook('setSubject', function () {
691
+ //clear highlight
692
+ $('tbody tr', '#user-list').each(function () {
693
+ if ($('strong', $(this)).length) {
694
+ var highlight = $('strong', $(this));
695
+ $('.icon-cog', $(this)).toggleClass('text-muted text-info');
696
+ $('.icon-cog', $(this)).prop('disabled', false);
697
+ highlight.replaceWith('<span>' + highlight.text() + '</span>');
698
+ }
699
+ });
700
+ //show post & pages access control groups that belong to backend
701
+ $('.aam-backend-post-access').show();
702
+ });
703
+
704
+ //in case interface needed to be reloaded
705
+ aam.addHook('refresh', function () {
706
+ $('#user-list').DataTable().ajax.url(aamLocal.ajaxurl).load();
707
+ });
708
+
709
+ })(jQuery);
710
+
711
+
712
+ /**
713
+ * Visitor Interface
714
+ *
715
+ * @param {jQuery} $
716
+ *
717
+ * @returns {void}
718
+ */
719
+ (function ($) {
720
+
721
+ $('document').ready(function() {
722
+ $('#manage-visitor').bind('click', function () {
723
+ var _this = this;
724
+
725
+ aam.setSubject('visitor', null, aam.__('Anonymous'), 0);
726
+ $('i.icon-cog', $(this)).attr('class', 'icon-spin4 animate-spin');
727
+
728
+ if (!aam.isUI()) {
729
+ aam.fetchContent();
730
+ $('i.icon-spin4', $(this)).attr('class', 'icon-cog');
731
+ } else {
732
+ $.aam.loadAccessForm($('#load-post-object-type').val(), $('#load-post-object').val(), null, function () {
733
+ $('i.icon-spin4', $(_this)).attr('class', 'icon-cog');
734
+ });
735
+ }
736
+ //hide post & pages access control groups that belong to backend
737
+ $('.aam-backend-post-access').hide();
738
+ });
739
+ });
740
+
741
+ })(jQuery);
742
+
743
+ /**
744
+ * Default Interface
745
+ *
746
+ * @param {jQuery} $
747
+ *
748
+ * @returns {void}
749
+ */
750
+ (function ($) {
751
+
752
+ $('document').ready(function() {
753
+ $('#manage-default').bind('click', function () {
754
+ var _this = this;
755
+
756
+ aam.setSubject('default', null, aam.__('All Users, Roles and Visitor'), 0);
757
+ $('i.icon-cog', $(this)).attr('class', 'icon-spin4 animate-spin');
758
+ if (!aam.isUI()) {
759
+ aam.fetchContent();
760
+ $('i.icon-spin4', $(this)).attr('class', 'icon-cog');
761
+ } else {
762
+ $.aam.loadAccessForm($('#load-post-object-type').val(), $('#load-post-object').val(), null, function () {
763
+ $('i.icon-spin4', $(_this)).attr('class', 'icon-cog');
764
+ });
765
+ }
766
+ });
767
+ });
768
+
769
+ })(jQuery);
770
+
771
+
772
+ /**
773
+ * Admin Menu Interface
774
+ *
775
+ * @param {jQuery} $
776
+ *
777
+ * @returns {void}
778
+ */
779
+ (function ($) {
780
+
781
+ /**
782
+ *
783
+ * @param {type} param
784
+ * @param {type} value
785
+ * @returns {undefined}
786
+ */
787
+ function save(items, status, successCallback) {
788
+ $.ajax(aamLocal.ajaxurl, {
789
+ type: 'POST',
790
+ dataType: 'json',
791
+ data: {
792
+ action: 'aam',
793
+ sub_action: 'Menu.save',
794
+ subject: aam.getSubject().type,
795
+ subjectId: aam.getSubject().id,
796
+ _ajax_nonce: aamLocal.nonce,
797
+ items: items,
798
+ status: status
799
+ },
800
+ success: function(response) {
801
+ successCallback(response);
802
+ },
803
+ error: function () {
804
+ aam.notification('danger', aam.__('Application Error'));
805
+ }
806
+ });
807
+ }
808
+
809
+ /**
810
+ *
811
+ * @returns {undefined}
812
+ */
813
+ function initialize() {
814
+ if ($('#admin_menu-content').length) {
815
+ $('.aam-restrict-menu').each(function () {
816
+ $(this).bind('click', function () {
817
+ var _this = $(this);
818
+ var status = ($('i', $(this)).hasClass('icon-eye-off') ? 1 : 0);
819
+ var target = _this.data('target');
820
+
821
+ $('i', _this).attr('class', 'icon-spin4 animate-spin');
822
+
823
+ var items = new Array(_this.data('menu-id'));
824
+
825
+ $('input', target).each(function () {
826
+ $(this).attr('checked', status ? true : false);
827
+ items.push($(this).data('menu-id'));
828
+ });
829
+
830
+ save(items, status, function(result) {
831
+ if (result.status === 'success') {
832
+ $('#aam-menu-overwrite').show();
833
+
834
+ if (status) { //locked the menu
835
+ $('.aam-bordered', target).append(
836
+ $('<div/>', {'class': 'aam-lock'})
837
+ );
838
+ _this.removeClass('btn-danger').addClass('btn-primary');
839
+ _this.html('<i class="icon-eye"></i>' + aam.__('Show Menu'));
840
+ //add menu restricted indicator
841
+ var ind = $('<i/>', {
842
+ 'class': 'aam-panel-title-icon icon-eye-off text-danger'
843
+ });
844
+ $('.panel-title', target + '-heading').append(ind);
845
+ } else {
846
+ $('.aam-lock', target).remove();
847
+ _this.removeClass('btn-primary').addClass('btn-danger');
848
+ _this.html(
849
+ '<i class="icon-eye-off"></i>' + aam.__('Restrict Menu')
850
+ );
851
+ $('.panel-title .icon-eye-off', target + '-heading').remove();
852
+ }
853
+ } else {
854
+ _this.attr('checked', !status);
855
+ }
856
+ });
857
+ });
858
+ });
859
+
860
+ $('input[type="checkbox"]', '#admin-menu').each(function () {
861
+ $(this).bind('click', function () {
862
+ aam.save(
863
+ $(this).data('menu-id'),
864
+ $(this).attr('checked') ? 1 : 0,
865
+ 'menu',
866
+ null,
867
+ function(result) {
868
+ if (result.status === 'success') {
869
+ $('#aam-menu-overwrite').show();
870
+ }
871
+ }
872
+ );
873
+ });
874
+ });
875
+
876
+ //reset button
877
+ $('#menu-reset').bind('click', function () {
878
+ aam.reset('menu');
879
+ });
880
+ }
881
+ }
882
+
883
+ aam.addHook('init', initialize);
884
+
885
+ })(jQuery);
886
+
887
+
888
+ /**
889
+ * Metaboxes & Widgets Interface
890
+ *
891
+ * @param {jQuery} $
892
+ *
893
+ * @returns {void}
894
+ */
895
+ (function ($) {
896
+
897
+ /**
898
+ *
899
+ * @returns {undefined}
900
+ */
901
+ function getContent() {
902
+ $.ajax(aamLocal.ajaxurl, {
903
+ type: 'POST',
904
+ dataType: 'html',
905
+ data: {
906
+ action: 'aam',
907
+ sub_action: 'Metabox.getContent',
908
+ _ajax_nonce: aamLocal.nonce,
909
+ subject: aam.getSubject().type,
910
+ subjectId: aam.getSubject().id
911
+ },
912
+ success: function (response) {
913
+ $('#metabox-content').replaceWith(response);
914
+ $('#metabox-content').addClass('active');
915
+ initialize();
916
+ },
917
+ error: function () {
918
+ aam.notification('danger', aam.__('Application error'));
919
+ }
920
+ });
921
+ }
922
+
923
+ /**
924
+ *
925
+ * @returns {undefined}
926
+ */
927
+ function initialize() {
928
+ if ($('#metabox-content').length) {
929
+ //init refresh list button
930
+ $('#refresh-metabox-list').bind('click', function () {
931
+ $.ajax(aamLocal.ajaxurl, {
932
+ type: 'POST',
933
+ dataType: 'json',
934
+ data: {
935
+ action: 'aam',
936
+ sub_action: 'Metabox.refreshList',
937
+ _ajax_nonce: aamLocal.nonce
938
+ },
939
+ beforeSend: function () {
940
+ $('i', '#refresh-metabox-list').attr(
941
+ 'class', 'icon-spin4 animate-spin'
942
+ );
943
+ },
944
+ success: function (response) {
945
+ if (response.status === 'success') {
946
+ getContent();
947
+ } else {
948
+ aam.notification(
949
+ 'danger', aam.__('Failed to retrieve mataboxes')
950
+ );
951
+ }
952
+ },
953
+ error: function () {
954
+ aam.notification('danger', aam.__('Application error'));
955
+ },
956
+ complete: function () {
957
+ $('i', '#refresh-metabox-list').attr(
958
+ 'class', 'icon-arrows-cw'
959
+ );
960
+ }
961
+ });
962
+ });
963
+
964
+ $('#init-url-btn').bind('click', function () {
965
+ $.ajax(aamLocal.ajaxurl, {
966
+ type: 'POST',
967
+ dataType: 'json',
968
+ data: {
969
+ action: 'aam',
970
+ sub_action: 'Metabox.initURL',
971
+ _ajax_nonce: aamLocal.nonce,
972
+ url: $('#init-url').val()
973
+ },
974
+ beforeSend: function () {
975
+ $('#init-url-btn').text(aam.__('Processing'));
976
+ },
977
+ success: function (response) {
978
+ if (response.status === 'success') {
979
+ $('#init-url-modal').modal('hide');
980
+ getContent();
981
+ } else {
982
+ aam.notification(
983
+ 'danger', aam.__('Failed to initialize URL')
984
+ );
985
+ }
986
+ },
987
+ error: function () {
988
+ aam.notification('danger', aam.__('Application error'));
989
+ },
990
+ complete: function () {
991
+ $('#init-url-btn').text(aam.__('Initialize'));
992
+ $('#init-url-modal').modal('hide');
993
+ }
994
+ });
995
+ });
996
+
997
+ //reset button
998
+ $('#metabox-reset').bind('click', function () {
999
+ aam.reset('metabox');
1000
+ });
1001
+
1002
+ $('input[type="checkbox"]', '#metabox-list').each(function () {
1003
+ $(this).bind('click', function () {
1004
+ aam.save(
1005
+ $(this).data('metabox'),
1006
+ $(this).attr('checked') ? 1 : 0,
1007
+ 'metabox',
1008
+ null,
1009
+ function(result) {
1010
+ if (result.status === 'success') {
1011
+ $('#aam-metabox-overwrite').show();
1012
+ }
1013
+ }
1014
+ );
1015
+ });
1016
+ });
1017
+ }
1018
+ }
1019
+
1020
+ aam.addHook('init', initialize);
1021
+
1022
+ })(jQuery);
1023
+
1024
+
1025
+ /**
1026
+ * Capabilities Interface
1027
+ *
1028
+ * @param {jQuery} $
1029
+ *
1030
+ * @returns {void}
1031
+ */
1032
+ (function ($) {
1033
+
1034
+ /**
1035
+ *
1036
+ * @param {type} capability
1037
+ * @param {type} btn
1038
+ * @returns {undefined}
1039
+ */
1040
+ function save(capability, btn) {
1041
+ var granted = $(btn).hasClass('icon-check-empty') ? 1 : 0;
1042
+
1043
+ //show indicator
1044
+ $(btn).attr('class', 'aam-row-action icon-spin4 animate-spin');
1045
+
1046
+ aam.save(capability, granted, 'capability', null, function(result) {
1047
+ if (result.status === 'success') {
1048
+ if (granted) {
1049
+ $(btn).attr('class', 'aam-row-action text-success icon-check');
1050
+ } else {
1051
+ $(btn).attr('class', 'aam-row-action text-muted icon-check-empty');
1052
+ }
1053
+ } else {
1054
+ if (granted) {
1055
+ aam.notification(
1056
+ 'danger', aam.__('WordPress core does not allow to grant this capability')
1057
+ );
1058
+ $(btn).attr('class', 'aam-row-action text-muted icon-check-empty');
1059
+ } else {
1060
+ $(btn).attr('class', 'aam-row-action text-success icon-check');
1061
+ }
1062
+ }
1063
+ });
1064
+ }
1065
+ /**
1066
+ *
1067
+ * @returns {undefined}
1068
+ */
1069
+ function initialize() {
1070
+ if ($('#capability-content').length) {
1071
+ //initialize the role list table
1072
+ $('#capability-list').DataTable({
1073
+ autoWidth: false,
1074
+ ordering: false,
1075
+ pagingType: 'simple',
1076
+ serverSide: false,
1077
+ ajax: {
1078
+ url: aamLocal.ajaxurl,
1079
+ type: 'POST',
1080
+ data: {
1081
+ action: 'aam',
1082
+ sub_action: 'Capability.getTable',
1083
+ _ajax_nonce: aamLocal.nonce,
1084
+ subject: aam.getSubject().type,
1085
+ subjectId: aam.getSubject().id
1086
+ }
1087
+ },
1088
+ columnDefs: [
1089
+ {visible: false, targets: [0]}
1090
+ ],
1091
+ language: {
1092
+ search: '_INPUT_',
1093
+ searchPlaceholder: aam.__('Search Capability'),
1094
+ info: aam.__('_TOTAL_ capability(s)'),
1095
+ infoFiltered: '',
1096
+ infoEmpty: aam.__('Nothing to show'),
1097
+ lengthMenu: '_MENU_'
1098
+ },
1099
+ createdRow: function (row, data) {
1100
+ var actions = data[3].split(',');
1101
+
1102
+ var container = $('<div/>', {'class': 'aam-row-actions'});
1103
+ $.each(actions, function (i, action) {
1104
+ switch (action) {
1105
+ case 'unchecked':
1106
+ $(container).append($('<i/>', {
1107
+ 'class': 'aam-row-action text-muted icon-check-empty'
1108
+ }).bind('click', function () {
1109
+ save(data[0], this);
1110
+ }));
1111
+ break;
1112
+
1113
+ case 'checked':
1114
+ $(container).append($('<i/>', {
1115
+ 'class': 'aam-row-action text-success icon-check'
1116
+ }).bind('click', function () {
1117
+ save(data[0], this);
1118
+ }));
1119
+ break;
1120
+
1121
+ case 'edit':
1122
+ $(container).append($('<i/>', {
1123
+ 'class': 'aam-row-action icon-pencil text-warning'
1124
+ }).bind('click', function () {
1125
+ $('#capability-id').val(data[0]);
1126
+ $('#update-capability-btn').attr('data-cap', data[0]);
1127
+ $('#edit-capability-modal').modal('show');
1128
+ }));
1129
+ break;
1130
+
1131
+ case 'delete':
1132
+ $(container).append($('<i/>', {
1133
+ 'class': 'aam-row-action icon-trash-empty text-danger'
1134
+ }).bind('click', function () {
1135
+ var message = $('.aam-confirm-message', '#delete-capability-modal');
1136
+ $(message).html(message.data('message').replace(
1137
+ '%s', '<b>' + data[0] + '</b>')
1138
+ );
1139
+ $('#capability-id').val(data[0]);
1140
+ $('#delete-capability-btn').attr('data-cap', data[0]);
1141
+ $('#delete-capability-modal').modal('show');
1142
+ }));
1143
+ break;
1144
+
1145
+ default:
1146
+ aam.triggerHook('decorate-capability-row', {
1147
+ action: action,
1148
+ container: container,
1149
+ data: data
1150
+ });
1151
+ break;
1152
+ }
1153
+ });
1154
+ $('td:eq(2)', row).html(container);
1155
+ }
1156
+ });
1157
+
1158
+ $('a', '#capability-groups').each(function () {
1159
+ $(this).bind('click', function () {
1160
+ var table = $('#capability-list').DataTable();
1161
+ if ($(this).data('clear') !== true) {
1162
+ table.column(1).search($(this).text()).draw();
1163
+ } else {
1164
+ table.column(1).search('').draw();
1165
+ }
1166
+ });
1167
+ });
1168
+
1169
+ $('#add-capability-modal').on('shown.bs.modal', function (e) {
1170
+ $('#new-capability-name').val('');
1171
+ });
1172
+
1173
+ $('#add-capability').bind('click', function () {
1174
+ $('#add-capability-modal').modal('show');
1175
+ });
1176
+
1177
+ $('#add-capability-btn').bind('click', function () {
1178
+ var _this = this;
1179
+
1180
+ var capability = $.trim($('#new-capability-name').val());
1181
+ $('#new-capability-name').parent().removeClass('has-error');
1182
+
1183
+ if (capability) {
1184
+ $.ajax(aamLocal.ajaxurl, {
1185
+ type: 'POST',
1186
+ dataType: 'json',
1187
+ data: {
1188
+ action: 'aam',
1189
+ sub_action: 'Capability.add',
1190
+ _ajax_nonce: aamLocal.nonce,
1191
+ capability: capability,
1192
+ subject: aam.getSubject().type,
1193
+ subjectId: aam.getSubject().id
1194
+ },
1195
+ beforeSend: function () {
1196
+ $(_this).text(aam.__('Saving...')).attr('disabled', true);
1197
+ },
1198
+ success: function (response) {
1199
+ if (response.status === 'success') {
1200
+ $('#add-capability-modal').modal('hide');
1201
+ $('#capability-list').DataTable().ajax.reload();
1202
+ } else {
1203
+ aam.notification(
1204
+ 'danger', aam.__('Failed to add new capability')
1205
+ );
1206
+ }
1207
+ },
1208
+ error: function () {
1209
+ aam.notification('danger', aam.__('Application error'));
1210
+ },
1211
+ complete: function () {
1212
+ $(_this).text(aam.__('Add Capability')).attr('disabled', false);
1213
+ }
1214
+ });
1215
+ } else {
1216
+ $('#new-capability-name').parent().addClass('has-error');
1217
+ }
1218
+ });
1219
+
1220
+ $('#add-capability-modal').on('shown.bs.modal', function (e) {
1221
+ $('#new-capability-name').focus();
1222
+ });
1223
+
1224
+ $('#update-capability-btn').bind('click', function () {
1225
+ var btn = this;
1226
+ var cap = $.trim($('#capability-id').val());
1227
+
1228
+ if (cap) {
1229
+ $.ajax(aamLocal.ajaxurl, {
1230
+ type: 'POST',
1231
+ dataType: 'json',
1232
+ data: {
1233
+ action: 'aam',
1234
+ sub_action: 'Capability.update',
1235
+ _ajax_nonce: aamLocal.nonce,
1236
+ capability: $(this).attr('data-cap'),
1237
+ updated: cap
1238
+ },
1239
+ beforeSend: function () {
1240
+ $(btn).text(aam.__('Saving...')).attr('disabled', true);
1241
+ },
1242
+ success: function (response) {
1243
+ if (response.status === 'success') {
1244
+ $('#edit-capability-modal').modal('hide');
1245
+ $('#capability-list').DataTable().ajax.reload();
1246
+ } else {
1247
+ aam.notification(
1248
+ 'danger', aam.__('Failed to update capability')
1249
+ );
1250
+ }
1251
+ },
1252
+ error: function () {
1253
+ aam.notification('danger', aam.__('Application error'));
1254
+ },
1255
+ complete: function () {
1256
+ $(btn).text(aam.__('Update Capability')).attr(
1257
+ 'disabled', false
1258
+ );
1259
+ }
1260
+ });
1261
+ }
1262
+ });
1263
+
1264
+ $('#delete-capability-btn').bind('click', function () {
1265
+ var btn = this;
1266
+
1267
+ $.ajax(aamLocal.ajaxurl, {
1268
+ type: 'POST',
1269
+ dataType: 'json',
1270
+ data: {
1271
+ action: 'aam',
1272
+ sub_action: 'Capability.delete',
1273
+ _ajax_nonce: aamLocal.nonce,
1274
+ subject: aam.getSubject().type,
1275
+ subjectId: aam.getSubject().id,
1276
+ capability: $(this).attr('data-cap')
1277
+ },
1278
+ beforeSend: function () {
1279
+ $(btn).text(aam.__('Deleting...')).attr('disabled', true);
1280
+ },
1281
+ success: function (response) {
1282
+ if (response.status === 'success') {
1283
+ $('#delete-capability-modal').modal('hide');
1284
+ $('#capability-list').DataTable().ajax.reload();
1285
+ } else {
1286
+ aam.notification(
1287
+ 'danger', aam.__('Failed to delete capability')
1288
+ );
1289
+ }
1290
+ },
1291
+ error: function () {
1292
+ aam.notification('danger', aam.__('Application error'));
1293
+ },
1294
+ complete: function () {
1295
+ $(btn).text(aam.__('Delete Capability')).attr(
1296
+ 'disabled', false
1297
+ );
1298
+ }
1299
+ });
1300
+ });
1301
+
1302
+ //reset button
1303
+ $('#capability-reset').bind('click', function () {
1304
+ aam.reset('capability');
1305
+ });
1306
+ }
1307
+ }
1308
+
1309
+ aam.addHook('init', initialize);
1310
+
1311
+ })(jQuery);
1312
+
1313
+
1314
+ /**
1315
+ * Posts & Pages Interface
1316
+ *
1317
+ * @param {jQuery} $
1318
+ *
1319
+ * @returns {void}
1320
+ */
1321
+ (function ($) {
1322
+
1323
+ /**
1324
+ * Table extra filter
1325
+ *
1326
+ * @type Object
1327
+ */
1328
+ var filter = {
1329
+ type: null
1330
+ };
1331
+
1332
+ /**
1333
+ *
1334
+ * @param {*} param
1335
+ * @param {*} value
1336
+ * @param {*} object
1337
+ * @param {*} object_id
1338
+ * @param {*} successCallback
1339
+ */
1340
+ function save(param, value, object, object_id, successCallback) {
1341
+ $.ajax(aamLocal.ajaxurl, {
1342
+ type: 'POST',
1343
+ dataType: 'json',
1344
+ data: {
1345
+ action: 'aam',
1346
+ sub_action: 'Post.save',
1347
+ _ajax_nonce: aamLocal.nonce,
1348
+ subject: aam.getSubject().type,
1349
+ subjectId: aam.getSubject().id,
1350
+ param: param,
1351
+ value: value,
1352
+ object: object,
1353
+ objectId: object_id
1354
+ },
1355
+ success: function (response) {
1356
+ if (response.status === 'failure') {
1357
+ aam.notification('danger', response.error);
1358
+ } else {
1359
+ $('#post-overwritten').removeClass('hidden');
1360
+ //add some specific attributes to reset button
1361
+ $('#post-reset').attr({
1362
+ 'data-type': object,
1363
+ 'data-id': object_id
1364
+ });
1365
+ }
1366
+ successCallback(response);
1367
+ },
1368
+ error: function () {
1369
+ aam.notification('danger', aam.__('Application error'));
1370
+ }
1371
+ });
1372
+ }
1373
+
1374
+ /**
1375
+ *
1376
+ * @param {type} type
1377
+ * @param {type} id
1378
+ * @param {type} title
1379
+ * @returns {undefined}
1380
+ */
1381
+ function addBreadcrumbLevel(type, id, title) {
1382
+ var level = $((type === 'type' ? '<a/>' : '<span/>')).attr({
1383
+ 'href': '#',
1384
+ 'data-level': type,
1385
+ 'data-id': id
1386
+ }).html('<i class="icon-angle-double-right"></i>' + title);
1387
+ $('.aam-post-breadcrumb').append(level);
1388
+ }
1389
+
1390
+ /**
1391
+ *
1392
+ * @param {type} object
1393
+ * @param {type} id
1394
+ * @param {type} btn
1395
+ * @param {type} callback
1396
+ * @returns {undefined}
1397
+ */
1398
+ $.aam.loadAccessForm = function(object, id, btn, callback) {
1399
+ //reset the form first
1400
+ var container = $('.aam-access-form[data-type="' + object + '"]');
1401
+ $('#post-overwritten').addClass('hidden');
1402
+
1403
+ //show overlay if present
1404
+ $('.aam-overlay', container).show();
1405
+
1406
+ //reset data preview elements
1407
+ $('[data-preview]', container).text('');
1408
+
1409
+ $('.aam-row-action', container).each(function () {
1410
+ $(this).attr({
1411
+ 'class': 'aam-row-action text-muted icon-check-empty',
1412
+ 'data-type': object,
1413
+ 'data-id': id
1414
+ });
1415
+
1416
+ //initialize each access property
1417
+ $(this).unbind('click').bind('click', function () {
1418
+ var _this = $(this);
1419
+ var checked = !_this.hasClass('icon-check');
1420
+
1421
+ _this.attr('class', 'aam-row-action icon-spin4 animate-spin');
1422
+ save(
1423
+ _this.data('property'),
1424
+ (checked ? 1 : 0),
1425
+ object,
1426
+ id,
1427
+ function(response) {
1428
+ if (response.status === 'success') {
1429
+ if (checked) {
1430
+ _this.attr(
1431
+ 'class', 'aam-row-action text-danger icon-check'
1432
+ );
1433
+ } else {
1434
+ _this.attr(
1435
+ 'class', 'aam-row-action text-muted icon-check-empty'
1436
+ );
1437
+ }
1438
+ }
1439
+ }
1440
+ );
1441
+ });
1442
+
1443
+ });
1444
+
1445
+ $.ajax(aamLocal.ajaxurl, {
1446
+ type: 'POST',
1447
+ dataType: 'json',
1448
+ data: {
1449
+ action: 'aam',
1450
+ sub_action: 'Post.getAccess',
1451
+ _ajax_nonce: aamLocal.nonce,
1452
+ type: object,
1453
+ id: id,
1454
+ subject: aam.getSubject().type,
1455
+ subjectId: aam.getSubject().id
1456
+ },
1457
+ beforeSend: function () {
1458
+ $(btn).attr('data-class', $(btn).attr('class'));
1459
+ $(btn).attr('class', 'aam-row-action icon-spin4 animate-spin');
1460
+ },
1461
+ success: function (response) {
1462
+ //iterate through each property
1463
+ for (var property in response.access) {
1464
+ var checked = (parseInt(response.access[property]) ? 'text-danger icon-check' : 'text-muted icon-check-empty');
1465
+ var checkbox = $('[data-property="' + property + '"]', container);
1466
+
1467
+ if (checkbox.length) {
1468
+ checkbox.attr({
1469
+ 'class': 'aam-row-action ' + checked
1470
+ });
1471
+ } else {
1472
+ $('[data-preview="' + property + '"]', container).prop('data-original-value', response.access[property]);
1473
+ $('[data-preview="' + property + '"]', container).html(
1474
+ preparePreview(response.access[property])
1475
+ );
1476
+ }
1477
+ }
1478
+
1479
+ //check metadata and show message if necessary
1480
+ if (response.meta.overwritten === true) {
1481
+ $('#post-overwritten').removeClass('hidden');
1482
+ //add some specific attributes to reset button
1483
+ $('#post-reset').attr({
1484
+ 'data-type': object,
1485
+ 'data-id': id
1486
+ });
1487
+ }
1488
+
1489
+ $('.extended-post-access-btn').attr({
1490
+ 'data-type': object,
1491
+ 'data-id': id
1492
+ });
1493
+
1494
+ $('#post-list_wrapper').addClass('aam-hidden');
1495
+ container.addClass('active');
1496
+
1497
+ if (typeof callback === 'function') {
1498
+ callback.call();
1499
+ }
1500
+
1501
+ //update dynamic labels
1502
+ if ($('#load-post-object-title').length) {
1503
+ var marker = $('#load-post-object-title').val();
1504
+ } else {
1505
+ marker = $('.aam-post-breadcrumb span').text();
1506
+ }
1507
+ $('[data-dynamic-post-label]').each(function() {
1508
+ $(this).html(
1509
+ $(this).attr('data-dynamic-post-label').replace(/%s/g, '<b>' + marker + '</b>')
1510
+ );
1511
+ });
1512
+ },
1513
+ error: function () {
1514
+ aam.notification('danger', aam.__('Application error'));
1515
+ },
1516
+ complete: function () {
1517
+ $(btn).attr('class', $(btn).attr('data-class')).removeAttr('data-class');
1518
+ //show overlay if present
1519
+ $('.aam-overlay', container).hide();
1520
+ }
1521
+ });
1522
+ };
1523
+
1524
+ /**
1525
+ *
1526
+ * @param {type} text
1527
+ * @returns {String}
1528
+ */
1529
+ function preparePreview(preview) {
1530
+ if (typeof preview === 'string') {
1531
+ preview = preview.replace(/<\/?[^>]+(>|$)/g, "");
1532
+
1533
+ if (preview.length > 25) {
1534
+ preview = preview.substring(0, 22) + '...';
1535
+ }
1536
+ }
1537
+
1538
+ return preview;
1539
+ }
1540
+
1541
+ /**
1542
+ *
1543
+ * @returns {undefined}
1544
+ */
1545
+ function initialize() {
1546
+ if ($('#post-content').length) {
1547
+ //reset filter to default list of post types
1548
+ filter.type = null;
1549
+
1550
+ //initialize the role list table
1551
+ $('#post-list').DataTable({
1552
+ autoWidth: false,
1553
+ ordering: false,
1554
+ pagingType: 'simple',
1555
+ processing: true,
1556
+ serverSide: true,
1557
+ ajax: {
1558
+ url: aamLocal.ajaxurl,
1559
+ type: 'POST',
1560
+ data: function (data) {
1561
+ data.action = 'aam';
1562
+ data.sub_action = 'Post.getTable';
1563
+ data._ajax_nonce = aamLocal.nonce;
1564
+ data.subject = aam.getSubject().type;
1565
+ data.subjectId = aam.getSubject().id;
1566
+ data.type = filter.type;
1567
+ }
1568
+ },
1569
+ columnDefs: [
1570
+ {visible: false, targets: [0, 1]}
1571
+ ],
1572
+ language: {
1573
+ search: '_INPUT_',
1574
+ searchPlaceholder: aam.__('Search'),
1575
+ info: aam.__('_TOTAL_ object(s)'),
1576
+ infoFiltered: '',
1577
+ lengthMenu: '_MENU_'
1578
+ },
1579
+ initComplete: function () {
1580
+ $('#post-list_filter .form-control').bind('change', function() {
1581
+ if ($(this).val()) {
1582
+ $(this).addClass('highlight');
1583
+ } else {
1584
+ $(this).removeClass('highlight');
1585
+ }
1586
+ });
1587
+ },
1588
+ rowCallback: function (row, data) {
1589
+ //object type icon
1590
+ switch (data[2]) {
1591
+ case 'type':
1592
+ $('td:eq(0)', row).html('<i class="icon-box"></i>');
1593
+ break;
1594
+
1595
+ case 'term':
1596
+ $('td:eq(0)', row).html('<i class="icon-folder"></i>');
1597
+ break;
1598
+
1599
+ default:
1600
+ $('td:eq(0)', row).html('<i class="icon-doc-text-inv"></i>');
1601
+ break;
1602
+ }
1603
+
1604
+ //update the title to a link
1605
+ if (data[2] === 'type') {
1606
+ var link = $('<a/>', {
1607
+ href: '#'
1608
+ }).bind('click', function () {
1609
+ //visual feedback - show loading icon
1610
+ $('td:eq(0)', row).html(
1611
+ '<i class="icon-spin4 animate-spin"></i>'
1612
+ );
1613
+ //set filter
1614
+ filter[data[2]] = data[0];
1615
+
1616
+ //finally reload the data
1617
+ $('#post-list').DataTable().ajax.reload();
1618
+
1619
+ //update the breadcrumb
1620
+ addBreadcrumbLevel('type', data[0], data[3]);
1621
+
1622
+ }).html(data[3]);
1623
+ $('td:eq(1)', row).html(link);
1624
+ } else { //reset the post/term title
1625
+ $('td:eq(1)', row).html(data[3]);
1626
+ }
1627
+
1628
+ //update the actions
1629
+ var actions = data[4].split(',');
1630
+
1631
+ var container = $('<div/>', {'class': 'aam-row-actions'});
1632
+ $.each(actions, function (i, action) {
1633
+ switch (action) {
1634
+ case 'drilldown':
1635
+ $(container).append($('<i/>', {
1636
+ 'class': 'aam-row-action text-success icon-level-down'
1637
+ }).bind('click', function () {
1638
+ if (!$(this).prop('disabled')) {
1639
+ $(this).prop('disabled', true);
1640
+ //set filter
1641
+ filter[data[2]] = data[0];
1642
+ //finally reload the data
1643
+ $('#post-list').DataTable().ajax.reload();
1644
+ //update the breadcrumb
1645
+ addBreadcrumbLevel('type', data[0], data[3]);
1646
+ }
1647
+ }).attr({
1648
+ 'data-toggle': "tooltip",
1649
+ 'title': aam.__('Drill-Down')
1650
+ }));
1651
+ $('.tooltip').remove();
1652
+ break;
1653
+
1654
+ case 'manage':
1655
+ $(container).append($('<i/>', {
1656
+ 'class': 'aam-row-action text-info icon-cog'
1657
+ }).bind('click', function () {
1658
+ $.aam.loadAccessForm(data[2], data[0], $(this), function () {
1659
+ addBreadcrumbLevel('edit', data[2], data[3]);
1660
+ });
1661
+ }).attr({
1662
+ 'data-toggle': "tooltip",
1663
+ 'title': aam.__('Manage Access')
1664
+ }));
1665
+ $('.tooltip').remove();
1666
+ break;
1667
+
1668
+ case 'edit' :
1669
+ $(container).append($('<i/>', {
1670
+ 'class': 'aam-row-action text-warning icon-pencil'
1671
+ }).bind('click', function () {
1672
+ window.open(data[1], '_blank');
1673
+ }).attr({
1674
+ 'data-toggle': "tooltip",
1675
+ 'title': aam.__('Edit')
1676
+ }));
1677
+ break;
1678
+
1679
+ default:
1680
+ aam.triggerHook('post-action', {
1681
+ container: container,
1682
+ action : action,
1683
+ data : data
1684
+ });
1685
+ break;
1686
+ }
1687
+ });
1688
+ $('td:eq(2)', row).html(container);
1689
+ }
1690
+ });
1691
+
1692
+ //initialize the breadcrumb
1693
+ $('.aam-post-breadcrumb').delegate('a', 'click', function () {
1694
+ filter.type = $(this).data('id');
1695
+ $('#post-list').DataTable().ajax.reload();
1696
+ $(this).nextAll().remove();
1697
+ $('.aam-slide-form').removeClass('active');
1698
+ $('#post-list_wrapper').removeClass('aam-hidden');
1699
+ $('#post-overwritten').addClass('hidden');
1700
+ });
1701
+
1702
+ //reset button
1703
+ $('#post-reset').bind('click', function () {
1704
+ var type = $(this).attr('data-type');
1705
+ var id = $(this).attr('data-id');
1706
+
1707
+ $.ajax(aamLocal.ajaxurl, {
1708
+ type: 'POST',
1709
+ dataType: 'json',
1710
+ data: {
1711
+ action: 'aam',
1712
+ sub_action: 'Post.reset',
1713
+ _ajax_nonce: aamLocal.nonce,
1714
+ type: type,
1715
+ id: id,
1716
+ subject: aam.getSubject().type,
1717
+ subjectId: aam.getSubject().id
1718
+ },
1719
+ success: function (response) {
1720
+ if (response.status === 'success') {
1721
+ $('#post-overwritten').addClass('hidden');
1722
+ $.aam.loadAccessForm(type, id);
1723
+ }
1724
+ }
1725
+ });
1726
+ });
1727
+
1728
+ //go back button
1729
+ $('.aam-slide-form').delegate('.post-back', 'click', function () {
1730
+ var type = $(this).parent().data('type');
1731
+
1732
+ $('.aam-slide-form[data-type="' + type + '"]').removeClass('active');
1733
+ $('#post-list_wrapper').removeClass('aam-hidden');
1734
+ $('.aam-post-breadcrumb span:last').remove();
1735
+ $('#post-overwritten').addClass('hidden');
1736
+ });
1737
+
1738
+ //load referenced post
1739
+ if ($('#load-post-object').val()) {
1740
+ $.aam.loadAccessForm(
1741
+ $('#load-post-object-type').val(),
1742
+ $('#load-post-object').val()
1743
+ );
1744
+ }
1745
+
1746
+ $('.change-password').each(function() {
1747
+ $(this).bind('click', function() {
1748
+ var password = $('#' + $(this).attr('data-preview-id')).text();
1749
+
1750
+ if (password !== '') {
1751
+ $('#password-value').val(password);
1752
+ } else {
1753
+ $('#password-value').val('');
1754
+ }
1755
+
1756
+ $('#change-password-btn').attr({
1757
+ 'data-ref': $(this).attr('data-ref'),
1758
+ 'data-preview-id': $(this).attr('data-preview-id')
1759
+ });
1760
+
1761
+ $('#password-modal').modal('show');
1762
+ });
1763
+ });
1764
+
1765
+ $('#change-password-btn').bind('click', function() {
1766
+ var _this = $(this);
1767
+ _this.text(aam.__('Saving...'));
1768
+
1769
+ var password = $('#password-value').val();
1770
+ save(
1771
+ _this.attr('data-ref'),
1772
+ password,
1773
+ _this.attr('data-type'),
1774
+ _this.attr('data-id'),
1775
+ function(response) {
1776
+ if (response.status === 'success') {
1777
+ var preview = $('#' + _this.attr('data-preview-id'));
1778
+ var action = $('.aam-row-action', preview.parent().parent().parent());
1779
+
1780
+ preview.html(password ? password : '');
1781
+
1782
+ if ($(action).hasClass('icon-check-empty')) {
1783
+ action.trigger('click');
1784
+ }
1785
+ }
1786
+ $('#password-modal').modal('hide');
1787
+
1788
+ _this.text(aam.__('Set'));
1789
+ }
1790
+ );
1791
+ });
1792
+
1793
+ $('.change-location').each(function() {
1794
+ $(this).bind('click', function() {
1795
+ var location = $('#' + $(this).attr('data-preview-id')).text();
1796
+
1797
+ if (location !== '') {
1798
+ $('#location-value').val(location);
1799
+ } else {
1800
+ $('#location-value').val('');
1801
+ }
1802
+
1803
+ $('#change-location-btn').attr({
1804
+ 'data-ref': $(this).attr('data-ref'),
1805
+ 'data-preview-id': $(this).attr('data-preview-id')
1806
+ });
1807
+
1808
+ $('#location-modal').modal('show');
1809
+ });
1810
+ });
1811
+
1812
+ $('#change-location-btn').bind('click', function() {
1813
+ var _this = $(this);
1814
+ _this.text(aam.__('Saving...'));
1815
+
1816
+ var redirect = $('#location-value').val();
1817
+ save(
1818
+ _this.attr('data-ref'),
1819
+ redirect,
1820
+ _this.attr('data-type'),
1821
+ _this.attr('data-id'),
1822
+ function(response) {
1823
+ if (response.status === 'success') {
1824
+ var preview = $('#' + _this.attr('data-preview-id'));
1825
+ var action = $('.aam-row-action', preview.parent().parent().parent());
1826
+
1827
+ preview.html(redirect ? redirect : '');
1828
+
1829
+ if ($(action).hasClass('icon-check-empty')) {
1830
+ action.trigger('click');
1831
+ }
1832
+ }
1833
+ $('#location-modal').modal('hide');
1834
+ _this.text(aam.__('Set'));
1835
+ }
1836
+ );
1837
+ });
1838
+
1839
+ $('.change-expiration').each(function() {
1840
+ $(this).bind('click', function() {
1841
+ var expiration = $('#' + $(this).attr('data-preview-id')).text();
1842
+
1843
+ if (expiration !== '') {
1844
+ $('#expiration-value').val(expiration);
1845
+ } else {
1846
+ $('#expiration-value').val('');
1847
+ }
1848
+
1849
+ $('#change-expiration-btn').attr({
1850
+ 'data-ref': $(this).attr('data-ref'),
1851
+ 'data-preview-id': $(this).attr('data-preview-id')
1852
+ });
1853
+
1854
+ $('#expiration-modal').modal('show');
1855
+ });
1856
+ });
1857
+
1858
+ $('#change-expiration-btn').bind('click', function() {
1859
+ var _this = $(this);
1860
+ _this.text(aam.__('Saving...'));
1861
+
1862
+ var expires = $('#expiration-value').val();
1863
+ save(
1864
+ _this.attr('data-ref'),
1865
+ expires,
1866
+ _this.attr('data-type'),
1867
+ _this.attr('data-id'),
1868
+ function(response) {
1869
+ if (response.status === 'success') {
1870
+ var preview = $('#' + _this.attr('data-preview-id'));
1871
+ var action = $('.aam-row-action', preview.parent().parent().parent());
1872
+ preview.html(response.value);
1873
+
1874
+ if ($(action).hasClass('icon-check-empty')) {
1875
+ action.trigger('click');
1876
+ }
1877
+ }
1878
+ $('#expiration-modal').modal('hide');
1879
+ _this.text(aam.__('Set'));
1880
+ }
1881
+ );
1882
+ });
1883
+
1884
+ $('.change-teaser').each(function() {
1885
+ $(this).bind('click', function() {
1886
+ var teaser = $('#' + $(this).attr('data-preview-id')).prop('data-original-value');
1887
+ $('#teaser-value').val(teaser);
1888
+
1889
+ $('#change-teaser-btn').attr({
1890
+ 'data-ref': $(this).attr('data-ref'),
1891
+ 'data-preview-id': $(this).attr('data-preview-id')
1892
+ });
1893
+
1894
+ $('#teaser-modal').modal('show');
1895
+ });
1896
+ });
1897
+
1898
+ $('#change-teaser-btn').bind('click', function() {
1899
+ var _this = $(this);
1900
+ _this.text(aam.__('Saving...'));
1901
+
1902
+ var teaser = $('#teaser-value').val();
1903
+ save(
1904
+ _this.attr('data-ref'),
1905
+ teaser,
1906
+ _this.attr('data-type'),
1907
+ _this.attr('data-id'),
1908
+ function(response) {
1909
+ if (response.status === 'success') {
1910
+ var preview = $('#' + _this.attr('data-preview-id'));
1911
+ var action = $('.aam-row-action', preview.parent().parent().parent());
1912
+
1913
+ preview.prop('data-original-value', teaser);
1914
+ preview.html(preparePreview(teaser));
1915
+
1916
+ if ($(action).hasClass('icon-check-empty')) {
1917
+ action.trigger('click');
1918
+ }
1919
+ }
1920
+ $('#teaser-modal').modal('hide');
1921
+ _this.text(aam.__('Save'));
1922
+ }
1923
+ );
1924
+ });
1925
+ }
1926
+ }
1927
+
1928
+ aam.addHook('init', initialize);
1929
+
1930
+ })(jQuery);
1931
+
1932
+ /**
1933
+ * Redirect Interface
1934
+ *
1935
+ * @param {jQuery} $
1936
+ *
1937
+ * @returns {void}
1938
+ */
1939
+ (function ($) {
1940
+
1941
+ /**
1942
+ *
1943
+ * @returns {undefined}
1944
+ */
1945
+ function initialize() {
1946
+ var container = '#redirect-content';
1947
+
1948
+ if ($(container).length) {
1949
+ $('input[type="radio"]', container).each(function () {
1950
+ $(this).bind('click', function () {
1951
+ //hide group
1952
+ $('.' + $(this).data('group')).hide();
1953
+
1954
+ //show the specific one
1955
+ $($(this).data('action')).show();
1956
+
1957
+ //save redirect type
1958
+ aam.save(
1959
+ $(this).attr('name'),
1960
+ $(this).val(),
1961
+ 'redirect',
1962
+ null,
1963
+ function(result) {
1964
+ if (result.status === 'success') {
1965
+ $('#aam-redirect-overwrite').show();
1966
+ }
1967
+ }
1968
+ );
1969
+ });
1970
+ });
1971
+
1972
+ $('input[type="text"],select,textarea', container).each(function () {
1973
+ $(this).bind('change', function () {
1974
+ //save redirect type
1975
+ aam.save(
1976
+ $(this).attr('name'),
1977
+ $(this).val(),
1978
+ 'redirect',
1979
+ null,
1980
+ function(result) {
1981
+ if (result.status === 'success') {
1982
+ $('#aam-redirect-overwrite').show();
1983
+ }
1984
+ }
1985
+ );
1986
+ });
1987
+ });
1988
+
1989
+ $('#redirect-reset').bind('click', function () {
1990
+ aam.reset('redirect');
1991
+ });
1992
+ }
1993
+ }
1994
+
1995
+ aam.addHook('init', initialize);
1996
+
1997
+ })(jQuery);
1998
+
1999
+ /**
2000
+ * Login Redirect Interface
2001
+ *
2002
+ * @param {jQuery} $
2003
+ *
2004
+ * @returns {void}
2005
+ */
2006
+ (function ($) {
2007
+
2008
+ /**
2009
+ *
2010
+ * @returns {undefined}
2011
+ */
2012
+ function initialize() {
2013
+ var container = '#login_redirect-content';
2014
+
2015
+ if ($(container).length) {
2016
+ $('input[type="radio"]', container).each(function () {
2017
+ $(this).bind('click', function () {
2018
+ //hide all fields
2019
+ $('.login-redirect-action').hide();
2020
+
2021
+ //show the specific one
2022
+ $($(this).data('action')).show();
2023
+
2024
+ //save redirect type
2025
+ aam.save(
2026
+ $(this).attr('name'),
2027
+ $(this).val(),
2028
+ 'loginRedirect',
2029
+ null,
2030
+ function(result) {
2031
+ if (result.status === 'success') {
2032
+ $('#aam-login-redirect-overwrite').show();
2033
+ }
2034
+ }
2035
+ );
2036
+ });
2037
+ });
2038
+
2039
+ $('input[type="text"],select,textarea', container).each(function () {
2040
+ $(this).bind('change', function () {
2041
+ if ($(this).is('input[type="checkbox"]')) {
2042
+ var val = $(this).prop('checked') ? $(this).val() : 0;
2043
+ } else {
2044
+ val = $.trim($(this).val());
2045
+ }
2046
+
2047
+ //save redirect type
2048
+ aam.save(
2049
+ $(this).attr('name'),
2050
+ val,
2051
+ 'loginRedirect',
2052
+ null,
2053
+ function(result) {
2054
+ if (result.status === 'success') {
2055
+ $('#aam-login-redirect-overwrite').show();
2056
+ }
2057
+ }
2058
+ );
2059
+ });
2060
+ });
2061
+
2062
+ $('#login-redirect-reset').bind('click', function () {
2063
+ aam.reset('loginRedirect');
2064
+ });
2065
+ }
2066
+ }
2067
+
2068
+ aam.addHook('init', initialize);
2069
+
2070
+ })(jQuery);
2071
+
2072
+ /**
2073
+ * Logout Redirect Interface
2074
+ *
2075
+ * @param {jQuery} $
2076
+ *
2077
+ * @returns {void}
2078
+ */
2079
+ (function ($) {
2080
+
2081
+ /**
2082
+ *
2083
+ * @returns {undefined}
2084
+ */
2085
+ function initialize() {
2086
+ var container = '#logout_redirect-content';
2087
+
2088
+ if ($(container).length) {
2089
+ $('input[type="radio"]', container).each(function () {
2090
+ $(this).bind('click', function () {
2091
+ //hide all fields
2092
+ $('.logout-redirect-action').hide();
2093
+
2094
+ //show the specific one
2095
+ $($(this).data('action')).show();
2096
+
2097
+ //save redirect type
2098
+ aam.save(
2099
+ $(this).attr('name'),
2100
+ $(this).val(),
2101
+ 'logoutRedirect',
2102
+ null,
2103
+ function(result) {
2104
+ if (result.status === 'success') {
2105
+ $('#aam-logout-redirect-overwrite').show();
2106
+ }
2107
+ }
2108
+ );
2109
+ });
2110
+ });
2111
+
2112
+ $('input[type="text"],select,textarea', container).each(function () {
2113
+ $(this).bind('change', function () {
2114
+ //save redirect type
2115
+ aam.save(
2116
+ $(this).attr('name'),
2117
+ $(this).val(),
2118
+ 'logoutRedirect',
2119
+ null,
2120
+ function(result) {
2121
+ if (result.status === 'success') {
2122
+ $('#aam-logout-redirect-overwrite').show();
2123
+ }
2124
+ }
2125
+ );
2126
+ });
2127
+ });
2128
+
2129
+ $('#logout-redirect-reset').bind('click', function () {
2130
+ aam.reset('logoutRedirect');
2131
+ });
2132
+ }
2133
+ }
2134
+
2135
+ aam.addHook('init', initialize);
2136
+
2137
+ })(jQuery);
2138
+
2139
+ /**
2140
+ * Teaser Interface
2141
+ *
2142
+ * @param {jQuery} $
2143
+ *
2144
+ * @returns {void}
2145
+ */
2146
+ (function ($) {
2147
+
2148
+ /**
2149
+ *
2150
+ * @returns {undefined}
2151
+ */
2152
+ function initialize() {
2153
+ var container = '#teaser-content';
2154
+
2155
+ if ($(container).length) {
2156
+ $('input, textarea', container).each(function () {
2157
+ $(this).bind('change', function () {
2158
+ if ($(this).is('input[type="checkbox"]')) {
2159
+ var val = $(this).prop('checked') ? $(this).val() : 0;
2160
+ } else {
2161
+ val = $.trim($(this).val());
2162
+ }
2163
+ //save redirect type
2164
+ aam.save(
2165
+ $(this).attr('name'),
2166
+ val,
2167
+ 'teaser',
2168
+ null,
2169
+ function(result) {
2170
+ if (result.status === 'success') {
2171
+ $('#aam-teaser-overwrite').show();
2172
+ }
2173
+ }
2174
+ );
2175
+ });
2176
+ });
2177
+
2178
+ $('#teaser-reset').bind('click', function () {
2179
+ aam.reset('teaser');
2180
+ });
2181
+ }
2182
+ }
2183
+
2184
+ aam.addHook('init', initialize);
2185
+
2186
+ })(jQuery);
2187
+
2188
+ /**
2189
+ * 404 Redirect Interface
2190
+ *
2191
+ * @param {jQuery} $
2192
+ *
2193
+ * @returns {void}
2194
+ */
2195
+ (function ($) {
2196
+
2197
+ /**
2198
+ *
2199
+ * @param {type} param
2200
+ * @param {type} value
2201
+ * @returns {undefined}
2202
+ */
2203
+ function save(param, value) {
2204
+ $.ajax(aamLocal.ajaxurl, {
2205
+ type: 'POST',
2206
+ dataType: 'json',
2207
+ data: {
2208
+ action: 'aam',
2209
+ sub_action: '404Redirect.save',
2210
+ _ajax_nonce: aamLocal.nonce,
2211
+ subject: aam.getSubject().type,
2212
+ subjectId: aam.getSubject().id,
2213
+ param: param,
2214
+ value: value
2215
+ },
2216
+ error: function () {
2217
+ aam.notification('danger', aam.__('Application error'));
2218
+ }
2219
+ });
2220
+ }
2221
+
2222
+ /**
2223
+ *
2224
+ * @returns {undefined}
2225
+ */
2226
+ function initialize() {
2227
+ var container = '#404redirect-content';
2228
+
2229
+ if ($(container).length) {
2230
+ $('input[type="radio"]', container).each(function () {
2231
+ $(this).bind('click', function () {
2232
+ //hide group
2233
+ $('.aam-404redirect-action').hide();
2234
+
2235
+ //show the specific one
2236
+ $($(this).data('action')).show();
2237
+
2238
+ //save redirect type
2239
+ save($(this).attr('name'), $(this).val());
2240
+ });
2241
+ });
2242
+
2243
+ $('input[type="text"],select,textarea', container).each(function () {
2244
+ $(this).bind('change', function () {
2245
+ //save redirect type
2246
+ save($(this).attr('name'), $(this).val());
2247
+ });
2248
+ });
2249
+ }
2250
+ }
2251
+
2252
+ aam.addHook('init', initialize);
2253
+
2254
+ })(jQuery);
2255
+
2256
+ /**
2257
+ * Extensions Interface
2258
+ *
2259
+ * @param {jQuery} $
2260
+ *
2261
+ * @returns {void}
2262
+ */
2263
+ (function ($) {
2264
+
2265
+ var dump = null;
2266
+
2267
+ /**
2268
+ *
2269
+ * @param {*} data
2270
+ * @param {*} completeCallback
2271
+ */
2272
+ function downloadExtension(data, completeCallback) {
2273
+ $.ajax(aamLocal.ajaxurl, {
2274
+ type: 'POST',
2275
+ dataType: 'json',
2276
+ data: data,
2277
+ success: function (response) {
2278
+ if (response.status === 'success') {
2279
+ setTimeout(function () {
2280
+ location.reload();
2281
+ }, 500);
2282
+ } else {
2283
+ aam.notification('danger', aam.__(response.error));
2284
+ if (typeof response.content !== 'undefined') {
2285
+ dump = response;
2286
+ $('#installation-error').html(response.error);
2287
+ $('#extension-notification-modal').modal('show');
2288
+ }
2289
+ }
2290
+ },
2291
+ error: function () {
2292
+ aam.notification('danger', aam.__('Application error'));
2293
+ },
2294
+ complete: function() {
2295
+ completeCallback();
2296
+ }
2297
+ });
2298
+ }
2299
+
2300
+ /**
2301
+ *
2302
+ * @returns {undefined}
2303
+ */
2304
+ function initialize() {
2305
+ if ($('#extension-content').length) {
2306
+ //check for updates
2307
+ $('#aam-update-check').bind('click', function() {
2308
+ $.ajax(aamLocal.ajaxurl, {
2309
+ type: 'POST',
2310
+ dataType: 'json',
2311
+ data: {
2312
+ action: 'aam',
2313
+ sub_action: 'Extension.check',
2314
+ _ajax_nonce: aamLocal.nonce,
2315
+ },
2316
+ beforeSend: function () {
2317
+ $('#aam-update-check i').attr('class', 'icon-spin4 animate-spin');
2318
+ },
2319
+ complete: function () {
2320
+ location.reload();
2321
+ }
2322
+ });
2323
+ });
2324
+
2325
+ //init refresh list button
2326
+ $('#install-extension').bind('click', function () {
2327
+ $('#extension-key').parent().removeClass('error');
2328
+
2329
+ var _this = $(this);
2330
+ var license = $.trim($('#extension-key').val());
2331
+
2332
+ if (!license) {
2333
+ $('#extension-key').parent().addClass('error');
2334
+ $('#extension-key').focus();
2335
+ return;
2336
+ }
2337
+
2338
+ $('i', _this).attr('class', 'icon-spin4 animate-spin');
2339
+ downloadExtension({
2340
+ action: 'aam',
2341
+ sub_action: 'Extension.install',
2342
+ _ajax_nonce: aamLocal.nonce,
2343
+ license: $('#extension-key').val()
2344
+ }, function() {
2345
+ $('i', _this).attr('class', 'icon-download-cloud');
2346
+ });
2347
+ });
2348
+
2349
+ //update extension
2350
+ $('.aam-update-extension').each(function () {
2351
+ $(this).bind('click', function () {
2352
+ var _this = $(this);
2353
+
2354
+ $('i', _this).attr('class', 'icon-spin4 animate-spin');
2355
+ downloadExtension({
2356
+ action: 'aam',
2357
+ sub_action: 'Extension.update',
2358
+ _ajax_nonce: aamLocal.nonce,
2359
+ extension: _this.data('product')
2360
+ }, function() {
2361
+ $('i', _this).attr('class', 'icon-arrows-cw');
2362
+ });
2363
+ });
2364
+ });
2365
+
2366
+ //download extension
2367
+ $('.aam-download-extension').each(function () {
2368
+ $(this).bind('click', function () {
2369
+ var _this = $(this);
2370
+
2371
+ $('i', _this).attr('class', 'icon-spin4 animate-spin');
2372
+ downloadExtension({
2373
+ action: 'aam',
2374
+ sub_action: 'Extension.install',
2375
+ _ajax_nonce: aamLocal.nonce,
2376
+ license: _this.data('license')
2377
+ }, function() {
2378
+ $('i', _this).attr('class', 'icon-download-cloud');
2379
+ });
2380
+ });
2381
+ });
2382
+
2383
+ //bind the download handler
2384
+ $('#download-extension').bind('click', function () {
2385
+ download(
2386
+ 'data:application/zip;base64,' + dump.content,
2387
+ dump.title + '.zip',
2388
+ 'application/zip'
2389
+ );
2390
+ $('#extension-notification-modal').modal('hide');
2391
+ });
2392
+
2393
+ if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) {
2394
+ $('#safari-download-notification').removeClass('hidden');
2395
+ }
2396
+ }
2397
+ }
2398
+
2399
+ aam.addHook('init', initialize);
2400
+
2401
+ })(jQuery);
2402
+
2403
+
2404
+ /**
2405
+ * Utilities Interface
2406
+ *
2407
+ * @param {type} $
2408
+ *
2409
+ * @returns {undefined}
2410
+ */
2411
+ (function ($) {
2412
+
2413
+ /**
2414
+ *
2415
+ * @param {type} param
2416
+ * @param {type} value
2417
+ * @returns {undefined}
2418
+ */
2419
+ function save(param, value) {
2420
+ $.ajax(aamLocal.ajaxurl, {
2421
+ type: 'POST',
2422
+ dataType: 'json',
2423
+ data: {
2424
+ action: 'aam',
2425
+ sub_action: 'Utility.save',
2426
+ _ajax_nonce: aamLocal.nonce,
2427
+ param: param,
2428
+ value: value
2429
+ },
2430
+ error: function () {
2431
+ aam.notification('danger', aam.__('Application Error'));
2432
+ }
2433
+ });
2434
+ }
2435
+
2436
+ /**
2437
+ *
2438
+ * @returns {undefined}
2439
+ */
2440
+ function initialize() {
2441
+ if ($('#utilities-content').length) {
2442
+ $('[data-toggle="toggle"]').bootstrapToggle();
2443
+
2444
+ $('input[type="checkbox"]', '#utilities-content').bind('change', function () {
2445
+ save($(this).attr('name'), ($(this).prop('checked') ? 1 : 0));
2446
+ });
2447
+
2448
+ $('input[type="text"]', '#utilities-content').bind('change', function() {
2449
+ save($(this).attr('name'), $(this).val());
2450
+ });
2451
+
2452
+ $('#clear-settings').bind('click', function () {
2453
+ $.ajax(aamLocal.ajaxurl, {
2454
+ type: 'POST',
2455
+ dataType: 'json',
2456
+ data: {
2457
+ action: 'aam',
2458
+ sub_action: 'Utility.clear',
2459
+ _ajax_nonce: aamLocal.nonce
2460
+ },
2461
+ beforeSend: function() {
2462
+ $('#clear-settings').prop('disabled', true);
2463
+ },
2464
+ success: function (response) {
2465
+ if (response.status === 'success') {
2466
+ location.reload();
2467
+ }
2468
+ },
2469
+ error: function () {
2470
+ aam.notification('danger', aam.__('Application Error'));
2471
+ },
2472
+ complete: function() {
2473
+ $('#clear-settings').prop('disabled', false);
2474
+ }
2475
+ });
2476
+ });
2477
+
2478
+ $('#clear-cache').bind('click', function () {
2479
+ $.ajax(aamLocal.ajaxurl, {
2480
+ type: 'POST',
2481
+ dataType: 'json',
2482
+ data: {
2483
+ action: 'aam',
2484
+ sub_action: 'Utility.clearCache',
2485
+ _ajax_nonce: aamLocal.nonce
2486
+ },
2487
+ beforeSend: function() {
2488
+ $('#clear-cache').prop('disabled', true);
2489
+ },
2490
+ success: function (response) {
2491
+ if (response.status === 'success') {
2492
+ location.reload();
2493
+ }
2494
+ },
2495
+ error: function () {
2496
+ aam.notification('danger', aam.__('Application Error'));
2497
+ },
2498
+ complete: function() {
2499
+ $('#clear-cache').prop('disabled', false);
2500
+ }
2501
+ });
2502
+ });
2503
+
2504
+ $('#export-aam').bind('click', function () {
2505
+ $.ajax(aamLocal.ajaxurl, {
2506
+ type: 'POST',
2507
+ dataType: 'json',
2508
+ data: {
2509
+ action: 'aam',
2510
+ sub_action: 'Utility.export',
2511
+ _ajax_nonce: aamLocal.nonce
2512
+ },
2513
+ beforeSend: function () {
2514
+ $('#export-aam').attr('data-lable', $('#export-aam').text());
2515
+ $('#export-aam').html('<i class="icon-spin4 animate-spin"></i>');
2516
+ },
2517
+ success: function(response) {
2518
+ if (response.status === 'success') {
2519
+ download(
2520
+ 'data:text/plain;base64,' + response.content,
2521
+ 'aam-export.json',
2522
+ 'text/plain'
2523
+ );
2524
+ }
2525
+ },
2526
+ error: function () {
2527
+ aam.notification('danger', aam.__('Application Error'));
2528
+ },
2529
+ complete: function () {
2530
+ $('#export-aam').html($('#export-aam').attr('data-lable'));
2531
+ }
2532
+ });
2533
+ });
2534
+
2535
+ $('#import-aam').bind('click', function () {
2536
+ if (typeof FileReader !== 'undefined') {
2537
+ $('#aam-import-file').trigger('click');
2538
+ } else {
2539
+ aam.notification('danger', 'Your browser does not support FileReader functionality');
2540
+ }
2541
+ });
2542
+
2543
+ $('#aam-import-file').bind('change', function () {
2544
+ var file = $(this)[0].files[0];
2545
+ var json = null;
2546
+
2547
+ var reader = new FileReader();
2548
+ reader.onload = function(e) {
2549
+ json = reader.result;
2550
+
2551
+ try {
2552
+ //validate the content
2553
+ var loaded = JSON.parse(json);
2554
+ if (loaded.plugin && loaded.plugin == 'advanced-access-manager') {
2555
+ $.ajax(aamLocal.ajaxurl, {
2556
+ type: 'POST',
2557
+ dataType: 'json',
2558
+ data: {
2559
+ action: 'aam',
2560
+ sub_action: 'Utility.import',
2561
+ _ajax_nonce: aamLocal.nonce,
2562
+ json: json
2563
+ },
2564
+ beforeSend: function () {
2565
+ $('#import-aam').attr('data-lable', $('#import-aam').text());
2566
+ $('#import-aam').html('<i class="icon-spin4 animate-spin"></i>');
2567
+ },
2568
+ success: function(response) {
2569
+ if (response.status === 'success') {
2570
+ aam.notification('success', 'Data Imported Successfully');
2571
+ // location.reload();
2572
+ } else {
2573
+ aam.notification('danger', aam.__('Invalid data format'));
2574
+ }
2575
+ },
2576
+ error: function () {
2577
+ aam.notification('danger', aam.__('Application Error'));
2578
+ },
2579
+ complete: function () {
2580
+ $('#import-aam').html($('#import-aam').attr('data-lable'));
2581
+ }
2582
+ });
2583
+ } else {
2584
+ throw 'Invalid format';
2585
+ }
2586
+ } catch (e) {
2587
+ aam.notification('danger', 'Invalid file format');
2588
+ }
2589
+ };
2590
+ reader.readAsText(file);
2591
+
2592
+ });
2593
+ }
2594
+ }
2595
+
2596
+ aam.addHook('init', initialize);
2597
+
2598
+ })(jQuery);
2599
+
2600
+
2601
+ aam.fetchContent(); //fetch default AAM content
2602
+ }
2603
 
2604
  /**
2605
  * Main AAM class
2607
  * @returns void
2608
  */
2609
  function AAM() {
 
2610
  /**
2611
  * Current Subject
2612
  */
2616
  * Different UI hooks
2617
  */
2618
  this.hooks = {};
 
2619
  }
2620
+
2621
+ /**
2622
+ *
2623
+ * @returns {undefined}
2624
+ */
2625
+ AAM.prototype.initializeMenu = function() {
2626
+ var _this = this;
2627
+
2628
+ //initialize the menu switch
2629
+ $('li', '#feature-list').each(function () {
2630
+ $(this).bind('click', function () {
2631
+ $('.aam-feature').removeClass('active');
2632
+ //highlight active feature
2633
+ $('li', '#feature-list').removeClass('active');
2634
+ $(this).addClass('active');
2635
+ //show feature content
2636
+ $('#' + $(this).data('feature') + '-content').addClass('active');
2637
+ location.hash = $(this).data('feature');
2638
+ //trigger hook
2639
+ _this.triggerHook('menu-feature-click', $(this).data('feature'));
2640
+ });
2641
+ });
2642
+ };
2643
+
2644
+ /**
2645
+ *
2646
+ * @returns {undefined}
2647
+ */
2648
+ AAM.prototype.fetchContent = function () {
2649
+ var _this = this;
2650
+
2651
+ //referred object ID like post, page or any custom post type
2652
+ var object = window.location.search.match(/&oid\=([^&]*)/);
2653
+ var type = window.location.search.match(/&otype\=([^&]*)/);
2654
+
2655
+ $.ajax(aamLocal.url.site, {
2656
+ type: 'POST',
2657
+ dataType: 'html',
2658
+ data: {
2659
+ action: 'aamc',
2660
+ _ajax_nonce: aamLocal.nonce,
2661
+ subject: this.getSubject().type,
2662
+ subjectId: this.getSubject().id,
2663
+ oid: object ? object[1] : null,
2664
+ otype: type ? type[1] : null
2665
+ },
2666
+ beforeSend: function () {
2667
+ if ($('#aam-initial-load').length === 0) {
2668
+ var loader = $('<div/>', {'class': 'aam-loading'}).html(
2669
+ '<i class="icon-spin4 animate-spin"></i>'
2670
+ );
2671
+ $('#aam-content').html(loader);
2672
+ }
2673
+ },
2674
+ success: function (response) {
2675
+ $('#aam-content').html(response);
2676
+ //init menu
2677
+ _this.initializeMenu();
2678
+ //trigger initialization hook
2679
+ _this.triggerHook('init');
2680
+ //activate one of the menu items
2681
+ var item = $('li:eq(0)', '#feature-list');
2682
+
2683
+ if (location.hash !== '') {
2684
+ var hash = location.hash.substr(1);
2685
+ if ($('li[data-feature="' + hash + '"]', '#feature-list').length) {
2686
+ item = $('li[data-feature="' + hash + '"]', '#feature-list');
2687
+ }
2688
+ }
2689
+
2690
+ item.trigger('click');
2691
+ }
2692
+ });
2693
+ };
2694
 
2695
  /**
2696
  * Add UI hook
2739
  );
2740
 
2741
  //load the UI javascript support
2742
+ UI();
2743
 
2744
  //initialize help context
2745
  $('.aam-help-menu').each(function() {
2785
  return (aamLocal.translation[label] ? aamLocal.translation[label] : label);
2786
  };
2787
 
2788
+ /**
2789
+ *
2790
+ * @param {type} type
2791
+ * @param {type} id
2792
+ * @param {type} name
2793
+ * @param {type} level
2794
+ * @returns {undefined}
2795
+ */
2796
  AAM.prototype.setSubject = function (type, id, name, level) {
2797
  this.subject = {
2798
  type: type,
2846
 
2847
  /**
2848
  *
2849
+ * @param {type} param
2850
+ * @param {type} value
2851
+ * @param {type} object
2852
+ * @param {type} object_id
2853
+ * @param {type} successCallback
2854
+ * @returns {undefined}
2855
  */
2856
  AAM.prototype.save = function(param, value, object, object_id, successCallback) {
2857
  $.ajax(aamLocal.ajaxurl, {
2881
 
2882
  /**
2883
  *
2884
+ * @param {type} object
2885
  * @returns {undefined}
2886
  */
2887
  AAM.prototype.reset = function(object) {
2920
  }));
2921
  };
2922
 
2923
+ /**
2924
+ *
2925
+ * @returns {Boolean}
2926
+ */
2927
  AAM.prototype.isUI = function() {
2928
  return (typeof aamLocal.ui !== 'undefined');
2929
  };
2933
  */
2934
  $(document).ready(function () {
2935
  aam = new AAM();
 
2936
  $.aam = aam;
2937
+ aam.initialize();
2938
  });
2939
 
2940
  })(jQuery);
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: vasyltech
3
  Tags: access, role, user, capability, page access, post access, comments, security, login redirect, brute force attack, double authentication, membership, backend lockdown, wp-admin, 404, activity tracking
4
  Requires at least: 3.8
5
  Tested up to: 4.8.1
6
- Stable tag: 4.9.4
7
 
8
  Manage access to your website for any user, role or visitors for both frontend and backend.
9
 
@@ -102,6 +102,14 @@ Check our [help page](https://aamplugin.com/help) to find out more about AAM.
102
 
103
  == Changelog ==
104
 
 
 
 
 
 
 
 
 
105
  = 4.9.4 =
106
  * Significantly improved Admin Menu access management
107
  * Filter AAM UI based on Backend/Frontend Access Control options
3
  Tags: access, role, user, capability, page access, post access, comments, security, login redirect, brute force attack, double authentication, membership, backend lockdown, wp-admin, 404, activity tracking
4
  Requires at least: 3.8
5
  Tested up to: 4.8.1
6
+ Stable tag: 4.9.5
7
 
8
  Manage access to your website for any user, role or visitors for both frontend and backend.
9
 
102
 
103
  == Changelog ==
104
 
105
+ = 4.9.5 =
106
+ * Improved user experience with AAM UI
107
+ * Removed Welcome message
108
+ * Fixed bug with media access
109
+ * Added filter for AAM shordcodes so other plugins can hook to AAM
110
+ * Optimized AAM javascript
111
+ * Removed subscription box to reduce "UI noise" as more features are coming
112
+
113
  = 4.9.4 =
114
  * Significantly improved Admin Menu access management
115
  * Filter AAM UI based on Backend/Frontend Access Control options