PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.3
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / assets / js / mainwp-groups.js

mainwp-groups.js in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.3, at assets/js/mainwp-groups.js

196 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery( document ).ready( function () {
2
3 // Init the groups menu
4 jQuery( '#mainwp-groups-menu' ).find( 'a.item' ).on( 'click', function () {
5 jQuery( this ).addClass( 'active green' );
6 jQuery( this ).siblings().removeClass( 'active green' );
7 jQuery( this ).find( '.label' ).addClass( 'green' );
8 jQuery( this ).siblings().find( '.label' ).removeClass( 'green' );
9 jQuery( '#mainwp-delete-group-button' ).removeClass( 'disabled' );
10 jQuery( '#mainwp-rename-group-button' ).removeClass( 'disabled' );
11 jQuery( '#mainwp-save-sites-groups-selection-button' ).removeClass( 'disabled' );
12 show_group_items( this );
13 } );
14
15 // Trigger the create a new group modal
16 jQuery( document ).on( 'click', '#mainwp-new-sites-group-button', function () {
17 jQuery( '#mainwp-create-group-modal' ).modal( {
18 onHide: function () {
19 window.location.reload();
20 return false;
21 },
22 onShow: function () {
23 jQuery( '#mainwp-create-group-modal' ).find( 'input' ).val( '' );
24 return false;
25 }
26 } ).modal( 'show' );
27 } );
28
29 // Trigger the edit group modal
30 jQuery( document ).on( 'click', '#mainwp-rename-group-button', function () {
31 jQuery( '#mainwp-rename-group-modal' ).modal( {
32 onHide: function () {
33 window.location.reload();
34 return false;
35 },
36 onShow: function () {
37 var groupName = jQuery( '#mainwp-groups-menu' ).find( '.active' ).find( '#mainwp-hidden-group-name' ).val();
38 jQuery( '#mainwp-rename-group-modal' ).find( 'input' ).val( groupName );
39 return false;
40 }
41 } ).modal( 'show' );
42 } );
43
44 // Create a new group
45 jQuery( document ).on( 'click', '#mainwp-save-new-group-button', function () {
46 var newName = jQuery( '#mainwp-create-group-modal' ).find( 'input' ).val();
47 var data = mainwp_secure_data( {
48 action: 'mainwp_group_add',
49 newName: newName
50 } );
51 jQuery.post( ajaxurl, data, function ( response ) {
52 try {
53 resp = jQuery.parseJSON( response );
54
55 if ( resp.error != undefined )
56 return;
57 } catch ( err ) {
58 // to fix js error.
59 }
60 jQuery( '#mainwp-create-group-modal' ).modal( {
61 onHide: function () {
62 window.location.reload();
63 return false;
64 }
65 } ).modal( 'hide' );
66 } );
67 return false;
68 } );
69
70 // Delete a group
71 jQuery( document ).on( 'click', '#mainwp-delete-group-button', function () {
72 var gruopItem = jQuery( '#mainwp-groups-menu' ).find( '.active' );
73 mainwp_confirm( 'Are you sure you want to delete this group?', function() {
74 var groupID = gruopItem.attr( 'id' );
75 var data = mainwp_secure_data( {
76 action: 'mainwp_group_delete',
77 groupId: groupID
78 } );
79 jQuery.post( ajaxurl, data, function ( gruopItem ) {
80 return function ( response ) {
81 response = jQuery.trim( response );
82 if ( response == 'OK' ) {
83 gruopItem.fadeOut( 300 );
84 }
85 }
86 }( gruopItem ) );
87 } );
88 return false;
89 } );
90
91 // Update group name
92 jQuery( document ).on( 'click', '#mainwp-update-new-group-button', function () {
93 var groupID = jQuery( '#mainwp-groups-menu' ).find( '.active' ).attr( 'id' );
94 var newName = jQuery( '#mainwp-rename-group-modal' ).find( 'input' ).val();
95 var data = mainwp_secure_data( {
96 action: 'mainwp_group_rename',
97 groupId: groupID,
98 newName: newName
99 } );
100 jQuery.post( ajaxurl, data, function () {
101 return function ( response ) {
102 if ( response.error ) {
103 return;
104 }
105 response = jQuery.trim( response.result );
106 jQuery( '#mainwp-create-group-modal' ).modal( {
107 onHide: function () {
108 window.location.reload();
109 return false;
110 }
111 } ).modal( 'hide' );
112 }
113 }(), 'json' );
114 return false;
115 } );
116
117 // Select all sites
118 jQuery( '#mainwp-manage-groups-sites-table th input[type="checkbox"]' ).on( 'change', function () {
119 var checkboxes = jQuery( '#mainwp-manage-groups-sites-table' ).find( ':checkbox' );
120 if ( jQuery( this ).prop( 'checked' ) ) {
121 checkboxes.prop( 'checked', true );
122 checkboxes.parents( 'tr' ).addClass( 'active' );
123 } else {
124 checkboxes.prop( 'checked', false );
125 checkboxes.parents( 'tr' ).removeClass( 'active' );
126 }
127 } );
128
129 // Set class 'active' to selected sites table row
130 jQuery( '.mainwp-site-checkbox' ).on( 'change', function () {
131 if ( jQuery( this ).prop( 'checked' ) ) {
132 jQuery( this ).parents( 'tr' ).addClass( 'active' );
133 } else {
134 jQuery( this ).parents( 'tr' ).removeClass( 'active' );
135 }
136 } );
137
138 // Save selected sites for a group
139 jQuery( document ).on( 'click', '#mainwp-save-sites-groups-selection-button', function () {
140 var groupID = jQuery( '#mainwp-groups-menu' ).find( '.active' ).attr( 'id' );
141 var sites = jQuery( '#mainwp-manage-groups-sites-table' ).find( 'input.mainwp-site-checkbox:checked' );
142 var sitesIDs = [ ];
143
144 for ( var i = 0; i < sites.length; i++ ) {
145 sitesIDs.push( jQuery( sites[i] ).val() );
146 }
147
148 if ( groupID == undefined ) {
149 return;
150 }
151
152 var data = mainwp_secure_data( {
153 action: 'mainwp_group_updategroup',
154 groupId: groupID,
155 websiteIds: sitesIDs
156 } );
157
158 jQuery( this ).addClass( 'disabled' );
159
160 jQuery.post( ajaxurl, data, function () {
161 jQuery( this ).removeClass( 'disabled' );
162 jQuery( '#mainwp-message-zone' ).stop( true, true );
163 jQuery( '#mainwp-message-zone' ).show();
164 jQuery( '#mainwp-message-zone' ).fadeOut( 3000 );
165 return;
166 }, 'json' );
167
168 } );
169
170 // Load group sites
171 show_group_items = function( group ) {
172 var groupID = jQuery( group ).attr( 'id' );
173 var data = mainwp_secure_data( {
174 action: 'mainwp_group_getsites',
175 groupId: groupID
176 } );
177 jQuery( '.dimmer' ).addClass( 'active' );
178 jQuery.post( ajaxurl, data, function ( response ) {
179 jQuery( '.dimmer' ).removeClass( 'active' );
180 response = jQuery.trim( response );
181 if ( response == 'ERROR' ) {
182 return;
183 }
184 jQuery( 'input.mainwp-site-checkbox' ).prop( 'checked', false );
185 jQuery( 'input.mainwp-site-checkbox' ).closest( 'tr' ).removeClass( 'active' );
186 var sites = jQuery.parseJSON( response );
187 for ( var i = 0; i < sites.length; i++ ) {
188 jQuery( 'input[value="' + sites[i] + '"].mainwp-site-checkbox' ).prop( 'checked', true );
189 jQuery( 'input[value="' + sites[i] + '"].mainwp-site-checkbox' ).closest( 'tr' ).addClass( 'active' );
190 }
191 } );
192 return false;
193 }
194
195 } );
196