2015-01-20 10:25:10 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
2015-01-31 05:17:47 +00:00
|
|
|
'common',
|
2015-12-27 14:09:52 +00:00
|
|
|
'app/views/share',
|
|
|
|
'app/views/dialogs/history-settings'
|
|
|
|
], function($, _, Backbone, Common, ShareView, HistorySettingsDialog) {
|
2015-01-20 10:25:10 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var RepoView = Backbone.View.extend({
|
|
|
|
tagName: 'tr',
|
|
|
|
|
2015-04-03 04:15:41 +00:00
|
|
|
template: _.template($('#repo-tmpl').html()),
|
2015-03-31 04:15:47 +00:00
|
|
|
repoDelConfirmTemplate: _.template($('#repo-del-confirm-template').html()),
|
2015-12-27 14:09:52 +00:00
|
|
|
renameTemplate: _.template($("#repo-rename-form-template").html()),
|
2015-01-20 10:25:10 +00:00
|
|
|
|
2015-01-31 05:17:47 +00:00
|
|
|
events: {
|
2015-03-31 04:15:47 +00:00
|
|
|
'mouseenter': 'highlight',
|
|
|
|
'mouseleave': 'rmHighlight',
|
|
|
|
'click .repo-delete-btn': 'del',
|
2015-12-27 14:09:52 +00:00
|
|
|
'click .repo-share-btn': 'share',
|
|
|
|
'click .js-toggle-popup': 'togglePopup',
|
|
|
|
'click .js-repo-rename': 'rename',
|
|
|
|
'click .js-popup-history-settings': 'popupHistorySettings',
|
|
|
|
'click .js-popup-permission-settings': 'popupPermissionSettings'
|
2015-01-31 05:17:47 +00:00
|
|
|
},
|
2015-02-04 13:57:26 +00:00
|
|
|
|
2015-01-20 10:25:10 +00:00
|
|
|
initialize: function() {
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2015-12-27 14:09:52 +00:00
|
|
|
var obj = this.model.toJSON();
|
|
|
|
$.extend(obj, {
|
|
|
|
enable_repo_history_setting: app.pageOptions.enable_repo_history_setting
|
|
|
|
});
|
|
|
|
this.$el.html(this.template(obj));
|
2015-01-20 10:25:10 +00:00
|
|
|
return this;
|
2015-01-31 05:17:47 +00:00
|
|
|
},
|
|
|
|
|
2015-03-31 04:15:47 +00:00
|
|
|
// disable 'hover' when 'repo-del-confirm' popup is shown
|
|
|
|
highlight: function() {
|
2015-12-27 14:09:52 +00:00
|
|
|
if ($('#my-own-repos .repo-del-confirm').length == 0
|
|
|
|
&& !$('.hidden-op:visible').length
|
|
|
|
&& !$('#repo-rename-form').length) {
|
2015-03-31 04:15:47 +00:00
|
|
|
this.$el.addClass('hl').find('.op-icon').removeClass('vh');
|
|
|
|
}
|
2015-01-31 05:17:47 +00:00
|
|
|
},
|
|
|
|
|
2015-03-31 04:15:47 +00:00
|
|
|
rmHighlight: function() {
|
2015-12-27 14:09:52 +00:00
|
|
|
if ($('#my-own-repos .repo-del-confirm').length == 0
|
|
|
|
&& !$('.hidden-op:visible').length
|
|
|
|
&& !$('#repo-rename-form').length) {
|
2015-03-31 04:15:47 +00:00
|
|
|
this.$el.removeClass('hl').find('.op-icon').addClass('vh');
|
2015-01-31 05:17:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-31 04:15:47 +00:00
|
|
|
del: function() {
|
|
|
|
var del_icon = this.$('.repo-delete-btn');
|
|
|
|
var op_container = this.$('.op-container').css({'position': 'relative'});
|
|
|
|
|
|
|
|
var confirm_msg = gettext("Really want to delete {lib_name}?")
|
|
|
|
.replace('{lib_name}', '<span class="op-target">' + Common.HTMLescape(this.model.get('name')) + '</span>');
|
|
|
|
var confirm_popup = $(this.repoDelConfirmTemplate({
|
|
|
|
content: confirm_msg
|
|
|
|
}))
|
|
|
|
.appendTo(op_container)
|
|
|
|
.css({
|
|
|
|
'left': del_icon.position().left,
|
|
|
|
'top': del_icon.position().top + del_icon.height() + 2,
|
|
|
|
'width': 180
|
|
|
|
});
|
2015-01-31 05:17:47 +00:00
|
|
|
|
2015-03-31 04:15:47 +00:00
|
|
|
var _this = this;
|
|
|
|
$('.no', confirm_popup).click(function() {
|
|
|
|
confirm_popup.addClass('hide').remove(); // `addClass('hide')`: to rm cursor
|
|
|
|
_this.rmHighlight();
|
|
|
|
});
|
|
|
|
$('.yes', confirm_popup).click(function() {
|
|
|
|
$.ajax({
|
|
|
|
url: Common.getUrl({'name':'repo_del', 'repo_id': _this.model.get('id')}),
|
2015-10-10 06:31:20 +00:00
|
|
|
type: 'POST',
|
2015-03-31 04:15:47 +00:00
|
|
|
dataType: 'json',
|
2015-10-10 06:31:20 +00:00
|
|
|
beforeSend: Common.prepareCSRFToken,
|
2015-03-31 04:15:47 +00:00
|
|
|
success: function(data) {
|
|
|
|
_this.remove();
|
|
|
|
Common.feedback(gettext("Delete succeeded."), 'success');
|
2015-01-31 05:17:47 +00:00
|
|
|
},
|
2015-03-31 04:15:47 +00:00
|
|
|
error: function(xhr) {
|
|
|
|
confirm_popup.addClass('hide').remove();
|
|
|
|
_this.rmHighlight();
|
|
|
|
|
|
|
|
var err;
|
|
|
|
if (xhr.responseText) {
|
|
|
|
err = $.parseJSON(xhr.responseText).error;
|
|
|
|
} else {
|
|
|
|
err = gettext("Failed. Please check the network.");
|
|
|
|
}
|
|
|
|
Common.feedback(err, 'error');
|
2015-01-31 05:17:47 +00:00
|
|
|
}
|
|
|
|
});
|
2015-03-31 04:15:47 +00:00
|
|
|
});
|
2015-01-31 05:17:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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'),
|
2015-05-27 09:58:21 +00:00
|
|
|
'user_perm': 'rw',
|
2015-03-18 02:45:13 +00:00
|
|
|
'repo_id': this.model.get('id'),
|
2015-05-13 09:35:14 +00:00
|
|
|
'repo_encrypted': this.model.get('encrypted'),
|
2015-03-18 02:45:13 +00:00
|
|
|
'is_dir': true,
|
|
|
|
'dirent_path': '/',
|
|
|
|
'obj_name': this.model.get('name')
|
|
|
|
};
|
|
|
|
new ShareView(options);
|
2015-12-27 14:09:52 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
togglePopup: function() {
|
|
|
|
var icon = this.$('.js-toggle-popup'),
|
|
|
|
popup = this.$('.hidden-op');
|
|
|
|
|
|
|
|
if (popup.hasClass('hide')) { // the popup is not shown
|
|
|
|
popup.css({'left': icon.position().left});
|
|
|
|
if (icon.offset().top + popup.height() <= $('#main').offset().top + $('#main').height()) {
|
|
|
|
// below the icon
|
|
|
|
popup.css('top', icon.position().top + icon.height() + 3);
|
|
|
|
} else {
|
|
|
|
popup.css('bottom', icon.parent().outerHeight() - icon.position().top + 3);
|
|
|
|
}
|
|
|
|
popup.removeClass('hide');
|
|
|
|
} else {
|
|
|
|
popup.addClass('hide');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
rename: function() {
|
|
|
|
var repo_name = this.model.get('name');
|
|
|
|
|
|
|
|
var form = $(this.renameTemplate({
|
|
|
|
repo_name: repo_name
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
var $name_span = this.$('.repo-name-span'),
|
|
|
|
$op_td = this.$('.repo-op-td'),
|
|
|
|
$name_td = $name_span.closest('td');
|
|
|
|
$name_td.attr('colspan', 2).css({
|
|
|
|
'width': $name_span.width() + $op_td.outerWidth(),
|
|
|
|
'height': $name_span.height()
|
|
|
|
}).append(form);
|
|
|
|
$op_td.hide();
|
|
|
|
$name_span.hide();
|
|
|
|
|
|
|
|
this.togglePopup();
|
|
|
|
|
|
|
|
var cancelRename = function() {
|
|
|
|
form.remove();
|
|
|
|
$op_td.show();
|
|
|
|
$name_span.show();
|
|
|
|
$name_td.attr('colspan', 1).css({
|
|
|
|
'width': $name_span.width()
|
|
|
|
});
|
|
|
|
return false; // stop bubbling (to 'doc click to hide .hidden-op')
|
|
|
|
};
|
|
|
|
$('.cancel', form).click(cancelRename);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
popupHistorySettings: function() {
|
|
|
|
var options = {
|
|
|
|
'repo_name': this.model.get('name'),
|
|
|
|
'repo_id': this.model.get('id')
|
|
|
|
};
|
|
|
|
this.togglePopup(); // close the popup
|
|
|
|
new HistorySettingsDialog(options);
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
popupPermissionSettings: function() {
|
|
|
|
var options = {
|
|
|
|
'repo_name': this.model.get('name'),
|
|
|
|
'repo_id': this.model.get('id')
|
|
|
|
};
|
|
|
|
this.togglePopup(); // close the popup
|
|
|
|
new HistorySettingsDialog(options);
|
|
|
|
return false;
|
2015-01-20 10:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return RepoView;
|
|
|
|
});
|