1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-14 14:21:23 +00:00

[dir view] clean up views/dirent.js, views/dirent-grid.js

This commit is contained in:
llj
2016-03-03 17:47:36 +08:00
parent 9a89536ae5
commit abec40b07c
2 changed files with 14 additions and 195 deletions

View File

@@ -7,7 +7,7 @@ define([
'app/views/share', 'app/views/share',
'app/views/folder-perm', 'app/views/folder-perm',
'app/views/dialogs/dirent-mvcp', 'app/views/dialogs/dirent-mvcp',
'app/views/dialogs/dirent-rename', 'app/views/dialogs/dirent-rename'
], function($, _, Backbone, Common, FileTree, ShareView, FolderPermView, ], function($, _, Backbone, Common, FileTree, ShareView, FolderPermView,
DirentMvcpDialog, DirentRenameDialog) { DirentMvcpDialog, DirentRenameDialog) {
'use strict'; 'use strict';
@@ -25,10 +25,6 @@ define([
fileOpTemplate: _.template($('#grid-view-file-op-tmpl').html()), fileOpTemplate: _.template($('#grid-view-file-op-tmpl').html()),
renameTemplate: _.template($("#dirent-rename-dialog-template").html()), renameTemplate: _.template($("#dirent-rename-dialog-template").html()),
// renameTemplate: _.template($("#grid-rename-form-template").html()),
// mvcpTemplate: _.template($("#mvcp-form-template").html()),
// mvProgressTemplate: _.template($("#mv-progress-popup-template").html()),
initialize: function(options) { initialize: function(options) {
this.dirView = options.dirView; this.dirView = options.dirView;
this.dir = this.dirView.dir; this.dir = this.dirView.dir;
@@ -68,22 +64,8 @@ define([
events: { events: {
'mouseenter': 'highlight', 'mouseenter': 'highlight',
'mouseleave': 'rmHighlight', 'mouseleave': 'rmHighlight',
//'mousedown .img-link': 'showPopupMenu',
//'mousedown .text-link': 'showPopupMenu'
'contextmenu .img-link': 'showPopupMenu', 'contextmenu .img-link': 'showPopupMenu',
'contextmenu .text-link': 'showPopupMenu' 'contextmenu .text-link': 'showPopupMenu'
/*
'click .dir-link': 'visitDir',
'click .share': 'share',
'click .delete': 'del', // 'delete' is a preserve word
'click .rename': 'rename',
'click .mv': 'mvcp',
'click .cp': 'mvcp',
'click .set-folder-permission': 'setFolderPerm',
'click .lock-file': 'lockFile',
'click .unlock-file': 'unlockFile'
*/
}, },
highlight: function() { highlight: function() {
@@ -184,8 +166,8 @@ define([
return false; return false;
}, },
mvcp: function(event) { mvcp: function(e) {
var op_type = $(event.target).hasClass('mv') ? 'mv' : 'cp'; var op_type = $(e.currentTarget).hasClass('mv') ? 'mv' : 'cp';
var options = { var options = {
'dir': this.dir, 'dir': this.dir,
'dirent': this.model, 'dirent': this.model,

View File

@@ -5,8 +5,10 @@ define([
'common', 'common',
'file-tree', 'file-tree',
'app/views/share', 'app/views/share',
'app/views/dialogs/dirent-mvcp',
'app/views/folder-perm' 'app/views/folder-perm'
], function($, _, Backbone, Common, FileTree, ShareView, FolderPermView) { ], function($, _, Backbone, Common, FileTree, ShareView, DirentMvcpDialog,
FolderPermView) {
'use strict'; 'use strict';
app = app || {}; app = app || {};
@@ -73,7 +75,6 @@ define([
}, },
_hideMenu: function() { _hideMenu: function() {
//this.$('.hidden-op').addClass('hide');
this.$el.removeClass('hl').find('.repo-file-op').addClass('vh'); this.$el.removeClass('hl').find('.repo-file-op').addClass('vh');
this.$('.hidden-op').addClass('hide'); this.$('.hidden-op').addClass('hide');
}, },
@@ -270,179 +271,15 @@ define([
return false; return false;
}, },
mvcp: function(event) { mvcp: function(e) {
var dir = this.dir; var op_type = $(e.currentTarget).hasClass('mv') ? 'mv' : 'cp';
var el = event.target || event.srcElement, var options = {
op_type = $(el).hasClass('mv') ? 'mv' : 'cp', 'dir': this.dir,
obj_name = this.model.get('obj_name'), 'dirent': this.model,
obj_type = this.model.get('is_dir') ? 'dir' : 'file'; 'op_type': op_type
};
var title = op_type == 'mv' ? gettext("Move {placeholder} to:") : gettext("Copy {placeholder} to:"); new DirentMvcpDialog(options);
title = title.replace('{placeholder}', '<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(obj_name) + '">' + Common.HTMLescape(obj_name) + '</span>');
var show_cur_repo = true;
if (this.model.get('perm') == 'r') {
show_cur_repo = false;
}
var form = $(this.mvcpTemplate({
form_title: title,
op_type: op_type,
obj_type: obj_type,
obj_name: obj_name,
show_cur_repo: show_cur_repo,
show_other_repos: !dir.encrypted
}));
form.modal({appendTo:'#main', autoResize:true, focus:false});
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
if (show_cur_repo) {
FileTree.renderTreeForPath({
repo_name: dir.repo_name,
repo_id: dir.repo_id,
path: dir.path
});
}
if (!dir.encrypted) {
FileTree.prepareOtherReposTree({cur_repo_id: dir.repo_id});
}
var dirent = this.$el;
var _this = this;
form.submit(function() {
var form = $(this),
form_id = form.attr('id'),
path = dir.path,
repo_id = dir.repo_id;
var dst_repo = $('[name="dst_repo"]', form).val(),
dst_path = $('[name="dst_path"]', form).val(),
op = $('[name="op"]', form).val(),
obj_name = $('[name="obj_name"]', form).val(),
obj_type = $('[name="obj_type"]', form).val();
if (!$.trim(dst_repo) || !$.trim(dst_path)) {
$('.error', form).removeClass('hide');
return false;
}
if (dst_repo == repo_id && (dst_path == path || (obj_type == 'dir' && dst_path == path + obj_name + '/'))) {
$('.error', form).html(gettext("Invalid destination path")).removeClass('hide');
return false;
}
var options = { repo_id: repo_id };
if (obj_type == 'dir') {
options.name = op == 'mv' ? 'mv_dir' : 'cp_dir';
} else {
options.name = op == 'mv' ? 'mv_file' : 'cp_file';
}
var post_url = Common.getUrl(options) + '?path=' + encodeURIComponent(path) + '&obj_name=' + encodeURIComponent(obj_name);
var post_data = {
'dst_repo': dst_repo,
'dst_path': dst_path
};
var after_op_success = function(data) {
$.modal.close();
var msg = data['msg'];
if (!data['task_id']) { // no progress
if (op == 'mv') {
dirent.remove();
}
Common.feedback(msg, 'success');
} else {
var mv_progress_popup = $(_this.mvProgressTemplate());
var details = $('#mv-details', mv_progress_popup),
cancel_btn = $('#cancel-mv', mv_progress_popup),
other_info = $('#mv-other-info', mv_progress_popup);
cancel_btn.removeClass('hide');
setTimeout(function () {
mv_progress_popup.modal({containerCss: {
width: 300,
height: 150,
paddingTop: 50
}, focus:false});
var det_text = op == 'mv' ? gettext("Moving %(name)s") : gettext("Copying %(name)s");
details.html(det_text.replace('%(name)s', Common.HTMLescape(obj_name))).removeClass('vh');
$('#mv-progress').progressbar();
req_progress();
}, 100);
var req_progress = function () {
$.ajax({
url: Common.getUrl({name: 'get_cp_progress'}) + '?task_id=' + encodeURIComponent(data['task_id']),
dataType: 'json',
success: function(data) {
var bar = $('.ui-progressbar-value', $('#mv-progress'));
if (!data['failed'] && !data['canceled'] && !data['successful']) {
if (data['done'] == data['total']) {
bar.css('width', '100%'); // 'done' and 'total' can be both 0
details.addClass('vh');
cancel_btn.addClass('hide');
other_info.html(gettext("Saving...")).removeClass('hide');
} else {
bar.css('width', parseInt(data['done']/data['total']*100, 10) + '%');
}
bar.show();
setTimeout(req_progress, 1000);
} else if (data['successful']) {
$.modal.close();
if (op == 'mv') {
dirent.remove();
}
Common.feedback(msg, 'success');
} else { // failed or canceled
details.addClass('vh');
var other_msg = data['failed'] ? gettext("Failed.") : gettext("Canceled.");
other_info.html(other_msg).removeClass('hide');
cancel_btn.addClass('hide');
setTimeout(function () { $.modal.close(); }, 1000);
}
},
error: function(xhr, textStatus, errorThrown) {
var error;
if (xhr.responseText) {
error = $.parseJSON(xhr.responseText).error;
} else {
error = gettext("Failed. Please check the network.");
}
details.addClass('vh')
other_info.html(error).removeClass('hide');
cancel_btn.addClass('hide');
setTimeout(function () { $.modal.close(); }, 1000);
}
});
};
cancel_btn.click(function() {
Common.disableButton(cancel_btn);
$.ajax({
url: Common.getUrl({name: 'cancel_cp'}) + '?task_id=' + encodeURIComponent(data['task_id']),
dataType: 'json',
success: function(data) {
details.addClass('vh')
other_info.html(gettext("Canceled.")).removeClass('hide');
cancel_btn.addClass('hide');
setTimeout(function () {$.modal.close();}, 1000);
},
error: function(xhr, textStatus, errorThrown) {
var error;
if (xhr.responseText) {
error = $.parseJSON(xhr.responseText).error;
} else {
error = gettext("Failed. Please check the network.");
}
other_info.html(error).removeClass('hide');
Common.enableButton(cancel_btn);
}
});
});
}
}
Common.ajaxPost({
'form': form,
'post_url': post_url,
'post_data': post_data,
'after_op_success': after_op_success,
'form_id': form_id
});
return false;
});
return false; return false;
}, },