1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 15:38:15 +00:00

Rewrite repo with HLItemView

This commit is contained in:
Daniel Pan
2016-03-22 11:47:52 +08:00
parent 6254417be8
commit 2e5ced905f
6 changed files with 38 additions and 66 deletions

View File

@@ -265,7 +265,8 @@ app["pageOptions"] = {
}; };
app.ui = { app.ui = {
currentDropdown: null, currentDropdown: null,
currentHighlightedItem: null currentHighlightedItem: null,
freezeItemHightlight: false
}; };
</script> </script>
{% if debug %} {% if debug %}

View File

@@ -2,22 +2,23 @@ define([
'jquery', 'jquery',
'underscore', 'underscore',
'backbone', 'backbone',
'common' 'common',
], function($, _, Backbone, Common) { 'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, HLItemView) {
'use strict'; 'use strict';
var GroupRepoView = Backbone.View.extend({ var GroupRepoView = HLItemView.extend({
tagName: 'tr', tagName: 'tr',
template: _.template($('#group-repo-tmpl').html()), template: _.template($('#group-repo-tmpl').html()),
events: { events: {
'mouseenter': 'highlight',
'mouseleave': 'rmHighlight',
'click .cancel-share': 'unshare' 'click .cancel-share': 'unshare'
}, },
initialize: function(options) { initialize: function(options) {
HLItemView.prototype.initialize.call(this);
this.group_id = options.group_id; this.group_id = options.group_id;
this.is_staff = options.is_staff; this.is_staff = options.is_staff;
@@ -48,14 +49,6 @@ define([
return this; return this;
}, },
highlight: function() {
this.$el.addClass('hl').find('.op-icon').removeClass('vh');
},
rmHighlight: function() {
this.$el.removeClass('hl').find('.op-icon').addClass('vh');
},
unshare: function() { unshare: function() {
var lib_name = this.model.get('name'); var lib_name = this.model.get('name');
this.model.destroy({ this.model.destroy({

View File

@@ -2,16 +2,18 @@ define([
'jquery', 'jquery',
'underscore', 'underscore',
'backbone', 'backbone',
'common' 'common',
], function($, _, Backbone, Common) { 'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, HLItemView) {
'use strict'; 'use strict';
var OrganizationRepoView = Backbone.View.extend({ var OrganizationRepoView = HLItemView.extend({
tagName: 'tr', tagName: 'tr',
template: _.template($('#organization-repo-tmpl').html()), template: _.template($('#organization-repo-tmpl').html()),
initialize: function() { initialize: function() {
HLItemView.prototype.initialize.call(this);
}, },
render: function() { render: function() {
@@ -27,19 +29,9 @@ define([
}, },
events: { events: {
'mouseenter': 'highlight',
'mouseleave': 'rmHighlight',
'click .cancel-share': 'removeShare' 'click .cancel-share': 'removeShare'
}, },
highlight: function() {
this.$el.addClass('hl').find('.op-icon').removeClass('vh');
},
rmHighlight: function() {
this.$el.removeClass('hl').find('.op-icon').addClass('vh');
},
removeShare: function() { removeShare: function() {
var el = this.$el; var el = this.$el;
var lib_name = this.model.get('name'); var lib_name = this.model.get('name');

View File

@@ -7,12 +7,14 @@ define([
'app/views/dialogs/repo-change-password', 'app/views/dialogs/repo-change-password',
'app/views/dialogs/repo-history-settings', 'app/views/dialogs/repo-history-settings',
'app/views/dialogs/repo-share-link-admin', 'app/views/dialogs/repo-share-link-admin',
'app/views/dialogs/repo-folder-perm-admin' 'app/views/dialogs/repo-folder-perm-admin',
'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, ShareView, RepoChangePasswordDialog, ], function($, _, Backbone, Common, ShareView, RepoChangePasswordDialog,
HistorySettingsDialog, RepoShareLinkAdminDialog, RepoFolderPermAdminDialog) { HistorySettingsDialog, RepoShareLinkAdminDialog, RepoFolderPermAdminDialog,
HLItemView) {
'use strict'; 'use strict';
var RepoView = Backbone.View.extend({ var RepoView = HLItemView.extend({
tagName: 'tr', tagName: 'tr',
template: _.template($('#repo-tmpl').html()), template: _.template($('#repo-tmpl').html()),
@@ -21,8 +23,6 @@ define([
transferTemplate: _.template($('#repo-transfer-form-tmpl').html()), transferTemplate: _.template($('#repo-transfer-form-tmpl').html()),
events: { events: {
'mouseenter': 'highlight',
'mouseleave': 'rmHighlight',
'click .repo-delete-btn': 'del', 'click .repo-delete-btn': 'del',
'click .repo-share-btn': 'share', 'click .repo-share-btn': 'share',
'click .js-toggle-popup': 'togglePopup', 'click .js-toggle-popup': 'togglePopup',
@@ -35,6 +35,8 @@ define([
}, },
initialize: function() { initialize: function() {
HLItemView.prototype.initialize.call(this);
this.listenTo(this.model, "change", this.render); this.listenTo(this.model, "change", this.render);
}, },
@@ -50,23 +52,6 @@ define([
return this; return this;
}, },
// disable 'hover' when 'repo-del-confirm' popup is shown
highlight: function() {
if ($('#my-own-repos .repo-del-confirm').length == 0
&& !$('.hidden-op:visible').length
&& !$('#repo-rename-form').length) {
this.$el.addClass('hl').find('.op-icon').removeClass('vh');
}
},
rmHighlight: function() {
if ($('#my-own-repos .repo-del-confirm').length == 0
&& !$('.hidden-op:visible').length
&& !$('#repo-rename-form').length) {
this.$el.removeClass('hl').find('.op-icon').addClass('vh');
}
},
del: function() { del: function() {
var del_icon = this.$('.repo-delete-btn'); var del_icon = this.$('.repo-delete-btn');
var op_container = this.$('.op-container').css({'position': 'relative'}); var op_container = this.$('.op-container').css({'position': 'relative'});
@@ -83,9 +68,12 @@ define([
'width': 180 'width': 180
}); });
app.ui.freezeItemHightlight = true;
var _this = this; var _this = this;
$('.no', confirm_popup).click(function() { $('.no', confirm_popup).click(function() {
confirm_popup.addClass('hide').remove(); // `addClass('hide')`: to rm cursor confirm_popup.addClass('hide').remove(); // `addClass('hide')`: to rm cursor
app.ui.freezeItemHightlight = false;
_this.rmHighlight(); _this.rmHighlight();
}); });
$('.yes', confirm_popup).click(function() { $('.yes', confirm_popup).click(function() {
@@ -95,10 +83,12 @@ define([
dataType: 'json', dataType: 'json',
beforeSend: Common.prepareCSRFToken, beforeSend: Common.prepareCSRFToken,
success: function(data) { success: function(data) {
app.ui.freezeItemHightlight = false;
_this.remove(); _this.remove();
Common.feedback(gettext("Delete succeeded."), 'success'); Common.feedback(gettext("Delete succeeded."), 'success');
}, },
error: function(xhr) { error: function(xhr) {
app.ui.freezeItemHightlight = false;
confirm_popup.addClass('hide').remove(); confirm_popup.addClass('hide').remove();
_this.rmHighlight(); _this.rmHighlight();
@@ -164,8 +154,10 @@ define([
$name_span.hide(); $name_span.hide();
this.togglePopup(); this.togglePopup();
app.ui.freezeItemHightlight = true;
var cancelRename = function() { var cancelRename = function() {
app.ui.freezeItemHightlight = false;
form.remove(); form.remove();
$op_td.show(); $op_td.show();
$name_span.show(); $name_span.show();
@@ -195,6 +187,7 @@ define([
repo_id: _this.model.get('id') repo_id: _this.model.get('id')
}) + '?op=rename'; }) + '?op=rename';
var after_op_success = function(data) { var after_op_success = function(data) {
app.ui.freezeItemHightlight = false;
_this.model.set({ 'name': new_name }); // it will trigger 'change' event _this.model.set({ 'name': new_name }); // it will trigger 'change' event
}; };
var after_op_error = function(xhr) { var after_op_error = function(xhr) {

View File

@@ -2,22 +2,22 @@ define([
'jquery', 'jquery',
'underscore', 'underscore',
'backbone', 'backbone',
'common' 'common',
], function($, _, Backbone, Common) { 'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, HLItemView) {
'use strict'; 'use strict';
var SharedRepoView = Backbone.View.extend({ var SharedRepoView = HLItemView.extend({
tagName: 'tr', tagName: 'tr',
template: _.template($('#shared-repo-tmpl').html()), template: _.template($('#shared-repo-tmpl').html()),
events: { events: {
'mouseenter': 'showAction',
'mouseleave': 'hideAction',
'click .unshare-btn': 'removeShare' 'click .unshare-btn': 'removeShare'
}, },
initialize: function() { initialize: function() {
HLItemView.prototype.initialize.call(this);
}, },
removeShare: function(e) { removeShare: function(e) {
@@ -56,17 +56,8 @@ define([
}); });
this.$el.html(this.template(obj)); this.$el.html(this.template(obj));
return this; return this;
},
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');
} }
}); });
return SharedRepoView; return SharedRepoView;

View File

@@ -20,7 +20,9 @@ define([
}, },
highlight: function() { highlight: function() {
if (app.ui.currentDropdown) { // if there are dropdown items or freezeItemHightlight is set, don't highlight
console.log("highlight");
if (app.ui.currentDropdown || app.ui.freezeItemHightlight) {
return; return;
} }
app.ui.currentHighlightedItem = this; app.ui.currentHighlightedItem = this;
@@ -28,7 +30,7 @@ define([
}, },
rmHighlight: function() { rmHighlight: function() {
if (app.ui.currentDropdown) { if (app.ui.currentDropdown || app.ui.freezeItemHightlight) {
return; return;
} }
app.ui.currentHighlightedItem = null; app.ui.currentHighlightedItem = null;