From 2dc00204df442721a3bb94dd775cb12c0b0d1896 Mon Sep 17 00:00:00 2001 From: llj Date: Tue, 12 May 2015 16:35:39 +0800 Subject: [PATCH] enable 'show error' for 'fetch libs' Conflicts: static/scripts/app/views/group.js static/scripts/app/views/myhome-repos.js static/scripts/app/views/myhome-shared-repos.js static/scripts/app/views/organization.js --- media/css/seahub.css | 1 + seahub/templates/libraries.html | 5 +- static/scripts/app/views/group.js | 49 ++++++++++++++----- static/scripts/app/views/myhome-repos.js | 38 +++++++++++--- .../scripts/app/views/myhome-shared-repos.js | 36 +++++++++++--- static/scripts/app/views/myhome-sub-repos.js | 28 +++++++++-- static/scripts/app/views/organization.js | 36 +++++++++++--- 7 files changed, 154 insertions(+), 39 deletions(-) diff --git a/media/css/seahub.css b/media/css/seahub.css index 50a9211520..13052cf7cb 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -245,6 +245,7 @@ p { margin:0.5em 0; } .hide { display:none } .error { color:red; } .errorlist { color: red; } +.error-tip { text-align:center; margin-top:5em;} .ovhd { overflow:hidden; } .bold { font-weight:bold; } .no-bold { font-weight:normal; } diff --git a/seahub/templates/libraries.html b/seahub/templates/libraries.html index dad76ed46e..a4c52fdde3 100644 --- a/seahub/templates/libraries.html +++ b/seahub/templates/libraries.html @@ -104,6 +104,7 @@ {% trans 'Loading...' %} +

@@ -177,6 +178,7 @@
{% trans 'Loading...' %} +

@@ -189,11 +191,12 @@ - {% trans 'Loading...' %}

{% trans "No public library" %}

{% blocktrans %}You can create a public library by clicking "New Library" button, others can view and download this library.{% endblocktrans %}

+ {% trans 'Loading...' %} +

{% include "js/dir-view.html" %} diff --git a/static/scripts/app/views/group.js b/static/scripts/app/views/group.js index 3d74db9209..1e8337f60b 100644 --- a/static/scripts/app/views/group.js +++ b/static/scripts/app/views/group.js @@ -12,23 +12,23 @@ define([ 'use strict'; var GroupView = Backbone.View.extend({ - el: '#main', + el: '#group-repo-tabs', reposHdTemplate: _.template($('#shared-repos-hd-tmpl').html()), events: { - 'click #group-repo-tabs .repo-create': 'createRepo', + 'click .repo-create': 'createRepo', 'click #grp-repos .by-name': 'sortByName', 'click #grp-repos .by-time': 'sortByTime' }, initialize: function(options) { - this.$tabs = this.$('#group-repo-tabs'); - this.$table = this.$('#grp-repos table', this.$tabs); - this.$tableHead = $('thead', this.$table); - this.$tableBody = $('tbody', this.$table); - this.$loadingTip = $('.loading-tip', this.$tabs); - this.$emptyTip = $('.empty-tips', this.$tabs); + this.$tabs = this.$el; + this.$table = this.$('table'); + this.$tableHead = this.$('thead'); + this.$tableBody = this.$('tbody'); + this.$loadingTip = this.$('.loading-tip'); + this.$emptyTip = this.$('.empty-tips'); this.sideNavView = new GroupSideNavView(); @@ -57,12 +57,13 @@ define([ }, reset: function() { - this.renderReposHd(); - this.$tableBody.empty(); - this.repos.each(this.addOne, this); + this.$('.error').hide(); this.$loadingTip.hide(); if (this.repos.length) { this.$emptyTip.hide(); + this.renderReposHd(); + this.$tableBody.empty(); + this.repos.each(this.addOne, this); this.$table.show(); } else { this.$emptyTip.show(); @@ -87,9 +88,31 @@ define([ this.$emptyTip.hide(); this.$tabs.show(); this.$table.hide(); + var $loadingTip = this.$loadingTip; + $loadingTip.show(); + var _this = this; this.repos.setGroupID(group_id); - this.repos.fetch({reset: true, data: {from: 'web'}}); - this.$loadingTip.show(); + this.repos.fetch({ + reset: true, + data: {from: 'web'}, + success: function (collection, response, opts) { + }, + error: function (collection, response, opts) { + $loadingTip.hide(); + var $error = _this.$('.error'); + var err_msg; + if (response.responseText) { + if (response['status'] == 401 || response['status'] == 403) { + err_msg = gettext("Permission error"); + } else { + err_msg = gettext("Error"); + } + } else { + err_msg = gettext('Please check the network.'); + } + $error.html(err_msg).show(); + } + }); }, hideRepoList: function() { diff --git a/static/scripts/app/views/myhome-repos.js b/static/scripts/app/views/myhome-repos.js index 7881264bc7..36b894d2bd 100644 --- a/static/scripts/app/views/myhome-repos.js +++ b/static/scripts/app/views/myhome-repos.js @@ -48,30 +48,52 @@ define([ }, reset: function() { - this.renderReposHd(); - this.$tableBody.empty(); - this.repos.each(this.addOne, this); + this.$('.error').hide(); + this.$loadingTip.hide(); if (this.repos.length) { this.$emptyTip.hide(); + this.renderReposHd(); + this.$tableBody.empty(); + this.repos.each(this.addOne, this); this.$table.show(); } else { - this.$emptyTip.show(); this.$table.hide(); + this.$emptyTip.show(); // Show guide popup when there is no owned repos and guide flag is true. if (app.pageOptions.guide_enabled) { $('#guide-for-new').modal({appendTo: '#main', focus:false}); app.pageOptions.guide_enabled = false; } } - this.$loadingTip.hide(); }, showMyRepos: function() { - this.repos.fetch({reset: true}); this.$tabs.show(); + $('#mylib-tab').parent().addClass('ui-state-active'); this.$table.hide(); - this.$loadingTip.show(); - $('#mylib-tab', this.$tabs).parent().addClass('ui-state-active'); + var $loadingTip = this.$loadingTip; + $loadingTip.show(); + var _this = this; + this.repos.fetch({ + reset: true, + success: function (collection, response, opts) { + }, + error: function (collection, response, opts) { + $loadingTip.hide(); + var $error = _this.$('.error'); + var err_msg; + if (response.responseText) { + if (response['status'] == 401 || response['status'] == 403) { + err_msg = gettext("Permission error"); + } else { + err_msg = gettext("Error"); + } + } else { + err_msg = gettext('Please check the network.'); + } + $error.html(err_msg).show(); + } + }); }, show: function() { diff --git a/static/scripts/app/views/myhome-shared-repos.js b/static/scripts/app/views/myhome-shared-repos.js index 34e0a00615..a193e89cff 100644 --- a/static/scripts/app/views/myhome-shared-repos.js +++ b/static/scripts/app/views/myhome-shared-repos.js @@ -40,25 +40,47 @@ define([ }, reset: function() { - this.renderReposHd(); - this.$tableBody.empty(); - this.repos.each(this.addOne, this); + this.$('.error').hide(); + this.$loadingTip.hide(); if (this.repos.length) { this.$emptyTip.hide(); + this.renderReposHd(); + this.$tableBody.empty(); + this.repos.each(this.addOne, this); this.$table.show(); } else { this.$emptyTip.show(); this.$table.hide(); } - this.$loadingTip.hide(); }, showSharedRepos: function() { - this.repos.fetch({reset: true}); this.$tabs.show(); + $('#shared-lib-tab').parent().addClass('ui-state-active'); this.$table.hide(); - this.$loadingTip.show(); - $('#shared-lib-tab', this.$tabs).parent().addClass('ui-state-active'); + var $loadingTip = this.$loadingTip; + $loadingTip.show(); + var _this = this; + this.repos.fetch({ + reset: true, + success: function (collection, response, opts) { + }, + error: function (collection, response, opts) { + $loadingTip.hide(); + var $error = _this.$('.error'); + var err_msg; + if (response.responseText) { + if (response['status'] == 401 || response['status'] == 403) { + err_msg = gettext("Permission error"); + } else { + err_msg = gettext("Error"); + } + } else { + err_msg = gettext('Please check the network.'); + } + $error.html(err_msg).show(); + } + }); }, show: function() { diff --git a/static/scripts/app/views/myhome-sub-repos.js b/static/scripts/app/views/myhome-sub-repos.js index 240791111d..ce44197a19 100644 --- a/static/scripts/app/views/myhome-sub-repos.js +++ b/static/scripts/app/views/myhome-sub-repos.js @@ -40,6 +40,7 @@ define([ }, reset: function() { + this.$('.error').hide(); this.$tableBody.empty(); this.repos.each(this.addOne, this); if (this.repos.length) { @@ -53,11 +54,32 @@ define([ }, showSubRepos: function() { - this.repos.fetch({reset: true}); this.$tabs.show(); + $('#sublib-tab').parent().addClass('ui-state-active'); this.$table.hide(); - this.$loadingTip.show(); - $('#sublib-tab', this.$tabs).parent().addClass('ui-state-active'); + var $loadingTip = this.$loadingTip; + $loadingTip.show(); + var _this = this; + this.repos.fetch({ + reset: true, + success: function (collection, response, opts) { + }, + error: function (collection, response, opts) { + $loadingTip.hide(); + var $error = _this.$('.error'); + var err_msg; + if (response.responseText) { + if (response['status'] == 401 || response['status'] == 403) { + err_msg = gettext("Permission error"); + } else { + err_msg = gettext("Error"); + } + } else { + err_msg = gettext('Please check the network.'); + } + $error.html(err_msg).show(); + } + }); }, show: function() { diff --git a/static/scripts/app/views/organization.js b/static/scripts/app/views/organization.js index c8e03049cb..4024c4f9f8 100644 --- a/static/scripts/app/views/organization.js +++ b/static/scripts/app/views/organization.js @@ -56,25 +56,47 @@ define([ }, reset: function() { - this.renderReposHd(); - this.$tableBody.empty(); - this.repos.each(this.addOne, this); + this.$('.error').hide(); + this.$loadingTip.hide(); if (this.repos.length) { this.$emptyTip.hide(); + this.renderReposHd(); + this.$tableBody.empty(); + this.repos.each(this.addOne, this); this.$table.show(); } else { - this.$emptyTip.show(); this.$table.hide(); + this.$emptyTip.show(); } - this.$loadingTip.hide(); }, showRepoList: function() { this.$sideNav.show(); this.dirView.hide(); this.$reposDiv.show(); - this.repos.fetch({reset: true}); - this.$loadingTip.show(); + var $loadingTip = this.$loadingTip; + $loadingTip.show(); + var _this = this; + this.repos.fetch({ + reset: true, + success: function (collection, response, opts) { + }, + error: function (collection, response, opts) { + $loadingTip.hide(); + var $error = _this.$('.error'); + var err_msg; + if (response.responseText) { + if (response['status'] == 401 || response['status'] == 403) { + err_msg = gettext("Permission error"); + } else { + err_msg = gettext("Error"); + } + } else { + err_msg = gettext('Please check the network.'); + } + $error.html(err_msg).show(); + } + }); }, hideRepoList: function() {