From 6e193e08526848282170bca3849172a2b9d2ba17 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Fri, 18 Sep 2015 17:45:03 +0300 Subject: [PATCH] FM updates --- web/file_manager/fm_core.php | 6 +- web/js/file_manager.js | 115 ++++++++++++++++++++++------------- web/js/i18n.js.php | 26 ++++++++ web/js/templates.js | 52 ++++++++-------- web/upload/UploadHandler.php | 13 ++-- 5 files changed, 135 insertions(+), 77 deletions(-) diff --git a/web/file_manager/fm_core.php b/web/file_manager/fm_core.php index 5a9e39b7d..fb827d481 100644 --- a/web/file_manager/fm_core.php +++ b/web/file_manager/fm_core.php @@ -45,13 +45,13 @@ class FileManager { public function checkFileType($dir) { $dir = $this->formatFullPath($dir); - exec(VESTA_CMD . "v-delete-fs-file {$this->user} {$dir}", $output, $return_var); + exec(VESTA_CMD . "v-get-fs-file-type {$this->user} {$dir}", $output, $return_var); $error = self::check_return_code($return_var, $output); - if (empty($error)) { return array( - 'result' => true + 'result' => true, + 'data' => implode('', $output) ); } else { diff --git a/web/js/file_manager.js b/web/js/file_manager.js index 263902740..2702b92d2 100644 --- a/web/js/file_manager.js +++ b/web/js/file_manager.js @@ -46,11 +46,37 @@ FM.EDITABLE_FILETYPES = [ 'txt', 'php', 'js', 'html' ]; +FM.EDITABLE_MIMETYPES = [ + 'application/emma+xml', + 'application/epp+xml', + 'application/javascript', + 'application/json', + 'application/jsonml+json ', + 'application/lost+xml', + 'application/marc', + 'application/msword', + 'application/sru+xml', + 'application/vnd.android.package-archive', + 'text/csv', + 'text/css', + 'text/javascript', + 'text/html', + 'text/x-java-source' +]; + +FM.EDITABLE_MIMETYPES_MASKS = [ + /(.)*text(.)*/, + /(.)*inode(.)*/ +]; + FM.preselectedItems = {'A': [], 'B': []}; FM.directoryNotAvailable = function(reply) { - alert('Directory not available'); // todo: translate + var tpl = Tpl.get('popup_alert', 'FM'); + tpl.set(':TEXT', App.Constants.FM_DIRECTORY_NOT_AVAILABLE); + + FM.popupOpen(tpl.finalize()); } FM.showError = function(type, message) { @@ -382,7 +408,8 @@ FM.sortItems = function(items, box) { return sorted; } -FM.isFileEditable = function(src) { +FM.isFileEditable = function(src, mime) { + if ('undefined' == typeof src.filetype) { return false; } @@ -391,7 +418,21 @@ FM.isFileEditable = function(src) { return true; } - return false; + var mime_type = mime.split(';'); + mime_type = mime_type[0]; + + if ($.inArray(mime_type, FM.EDITABLE_MIMETYPES) != -1) { + return true; + } + + var editable = false; + $.each(FM.EDITABLE_MIMETYPES_MASKS, function(i, mask) { + if (mime_type.search(mask) != -1) { + editable = true; + } + }); + + return editable; } FM.editFileFromSubcontext = function(elm) { @@ -414,26 +455,36 @@ FM.openFile = function(dir, box, elm) { var tab = FM.getTabLetter(box); FM['TAB_'+tab+'_CURRENT_PATH'] = dir; - - - + var elm = $(elm).hasClass('dir') ? $(elm) : $(elm).closest('.dir'); var src = $.parseJSON($(elm).find('.source').val()); - + if (FM.isItemPseudo(src)) { - FM.open(FM['TAB_' + tab + '_CURRENT_PATH'], FM['TAB_' + tab]); - } - - if (FM.isFileEditable(src)) { - var myWindow = window.open('/edit/file/?path=' + src.full_path, '_blank');//, src.full_path, "width=900, height=700"); - } - else { - var path = src.full_path; - var win = window.open('/download/file/?path=' + path, '_blank'); - win.focus(); + return FM.open(FM['TAB_' + tab + '_CURRENT_PATH'], FM['TAB_' + tab]); } + var params = { + dir: src.full_path + }; + App.Ajax.request('check_file_type', params, function(reply) { + if (reply.result) { + if (FM.isFileEditable(src, reply.data)) { + var myWindow = window.open('/edit/file/?path=' + src.full_path, '_blank');//, src.full_path, "width=900, height=700"); + } + else { + var path = src.full_path; + var win = window.open('/download/file/?path=' + path, '_blank'); + //win.focus(); + } + } + else { + // force download file + var path = src.full_path; + var win = window.open('/download/file/?path=' + path, '_blank'); + //win.focus(); + } + }); } FM.getTabLetter = function(box) { @@ -551,7 +602,6 @@ FM.generate_listing = function(reply, box) { FM.toggleCheck = function(uid) { var ref = $('#check' + uid); if (ref.length > 0) { - //ref.attr('checked', true); $(ref).hasClass('checkbox-selected') ? $(ref).addClass('checkbox-selected') : $(ref).removeClass('checkbox-selected'); } } @@ -605,7 +655,7 @@ FM.checkBulkStatus = function(bulkStatuses, acc) { } if (status == true) { - $('#popup .results').html('Done'); + $('#popup .results').html(App.Constants.FM_DONE); $('.controls p').replaceWith('

close

'); } else { @@ -665,7 +715,7 @@ FM.bulkCopy = function() { }); var tpl = Tpl.get('popup_bulk', 'FM'); - tpl.set(':ACTION', 'YOU ARE COPYING'); + tpl.set(':ACTION', App.Constants.FM_YOU_ARE_COPYING); tpl.set(':TEXT', cfr_html); FM.popupOpen(tpl.finalize()); @@ -740,7 +790,7 @@ FM.bulkRemove = function() { }); var tpl = Tpl.get('popup_bulk', 'FM'); - tpl.set(':ACTION', 'YOU ARE REMOVING'); + tpl.set(':ACTION', App.Constants.FM_YOU_ARE_REMOVING); tpl.set(':TEXT', cfr_html); FM.popupOpen(tpl.finalize()); @@ -750,10 +800,7 @@ FM.bulkRemove = function() { var ref = $(o); var src = $(ref).find('.source').val(); src = $.parseJSON(src); - - /*if (!FM.isItemPseudo(o)) { - cfr_html += '
'+src.name+'
'; - }*/ + var tab = FM.getTabLetter(FM.CURRENT_TAB); var opposite_tab = 'A'; @@ -1610,22 +1657,6 @@ FM.init(); $(document).ready(function() { $('.progress-container').hide(); - //return alert('statechange: Back'); - /*$(document).bind('keydown.up', function() { - console.log(1); - //try{FM.goUp();}catch(e){console.log(e);} - //console.log(FM); - FM.goUp(); - }); - - $(document).bind('keydown.down', function() { - console.log(1); - //try{FM.goUp();}catch(e){console.log(e);} - //console.log(FM); - FM.goDown(); - });*/ - - var ph = $('.window .pwd').outerHeight(); var mh = $('.window .menu').outerHeight(); var wh = $(window).outerHeight(); @@ -1825,5 +1856,5 @@ $(document).ready(function() { $(window).bind('statechange', function(evt){ $(evt).stopPropagation(); // History.getState() - alert('No way back yet'); + //alert('No way back yet'); }) diff --git a/web/js/i18n.js.php b/web/js/i18n.js.php index dcf372709..500b98f0c 100644 --- a/web/js/i18n.js.php +++ b/web/js/i18n.js.php @@ -53,3 +53,29 @@ App.Constants.FM_NO_FILE_SELECTED = ''; App.Constants.FM_FILE_TYPE_NOT_SUPPORTED = ''; +App.Constants.FM_DIRECTORY_NOT_AVAILABLE = ''; +App.Constants.FM_DONE = ''; +App.Constants.FM_CLOSE = ''; +App.Constants.FM_COPY = ''; +App.Constants.FM_CANCEL = ''; +App.Constants.FM_RENAME = ''; +App.Constants.FM_DELETE = ''; +App.Constants.FM_EXTRACT = ''; +App.Constants.FM_CREATE = ''; +App.Constants.FM_PACK = ''; +App.Constants.FM_OK = ''; +App.Constants.FM_YOU_ARE_COPYING = ''; +App.Constants.FM_YOU_ARE_REMOVING = ''; + +App.Constants.FM_CONFIRM_COPY = ''; +App.Constants.FM_CONFIRM_DELETE = ''; +App.Constants.FM_INTO_KEYWORD = ''; +App.Constants.FM_EXISTING_FILES_WILL_BE_DELETED = ''; +App.Constants.FM_ORIGINAL_NAME = ''; +App.Constants.FM_FILE = ''; +App.Constants.FM_ALREADY_EXISTS = ''; +App.Constants.FM_EXTRACT = ''; +App.Constants.FM_CREATE_FILE = ''; + + + diff --git a/web/js/templates.js b/web/js/templates.js index 0b97136f5..dd33f790e 100644 --- a/web/js/templates.js +++ b/web/js/templates.js @@ -38,47 +38,47 @@ App.Templates.html = {
~!:ACTION~!:
~!:TEXT~!
\
\
\ - \ + \

\
\ '], popup_delete: [''], popup_copy: [''], popup_rename: ['
\ -
Original name: "~!:FILENAME~!"
\ - \ +
'+App.Constants.FM_ORIGINAL_NAME+': "~!:FILENAME~!"
\ + \
\
\ \
\
\ -

cancel

\ -

rename

\ +

'+App.Constants.FM_CANCEL+'

\ +

'+App.Constants.FM_RENAME+'

\
\
\ -

cancel

\ -

rename

\ +

'+App.Constants.FM_CANCEL+'

\ +

'+App.Constants.FM_Rename+'

\
\
'], popup_pack: ['
\ -
Pack "~!:FILENAME~!" into:
\ +
'+App.Constants.FM_PACK+' "~!:FILENAME~!" '+App.Constants.FM_INTO_KEYWORD+':
\
\ \
\ @@ -87,13 +87,13 @@ App.Templates.html = { \
\
\ -

cancel

\ -

Pack

\ +

'+App.Constants.FM_CANCEL+'

\ +

'+App.Constants.FM_PACK+'

\
\ '], popup_unpack: ['
\ -
Extract archive "~!:FILENAME~!" to:
\ +
'+App.Constants.FM_EXTRACT+' "~!:FILENAME~!" '+App.Constants.FM_INTO_KEYWORD+':
\
\ \
\ @@ -102,22 +102,22 @@ App.Templates.html = { \
\
\ -

cancel

\ -

Extract

\ +

'+App.Constants.FM_CANCEL+'

\ +

'+App.Constants.FM_EXTRACT+'

\
\ '], popup_create_file: ['
\ -
Create file
\ +
'+App.Constants.FM_CREATE_FILE+'
\ \
\
\ \
\
\ -

cancel

\ -

create

\ +

'+App.Constants.FM_CANCEL+'

\ +

'+App.Constants.FM_CREATE+'

\
\
'], popup_create_dir: ['
\ @@ -128,14 +128,14 @@ App.Templates.html = { \
\
\ -

cancel

\ -

create

\ +

'+App.Constants.FM_CANCEL+'

\ +

'+App.Constants.FM_CREATE+'

\
\ '], popup_no_file_selected: ['
\
Please select a file
\
\ -

ok

\ +

'+App.Constants.FM_OK+'

\
\
'] } diff --git a/web/upload/UploadHandler.php b/web/upload/UploadHandler.php index fa7947654..1f170eca2 100755 --- a/web/upload/UploadHandler.php +++ b/web/upload/UploadHandler.php @@ -210,7 +210,7 @@ class UploadHandler protected function get_upload_path($file_name = null, $version = null) { $relocate_directory = $_GET['dir']; if (empty($relocate_directory)) { - $relocate_directory = '/home/admin/'; + $relocate_directory = '/home/admin/'; // fallback dir } if ($relocate_directory[strlen($relocate_directory) -1] != '/') { $relocate_directory .= '/'; @@ -1041,7 +1041,7 @@ class UploadHandler } protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, - $index = null, $content_range = null) { + $index = null, $content_range = null) { $file = new \stdClass(); $file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error, $index, $content_range); @@ -1076,12 +1076,13 @@ class UploadHandler ); } $file_size = $this->get_file_size($file_path, $append_file); - //var_dump($file_size);die(); + if ($file_size === $file->size) { $file->url = $this->get_download_url($file->name); - if ($this->is_valid_image_file($file_path)) { - $this->handle_image_file($file_path, $file); - } + // uncomment if images also need to be resized + //if ($this->is_valid_image_file($file_path)) { + // $this->handle_image_file($file_path, $file); + //} } else { $file->size = $file_size; if (!$content_range && $this->options['discard_aborted_uploads']) {