2015-01-20 10:25:10 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
2015-01-31 05:17:47 +00:00
|
|
|
'common',
|
2015-03-18 02:45:13 +00:00
|
|
|
'app/views/share',
|
2015-02-04 13:57:26 +00:00
|
|
|
'text!' + app.config._tmplRoot + 'repo.html'
|
2015-03-18 02:45:13 +00:00
|
|
|
], function($, _, Backbone, Common, ShareView, reposTemplate) {
|
2015-01-20 10:25:10 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var RepoView = Backbone.View.extend({
|
|
|
|
tagName: 'tr',
|
|
|
|
|
|
|
|
template: _.template(reposTemplate),
|
|
|
|
|
2015-01-31 05:17:47 +00:00
|
|
|
events: {
|
|
|
|
'mouseenter': 'showAction',
|
|
|
|
'mouseleave': 'hideAction',
|
|
|
|
'click .repo-delete-btn': 'delete',
|
|
|
|
'click .repo-share-btn': 'share'
|
|
|
|
},
|
2015-02-04 13:57:26 +00:00
|
|
|
|
2015-01-20 10:25:10 +00:00
|
|
|
initialize: function() {
|
|
|
|
console.log('init RepoView');
|
2015-01-31 05:17:47 +00:00
|
|
|
|
|
|
|
this.listenTo(this.model, 'destroy', this.remove);
|
2015-01-20 10:25:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
this.$el.html(this.template(this.model.toJSON()));
|
|
|
|
return this;
|
2015-01-31 05:17:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
showAction: function() {
|
|
|
|
this.$el.addClass('hl');
|
|
|
|
this.$el.find('.op-icon').removeClass('vh');
|
|
|
|
},
|
|
|
|
|
|
|
|
hideAction: function() {
|
|
|
|
this.$el.removeClass('hl');
|
|
|
|
this.$el.find('.op-icon').addClass('vh');
|
|
|
|
},
|
|
|
|
|
|
|
|
showDelConfirm: function($target, msg, yesCallback) {
|
|
|
|
// TODO: need to refactor, copied from repo_del_js.html
|
|
|
|
|
|
|
|
var op = $target,
|
|
|
|
cont = op.parent().css({'position': 'relative'}),
|
|
|
|
cfm;
|
|
|
|
|
|
|
|
// only show 1 popup each time.
|
|
|
|
$('.repo-del-cfm', op.parents('table')).addClass('hide');
|
|
|
|
|
|
|
|
if (cont.find('.repo-del-cfm').length == 1) {
|
|
|
|
cfm = cont.find('.repo-del-cfm');
|
|
|
|
} else {
|
|
|
|
cfm = $('#repo-del-cfm-popup').clone().removeAttr('id');
|
|
|
|
cont.append(cfm);
|
|
|
|
cfm.css({'left': op.position().left, 'top': op.position().top + op.height() + 2, 'width':202});
|
|
|
|
}
|
|
|
|
|
|
|
|
var con = $('.con', cfm);
|
|
|
|
con.html(msg.replace('{placeholder}', '<span class="op-target">' + this.model.get("name") + '</span>'));
|
|
|
|
cfm.removeClass('hide');
|
|
|
|
$('.no',cfm).click(function() {
|
|
|
|
cfm.addClass('hide');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.yes', cfm).click(yesCallback);
|
|
|
|
},
|
|
|
|
|
|
|
|
delete: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var that = this;
|
|
|
|
var yesCallback = function() {
|
|
|
|
Common.feedback(gettext('Loading...'), 'info', Common.INFO_TIMEOUT); // TODO: what if there is still response after 10 secs ?
|
|
|
|
that.model.destroy({
|
|
|
|
wait: true,
|
|
|
|
success: function(model, rep) {
|
|
|
|
Common.feedback(gettext('Delete succeeded'), 'success', Common.SUCCESS_TIMOUT);
|
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
Common.feedback(gettext('Error'), 'error', Common.ERROR_TIMEOUT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.showDelConfirm(
|
|
|
|
$(e.target),
|
|
|
|
gettext('Really want to delete {placeholder} ?')
|
|
|
|
.replace(/\{placeholder\}/g, '<span class="op-target">' + this.model.get('name') + '</span>'),
|
|
|
|
yesCallback
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
share: function() {
|
2015-02-26 06:39:35 +00:00
|
|
|
var options = {
|
2015-03-18 02:45:13 +00:00
|
|
|
'is_repo_owner': true,
|
|
|
|
'is_virtual': this.model.get('virtual'),
|
|
|
|
'user_perm': this.model.get('permission'),
|
|
|
|
'repo_id': this.model.get('id'),
|
|
|
|
'is_dir': true,
|
|
|
|
'dirent_path': '/',
|
|
|
|
'obj_name': this.model.get('name')
|
|
|
|
};
|
|
|
|
new ShareView(options);
|
2015-01-20 10:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return RepoView;
|
|
|
|
});
|