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 d55dbe08e..da5d7ef94 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
@@ -54,7 +54,7 @@ var getTransId = function() {
// Load language file
var loadLangFile = function(enjs) {
- if($.urlParam('langCode') !== 0 && file_exists (enjs)) {
+ if ($.urlParam('langCode') !== 0 && file_exists (enjs)) {
culture = $.urlParam('langCode');
}
return $.ajax({
@@ -70,6 +70,7 @@ 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;
}
@@ -92,7 +93,7 @@ var setDimensions = function() {
// Display Min Path
var displayPath = function(path) {
- if(config.options.showFullPath === false) {
+ if (config.options.showFullPath === false) {
// if a "displayPathDecorator" function is defined, use it to decorate path
return 'function' === (typeof displayPathDecorator)
? displayPathDecorator(path)
@@ -107,8 +108,7 @@ var setViewButtonsFor = function(viewMode) {
if (viewMode == 'grid') {
$('.grid').addClass('ON');
$('.list').removeClass('ON');
- }
- else {
+ } else {
$('.list').addClass('ON');
$('.grid').removeClass('ON');
}
@@ -118,13 +118,15 @@ var setViewButtonsFor = function(viewMode) {
* preg_replace
*/
var preg_replace = function(array_pattern, array_pattern_replace, str) {
- var new_str = String (str);
+ var i = 0, reg_exp, val_to_replace,
+ new_str = String(str);
- for (var i=0; i < array_pattern.length; i++) {
- var reg_exp= RegExp(array_pattern[i], "g");
- var val_to_replace = array_pattern_replace[i];
+ while (i < array_pattern.length) {
+ reg_exp= RegExp(array_pattern[i], "g");
+ val_to_replace = array_pattern_replace[i];
new_str = new_str.replace (reg_exp, val_to_replace);
+ i += 1;
}
return new_str;
@@ -166,7 +168,7 @@ var cleanString = function(str) {
*/
var nameFormat = function(input) {
var filename = '';
- if(input.lastIndexOf('.') != -1) {
+ if (input.lastIndexOf('.') != -1) {
filename = cleanString(input.substr(0, input.lastIndexOf('.')));
filename += '.' + input.split('.').pop();
} else {
@@ -176,20 +178,18 @@ var nameFormat = function(input) {
};
//Converts bytes to kb, mb, or gb as needed for display.
-var formatBytes = function(bytes){
- var n = parseFloat(bytes);
- var d = parseFloat(1024);
- var c = 0;
- var u = [lg.bytes,lg.kb,lg.mb,lg.gb];
+var formatBytes = function(bytes) {
+ var n = parseFloat(bytes),
+ d = parseFloat(1024),
+ c = 0,
+ u = [lg.bytes,lg.kb,lg.mb,lg.gb];
- while(true){
- if(n < d){
- n = Math.round(n * 100) / 100;
- return n + u[c];
- } else {
- n /= d;
- c += 1;
+ while(true) {
+ if (n < d) {
+ return (Math.round(n * 100) / 100) + u[c];
}
+ n /= d;
+ c += 1;
}
};
@@ -208,42 +208,50 @@ var handleError = function(errMsg) {
* 'cap' is one of 'select', 'rename', 'delete', 'download'
*/
function has_capability(data, cap) {
- if (typeof(data['Capabilities']) == "undefined") return true;
- else return $.inArray(cap, data['Capabilities']) > -1;
+ if (typeof(data.Capabilities) == "undefined") {
+ return true;
+ } else {
+ return ($.inArray(cap, data.Capabilities) > -1);
+ }
}
// Test if file is authorized
var isAuthorizedFile = function(filename) {
- if(config.security.uploadPolicy == 'DISALLOW_ALL') {
- if($.inArray(getExtension(filename), config.security.uploadRestrictions) != -1) return true;
- }
- if(config.security.uploadPolicy == 'ALLOW_ALL') {
- if($.inArray(getExtension(filename), config.security.uploadRestrictions) == -1) return true;
- }
- return false;
+ 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
var getExtension = function(filename) {
- if(filename.split('.').length == 1)
+ if (filename.split('.').length == 1) {
return "";
+ }
return filename.split('.').pop();
};
// return filename without extension {
var getFilename = function(filename) {
- if(filename.lastIndexOf('.') != -1)
+ if (filename.lastIndexOf('.') != -1) {
return filename.substring(0, filename.lastIndexOf('.'));
- else
+ } else {
return filename;
+ }
};
// helpful in show/hide toolbar button for Windows
var hideButtons = function() {
- var current_path = $('.currentpath').val();
- if(config.options.platform_type == 'win32' && current_path === "")
- return true;
- return false;
+ return (
+ config.options.platform_type == 'win32' && $('.currentpath').val() == ''
+ );
};
/*
@@ -251,41 +259,47 @@ var hideButtons = function() {
* to the path specified. Called on initial page load and
* whenever a new directory is selected.
*/
-var setUploader = function(path){
+var setUploader = function(path) {
$('.storage_dialog #uploader').find('a').remove();
$('.storage_dialog #uploader').find('b').remove();
path = decodeURI(path);
- var display_string = displayPath(path);
- var mypath = '';
+
+ var display_string = displayPath(path),
+ mypath = '';
// split path
var split_path = display_string.split('/');
- split_path = split_path.filter(function(e){return e;});
+ split_path = split_path.filter(function(e) {return e;});
// set empty path if it is windows
if (config.options.platform_type === "win32" && config.options.show_volumes) {
mypath = "";
- }
- else if (split_path.length === 0)
+ } else if (split_path.length === 0) {
mypath = $('/ ');
- else
+ } else {
mypath = $('/ ');
+ }
$(mypath).appendTo($('.storage_dialog #uploader h1'));
- for(var i in split_path) {
- if (i < split_path.length-1) {
- mypath = $(''+split_path[i]+'/ ');
+ Object.keys(split_path).forEach(function (i) {
+ if (i < split_path.length - 1) {
+ mypath = $(
+ '' + split_path[i] + '/ '
+ );
$(mypath).appendTo($('.storage_dialog #uploader h1'));
- }
- else {
- mypath = $(''+split_path[i]+'/ ');
- $(mypath).appendTo($('.storage_dialog #uploader h1'));
- }
- }
+ } else {
+ mypath = $('' + split_path[i] + '/ ');
+ $(mypath).appendTo(
+ $('.storage_dialog #uploader h1')
+ );
+ }
+ });
$('.currentpath').val(path);
- if($('.storage_dialog #uploader h1 span').length === 0) {
+ if ($('.storage_dialog #uploader h1 span').length === 0) {
$(''+lg.current_folder+' ').appendTo($('.storage_dialog #uploader h1'));
}
@@ -293,23 +307,25 @@ var setUploader = function(path){
$('.storage_dialog #uploader h1').attr('data-path', display_string);
// create new folder
- $('.create').unbind().click(function(){
+ $('.create').unbind().click(function() {
var foldername = lg.new_folder;
var $file_element,
- $file_element_list;
+ $file_element_list,
+ folder_div;
+
$('.file_manager button.create').attr('disabled', 'disabled');
- if($('.fileinfo').data('view') == 'grid'){
+ if ($('.fileinfo').data('view') == 'grid') {
// template for creating new folder
- var folder_div =
+ folder_div =
"
" +
"" +
"" +
@@ -364,30 +382,32 @@ var setUploader = function(path){
// rename folder/file on blur
$file_element_list.find('p input').on('blur', function(e) {
$('.file_manager button.create').removeAttr('disabled');
- var text_value = $file_element_list.find('p input').val(),
- path = $('.currentpath').val();
+ var text_value = $file_element_list.find('p input').val();
+ path = $('.currentpath').val();
$file_element_list.find('p input').toggle();
$file_element_list.find('p span').toggle().html(text_value);
- if(text_value === undefined) text_value = lg.new_folder;
+ if (text_value === undefined) {
+ text_value = lg.new_folder;
+ }
getFolderName(text_value);
getFolderInfo(path);
});
}
// create a new folder
- var getFolderName = function(value){
+ var getFolderName = function(value) {
var fname = value;
- if(fname != ''){
+ 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 + '&time=' + d.getMilliseconds(), function(resp) {
var result = resp.data.result;
- if(result['Code'] === 0){
+ if (result.Code === 0) {
alertify.success(lg.successful_added_folder);
- getFolderInfo(result['Parent']);
+ getFolderInfo(result.Parent);
} else {
- alertify.error(result['Error']);
+ alertify.error(result.Error);
}
});
} else {
@@ -402,48 +422,44 @@ var setUploader = function(path){
* Binds specific actions to the toolbar based on capability.
* and show/hide buttons
*/
-var bindToolbar = function(data){
+var bindToolbar = function(data) {
if (!has_capability(data, 'upload') || hideButtons()) {
$('.file_manager').find('button.upload').hide();
- }
- else {
+ } else {
$('.file_manager').find('button.upload').show();
}
if (!has_capability(data, 'create') || hideButtons()) {
$('.file_manager').find('button.create').hide();
- }
- else {
+ } else {
$('.file_manager').find('button.create').show();
}
if (!has_capability(data, 'delete') || hideButtons()) {
$('.file_manager').find('button.delete').hide();
} else {
- $('.file_manager').find('button.delete').click(function(){
+ $('.file_manager').find('button.delete').click(function() {
// hide dimmer
$('.fileinfo .delete_item, .fm_dimmer').show();
});
// take action based on pressed button yes or no
$('.fileinfo .delete_item button.btn_yes').unbind().on('click', function() {
- if($('.fileinfo').data('view') == 'grid'){
- var path = $('.fileinfo').find('#contents li.selected .clip span').attr('data-alt');
- if(path.lastIndexOf('/') == path.length - 1){
- data['Path'] = path;
+ var path;
+ if ($('.fileinfo').data('view') == 'grid') {
+ path = $('.fileinfo').find('#contents li.selected .clip span').attr('data-alt');
+ if (path.lastIndexOf('/') == path.length - 1) {
+ data.Path = path;
+ deleteItem(data);
+ } else {
deleteItem(data);
}
- else {
+ } else {
+ path = $('.fileinfo').find('table#contents tbody tr.selected td:first-child').attr('title');
+ if (path.lastIndexOf('/') == path.length - 1) {
+ data.Path = path;
deleteItem(data);
- }
- }
- else {
- var path = $('.fileinfo').find('table#contents tbody tr.selected td:first-child').attr('title');
- if(path.lastIndexOf('/') == path.length - 1){
- data['Path'] = path;
- deleteItem(data);
- }
- else {
+ } else {
deleteItem(data);
}
}
@@ -457,13 +473,13 @@ var bindToolbar = function(data){
if (!has_capability(data, 'download') || hideButtons()) {
$('.file_manager').find('button.download').hide();
} else {
- $('.file_manager').find('button.download').unbind().click(function(){
- if($('.fileinfo').data('view') == 'grid'){
- var path = $('.fileinfo li.selected').find('.clip span').attr('data-alt');
+ $('.file_manager').find('button.download').unbind().click(function() {
+ var path;
+ if ($('.fileinfo').data('view') == 'grid') {
+ path = $('.fileinfo li.selected').find('.clip span').attr('data-alt');
window.open(fileConnector + '?mode=download&path=' + encodeURIComponent(path), '_blank');
- }
- else {
- var path = $('.fileinfo').find('table#contents tbody tr.selected td:first-child').attr('title');
+ } else {
+ path = $('.fileinfo').find('table#contents tbody tr.selected td:first-child').attr('title');
window.open(fileConnector + '?mode=download&path=' + encodeURIComponent(path), '_blank');
}
});
@@ -471,15 +487,14 @@ var bindToolbar = function(data){
if (!has_capability(data, 'rename') || hideButtons()) {
$('.file_manager').find('button.rename').hide();
- }
- else {
+ } else {
$('.file_manager').find('button.rename').show();
}
};
// enable/disable button when files/folder are loaded
var enable_disable_btn = function() {
- if($('.fileinfo').data('view') == 'grid'){
+ if ($('.fileinfo').data('view') == 'grid') {
var $grid_file = $('.file_manager').find('#contents li.selected');
$grid_file.removeClass('selected');
$('.file_manager').find('button.delete').prop('disabled', true);
@@ -516,8 +531,10 @@ $('.file_manager .fileinfo').on('click', function(e) {
// 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("/")) + "/";
+ var curr_path = $('.currentpath').val(),
+ path = curr_path.substring(
+ 0, curr_path.lastIndexOf("/")
+ ) + "/";
getFolderInfo(path);
});
@@ -530,24 +547,24 @@ $('.file_manager .refresh').on('click', function(e) {
* by double clicking or by clicking the "Rename" button in
* table(list) views.
*/
-var renameItem = function(data){
- var orig_name = getFilename(data['Filename']),
+var renameItem = function(data) {
+ var orig_name = getFilename(data.Filename),
finalName = '';
- var getNewName = function(rname){
- if(rname !== ''){
+ var getNewName = function(rname) {
+ if (rname !== '') {
var givenName = nameFormat(rname),
- suffix = getExtension(data['Filename']);
- if(suffix.length > 0) {
+ suffix = getExtension(data.Filename);
+ if (suffix.length > 0) {
givenName = givenName + '.' + suffix;
}
- var oldPath = data['Path'],
+ var oldPath = data.Path,
post_data = {
- "mode": "rename",
- "old": data['Path'],
- "new": givenName,
- };
+ "mode": "rename",
+ "old": data.Path,
+ "new": givenName
+ };
$.ajax({
type: 'POST',
@@ -556,17 +573,18 @@ var renameItem = function(data){
dataType: 'json',
contentType: "application/json; charset=utf-8",
async: false,
- success: function(resp){
+ success: function(resp) {
var result = resp.data.result;
- if(result['Code'] === 0){
+ if (result.Code === 0) {
var newPath = result['New Path'],
newName = result['New Name'],
title = $("#preview h1").attr("title");
- if (typeof title !="undefined" && title == oldPath)
+ if (typeof title !="undefined" && title == oldPath) {
$('#preview h1').text(newName);
+ }
- if($('.fileinfo').data('view') == 'grid'){
+ if ($('.fileinfo').data('view') == 'grid') {
$('.fileinfo span[data-alt="' + oldPath + '"]').parent().next('p span').text(newName);
$('.fileinfo span[data-alt="' + oldPath + '"]').attr('data-alt', newPath);
} else {
@@ -576,15 +594,15 @@ var renameItem = function(data){
$("#preview h1").html(newName);
// actualized data for binding
- data['Path']=newPath;
- data['Filename']=newName;
+ data.Path=newPath;
+ data.Filename=newName;
// UnBind toolbar functions.
$('.fileinfo').find('button.rename, button.delete, button.download').unbind();
alertify.success(lg.successful_rename);
} else {
- alertify.error(result['Error']);
+ alertify.error(result.Error);
}
finalName = result['New Name'];
@@ -593,7 +611,7 @@ var renameItem = function(data){
}
};
- getNewName(data['NewFilename']);
+ getNewName(data.NewFilename);
return finalName;
};
@@ -601,16 +619,16 @@ var renameItem = function(data){
* delete the folder or files by clicking the "Delete" button
* in table(list) view
*/
-var deleteItem = function(data){
+var deleteItem = function(data) {
var isDeleted = false,
msg = lg.confirmation_delete;
- var doDelete = function(data){
- var parent = data['Path'].split('/').reverse().slice(1).reverse().join('/') + '/';
+ var doDelete = function(data) {
+ var parent = data.Path.split('/').reverse().slice(1).reverse().join('/') + '/';
var post_data = {
- "mode": "delete",
- "path": data['Path']
- };
+ "mode": "delete",
+ "path": data.Path
+ };
$.ajax({
type: 'POST',
@@ -619,19 +637,19 @@ var deleteItem = function(data){
dataType: 'json',
contentType: "application/json; charset=utf-8",
async: false,
- success: function(resp){
+ success: function(resp) {
var result = resp.data.result;
- if(result['Code'] === 0){
+ if (result.Code === 0) {
isDeleted = true;
- if(isDeleted) {
+ if (isDeleted) {
alertify.success(lg.successful_delete);
- var rootpath = result['Path'].substring(0, result['Path'].length-1); // removing the last slash
+ var rootpath = result.Path.substring(0, result.Path.length-1); // removing the last slash
rootpath = rootpath.substr(0, rootpath.lastIndexOf('/') + 1);
getFolderInfo(rootpath);
}
} else {
isDeleted = false;
- alertify.error(result['Error']);
+ alertify.error(result.Error);
}
}
});
@@ -655,12 +673,13 @@ $('.delete_item button.btn_no').on('click', function() {
/* Decides whether to retrieve file or folder info based on
* the path provided.
*/
-var getDetailView = function(path){
- if(path.lastIndexOf('/') == path.length - 1){
+var getDetailView = function(path) {
+ if (path.lastIndexOf('/') == path.length - 1) {
var allowed_types = config.options.allowed_file_types;
var set_type = allowed_types[0];
- if(allowed_types[0] == "*")
+ if (allowed_types[0] == "*") {
set_type = allowed_types[1];
+ }
getFolderInfo(path, set_type);
}
};
@@ -672,7 +691,7 @@ var getDetailView = function(path){
* enable specific actions. Called whenever an item is
* clicked in list views.
*/
-var getFileInfo = function(file){
+var getFileInfo = function(file) {
// Update location for status, upload, & new folder functions.
var currentpath = file.substr(0, file.lastIndexOf('/') + 1);
setUploader(currentpath);
@@ -680,9 +699,9 @@ var getFileInfo = function(file){
// Retrieve the data & populate the template.
var d = new Date(); // to prevent IE cache issues
var post_data = {
- 'path': file,
- 'mode': 'getinfo'
- };
+ 'path': file,
+ 'mode': 'getinfo'
+ };
$.ajax({
type: 'POST',
@@ -691,15 +710,22 @@ var getFileInfo = function(file){
dataType: 'json',
contentType: "application/json; charset=utf-8",
async: false,
- success: function(resp){
+ success: function(resp) {
var data = resp.data.result;
- if(data['Code'] === 0){
+
+ if (data.Code === 0) {
var properties = '';
- if(data['Properties']['Size'] || parseInt(data['Properties']['Size'])==0) properties += '' + lg.size + ' ' + formatBytes(data['Properties']['Size']) + ' ';
- data['Capabilities'] = capabilities;
+ if (
+ data.Properties.Size || parseInt(data.Properties.Size)==0
+ ) {
+ properties += '' + lg.size + ' ' + formatBytes(
+ data.Properties.Size
+ ) + ' ';
+ }
+ data.Capabilities = capabilities;
bindToolbar(data);
} else {
- alertify.error(data['Error']);
+ alertify.error(data.Error);
}
}
});
@@ -709,19 +735,26 @@ var getFileInfo = function(file){
* Retrieves data for all items within the given folder and
* creates a list view.
*/
-var getFolderInfo = function(path, file_type=''){
+var getFolderInfo = function(path, file_type) {
+ if (!file_type) {
+ file_type = '';
+ }
// Update location for status, upload, & new folder functions.
setUploader(path);
// set default selected file type
- if (file_type === '')
+ if (file_type === '') {
file_type = $('.change_file_types select').val();
+ }
// navigate to directory or path when clicked on breadcrumbs
$('.file_manager a.breadcrumbs').unbind().on('click', function() {
- var path = $(this).attr('data-path'),
+ var curr_path = $(this).attr('data-path'),
current_dir = $(this).html(),
- move_to = path.substring(0, path.lastIndexOf(current_dir))+current_dir;
+ move_to = curr_path.substring(
+ 0, curr_path.lastIndexOf(current_dir)
+ ) + current_dir;
+
getFolderInfo(move_to);
enab_dis_level_up();
});
@@ -729,8 +762,7 @@ var getFolderInfo = function(path, file_type=''){
// hide select file if we are listing drives in windows.
if (hideButtons()) {
$(".allowed_file_types .change_file_types").hide();
- }
- else {
+ } else {
$(".allowed_file_types .change_file_types").show();
}
@@ -741,7 +773,9 @@ 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');
+ if ($.urlParam('type')) {
+ url += '&type=' + $.urlParam('type');
+ }
var post_data = {
'path': path,
@@ -756,183 +790,342 @@ var getFolderInfo = function(path, file_type=''){
dataType: 'json',
contentType: "application/json; charset=utf-8",
async: false,
- success: function(resp){
- var result = '';
- data = resp.data.result;
+ success: function(resp) {
+ var result = '',
+ data = resp.data.result;
- // hide activity indicator
- $('.fileinfo').find('span.activity').hide();
- if(data.Code === 0) {
- alertify.error(data.err_msg);
- return;
- }
+ // hide activity indicator
+ $('.fileinfo').find('span.activity').hide();
+ if (data.Code === 0) {
+ alertify.error(data.err_msg);
+ return;
+ }
- // generate HTML for files/folder and render into container
- if(!_.isEmpty(data)){
- if($('.fileinfo').data('view') == 'grid') {
- result += '';
- for(var key in data) {
- var props = data[key]['Properties'],
- cap_classes = "";
- for (var cap in capabilities) {
- if (has_capability(data[key], capabilities[cap])) {
- cap_classes += "cap_" + capabilities[cap];
+ // generate HTML for files/folder and render into container
+ if (!_.isEmpty(data)) {
+ if ($('.fileinfo').data('view') == 'grid') {
+ result += '';
+ Object.keys(data).forEach(function (key) {
+ var props = (data[key]).Properties,
+ cap_classes = "";
+
+ Object.keys(capabilities).forEach(function (cap) {
+ if (has_capability(data[key], capabilities[cap])) {
+ cap_classes += "cap_" + capabilities[cap];
+ }
+ });
+
+ (data[key]).Capabilities = capabilities;
+ bindToolbar(data[key]);
+
+ var class_type;
+ if ((data[key]).file_type == 'dir') {
+ class_type = 'fa fa-folder-open fm_folder';
+ } else if ((data[key]).file_type == 'drive') {
+ class_type = 'fa fa-hdd-o fm_drive';
+ } else {
+ class_type = 'fa fa-file-text fm_file';
}
- }
- data[key]['Capabilities'] = capabilities;
- bindToolbar(data[key]);
+ var fm_filename = (data[key]).Filename;
+ if (fm_filename.length > 15 ) {
+ fm_filename = (data[key]).Filename.substr(0, 10) +'...';
+ }
- var class_type;
- if(data[key]['file_type'] == 'dir') {
- class_type = 'fa fa-folder-open fm_folder';
- }
- else if(data[key]['file_type'] == 'drive') {
- class_type = 'fa fa-hdd-o fm_drive';
- }
- else {
- class_type = 'fa fa-file-text fm_file';
- }
+ var file_name_original = encodeURI((data[key]).Filename);
+ var file_path_orig = encodeURI((data[key]).Path);
- var fm_filename = data[key]['Filename'];
- if (fm_filename.length > 15 ) {
- fm_filename = data[key]['Filename'].substr(0, 10) +'...';
- }
+ result += '';
+ if ((data[key]).Protected == 1) {
+ result += '
';
+ }
- var file_name_original = encodeURI(data[key]['Filename']);
- var file_path_orig = encodeURI(data[key]['Path']);
- result += '
';
- if (data[key]['Protected'] == 1) {
- result += ' ';
- }
- result += '
';
- if(!has_capability(data[key], 'rename'))
- result += '' + fm_filename + ' ';
- else
- result += '' + fm_filename + '
';
- if(props['Width'] && props['Width'] != '') result += '' + props['Width'] + 'x' + props['Height'] + ' ';
- if(props['Size'] && props['Size'] != '') result += '' + props['Size'] + ' ';
- if(props['Date Created'] && props['Date Created'] != '') result += '' + props['Date Created'] + ' ';
- if(props['Date Modified'] && props['Date Modified'] != '') result += '' + props['Date Modified'] + ' ';
- result += '';
+ result += '
';
+ if (!has_capability(data[key], 'rename')) {
+ result += '' + fm_filename + ' ';
+ } else {
+ result +=
+ ' ' +
+ '' + fm_filename +
+ '
';
+ }
+ if (props.Width && props.Width != '') {
+ result += '' +
+ props.Width + 'x' + props.Height + ' ';
+ }
+ if (props.Size && props.Size != '') {
+ result += '' +
+ props.Size + ' ';
+ }
+ if (props['Date Created'] && props['Date Created'] != '') {
+ result += '' +
+ props['Date Created'] + ' ';
+ }
+ if (props['Date Modified'] && props['Date Modified'] != '') {
+ result += '' +
+ props['Date Modified'] + ' ';
+ }
+ result += ' ';
+ });
+
+ result += ' ';
+ } else {
+ result += '';
}
-
- result += ' ';
} else {
- result += '';
- result += '';
- result += '' + lg.size + ' ';
- result += '' + lg.modified + ' ';
- result += '';
+ if ($('.fileinfo').data('view') == 'grid') {
+ result += '';
+ } else {
+ result += '';
+ result += '' + lg.size +
+ ' ' + lg.modified +
+ ' ';
+ result += '';
+ }
+ result += '' +
+ lg.could_not_retrieve_folder + ' ';
- for(var key in data){
- var path = encodeURI(data[key]['Path']),
- props = data[key]['Properties'],
- cap_classes = "";
- for (var cap in capabilities) {
- if (has_capability(data[key], capabilities[cap])) {
- cap_classes += " cap_" + capabilities[cap];
+ var cap_no_folders = ['upload', 'create'];
+
+ data.Capabilities = cap_no_folders;
+ bindToolbar(data);
+ }
+
+ // Add the new markup to the DOM.
+ $('.fileinfo .file_listing').html(result);
+
+ // rename file/folder
+ $('.file_manager button.rename').unbind().on('click',function(e) {
+ if ($('.fileinfo').data('view') == 'grid') {
+ e.stopPropagation();
+ var $this = $('.file_manager').find('#contents li.selected p'),
+ orig_value = decodeURI($this.find('span').attr('title')),
+ newvalue = orig_value.substring(0, orig_value.indexOf('.'));
+
+ if (newvalue === '') {
+ newvalue = decodeURI(orig_value);
+ }
+
+ $this.find('input').toggle().val(newvalue).focus();
+ $this.find('span').toggle();
+
+ // Rename folder/file on pressing enter key
+ $('.file_manager').unbind().on('keyup', function(e) {
+ if (e.keyCode == 13) {
+ e.stopPropagation();
+ $('.fileinfo #contents li.selected p').find(
+ 'input'
+ ).trigger('blur');
+ }
+ });
+ } else if ($('.fileinfo').data('view') == 'list') {
+ e.stopPropagation();
+ var $this = $('.fileinfo').find(
+ 'table#contents tbody tr.selected td:first-child p'
+ ),
+ orig_value = decodeURI($this.find('span').html()),
+ newvalue = orig_value.substring(0, orig_value.indexOf('.'));
+
+ if (newvalue === '') {
+ newvalue = orig_value;
+ }
+ $this.find('input').toggle().val(newvalue).focus();
+ $this.find('span').toggle();
+
+ // Rename folder/file on pressing enter key
+ $('.file_manager').unbind().on('keyup', function(e) {
+ if (e.keyCode == 13) {
+ e.stopPropagation();
+ $('.fileinfo table#contents tr.selected td p').find(
+ 'input'
+ ).trigger('blur');
+ }
+ });
+ }
+ });
+
+ $('.fileinfo #contents li p').on('dblclick',function(e) {
+ e.stopPropagation();
+ var $this = $(this);
+ var orig_value = decodeURI($this.find('span').attr('title')),
+ newvalue = orig_value.substring(0, orig_value.indexOf('.'));
+
+ if (newvalue === '') {
+ newvalue = orig_value;
+ }
+
+ $this.find('input').toggle().val(newvalue).focus();
+ $this.find('span').toggle();
+
+ // Rename folder/file on pressing enter key
+ $('.file_manager').unbind().on('keyup', function(e) {
+ if (e.keyCode == 13) {
+ e.stopPropagation();
+ $this.find('input').trigger('blur');
+ }
+ });
+ });
+
+ // Rename UI handling
+ $('.fileinfo #contents li p').on('blur dblclick','input', function(e) {
+ e.stopPropagation();
+
+ var old_name = decodeURI($(this).siblings('span').attr('title')),
+ newvalue = old_name.substring(0, old_name.indexOf('.')),
+ last = getFileExtension(old_name);
+
+ if (old_name.indexOf('.') == 0) {
+ last = '';
+ }
+
+ if (newvalue == '') {
+ newvalue = decodeURI(old_name);
+ }
+
+ if (e.type=="keydown") {
+ if (e.which==13) {
+ var full_name = decodeURI($(this).val()) + (
+ last !== '' ? '.' + last: ''
+ );
+
+ $(this).toggle();
+ $(this).siblings('span').toggle().html(full_name);
+
+ var new_name = decodeURI($(this).val()),
+ path = decodeURI($(this).parent().parent().find(
+ 'span'
+ ).attr('data-alt')),
+ data = {
+ 'Filename': old_name,
+ 'Path': path,
+ 'NewFilename': new_name
+ };
+
+ if (newvalue !== new_name) {
+ renameItem(data);
+ var parent = $('.currentpath').val();
+ getFolderInfo(parent);
+ }
+ e.stopPropagation();
+ }
+
+ if (
+ e.which==38 || e.which==40 || e.which==37 ||
+ e.which==39 || e.keyCode == 32
+ ) {
+ e.stopPropagation();
+ }
+ } else if (e.type=="focusout") {
+ if ($(this).css('display')=="inline-block") {
+ var full_name = decodeURI(
+ $(this).val()
+ ) + (last !== ''? '.' + last: '');
+
+ $(this).toggle();
+ $(this).siblings('span').toggle().html(full_name);
+
+ var new_name = decodeURI($(this).val()),
+ path = decodeURI($(this).parent().parent().find(
+ 'span'
+ ).attr('data-alt')),
+ data = {
+ 'Filename': old_name,
+ 'Path': path,
+ 'NewFilename': new_name
+ };
+
+ if (newvalue !== new_name) {
+ renameItem(data);
+ getFolderInfo($('.currentpath').val());
}
}
-
- data[key]['Capabilities'] = capabilities;
- bindToolbar(data[key]);
-
- var class_type;
- if(data[key]['file_type'] == 'dir') {
- class_type = 'fa fa-folder-open tbl_folder';
- }
- else if(data[key]['file_type'] == 'drive') {
- class_type = 'fa fa-hdd-o tbl_drive';
- }
- else {
- class_type = 'fa fa-file-text tbl_file'
- }
-
- var file_name_original = encodeURI(data[key]['Filename']);
- result += '';
-
- var fm_filename = data[key]['Filename'];
- if (fm_filename.length > 15 ) {
- fm_filename = data[key]['Filename'].substr(0, 10) +'...';
- }
-
- result += '';
- if(data[key]['Protected'] == 1) {
- result += ' ';
- }
- if(!has_capability(data[key], 'rename'))
- result += '' + fm_filename + ' ';
- else
- result += '' + fm_filename + '
';
-
- if(props['Size'] && props['Size'] != ''){
- result += '' + props['Size'] + ' ';
- } else {
- result += ' ';
- }
-
- if(props['Date Modified'] && props['Date Modified'] != ''){
- result += '' + props['Date Modified'] + ' ';
- } else {
- result += ' ';
- }
-
- result += ' ';
+ } else {
+ e.stopPropagation();
}
+ });
- result += ' ';
- result += '
';
- }
- } else {
- if($('.fileinfo').data('view') == 'grid') {
- result += '';
- }
- else {
- result += '';
- result += '' + lg.size + ' ' + lg.modified + ' ';
- result += '';
- }
- result += '' + lg.could_not_retrieve_folder + ' ';
- var cap_no_folders = ['upload', 'create']
- data['Capabilities'] = cap_no_folders;
- bindToolbar(data);
- }
-
- // Add the new markup to the DOM.
- $('.fileinfo .file_listing').html(result);
-
- // rename file/folder
- $('.file_manager button.rename').unbind().on('click',function(e){
- if($('.fileinfo').data('view') == 'grid'){
+ $('.fileinfo table#contents tr td p').on('dblclick', function(e) {
e.stopPropagation();
- var $this = $('.file_manager').find('#contents li.selected p'),
- orig_value = decodeURI($this.find('span').attr('title')),
+ // 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 === '')
- newvalue = decodeURI(orig_value);
-
- $this.find('input').toggle().val(newvalue).focus();
- $this.find('span').toggle();
-
- // Rename folder/file on pressing enter key
- $('.file_manager').unbind().on('keyup', function(e) {
- if (e.keyCode == 13) {
- e.stopPropagation();
- $('.fileinfo #contents li.selected p').find('input').trigger('blur');
- }
- });
-
- }
- else if($('.fileinfo').data('view') == 'list'){
- e.stopPropagation();
- var $this = $('.fileinfo').find('table#contents tbody tr.selected td:first-child p'),
- orig_value = decodeURI($this.find('span').html()),
- newvalue = orig_value.substring(0, orig_value.indexOf('.'));
- if (newvalue === '')
+ if (newvalue === '') {
newvalue = orig_value;
+ }
$this.find('input').toggle().val(newvalue).focus();
$this.find('span').toggle();
@@ -941,289 +1134,215 @@ var getFolderInfo = function(path, file_type=''){
$('.file_manager').unbind().on('keyup', function(e) {
if (e.keyCode == 13) {
e.stopPropagation();
- $('.fileinfo table#contents tr.selected td p').find('input').trigger('blur');
+ $this.find('input').trigger('blur');
}
});
- }
- });
-
- $('.fileinfo #contents li p').on('dblclick',function(e){
- e.stopPropagation();
- var $this = $(this);
- var orig_value = decodeURI($this.find('span').attr('title')),
- newvalue = orig_value.substring(0, orig_value.indexOf('.'));
-
- if (newvalue === '')
- newvalue = orig_value;
-
- $this.find('input').toggle().val(newvalue).focus();
- $this.find('span').toggle();
-
- // Rename folder/file on pressing enter key
- $('.file_manager').unbind().on('keyup', function(e) {
- if (e.keyCode == 13) {
- e.stopPropagation();
- $this.find('input').trigger('blur');
- }
});
- });
- // Rename UI handling
- $('.fileinfo #contents li p').on('blur dblclick','input', function(e){
- e.stopPropagation();
- var old_name = decodeURI($(this).siblings('span').attr('title')),
- newvalue = old_name.substring(0, old_name.indexOf('.')),
- last = getFileExtension(old_name);
- if(old_name.indexOf('.') == 0)
- last = ''
+ $('.fileinfo table#contents tr td p').on(
+ 'blur dblclick', 'input', function(e) {
+ var old_name = decodeURI($(this).siblings('span').attr('title')),
+ newvalue = old_name.substring(0, old_name.indexOf('.')),
+ last = getFileExtension(old_name);
- if (newvalue == '')
- newvalue = decodeURI(old_name);
-
- if(e.type=="keydown")
- {
- if(e.which==13)
- {
- var full_name = decodeURI($(this).val()) + (last !== '' ? '.' + last: '');
- $(this).toggle();
- $(this).siblings('span').toggle().html(full_name);
-
- var new_name = decodeURI($(this).val()),
- path = decodeURI($(this).parent().parent().find('span').attr('data-alt'));
-
- var data = {
- 'Filename': old_name,
- 'Path': path,
- 'NewFilename': new_name
- };
-
- if (newvalue !== new_name) {
- renameItem(data);
- var parent = $('.currentpath').val();
- getFolderInfo(parent);
- }
- e.stopPropagation();
+ if (old_name.indexOf('.') == 0) {
+ last = '';
}
- if(e.which==38 || e.which==40 || e.which==37 || e.which==39 || e.keyCode == 32)
- {
- e.stopPropagation();
+
+ if (newvalue == '') {
+ newvalue = old_name;
}
- }
- else if(e.type=="focusout")
- {
- if($(this).css('display')=="inline-block")
- {
- var full_name = decodeURI($(this).val()) + (last !== ''? '.' + last: '');
- $(this).toggle();
- $(this).siblings('span').toggle().html(full_name);
- var new_name = decodeURI($(this).val()),
- path = decodeURI($(this).parent().parent().find('span').attr('data-alt'));
+ if (e.type=="focusout") {
+ if ($(this).css('display')=="inline-block") {
+ var full_name = decodeURI($(this).val()) + (
+ last !== ''? '.' + last: ''
+ );
+ $(this).toggle();
+ $(this).siblings('span').toggle().html(full_name);
- var data = {
- 'Filename': old_name,
- 'Path': path,
- 'NewFilename': new_name
- };
+ var new_name = decodeURI($(this).val()),
+ path = decodeURI($(this).parent().parent().attr('title')),
+ data = {
+ 'Filename': old_name,
+ 'Path': path,
+ 'NewFilename': new_name
+ };
- if (newvalue !== new_name) {
- renameItem(data);
- var parent = $('.currentpath').val();
- getFolderInfo(parent);
- }
- }
- }
- else
- {
- e.stopPropagation();
- }
- });
-
- $('.fileinfo table#contents tr td p').on('dblclick',function(e){
- e.stopPropagation();
- // Prompt to rename file/folder
- $this = $(this);
- var orig_value = decodeURI($this.find('span').attr('title')),
- newvalue = orig_value.substring(0, orig_value.indexOf('.'));
-
- if (newvalue === '')
- newvalue = orig_value;
-
- $this.find('input').toggle().val(newvalue).focus();
- $this.find('span').toggle();
-
- // Rename folder/file on pressing enter key
- $('.file_manager').unbind().on('keyup', function(e) {
- if (e.keyCode == 13) {
- e.stopPropagation();
- $this.find('input').trigger('blur');
- }
- });
- });
-
- $('.fileinfo table#contents tr td p').on('blur dblclick','input',function(e){
- var old_name = decodeURI($(this).siblings('span').attr('title')),
- newvalue = old_name.substring(0, old_name.indexOf('.'));
- last = getFileExtension(old_name);
- if(old_name.indexOf('.') == 0)
- last = ''
-
- if (newvalue == '')
- newvalue = old_name;
-
- if(e.type=="focusout")
- {
- if($(this).css('display')=="inline-block")
- {
- var full_name = decodeURI($(this).val()) + (last !== ''? '.' + last: '');
- $(this).toggle();
- $(this).siblings('span').toggle().html(full_name);
-
- var new_name = decodeURI($(this).val()),
- path = decodeURI($(this).parent().parent().attr('title'));
-
- var data = {
- 'Filename': old_name,
- 'Path': path,
- 'NewFilename': new_name
- };
-
- if (newvalue !== new_name) {
- renameItem(data);
- var parent = path.split('/').reverse().slice(2).reverse().join('/') + '/';
- getFolderInfo(parent);
- }
- }
- }
- else
- {
- e.stopPropagation();
- }
- });
-
- var data_cap = {}
- /*
- * Bind click events
- * Select items - afolder dblclick
- */
- if($('.fileinfo').data('view') == 'grid'){
- // Get into folder on dblclick
- $('.fileinfo').find('#contents li').dblclick(function(e){
- e.stopPropagation();
-
- // Enable/Disable level up button
- enab_dis_level_up();
- var path = decodeURI($(this).find('span').attr('data-alt'));
- if(path.lastIndexOf("/") == path.length - 1){
- $('.file_manager_ok').addClass('disabled');
- var $create_input = $('.create_input input[type="text"]');
- $('.file_manager button.delete, .file_manager button.rename').attr('disabled', 'disabled');
- $('.file_manager button.download').attr('disabled', 'disabled');
- getFolderInfo(path);
- if ($create_input.length != 0 && $create_input.val() != '') {
- $('.file_manager_ok').removeClass('disabled');
+ if (newvalue !== new_name) {
+ renameItem(data);
+ var parent = path.split('/').reverse().slice(2).reverse().join('/') + '/';
+ getFolderInfo(parent);
+ }
}
} else {
- getFileInfo(path);
+ e.stopPropagation();
}
});
- data_cap['Capabilities'] = capabilities;
- $('.fileinfo').find('#contents li').click(function(e){
- e.stopPropagation();
- var path = decodeURI($(this).find('.clip span').attr('data-alt')),
- file_name = $(this).find('p span').attr('title'),
- is_protected = $(this).find('.clip span.fm_lock_icon').attr('data-protected');
- if(path.lastIndexOf('/') == path.length - 1){
- if(has_capability(data_cap, 'select_folder') && is_protected == undefined) {
- $(this).parent().find('li.selected').removeClass('selected');
- $(this).addClass('selected');
- $('.file_manager_ok').removeClass('disabled');
- $('.file_manager button.delete, .file_manager button.rename').removeAttr('disabled', 'disabled');
+ var data_cap = {};
+ /*
+ * Bind click events
+ * Select items - afolder dblclick
+ */
+ if ($('.fileinfo').data('view') == 'grid') {
+ // Get into folder on dblclick
+ $('.fileinfo').find('#contents li').dblclick(function(e) {
+ e.stopPropagation();
+
+ // Enable/Disable level up button
+ enab_dis_level_up();
+
+ var path = decodeURI($(this).find('span').attr('data-alt'));
+
+ if (path.lastIndexOf("/") == path.length - 1) {
+ $('.file_manager_ok').addClass('disabled');
+
+ var $create_input = $('.create_input input[type="text"]');
+
+ $('.file_manager button.delete, .file_manager button.rename').attr('disabled', 'disabled');
$('.file_manager button.download').attr('disabled', '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');
- }
- //getFolderInfo(path);
- } else {
- if(has_capability(data_cap, 'select_file') && is_protected == undefined) {
- $(this).parent().find('li.selected').removeClass('selected');
- $(this).addClass('selected');
- $('.file_manager_ok').removeClass('disabled');
- $('.file_manager button.delete, .file_manager button.download, .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');
- }
- if(config.options.dialog_type == 'create_file' && is_protected == undefined) {
- $('.create_input input[type="text"]').val(file_name);
- $('.file_manager_ok, .file_manager_create').removeClass('disabled');
- }
- getFileInfo(path);
- }
- });
- } else {
- $('.fileinfo table#contents tbody tr').on('click', function(e){
- e.stopPropagation();
- var path = decodeURI($('td:first-child', this).attr('title')),
- file_name = decodeURI($('td:first-child p span', this).attr('title')),
- is_protected = $('td:first-child', this).find('i.tbl_lock_icon').attr('data-protected');
- if(path.lastIndexOf('/') == path.length - 1){
- if(has_capability(data_cap, 'select_folder') && is_protected == undefined) {
- $(this).parent().find('tr.selected').removeClass('selected');
- $('td:first-child', this).parent().addClass('selected');
+ getFolderInfo(path);
+ if ($create_input.length != 0 && $create_input.val() != '') {
+ $('.file_manager_ok').removeClass('disabled');
+ }
+ } else {
+ getFileInfo(path);
+ }
+ });
+
+ data_cap.Capabilities = capabilities;
+ $('.fileinfo').find('#contents li').click(function(e) {
+ e.stopPropagation();
+ var path = decodeURI($(this).find('.clip span').attr('data-alt')),
+ file_name = $(this).find('p span').attr('title'),
+ is_protected = $(this).find(
+ '.clip span.fm_lock_icon'
+ ).attr('data-protected');
+
+ if (path.lastIndexOf('/') == path.length - 1) {
+ if (
+ has_capability(data_cap, 'select_folder') &&
+ is_protected == undefined
+ ) {
+ $(this).parent().find('li.selected').removeClass('selected');
+ $(this).addClass('selected');
+
+ $('.file_manager_ok').removeClass('disabled');
+ $('.file_manager button.delete, .file_manager button.rename').removeAttr(
+ 'disabled', 'disabled'
+ );
+ $('.file_manager button.download').attr(
+ 'disabled', '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'
+ );
+ }
+ //getFolderInfo(path);
+ } else {
+ if (
+ has_capability(data_cap, 'select_file') &&
+ is_protected == undefined
+ ) {
+ $(this).parent().find('li.selected').removeClass('selected');
+ $(this).addClass('selected');
+ $('.file_manager_ok').removeClass('disabled');
+ $('.file_manager button.delete, .file_manager button.download, .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'
+ );
+ }
+
+ if (
+ config.options.dialog_type == 'create_file' &&
+ is_protected == undefined
+ ) {
+ $('.create_input input[type="text"]').val(file_name);
+ $('.file_manager_ok, .file_manager_create').removeClass('disabled');
+ }
+ getFileInfo(path);
+ }
+ });
+ } else {
+ $('.fileinfo table#contents tbody tr').on('click', function(e) {
+ e.stopPropagation();
+ var path = decodeURI($('td:first-child', this).attr('title')),
+ file_name = decodeURI($('td:first-child p span', this).attr(
+ 'title'
+ )),
+ is_protected = $('td:first-child', this).find(
+ 'i.tbl_lock_icon'
+ ).attr('data-protected');
+
+ if (path.lastIndexOf('/') == path.length - 1) {
+ if (has_capability(data_cap, 'select_folder') && is_protected == undefined) {
+ $(this).parent().find('tr.selected').removeClass('selected');
+ $('td:first-child', this).parent().addClass('selected');
+ $('.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');
+ }
+ //getFolderInfo(path);
+ } else {
+ if (has_capability(data_cap, 'select_file') && is_protected == undefined) {
+ $(this).parent().find('tr.selected').removeClass('selected');
+ $('td:first-child', this).parent().addClass('selected');
+ $('.file_manager_ok').removeClass('disabled');
+ $('.file_manager button.delete, .file_manager button.download, .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'
+ );
+ }
+ if (
+ config.options.dialog_type == 'create_file' &&
+ is_protected == undefined
+ ) {
+ $('.create_input input[type="text"]').val(file_name);
+ $('.file_manager_ok, .file_manager_create').removeClass('disabled');
+ }
+ getFileInfo(path);
+ }
+ });
+
+ $('.fileinfo table#contents tbody tr').on('dblclick', function(e) {
+ e.stopPropagation();
+
+ // Enable/Disable level up button
+ enab_dis_level_up();
+
+ var path = $('td:first-child', this).attr('title');
+
+ if (path.lastIndexOf('/') == path.length - 1) {
$('.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');
+ $('.file_manager button.delete, .file_manager button.rename').attr('disabled', 'disabled');
+ getFolderInfo(path);
+ } else {
+ getFileInfo(path);
}
- //getFolderInfo(path);
- } else {
- if(has_capability(data_cap, 'select_file') && is_protected == undefined) {
- $(this).parent().find('tr.selected').removeClass('selected');
- $('td:first-child', this).parent().addClass('selected');
- $('.file_manager_ok').removeClass('disabled');
- $('.file_manager button.delete, .file_manager button.download, .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');
- }
- if(config.options.dialog_type == 'create_file' && is_protected == undefined) {
- $('.create_input input[type="text"]').val(file_name);
- $('.file_manager_ok, .file_manager_create').removeClass('disabled');
- }
- getFileInfo(path);
- }
-
-
- });
-
- $('.fileinfo table#contents tbody tr').on('dblclick', function(e){
- e.stopPropagation();
-
- // Enable/Disable level up button
- enab_dis_level_up();
- var path = $('td:first-child', this).attr('title');
- if(path.lastIndexOf('/') == path.length - 1){
- $('.file_manager_ok').removeClass('disabled');
- $('.file_manager button.download').attr('disabled', 'disabled');
- $('.file_manager button.delete, .file_manager button.rename').attr('disabled', 'disabled');
- getFolderInfo(path);
- } else {
- getFileInfo(path);
- }
- });
+ });
+ }
}
- }
});
};
@@ -1232,28 +1351,30 @@ var enab_dis_level_up = function() {
$('.file_manager #uploader h1').show();
$('.show_selected_file').remove();
+
setTimeout(function() {
var b = $('.currentpath').val(),
$level_up = $('.file_manager').find('button.level-up'),
$home_btn = $('.file_manager').find('button.home');
+
if (b === fileRoot) {
$level_up.attr('disabled', 'disabled');
$home_btn.attr('disabled', 'disabled');
- }
- else {
+ } else {
$home_btn.removeAttr('disabled');
$level_up.removeAttr('disabled');
}
}, 100);
-}
+};
// Get transaction id to generate request url and
// to generate config files on runtime
var transId = getTransId(),
t_id = '';
-if (transId.readyState == 4)
+if (transId.readyState == 4) {
t_res = JSON.parse(transId.responseText);
+}
t_id = t_res.data.fileTransId;
var root_url = '{{ url_for("file_manager.index") }}',
@@ -1264,8 +1385,9 @@ var root_url = '{{ url_for("file_manager.index") }}',
config;
// load user configuration file
-if (cfg.readyState == 4)
+if (cfg.readyState == 4) {
config = JSON.parse(cfg.responseText);
+}
var fileRoot = config.options.fileRoot,
capabilities = config.options.capabilities;
@@ -1278,8 +1400,9 @@ var lg = [],
enjs = '{{ url_for("file_manager.index") }}' + "en.js",
lgf = loadLangFile(enjs);
-if (lgf.readyState == 4)
+if (lgf.readyState == 4) {
lg = JSON.parse(lgf.responseText);
+}
// Disable home button on load
$('.file_manager').find('button.home').attr('disabled', 'disabled');
@@ -1293,33 +1416,35 @@ if (
// Create file selection dropdown
var allowed_types = config.options.allowed_file_types,
types_len = allowed_types.length,
- select_box = '', file_type = "All Files";
- if(types_len > 0) {
- var i = 0, j = 0,
- select_box = "";
+ select_box = '',
+ file_type = '';
+
+ if (types_len > 0) {
+ var i = 0, j = 0, t,
+ selected = false,
+ have_all_types = false;
+
+ select_box = "" +
+ "";
+
while(i < types_len) {
-
- if(j == 1) {
- select_box += "" + allowed_types[i] + " ";
- j = 0;
- }
- else {
- if(allowed_types[i] == '*'){
- j = 1;
- file_type = "All Files";
- }
- else {
- file_type = allowed_types[i];
- }
-
- select_box += "" + file_type + " ";
+ t = allowed_types[i];
+ if (!selected && (types_len == 1 || t != '*')) {
+ select_box += "" + t + " ";
+ selected = true;
+ have_all_types = (have_all_types || (t == '*'));
+ } else {
+ select_box += '' +
+ (t == '*' ? '{{ _('All Files') }}' : t) + " ";
+ have_all_types = (t == '*');
}
i++;
}
- select_box += " ";
- select_box += "Format:
";
+
+ if (!have_all_types) {
+ select_box += '{{ _('All Files') }} ';
+ }
+ select_box += " {{ _('Format') }}: ";
}
$(".allowed_file_types").html(select_box);
@@ -1341,10 +1466,9 @@ if (config.options.dialog_type == 'create_file') {
$('.create_input input[type="text"]').on('keypress, keydown', function() {
var input_text_len = $(this).val().length;
- if(input_text_len > 0 ) {
+ if (input_text_len > 0 ) {
$('.file_manager_ok').removeClass('disabled');
- }
- else {
+ } else {
$('.file_manager_ok').addClass('disabled');
}
});
@@ -1353,10 +1477,10 @@ if (config.options.dialog_type == 'create_file') {
Initialization
---------------------------------------------------------*/
-$(function(){
+$(function() {
var expandedFolder = '';
- if(config.extra_js) {
+ if (config.extra_js) {
for(var i=0; i< config.extra_js.length; i++) {
$.ajax({
url: config.extra_js[i],
@@ -1366,7 +1490,7 @@ $(function(){
}
}
- if($.urlParam('expandedFolder') != 0) {
+ if ($.urlParam('expandedFolder') != 0) {
expandedFolder = $.urlParam('expandedFolder');
}
@@ -1375,7 +1499,7 @@ $(function(){
// we finalize the FileManager UI initialization
// with localized text if necessary
- if(config.autoload == true) {
+ if (config.autoload == true) {
$('.upload').append(lg.upload);
$('.create').append(lg.new_folder);
$('.grid').attr('title', lg.grid_view);
@@ -1426,7 +1550,7 @@ $(function(){
});
// re-render the home view
- $('.file_manager .home').click(function(){
+ $('.file_manager .home').click(function() {
var currentViewMode = $('.fileinfo').data('view');
$('.fileinfo').data('view', currentViewMode);
getFolderInfo(fileRoot);
@@ -1449,7 +1573,7 @@ $(function(){
});
// set buttons to switch between grid and list views.
- $('.file_manager .grid').click(function(){
+ $('.file_manager .grid').click(function() {
setViewButtonsFor('grid');
$('.fileinfo').data('view', 'grid');
enable_disable_btn();
@@ -1457,7 +1581,7 @@ $(function(){
});
// Show list mode
- $('.file_manager .list').click(function(){
+ $('.file_manager .list').click(function() {
setViewButtonsFor('list');
$('.fileinfo').data('view', 'list');
enable_disable_btn();
@@ -1469,9 +1593,10 @@ $(function(){
$('#uploader').attr('action', fileConnector);
- data = {
+ var data = {
'Capabilities': capabilities
};
+
if (has_capability(data, 'upload')) {
Dropzone.autoDiscover = false;
// we remove simple file upload element
@@ -1481,25 +1606,29 @@ $(function(){
$('.upload').unbind().click(function() {
// we create prompt
- var msg = '';
- msg += '
';
- msg += '
';
- msg += '
'+lg.file_size_limit + config.upload.fileSizeLimit + ' ' + lg.mb + '.
';
+ var msg = '
' +
+ '
' +
+ '
' +
+ '
' + lg.file_size_limit +
+ config.upload.fileSizeLimit + ' ' + lg.mb + '.
',
+ error_flag = false,
+ path = $('.currentpath').val(),
+ filesizelimit = config.upload.fileSizeLimit,
+ // default dropzone value
+ fileSize = (filesizelimit != 'auto') ? filesizelimit : 256,
+ acceptFiles;
- error_flag = false;
- var path = $('.currentpath').val(),
- fileSize = (config.upload.fileSizeLimit != 'auto') ? config.upload.fileSizeLimit : 256; // default dropzone value
-
- if(config.security.uploadPolicy == 'DISALLOW_ALL') {
- var allowedFiles = '.' + config.security.uploadRestrictions.join(',.');
+ if (config.security.uploadPolicy == 'DISALLOW_ALL') {
+ acceptFiles = '.' + config.security.uploadRestrictions.join(',.');
} else {
- // we allow any extension since we have no easy way to handle the the built-in `acceptedFiles` params
- // Would be handled later by the connector
- var allowedFiles = null;
+ // We allow any extension since we have no easy way to handle the the
+ // built-in `acceptedFiles` params would be handled later by the
+ // connector.
+ acceptFiles = null;
}
if ($.urlParam('type').toString().toLowerCase() == 'images' || config.upload.imagesOnly) {
- var allowedFiles = '.' + config.images.imagesExt.join(',.');
+ acceptFiles = '.' + config.images.imagesExt.join(',.');
}
$('.file_manager .upload_file').toggle();
@@ -1507,16 +1636,16 @@ $(function(){
//var previewTemplate = '
';
var previewTemplate = '
'+
- '
'+
- '
'+
- '
'+
- '
'+
- '
'+
- '
'+
- '
';
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
';
$("div#multiple-uploads").dropzone({
paramName: "newfile",
@@ -1526,18 +1655,21 @@ $(function(){
addRemoveLinks: true,
previewTemplate: previewTemplate,
parallelUploads: config.upload.number,
- dictMaxFilesExceeded: lg.dz_dictMaxFilesExceeded.replace("%s", config.upload.number),
+ dictMaxFilesExceeded: lg.dz_dictMaxFilesExceeded.replace(
+ "%s", config.upload.number
+ ),
dictDefaultMessage: lg.dz_dictDefaultMessage,
dictInvalidFileType: lg.dz_dictInvalidFileType,
- dictFileTooBig: lg.file_too_big + ' ' + lg.file_size_limit + config.upload.fileSizeLimit + ' ' + lg.mb,
- acceptedFiles: allowedFiles,
+ dictFileTooBig: lg.file_too_big + ' ' + lg.file_size_limit +
+ config.upload.fileSizeLimit + ' ' + lg.mb,
+ acceptedFiles: acceptFiles,
autoProcessQueue: true,
init: function() {
var dropzone = this;
+
$('.dz_cross_btn').unbind().on('click', function() {
$('.file_manager .upload_file').toggle();
});
-
},
sending: function(file, xhr, formData) {
formData.append("mode", "add");
@@ -1550,8 +1682,8 @@ $(function(){
data = response.data.result,
$this = $(file.previewTemplate);
- if (data['Code'] == 0) {
- setTimeout(function(){
+ if (data.Code == 0) {
+ setTimeout(function() {
$this.find(".dz-upload").addClass("success");
}, 1000);
$this.find(".dz-upload").css('width', "100%").html("100%");
@@ -1559,15 +1691,16 @@ $(function(){
} else {
$this.find(".dz-upload").addClass("error");
$this.find(".dz-upload").css('width', "0%").html("0%");
- alertify.error(data['Error']);
+ alertify.error(data.Error);
}
getFolderInfo(path);
},
- totaluploadprogress: function(progress) {
- },
+ totaluploadprogress: function(progress) {},
complete: function(file) {
- if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
- }
+ if (
+ this.getUploadingFiles().length === 0 &&
+ this.getQueuedFiles().length === 0
+ ) {}
if (file.status == "error") {
alertify.error(lg.ERROR_UPLOADING_FILE);
}
@@ -1575,14 +1708,15 @@ $(function(){
getFolderInfo(path);
}
});
-
});
}
// Disable select function if no window.opener
- if(! (window.opener || window.tinyMCEPopup) ) $('#itemOptions a[href$="#select"]').remove();
+ if (! (window.opener || window.tinyMCEPopup) ) {
+ $('#itemOptions a[href$="#select"]').remove();
+ }
// Keep only browseOnly features if needed
- if(config.options.browseOnly == true) {
+ if (config.options.browseOnly == true) {
$('.newfile').remove();
$('.upload').remove();
$('.create').remove();
diff --git a/web/pgadmin/static/css/overrides.css b/web/pgadmin/static/css/overrides.css
index d37db64fc..1d6fe2477 100755
--- a/web/pgadmin/static/css/overrides.css
+++ b/web/pgadmin/static/css/overrides.css
@@ -1156,3 +1156,12 @@ form[name="change_password_form"] .help-block {
height: 32px;
padding-left: 5px;
}
+
+/* Overriding the css for the dropzone */
+.dropzone .dz-preview .dz-progress {
+ height: initial;
+}
+
+.dropzone .dz-preview .dz-progress .dz-upload {
+ bottom: initial;
+}
diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/index.html b/web/pgadmin/tools/datagrid/templates/datagrid/index.html
index ddb9d8f8e..6813b70cd 100644
--- a/web/pgadmin/tools/datagrid/templates/datagrid/index.html
+++ b/web/pgadmin/tools/datagrid/templates/datagrid/index.html
@@ -17,6 +17,9 @@ body {
+
+
+
diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py
index 3917f3dbf..f1068471d 100644
--- a/web/pgadmin/tools/sqleditor/__init__.py
+++ b/web/pgadmin/tools/sqleditor/__init__.py
@@ -13,6 +13,7 @@ MODULE_NAME = 'sqleditor'
import json
import pickle
import random
+import os
from flask import Response, url_for, render_template, session, request
from flask.ext.babel import gettext
from flask.ext.security import login_required
@@ -21,7 +22,13 @@ from pgadmin.utils.ajax import make_json_response, bad_request, success_return,
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.tools.sqleditor.command import QueryToolCommand
+from pgadmin.utils import get_storage_directory
+# import unquote from urlib for python2.x and python3.x
+try:
+ from urllib import unquote
+except Exception as e:
+ from urllib.parse import unquote
# Async Constants
ASYNC_OK = 1
@@ -44,7 +51,7 @@ class SqlEditorModule(PgAdminModule):
A module class for SQL Grid derived from PgAdminModule.
"""
- LABEL = "SQL Editor"
+ LABEL = gettext("SQL Editor")
def get_own_menuitems(self):
return {}
@@ -949,3 +956,87 @@ def is_begin_required(query):
return True
return True
+
+
+@blueprint.route('/load_file/', methods=["PUT", "POST"])
+@login_required
+def load_file():
+ """
+ This function gets name of file from request data
+ reads the data and sends back in reponse
+ """
+ if request.data:
+ file_data = json.loads(request.data.decode())
+
+ # retrieve storage directory path
+ storage_manager_path = get_storage_directory()
+
+ # generate full path of file
+ file_path = os.path.join(
+ storage_manager_path,
+ unquote(file_data['file_name'])
+ )
+ file_data = None
+
+ # read file
+ try:
+ with open(file_path, 'r') as myfile:
+ file_data = myfile.read()
+ except IOError as e:
+ # we don't want to expose real path of file
+ # so only show error message.
+ if e.strerror == 'Permission denied':
+ err_msg = "Error: {0}".format(e.strerror)
+ else:
+ err_msg = "Error: {0}".format(e.strerror)
+ return internal_server_error(errormsg=err_msg)
+ except Exception as e:
+ err_msg = "Error: {0}".format(e.strerror)
+ return internal_server_error(errormsg=err_msg)
+ return make_json_response(
+ data={
+ 'status': True, 'result': file_data,
+ }
+ )
+
+
+@blueprint.route('/save_file/', methods=["PUT", "POST"])
+@login_required
+def save_file():
+ """
+ This function retrieves file_name and data from request.
+ and then save the data to the file
+ """
+ if request.data:
+ file_data = json.loads(request.data.decode())
+
+ # retrieve storage directory path
+ storage_manager_path = get_storage_directory()
+
+ # generate full path of file
+ file_path = os.path.join(
+ storage_manager_path,
+ unquote(file_data['file_name'])
+ )
+ file_content = file_data['file_content']
+ file_data = None
+
+ # write to file
+ try:
+ with open(file_path, 'w') as output_file:
+ output_file.write(file_content)
+ except IOError as e:
+ if e.strerror == 'Permission denied':
+ err_msg = "Error: {0}".format(e.strerror)
+ else:
+ err_msg = "Error: {0}".format(e.strerror)
+ return internal_server_error(errormsg=err_msg)
+ except Exception as e:
+ err_msg = "Error: {0}".format(e.strerror)
+ return internal_server_error(errormsg=err_msg)
+
+ return make_json_response(
+ data={
+ 'status': True,
+ }
+ )
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
index ee533a1ea..8c2aade0f 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
@@ -3,7 +3,7 @@ define(
'codemirror/mode/sql/sql', 'codemirror/addon/selection/mark-selection', 'codemirror/addon/selection/active-line',
'codemirror/addon/fold/foldgutter', 'codemirror/addon/fold/foldcode', 'codemirror/addon/fold/pgadmin-sqlfoldcode',
'backgrid.select.all', 'backbone.paginator', 'backgrid.paginator', 'backgrid.filter',
- 'bootstrap', 'pgadmin.browser', 'wcdocker'],
+ 'bootstrap', 'pgadmin.browser', 'wcdocker', 'pgadmin.file_manager'],
function($, _, alertify, pgAdmin, Backbone, Backgrid, CodeMirror) {
// Some scripts do export their object in the window only.
@@ -143,6 +143,7 @@ define(
// Bind all the events
events: {
+ "click .btn-load-file": "on_file_load",
"click #btn-save": "on_save",
"click #btn-add-row": "on_add",
"click #btn-filter": "on_show_filter",
@@ -641,7 +642,20 @@ define(
},
do_not_close_menu: function(ev) {
ev.stopPropagation();
- }
+ },
+
+ // callback function for load file button click.
+ on_file_load: function() {
+ var self = this;
+
+ // Trigger the save signal to the SqlEditorController class
+ self.handler.trigger(
+ 'pgadmin-sqleditor:button:load_file',
+ self,
+ self.handler
+ );
+ },
+
});
/* Defining controller class for data grid, which actually
@@ -683,11 +697,22 @@ define(
self.transId = self.container.data('transId');
self.gridView.editor_title = editor_title;
+ self.gridView.current_file = undefined;
// Render the header
self.gridView.render();
+ // Listen to the file manager button events
+ pgAdmin.Browser.Events.on('pgadmin-storage:finish_btn:select_file', self._select_file_handler, self);
+ pgAdmin.Browser.Events.on('pgadmin-storage:finish_btn:create_file', self._save_file_handler, self);
+
+ // Listen to the codemirror on text change event
+ // only in query editor tool
+ if (self.is_query_tool)
+ self.gridView.query_tool_obj.on('change', self._on_query_change, self);
+
// Listen on events come from SQLEditorView for the button clicked.
+ self.on('pgadmin-sqleditor:button:load_file', self._load_file, self);
self.on('pgadmin-sqleditor:button:save', self._save, self);
self.on('pgadmin-sqleditor:button:addrow', self._add, self);
self.on('pgadmin-sqleditor:button:show_filter', self._show_filter, self);
@@ -1297,12 +1322,34 @@ define(
/* This function will fetch the list of changed models and make
* the ajax call to save the data into the database server.
+ * and will open save file dialog conditionally.
*/
_save: function() {
var self = this,
data = [],
save_data = true;
+ // Open save file dialog if query tool
+ if (self.is_query_tool) {
+
+ var current_file = self.gridView.current_file;
+ if (!_.isUndefined(current_file)) {
+ self._save_file_handler(current_file);
+ }
+ else {
+ // provide custom option to save file dialog
+ var params = {
+ 'supported_types': ["*", "sql"],
+ 'dialog_type': 'create_file',
+ 'dialog_title': 'Save File',
+ 'btn_primary': 'Save'
+ }
+ pgAdmin.FileManager.init();
+ pgAdmin.FileManager.show_dialog(params);
+ }
+ return;
+ }
+
$("#btn-save").prop('disabled', true);
if (self.changedModels.length == 0)
return;
@@ -1395,6 +1442,87 @@ define(
}
},
+ // load select file dialog
+ _load_file: function() {
+ var params = {
+ 'supported_types': ["sql"], // file types allowed
+ 'dialog_type': 'select_file' // open select file dialog
+ }
+ pgAdmin.FileManager.init();
+ pgAdmin.FileManager.show_dialog(params);
+ },
+
+ // read file data and return as response
+ _select_file_handler: function(e) {
+ var self = this;
+
+ data = {
+ 'file_name': e
+ }
+
+ // Make ajax call to load the data from file
+ $.ajax({
+ url: "{{ url_for('sqleditor.index') }}" + "load_file/",
+ method: 'POST',
+ async: false,
+ contentType: "application/json",
+ data: JSON.stringify(data),
+ success: function(res) {
+ if (res.data.status) {
+ self.gridView.query_tool_obj.setValue(res.data.result);
+ self.gridView.current_file = e;
+ }
+ },
+ error: function(e) {
+ var errmsg = $.parseJSON(e.responseText).errormsg;
+ alertify.error(errmsg);
+ }
+ });
+ },
+
+ // read data from codemirror and write to file
+ _save_file_handler: function(e) {
+ var self = this;
+ data = {
+ 'file_name': e,
+ 'file_content': self.gridView.query_tool_obj.getValue()
+ }
+
+ // Make ajax call to save the data to file
+ $.ajax({
+ url: "{{ url_for('sqleditor.index') }}" + "save_file/",
+ method: 'POST',
+ async: false,
+ contentType: "application/json",
+ data: JSON.stringify(data),
+ success: function(res) {
+ if (res.data.status) {
+ alertify.success('{{ _('File saved successfully.') }}');
+ self.gridView.current_file = e;
+
+ // disable save button on file save
+ $("#btn-save").prop('disabled', true);
+ }
+ },
+ error: function(e) {
+ var errmsg = $.parseJSON(e.responseText).errormsg;
+ alertify.error(errmsg);
+ }
+ });
+ },
+
+ // codemirror text change event
+ _on_query_change: function(query_tool_obj) {
+
+ if(query_tool_obj.getValue().length == 0) {
+ $("#btn-save").prop('disabled', true);
+ }
+ else {
+ $("#btn-save").prop('disabled', false);
+ }
+ },
+
+
// This function will run the SQL query and refresh the data in the backgrid.
_refresh: function() {
var self = this;
@@ -1696,6 +1824,7 @@ define(
$("#btn-query-dropdown").prop('disabled', disabled);
$("#btn-edit-dropdown").prop('disabled', disabled);
$("#btn-edit").prop('disabled', disabled);
+ $('#btn-load-file').prop('disabled', disabled);
},
// This function will fetch the sql query from the text box