2015-01-20 18:25:10 +08:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
2015-01-26 14:14:22 +08:00
|
|
|
'common',
|
2015-01-25 18:47:42 +08:00
|
|
|
'text!' + app.config._tmplRoot + 'dirent.html'
|
2015-01-26 14:14:22 +08:00
|
|
|
], function($, _, Backbone, Common, direntsTemplate) {
|
2015-01-20 18:25:10 +08:00
|
|
|
'use strict';
|
|
|
|
|
2015-01-25 18:47:42 +08:00
|
|
|
app = app || {};
|
|
|
|
app.globalState = app.globalState || {};
|
|
|
|
|
2015-01-20 18:25:10 +08:00
|
|
|
var DirentView = Backbone.View.extend({
|
|
|
|
tagName: 'tr',
|
|
|
|
|
|
|
|
template: _.template(direntsTemplate),
|
|
|
|
|
2015-01-25 18:47:42 +08:00
|
|
|
initialize: function(options) {
|
|
|
|
this.options = options || {};
|
|
|
|
this.model = options.model;
|
|
|
|
this.dirView = options.dirView;
|
|
|
|
|
|
|
|
app.globalState.noFileOpPopup = true;
|
|
|
|
this.listenTo(this.model, "change", this.render);
|
|
|
|
//Backbone.View.prototype.initialize.apply(this, arguments);
|
2015-01-20 18:25:10 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2015-01-26 14:14:22 +08:00
|
|
|
var dirent_path = Common.pathJoin([this.dirView.dir.path,
|
|
|
|
this.model.attributes.obj_name]);
|
|
|
|
//console.log(Common.pathJointhis.dirView.dir.path + "/" + this.model.attributes.obj_name);
|
2015-01-25 18:47:42 +08:00
|
|
|
this.$el.html(this.template({
|
|
|
|
dirent: this.model.attributes,
|
|
|
|
repo_id: this.dirView.dir.repo_id,
|
|
|
|
path: this.dirView.dir.path,
|
2015-01-26 14:14:22 +08:00
|
|
|
dirent_path: dirent_path,
|
2015-01-25 18:47:42 +08:00
|
|
|
user_perm: this.dirView.dir.user_perm,
|
|
|
|
repo_encrypted: this.dirView.dir.encrypted
|
|
|
|
}));
|
2015-01-20 18:25:10 +08:00
|
|
|
return this;
|
2015-01-25 18:47:42 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'mouseenter': 'highlight',
|
|
|
|
'mouseleave': 'rmHighlight',
|
|
|
|
'click .select': 'select',
|
|
|
|
'click .file-star': 'starFile',
|
|
|
|
'click .dir-link': 'visitDir',
|
|
|
|
'click .more-op-icon': 'togglePopup',
|
|
|
|
'click .share': 'share',
|
|
|
|
'click .del': 'delete',
|
|
|
|
'click .rename': 'rename',
|
|
|
|
'click .mv': 'mvcp',
|
|
|
|
'click .cp': 'mvcp',
|
|
|
|
'click .file-update': 'updateFile'
|
|
|
|
},
|
|
|
|
|
|
|
|
highlight: function() {
|
|
|
|
if (app.globalState.noFileOpPopup) {
|
|
|
|
this.$el.addClass('hl').find('.repo-file-op').removeClass('vh');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
rmHighlight: function() {
|
|
|
|
if (app.globalState.noFileOpPopup) {
|
|
|
|
this.$el.removeClass('hl').find('.repo-file-op').addClass('vh');
|
|
|
|
}
|
|
|
|
},
|
2015-01-20 18:25:10 +08:00
|
|
|
|
2015-01-26 14:14:22 +08:00
|
|
|
select: function () {
|
|
|
|
var checkbox = this.$('.checkbox');
|
|
|
|
checkbox.toggleClass('checkbox-checked');
|
|
|
|
if (checkbox.hasClass('checkbox-checked')) {
|
|
|
|
this.model.set({'selected':true}, {silent:true}); // do not trigger the 'change' event.
|
|
|
|
} else {
|
|
|
|
this.model.set({'selected':false}, {silent:true});
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
starFile: function() {
|
|
|
|
var _this = this;
|
|
|
|
var dir = this.dirView.dir;
|
|
|
|
//var path = dir.path;
|
|
|
|
//path += (path == '/' ? '' : '/');
|
|
|
|
var starred = this.model.get('starred');
|
|
|
|
var options = { repo_id: dir.repo_id };
|
|
|
|
options.name = starred ? 'unstar_file' : 'star_file';
|
|
|
|
var filePath = Common.pathJoin([dir.path, this.model.get('obj_name')]);
|
|
|
|
var url = Common.getUrl(options) + '?file=' + encodeURIComponent(filePath);
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
dataType: 'json',
|
|
|
|
cache: false,
|
|
|
|
success: function () {
|
|
|
|
if (starred) {
|
|
|
|
_this.model.set({'starred':false});
|
|
|
|
} else {
|
|
|
|
_this.model.set({'starred':true});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: Common.ajaxErrorHandler
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
visitDir: function () {
|
|
|
|
// show 'loading'
|
|
|
|
this.$('.dirent-icon img').attr({
|
|
|
|
'src': app.config.mediaURL + 'img/loading-icon.gif',
|
|
|
|
'alt':''
|
|
|
|
});
|
|
|
|
// empty all models
|
|
|
|
this.dirView.dir.reset();
|
|
|
|
// update url & dirents
|
|
|
|
var dir_url = this.$('.dir-link').attr("href");
|
|
|
|
app.router.navigate(dir_url, {trigger: true}); // offer an url fragment
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
togglePopup: function () {
|
|
|
|
var icon = this.$('.more-op-icon'),
|
|
|
|
popup = this.$('.hidden-op');
|
|
|
|
|
|
|
|
if (popup.hasClass('hide')) { // the popup is not shown
|
|
|
|
if (icon.position().left + icon.width() + popup.outerWidth() < icon.parent().width()) {
|
|
|
|
popup.css({'left': icon.position().left + icon.width() + 5});
|
|
|
|
if (icon.offset().top + popup.height() <= $('#main').offset().top + $('#main').height()) {
|
|
|
|
popup.css('top', 6);
|
|
|
|
} else {
|
|
|
|
popup.css('bottom', 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
popup.css({'right':0});
|
|
|
|
if (icon.offset().top + popup.height() <= $('#main').offset().top + $('#main').height()) {
|
|
|
|
popup.css('top', icon.position().top + icon.height() + 3);
|
|
|
|
} else {
|
|
|
|
popup.css('bottom', icon.position().top + icon.height() + 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
popup.removeClass('hide');
|
|
|
|
app.globalState.noFileOpPopup = false;
|
|
|
|
app.globalState.popup_tr = icon.parents('tr');
|
|
|
|
} else {
|
|
|
|
popup.addClass('hide');
|
|
|
|
app.globalState.noFileOpPopup = true;
|
|
|
|
app.globalState.popup_tr = '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-01-20 18:25:10 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return DirentView;
|
|
|
|
});
|