diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py
index bc67a5943..96f61c8b2 100644
--- a/web/pgadmin/misc/file_manager/__init__.py
+++ b/web/pgadmin/misc/file_manager/__init__.py
@@ -677,6 +677,7 @@ class Filemanager(object):
dir = self.dir
err_msg = ''
code = 1
+ name = unquote(name)
try:
orig_path = "{0}{1}".format(dir, path)
newName = '{0}{1}'.format(orig_path, name)
@@ -689,40 +690,7 @@ class Filemanager(object):
result = {
'Path': path,
- 'Name': newName,
- 'Error': err_msg,
- 'Code': code
- }
-
- return result
-
- def create_file(self, path, name, req=None):
- """
- Create new file functionality
- """
- if not self.validate_request('create'):
- return {
- 'Error': gettext('Not allowed'),
- 'Code': 1
- }
-
- dir = self.dir
- err_msg = ''
- code = 1
- try:
- orig_path = "{0}{1}".format(dir, path)
- newName = '{0}{1}'.format(orig_path, name)
- if not os.path.exists(newName):
- open(newName, 'w')
- code = 0
- else:
- err_msg = gettext("Error: File already exists")
- except Exception as e:
- err_msg = "Error: {0}".format(e.strerror)
-
- result = {
- 'Path': path,
- 'Name': newName,
+ 'Name': name,
'Error': err_msg,
'Code': code
}
diff --git a/web/pgadmin/misc/file_manager/static/css/file_manager.css b/web/pgadmin/misc/file_manager/static/css/file_manager.css
index 069d00302..c646f8930 100755
--- a/web/pgadmin/misc/file_manager/static/css/file_manager.css
+++ b/web/pgadmin/misc/file_manager/static/css/file_manager.css
@@ -40,9 +40,12 @@
overflow: auto;
/* no margin or border allowed */
}
+.file_listing #contents.grid li.selected {
+ border: 1px solid #D9EDF7;
+}
-.fileinfo #contents li.selected, .fileinfo #contents tbody tr.selected {
- background: #D9EDF7;
+.file_listing #contents.grid li.selected, .fileinfo #contents tbody tr.selected {
+ background: #D9EDF7 !important;
}
.fileinfo #contents li .fm_file_rename,
@@ -54,6 +57,17 @@
height: 17px;
}
+.fileinfo #contents li p > span.less_text,
+.fileinfo table#contents tr td:first-child p span.less_text {
+ width: 100%;
+ display: inline-block;
+ text-overflow: ellipsis;
+ overflow: hidden;
+ text-align: center;
+ white-space: nowrap;
+ padding: 0 10px;
+}
+
.fileinfo table#contents tr td p {
display: inline-block;
margin-bottom: 0;
@@ -164,13 +178,14 @@ x:-o-prefocus, .file-input-container {top:16px;width:198px;}
display: block;
float: left;
width: 100px;
- min-height: 80px;
+ height: 80px;
text-align: center;
overflow: hidden;
margin-bottom: 10px;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
+ border: 1px solid #fff;
}
div.clip {
@@ -199,12 +214,12 @@ div.clip {
.file_listing #contents.list thead {
background: rgb(244,241,237); /* Old browsers */
- background: -moz-linear-gradient(top, rgba(244,241,237,1) 0%, rgba(214,212,209,1) 100%); /* FF3.6+ */
- background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(244,241,237,1)), color-stop(100%,rgba(214,212,209,1))); /* Chrome,Safari4+ */
- background: -webkit-linear-gradient(top, rgba(244,241,237,1) 0%,rgba(214,212,209,1) 100%); /* Chrome10+,Safari5.1+ */
- background: -o-linear-gradient(top, rgba(244,241,237,1) 0%,rgba(214,212,209,1) 100%); /* Opera 11.10+ */
- background: -ms-linear-gradient(top, rgba(244,241,237,1) 0%,rgba(214,212,209,1) 100%); /* IE10+ */
- background: linear-gradient(to bottom, rgba(244,241,237,1) 0%,rgba(214,212,209,1) 100%); /* W3C */
+ background: -moz-linear-gradient(top, rgba(44, 118, 180, 0.71) 0%, rgba(44, 118, 180, 0.98) 100%); /* FF3.6+ */
+ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(44, 118, 180, 0.71)), color-stop(100%,rgba(44, 118, 180, 0.98))); /* Chrome,Safari4+ */
+ background: -webkit-linear-gradient(top, rgba(44, 118, 180, 0.71) 0%,rgba(44, 118, 180, 0.98) 100%); /* Chrome10+,Safari5.1+ */
+ background: -o-linear-gradient(top, rgba(44, 118, 180, 0.71) 0%,rgba(44, 118, 180, 0.98) 100%); /* Opera 11.10+ */
+ background: -ms-linear-gradient(top, rgba(44, 118, 180, 0.71) 0%,rgba(44, 118, 180, 0.98) 100%); /* IE10+ */
+ background: linear-gradient(to bottom, rgba(44, 118, 180, 0.71) 0%,rgba(44, 118, 180, 0.98) 100%)
border-bottom: 1px solid #ccc;
display: inline-block;
width: 100%;
@@ -213,6 +228,7 @@ div.clip {
.file_listing #contents.list th {
font-weight: bold;
cursor: pointer;
+ color: #fff;
}
.file_listing #contents.list th.tablesorter-headerAsc,
@@ -226,15 +242,11 @@ div.clip {
background: linear-gradient(to bottom, rgba(214,212,209,1) 0%,rgba(244,241,237,1) 100%); /* W3C */
}
-.file_listing #contents.list td {
- border-bottom: 1px dotted #ccc;
-}
-
.file_listing #contents.list td:first-child {
display: table-cell;
padding-left: 0;
width: 100%;
- padding-left: 22px;
+ padding-left: 12px;
background-repeat: no-repeat;
background-position: 3px center;
}
@@ -253,16 +265,15 @@ div.clip {
margin-right: 5px;
}
-.file_listing #contents.list tbody tr:hover {
- background-color: #eee;
- cursor: pointer;
+.file_listing #contents.list tbody tr:nth-child(even):hover {
+ background-color: #f5f5f5 !important;
}
.file_listing #contents.grid li:hover {
border: 1px solid #E5E5E5;
background-color: #F7F7F7;
cursor: pointer;
- max-height: 78px;
+ height: 80px;
}
.meta {
@@ -320,7 +331,8 @@ button.list span {
top: 0;
}
-.btn-group.filemanager-btn-group .btn:not(:first-child):not(:last-child) {
+.btn-group.filemanager-btn-group .btn:not(:first-child):not(:last-child),
+.btn-group.filemanager-path-group .btn:not(:first-child):not(:last-child) {
border-left: 1px solid #A9A9A9;
}
@@ -377,6 +389,14 @@ button.list span {
width: 100%;
}
+.file_manager .fileinfo #contents tbody tr:nth-child(even) {
+ background: #eee;
+}
+
+.file_manager .fileinfo #contents thead tr th:not(:first-child) {
+ border-left: 1px solid #fff;
+}
+
.file_manager .fileinfo #contents thead tr th:nth-child(1),
.file_manager .fileinfo #contents tbody tr td:nth-child(1) {
position: relative;
@@ -389,6 +409,7 @@ button.list span {
width: 152px;
min-width: 152px;
max-width: 152px;
+ padding-left: 10px;
}
.file_manager .fileinfo #contents tbody tr td:nth-child(2) {
@@ -401,12 +422,13 @@ button.list span {
width: 197px;
min-width: 197px;
max-width: 197px;
+ padding-left: 10px;
}
.file_manager .fileinfo #contents tbody tr td:nth-child(3) {
- width: 180px;
- min-width: 180px;
- max-width: 180px;
+ width: 177px;
+ min-width: 177px;
+ max-width: 177px;
}
.file_manager .fileinfo #contents tbody {
@@ -415,10 +437,12 @@ button.list span {
width: 100%;
height: calc(100% - 30px);
}
+
.file_manager .fileinfo #contents tbody tr{
- display: table;
+ /*display: table;*/
max-width: 100%;
width: 100%;
+ cursor: pointer;
}
.file_manager .upload_file {
@@ -457,11 +481,14 @@ button.list span {
}
.file_manager #uploader .btn-group .show_selected_file {
- float: left;
- text-align: left;
vertical-align: middle;
+ text-align: left;
padding: 4px 0 0 5px;
- height: 100%;
+ display: inline-block;
+ overflow: hidden;
+ width: calc(100% - 73px);
+ text-overflow: ellipsis;
+ white-space: nowrap;
}
.fileinfo .file_listing {
@@ -559,6 +586,7 @@ button.list span {
}
.file_upload_main .dz-progress {
+ height: 21px !important;
top: 83px !important;
border: 1px solid #8a6d3b;
border-radius: 0 !important;
@@ -655,7 +683,7 @@ a.dz-remove {
.file_manager .fileinfo #contents .fa-lock.tbl_lock_icon {
color: red;
position: absolute;
- left: 29px;
+ left: 19px;
top: 5px;
font-size: 10px;
}
@@ -676,8 +704,9 @@ a.dz-remove {
.file_listing .no_folder_found {
text-align: center;
position: absolute;
- top: 35;
+ top: 35px;
width: 100%;
+ font-size: 14px;
}
.fileinfo .is_file_replace {
diff --git a/web/pgadmin/misc/file_manager/templates/file_manager/js/file_manager.js b/web/pgadmin/misc/file_manager/templates/file_manager/js/file_manager.js
index bf7171f5f..5ab77c172 100644
--- a/web/pgadmin/misc/file_manager/templates/file_manager/js/file_manager.js
+++ b/web/pgadmin/misc/file_manager/templates/file_manager/js/file_manager.js
@@ -131,7 +131,7 @@ define([
//closeEvent.cancel = true;
}
if (closeEvent.button.text == "{{ _('Select') }}") {
- if($('.fileinfo').data('view') == 'grid'){
+ if($('.fileinfo').data('view') == 'grid') {
sel_file = $('.fileinfo').find('#contents li.selected p span').attr('title');
} else {
sel_file = $('.fileinfo tbody tr.selected td p span').attr('title');
@@ -239,7 +239,7 @@ define([
},
callback: function(closeEvent) {
if (closeEvent.button.text == "{{ _('Select') }}") {
- if($('.fileinfo').data('view') == 'grid'){
+ if($('.fileinfo').data('view') == 'grid') {
sel_file = $('.fileinfo').find('#contents li.selected p span').attr('title');
} else {
sel_file = $('.fileinfo tbody tr.selected td p span').attr('title');
@@ -346,7 +346,7 @@ define([
},
callback: function(closeEvent) {
if (closeEvent.button.text == "{{ _('Select') }}") {
- if($('.fileinfo').data('view') == 'grid'){
+ if($('.fileinfo').data('view') == 'grid') {
sel_file = $('.fileinfo').find('#contents li.selected p span').attr('title');
} else {
sel_file = $('.fileinfo tbody tr.selected td p span').attr('title');
@@ -481,9 +481,9 @@ define([
dataType: 'json',
contentType: "application/x-download; charset=utf-8",
async: false,
- success: function(resp){
+ success: function(resp) {
data = resp.data.result;
- if(data['Code'] === 0){
+ if(data['Code'] === 0) {
is_exist = true;
} else {
is_exist = false;
@@ -492,39 +492,8 @@ define([
});
return is_exist;
},
- create_file: function() {
- var selected_item = $('.allowed_file_types .create_input input[type="text"]').val(),
- is_exist = false,
- is_created = false;
-
- var post_data = {
- 'path': $('.currentpath').val(),
- 'name': selected_item,
- 'mode': 'create_file'
- };
-
- $.ajax({
- type: 'POST',
- data: JSON.stringify(post_data),
- url: fileConnector + trans_id+'/',
- dataType: 'json',
- contentType: "application/x-download; charset=utf-8",
- async: false,
- success: function(resp){
- data = resp.data.result;
- if(data['Code'] === 0){
- alertify.success("New File created successfully.");
- is_created = true;
- } else {
- alertify.error(data['Error']);
- return false;
- }
- }
- });
- return is_created;
- },
callback: function(closeEvent) {
- if (closeEvent.button.text == "{{ _('Create') }}"){
+ if (closeEvent.button.text == "{{ _('Create') }}") {
var selected_item = $('.allowed_file_types .create_input input[type="text"]').val();
var newFile = $('.currentpath').val() + selected_item;
newFile = newFile.substr(1);
@@ -533,17 +502,11 @@ define([
closeEvent.cancel = true;
}
else {
- var is_created = this.create_file();
- if (is_created) {
- pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:create_file', newFile);
- removeTransId(trans_id);
- }
- else {
- closeEvent.cancel = true;
- }
+ pgAdmin.Browser.Events.trigger('pgadmin-storage:finish_btn:create_file', newFile);
+ removeTransId(trans_id);
}
}
- if (closeEvent.button.text == "{{ _('Cancel') }}"){
+ if (closeEvent.button.text == "{{ _('Cancel') }}") {
removeTransId(trans_id);
}
},
diff --git a/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js b/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js
index f0b45ac2b..3dc70bb6f 100755
--- a/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js
+++ b/web/pgadmin/misc/file_manager/templates/file_manager/js/utility.js
@@ -12,106 +12,52 @@
(function($) {
"use strict";
-// User alertify object
-var alertify = require("alertify");
-
+// use alertify and underscore js
+var alertify = require("alertify"),
+ _ = require("underscore");
/*---------------------------------------------------------
Define functions used for various operations
---------------------------------------------------------*/
-// function to retrieve GET params
-$.urlParam = function(name) {
- var results = new RegExp('[\\?&]' + name + '=([^]*)').exec(window.location.href);
- if (results) {
- return results[1];
- } else {
- return 0;
- }
-};
-
+// return file extension
var getFileExtension = function(name) {
- var found = name.lastIndexOf('.') + 1;
- return (found > 0 ? name.substr(found) : "");
+ var found = name.lastIndexOf('.') + 1;
+ return (found > 0 ? name.substr(found) : "");
};
+// returns filename without extension
var getFileName = function(name) {
var fm_filename = name;
if (fm_filename.length > 15 ) {
- fm_filename = name.substr(0, 10) +'...';
+ fm_filename = name.substr(0, 10) +'...';
}
return fm_filename;
};
-// send a request to get transaction id
-var getTransId = function() {
+/* Common function to load:
+ * en.js language file
+ * file_manager_config.js config file
+ * return transaction id
+ */
+var loadData = function(url) {
return $.ajax({
async: false,
- url: "{{ url_for('file_manager.index') }}get_trans_id",
- dataType: "jsonp"
- });
-};
-
-// Load language file
-var loadLangFile = function(enjs) {
- if ($.urlParam('langCode') !== 0 && file_exists (enjs)) {
- culture = $.urlParam('langCode');
- }
- return $.ajax({
- async: false,
- url: enjs,
+ url: url,
dataType: 'jsonp',
contentType: "application/json; charset=utf-8"
});
};
-var userconfig = file_manager_config_json;
-
-// We retrieve config settings from filemanager.config.js
-var loadConfigFile = function (type) {
- type = (typeof type === "undefined") ? "user" : type;
- var url;
- if (type == 'user') {
- url = file_manager_config_json;
- }
- return $.ajax({
- async: false,
- url: url,
- dataType: "jsonp",
- contentType: "application/json; charset=utf-8"
- });
-};
-
-/*
- * Forces columns to fill the layout vertically.
- * Called on initial page load and on resize.
- */
-var setDimensions = function() {
- var main_container_height = ( $(window).height() ) / 2 + 35;
- var newH = main_container_height - $('#uploader').height() - 30;
-};
-
-// Display Min Path
-var displayPath = function(path) {
- if (config.options.showFullPath === false) {
- // if a "displayPathDecorator" function is defined, use it to decorate path
- return 'function' === (typeof displayPathDecorator)
- ? displayPathDecorator(path)
- : path.replace(fileRoot, "/");
- } else {
- return path;
- }
-};
-
-// Set the view buttons state
+// Set enable/disable state of list and grid view
var setViewButtonsFor = function(viewMode) {
- if (viewMode == 'grid') {
- $('.grid').addClass('ON');
- $('.list').removeClass('ON');
- } else {
- $('.list').addClass('ON');
- $('.grid').removeClass('ON');
- }
+ if (viewMode == 'grid') {
+ $('.grid').addClass('ON');
+ $('.list').removeClass('ON');
+ } else {
+ $('.list').addClass('ON');
+ $('.grid').removeClass('ON');
+ }
};
/*
@@ -193,10 +139,7 @@ var formatBytes = function(bytes) {
}
};
-/*
- * Handle Error. Freeze interactive buttons and display
- * error message. Also called when auth() function return false (Code == "-1")
- */
+// Freeze toolbar buttons and display errors
var handleError = function(errMsg) {
$('.storage_dialog .newfile').attr("disabled", "disabled");
$('.storage_dialog .upload').attr("disabled", "disabled");
@@ -207,27 +150,12 @@ var handleError = function(errMsg) {
* Test if Data structure has the 'cap' capability
* 'cap' is one of 'select', 'rename', 'delete', 'download'
*/
-function has_capability(data, cap) {
+var has_capability = function(data, cap) {
if (typeof(data.Capabilities) == "undefined") {
return true;
} else {
return ($.inArray(cap, data.Capabilities) > -1);
}
-}
-
-// Test if file is authorized
-var isAuthorizedFile = function(filename) {
- return ((
- config.security.uploadPolicy == 'DISALLOW_ALL' &&
- $.inArray(
- getExtension(filename), config.security.uploadRestrictions
- ) != -1
- ) || (
- config.security.uploadPolicy == 'ALLOW_ALL' &&
- $.inArray(
- getExtension(filename), config.security.uploadRestrictions
- ) == -1
- ));
};
// return filename extension
@@ -238,7 +166,7 @@ var getExtension = function(filename) {
return filename.split('.').pop();
};
-// return filename without extension {
+// return filename without extension
var getFilename = function(filename) {
if (filename.lastIndexOf('.') != -1) {
return filename.substring(0, filename.lastIndexOf('.'));
@@ -250,7 +178,8 @@ var getFilename = function(filename) {
// helpful in show/hide toolbar button for Windows
var hideButtons = function() {
return (
- config.options.platform_type == 'win32' && $('.currentpath').val() == ''
+ config.options.platform_type == 'win32' &&
+ $('.currentpath').val() === ''
);
};
@@ -265,7 +194,7 @@ var setUploader = function(path) {
path = decodeURI(path);
- var display_string = displayPath(path),
+ var display_string = path,
mypath = '';
// split path
@@ -401,7 +330,7 @@ var setUploader = function(path) {
if (fname != '') {
foldername = cleanString(fname);
var d = new Date(); // to prevent IE cache issues
- $.getJSON(fileConnector + '?mode=addfolder&path=' + $('.currentpath').val() + '&name=' + foldername + '&time=' + d.getMilliseconds(), function(resp) {
+ $.getJSON(fileConnector + '?mode=addfolder&path=' + $('.currentpath').val() + '&name=' + foldername, function(resp) {
var result = resp.data.result;
if (result.Code === 0) {
alertify.success(lg.successful_added_folder);
@@ -423,16 +352,18 @@ var setUploader = function(path) {
* and show/hide buttons
*/
var bindToolbar = function(data) {
- if (!has_capability(data, 'upload') || hideButtons()) {
- $('.file_manager').find('button.upload').hide();
- } else {
- $('.file_manager').find('button.upload').show();
- }
- if (!has_capability(data, 'create') || hideButtons()) {
- $('.file_manager').find('button.create').hide();
- } else {
- $('.file_manager').find('button.create').show();
+ // hide/show rename, upload and create button
+ if(_.has(data, 'Capabilities')) {
+ _.each(data.Capabilities, function(cap) {
+ var target_btn = 'button.' + cap,
+ $target_el = $('.file_manager').find(target_btn);
+ if (!has_capability(data, cap) || hideButtons()) {
+ $target_el.hide();
+ } else {
+ $target_el.show();
+ }
+ });
}
if (!has_capability(data, 'delete') || hideButtons()) {
@@ -484,12 +415,6 @@ var bindToolbar = function(data) {
}
});
}
-
- if (!has_capability(data, 'rename') || hideButtons()) {
- $('.file_manager').find('button.rename').hide();
- } else {
- $('.file_manager').find('button.rename').show();
- }
};
// enable/disable button when files/folder are loaded
@@ -522,26 +447,6 @@ var enable_disable_btn = function() {
$('.file_manager #uploader .show_selected_file').remove();
};
-// switch to folder view
-$('.file_manager .fileinfo').on('click', function(e) {
- enable_disable_btn();
-});
-
-
-// refresh current directory
-$('.file_manager .refresh').on('click', function(e) {
- enable_disable_btn();
- var curr_path = $('.currentpath').val(),
- path = curr_path.substring(
- 0, curr_path.lastIndexOf("/")
- ) + "/";
- getFolderInfo(path);
-});
-
-/*---------------------------------------------------------
- Item Actions
----------------------------------------------------------*/
-
/*
* Rename the current item and returns the new name.
* by double clicking or by clicking the "Rename" button in
@@ -660,12 +565,6 @@ var deleteItem = function(data) {
return isDeleted;
};
-
-// hide message prompt and dimmer if clicked no
-$('.delete_item button.btn_no').on('click', function() {
- $('.delete_item, .fileinfo .fm_dimmer').hide();
-});
-
/*---------------------------------------------------------
Functions to Retrieve File and Folder Details
---------------------------------------------------------*/
@@ -771,12 +670,6 @@ var getFolderInfo = function(path, file_type) {
""
);
- // Retrieve the data and generate the markup.
- var d = new Date(); // to prevent IE cache issues
- if ($.urlParam('type')) {
- url += '&type=' + $.urlParam('type');
- }
-
var post_data = {
'path': path,
'mode': 'getfolder',
@@ -848,7 +741,7 @@ var getFolderInfo = function(path, file_type) {
} else {
result +=
'
' + - '' + fm_filename + + '' + fm_filename + '
'; } if (props.Width && props.Width != '') { @@ -919,7 +812,7 @@ var getFolderInfo = function(path, file_type) { result += '' + fm_filename + ''; } else { - result += '' + fm_filename + '
'; } if (props.Size && props.Size != '') { @@ -994,11 +887,12 @@ var getFolderInfo = function(path, file_type) { 'table#contents tbody tr.selected td:first-child p' ), orig_value = decodeURI($this.find('span').html()), - newvalue = orig_value.substring(0, orig_value.indexOf('.')); + newvalue = orig_value.substring(0, orig_value.lastIndexOf('.')); - if (newvalue === '') { - newvalue = orig_value; + if (orig_value.lastIndexOf('/') == orig_value.length - 1 || newvalue === '') { + newvalue = decodeURI(orig_value); } + $this.find('input').toggle().val(newvalue).focus(); $this.find('span').toggle(); @@ -1116,14 +1010,13 @@ var getFolderInfo = function(path, file_type) { $('.fileinfo table#contents tr td p').on('dblclick', function(e) { e.stopPropagation(); - // Prompt to rename file/folder var $this = $(this), orig_value = decodeURI( $this.find('span').attr('title') - ), - newvalue = orig_value.substring(0, orig_value.indexOf('.')); + ); - if (newvalue === '') { + var newvalue = orig_value.substring(0, orig_value.lastIndexOf('.')); + if (orig_value.lastIndexOf('/') == orig_value.length - 1 || newvalue === '') { newvalue = orig_value; } @@ -1181,6 +1074,7 @@ var getFolderInfo = function(path, file_type) { }); var data_cap = {}; + data_cap.Capabilities = capabilities; /* * Bind click events * Select items - afolder dblclick @@ -1212,7 +1106,6 @@ var getFolderInfo = function(path, file_type) { } }); - data_cap.Capabilities = capabilities; $('.fileinfo').find('#contents li').click(function(e) { e.stopPropagation(); var path = decodeURI($(this).find('.clip span').attr('data-alt')), @@ -1243,7 +1136,6 @@ var getFolderInfo = function(path, file_type) { '.file_manager #uploader .filemanager-path-group' ); } - //getFolderInfo(path); } else { if ( has_capability(data_cap, 'select_file') && @@ -1291,12 +1183,14 @@ var getFolderInfo = function(path, file_type) { $('.file_manager_ok').removeClass('disabled'); $('.file_manager button.download').attr('disabled', 'disabled'); $('.file_manager button.delete, .file_manager button.rename').removeAttr('disabled'); + // set selected folder name in breadcrums $('.file_manager #uploader h1').hide(); $('.file_manager #uploader .show_selected_file').remove(); - $(''+path+'').appendTo('.file_manager #uploader .filemanager-path-group'); + $(''+path+'').appendTo( + '.file_manager #uploader .filemanager-path-group' + ); } - //getFolderInfo(path); } else { if (has_capability(data_cap, 'select_file') && is_protected == undefined) { $(this).parent().find('tr.selected').removeClass('selected'); @@ -1348,7 +1242,6 @@ var getFolderInfo = function(path, file_type) { // Enable/Disable level up button var enab_dis_level_up = function() { - $('.file_manager #uploader h1').show(); $('.show_selected_file').remove(); @@ -1367,11 +1260,16 @@ var enab_dis_level_up = function() { }, 100); }; -// Get transaction id to generate request url and -// to generate config files on runtime -var transId = getTransId(), - t_id = '', - t_res; +/*--------------------------------------------------------- + Initialization - Entry point +---------------------------------------------------------*/ +/* + * get transaction id to generate request url and + * to generate config files on runtime + */ +var fm_url = "{{ url_for('file_manager.index') }}get_trans_id", + transId = loadData(fm_url), + t_id = ''; if (transId.readyState == 4) { t_res = JSON.parse(transId.responseText); @@ -1382,7 +1280,7 @@ var root_url = '{{ url_for("file_manager.index") }}', file_manager_config_json = root_url+t_id+'/file_manager_config.json', file_manager_config_js = root_url+'file_manager_config.js', fileConnector = root_url+'filemanager/'+t_id+'/', - cfg = loadConfigFile(), + cfg = loadData(file_manager_config_json), config; // load user configuration file @@ -1390,6 +1288,7 @@ if (cfg.readyState == 4) { config = JSON.parse(cfg.responseText); } +// set main url to filemanager and its capabilites var fileRoot = config.options.fileRoot, capabilities = config.options.capabilities; @@ -1399,16 +1298,13 @@ var fileRoot = config.options.fileRoot, */ var lg = [], enjs = '{{ url_for("file_manager.index") }}' + "en.js", - lgf = loadLangFile(enjs); + lgf = loadData(enjs); if (lgf.readyState == 4) { lg = JSON.parse(lgf.responseText); } -// Disable home button on load -$('.file_manager').find('button.home').attr('disabled', 'disabled'); -$('.file_manager').find('button.rename').attr('disabled', 'disabled'); - +// create and enable user to create new file if ( config.options.dialog_type == 'select_file' || config.options.dialog_type == 'create_file' || @@ -1436,14 +1332,14 @@ if ( have_all_types = (have_all_types || (t == '*')); } else { select_box += '"; + (t == '*' ? '{{ _("All Files") }}' : t) + ""; have_all_types = (have_all_types || (t == '*')); } i++; } if (!have_all_types) { - select_box += ''; + select_box += ''; } select_box += ""; } @@ -1464,7 +1360,6 @@ if (config.options.dialog_type == 'create_file') { ''; $('.create_mode_dlg').find('.allowed_file_types').prepend(create_file_html); - $('.create_input input[type="text"]').on('keypress, keydown', function() { var input_text_len = $(this).val().length; if (input_text_len > 0 ) { @@ -1474,258 +1369,218 @@ if (config.options.dialog_type == 'create_file') { } }); } + /*--------------------------------------------------------- - Initialization + Item Actions - Object events ---------------------------------------------------------*/ -$(function() { - var expandedFolder = ''; - - if (config.extra_js) { - for(var i=0; i< config.extra_js.length; i++) { - $.ajax({ - url: config.extra_js[i], - dataType: "script", - async: extra_js_async - }); - } - } - - if ($.urlParam('expandedFolder') != 0) { - expandedFolder = $.urlParam('expandedFolder'); - } - - // Adjust layout. - setDimensions(); - - // we finalize the FileManager UI initialization - // with localized text if necessary - if (config.autoload == true) { - $('.upload').append(lg.upload); - $('.create').append(lg.new_folder); - $('.grid').attr('title', lg.grid_view); - $('.list').attr('title', lg.list_view); - $('.fileinfo h1').append(lg.select_from_left); - $('#itemOptions a[href$="#select"]').append(lg.select); - $('#itemOptions a[href$=".download"]').append(lg.download); - $('#itemOptions a[href$=".rename"]').append(lg.rename); - $('#itemOptions a[href$=".delete"]').append(lg.del); - /** Input file Replacement */ - $('.browse').append('+'); - - $('.browse').attr('title', lg.browse); - - $(".newfile").change(function() { - $(".filepath").val($(this).val()); - }); - /** Input file Replacement - end */ - } - - // stop click event on dimmer click - $('.fileinfo .fm_dimmer').on('click', function(e) { - e.stopPropagation(); - }); - - $('.fileinfo .replace_file').not( - $(this).find('span.pull-right') - ).on( - 'click', function(e) { - $('#uploader .filemanager-btn-group').unbind().on( - 'click', function() { - $('.fileinfo .delete_item, .fileinfo .replace_file, .fileinfo .fm_dimmer').hide(); - }); - e.stopPropagation(); - }); - - // Set initial view state. - $('.fileinfo').data('view', config.options.defaultViewMode); - setViewButtonsFor(config.options.defaultViewMode); - - // Upload click event - $('.file_manager .uploader').on('click', 'a', function(e) { - e.preventDefault(); - var b = $('.currentpath').val(); - var node_val = $(this).next().text(); - parent = b.substring(0, b.slice(0, -1).lastIndexOf(node_val)); - getFolderInfo(parent); - }); - - // re-render the home view - $('.file_manager .home').click(function() { - var currentViewMode = $('.fileinfo').data('view'); - $('.fileinfo').data('view', currentViewMode); - getFolderInfo(fileRoot); - enab_dis_level_up(); - }); - - // Go one directory back - $(".file_manager .level-up").click(function() { - var b = $('.currentpath').val(); - - // Enable/Disable level up button - enab_dis_level_up(); - - if (b != fileRoot) { - parent = b.substring(0, b.slice(0, -1).lastIndexOf("/")) + "/"; - var d = $(".fileinfo").data("view"); - $(".fileinfo").data("view", d); - getFolderInfo(parent); - } - }); - - // set buttons to switch between grid and list views. - $('.file_manager .grid').click(function() { - setViewButtonsFor('grid'); - $('.fileinfo').data('view', 'grid'); - enable_disable_btn(); - getFolderInfo($('.currentpath').val()); - }); - - // Show list mode - $('.file_manager .list').click(function() { - setViewButtonsFor('list'); - $('.fileinfo').data('view', 'list'); - enable_disable_btn(); - getFolderInfo($('.currentpath').val()); - }); - - // Provide initial values for upload form, status, etc. - setUploader(fileRoot); - - $('#uploader').attr('action', fileConnector); - - var data = { - 'Capabilities': capabilities - }; - - if (has_capability(data, 'upload')) { - Dropzone.autoDiscover = false; - // we remove simple file upload element - $('.file-input-container').remove(); - $('.upload').remove(); - $( ".create" ).before( ' ' ); - - $('.upload').unbind().click(function() { - // we create prompt - var msg = '