PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.0
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.0
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / features / roles-editor / assets / js / roles-editor.js

roles-editor.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.0, at features/roles-editor/assets/js/roles-editor.js

515 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var wppb_re_capabilities_group = [];
2 var wppb_re_new_capabilities = {};
3 var wppb_re_current_role_capabilities = jQuery.extend( {}, wppb_roles_editor_data.current_role_capabilities );
4 var wppb_re_unsaved_capabilities = {};
5 var wppb_re_capabilities_to_delete = {};
6
7 jQuery( document ).ready( function() {
8 // Disable Enter key
9 jQuery( window ).on( 'keydown', function( e ) {
10
11 if( typeof e.target.id !== "undefined" && e.target.id === 'post-search-input' )
12 return true;
13
14 if( e.keyCode == 13 ) {
15 event.preventDefault();
16 return false;
17 }
18 } );
19
20 // Disable the role title field when editing a role
21 if( wppb_roles_editor_data.current_screen_action != 'add' ) {
22 jQuery( '.post-type-wppb-roles-editor input#title' ).attr( 'disabled', 'disabled' );
23 }
24
25 var table_roles = jQuery( '.post-type-wppb-roles-editor .wp-list-table.posts tr .row-actions' );
26 if( jQuery( table_roles ).find( '.default_role' ) ) {
27 jQuery( '<span class="table-role-info"> — ' + wppb_roles_editor_data.default_role_text + '</span>' ).insertAfter( jQuery( table_roles ).find( '.default_role' ).parent().parent().find( 'strong .row-title' ) );
28 }
29 if( jQuery( table_roles ).find( '.delete_notify.your_role' ) ) {
30 jQuery( '<span class="table-role-info"> — ' + wppb_roles_editor_data.your_role_text + '</span>' ).insertAfter( jQuery( table_roles ).find( '.delete_notify.your_role' ).parent().parent().find( 'strong .row-title' ) );
31 }
32
33 // Dynamically change value of the Role Slug field
34 jQuery( '.post-type-wppb-roles-editor #titlewrap' ).find( '#title' ).on('change', function() {
35 if( ! jQuery( '.post-type-wppb-roles-editor #wppb-role-slug' ).val() ) {
36 jQuery( '.post-type-wppb-roles-editor #wppb-role-slug' ).val( jQuery( this ).val().toLowerCase() );
37 }
38 } );
39
40 // Create an object with grouped capabilities for the Add Capability select2
41 var counter = 1;
42 jQuery.each( wppb_roles_editor_data.capabilities, function( key, value ) {
43 var capabilities_single_group = {};
44 if( key != 'post_types' ) {
45 capabilities_single_group = wppb_re_create_capabilities_group( key, value, counter );
46 wppb_re_capabilities_group.push( capabilities_single_group );
47 counter++;
48 } else if( key == 'post_types' ) {
49 jQuery.each( value, function( key, value ) {
50 capabilities_single_group = wppb_re_create_capabilities_group( key, value, counter );
51 wppb_re_capabilities_group.push( capabilities_single_group );
52 counter++;
53 } );
54 }
55 } );
56
57 // Display the current role capabilities (on single role page)
58 wppb_re_display_capabilities( 'all' );
59
60 // Check for already added capabilities and disable them before select2 initialization
61 wppb_re_disable_select_capabilities( wppb_re_capabilities_group, wppb_roles_editor_data.current_role_capabilities, 'add' );
62
63 if( wppb_re_getParameterByName( 'wppb_re_clone' ) ) {
64 var data = {
65 'action' : 'get_role_capabilities',
66 'security' : jQuery( '.post-type-wppb-roles-editor #wppb-re-ajax-nonce' ).val(),
67 'role' : wppb_re_getParameterByName( 'wppb_re_clone' )
68 };
69
70 jQuery( '.post-type-wppb-roles-editor .wppb-role-edit-no-cap' ).remove();
71
72 jQuery.post( wppb_roles_editor_data.ajaxUrl, data, function( response ) {
73 if( response != 'no_caps' ) {
74 jQuery( '.post-type-wppb-roles-editor .wppb-re-spinner-container' ).hide();
75 wppb_re_current_role_capabilities = jQuery.extend( wppb_re_current_role_capabilities, JSON.parse( response ) );
76 wppb_re_display_capabilities( 'all' );
77 wppb_re_disable_select_capabilities( wppb_re_capabilities_group, wppb_re_current_role_capabilities, 'add' );
78 } else {
79 jQuery( '.wppb-re-spinner-container' ).hide();
80 wppb_re_no_capabilities_found();
81 }
82 } );
83 }
84
85 // Delete a capability
86 jQuery( '.post-type-wppb-roles-editor #wppb-role-edit-table' ).on( 'click', 'a.wppb-delete-capability-link', function() {
87 if( ( wppb_roles_editor_data.current_user_role && jQuery.inArray( jQuery( this ).closest( 'span.wppb-delete-capability' ).siblings( 'span.wppb-capability' ).text(), wppb_roles_editor_data.admin_capabilities ) === -1 ) || ! wppb_roles_editor_data.current_user_role ) {
88 jQuery( this ).closest( 'div.wppb-role-edit-table-entry' ).remove();
89
90 var deleted_capability = {};
91 deleted_capability[jQuery( this ).closest( 'span.wppb-delete-capability' ).siblings( 'span.wppb-capability' ).text()] = jQuery( this ).closest( 'span.wppb-delete-capability' ).siblings( 'span.wppb-capability' ).text();
92 wppb_re_capabilities_to_delete[jQuery( this ).closest( 'span.wppb-delete-capability' ).siblings( 'span.wppb-capability' ).text()] = jQuery( this ).closest( 'span.wppb-delete-capability' ).siblings( 'span.wppb-capability' ).text();
93
94 delete wppb_re_current_role_capabilities[jQuery( this ).closest( 'span.wppb-delete-capability' ).siblings( 'span.wppb-capability' ).text()];
95 delete wppb_re_new_capabilities[jQuery( this ).closest( 'span.wppb-delete-capability' ).siblings( 'span.wppb-capability' ).text()];
96
97 if( jQuery( '.wppb-add-new-cap-input' ).is( ':visible' ) ) {
98 wppb_re_change_select_to_input();
99 }
100
101 wppb_re_disable_select_capabilities( wppb_re_capabilities_group, deleted_capability, 'delete' );
102
103 if( jQuery( '.wppb-role-edit-table-entry' ).length < 1 ) {
104 wppb_re_no_capabilities_found();
105 }
106
107 wppb_re_number_of_capabilities();
108 }
109 } );
110
111 // Change between select2 with all existing capabilities and input to add a new capability
112 jQuery( '.post-type-wppb-roles-editor a.wppb-add-new-cap-link' ).on( 'click', function() {
113 wppb_re_change_select_to_input();
114 } );
115
116 jQuery( '.post-type-wppb-roles-editor .wppb-role-editor-tab' ).on( 'click', function() {
117 wppb_re_tabs_handler( jQuery( this ) );
118 } );
119
120 wppb_re_form_submit();
121
122 wppb_re_number_of_capabilities();
123
124 // Display number of users for current role
125 if( wppb_roles_editor_data.current_role_users_count !== null ) {
126 jQuery( '.post-type-wppb-roles-editor .misc-pub-section.misc-pub-section-users span' ).find( 'strong' ).text( wppb_roles_editor_data.current_role_users_count );
127 }
128
129 // Check if role has a title or return an error if not
130 jQuery( 'body' ).on( 'submit.edit-post', '#post', function() {
131 if( jQuery( '.post-type-wppb-roles-editor #title' ).val().replace( / /g, '' ).length === 0 ) {
132 window.alert( wppb_roles_editor_data.role_name_required_error_text );
133 jQuery( '.post-type-wppb-roles-editor #major-publishing-actions .spinner' ).hide();
134 jQuery( '.post-type-wppb-roles-editor #major-publishing-actions' ).find( ':button, :submit, a.submitdelete, #post-preview' ).removeClass( 'disabled' );
135 jQuery( '.post-type-wppb-roles-editor #title' ).trigger( 'focus' );
136
137 wppb_re_form_submit();
138
139 return false;
140 } else {
141 jQuery( '.post-type-wppb-roles-editor #major-publishing-actions .spinner' ).show();
142 }
143 } );
144 } );
145
146 function wppb_re_form_submit() {
147 jQuery( '.post-type-wppb-roles-editor #publishing-action #publish' ).off( 'click' ).one( 'click', function( e ) {
148 e.preventDefault();
149 jQuery( this ).addClass( 'disabled' );
150 jQuery( this ).siblings( '.spinner' ).addClass( 'is-active' );
151 wppb_re_update_role_capabilities();
152 } );
153 }
154
155 function wppb_re_no_capabilities_found() {
156 jQuery( '.post-type-wppb-roles-editor #wppb-role-edit-table' ).find( '#wppb-role-edit-caps-clear' ).after(
157 '<div class="wppb-role-edit-table-entry wppb-role-edit-no-cap">' +
158 '<span class="wppb-capability wppb-role-edit-not-capability">' + wppb_roles_editor_data.no_capabilities_found_text + '</span>' +
159 '</div>'
160 );
161 }
162
163 function wppb_re_number_of_capabilities() {
164 var count = 0;
165 var i;
166
167 for( i in wppb_re_current_role_capabilities ) {
168 if( wppb_re_current_role_capabilities.hasOwnProperty( i ) ) {
169 count++;
170 }
171 }
172
173 jQuery( '.post-type-wppb-roles-editor .misc-pub-section.misc-pub-section-capabilities span' ).find( 'strong' ).text( count );
174 }
175
176 function wppb_re_tabs_handler( tab ) {
177 wppb_re_display_capabilities( jQuery( tab ).data( 'wppb-re-tab' ) );
178
179 jQuery( '.post-type-wppb-roles-editor .wppb-role-editor-tab-title.wppb-role-editor-tab-active' ).removeClass( 'wppb-role-editor-tab-active' );
180 jQuery( tab ).closest( '.wppb-role-editor-tab-title' ).addClass( 'wppb-role-editor-tab-active' );
181 }
182
183 function wppb_re_disable_select_capabilities( wppb_re_capabilities_group, capabilities, action ) {
184 if( capabilities != null ) {
185 jQuery.each( wppb_re_capabilities_group, function( key, value ) {
186 jQuery.each( value['children'], function( key, value ) {
187 if( value['text'] in capabilities ) {
188 if( action == 'add' ) {
189 value['disabled'] = true;
190 } else if( action == 'delete' ) {
191 value['disabled'] = false;
192 }
193 }
194 } );
195 } );
196 }
197
198 wppb_re_initialize_select2( wppb_re_capabilities_group );
199 }
200
201 function wppb_re_initialize_select2( wppb_re_capabilities_group ) {
202 var capabilities_select = jQuery( '.wppb-capabilities-select' );
203
204 capabilities_select.empty();
205 capabilities_select.select2( {
206 placeholder: wppb_roles_editor_data.select2_placeholder_text,
207 allowClear: true,
208 data: wppb_re_capabilities_group,
209 templateResult: function( data ) {
210 if( data.id == null || jQuery.inArray( data.text, wppb_roles_editor_data.capabilities['custom']['capabilities'] ) === -1 ) {
211 return data.text;
212 }
213
214 var option = jQuery( '<span></span>' );
215 var delete_cap = jQuery( '<a class="wppb-re-cap-perm-delete">' + wppb_roles_editor_data.delete_permanently_text + '</a>' );
216
217 delete_cap.on( 'mouseup', function( event ) {
218 event.stopPropagation();
219 } );
220
221 delete_cap.on( 'click', function( event ) {
222 if( confirm( wppb_roles_editor_data.capability_text + ': ' + jQuery( this ).siblings( 'span' ).text() + '\n\n' + wppb_roles_editor_data.capability_perm_delete_text ) ) {
223 wppb_re_delete_capability_permanently( jQuery( this ).siblings( 'span' ).text() );
224 }
225 } );
226
227 option.text( data.text );
228 option = option.add( delete_cap );
229
230 return option;
231 }
232 } );
233 }
234
235 function wppb_re_delete_capability_permanently( capability ) {
236 var data = {
237 'action' : 'delete_capability_permanently',
238 'security' : jQuery( '.post-type-wppb-roles-editor #wppb-re-ajax-nonce' ).val(),
239 'capability' : capability
240 };
241
242 jQuery( '.post-type-wppb-roles-editor .wppb-role-edit-table-entry' ).remove();
243 jQuery( '.post-type-wppb-roles-editor .wppb-re-spinner-container' ).show();
244
245 jQuery.post( wppb_roles_editor_data.ajaxUrl, data, function( response ) {
246 window.location.reload();
247 } );
248 }
249
250 function wppb_re_create_capabilities_group( key, value, counter ) {
251 var capabilities_single_group_caps = {};
252 var capabilities_single_group_caps_array = [];
253
254 jQuery.each( value['capabilities'], function( key, value ) {
255 capabilities_single_group_caps = {
256 id: value + '_' + counter,
257 text: value
258 };
259
260 capabilities_single_group_caps_array.push( capabilities_single_group_caps );
261 } );
262
263 return {
264 category: key,
265 text: value['label'],
266 children: capabilities_single_group_caps_array
267 };
268 }
269
270 function wppb_re_display_capabilities( action ) {
271 jQuery( '.post-type-wppb-roles-editor .wppb-re-spinner-container' ).hide();
272 jQuery( '.post-type-wppb-roles-editor .wppb-role-edit-table-entry' ).remove();
273
274 var capabilities;
275 if( action == 'all' ) {
276 capabilities = wppb_re_current_role_capabilities;
277 } else {
278 capabilities = wppb_re_capabilities_group;
279 }
280
281 jQuery.each( capabilities, function( key, value ) {
282 var table = jQuery( '#wppb-role-edit-table' );
283
284 if( action == 'all' ) {
285 wppb_re_display_capability( key );
286 } else {
287 if( value['category'] == action ) {
288 jQuery.each( value['children'], function( key, value ) {
289 if( wppb_re_current_role_capabilities != null && value['text'] in wppb_re_current_role_capabilities ) {
290 wppb_re_display_capability( value['text'] );
291 }
292 } );
293 }
294
295 if( value['category'] == action && action == 'custom' ) {
296 if( ! jQuery.isEmptyObject( wppb_re_new_capabilities ) ) {
297 jQuery.each( wppb_re_new_capabilities, function( key, value ) {
298 if( ! ( value in wppb_roles_editor_data.all_capabilities ) ) {
299 var new_capability_check = 0;
300 jQuery.each( wppb_roles_editor_data.capabilities, function( key2, value2 ) {
301 if( value2['label'] && value2['label'] != 'Custom' && jQuery.inArray( value, value2['capabilities'] ) !== -1 ) {
302 new_capability_check++;
303 }
304 } );
305
306 if( new_capability_check == 0 ) {
307 wppb_re_display_capability( value );
308 }
309 }
310 } );
311 }
312 }
313 }
314 } );
315
316 if( jQuery( '.post-type-wppb-roles-editor .wppb-role-edit-table-entry' ).length ) {
317 jQuery( '.post-type-wppb-roles-editor .wppb-role-edit-no-cap' ).remove();
318 } else {
319 wppb_re_no_capabilities_found();
320 }
321 }
322
323 function wppb_re_display_capability( capability ) {
324 var title = '';
325 var wppb_capability_class = 'wppb-capability';
326 if( ! wppb_roles_editor_data.current_role_capabilities || ( wppb_roles_editor_data.current_role_capabilities && ! ( capability in wppb_roles_editor_data.current_role_capabilities ) ) ) {
327 wppb_capability_class = wppb_capability_class + ' wppb-new-capability';
328 title = 'title = "' + wppb_roles_editor_data.new_cap_update_title_text + '"';
329 } else if( wppb_re_getParameterByName( 'wppb_re_clone' ) && ! wppb_roles_editor_data.current_role_capabilities ) {
330 wppb_capability_class = wppb_capability_class + ' wppb-new-capability';
331 title = 'title = "' + wppb_roles_editor_data.new_cap_publish_title_text + '"';
332 }
333
334 var delete_link = '<a class="wppb-delete-capability-link" href="javascript:void(0)">Delete</a>';
335 if( wppb_roles_editor_data.current_user_role && jQuery.inArray( capability, wppb_roles_editor_data.admin_capabilities ) !== -1 ) {
336 delete_link = '<span class="wppb-delete-capability-disabled" title="' + wppb_roles_editor_data.cap_no_delete_text + '">' + wppb_roles_editor_data.delete_text + '</span>';
337 }
338
339 jQuery( '.post-type-wppb-roles-editor #wppb-role-edit-table' ).find( '#wppb-role-edit-caps-clear' ).after(
340 '<div class="wppb-role-edit-table-entry" ' + title + '>' +
341 '<span class="' + wppb_capability_class + '">' + capability + '</span>' +
342 '<span class="wppb-delete-capability">' + delete_link + '</span>' +
343 '</div>'
344 );
345 }
346
347 function wppb_re_add_capability() {
348 var capabilities_select = jQuery( '.post-type-wppb-roles-editor .wppb-capabilities-select' );
349 var new_capability_input = jQuery( '.post-type-wppb-roles-editor .wppb-add-new-cap-input' );
350 var table = jQuery( '.post-type-wppb-roles-editor #wppb-role-edit-table' );
351 var capabilities = {};
352 var no_duplicates = {};
353
354 if( jQuery( '.post-type-wppb-roles-editor .select2.select2-container' ).is( ':visible' ) && jQuery( capabilities_select ).val() != null ) {
355 jQuery( capabilities_select ).find( 'option:selected' ).each( function() {
356 if( ! no_duplicates[jQuery( this ).text()] ) {
357 if( ! jQuery( '.post-type-wppb-roles-editor .wppb-role-editor-tab.wppb-role-editor-all' ).closest( 'li.wppb-role-editor-tab-title' ).hasClass( 'wppb-role-editor-tab-active' ) ) {
358 wppb_re_tabs_handler( jQuery( '.post-type-wppb-roles-editor .wppb-role-editor-tab.wppb-role-editor-all' ) );
359 }
360
361 var title = '';
362 var wppb_capability_class = 'wppb-capability';
363 if( ! wppb_roles_editor_data.current_role_capabilities || ( wppb_roles_editor_data.current_role_capabilities && ! ( jQuery( this ).text() in wppb_roles_editor_data.current_role_capabilities ) ) ) {
364 wppb_capability_class = wppb_capability_class + ' wppb-new-capability';
365 wppb_re_unsaved_capabilities[jQuery( this ).text()] = jQuery( this ).text();
366 title = 'title = "' + wppb_roles_editor_data.new_cap_update_title_text + '"';
367 } else if( wppb_re_getParameterByName( 'wppb_re_clone' ) && ! wppb_roles_editor_data.current_role_capabilities ) {
368 wppb_capability_class = wppb_capability_class + ' wppb-new-capability';
369 title = 'title = "' + wppb_roles_editor_data.new_cap_publish_title_text + '"';
370 }
371
372 jQuery( '.post-type-wppb-roles-editor .wppb-role-edit-no-cap' ).remove();
373
374 jQuery( table ).find( '#wppb-role-edit-caps-clear' ).after(
375 '<div class="wppb-role-edit-table-entry wppb-new-capability-highlight" ' + title + '>' +
376 '<span class="' + wppb_capability_class + '">' + jQuery( this ).text() + '</span>' +
377 '<span class="wppb-delete-capability"><a class="wppb-delete-capability-link" href="javascript:void(0)">' + wppb_roles_editor_data.delete_text + '</a></span>' +
378 '</div>' );
379
380 capabilities[jQuery( this ).text()] = jQuery( this ).text();
381 no_duplicates[jQuery( this ).text()] = jQuery( this ).text();
382
383 delete wppb_re_capabilities_to_delete[jQuery( this ).text()];
384 }
385 } );
386
387 wppb_re_new_capability( capabilities );
388
389 wppb_re_disable_select_capabilities( wppb_re_capabilities_group, capabilities, 'add' );
390
391 jQuery( capabilities_select ).val( null ).trigger( 'change' );
392
393 wppb_re_number_of_capabilities();
394
395 setTimeout( function() {
396 jQuery( '.post-type-wppb-roles-editor .wppb-role-edit-table-entry' ).removeClass( 'wppb-new-capability-highlight' );
397 }, 500 );
398 } else if( jQuery( new_capability_input ).is( ':visible' ) && jQuery( new_capability_input ).val().length != 0 ) {
399 var new_capability_value = jQuery( new_capability_input ).val();
400 new_capability_value = new_capability_value.trim().replace( /<.*?>/g, '' ).replace( /\s/g, '_' ).replace( /[^a-zA-Z0-9_]/g, '' );
401
402 if( new_capability_value && ( ! wppb_roles_editor_data.hidden_capabilities || ! ( new_capability_value in wppb_roles_editor_data.hidden_capabilities ) ) ) {
403 if( ! ( new_capability_value in wppb_re_current_role_capabilities ) && ! ( new_capability_value in wppb_re_new_capabilities ) ) {
404 wppb_re_tabs_handler( jQuery( '.post-type-wppb-roles-editor .wppb-role-editor-tab.wppb-role-editor-all' ) );
405
406 var title = '';
407 var wppb_capability_class = 'wppb-capability';
408 if( ! wppb_roles_editor_data.current_role_capabilities || ( wppb_roles_editor_data.current_role_capabilities && ! ( new_capability_value in wppb_roles_editor_data.current_role_capabilities ) ) ) {
409 wppb_capability_class = wppb_capability_class + ' wppb-new-capability';
410 wppb_re_unsaved_capabilities[new_capability_value] = new_capability_value;
411 title = 'title = "' + wppb_roles_editor_data.new_cap_update_title_text + '"';
412 } else if( wppb_re_getParameterByName( 'wppb_re_clone' ) && ! wppb_roles_editor_data.current_role_capabilities ) {
413 wppb_capability_class = wppb_capability_class + ' wppb-new-capability';
414 title = 'title = "' + wppb_roles_editor_data.new_cap_publish_title_text + '"';
415 }
416
417 jQuery( '.post-type-wppb-roles-editor .wppb-role-edit-no-cap' ).remove();
418
419 jQuery( table ).find( '#wppb-role-edit-caps-clear' ).after(
420 '<div class="wppb-role-edit-table-entry wppb-new-capability-highlight" ' + title + '>' +
421 '<span class="' + wppb_capability_class + '">' + new_capability_value + '</span>' +
422 '<span class="wppb-delete-capability"><a class="wppb-delete-capability-link" href="javascript:void(0)">' + wppb_roles_editor_data.delete_text + '</a></span>' +
423 '</div>' );
424
425 capabilities[new_capability_value] = new_capability_value;
426 delete wppb_re_capabilities_to_delete[new_capability_value];
427
428 wppb_re_change_select_to_input();
429
430 wppb_re_new_capability( capabilities );
431
432 wppb_re_disable_select_capabilities( wppb_re_capabilities_group, capabilities, 'add' );
433
434 jQuery( new_capability_input ).val( '' );
435
436 wppb_re_number_of_capabilities();
437
438 setTimeout( function() {
439 jQuery( '.post-type-wppb-roles-editor .wppb-role-edit-table-entry' ).removeClass( 'wppb-new-capability-highlight' );
440 }, 500 );
441 } else {
442 jQuery( new_capability_input ).val( '' );
443
444 jQuery( '.post-type-wppb-roles-editor #wppb-duplicate-capability-error' ).show().delay( 3000 ).fadeOut();
445 }
446 } else if( wppb_roles_editor_data.hidden_capabilities && new_capability_value in wppb_roles_editor_data.hidden_capabilities ) {
447 jQuery( '.post-type-wppb-roles-editor #wppb-hidden-capability-error' ).show().delay( 3000 ).fadeOut();
448 } else {
449 jQuery( '.post-type-wppb-roles-editor #wppb-add-capability-error' ).show().delay( 3000 ).fadeOut();
450 }
451 } else {
452 jQuery( '.post-type-wppb-roles-editor #wppb-add-capability-error' ).show().delay( 3000 ).fadeOut();
453 }
454 }
455
456 function wppb_re_new_capability( capabilities ) {
457 jQuery.each( capabilities, function( key, value ) {
458 if( ! ( value in wppb_roles_editor_data.all_capabilities ) || ! ( value in wppb_re_current_role_capabilities ) ) {
459 wppb_re_new_capabilities[value] = value;
460 }
461 } );
462
463 jQuery.extend( wppb_re_current_role_capabilities, wppb_re_new_capabilities );
464 }
465
466 function wppb_re_update_role_capabilities() {
467 jQuery( '.post-type-wppb-roles-editor #wppb-role-slug-hidden' ).val( jQuery( '#wppb-role-slug' ).val() );
468
469 var data = {
470 'action' : 'update_role_capabilities',
471 'security' : jQuery( '.post-type-wppb-roles-editor #wppb-re-ajax-nonce' ).val(),
472 'role_display_name' : jQuery( '.post-type-wppb-roles-editor #titlediv' ).find( '#title' ).val(),
473 'role' : jQuery( '.post-type-wppb-roles-editor #wppb-role-slug' ).val(),
474 'new_capabilities' : wppb_re_unsaved_capabilities,
475 'all_capabilities' : wppb_re_current_role_capabilities,
476 'capabilities_to_delete' : wppb_re_capabilities_to_delete
477 };
478
479 jQuery.post( wppb_roles_editor_data.ajaxUrl, data, function( response ) {
480 jQuery( '.post-type-wppb-roles-editor #publishing-action #publish' ).removeClass( 'disabled' ).trigger( 'click' );
481 } );
482 }
483
484 function wppb_re_change_select_to_input() {
485 if( jQuery( '.post-type-wppb-roles-editor .select2.select2-container' ).is( ':visible' ) ) {
486 jQuery( '.post-type-wppb-roles-editor .select2.select2-container' ).hide();
487 jQuery( '.post-type-wppb-roles-editor .wppb-add-new-cap-input' ).show();
488 jQuery( '.post-type-wppb-roles-editor a.wppb-add-new-cap-link' ).text( wppb_roles_editor_data.cancel_text );
489 } else {
490 jQuery( '.post-type-wppb-roles-editor .select2.select2-container' ).show();
491 jQuery( '.post-type-wppb-roles-editor .wppb-add-new-cap-input' ).hide();
492 jQuery( '.post-type-wppb-roles-editor a.wppb-add-new-cap-link' ).text( wppb_roles_editor_data.add_new_capability_text );
493 }
494 }
495
496 function wppb_re_getParameterByName( name, url ) {
497 if( ! url ) {
498 url = window.location.href;
499 }
500
501 name = name.replace( /[\[\]]/g, "\\$&" );
502
503 var regex = new RegExp( "[?&]" + name + "(=([^&#]*)|&|#|$)" ), results = regex.exec( url );
504
505 if( ! results ) {
506 return null;
507 }
508
509 if( ! results[2] ) {
510 return '';
511 }
512
513 return decodeURIComponent( results[2].replace( /\+/g, " " ) );
514 }
515