1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-19 18:29:23 +00:00

show/delete shared repo

This commit is contained in:
lian
2015-03-06 17:53:41 +08:00
committed by Daniel Pan
parent 1496940aa4
commit c42822969d
8 changed files with 165 additions and 23 deletions

View File

@@ -13,11 +13,11 @@ define([
initialize: function(options) {
this.$tabs = $('#repo-tabs');
this.$table = this.$('#repos-shared-to-me table');
this.$table = $('#repos-shared-to-me table');
this.$tableHead = $('thead', this.$table);
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = $('.loading-tip', this.$tabs);
this.$emptyTip = $('.empty-tips', this.tabs);
this.$emptyTip = $('#repos-shared-to-me .empty-tips');
this.repos = new RepoCollection({type: 'shared'});
this.listenTo(this.repos, 'add', this.addOne);
@@ -25,7 +25,7 @@ define([
},
addOne: function(repo, collection, options) {
var view = new SharedRepoView({model: repo});
var view = new SharedRepoView({model: repo, collection: this.repos});
if (options.prepend) {
this.$tableBody.prepend(view.render().el);
} else {
@@ -69,7 +69,6 @@ define([
$('#shared-lib-tab', this.$tabs).parent().removeClass('ui-state-active');
},
});
return SharedReposView;

View File

@@ -15,12 +15,33 @@ define([
events: {
'mouseenter': 'showAction',
'mouseleave': 'hideAction',
'click .repo-delete-btn': 'delete',
'click .repo-share-btn': 'share'
'click .unshare-btn': 'removeShare'
},
initialize: function() {
this.listenTo(this.model, 'destroy', this.remove);
},
removeShare: function(e) {
var _this = this,
after_leave_success = function(data) {
Common.feedback(gettext('Success'), 'success', Common.SUCCESS_TIMOUT);
_this.$el.remove();
_this.collection.remove(_this.model, {silent: true});
if (_this.collection.length == 0) {
$('#repos-shared-to-me table').hide();
$('#repos-shared-to-me .empty-tips').show();
};
};
Common.ajaxGet({
'get_url': Common.getUrl({name: 'ajax_repo_remove_share'}),
'data': {
'repo_id': this.model.get('id'),
'from': this.model.get('owner'),
'share_type': this.model.get('share_type')
},
'after_op_success': after_leave_success
});
},
render: function() {
@@ -37,8 +58,6 @@ define([
this.$el.removeClass('hl');
this.$el.find('.op-icon').addClass('vh');
},
});
return SharedRepoView;

View File

@@ -78,6 +78,8 @@ define([
case 'cancel_cp': return siteRoot + 'ajax/cancel_cp/';
case 'get_shared_link': return '';
case 'get_shared_upload_link': return '';
case 'ajax_repo_remove_share': return siteRoot + 'share/ajax/repo_remove_share/';
}
},
@@ -188,6 +190,36 @@ define([
}
},
ajaxGet: function(params) {
var _this = this,
get_url = params.get_url,
data = params.data,
after_op_error,
after_op_success = params.after_op_success;
if (params.hasOwnProperty('after_op_error')) {
after_op_error = params.after_op_error;
} else {
after_op_error = function(xhr, textStatus, errorThrown) {
var err;
if (xhr.responseText) {
err = $.parseJSON(xhr.responseText).error;
} else {
err = gettext("Failed. Please check the network.");
}
_this.feedback(err, 'error', _this.ERROR_TIMEOUT);
}
};
$.ajax({
url: get_url,
cache: false,
dataType: 'json',
data: data,
success: function(data) {after_op_success(data);},
error: after_op_error
});
},
ajaxPost: function(params) {
var form = params.form,
post_url = params.post_url,
@@ -212,7 +244,7 @@ define([
if (xhr.responseText) {
err = $.parseJSON(xhr.responseText).error;
} else {
err = getText("Failed. Please check the network.");
err = gettext("Failed. Please check the network.");
}
this.feedback(err);
this.enableButton(submit_btn);