PluginProbe ʕ •ᴥ•ʔ
File Manager Pro – Filester / trunk
File Manager Pro – Filester vtrunk
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 5 years ago cross.js 5 years ago file_manager_admin.js 9 months ago review.js 5 years ago
file_manager_admin.js
422 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 enable_sensitive_protection = jQuery("#enable_sensitive_protection").is(":checked")
212 const data = {
213 'nonce': wpData.nonce,
214 'action': 'njt_fs_save_setting',
215 'root_folder_path': root_folder_path,
216 'root_folder_url': root_folder_url,
217 'list_user_alow_access': list_user_alow_access,
218 'upload_max_size': upload_max_size,
219 'fm_locale': fm_locale,
220 'enable_htaccess': enable_htaccess,
221 'enable_trash': enable_trash,
222 'enable_sensitive_protection': enable_sensitive_protection
223
224 }
225 const toastr_opt = {
226 closeButton: true,
227 showDuration: 300,
228 hideDuration: 300,
229 hideMethod: "fadeOut",
230 positionClass: "toast-top-right njt-fs-toastr"
231 }
232 jQuery.post(
233 wpData.admin_ajax,
234 data,
235 function (response) {
236 const list_access = response.data.njt_fs_file_manager_settings.list_user_alow_access
237 const index = list_access.indexOf('administrator');
238 if (index > -1) {
239 list_access.splice(index, 1);
240 }
241
242 if (list_access.length > 0) {
243 jQuery('.njt-fs-list-user-restrictions').empty()
244 list_access.forEach((item) => {
245 jQuery('.njt-fs-list-user-restrictions').append(`<option value="${item}"> ${njtFileManager.capitalizeFirstLetter(item)} </option>`);
246 });
247 jQuery('.njt-text-error').hide()
248 } else {
249 jQuery('.njt-fs-list-user-restrictions').empty()
250 jQuery('.njt-fs-list-user-restrictions').append('<option selected="" disabled="" hidden="">Nothing to choose</option>');
251 jQuery('.njt-text-error').show()
252 }
253 jQuery('.njt-fs-list-user-restrictions').change()
254 if (response.success) {
255 jQuery('.njt-settings-form-submit').removeClass('njt-fs-updating-message');
256 toastr.success('Changes Saved', '', toastr_opt)
257 } else {
258 jQuery('.njt-settings-form-submit').removeClass('njt-fs-updating-message');
259 toastr.error('Please try again later', '', toastr_opt)
260 }
261 });
262 })
263 },
264 ajaxSaveSettingsRestrictions() {
265 jQuery('#njt-form-user-role-restrictionst').on('click', function () {
266 jQuery(this).addClass('njt-fs-updating-message');
267 const njt_fs_list_user_restrictions = jQuery(".njt-fs-list-user-restrictions").val()
268 const list_user_restrictions_alow_access = jQuery("#list_user_restrictions_alow_access").val()
269 const private_folder_access = jQuery("#private_folder_access").val()
270 const private_url_folder_access = jQuery("#private_url_folder_access").val()
271 const hide_paths = jQuery("#hide_paths").val()
272 const lock_files = jQuery("#lock_files").val()
273 const can_upload_mime = jQuery("#can_upload_mime").val()
274
275 const data = {
276 'nonce': wpData.nonce,
277 'action': 'njt_fs_save_setting_restrictions',
278 'njt_fs_list_user_restrictions': njt_fs_list_user_restrictions,
279 'list_user_restrictions_alow_access': list_user_restrictions_alow_access,
280 'private_folder_access': private_folder_access,
281 'private_url_folder_access': private_url_folder_access,
282 'hide_paths': hide_paths,
283 'lock_files': lock_files,
284 'can_upload_mime': can_upload_mime
285 }
286 const toastr_opt = {
287 closeButton: true,
288 showDuration: 300,
289 hideDuration: 200,
290 hideMethod: "fadeOut",
291 positionClass: "toast-top-right njt-fs-toastr"
292 }
293 jQuery.post(
294 wpData.admin_ajax,
295 data,
296 function (response) {
297 if (response.success) {
298 jQuery('#njt-form-user-role-restrictionst').removeClass('njt-fs-updating-message');
299 toastr.success('Changes Saved', '', toastr_opt)
300 } else {
301 jQuery('#njt-form-user-role-restrictionst').removeClass('njt-fs-updating-message');
302 toastr.error('Error! Please try again', '', toastr_opt)
303 }
304 });
305 })
306 },
307 fsConnector() {
308 jQuery('#njt-fs-file-manager').elfinder({
309 url: ajaxurl,
310 handlers : {
311 dblclick : function(event, elfinderInstance) {
312 event.preventDefault();
313 elfinderInstance.exec('getfile')
314 .done(function() {
315 try {
316 elfinderInstance.exec('edit');
317 } catch (e) {
318 elfinderInstance.exec('quicklook');
319 }
320 })
321 .fail(function() { elfinderInstance.exec('open');});
322 }
323 },
324 // disable quicklook
325 // bootCallback : function(fm) {
326 // fm.bind('init', function() {
327 // fm._commands.quicklook.getstate = function() {
328 // return -1;
329 // }
330 // });
331 // },
332 getFileCallback : function(files, fm) {
333 return false;
334 },
335 contextmenu: {
336 // current directory file menu
337 files: ['getfile', '|', 'open', 'opennew', 'download', 'opendir', 'quicklook', 'email', '|', 'upload',
338 'mkdir', '|', 'copy', 'cut', 'paste', 'duplicate', '|', 'rm', 'empty', 'hide', '|', 'rename', 'edit',
339 'resize', '|', 'archive', 'extract', '|', 'selectall', 'selectinvert', '|', 'places', 'info', 'chmod',
340 'netunmount'
341 ],
342 // navbarfolder menu
343 navbar: ['open', 'opennew', 'download', '|', 'upload', 'mkdir', '|', 'copy', 'cut', 'paste', 'duplicate',
344 '|', 'rm', 'empty', 'hide', '|', 'rename', '|', 'archive', '|', 'places', 'info', 'chmod',
345 'netunmount'
346 ],
347 // current directory menu
348 cwd: ['undo', 'redo', '|', 'back', 'up', 'reload', '|', 'upload', 'mkdir', 'mkfile', 'paste', '|',
349 'empty', 'hide', '|', 'view', 'sort', 'selectall', 'colwidth', '|', 'places', 'info', 'chmod',
350 'netunmount',
351 '|', 'fullscreen', '|'
352 ],
353 },
354 uiOptions : {
355 // toolbar configuration
356 toolbar : [
357 ['home', 'back', 'forward', 'up', 'reload'],
358 ['netmount'],
359 ['mkdir', 'mkfile', 'upload'],
360 ['open', 'download', 'getfile'],
361 ['undo', 'redo'],
362 ['copy', 'cut', 'paste', 'rm', 'empty', 'hide'],
363 ['duplicate', 'rename', 'edit', 'resize', 'chmod'],
364 ['selectall', 'selectnone', 'selectinvert'],
365 ['quicklook', 'info'],
366 ['extract', 'archive'],
367 ['search'],
368 ['view', 'sort'],
369 ['preference', 'help'],
370 ['fullscreen']
371 ],
372 toolbarExtra : {
373 defaultHides: [],
374 // show Preference button into contextmenu of the toolbar (true / false)
375 preferenceInContextmenu: false
376 },
377 },
378 ui: ['toolbar', 'tree', 'path', 'stat'],
379 customData: {
380 action: 'fs_connector',
381 nonce: wpData.nonce_connector,
382 },
383 lang: wpData.lang,
384 requestType: 'get',
385 width: 'auto',
386 height: '600',
387 });
388 }
389 }
390
391 jQuery(document).ready(function () {
392 if (jQuery("div").hasClass("njt-fs-file-manager")) {
393
394 //set select value
395 njtFileManager.themeSelector();
396 // Start- Setting for `Select User Roles to access`
397 njtFileManager.actionSettingFormSubmit();
398 // Get value to prop checked for input checkbox
399 njtFileManager.userHasApproved();
400 //Setting tab
401 njtFileManager.activeTabSetting();
402
403 njtFileManager.actionSubmitRoleRestrictionst();
404 // Get value to prop checked for input checkbox
405 njtFileManager.restrictionsHasApproved();
406 //Ajax change value
407 njtFileManager.ajaxRoleRestrictions();
408 //Creat root path default
409 njtFileManager.clickedCreatRootPath();
410 // End- Setting for `Select User Roles Restrictions to access`
411
412 //Ajax settings
413 njtFileManager.ajaxSaveSettings();
414 njtFileManager.ajaxSaveSettingsRestrictions();
415 if(jQuery(".elfinder-theme-ext") > 0) {
416 jQuery(".elfinder-theme-ext").remove()
417 }
418 njtFileManager.fsConnector();
419
420 }
421 });
422