PluginProbe ʕ •ᴥ•ʔ
File Manager Pro – Filester / 1.8.2
File Manager Pro – Filester v1.8.2
2.1.1 trunk 1.6.1 1.7.6 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 2.0 2.0.1 2.0.2 2.1.0
filester / assets / js / file_manager_admin.js
filester / assets / js Last commit date
toastr 1 year ago cross.js 1 year ago file_manager_admin.js 1 year ago review.js 1 year ago
file_manager_admin.js
336 lines
1 const njtFileManager = {
2 sunriseCreateCookie(name, value, days) {
3 if (days) {
4 var date = new Date();
5 date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
6 var expires = "; expires=" + date.toGMTString();
7 } else var expires = "";
8 document.cookie = name + "=" + value + expires + "; path=/";
9 },
10
11 sunriseReadCookie(name) {
12 var nameEQ = name + "=";
13 var ca = document.cookie.split(";");
14 for (var i = 0; i < ca.length; i++) {
15 var c = ca[i];
16 while (c.charAt(0) == " ") c = c.substring(1, c.length);
17 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
18 }
19 return null;
20 },
21
22 capitalizeFirstLetter(string) {
23 return string.charAt(0).toUpperCase() + string.slice(1);
24 },
25
26 //Setting tab
27 activeTabSetting() {
28 var pagenow = "njt-fs-filemanager-settings-tab";
29 jQuery("#njt-plugin-tabs a").click(function (event) {
30 jQuery("#njt-plugin-tabs a").removeClass("nav-tab-active");
31 jQuery(".njt-plugin-setting").hide();
32 jQuery(this).addClass("nav-tab-active");
33 if (jQuery(this).data('tab') == 'njt_fs_roles') {
34 location.hash = "#user-role-restrictions";
35 } else {
36 var noHashURL = window.location.href.replace(/#.*$/, '');
37 window.history.replaceState('', document.title, noHashURL)
38 }
39
40 // Show current pane
41 jQuery(".njt-plugin-setting:eq(" + jQuery(this).index() + ")").show();
42 njtFileManager.sunriseCreateCookie(pagenow + "_last_tab", jQuery(this).index(), 365);
43 });
44
45 //Auto-open tab by cookies
46 if (njtFileManager.sunriseReadCookie(pagenow + "_last_tab") != null)
47 jQuery("#njt-plugin-tabs a:eq(" + njtFileManager.sunriseReadCookie(pagenow + "_last_tab") + ")").trigger("click");
48 // Open first tab by default
49 else jQuery("#njt-plugin-tabs a:eq(0)").trigger("click");
50 },
51
52 themeSelector() {
53 if (jQuery('input[name = "selected-theme"]')) {
54 const selectedTheme = jQuery('input[name = "selected-theme"]').val()
55 jQuery('#selector-themes').val(selectedTheme);
56 }
57
58 jQuery('select#selector-themes').on('change', function () {
59 const themesValue = jQuery(this).val()
60 const dataThemes = {
61 'action': 'selector_themes',
62 'themesValue': themesValue,
63 'nonce': wpData.nonce,
64 }
65 jQuery.post(
66 wpData.admin_ajax,
67 dataThemes,
68 function (response) {
69 jQuery('link#themes-selector-css').attr('href', response.data)
70 });
71 });
72 },
73
74 actionSettingFormSubmit() {
75 jQuery('.njt-settings-form-submit').on('click', function () {
76 const arraylistUserAccess = [];
77 jQuery('.fm-list-user-item').each(function () {
78 if (jQuery(this).is(":checked")) {
79 arraylistUserAccess.push(jQuery(this).val());
80 }
81 });
82 if (!wpData.is_multisite) {
83 arraylistUserAccess.push('administrator')
84 }
85 jQuery("#list_user_alow_access").val(arraylistUserAccess)
86 })
87 },
88
89 userHasApproved() {
90 const arrayUserHasApproved = jQuery('#list_user_has_approved').val() ? jQuery('#list_user_has_approved').val().split(",") : []
91 for (itemUserHasApproved of arrayUserHasApproved) {
92 if (!wpData.is_multisite) {
93 if (itemUserHasApproved != 'administrator') {
94 jQuery('input[name = ' + itemUserHasApproved + ']').prop('checked', true);
95 }
96 } else {
97 jQuery('input[name = ' + itemUserHasApproved + ']').prop('checked', true);
98 }
99
100 }
101 },
102
103 actionSubmitRoleRestrictionst() {
104 jQuery('#njt-form-user-role-restrictionst').on('click', function () {
105 const arrayUserRestrictionsAccess = [];
106 if (!jQuery('.njt-fs-list-user-restrictions').val()) {
107 alert('Please select a User Role at Setings tab to use this option.')
108 return false;
109 }
110 jQuery('.fm-list-user-restrictions-item').each(function () {
111 if (jQuery(this).is(":checked")) {
112 arrayUserRestrictionsAccess.push(jQuery(this).val());
113 }
114 });
115 jQuery("#list_user_restrictions_alow_access").val(arrayUserRestrictionsAccess)
116
117 if (jQuery("#hide_paths").val().trim().length > 0) {
118 const valueHidePaths = jQuery("#hide_paths").val().trim().split("|")
119 const newValueHidePaths = []
120 for (const itemHidePath of valueHidePaths) {
121 if (itemHidePath.trim().length > 0) {
122 newValueHidePaths.push(itemHidePath.trim())
123 }
124 }
125 jQuery("#hide_paths").val(newValueHidePaths.join("|"))
126 }
127
128 if (jQuery("#lock_files").val().trim().length > 0) {
129 const valueLockFiles = jQuery("#lock_files").val().trim().split("|")
130 const newValueLockFiles = []
131 for (const itemLockFile of valueLockFiles) {
132 if (itemLockFile.trim().length > 0) {
133 newValueLockFiles.push(itemLockFile.trim())
134 }
135 }
136 jQuery("#lock_files").val(newValueLockFiles.join("|"))
137 }
138
139 })
140 },
141
142 restrictionsHasApproved() {
143 const arrayRestrictionsHasApproved = jQuery('#list_restrictions_has_approved').val() ? jQuery('#list_restrictions_has_approved').val().split(",") : []
144 for (itemRestrictionsHasApproved of arrayRestrictionsHasApproved) {
145 jQuery('input[name = ' + itemRestrictionsHasApproved + ']').prop('checked', true);
146 }
147 },
148
149 ajaxRoleRestrictions() {
150 jQuery('select.njt-fs-list-user-restrictions').on('change', function () {
151 const valueUserRole = jQuery(this).val()
152 const dataUserRole = {
153 'action': 'get_role_restrictions',
154 'valueUserRole': valueUserRole,
155 'nonce': wpData.nonce,
156 }
157 jQuery.post(
158 wpData.admin_ajax,
159 dataUserRole,
160 function (response) {
161 const resRestrictionsHasApproved = response.data.disable_operations ? response.data.disable_operations.split(",") : []
162 const resPrivateFolderAccess = response.data.private_folder_access ? response.data.private_folder_access : ''
163 const resPrivateURLFolderAccess = response.data.private_url_folder_access ? response.data.private_url_folder_access : ''
164 const resHidePaths = response.data.hide_paths ? response.data.hide_paths.replace(/[,]+/g, ' | ') : '';
165 const resLockFiles = response.data.lock_files ? response.data.lock_files.replace(/[,]+/g, ' | ') : '';
166 const resCanUploadMime = response.data.can_upload_mime ? response.data.can_upload_mime : '';
167 jQuery('input.fm-list-user-restrictions-item').prop('checked', false);
168 for (itemRestrictionsHasApproved of resRestrictionsHasApproved) {
169 jQuery('input[name = ' + itemRestrictionsHasApproved + ']').prop('checked', true);
170 }
171 // Set value for textarea[name='private_folder_access']
172 jQuery('textarea#private_folder_access').val(resPrivateFolderAccess)
173 // Set value for textarea[name='private_url_folder_access']
174 jQuery('textarea#private_url_folder_access').val(resPrivateURLFolderAccess)
175 // Set value for textarea[name='hide_paths']
176 jQuery('textarea#hide_paths').val(resHidePaths)
177 // Set value for textarea[name='lock_files']
178 jQuery('textarea#lock_files').val(resLockFiles)
179 // Set value for textarea[name='can_upload_mime']
180 jQuery('textarea#can_upload_mime').val(resCanUploadMime)
181 });
182 });
183 },
184 clickedCreatRootPath() {
185 jQuery('.js-creat-root-path').on('click', function () {
186 const valueRootPath = wpData.ABSPATH
187 jQuery('textarea#private_folder_access').val(valueRootPath)
188 })
189 },
190
191 ajaxSaveSettings() {
192 jQuery('.njt-settings-form-submit').on('click', function () {
193 const arraylistUserAccess = [];
194 jQuery(this).addClass('njt-fs-updating-message');
195 jQuery('.fm-list-user-item').each(function () {
196 if (jQuery(this).is(":checked")) {
197 arraylistUserAccess.push(jQuery(this).val());
198 }
199 });
200 if (!wpData.is_multisite) {
201 arraylistUserAccess.push('administrator')
202 }
203 jQuery("#list_user_alow_access").val(arraylistUserAccess)
204 const list_user_alow_access = jQuery("#list_user_alow_access").val()
205 const root_folder_path = jQuery("#root_folder_path").val()
206 const root_folder_url = jQuery("#root_folder_url").val()
207 const upload_max_size = jQuery("#upload_max_size").val()
208 const fm_locale = jQuery("#fm_locale").val()
209 const enable_htaccess = jQuery("#enable_htaccess").is(":checked")
210 const enable_trash = jQuery("#enable_trash").is(":checked")
211 const data = {
212 'nonce': wpData.nonce,
213 'action': 'njt_fs_save_setting',
214 'root_folder_path': root_folder_path,
215 'root_folder_url': root_folder_url,
216 'list_user_alow_access': list_user_alow_access,
217 'upload_max_size': upload_max_size,
218 'fm_locale': fm_locale,
219 'enable_htaccess': enable_htaccess,
220 'enable_trash': enable_trash
221
222 }
223 const toastr_opt = {
224 closeButton: true,
225 showDuration: 300,
226 hideDuration: 300,
227 hideMethod: "fadeOut",
228 positionClass: "toast-top-right njt-fs-toastr"
229 }
230 jQuery.post(
231 wpData.admin_ajax,
232 data,
233 function (response) {
234 const list_access = response.data.njt_fs_file_manager_settings.list_user_alow_access
235 const index = list_access.indexOf('administrator');
236 if (index > -1) {
237 list_access.splice(index, 1);
238 }
239
240 if (list_access.length > 0) {
241 jQuery('.njt-fs-list-user-restrictions').empty()
242 list_access.forEach((item) => {
243 jQuery('.njt-fs-list-user-restrictions').append(`<option value="${item}"> ${njtFileManager.capitalizeFirstLetter(item)} </option>`);
244 });
245 jQuery('.njt-text-error').hide()
246 } else {
247 jQuery('.njt-fs-list-user-restrictions').empty()
248 jQuery('.njt-fs-list-user-restrictions').append('<option selected="" disabled="" hidden="">Nothing to choose</option>');
249 jQuery('.njt-text-error').show()
250 }
251 jQuery('.njt-fs-list-user-restrictions').change()
252 if (response.success) {
253 jQuery('.njt-settings-form-submit').removeClass('njt-fs-updating-message');
254 toastr.success('Changes Saved', '', toastr_opt)
255 } else {
256 jQuery('.njt-settings-form-submit').removeClass('njt-fs-updating-message');
257 toastr.error('Please try again later', '', toastr_opt)
258 }
259 });
260 })
261 },
262 ajaxSaveSettingsRestrictions() {
263 jQuery('#njt-form-user-role-restrictionst').on('click', function () {
264 jQuery(this).addClass('njt-fs-updating-message');
265 const njt_fs_list_user_restrictions = jQuery(".njt-fs-list-user-restrictions").val()
266 const list_user_restrictions_alow_access = jQuery("#list_user_restrictions_alow_access").val()
267 const private_folder_access = jQuery("#private_folder_access").val()
268 const private_url_folder_access = jQuery("#private_url_folder_access").val()
269 const hide_paths = jQuery("#hide_paths").val()
270 const lock_files = jQuery("#lock_files").val()
271 const can_upload_mime = jQuery("#can_upload_mime").val()
272
273 const data = {
274 'nonce': wpData.nonce,
275 'action': 'njt_fs_save_setting_restrictions',
276 'njt_fs_list_user_restrictions': njt_fs_list_user_restrictions,
277 'list_user_restrictions_alow_access': list_user_restrictions_alow_access,
278 'private_folder_access': private_folder_access,
279 'private_url_folder_access': private_url_folder_access,
280 'hide_paths': hide_paths,
281 'lock_files': lock_files,
282 'can_upload_mime': can_upload_mime
283 }
284 const toastr_opt = {
285 closeButton: true,
286 showDuration: 300,
287 hideDuration: 200,
288 hideMethod: "fadeOut",
289 positionClass: "toast-top-right njt-fs-toastr"
290 }
291 jQuery.post(
292 wpData.admin_ajax,
293 data,
294 function (response) {
295 if (response.success) {
296 jQuery('#njt-form-user-role-restrictionst').removeClass('njt-fs-updating-message');
297 toastr.success('Changes Saved', '', toastr_opt)
298 } else {
299 jQuery('#njt-form-user-role-restrictionst').removeClass('njt-fs-updating-message');
300 toastr.error('Error! Please try again', '', toastr_opt)
301 }
302 });
303 })
304 }
305 }
306
307 jQuery(document).ready(function () {
308 if (jQuery("div").hasClass("njt-fs-file-manager")) {
309
310 //set select value
311 njtFileManager.themeSelector();
312 // Start- Setting for `Select User Roles to access`
313 njtFileManager.actionSettingFormSubmit();
314 // Get value to prop checked for input checkbox
315 njtFileManager.userHasApproved();
316 //Setting tab
317 njtFileManager.activeTabSetting();
318
319 njtFileManager.actionSubmitRoleRestrictionst();
320 // Get value to prop checked for input checkbox
321 njtFileManager.restrictionsHasApproved();
322 //Ajax change value
323 njtFileManager.ajaxRoleRestrictions();
324 //Creat root path default
325 njtFileManager.clickedCreatRootPath();
326 // End- Setting for `Select User Roles Restrictions to access`
327
328 //Ajax settings
329 njtFileManager.ajaxSaveSettings();
330 njtFileManager.ajaxSaveSettingsRestrictions();
331 if(jQuery(".elfinder-theme-ext") > 0) {
332 jQuery(".elfinder-theme-ext").remove()
333 }
334 }
335 });
336