1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-01 09:24:35 +00:00
seahub/static/scripts/app/views/share-admin-upload-links.js

90 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-06-30 07:06:43 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'app/collections/share-admin-upload-links',
'app/views/share-admin-upload-link'
], function($, _, Backbone, Common, ShareAdminUploadLinkCollection,
ShareAdminUploadLinkView) {
'use strict';
var ShareAdminUploadLinksView = Backbone.View.extend({
2017-12-05 09:53:45 +00:00
el: '.main-panel',
2016-06-30 07:06:43 +00:00
template: _.template($('#share-admin-upload-links-tmpl').html()),
initialize: function() {
this.links = new ShareAdminUploadLinkCollection();
this.listenTo(this.links, 'add', this.addOne);
this.listenTo(this.links, 'reset', this.reset);
},
2017-12-05 09:53:45 +00:00
renderMainCon: function() {
this.$mainCon = $('<div class="main-panel-main" id="share-admin-upload-links"></div>').html(this.template());
this.$el.append(this.$mainCon);
2016-06-30 07:06:43 +00:00
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
},
hide: function() {
2017-12-05 09:53:45 +00:00
this.$mainCon.detach();
2016-06-30 07:06:43 +00:00
},
show: function() {
2017-12-05 09:53:45 +00:00
this.renderMainCon();
2016-06-30 07:06:43 +00:00
this.showContent();
},
showContent: function() {
var _this = this;
this.initPage();
this.links.fetch({
cache: false,
reset: true,
error: function(collection, response, opts) {
var $error = _this.$('.error');
2018-07-31 10:15:44 +00:00
var err_msg = Common.prepareCollectionFetchErrorMsg(collection, response, opts);
2016-06-30 07:06:43 +00:00
$error.html(err_msg).show();
2018-07-31 10:15:44 +00:00
_this.$loadingTip.hide();
2016-06-30 07:06:43 +00:00
}
});
},
initPage: function() {
this.$table.hide();
this.$tableBody.empty();
this.$loadingTip.show();
this.$emptyTip.hide();
this.$('.error').hide();
},
reset: function() {
this.$('.error').hide();
this.$loadingTip.hide();
if (this.links.length) {
this.$emptyTip.hide();
this.$tableBody.empty();
this.links.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
this.$table.hide();
}
},
addOne: function(link) {
var view = new ShareAdminUploadLinkView({model: link});
this.$tableBody.append(view.render().el);
}
});
return ShareAdminUploadLinksView;
});