2016-01-31 14:06:40 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
|
|
|
'file-tree',
|
|
|
|
'app/views/share',
|
2016-02-25 08:39:52 +00:00
|
|
|
'app/views/folder-perm',
|
|
|
|
'app/views/dialogs/dirent-mvcp'
|
|
|
|
], function($, _, Backbone, Common, FileTree, ShareView, FolderPermView,
|
|
|
|
DirentMvcpDialog) {
|
2016-01-31 14:06:40 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
app = app || {};
|
|
|
|
app.globalState = app.globalState || {};
|
|
|
|
|
|
|
|
var DirentGridView = Backbone.View.extend({
|
|
|
|
tagName: 'li',
|
|
|
|
className: 'grid-item',
|
|
|
|
|
|
|
|
dirTemplate: _.template($('#grid-view-dir-item-tmpl').html()),
|
2016-02-22 14:32:52 +00:00
|
|
|
dirOpTemplate: _.template($('#grid-view-dir-op-tmpl').html()),
|
2016-01-31 14:06:40 +00:00
|
|
|
fileTemplate: _.template($('#grid-view-file-item-tmpl').html()),
|
2016-02-22 14:32:52 +00:00
|
|
|
fileOpTemplate: _.template($('#grid-view-file-op-tmpl').html()),
|
2016-01-31 14:06:40 +00:00
|
|
|
|
|
|
|
// renameTemplate: _.template($("#grid-rename-form-template").html()),
|
|
|
|
// mvcpTemplate: _.template($("#mvcp-form-template").html()),
|
|
|
|
// mvProgressTemplate: _.template($("#mv-progress-popup-template").html()),
|
|
|
|
|
|
|
|
initialize: function(options) {
|
|
|
|
this.dirView = options.dirView;
|
|
|
|
this.dir = this.dirView.dir;
|
|
|
|
|
|
|
|
this.listenTo(this.model, "change", this.render);
|
|
|
|
this.listenTo(this.model, 'remove', this.remove); // for multi dirents: delete, mv
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var dir = this.dir;
|
|
|
|
var template;
|
|
|
|
|
|
|
|
if (this.model.get('is_dir')) {
|
|
|
|
template = this.dirTemplate;
|
|
|
|
} else {
|
|
|
|
template = this.fileTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$el.html(template({
|
|
|
|
dirent: this.model.attributes,
|
2016-02-24 04:11:28 +00:00
|
|
|
dirent_path: this.model.getPath(),
|
|
|
|
url: this.model.getWebUrl(),
|
2016-01-31 14:06:40 +00:00
|
|
|
category: dir.category,
|
|
|
|
repo_id: dir.repo_id,
|
|
|
|
is_repo_owner: dir.is_repo_owner,
|
|
|
|
can_generate_shared_link: app.pageOptions.can_generate_shared_link,
|
2016-02-22 14:32:52 +00:00
|
|
|
is_pro: app.pageOptions.is_pro,
|
2016-01-31 14:06:40 +00:00
|
|
|
repo_encrypted: dir.encrypted
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.$('.file-locked-icon').attr('title', gettext("locked by {placeholder}").replace('{placeholder}', this.model.get('lock_owner_name')));
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'mouseenter': 'highlight',
|
|
|
|
'mouseleave': 'rmHighlight',
|
2016-02-24 04:11:28 +00:00
|
|
|
//'mousedown .img-link': 'showPopupMenu',
|
|
|
|
//'mousedown .text-link': 'showPopupMenu'
|
|
|
|
'contextmenu .img-link': 'showPopupMenu',
|
|
|
|
'contextmenu .text-link': 'showPopupMenu'
|
2016-02-22 14:32:52 +00:00
|
|
|
|
|
|
|
/*
|
2016-01-31 14:06:40 +00:00
|
|
|
'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'
|
2016-02-22 14:32:52 +00:00
|
|
|
*/
|
2016-01-31 14:06:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
highlight: function() {
|
|
|
|
this.$('.img-link').addClass('hl');
|
|
|
|
this.$('.text-link').addClass('hl');
|
|
|
|
/*
|
|
|
|
if (!$('.grid-hidden-op:visible').length && !$('#grid-rename-form').length) {
|
|
|
|
this.$('.grid-img-inner-container').addClass('hl');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
|
|
|
|
rmHighlight: function() {
|
|
|
|
this.$('.img-link').removeClass('hl');
|
|
|
|
this.$('.text-link').removeClass('hl');
|
|
|
|
/*
|
|
|
|
if (!$('.grid-hidden-op:visible').length && !$('#grid-rename-form').length) {
|
|
|
|
this.$('.grid-img-inner-container').removeClass('hl');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
|
2016-02-24 04:11:28 +00:00
|
|
|
showPopupMenu: function(event) {
|
2016-02-22 14:32:52 +00:00
|
|
|
var dir = this.dir;
|
|
|
|
var template;
|
2016-01-31 14:06:40 +00:00
|
|
|
|
2016-02-22 14:32:52 +00:00
|
|
|
if (this.model.get('is_dir')) {
|
|
|
|
template = this.dirOpTemplate;
|
|
|
|
} else {
|
|
|
|
template = this.fileOpTemplate;
|
2016-01-31 14:06:40 +00:00
|
|
|
}
|
|
|
|
|
2016-02-22 14:32:52 +00:00
|
|
|
this.$('.img-link').addClass('hl');
|
|
|
|
this.$('.text-link').addClass('hl');
|
2016-01-31 14:06:40 +00:00
|
|
|
|
2016-02-24 04:11:28 +00:00
|
|
|
var op = template({
|
|
|
|
dirent: this.model.attributes,
|
|
|
|
dirent_path: this.model.getPath(),
|
|
|
|
download_url: this.model.getDownloadUrl(),
|
|
|
|
category: dir.category,
|
|
|
|
repo_id: dir.repo_id,
|
|
|
|
is_repo_owner: dir.is_repo_owner,
|
|
|
|
can_generate_shared_link: app.pageOptions.can_generate_shared_link,
|
|
|
|
is_pro: app.pageOptions.is_pro,
|
|
|
|
repo_encrypted: dir.encrypted
|
|
|
|
});
|
|
|
|
this.$el.append(op);
|
|
|
|
this.$('.grid-item-op').css({
|
|
|
|
'left': '100px',
|
|
|
|
'top': '100px',
|
|
|
|
});
|
|
|
|
|
2016-02-25 05:47:19 +00:00
|
|
|
// Using _.bind(function, object) to make that whenever the function is
|
|
|
|
// called, the value of this will be the object.
|
|
|
|
this.$el.on('click', '.delete', _.bind(this.del, this));
|
|
|
|
this.$el.on('click', '.share', _.bind(this.share, this));
|
2016-02-25 08:39:52 +00:00
|
|
|
this.$el.on('click', '.mv', _.bind(this.mvcp, this));
|
|
|
|
this.$el.on('click', '.cp', _.bind(this.mvcp, this));
|
2016-02-24 09:11:15 +00:00
|
|
|
|
2016-02-24 04:11:28 +00:00
|
|
|
return false;
|
2016-02-24 09:11:15 +00:00
|
|
|
},
|
|
|
|
|
2016-02-25 05:47:19 +00:00
|
|
|
_closeMenu: function() {
|
|
|
|
this.$('.grid-item-op').remove();
|
|
|
|
},
|
|
|
|
|
2016-02-24 09:11:15 +00:00
|
|
|
del: function(event) {
|
2016-02-25 05:47:19 +00:00
|
|
|
var dirent_name = this.model.get('obj_name');
|
|
|
|
this.model.deleteFromServer({
|
2016-02-24 09:11:15 +00:00
|
|
|
success: function(data) {
|
|
|
|
var msg = gettext("Successfully deleted %(name)s")
|
|
|
|
.replace('%(name)s', Common.HTMLescape(dirent_name));
|
|
|
|
Common.feedback(msg, 'success');
|
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
Common.ajaxErrorHandler(xhr);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
},
|
2016-02-22 14:32:52 +00:00
|
|
|
|
2016-02-25 05:47:19 +00:00
|
|
|
share: function() {
|
|
|
|
var dir = this.dir,
|
|
|
|
obj_name = this.model.get('obj_name'),
|
|
|
|
dirent_path = this.model.getPath();
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
'is_repo_owner': dir.is_repo_owner,
|
|
|
|
'is_virtual': dir.is_virtual,
|
|
|
|
'user_perm': this.model.get('perm'),
|
|
|
|
'repo_id': dir.repo_id,
|
|
|
|
'repo_encrypted': false,
|
|
|
|
'is_dir': this.model.get('is_dir') ? true : false,
|
|
|
|
'dirent_path': dirent_path,
|
|
|
|
'obj_name': obj_name
|
|
|
|
};
|
|
|
|
new ShareView(options);
|
|
|
|
this._closeMenu();
|
|
|
|
return false;
|
2016-02-25 08:39:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
mvcp: function(event) {
|
|
|
|
var op_type = $(event.target).hasClass('mv') ? 'mv' : 'cp';
|
|
|
|
var options = {
|
|
|
|
'dir': this.dir,
|
|
|
|
'dirent': this.model,
|
|
|
|
'op_type': op_type
|
|
|
|
};
|
|
|
|
|
|
|
|
new DirentMvcpDialog(options);
|
|
|
|
this._closeMenu();
|
|
|
|
return false;
|
2016-02-25 05:47:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 14:06:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return DirentGridView;
|
|
|
|
});
|