2015-01-25 10:47:42 +00:00
|
|
|
define([
|
2015-01-30 11:36:42 +00:00
|
|
|
'jquery',
|
2015-03-02 06:07:55 +00:00
|
|
|
'jquery.ui.progressbar',
|
2015-04-09 07:01:46 +00:00
|
|
|
'jquery.magnific-popup',
|
2015-02-11 06:45:59 +00:00
|
|
|
'simplemodal',
|
2015-01-30 11:36:42 +00:00
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
|
|
|
'file-tree',
|
|
|
|
'app/collections/dirents',
|
2015-02-01 06:15:00 +00:00
|
|
|
'app/views/dirent',
|
2015-02-13 08:33:19 +00:00
|
|
|
'app/views/fileupload',
|
2015-04-03 04:15:41 +00:00
|
|
|
'app/views/share'
|
2015-04-17 02:59:48 +00:00
|
|
|
], function($, progressbar, magnificPopup, simplemodal, _, Backbone, Common,
|
|
|
|
FileTree, DirentCollection, DirentView, FileUploadView, ShareView) {
|
2015-01-30 11:36:42 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var DirView = Backbone.View.extend({
|
|
|
|
el: $('#dir-view'),
|
2015-03-18 02:45:13 +00:00
|
|
|
|
2015-05-11 06:10:10 +00:00
|
|
|
path_bar_template: _.template($('#dir-path-bar-tmpl').html()),
|
2015-04-03 04:15:41 +00:00
|
|
|
dir_op_bar_template: _.template($('#dir-op-bar-tmpl').html()),
|
2015-05-11 06:10:10 +00:00
|
|
|
dirents_hd_template: _.template($('#dirents-hd-tmpl').html()),
|
|
|
|
|
2015-01-30 11:47:17 +00:00
|
|
|
newDirTemplate: _.template($("#add-new-dir-form-template").html()),
|
|
|
|
newFileTemplate: _.template($("#add-new-file-form-template").html()),
|
2015-03-02 06:07:55 +00:00
|
|
|
mvcpTemplate: _.template($("#mvcp-form-template").html()),
|
|
|
|
mvProgressTemplate: _.template($("#mv-progress-popup-template").html()),
|
2015-01-30 11:36:42 +00:00
|
|
|
|
|
|
|
initialize: function(options) {
|
|
|
|
this.$dirent_list = this.$('.repo-file-list tbody');
|
|
|
|
this.$path_bar = this.$('.path');
|
|
|
|
// For compatible with css, we use .repo-op instead of .dir-op
|
|
|
|
this.$dir_op_bar = this.$('.repo-op');
|
|
|
|
|
|
|
|
this.dir = new DirentCollection();
|
|
|
|
this.listenTo(this.dir, 'add', this.addOne);
|
|
|
|
this.listenTo(this.dir, 'reset', this.reset);
|
|
|
|
|
2015-02-13 08:33:19 +00:00
|
|
|
this.fileUploadView = new FileUploadView({dirView: this});
|
|
|
|
|
2015-04-09 07:01:46 +00:00
|
|
|
this.$el.magnificPopup({
|
|
|
|
type: 'image',
|
|
|
|
delegate: '.img-name-link',
|
|
|
|
tClose: gettext("Close (Esc)"), // Alt text on close button
|
|
|
|
tLoading: gettext("Loading..."), // Text that is displayed during loading. Can contain %curr% and %total% keys
|
|
|
|
gallery: {
|
|
|
|
enabled: true,
|
|
|
|
tPrev: gettext("Previous (Left arrow key)"), // Alt text on left arrow
|
|
|
|
tNext: gettext("Next (Right arrow key)"), // Alt text on right arrow
|
|
|
|
tCounter: gettext("%curr% of %total%") // Markup for "1 of 7" counter
|
|
|
|
},
|
|
|
|
image: {
|
|
|
|
titleSrc: function(item) {
|
|
|
|
var el = item.el;
|
|
|
|
var img_name = el[0].innerHTML;
|
|
|
|
var img_link = '<a href="' + el.attr('href') + '" target="_blank">' + gettext("Open in New Tab") + '</a>';
|
|
|
|
return img_name + '<br />' + img_link;
|
|
|
|
},
|
|
|
|
tError: gettext('<a href="%url%" target="_blank">The image</a> could not be loaded.') // Error message when image could not be loaded
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-06 03:59:44 +00:00
|
|
|
// scroll window: get 'more', fix 'op bar'
|
2015-02-03 05:47:22 +00:00
|
|
|
var _this = this;
|
|
|
|
$(window).scroll(function() {
|
|
|
|
if ($(_this.el).is(':visible')) {
|
|
|
|
_this.onWindowScroll();
|
|
|
|
}
|
|
|
|
});
|
2015-02-06 06:25:36 +00:00
|
|
|
|
|
|
|
// hide 'hidden-op' popup
|
|
|
|
app.globalState.noFileOpPopup = true;
|
|
|
|
$(document).click(function(e) {
|
|
|
|
var target = e.target || event.srcElement;
|
|
|
|
var popup = $('.hidden-op');
|
|
|
|
if (!app.globalState.noFileOpPopup &&
|
|
|
|
!$('.more-op-icon, .hidden-op').is(target) &&
|
|
|
|
!popup.find('*').is(target)) {
|
|
|
|
popup.addClass('hide');
|
|
|
|
app.globalState.noFileOpPopup = true;
|
|
|
|
if (!app.globalState.popup_tr.find('*').is(target)) {
|
|
|
|
app.globalState.popup_tr.removeClass('hl').find('.repo-file-op').addClass('vh'); // clicked place: the first tr, place out of the table
|
|
|
|
$('.repo-file-list tr:gt(0)').each(function() { // when other tr is clicked
|
|
|
|
if ($(this).find('*').is(target)) {
|
|
|
|
$(this).addClass('hl').find('.repo-file-op').removeClass('vh');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-01-30 11:36:42 +00:00
|
|
|
},
|
|
|
|
|
2015-02-06 09:32:02 +00:00
|
|
|
showDir: function(category, repo_id, path) {
|
2015-01-30 11:36:42 +00:00
|
|
|
this.$el.show();
|
2015-03-22 14:39:39 +00:00
|
|
|
this.$dirent_list.empty();
|
2015-03-23 10:11:24 +00:00
|
|
|
var loading_tip = this.$('.loading-tip').show();
|
|
|
|
var dir = this.dir;
|
2015-02-06 09:32:02 +00:00
|
|
|
dir.setPath(category, repo_id, path);
|
2015-03-23 10:11:24 +00:00
|
|
|
var _this = this;
|
2015-02-03 05:47:22 +00:00
|
|
|
dir.fetch({
|
|
|
|
reset: true,
|
|
|
|
data: {'p': path},
|
|
|
|
success: function (collection, response, opts) {
|
|
|
|
dir.last_start = 0; // for 'more'
|
|
|
|
if (response.dirent_list.length == 0 || // the dir is empty
|
|
|
|
!response.dirent_more ) { // no 'more'
|
|
|
|
loading_tip.hide();
|
|
|
|
}
|
|
|
|
},
|
2015-03-23 10:11:24 +00:00
|
|
|
error: function (collection, response, opts) {
|
2015-02-03 05:47:22 +00:00
|
|
|
loading_tip.hide();
|
2015-03-23 10:11:24 +00:00
|
|
|
var $el_con = _this.$('.repo-file-list-topbar, .repo-file-list').hide();
|
|
|
|
var $error = _this.$('.error');
|
|
|
|
var err_msg;
|
2015-05-11 06:25:06 +00:00
|
|
|
var lib_need_decrypt = false;
|
2015-03-23 10:11:24 +00:00
|
|
|
if (response.responseText) {
|
2015-04-02 02:58:59 +00:00
|
|
|
if (response.responseJSON.lib_need_decrypt) {
|
2015-05-11 06:25:06 +00:00
|
|
|
lib_need_decrypt = true;
|
2015-04-02 02:58:59 +00:00
|
|
|
} else {
|
|
|
|
err_msg = response.responseJSON.error;
|
|
|
|
}
|
2015-03-23 10:11:24 +00:00
|
|
|
} else {
|
|
|
|
err_msg = gettext('Please check the network.');
|
|
|
|
}
|
2015-04-02 02:58:59 +00:00
|
|
|
if (err_msg) {
|
|
|
|
$error.html(err_msg).show();
|
|
|
|
}
|
2015-03-23 10:11:24 +00:00
|
|
|
|
2015-05-11 06:25:06 +00:00
|
|
|
if (lib_need_decrypt) {
|
2015-03-23 10:11:24 +00:00
|
|
|
var form = $($('#repo-decrypt-form-template').html());
|
2015-05-08 06:45:04 +00:00
|
|
|
var decrypt_success = false;
|
|
|
|
form.modal({
|
|
|
|
containerCss: {'padding': '1px'},
|
|
|
|
onClose: function () {
|
|
|
|
$.modal.close();
|
2015-05-11 06:25:06 +00:00
|
|
|
$el_con.show();
|
2015-05-08 06:45:04 +00:00
|
|
|
if (!decrypt_success) {
|
|
|
|
app.router.navigate(
|
|
|
|
category + '/', // need to append '/' at end
|
|
|
|
{trigger: true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-04-02 02:58:59 +00:00
|
|
|
$('#simplemodal-container').css({'height':'auto'});
|
2015-03-23 10:11:24 +00:00
|
|
|
form.submit(function() {
|
|
|
|
var passwd = $.trim($('[name="password"]', form).val());
|
|
|
|
if (!passwd) {
|
|
|
|
$('.error', form).html(gettext("Password is required.")).removeClass('hide');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Common.ajaxPost({
|
|
|
|
form: form,
|
|
|
|
form_id: form.attr('id'),
|
|
|
|
post_url: Common.getUrl({'name':'repo_set_password'}),
|
|
|
|
post_data: {
|
|
|
|
repo_id: repo_id,
|
|
|
|
password: passwd,
|
|
|
|
username: app.pageOptions.username
|
|
|
|
},
|
|
|
|
after_op_success: function() {
|
2015-05-08 06:45:04 +00:00
|
|
|
decrypt_success = true;
|
2015-04-02 02:58:59 +00:00
|
|
|
$.modal.close();
|
2015-03-23 10:11:24 +00:00
|
|
|
_this.showDir(category, repo_id, path);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2015-02-03 05:47:22 +00:00
|
|
|
}
|
|
|
|
});
|
2015-01-30 11:36:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this.$el.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
addOne: function(dirent) {
|
|
|
|
var view = new DirentView({model: dirent, dirView: this});
|
|
|
|
this.$dirent_list.append(view.render().el);
|
|
|
|
},
|
|
|
|
|
|
|
|
reset: function() {
|
|
|
|
this.dir.each(this.addOne, this);
|
|
|
|
this.renderPath();
|
|
|
|
this.renderDirOpBar();
|
2015-05-11 06:10:10 +00:00
|
|
|
this.renderDirentsHd();
|
2015-02-13 08:33:19 +00:00
|
|
|
this.fileUploadView.setFileInput();
|
2015-04-10 06:40:27 +00:00
|
|
|
this.getImageThumbnail();
|
2015-03-30 09:00:54 +00:00
|
|
|
},
|
|
|
|
|
2015-04-10 06:40:27 +00:00
|
|
|
getImageThumbnail: function() {
|
|
|
|
var images_with_no_thumbnail = this.dir.filter(function(dirent) {
|
|
|
|
// 'dirent' is a model
|
2015-07-16 05:09:52 +00:00
|
|
|
return dirent.get('is_img') && !dirent.get('encoded_thumbnail_src');
|
2015-04-10 06:40:27 +00:00
|
|
|
});
|
|
|
|
if (images_with_no_thumbnail.length == 0) {
|
|
|
|
return ;
|
2015-03-30 09:00:54 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 06:40:27 +00:00
|
|
|
var images_len = images_with_no_thumbnail.length,
|
|
|
|
repo_id = this.dir.repo_id,
|
|
|
|
cur_path = this.dir.path,
|
|
|
|
_this = this;
|
2015-03-30 09:00:54 +00:00
|
|
|
var get_thumbnail = function(i) {
|
2015-04-10 06:40:27 +00:00
|
|
|
var cur_img = images_with_no_thumbnail[i];
|
|
|
|
var cur_img_path = Common.pathJoin([cur_path, cur_img.get('obj_name')]);
|
2015-03-30 09:00:54 +00:00
|
|
|
$.ajax({
|
|
|
|
url: Common.getUrl({name: 'thumbnail_create', repo_id: repo_id}),
|
2015-04-10 06:40:27 +00:00
|
|
|
data: {'path': cur_img_path},
|
2015-03-30 09:00:54 +00:00
|
|
|
cache: false,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
2015-04-10 06:40:27 +00:00
|
|
|
cur_img.set({
|
2015-07-16 05:09:52 +00:00
|
|
|
'encoded_thumbnail_src': data.encoded_thumbnail_src
|
2015-03-30 09:00:54 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
complete: function() {
|
2015-04-10 06:40:27 +00:00
|
|
|
// cur path may be changed. e.g., the user enter another directory
|
|
|
|
if (i < images_len - 1 &&
|
|
|
|
_this.dir.repo_id == repo_id &&
|
|
|
|
_this.dir.path == cur_path) {
|
2015-03-30 09:00:54 +00:00
|
|
|
get_thumbnail(++i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
get_thumbnail(0);
|
2015-01-30 11:36:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
renderPath: function() {
|
2015-04-11 09:35:02 +00:00
|
|
|
var dir = this.dir;
|
|
|
|
var path = dir.path;
|
|
|
|
var context = 'my';
|
|
|
|
|
2015-04-14 05:25:10 +00:00
|
|
|
var category_start = dir.category.split('/')[0];
|
|
|
|
if (category_start == 'org') {
|
2015-04-11 09:35:02 +00:00
|
|
|
context = 'org';
|
2015-04-14 05:25:10 +00:00
|
|
|
} else if (category_start == 'group') {
|
2015-04-11 09:35:02 +00:00
|
|
|
context = 'group';
|
2015-04-25 07:39:06 +00:00
|
|
|
} else if (category_start == 'common') {
|
|
|
|
context = 'common';
|
2015-04-11 09:35:02 +00:00
|
|
|
}
|
|
|
|
var obj = {
|
2015-02-13 08:33:19 +00:00
|
|
|
path: path,
|
|
|
|
repo_name: dir.repo_name,
|
2015-04-11 09:35:02 +00:00
|
|
|
category: dir.category,
|
|
|
|
context: context
|
2015-02-13 08:33:19 +00:00
|
|
|
};
|
2015-01-30 11:47:17 +00:00
|
|
|
|
2015-04-08 10:26:23 +00:00
|
|
|
var path_list = path.substr(1).split('/');
|
2015-07-02 09:38:36 +00:00
|
|
|
var path_list_encoded = Common.encodePath(path.substr(1)).split('/');
|
2015-01-30 11:36:42 +00:00
|
|
|
if (path != '/') {
|
|
|
|
$.extend(obj, {
|
2015-04-08 10:26:23 +00:00
|
|
|
path_list: path_list,
|
|
|
|
path_list_encoded: path_list_encoded,
|
|
|
|
repo_id: dir.repo_id
|
2015-01-30 11:36:42 +00:00
|
|
|
});
|
|
|
|
}
|
2015-01-30 11:47:17 +00:00
|
|
|
|
2015-01-30 11:36:42 +00:00
|
|
|
this.$path_bar.html(this.path_bar_template(obj));
|
|
|
|
},
|
|
|
|
|
|
|
|
renderDirOpBar: function() {
|
2015-05-27 09:09:29 +00:00
|
|
|
var dir = this.dir;
|
2015-01-30 11:47:17 +00:00
|
|
|
|
2015-01-30 11:36:42 +00:00
|
|
|
this.$dir_op_bar.html($.trim(this.dir_op_bar_template({
|
2015-05-27 09:09:29 +00:00
|
|
|
user_perm: dir.user_perm,
|
2015-01-30 11:36:42 +00:00
|
|
|
encrypted: dir.encrypted,
|
|
|
|
path: dir.path,
|
2015-02-07 08:50:33 +00:00
|
|
|
repo_id: dir.repo_id,
|
2015-03-13 02:48:59 +00:00
|
|
|
site_root: app.pageOptions.site_root,
|
|
|
|
is_repo_owner: dir.is_repo_owner,
|
2015-05-27 09:09:29 +00:00
|
|
|
is_virtual: dir.is_virtual,
|
2015-06-12 08:04:10 +00:00
|
|
|
can_generate_shared_link: app.pageOptions.can_generate_shared_link,
|
2015-02-12 08:38:57 +00:00
|
|
|
enable_upload_folder: app.pageOptions.enable_upload_folder
|
2015-01-30 11:36:42 +00:00
|
|
|
})));
|
|
|
|
},
|
|
|
|
|
2015-05-11 06:10:10 +00:00
|
|
|
renderDirentsHd: function() {
|
|
|
|
this.$('thead').html(this.dirents_hd_template());
|
|
|
|
},
|
|
|
|
|
2015-01-30 11:36:42 +00:00
|
|
|
// Directory Operations
|
|
|
|
events: {
|
|
|
|
'click .path-link': 'visitDir',
|
|
|
|
'click #upload-file': 'uploadFile',
|
|
|
|
'click #add-new-dir': 'newDir',
|
|
|
|
'click #add-new-file': 'newFile',
|
|
|
|
'click #share-cur-dir': 'share',
|
|
|
|
'click th.select': 'select',
|
|
|
|
'click #mv-dirents': 'mv',
|
2015-03-02 06:07:55 +00:00
|
|
|
'click #cp-dirents': 'cp',
|
|
|
|
'click #del-dirents': 'del',
|
2015-07-09 09:16:10 +00:00
|
|
|
'click .by-name': 'sortByName',
|
|
|
|
'click .by-time': 'sortByTime'
|
2015-01-30 11:36:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
newDir: function() {
|
2015-01-30 11:47:17 +00:00
|
|
|
var form = $(this.newDirTemplate()),
|
|
|
|
form_id = form.attr('id'),
|
|
|
|
dir = this.dir,
|
|
|
|
dirView = this;
|
|
|
|
|
|
|
|
form.modal({appendTo:'#main'});
|
|
|
|
$('#simplemodal-container').css({'height':'auto'});
|
|
|
|
|
|
|
|
form.submit(function() {
|
2015-02-07 08:50:33 +00:00
|
|
|
var dirent_name = $.trim($('input[name="name"]', form).val());
|
2015-01-30 11:47:17 +00:00
|
|
|
|
|
|
|
if (!dirent_name) {
|
2015-01-31 04:07:49 +00:00
|
|
|
Common.showFormError(form_id, gettext("It is required."));
|
|
|
|
return false;
|
2015-01-30 11:47:17 +00:00
|
|
|
};
|
|
|
|
|
2015-02-07 08:50:33 +00:00
|
|
|
var post_data = {'dirent_name': dirent_name},
|
|
|
|
post_url = Common.getUrl({name: "new_dir", repo_id: dir.repo_id})
|
|
|
|
+ '?parent_dir=' + encodeURIComponent(dir.path);
|
2015-01-30 11:47:17 +00:00
|
|
|
var after_op_success = function(data) {
|
|
|
|
$.modal.close();
|
|
|
|
|
|
|
|
var new_dirent = dir.add({
|
|
|
|
'is_dir': true,
|
|
|
|
'obj_name': data['name'],
|
2015-05-27 06:16:07 +00:00
|
|
|
'perm': 'rw',
|
2015-01-30 11:47:17 +00:00
|
|
|
'last_modified': new Date().getTime() / 1000,
|
|
|
|
'last_update': gettext("Just now"),
|
|
|
|
'p_dpath': data['p_dpath']
|
|
|
|
}, {silent:true});
|
2015-02-13 08:33:19 +00:00
|
|
|
dirView.addNewDir(new_dirent);
|
2015-01-30 11:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Common.ajaxPost({
|
|
|
|
'form': form,
|
|
|
|
'post_url': post_url,
|
|
|
|
'post_data': post_data,
|
|
|
|
'after_op_success': after_op_success,
|
|
|
|
'form_id': form_id
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
2015-01-30 11:36:42 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-01-30 11:47:17 +00:00
|
|
|
newFile: function() {
|
|
|
|
var form = $(this.newFileTemplate()),
|
|
|
|
form_id = form.attr('id'),
|
|
|
|
file_name = form.find('input[name="name"]'),
|
|
|
|
dir = this.dir,
|
|
|
|
dirView = this;
|
|
|
|
|
2015-02-07 08:50:33 +00:00
|
|
|
form.modal({
|
|
|
|
appendTo: '#main',
|
|
|
|
focus: false,
|
|
|
|
containerCss: {'padding':'20px 25px'}
|
|
|
|
});
|
2015-01-30 11:47:17 +00:00
|
|
|
$('#simplemodal-container').css({'height':'auto'});
|
|
|
|
|
2015-02-07 08:50:33 +00:00
|
|
|
$('.set-file-type', form).click(function() {
|
2015-01-30 11:47:17 +00:00
|
|
|
file_name.val('.' + $(this).data('filetype'));
|
|
|
|
Common.setCaretPos(file_name[0], 0);
|
|
|
|
file_name.focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
form.submit(function() {
|
2015-02-07 08:50:33 +00:00
|
|
|
var dirent_name = $.trim(file_name.val());
|
2015-01-30 11:47:17 +00:00
|
|
|
|
|
|
|
if (!dirent_name) {
|
|
|
|
Common.showFormError(form_id, gettext("It is required."));
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2015-02-07 08:50:33 +00:00
|
|
|
// if it has an extension, make sure it has a name
|
|
|
|
if (dirent_name.lastIndexOf('.') != -1 && dirent_name.substr(0, dirent_name.lastIndexOf('.')).length == 0) {
|
|
|
|
Common.showFormError(form_id, gettext("Only an extension there, please input a name."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var post_data = {'dirent_name': dirent_name},
|
|
|
|
post_url = Common.getUrl({name: "new_file", repo_id: dir.repo_id})
|
|
|
|
+ '?parent_dir=' + encodeURIComponent(dir.path);
|
2015-01-30 11:47:17 +00:00
|
|
|
var after_op_success = function(data) {
|
2015-02-07 08:50:33 +00:00
|
|
|
$.modal.close();
|
|
|
|
var new_dirent = dir.add({
|
|
|
|
'is_file': true,
|
2015-04-09 07:01:46 +00:00
|
|
|
'is_img': Common.imageCheck(data['name']),
|
2015-02-07 08:50:33 +00:00
|
|
|
'obj_name': data['name'],
|
|
|
|
'file_size': Common.fileSizeFormat(0),
|
|
|
|
'obj_id': '0000000000000000000000000000000000000000',
|
|
|
|
'file_icon': 'file.png',
|
|
|
|
'starred': false,
|
2015-05-27 06:16:07 +00:00
|
|
|
'perm': 'rw',
|
2015-02-07 08:50:33 +00:00
|
|
|
'last_modified': new Date().getTime() / 1000,
|
2015-03-18 02:45:13 +00:00
|
|
|
'last_update': gettext("Just now")
|
2015-02-07 08:50:33 +00:00
|
|
|
}, {silent: true});
|
2015-02-12 08:38:57 +00:00
|
|
|
dirView.addNewFile(new_dirent);
|
2015-01-30 11:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Common.ajaxPost({
|
|
|
|
'form': form,
|
|
|
|
'post_url': post_url,
|
|
|
|
'post_data': post_data,
|
|
|
|
'after_op_success': after_op_success,
|
|
|
|
'form_id': form_id
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
2015-01-31 03:17:09 +00:00
|
|
|
},
|
|
|
|
|
2015-02-12 08:38:57 +00:00
|
|
|
addNewFile: function(new_dirent) {
|
|
|
|
var dirView = this,
|
|
|
|
dir = this.dir;
|
|
|
|
var view = new DirentView({model: new_dirent, dirView: dirView});
|
|
|
|
var new_file = view.render().el;
|
|
|
|
// put the new file as the first file
|
|
|
|
if ($('tr', dirView.$dirent_list).length == 0) {
|
|
|
|
dirView.$dirent_list.append(new_file);
|
|
|
|
} else {
|
|
|
|
var dirs = dir.where({'is_dir':true});
|
|
|
|
if (dirs.length == 0) {
|
|
|
|
dirView.$dirent_list.prepend(new_file);
|
|
|
|
} else {
|
|
|
|
// put the new file after the last dir
|
|
|
|
$($('tr', dirView.$dirent_list)[dirs.length - 1]).after(new_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-02-13 08:33:19 +00:00
|
|
|
addNewDir: function(new_dirent) {
|
|
|
|
var dirView = this;
|
|
|
|
var view = new DirentView({model: new_dirent, dirView: dirView});
|
|
|
|
dirView.$dirent_list.prepend(view.render().el); // put the new dir as the first one
|
|
|
|
},
|
|
|
|
|
2015-03-18 02:45:13 +00:00
|
|
|
share: function () {
|
|
|
|
var dir = this.dir;
|
|
|
|
var path = dir.path;
|
2015-03-22 14:39:39 +00:00
|
|
|
var options = {
|
2015-03-18 02:45:13 +00:00
|
|
|
'is_repo_owner': dir.is_repo_owner,
|
|
|
|
'is_virtual': dir.is_virtual,
|
|
|
|
'user_perm': dir.user_perm,
|
|
|
|
'repo_id': dir.repo_id,
|
|
|
|
'is_dir': true,
|
|
|
|
'dirent_path': path,
|
2015-04-03 07:22:24 +00:00
|
|
|
'obj_name': path == '/' ? dir.repo_name : path.substr(path.lastIndexOf('/') + 1)
|
2015-03-22 14:39:39 +00:00
|
|
|
};
|
2015-03-18 02:45:13 +00:00
|
|
|
new ShareView(options);
|
|
|
|
},
|
|
|
|
|
2015-01-31 03:17:09 +00:00
|
|
|
sortByName: function() {
|
2015-07-11 06:51:26 +00:00
|
|
|
this.$('.by-time .sort-icon').hide();
|
|
|
|
|
2015-01-31 03:17:09 +00:00
|
|
|
var dirents = this.dir;
|
2015-07-11 06:51:26 +00:00
|
|
|
var el = this.$('.by-name .sort-icon');
|
2015-04-30 03:59:09 +00:00
|
|
|
|
2015-03-24 08:59:46 +00:00
|
|
|
dirents.comparator = function(a, b) {
|
2015-01-31 03:17:09 +00:00
|
|
|
if (a.get('is_dir') && b.get('is_file')) {
|
|
|
|
return -1;
|
2015-07-14 06:22:12 +00:00
|
|
|
}
|
|
|
|
if (a.get('is_file') && b.get('is_dir')) {
|
2015-04-30 03:59:09 +00:00
|
|
|
return 1;
|
2015-01-31 03:17:09 +00:00
|
|
|
}
|
2015-04-30 03:59:09 +00:00
|
|
|
|
|
|
|
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
|
2015-01-31 03:17:09 +00:00
|
|
|
if (el.hasClass('icon-caret-up')) {
|
2015-04-30 03:59:09 +00:00
|
|
|
return -result;
|
2015-01-31 03:17:09 +00:00
|
|
|
} else {
|
2015-04-30 03:59:09 +00:00
|
|
|
return result;
|
2015-01-31 03:17:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
dirents.sort();
|
|
|
|
this.$dirent_list.empty();
|
|
|
|
dirents.each(this.addOne, this);
|
2015-07-09 09:16:10 +00:00
|
|
|
el.toggleClass('icon-caret-up icon-caret-down').show();
|
2015-05-11 06:54:10 +00:00
|
|
|
dirents.comparator = null;
|
2015-01-31 03:17:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sortByTime: function () {
|
2015-07-11 06:51:26 +00:00
|
|
|
this.$('.by-name .sort-icon').hide();
|
|
|
|
|
2015-01-31 03:17:09 +00:00
|
|
|
var dirents = this.dir;
|
2015-07-11 06:51:26 +00:00
|
|
|
var el = this.$('.by-time .sort-icon');
|
2015-01-31 03:17:09 +00:00
|
|
|
dirents.comparator = function(a, b) {
|
|
|
|
if (a.get('is_dir') && b.get('is_file')) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-07-14 06:22:12 +00:00
|
|
|
if (a.get('is_file') && b.get('is_dir')) {
|
|
|
|
return 1;
|
|
|
|
}
|
2015-01-31 03:17:09 +00:00
|
|
|
if (el.hasClass('icon-caret-down')) {
|
|
|
|
return a.get('last_modified') < b.get('last_modified') ? 1 : -1;
|
|
|
|
} else {
|
|
|
|
return a.get('last_modified') < b.get('last_modified') ? -1 : 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
dirents.sort();
|
2015-07-14 06:22:12 +00:00
|
|
|
|
2015-01-31 03:17:09 +00:00
|
|
|
this.$dirent_list.empty();
|
|
|
|
dirents.each(this.addOne, this);
|
2015-07-09 09:16:10 +00:00
|
|
|
el.toggleClass('icon-caret-up icon-caret-down').show();
|
2015-05-11 06:54:10 +00:00
|
|
|
dirents.comparator = null;
|
2015-01-31 03:17:09 +00:00
|
|
|
},
|
|
|
|
|
2015-03-02 06:07:55 +00:00
|
|
|
select: function () {
|
|
|
|
var el = this.$('th .checkbox');
|
|
|
|
el.toggleClass('checkbox-checked');
|
|
|
|
|
|
|
|
var dir = this.dir;
|
|
|
|
var all_dirent_checkbox = this.$('.checkbox');
|
|
|
|
var $dirents_op = this.$('#multi-dirents-op');
|
|
|
|
|
|
|
|
if (el.hasClass('checkbox-checked')) {
|
|
|
|
all_dirent_checkbox.addClass('checkbox-checked');
|
|
|
|
dir.each(function(model) {
|
|
|
|
model.set({'selected': true}, {silent: true});
|
|
|
|
});
|
|
|
|
$dirents_op.css({'display':'inline'});
|
|
|
|
} else {
|
|
|
|
all_dirent_checkbox.removeClass('checkbox-checked');
|
|
|
|
dir.each(function(model) {
|
|
|
|
model.set({'selected': false}, {silent: true});
|
|
|
|
});
|
|
|
|
$dirents_op.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
del: function () {
|
|
|
|
var dirents = this.dir;
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
var del_dirents = function() {
|
|
|
|
$('#confirm-popup').append('<p style="color:red;">' + gettext("Processing...") + '</p>');
|
|
|
|
var selected_dirents = dirents.where({'selected':true}),
|
|
|
|
selected_names = [];
|
|
|
|
$(selected_dirents).each(function() {
|
|
|
|
selected_names.push(this.get('obj_name'));
|
|
|
|
});
|
|
|
|
$.ajax({
|
|
|
|
url: Common.getUrl({
|
|
|
|
name: 'del_dirents',
|
|
|
|
repo_id: dirents.repo_id
|
|
|
|
}) + '?parent_dir=' + encodeURIComponent(dirents.path),
|
|
|
|
type: 'POST',
|
|
|
|
dataType: 'json',
|
|
|
|
beforeSend: Common.prepareCSRFToken,
|
|
|
|
traditional: true,
|
|
|
|
data: {
|
|
|
|
'dirents_names': selected_names
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
var del_len = data['deleted'].length,
|
|
|
|
not_del_len = data['undeleted'].length,
|
|
|
|
msg_s, msg_f;
|
|
|
|
|
|
|
|
if (del_len > 0) {
|
|
|
|
if (del_len == selected_names.length) {
|
|
|
|
dirents.remove(selected_dirents);
|
|
|
|
_this.$('th .checkbox').removeClass('checkbox-checked');
|
|
|
|
_this.$('#multi-dirents-op').hide();
|
|
|
|
} else {
|
|
|
|
$(selected_dirents).each(function() {
|
2015-05-15 09:19:08 +00:00
|
|
|
if (data['deleted'].indexOf(this.get('obj_name')) != -1) {
|
2015-03-02 06:07:55 +00:00
|
|
|
dirents.remove(this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (del_len == 1) {
|
|
|
|
msg_s = gettext("Successfully deleted %(name)s.");
|
|
|
|
} else if (del_len == 2) {
|
|
|
|
msg_s = gettext("Successfully deleted %(name)s and 1 other item.");
|
|
|
|
} else {
|
|
|
|
msg_s = gettext("Successfully deleted %(name)s and %(amount)s other items.");
|
|
|
|
}
|
2015-03-19 07:40:40 +00:00
|
|
|
msg_s = msg_s.replace('%(name)s', Common.HTMLescape(data['deleted'][0])).replace('%(amount)s', del_len - 1);
|
2015-03-02 06:07:55 +00:00
|
|
|
Common.feedback(msg_s, 'success');
|
|
|
|
}
|
|
|
|
if (not_del_len > 0) {
|
|
|
|
if (not_del_len == 1) {
|
2015-05-15 09:19:08 +00:00
|
|
|
msg_f = gettext("Failed to delete %(name)s.");
|
2015-03-02 06:07:55 +00:00
|
|
|
} else if (not_del_len == 2) {
|
2015-05-15 09:19:08 +00:00
|
|
|
msg_f = gettext("Failed to delete %(name)s and 1 other item.");
|
2015-03-02 06:07:55 +00:00
|
|
|
} else {
|
2015-05-15 09:19:08 +00:00
|
|
|
msg_f = gettext("Failed to delete %(name)s and %(amount)s other items.");
|
2015-03-02 06:07:55 +00:00
|
|
|
}
|
2015-03-19 07:40:40 +00:00
|
|
|
msg_f = msg_f.replace('%(name)s', Common.HTMLescape(data['undeleted'][0])).replace('%(amount)s', not_del_len - 1);
|
2015-03-02 06:07:55 +00:00
|
|
|
Common.feedback(msg_f, 'error');
|
|
|
|
}
|
|
|
|
$.modal.close();
|
|
|
|
},
|
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
|
|
$.modal.close();
|
|
|
|
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
Common.showConfirm(gettext("Delete Items"),
|
|
|
|
gettext("Are you sure you want to delete these selected items?"),
|
|
|
|
del_dirents);
|
|
|
|
},
|
|
|
|
|
|
|
|
mv: function () {
|
|
|
|
this.mvcp({'op':'mv'});
|
|
|
|
},
|
|
|
|
cp: function () {
|
|
|
|
this.mvcp({'op':'cp'});
|
|
|
|
},
|
|
|
|
mvcp: function (params) {
|
|
|
|
var dir = this.dir;
|
|
|
|
var op = params.op;
|
|
|
|
|
|
|
|
var title = op == 'mv' ? "Move selected item(s) to:" : "Copy selected item(s) to:";
|
|
|
|
|
|
|
|
var form = $(this.mvcpTemplate({
|
|
|
|
form_title: title,
|
|
|
|
op_type: op,
|
|
|
|
obj_type: '',
|
|
|
|
obj_name: '',
|
2015-06-10 05:43:41 +00:00
|
|
|
show_other_repos: !dir.encrypted
|
2015-03-02 06:07:55 +00:00
|
|
|
}));
|
|
|
|
form.modal({appendTo:'#main', autoResize:true, focus:false});
|
|
|
|
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
|
|
|
|
|
|
|
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 _this = this;
|
|
|
|
var dirents = this.dir;
|
|
|
|
// get models
|
|
|
|
var dirs = dirents.where({'is_dir':true, 'selected':true}),
|
|
|
|
files = dirents.where({'is_file':true, 'selected':true});
|
|
|
|
var dir_names = [], file_names = [];
|
|
|
|
$(dirs).each(function() {
|
|
|
|
dir_names.push(this.get('obj_name'));
|
|
|
|
});
|
|
|
|
$(files).each(function() {
|
|
|
|
file_names.push(this.get('obj_name'));
|
|
|
|
});
|
|
|
|
form.submit(function() {
|
|
|
|
var dst_repo = $('[name="dst_repo"]', form).val(),
|
|
|
|
dst_path = $('[name="dst_path"]', form).val(),
|
|
|
|
url_main;
|
|
|
|
var cur_path = dirents.path;
|
|
|
|
var url_obj = {repo_id:dirents.repo_id};
|
|
|
|
|
|
|
|
if (!$.trim(dst_repo) || !$.trim(dst_path)) {
|
|
|
|
$('.error', form).removeClass('hide');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (dst_repo == dirents.repo_id && dst_path == cur_path) {
|
|
|
|
$('.error', form).html(gettext("Invalid destination path")).removeClass('hide');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common.disableButton($('[type="submit"]', form));
|
|
|
|
form.append('<p style="color:red;">' + gettext("Processing...") + '</p>');
|
|
|
|
|
|
|
|
if (dst_repo == dirents.repo_id) {
|
|
|
|
// when mv/cp in current lib, files/dirs can be handled in batch, and no need to show progress
|
|
|
|
url_obj.name = op == 'mv' ? 'mv_dirents' : 'cp_dirents';
|
|
|
|
$.ajax({
|
|
|
|
url: Common.getUrl(url_obj) + '?parent_dir=' + encodeURIComponent(cur_path),
|
|
|
|
type: 'POST',
|
|
|
|
dataType: 'json',
|
|
|
|
beforeSend: Common.prepareCSRFToken,
|
|
|
|
traditional: true,
|
|
|
|
data: {
|
|
|
|
'file_names': file_names,
|
|
|
|
'dir_names': dir_names,
|
|
|
|
'dst_repo': dst_repo,
|
|
|
|
'dst_path': dst_path
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
var success_len = data['success'].length,
|
|
|
|
msg_s, msg_f,
|
|
|
|
view_url = data['url'];
|
|
|
|
|
|
|
|
$.modal.close();
|
|
|
|
if (success_len > 0) {
|
|
|
|
if (op == 'mv') {
|
|
|
|
if (success_len == files.length + dirs.length) {
|
|
|
|
dirents.remove(dirs);
|
|
|
|
dirents.remove(files);
|
|
|
|
_this.$('th .checkbox').removeClass('checkbox-checked');
|
|
|
|
_this.$('#multi-dirents-op').hide();
|
|
|
|
} else {
|
|
|
|
$(dirs).each(function() {
|
|
|
|
if (this.get('obj_name') in data['success']) {
|
|
|
|
dirents.remove(this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(files).each(function() {
|
|
|
|
if (this.get('obj_name') in data['success']) {
|
|
|
|
dirents.remove(this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (success_len == 1) {
|
|
|
|
msg_s = gettext("Successfully moved %(name)s.");
|
|
|
|
} else if (success_len == 2) {
|
|
|
|
msg_s = gettext("Successfully moved %(name)s and 1 other item.");
|
|
|
|
} else {
|
|
|
|
msg_s = gettext("Successfully moved %(name)s and %(amount)s other items.");
|
|
|
|
}
|
|
|
|
} else { // cp
|
|
|
|
if (success_len == 1) {
|
|
|
|
msg_s = gettext("Successfully copied %(name)s.");
|
|
|
|
} else if (success_len == 2) {
|
|
|
|
msg_s = gettext("Successfully copied %(name)s and 1 other item.");
|
|
|
|
} else {
|
|
|
|
msg_s = gettext("Successfully copied %(name)s and %(amount)s other items.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-19 07:40:40 +00:00
|
|
|
msg_s = msg_s.replace('%(name)s', Common.HTMLescape(data['success'][0])).replace('%(amount)s', success_len - 1);
|
2015-03-02 06:07:55 +00:00
|
|
|
//msg_s += ' <a href="' + view_url + '">' + "View" + '</a>';
|
|
|
|
Common.feedback(msg_s, 'success');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data['failed'].length > 0) {
|
|
|
|
if (op == 'mv') {
|
|
|
|
if (data['failed'].length > 1) {
|
|
|
|
msg_f = gettext("Internal error. Failed to move %(name)s and %(amount)s other item(s).");
|
|
|
|
} else {
|
|
|
|
msg_f = gettext("Internal error. Failed to move %(name)s.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (data['failed'].length > 1) {
|
|
|
|
msg_f = gettext("Internal error. Failed to copy %(name)s and %(amount)s other item(s).");
|
|
|
|
} else {
|
|
|
|
msg_f = gettext("Internal error. Failed to copy %(name)s.");
|
|
|
|
}
|
|
|
|
}
|
2015-03-19 07:40:40 +00:00
|
|
|
msg_f = msg_f.replace('%(name)s', Common.HTMLescape(data['failed'][0])).replace('%(amount)s', data['failed'].length - 1);
|
2015-03-02 06:07:55 +00:00
|
|
|
Common.feedback(msg_f, 'error');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
|
|
$.modal.close();
|
|
|
|
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// when mv/cp to another lib, files/dirs should be handled one by one, and need to show progress
|
|
|
|
var op_objs = dirents.where({'selected':true}),
|
|
|
|
i = 0;
|
|
|
|
// progress popup
|
|
|
|
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);
|
|
|
|
|
|
|
|
var mvcpDirent = function () {
|
|
|
|
var op_obj = op_objs[i],
|
|
|
|
obj_type = op_obj.get('is_dir') ? 'dir':'file',
|
|
|
|
obj_name = op_obj.get('obj_name'),
|
|
|
|
post_url,
|
|
|
|
post_data;
|
|
|
|
|
|
|
|
if (op == 'mv') {
|
|
|
|
url_obj.name = obj_type == 'dir' ? 'mv_dir' : 'mv_file';
|
|
|
|
} else {
|
|
|
|
url_obj.name = obj_type == 'dir' ? 'cp_dir' : 'cp_file';
|
|
|
|
}
|
|
|
|
post_url = Common.getUrl(url_obj) + '?path=' + encodeURIComponent(cur_path) + '&obj_name=' + encodeURIComponent(obj_name);
|
|
|
|
post_data = {
|
|
|
|
'dst_repo': dst_repo,
|
|
|
|
'dst_path': dst_path
|
|
|
|
};
|
|
|
|
var after_op_success = function (data) {
|
|
|
|
var det_text = op == 'mv' ? gettext("Moving file %(index)s of %(total)s") : gettext("Copying file %(index)s of %(total)s");
|
|
|
|
details.html(det_text.replace('%(index)s', i + 1).replace('%(total)s', op_objs.length)).removeClass('vh');
|
|
|
|
cancel_btn.removeClass('hide');
|
|
|
|
var req_progress = function () {
|
|
|
|
var task_id = data['task_id'];
|
|
|
|
cancel_btn.data('task_id', task_id);
|
|
|
|
$.ajax({
|
|
|
|
url: Common.getUrl({name:'get_cp_progress'}) + '?task_id=' + encodeURIComponent(task_id),
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
var bar = $('.ui-progressbar-value', $('#mv-progress'));
|
|
|
|
if (!data['failed'] && !data['canceled'] && !data['successful']) {
|
|
|
|
setTimeout(req_progress, 1000);
|
|
|
|
} else {
|
|
|
|
if (data['successful']) {
|
|
|
|
bar.css('width', parseInt((i + 1)/op_objs.length*100, 10) + '%').show();
|
|
|
|
if (op == 'mv') {
|
|
|
|
dirents.remove(op_obj);
|
|
|
|
}
|
|
|
|
endOrContinue();
|
|
|
|
} else { // failed or canceled
|
|
|
|
if (data['failed']) {
|
|
|
|
var error_msg = op == 'mv' ? gettext('Failed to move %(name)s') : gettext('Failed to copy %(name)s');
|
2015-03-19 07:40:40 +00:00
|
|
|
cancel_btn.after('<p class="error">' + error_msg.replace('%(name)s', Common.HTMLescape(obj_name)) + '</p>');
|
2015-03-02 06:07:55 +00:00
|
|
|
end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
|
|
var error;
|
|
|
|
if (xhr.responseText) {
|
|
|
|
error = $.parseJSON(xhr.responseText).error;
|
|
|
|
} else {
|
|
|
|
error = gettext("Failed. Please check the network.");
|
|
|
|
}
|
|
|
|
cancel_btn.after('<p class="error">' + error + '</p>');
|
|
|
|
end();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}; // 'req_progress' ends
|
|
|
|
if (i == 0) {
|
|
|
|
$.modal.close();
|
|
|
|
setTimeout(function () {
|
|
|
|
mv_progress_popup.modal({containerCss: {
|
|
|
|
width: 300,
|
|
|
|
height: 150,
|
|
|
|
paddingTop: 50
|
|
|
|
}, focus:false});
|
|
|
|
$('#mv-progress').progressbar();
|
|
|
|
req_progress();
|
|
|
|
}, 100);
|
|
|
|
} else {
|
|
|
|
req_progress();
|
|
|
|
}
|
|
|
|
}; // 'after_op_success' ends
|
|
|
|
Common.ajaxPost({
|
|
|
|
'form': form,
|
|
|
|
'post_url': post_url,
|
|
|
|
'post_data': post_data,
|
|
|
|
'after_op_success': after_op_success,
|
|
|
|
'form_id': form.attr('id')
|
|
|
|
});
|
|
|
|
}; // 'mvcpDirent' ends
|
|
|
|
var endOrContinue = function () {
|
|
|
|
if (i == op_objs.length - 1) {
|
|
|
|
setTimeout(function () { $.modal.close(); }, 500);
|
|
|
|
} else {
|
|
|
|
mvcpDirent(++i);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var end = function () {
|
|
|
|
setTimeout(function () { $.modal.close(); }, 500);
|
|
|
|
};
|
|
|
|
mvcpDirent();
|
|
|
|
cancel_btn.click(function() {
|
|
|
|
Common.disableButton(cancel_btn);
|
|
|
|
var task_id = $(this).data('task_id');
|
|
|
|
$.ajax({
|
|
|
|
url: Common.getUrl({name:'cancel_cp'}) + '?task_id=' + encodeURIComponent(task_id),
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
other_info.html(gettext("Canceled.")).removeClass('hide');
|
|
|
|
cancel_btn.addClass('hide');
|
|
|
|
end();
|
|
|
|
},
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-02-03 05:47:22 +00:00
|
|
|
onWindowScroll: function () {
|
2015-05-06 03:59:44 +00:00
|
|
|
// 'more'
|
2015-03-30 09:00:54 +00:00
|
|
|
var dir = this.dir,
|
2015-04-10 06:40:27 +00:00
|
|
|
start = dir.more_start;
|
2015-05-06 03:59:44 +00:00
|
|
|
if (dir.dirent_more &&
|
|
|
|
$(window).scrollTop() + $(window).height() > $(document).height() - $('#footer').outerHeight(true) &&
|
|
|
|
start != dir.last_start) {
|
2015-04-10 06:40:27 +00:00
|
|
|
var loading_tip = this.$('.loading-tip'),
|
|
|
|
_this = this;
|
2015-02-03 05:47:22 +00:00
|
|
|
dir.last_start = start;
|
|
|
|
dir.fetch({
|
|
|
|
remove: false,
|
|
|
|
data: {
|
|
|
|
'p': dir.path,
|
|
|
|
'start': dir.more_start
|
|
|
|
},
|
|
|
|
success: function (collection, response, opts) {
|
|
|
|
if (!response.dirent_more ) { // no 'more'
|
|
|
|
loading_tip.hide();
|
|
|
|
}
|
2015-04-10 06:40:27 +00:00
|
|
|
_this.getImageThumbnail();
|
2015-02-03 05:47:22 +00:00
|
|
|
},
|
|
|
|
error: function(xhr, textStatus, errorThrown) {
|
|
|
|
loading_tip.hide();
|
|
|
|
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-05-06 03:59:44 +00:00
|
|
|
|
|
|
|
// fixed 'dir-op-bar'
|
|
|
|
var op_bar = this.$dir_op_bar,
|
|
|
|
path_bar = this.$path_bar, // the element before op_bar
|
|
|
|
repo_file_list = this.$('.repo-file-list'); // the element after op_bar
|
|
|
|
var op_bar_top = path_bar.offset().top + path_bar.outerHeight(true);
|
|
|
|
var fixed_styles = {
|
|
|
|
'position': 'fixed',
|
|
|
|
'top': 0,
|
|
|
|
'left': path_bar.offset().left,
|
|
|
|
'z-index': 12 // make 'op_bar' shown on top of the checkboxes
|
|
|
|
};
|
|
|
|
if ($(window).scrollTop() >= op_bar_top) {
|
|
|
|
repo_file_list.css({'margin-top':op_bar.outerHeight(true)});
|
|
|
|
op_bar.outerWidth(this.$el.width()).css(fixed_styles);
|
|
|
|
} else {
|
|
|
|
repo_file_list.css({'margin-top':0});
|
|
|
|
op_bar.removeAttr('style');
|
|
|
|
}
|
2015-02-03 05:47:22 +00:00
|
|
|
}
|
2015-05-06 03:59:44 +00:00
|
|
|
|
2015-01-30 11:36:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return DirView;
|
2015-01-25 10:47:42 +00:00
|
|
|
});
|