misc_pterodactyl-panel/public/js/filemanager.min.js

5 lines
18 KiB
JavaScript
Raw Normal View History

'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(){var nameBlock=$(this.element).find('td[data-identifier="name"]');var currentName=decodeURIComponent(nameBlock.attr('data-name'));var currentPath=decodeURIComponent(nameBlock.data('path'));var inputValue=''+currentPath+currentName+'/';if($(this.element).data('type')==='file'){inputValue=currentPath}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+'/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 occured 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+'/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 occured 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)){nameBlock.html(currentLink)}else{nameBlock.html(currentName)}inputFie
'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=$('#headerTableRow').attr('data-currentDir');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.preventDefault();_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.preventDefault();Actions.move()});$(menu).find('li[data-action="rename"]').unbind().on('click',functi
'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 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().html(data).slideDown(100,function(){ContextMenu.run();_this.reloadFilesButton();if(_.isFunction(next)){return next()}});$('#internal_alert').slideUp()}).fail(function(jqXHR){_this.loader(false);if(_.isFunction(next)){return next(new Error('Failed to load file listing.'))}swal({type:'error',title:'File Error',text:'An error occured while attempting to process this request. Please try again.'});console.log(jqXHR)})}},{key:'loader',value:function loader(show){if($('#load_files').height()<5)return;if(show===true){var height=$('#load_files').height();var width=$('.ajax_loading_box').width();var center_height=height/2-30;var center_width=width/2-30;$('#position_me').css({'top':center_height,'left':center_width,'font-size':'60px'});$('.ajax_loading_box').css('height',height+5).show()}else{$('.ajax_loading_box').hide()}}},{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:'decodeHash',value:function decodeHash(){return decodeURIComponent(window.location.hash.substring(1))}}]);return FileManager}();window.Files=new FileManager;
//# sourceMappingURL=filemanager.min.js.map