misc_pterodactyl-panel/public/themes/pterodactyl/js/frontend/files/filemanager.min.js

5 lines
23 KiB
JavaScript
Raw Normal View History

2018-05-26 18:41:46 +00:00
'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var ActionsClass=function(){function ActionsClass(element,menu){_classCallCheck(this,ActionsClass);this.element=element;this.menu=menu}_createClass(ActionsClass,[{key:'destroy',value:function destroy(){this.element=undefined}},{key:'folder',value:function folder(path){var inputValue=void 0;if(path){inputValue=path}else{var nameBlock=$(this.element).find('td[data-identifier="name"]');var currentName=decodeURIComponent(nameBlock.data('name'));var currentPath=decodeURIComponent(nameBlock.data('path'));if($(this.element).data('type')==='file'){inputValue=currentPath}else{inputValue=''+currentPath+currentName+'/'}}swal({type:'input',title:'Create Folder',text:'Please enter the path and folder name below.',showCancelButton:true,showConfirmButton:true,closeOnConfirm:false,showLoaderOnConfirm:true,inputValue:inputValue},function(val){$.ajax({type:'POST',headers:{'X-Access-Token':Pterodactyl.server.daemonSecret,'X-Access-Server':Pterodactyl.server.uuid},contentType:'application/json; charset=utf-8',url:Pterodactyl.node.scheme+'://'+Pterodactyl.node.fqdn+':'+Pterodactyl.node.daemonListen+'/v1/server/file/folder',timeout:10000,data:JSON.stringify({path:val})}).done(function(data){swal.close();Files.list()}).fail(function(jqXHR){console.error(jqXHR);var error='An error occurred while trying to process this request.';if(typeof jqXHR.responseJSON!=='undefined'&&typeof jqXHR.responseJSON.error!=='undefined'){error=jqXHR.responseJSON.error}swal({type:'error',title:'',text:error})})})}},{key:'move',value:function move(){var nameBlock=$(this.element).find('td[data-identifier="name"]');var currentName=decodeURIComponent(nameBlock.attr('data-name'));var currentPath=decodeURIComponent(nameBlock.data('path'));swal({type:'input',title:'Move File',text:'Please enter the new path for the file below.',showCancelButton:true,showConfirmButton:true,closeOnConfirm:false,showLoaderOnConfirm:true,inputValue:''+currentPath+currentName},function(val){$.ajax({type:'POST',headers:{'X-Access-Token':Pterodactyl.server.daemonSecret,'X-Access-Server':Pterodactyl.server.uuid},contentType:'application/json; charset=utf-8',url:Pterodactyl.node.scheme+'://'+Pterodactyl.node.fqdn+':'+Pterodactyl.node.daemonListen+'/v1/server/file/move',timeout:10000,data:JSON.stringify({from:''+currentPath+currentName,to:''+val})}).done(function(data){nameBlock.parent().addClass('warning').delay(200).fadeOut();swal.close()}).fail(function(jqXHR){console.error(jqXHR);var error='An error occurred while trying to process this request.';if(typeof jqXHR.responseJSON!=='undefined'&&typeof jqXHR.responseJSON.error!=='undefined'){error=jqXHR.responseJSON.error}swal({type:'error',title:'',text:error})})})}},{key:'rename',value:function rename(){var nameBlock=$(this.element).find('td[data-identifier="name"]');var currentLink=nameBlock.find('a');var currentName=decodeURIComponent(nameBlock.attr('data-name'));var attachEditor='\n <input class="form-control input-sm" type="text" value="'+currentName+'" />\n <span class="input-loader"><i class="fa fa-refresh fa-spin fa-fw"></i></span>\n ';nameBlock.html(attachEditor);var inputField=nameBlock.find('input');var inputLoader=nameBlock.find('.input-loader');inputField.focus();inputField.on('blur keydown',function(e){if(e.type==='keydown'&&e.which===27||e.type==='blur'||e.type==='keydown'&&e.which===13&&currentName===inputField.val()){if(!_.isEmpty(currentLink)){nameBloc
2017-03-17 20:20:27 +00:00
'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var ContextMenuClass=function(){function ContextMenuClass(){_classCallCheck(this,ContextMenuClass);this.activeLine=null}_createClass(ContextMenuClass,[{key:'run',value:function run(){this.directoryClick();this.rightClick()}},{key:'makeMenu',value:function makeMenu(parent){$(document).find('#fileOptionMenu').remove();if(!_.isNull(this.activeLine))this.activeLine.removeClass('active');var newFilePath=$('#file_listing').data('current-dir');if(parent.data('type')==='folder'){var nameBlock=parent.find('td[data-identifier="name"]');var currentName=decodeURIComponent(nameBlock.attr('data-name'));var currentPath=decodeURIComponent(nameBlock.data('path'));newFilePath=''+currentPath+currentName}var buildMenu='<ul id="fileOptionMenu" class="dropdown-menu" role="menu" style="display:none" >';if(Pterodactyl.permissions.moveFiles){buildMenu+='<li data-action="rename"><a tabindex="-1" href="#"><i class="fa fa-fw fa-pencil-square-o"></i> Rename</a></li> <li data-action="move"><a tabindex="-1" href="#"><i class="fa fa-fw fa-arrow-right"></i> Move</a></li>'}if(Pterodactyl.permissions.copyFiles){buildMenu+='<li data-action="copy"><a tabindex="-1" href="#"><i class="fa fa-fw fa-clone"></i> Copy</a></li>'}if(Pterodactyl.permissions.compressFiles){buildMenu+='<li data-action="compress" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-fw fa-file-archive-o"></i> Compress</a></li>'}if(Pterodactyl.permissions.decompressFiles){buildMenu+='<li data-action="decompress" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-fw fa-expand"></i> Decompress</a></li>'}if(Pterodactyl.permissions.createFiles){buildMenu+='<li class="divider"></li> <li data-action="file"><a href="/server/'+Pterodactyl.server.uuidShort+'/files/add/?dir='+newFilePath+'" class="text-muted"><i class="fa fa-fw fa-plus"></i> New File</a></li> <li data-action="folder"><a tabindex="-1" href="#"><i class="fa fa-fw fa-folder"></i> New Folder</a></li>'}if(Pterodactyl.permissions.downloadFiles||Pterodactyl.permissions.deleteFiles){buildMenu+='<li class="divider"></li>'}if(Pterodactyl.permissions.downloadFiles){buildMenu+='<li data-action="download" class="hidden"><a tabindex="-1" href="#"><i class="fa fa-fw fa-download"></i> Download</a></li>'}if(Pterodactyl.permissions.deleteFiles){buildMenu+='<li data-action="delete" class="bg-danger"><a tabindex="-1" href="#"><i class="fa fa-fw fa-trash-o"></i> Delete</a></li>'}buildMenu+='</ul>';return buildMenu}},{key:'rightClick',value:function rightClick(){var _this=this;$('[data-action="toggleMenu"]').on('mousedown',function(event){event.preventDefault();if($(document).find('#fileOptionMenu').is(':visible')){$('body').trigger('click');return}_this.showMenu(event)});$('#file_listing > tbody td').on('contextmenu',function(event){_this.showMenu(event)})}},{key:'showMenu',value:function showMenu(event){var _this2=this;var parent=$(event.target).closest('tr');var menu=$(this.makeMenu(parent));if(parent.data('type')==='disabled')return;event.preventDefault();$(menu).appendTo('body');$(menu).data('invokedOn',$(event.target)).show().css({position:'absolute',left:event.pageX-150,top:event.pageY});this.activeLine=parent;this.activeLine.addClass('active');var Actions=new ActionsClass(parent,menu);if(Pterodactyl.permissions.moveFiles){$(menu).find('li[data-action="move"]').unbind().on('click',function(e){e.preventDefaul
2018-05-26 18:41:46 +00:00
'use strict';var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol&&obj!==Symbol.prototype?'symbol':typeof obj};var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var FileManager=function(){function FileManager(){_classCallCheck(this,FileManager);this.list(this.decodeHash())}_createClass(FileManager,[{key:'list',value:function list(path,next){var _this=this;if(_.isUndefined(path)){path=this.decodeHash()}this.loader(true);$.ajax({type:'POST',url:Pterodactyl.meta.directoryList,headers:{'X-CSRF-Token':Pterodactyl.meta.csrftoken},data:{directory:path}}).done(function(data){_this.loader(false);$('#load_files').slideUp(10).html(data).slideDown(10,function(){ContextMenu.run();_this.reloadFilesButton();_this.addFolderButton();_this.selectItem();_this.selectAll();_this.selectiveDeletion();_this.selectRow();if(_.isFunction(next)){return next()}});$('#internal_alert').slideUp();if((typeof Siofu==='undefined'?'undefined':_typeof(Siofu))==='object'){Siofu.listenOnInput(document.getElementById('files_touch_target'))}}).fail(function(jqXHR){_this.loader(false);if(_.isFunction(next)){return next(new Error('Failed to load file listing.'))}if(path!==''&&path!=='/'&&jqXHR.status===404){return _this.list('',next)}swal({type:'error',title:'File Error',text:jqXHR.responseJSON.errors[0].detail||'An error occurred while attempting to process this request. Please try again.'});console.error(jqXHR)})}},{key:'loader',value:function loader(show){if(show){$('.file-overlay').fadeIn(100)}else{$('.file-overlay').fadeOut(100)}}},{key:'reloadFilesButton',value:function reloadFilesButton(){var _this2=this;$('i[data-action="reload-files"]').unbind().on('click',function(){$('i[data-action="reload-files"]').addClass('fa-spin');_this2.list()})}},{key:'selectItem',value:function selectItem(){$('[data-action="addSelection"]').on('click',function(event){event.preventDefault()})}},{key:'selectAll',value:function selectAll(){$('[data-action="selectAll"]').on('click',function(event){event.preventDefault()})}},{key:'selectiveDeletion',value:function selectiveDeletion(){$('[data-action="selective-deletion"]').on('mousedown',function(event){new ActionsClass().deleteSelected()})}},{key:'addFolderButton',value:function addFolderButton(){$('[data-action="add-folder"]').unbind().on('click',function(){new ActionsClass().folder($('#file_listing').data('current-dir')||'/')})}},{key:'selectRow',value:function selectRow(){$('#file_listing tr').on('mousedown',function(event){if(event.which===1){if($(event.target).is('th')||$(event.target).is('input[data-action="selectAll"]')){new ActionsClass().highlightAll(event)}else if($(event.target).is('td')||$(event.target).is('input[data-action="addSelection"]')){new ActionsClass().toggleHighlight(event)}new ActionsClass().toggleMassActions()}})}},{key:'decodeHash',value:function decodeHash(){return decodeURIComponent(window.location.hash.substring(1))}}]);return FileManager}();window.Files=new FileManager;
2017-01-19 21:58:57 +00:00
//# sourceMappingURL=filemanager.min.js.map