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',
|
2016-02-22 09:16:40 +00:00
|
|
|
'js.cookie',
|
2015-01-30 11:36:42 +00:00
|
|
|
'app/collections/dirents',
|
2015-02-01 06:15:00 +00:00
|
|
|
'app/views/dirent',
|
2016-01-31 14:06:40 +00:00
|
|
|
'app/views/dirent-grid',
|
2015-02-13 08:33:19 +00:00
|
|
|
'app/views/fileupload',
|
2016-04-18 03:57:55 +00:00
|
|
|
'app/views/share',
|
|
|
|
'app/views/widgets/dropdown'
|
2015-04-17 02:59:48 +00:00
|
|
|
], function($, progressbar, magnificPopup, simplemodal, _, Backbone, Common,
|
2016-03-24 06:43:20 +00:00
|
|
|
FileTree, Cookies, DirentCollection, DirentView, DirentGridView,
|
2016-04-18 03:57:55 +00:00
|
|
|
FileUploadView, ShareView, DropdownView) {
|
2015-01-30 11:36:42 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var DirView = Backbone.View.extend({
|
2016-03-24 06:43:20 +00:00
|
|
|
id: 'dir-view',
|
|
|
|
|
|
|
|
template: _.template($('#dir-view-tmpl').html()),
|
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-11-03 03:06:24 +00:00
|
|
|
top_search_form_template: _.template($('#top-search-form-tmpl').html()),
|
2015-05-11 06:10:10 +00:00
|
|
|
|
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) {
|
2016-02-22 09:16:40 +00:00
|
|
|
var view_mode = Cookies.get('view_mode');
|
|
|
|
if (view_mode == 'grid') {
|
|
|
|
this.view_mode = 'grid';
|
2016-03-03 03:12:44 +00:00
|
|
|
} else {
|
2016-02-22 09:16:40 +00:00
|
|
|
this.view_mode = 'list';
|
2016-03-03 03:12:44 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 14:06:40 +00:00
|
|
|
this.contextOptions = {};
|
|
|
|
|
2016-10-13 09:53:31 +00:00
|
|
|
// for image files
|
|
|
|
this.magnificPopupOptions = {
|
|
|
|
type: 'image',
|
|
|
|
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 img_name = Common.HTMLescape(item.data.name);
|
|
|
|
var img_link = '<a href="' + item.data.url + '" 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-01-30 11:36:42 +00:00
|
|
|
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});
|
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
this.render();
|
|
|
|
|
2015-04-09 07:01:46 +00:00
|
|
|
|
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
|
|
|
|
2015-09-09 06:23:14 +00:00
|
|
|
// hide 'rename form'
|
|
|
|
$(document).click(function(e) {
|
|
|
|
var target = e.target || event.srcElement;
|
|
|
|
var $form = $('#rename-form');
|
|
|
|
if ($form.length && !$form.find('*').is(target)) {
|
2015-09-15 07:17:06 +00:00
|
|
|
var $tr = $form.closest('tr'); // get $tr before $form removed in `.cancel click()`
|
2015-09-09 06:23:14 +00:00
|
|
|
$('.cancel', $form).click();
|
|
|
|
}
|
|
|
|
});
|
2016-01-31 14:06:40 +00:00
|
|
|
|
2016-03-05 08:41:26 +00:00
|
|
|
// for 'grid view': click to hide the contextmenu of '.grid-item'
|
2016-02-22 14:32:52 +00:00
|
|
|
$(document).click(function(e) {
|
|
|
|
var target = e.target || event.srcElement;
|
|
|
|
var $popup = $('.grid-item-op');
|
|
|
|
if ($popup.length > 0 &&
|
|
|
|
!$popup.is(target) &&
|
2016-03-05 08:41:26 +00:00
|
|
|
!$popup.find('*').is(target) &&
|
|
|
|
!$popup.closest('.grid-item').is(target) &&
|
|
|
|
!$popup.closest('.grid-item').find('*').is(target)) {
|
2016-02-22 14:32:52 +00:00
|
|
|
$popup.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-30 11:36:42 +00:00
|
|
|
},
|
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
render: function() {
|
|
|
|
this.$el.html(this.template());
|
|
|
|
this.attached = false;
|
|
|
|
this.$dirent_list = this.$('.repo-file-list');
|
|
|
|
this.$dirent_grid = this.$('.grid-view');
|
|
|
|
this.$dirent_list_body = this.$('.repo-file-list tbody');
|
2016-06-04 02:24:08 +00:00
|
|
|
this.$loading_tip = this.$('.loading-tip');
|
|
|
|
this.$error = this.$('.error');
|
|
|
|
this.$el_con = this.$('.repo-file-list-topbar, .js-dir-content');
|
2016-03-24 06:43:20 +00:00
|
|
|
|
2016-05-02 03:31:01 +00:00
|
|
|
this.$path_bar = this.$('.path-bar');
|
2016-03-24 06:43:20 +00:00
|
|
|
// For compatible with css, we use .repo-op instead of .dir-op
|
|
|
|
this.$dir_op_bar = this.$('.repo-op');
|
|
|
|
},
|
|
|
|
|
2016-01-31 14:06:40 +00:00
|
|
|
// public function
|
|
|
|
// show a folder
|
2016-01-13 06:54:46 +00:00
|
|
|
// 'category' is sth. like url prefix
|
2016-01-31 14:06:40 +00:00
|
|
|
// options: for rendering from group view, currently is { group_name: group_name }
|
2016-01-13 06:54:46 +00:00
|
|
|
showDir: function(category, repo_id, path, options) {
|
2015-11-03 03:06:24 +00:00
|
|
|
$('#top-search-form').html(this.top_search_form_template({
|
|
|
|
search_repo_id: repo_id
|
|
|
|
}));
|
|
|
|
|
2016-01-13 06:54:46 +00:00
|
|
|
this.contextOptions = options;
|
2016-03-24 06:43:20 +00:00
|
|
|
if (!this.attached) {
|
|
|
|
this.attached = true;
|
|
|
|
$("#right-panel").html(this.$el);
|
|
|
|
}
|
2016-01-31 14:06:40 +00:00
|
|
|
this.dir.setPath(category, repo_id, path);
|
2016-11-01 10:01:41 +00:00
|
|
|
this.dir.dirent_more = false;
|
2016-01-31 14:06:40 +00:00
|
|
|
this.renderDir();
|
2015-01-30 11:36:42 +00:00
|
|
|
},
|
|
|
|
|
2016-01-31 14:06:40 +00:00
|
|
|
// public function
|
|
|
|
// hide the folder view
|
2015-01-30 11:36:42 +00:00
|
|
|
hide: function() {
|
2015-11-03 03:06:24 +00:00
|
|
|
$('#top-search-form').html(this.top_search_form_template({
|
|
|
|
search_repo_id: ''
|
|
|
|
}));
|
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
this.$el.detach();
|
|
|
|
this.attached = false;
|
2015-01-30 11:36:42 +00:00
|
|
|
},
|
|
|
|
|
2016-01-31 14:06:40 +00:00
|
|
|
/***** private functions *****/
|
2015-01-30 11:36:42 +00:00
|
|
|
addOne: function(dirent) {
|
2016-01-31 14:06:40 +00:00
|
|
|
var view;
|
|
|
|
if (this.view_mode == 'list') {
|
|
|
|
view = new DirentView({model: dirent, dirView: this});
|
|
|
|
this.$dirent_list_body.append(view.render().el);
|
|
|
|
} else {
|
|
|
|
view = new DirentGridView({model: dirent, dirView: this});
|
|
|
|
this.$dirent_grid.append(view.render().el);
|
|
|
|
}
|
2015-01-30 11:36:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
reset: function() {
|
|
|
|
this.renderPath();
|
|
|
|
this.renderDirOpBar();
|
2016-03-03 03:12:44 +00:00
|
|
|
if (this.view_mode == 'list') {
|
2016-01-31 14:06:40 +00:00
|
|
|
this.renderDirentsHd();
|
2016-03-03 03:12:44 +00:00
|
|
|
}
|
2016-03-15 04:04:31 +00:00
|
|
|
|
2016-09-08 08:26:23 +00:00
|
|
|
// sort
|
|
|
|
Common.updateSortIconByMode({'context': this.$el});
|
|
|
|
this.sortDirents();
|
2016-03-17 03:26:49 +00:00
|
|
|
|
2016-10-13 09:53:31 +00:00
|
|
|
this.updateMagnificPopupOptions();
|
|
|
|
|
2016-03-15 04:04:31 +00:00
|
|
|
this.dir.last_start = 0;
|
|
|
|
this.dir.limit = 100;
|
|
|
|
this.render_dirents_slice(this.dir.last_start, this.dir.limit);
|
|
|
|
|
2016-04-18 07:02:22 +00:00
|
|
|
this.setFileInput();
|
2016-04-18 03:57:55 +00:00
|
|
|
|
2015-04-10 06:40:27 +00:00
|
|
|
this.getImageThumbnail();
|
2015-03-30 09:00:54 +00:00
|
|
|
},
|
|
|
|
|
2016-10-13 09:53:31 +00:00
|
|
|
updateMagnificPopupOptions: function() {
|
|
|
|
var imgs = this.dir.where({is_img: true});
|
|
|
|
var items = [];
|
|
|
|
var repo_id = this.dir.repo_id,
|
|
|
|
path = this.dir.path;
|
|
|
|
$(imgs).each(function(index, model) {
|
|
|
|
var name = model.get('obj_name');
|
|
|
|
var dirent_path = Common.pathJoin([path, name]);
|
|
|
|
items.push({
|
|
|
|
'name': name,
|
|
|
|
'url': model.getWebUrl(),
|
|
|
|
'src': app.config.siteRoot + 'repo/' + repo_id + '/raw' + Common.encodePath(dirent_path)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.magnificPopupOptions.items = items;
|
|
|
|
},
|
|
|
|
|
2016-04-18 07:02:22 +00:00
|
|
|
// for fileupload
|
2016-10-13 09:53:31 +00:00
|
|
|
setFileInput: function() {
|
2016-04-18 07:02:22 +00:00
|
|
|
var dir = this.dir;
|
2016-04-20 10:00:38 +00:00
|
|
|
if (!dir.user_perm || dir.user_perm != 'rw') {
|
2016-04-18 07:02:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-20 10:00:38 +00:00
|
|
|
|
|
|
|
var $popup = this.fileUploadView.$el;
|
|
|
|
|
|
|
|
if (app.pageOptions.enable_upload_folder) {
|
|
|
|
if ('webkitdirectory' in $('#basic-upload-input')[0]) {
|
|
|
|
// if enable_upload_folder and is chrome
|
|
|
|
this.$("#basic-upload").remove();
|
|
|
|
this.$("#advanced-upload").show();
|
|
|
|
this.upload_dropdown = new DropdownView({
|
|
|
|
el: this.$("#advanced-upload")
|
|
|
|
});
|
2016-04-18 07:02:22 +00:00
|
|
|
$popup.fileupload(
|
|
|
|
'option',
|
|
|
|
'fileInput',
|
2016-04-20 10:00:38 +00:00
|
|
|
this.$('#advanced-upload input[type="file"]'));
|
|
|
|
} else {
|
|
|
|
this.$("#advanced-upload").remove();
|
|
|
|
$popup.fileupload(
|
|
|
|
'option',
|
|
|
|
'fileInput',
|
|
|
|
this.$('#basic-upload-input'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$popup.fileupload(
|
|
|
|
'option',
|
|
|
|
'fileInput',
|
|
|
|
this.$('#basic-upload-input'));
|
2016-04-18 07:02:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-04-10 06:40:27 +00:00
|
|
|
getImageThumbnail: function() {
|
2015-09-14 06:34:33 +00:00
|
|
|
if (!app.pageOptions.enable_thumbnail || this.dir.encrypted) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-10 06:40:27 +00:00
|
|
|
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;
|
2016-03-03 08:37:18 +00:00
|
|
|
var thumbnail_size = app.pageOptions.thumbnail_default_size;
|
|
|
|
if (this.view_mode == 'grid') {
|
|
|
|
thumbnail_size = app.pageOptions.thumbnail_size_for_grid;
|
|
|
|
}
|
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}),
|
2016-03-03 08:37:18 +00:00
|
|
|
data: {
|
|
|
|
'path': cur_img_path,
|
|
|
|
'size': thumbnail_size
|
|
|
|
},
|
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
|
|
|
},
|
|
|
|
|
2016-03-03 03:12:44 +00:00
|
|
|
_showLibDecryptDialog: function() {
|
2016-01-31 14:06:40 +00:00
|
|
|
var _this = this;
|
|
|
|
var form = $($('#repo-decrypt-form-template').html());
|
|
|
|
var decrypt_success = false;
|
|
|
|
form.modal({
|
|
|
|
containerCss: {'padding': '1px'},
|
|
|
|
onClose: function () {
|
|
|
|
$.modal.close();
|
|
|
|
_this.$el_con.show();
|
|
|
|
if (!decrypt_success) {
|
|
|
|
app.router.navigate(
|
2016-03-03 03:12:44 +00:00
|
|
|
_this.dir.category + '/', // need to append '/' at end
|
2016-01-31 14:06:40 +00:00
|
|
|
{trigger: true}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('#simplemodal-container').css({'height':'auto'});
|
|
|
|
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'),
|
2016-03-21 09:16:57 +00:00
|
|
|
post_url: Common.getUrl({
|
|
|
|
'name': 'api_v2.1_repo_set_password',
|
|
|
|
'repo_id': _this.dir.repo_id
|
|
|
|
}),
|
2016-01-31 14:06:40 +00:00
|
|
|
post_data: {
|
2016-03-21 07:38:22 +00:00
|
|
|
password: passwd
|
2016-01-31 14:06:40 +00:00
|
|
|
},
|
|
|
|
after_op_success: function() {
|
|
|
|
decrypt_success = true;
|
|
|
|
$.modal.close();
|
2016-03-03 03:12:44 +00:00
|
|
|
_this.renderDir();
|
2016-01-31 14:06:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
renderDir: function() {
|
2016-06-04 02:24:08 +00:00
|
|
|
this.$loading_tip.show();
|
|
|
|
this.$error.hide();
|
|
|
|
this.$el_con.show();
|
|
|
|
|
2016-01-31 14:06:40 +00:00
|
|
|
this.$dirent_grid.empty();
|
|
|
|
this.$dirent_list_body.empty();
|
|
|
|
|
|
|
|
if (this.view_mode == 'list') {
|
|
|
|
this.$dirent_list.show();
|
|
|
|
this.$dirent_grid.hide();
|
|
|
|
} else {
|
|
|
|
this.$dirent_list.hide();
|
|
|
|
this.$dirent_grid.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
var _this = this;
|
2016-03-03 08:37:18 +00:00
|
|
|
var thumbnail_size = app.pageOptions.thumbnail_default_size;
|
|
|
|
if (this.view_mode == 'grid') {
|
|
|
|
thumbnail_size = app.pageOptions.thumbnail_size_for_grid;
|
|
|
|
}
|
2016-01-31 14:06:40 +00:00
|
|
|
var dir = this.dir;
|
|
|
|
dir.fetch({
|
|
|
|
cache: false,
|
|
|
|
reset: true,
|
2016-03-03 08:37:18 +00:00
|
|
|
data: {
|
|
|
|
'p': dir.path,
|
|
|
|
'thumbnail_size': thumbnail_size
|
|
|
|
},
|
2016-03-15 04:04:31 +00:00
|
|
|
success: function() {
|
2016-06-04 02:24:08 +00:00
|
|
|
_this.$loading_tip.hide();
|
2016-01-31 14:06:40 +00:00
|
|
|
},
|
|
|
|
error: function(collection, response, opts) {
|
2016-06-04 02:24:08 +00:00
|
|
|
_this.$loading_tip.hide();
|
|
|
|
_this.$el_con.hide();
|
|
|
|
|
2016-01-31 14:06:40 +00:00
|
|
|
var err_msg;
|
|
|
|
if (response.responseText) {
|
|
|
|
if (response.responseJSON.lib_need_decrypt) {
|
2016-03-03 03:12:44 +00:00
|
|
|
_this._showLibDecryptDialog();
|
2016-01-31 14:06:40 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
err_msg = response.responseJSON.error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err_msg = gettext('Please check the network.');
|
|
|
|
}
|
2016-06-04 02:24:08 +00:00
|
|
|
_this.$error.html(err_msg).show();
|
2016-01-31 14:06:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
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 = {
|
2016-03-03 03:12:44 +00:00
|
|
|
path: path,
|
|
|
|
repo_name: dir.repo_name,
|
|
|
|
category: dir.category,
|
|
|
|
context: context
|
|
|
|
};
|
2016-01-31 14:06:40 +00:00
|
|
|
$.extend(obj, this.contextOptions);
|
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,
|
2016-01-31 14:06:40 +00:00
|
|
|
mode: this.view_mode,
|
2015-01-30 11:36:42 +00:00
|
|
|
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,
|
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());
|
|
|
|
},
|
|
|
|
|
2016-03-17 03:26:49 +00:00
|
|
|
render_dirents_slice: function(start, limit) {
|
|
|
|
var dir = this.dir;
|
|
|
|
_.each(dir.slice(start, start + limit), this.addOne, this);
|
|
|
|
if (dir.length > start + limit) {
|
|
|
|
dir.dirent_more = true;
|
|
|
|
dir.last_start = start + limit;
|
|
|
|
} else {
|
|
|
|
dir.dirent_more = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-01-30 11:36:42 +00:00
|
|
|
// Directory Operations
|
|
|
|
events: {
|
|
|
|
'click #add-new-dir': 'newDir',
|
|
|
|
'click #add-new-file': 'newFile',
|
|
|
|
'click #share-cur-dir': 'share',
|
2016-01-31 14:06:40 +00:00
|
|
|
'click #js-switch-grid-view': 'switchToGridView',
|
|
|
|
'click #js-switch-list-view': 'switchToListView',
|
2015-01-30 11:36:42 +00:00
|
|
|
'click th.select': 'select',
|
|
|
|
'click #mv-dirents': 'mv',
|
2015-03-02 06:07:55 +00:00
|
|
|
'click #cp-dirents': 'cp',
|
|
|
|
'click #del-dirents': 'del',
|
2016-04-28 07:16:58 +00:00
|
|
|
'click #download-dirents': 'download',
|
2015-07-09 09:16:10 +00:00
|
|
|
'click .by-name': 'sortByName',
|
2016-04-20 10:00:38 +00:00
|
|
|
'click .by-time': 'sortByTime',
|
|
|
|
'click .basic-upload-btn': 'uploadFile',
|
|
|
|
'click .advanced-upload-file': 'advancedUploadFile',
|
|
|
|
'click .advanced-upload-folder': 'advancedUploadFolder'
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadFile: function() {
|
|
|
|
this.$('#basic-upload-input').trigger('click');
|
|
|
|
},
|
|
|
|
|
|
|
|
advancedUploadFile: function() {
|
|
|
|
this.$('#advanced-upload-file-input').trigger('click');
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
advancedUploadFolder: function() {
|
|
|
|
this.$('#advanced-upload-folder-input').trigger('click');
|
|
|
|
return false;
|
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
|
|
|
};
|
|
|
|
|
2016-06-20 10:34:30 +00:00
|
|
|
var post_data = { 'operation': 'mkdir' },
|
2015-02-07 08:50:33 +00:00
|
|
|
post_url = Common.getUrl({name: "new_dir", repo_id: dir.repo_id})
|
2016-06-20 10:34:30 +00:00
|
|
|
+ '?p=' + encodeURIComponent(Common.pathJoin([dir.path, dirent_name]));
|
2015-01-30 11:47:17 +00:00
|
|
|
var after_op_success = function(data) {
|
|
|
|
$.modal.close();
|
|
|
|
|
|
|
|
var new_dirent = dir.add({
|
|
|
|
'is_dir': true,
|
2016-06-20 10:34:30 +00:00
|
|
|
'obj_name': data['obj_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"),
|
2016-06-20 10:34:30 +00:00
|
|
|
'p_dpath': Common.pathJoin([dir.path, data['obj_name']])
|
2015-01-30 11:47:17 +00:00
|
|
|
}, {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'}
|
|
|
|
});
|
2016-04-29 08:47:04 +00:00
|
|
|
file_name.focus();
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-20 10:34:30 +00:00
|
|
|
var post_data = { 'operation': 'create' },
|
2015-02-07 08:50:33 +00:00
|
|
|
post_url = Common.getUrl({name: "new_file", repo_id: dir.repo_id})
|
2016-06-20 10:34:30 +00:00
|
|
|
+ '?p=' + encodeURIComponent(Common.pathJoin([dir.path, dirent_name]));
|
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,
|
2016-06-20 10:34:30 +00:00
|
|
|
'is_img': Common.imageCheck(data['obj_name']),
|
|
|
|
'obj_name': data['obj_name'],
|
2015-02-07 08:50:33 +00:00
|
|
|
'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;
|
2016-02-22 09:32:32 +00:00
|
|
|
|
|
|
|
if (this.view_mode == 'list') {
|
|
|
|
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_body).length == 0) {
|
|
|
|
dirView.$dirent_list_body.append(new_file);
|
|
|
|
} else {
|
|
|
|
var dirs = dir.where({'is_dir':true});
|
|
|
|
if (dirs.length == 0) {
|
|
|
|
dirView.$dirent_list_body.prepend(new_file);
|
|
|
|
} else {
|
|
|
|
// put the new file after the last dir
|
|
|
|
$($('tr', dirView.$dirent_list_body)[dirs.length - 1]).after(new_file);
|
|
|
|
}
|
|
|
|
}
|
2015-02-12 08:38:57 +00:00
|
|
|
} else {
|
2016-02-22 09:32:32 +00:00
|
|
|
var gview = new DirentGridView({model: new_dirent, dirView: dirView});
|
|
|
|
var grid_new_file = gview.render().el;
|
|
|
|
if ($('.grid-item', dirView.$dirent_grid).length == 0) {
|
|
|
|
dirView.$dirent_grid.append(grid_new_file);
|
2015-02-12 08:38:57 +00:00
|
|
|
} else {
|
2016-02-22 09:32:32 +00:00
|
|
|
var dirs = dir.where({'is_dir':true});
|
|
|
|
if (dirs.length == 0) {
|
|
|
|
dirView.$dirent_grid.prepend(grid_new_file);
|
|
|
|
} else {
|
|
|
|
// put the new file after the last dir
|
|
|
|
$($('.grid-item', dirView.$dirent_grid)[dirs.length - 1]).after(grid_new_file);
|
|
|
|
}
|
2015-02-12 08:38:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-02-13 08:33:19 +00:00
|
|
|
addNewDir: function(new_dirent) {
|
|
|
|
var dirView = this;
|
2016-02-22 09:32:32 +00:00
|
|
|
if (this.view_mode == 'list') {
|
|
|
|
var view = new DirentView({model: new_dirent, dirView: dirView});
|
|
|
|
// put the new dir as the first one
|
|
|
|
dirView.$dirent_list_body.prepend(view.render().el);
|
|
|
|
} else {
|
|
|
|
var gview = new DirentGridView({model: new_dirent, dirView: dirView});
|
|
|
|
dirView.$dirent_grid.prepend(gview.render().el);
|
|
|
|
}
|
2015-02-13 08:33:19 +00:00
|
|
|
},
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
2016-01-31 14:06:40 +00:00
|
|
|
switchToGridView: function() {
|
|
|
|
if (this.view_mode == 'grid') {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
this.view_mode = 'grid';
|
2016-02-22 09:16:40 +00:00
|
|
|
Cookies.set('view_mode', 'grid');
|
2016-01-31 14:06:40 +00:00
|
|
|
this.renderDir();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
switchToListView: function() {
|
|
|
|
if (this.view_mode == 'list') {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
this.view_mode = 'list';
|
2016-02-22 09:16:40 +00:00
|
|
|
Cookies.set('view_mode', 'list');
|
2016-01-31 14:06:40 +00:00
|
|
|
this.renderDir();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-08 08:26:23 +00:00
|
|
|
sortDirents: function() {
|
|
|
|
var sort_mode = app.pageOptions.sort_mode;
|
|
|
|
switch(sort_mode) {
|
|
|
|
case 'name_up':
|
|
|
|
this.dir.comparator = function(a, b) {
|
|
|
|
if (a.get('is_dir') && b.get('is_file')) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.get('is_file') && b.get('is_dir')) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'name_down':
|
|
|
|
this.dir.comparator = function(a, b) {
|
|
|
|
if (a.get('is_dir') && b.get('is_file')) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.get('is_file') && b.get('is_dir')) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
var result = Common.compareTwoWord(a.get('obj_name'), b.get('obj_name'));
|
|
|
|
return -result;
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'time_up':
|
|
|
|
this.dir.comparator = function(a, b) {
|
|
|
|
if (a.get('is_dir') && b.get('is_file')) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.get('is_file') && b.get('is_dir')) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return a.get('last_modified') < b.get('last_modified') ? -1 : 1;
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 'time_down':
|
|
|
|
this.dir.comparator = function(a, b) {
|
|
|
|
if (a.get('is_dir') && b.get('is_file')) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.get('is_file') && b.get('is_dir')) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return a.get('last_modified') < b.get('last_modified') ? 1 : -1;
|
|
|
|
};
|
|
|
|
break;
|
2016-03-17 03:26:49 +00:00
|
|
|
}
|
2015-04-30 03:59:09 +00:00
|
|
|
|
2016-09-08 08:26:23 +00:00
|
|
|
this.dir.sort();
|
|
|
|
},
|
|
|
|
|
|
|
|
sortByName: function() {
|
|
|
|
Common.toggleSortByNameMode();
|
|
|
|
Common.updateSortIconByMode({'context': this.$el});
|
|
|
|
this.sortDirents();
|
2015-04-30 03:59:09 +00:00
|
|
|
|
2016-01-31 14:06:40 +00:00
|
|
|
this.$dirent_list_body.empty();
|
2016-03-15 04:04:31 +00:00
|
|
|
this.render_dirents_slice(0, this.dir.limit);
|
2016-03-17 03:26:49 +00:00
|
|
|
this.dir.comparator = null;
|
2016-04-19 06:41:17 +00:00
|
|
|
return false;
|
2015-01-31 03:17:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sortByTime: function () {
|
2016-09-08 08:26:23 +00:00
|
|
|
Common.toggleSortByTimeMode();
|
|
|
|
Common.updateSortIconByMode({'context': this.$el});
|
|
|
|
this.sortDirents();
|
2016-03-17 03:26:49 +00:00
|
|
|
|
|
|
|
this.$dirent_list_body.empty();
|
|
|
|
this.render_dirents_slice(0, this.dir.limit);
|
|
|
|
this.dir.comparator = null;
|
2016-04-19 06:41:17 +00:00
|
|
|
return false;
|
2016-03-17 03:26:49 +00:00
|
|
|
},
|
2015-07-11 06:51:26 +00:00
|
|
|
|
2015-03-02 06:07:55 +00:00
|
|
|
select: function () {
|
2016-04-07 03:06:48 +00:00
|
|
|
var $el = this.$('th [type=checkbox]');
|
2015-03-02 06:07:55 +00:00
|
|
|
|
|
|
|
var dir = this.dir;
|
2016-04-07 03:06:48 +00:00
|
|
|
var $all_dirent_checkbox = this.$('[type=checkbox]');
|
2015-03-02 06:07:55 +00:00
|
|
|
var $dirents_op = this.$('#multi-dirents-op');
|
|
|
|
|
2016-04-29 08:47:04 +00:00
|
|
|
var $curDirOps = this.$('#cur-dir-ops');
|
2016-03-22 03:46:42 +00:00
|
|
|
|
2016-04-07 03:06:48 +00:00
|
|
|
if ($el.prop('checked')) {
|
|
|
|
$all_dirent_checkbox.prop('checked', true);
|
2015-03-02 06:07:55 +00:00
|
|
|
dir.each(function(model) {
|
|
|
|
model.set({'selected': true}, {silent: true});
|
|
|
|
});
|
2016-03-22 07:03:50 +00:00
|
|
|
$dirents_op.css({'display':'inline-block'});
|
2016-03-22 03:46:42 +00:00
|
|
|
$curDirOps.hide();
|
2015-03-02 06:07:55 +00:00
|
|
|
} else {
|
2016-04-07 03:06:48 +00:00
|
|
|
$all_dirent_checkbox.prop('checked', false);
|
2015-03-02 06:07:55 +00:00
|
|
|
dir.each(function(model) {
|
|
|
|
model.set({'selected': false}, {silent: true});
|
|
|
|
});
|
|
|
|
$dirents_op.hide();
|
2016-03-22 03:46:42 +00:00
|
|
|
$curDirOps.show();
|
2015-03-02 06:07:55 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-28 07:16:58 +00:00
|
|
|
download: function () {
|
2016-07-04 07:31:55 +00:00
|
|
|
var dirents = this.dir;
|
|
|
|
var parent_dir = dirents.path;
|
|
|
|
var selected_dirents = dirents.where({'selected':true});
|
2016-07-04 06:46:49 +00:00
|
|
|
|
|
|
|
// select 1 item, and it is a file
|
|
|
|
if (selected_dirents.length == 1 &&
|
|
|
|
selected_dirents[0].get('is_file')) {
|
|
|
|
location.href = selected_dirents[0].getDownloadUrl();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-04 07:31:55 +00:00
|
|
|
var selected_names = [];
|
|
|
|
var interval;
|
|
|
|
var zip_token;
|
2016-07-04 06:46:49 +00:00
|
|
|
var packagingTip = gettext("Packaging...");
|
|
|
|
var $tip = $('<p></p>');
|
2016-07-04 07:31:55 +00:00
|
|
|
var queryZipProgress = function() {
|
|
|
|
$.ajax({
|
|
|
|
url: Common.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
|
|
|
|
dataType: 'json',
|
|
|
|
cache: false,
|
2016-07-04 06:46:49 +00:00
|
|
|
success: function(data) {
|
2016-08-02 03:35:05 +00:00
|
|
|
var progress = data.total == 0 ? '100%' : (data.zipped/data.total*100).toFixed(0) + '%';
|
2016-07-04 06:46:49 +00:00
|
|
|
$tip.html(packagingTip + ' ' + progress);
|
2016-07-04 07:31:55 +00:00
|
|
|
if (data['total'] == data['zipped']) {
|
2016-07-04 06:46:49 +00:00
|
|
|
setTimeout(function() { $.modal.close(); }, 500);
|
2016-07-04 07:31:55 +00:00
|
|
|
clearInterval(interval);
|
2016-07-04 06:46:49 +00:00
|
|
|
location.href = Common.getUrl({
|
|
|
|
name: 'download_dir_zip_url',
|
|
|
|
zip_token: zip_token
|
|
|
|
});
|
2016-07-04 07:31:55 +00:00
|
|
|
}
|
|
|
|
},
|
2016-07-04 06:46:49 +00:00
|
|
|
error: function(xhr) {
|
2016-07-04 07:31:55 +00:00
|
|
|
Common.ajaxErrorHandler(xhr);
|
|
|
|
clearInterval(interval);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2016-04-28 07:16:58 +00:00
|
|
|
$(selected_dirents).each(function() {
|
2016-07-04 07:31:55 +00:00
|
|
|
selected_names.push(this.get('obj_name'));
|
2016-04-28 07:16:58 +00:00
|
|
|
});
|
|
|
|
$.ajax({
|
2016-07-04 07:31:55 +00:00
|
|
|
url: Common.getUrl({name: 'zip_task', repo_id: dirents.repo_id}),
|
|
|
|
data: {
|
|
|
|
'parent_dir': parent_dir,
|
|
|
|
'dirents': selected_names
|
|
|
|
},
|
|
|
|
traditional: true,
|
2016-07-04 06:46:49 +00:00
|
|
|
dataType: 'json',
|
2016-04-28 07:16:58 +00:00
|
|
|
success: function(data) {
|
2016-07-04 07:31:55 +00:00
|
|
|
zip_token = data['zip_token'];
|
2016-07-04 06:46:49 +00:00
|
|
|
$tip.html(packagingTip).modal();
|
|
|
|
$('#simplemodal-container').css({'width':'auto'});
|
2016-07-04 07:31:55 +00:00
|
|
|
queryZipProgress();
|
|
|
|
interval = setInterval(queryZipProgress, 1000);
|
2016-04-28 07:16:58 +00:00
|
|
|
},
|
2016-07-04 06:46:49 +00:00
|
|
|
error: function(xhr) {
|
2016-04-28 07:16:58 +00:00
|
|
|
Common.ajaxErrorHandler(xhr);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-03-02 06:07:55 +00:00
|
|
|
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();
|
2016-06-14 08:39:31 +00:00
|
|
|
_this.$('#cur-dir-ops').show();
|
2015-03-02 06:07:55 +00:00
|
|
|
} 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.");
|
|
|
|
}
|
2016-07-04 07:31:55 +00:00
|
|
|
msg_s = msg_s.replace('%(name)s', 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
|
|
|
}
|
2016-07-04 07:31:55 +00:00
|
|
|
msg_f = msg_f.replace('%(name)s', 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;
|
|
|
|
|
2015-08-22 07:26:13 +00:00
|
|
|
var title = op == 'mv' ? gettext("Move selected item(s) to:") : gettext("Copy selected item(s) to:");
|
2015-03-02 06:07:55 +00:00
|
|
|
|
2015-12-18 03:30:24 +00:00
|
|
|
var show_cur_repo = true;
|
|
|
|
if (dir.user_perm == 'r') {
|
|
|
|
show_cur_repo = false;
|
|
|
|
}
|
|
|
|
|
2015-03-02 06:07:55 +00:00
|
|
|
var form = $(this.mvcpTemplate({
|
|
|
|
form_title: title,
|
|
|
|
op_type: op,
|
|
|
|
obj_type: '',
|
|
|
|
obj_name: '',
|
2015-12-18 03:30:24 +00:00
|
|
|
show_cur_repo: show_cur_repo,
|
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'});
|
|
|
|
|
2015-12-18 03:30:24 +00:00
|
|
|
if (show_cur_repo) {
|
|
|
|
FileTree.renderTreeForPath({
|
2016-03-10 07:11:21 +00:00
|
|
|
$form: form,
|
|
|
|
$container: $('#current-repo-dirs'),
|
2015-12-18 03:30:24 +00:00
|
|
|
repo_name: dir.repo_name,
|
|
|
|
repo_id: dir.repo_id,
|
|
|
|
path: dir.path
|
|
|
|
});
|
|
|
|
}
|
2015-03-02 06:07:55 +00:00
|
|
|
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();
|
2016-06-14 08:39:31 +00:00
|
|
|
_this.$('#cur-dir-ops').show();
|
2015-03-02 06:07:55 +00:00
|
|
|
} 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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 07:31:55 +00:00
|
|
|
msg_s = msg_s.replace('%(name)s', 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.");
|
|
|
|
}
|
|
|
|
}
|
2016-07-04 07:31:55 +00:00
|
|
|
msg_f = msg_f.replace('%(name)s', 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'
|
2016-03-15 04:04:31 +00:00
|
|
|
if (this.dir.dirent_more &&
|
2016-08-05 06:21:28 +00:00
|
|
|
$(window).scrollTop() + $(window).height() == $(document).height()) { // scroll to the bottom
|
2016-03-15 04:04:31 +00:00
|
|
|
this.render_dirents_slice(this.dir.last_start, this.dir.limit);
|
|
|
|
this.getImageThumbnail();
|
2015-02-03 05:47:22 +00:00
|
|
|
}
|
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,
|
2016-05-11 10:29:01 +00:00
|
|
|
'background-color': $('#header').css('background-color'),
|
2015-05-06 03:59:44 +00:00
|
|
|
'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
|
|
|
});
|