From 4a1d11d0fcc78db1d334edabeaf87b1145f29a7b Mon Sep 17 00:00:00 2001 From: llj Date: Tue, 3 Feb 2015 13:47:22 +0800 Subject: [PATCH] [myhome lib] added 'more', hide 'loading-tip' when necessary, fixed some bugs --- media/scripts/app/collections/dirents.js | 11 ++++-- media/scripts/app/routers/myhome.js | 5 ++- media/scripts/app/views/dir.js | 50 +++++++++++++++++++++++- media/scripts/common.js | 2 +- seahub/templates/base_for_backbone.html | 12 +++--- seahub/templates/myhome.html | 21 ++++------ 6 files changed, 73 insertions(+), 28 deletions(-) diff --git a/media/scripts/app/collections/dirents.js b/media/scripts/app/collections/dirents.js index 5165749b5f..fc08ab34ec 100644 --- a/media/scripts/app/collections/dirents.js +++ b/media/scripts/app/collections/dirents.js @@ -1,13 +1,18 @@ define([ 'underscore', 'backbone', + 'common', 'app/models/dirent' -], function(_, Backbone, Dirent) { +], function(_, Backbone, Common, Dirent) { 'use strict'; var DirentCollection = Backbone.Collection.extend({ model: Dirent, + url: function () { + return Common.getUrl({name: 'list_lib_dir', repo_id: this.repo_id}); + }, + initialize: function() { }, @@ -26,11 +31,9 @@ define([ }, setPath: function(repo_id, path) { - console.log('init dir: ' + repo_id + ' ' + path); this.repo_id = repo_id; this.path = path; - this.url = '/ajax/lib/' + repo_id + '/dir/?p=' + path; - }, + } }); return DirentCollection; diff --git a/media/scripts/app/routers/myhome.js b/media/scripts/app/routers/myhome.js index 6062381610..df8b65f1bb 100644 --- a/media/scripts/app/routers/myhome.js +++ b/media/scripts/app/routers/myhome.js @@ -20,10 +20,11 @@ define([ }, showDir: function(repo_id, path) { - if (path) + if (path) { path = '/' + path; - else + } else { path = '/'; + } console.log("Repo route has been called.." + "repo_id:" + repo_id + " path:" + path); this.myHomeView.showDir(repo_id, path); }, diff --git a/media/scripts/app/views/dir.js b/media/scripts/app/views/dir.js index 290b65d09d..2579b65c94 100644 --- a/media/scripts/app/views/dir.js +++ b/media/scripts/app/views/dir.js @@ -31,12 +31,34 @@ define([ // initialize common js behavior $('th .checkbox-orig').unbind(); + + var _this = this; + $(window).scroll(function() { + if ($(_this.el).is(':visible')) { + _this.onWindowScroll(); + } + }); }, showDir: function(repo_id, path) { - this.dir.setPath(repo_id, path); - this.dir.fetch({reset: true}); this.$el.show(); + var loading_tip = this.$('.loading-tip').show(); + var dir = this.dir; + dir.setPath(repo_id, path); + dir.fetch({ + reset: true, + data: {'p': path}, + success: function (collection, response, opts) { + dir.last_start = 0; // for 'more' + if (response.dirent_list.length == 0 || // the dir is empty + !response.dirent_more ) { // no 'more' + loading_tip.hide(); + } + }, + error: function () { // todo + loading_tip.hide(); + } + }); }, hide: function() { @@ -227,6 +249,30 @@ define([ el.toggleClass('icon-caret-up icon-caret-down'); }, + onWindowScroll: function () { + var dir = this.dir; + var start = dir.more_start; + if (dir.dirent_more && $(window).scrollTop() + $(window).height() > $(document).height() - $('#footer').outerHeight(true) && start != dir.last_start) { + dir.last_start = start; + var loading_tip = this.$('.loading-tip'); + dir.fetch({ + remove: false, + data: { + 'p': dir.path, + 'start': dir.more_start + }, + success: function (collection, response, opts) { + if (!response.dirent_more ) { // no 'more' + loading_tip.hide(); + } + }, + error: function(xhr, textStatus, errorThrown) { + loading_tip.hide(); + Common.ajaxErrorHandler(xhr, textStatus, errorThrown); + } + }); + } + } }); return DirView; diff --git a/media/scripts/common.js b/media/scripts/common.js index 53f209223d..3bc70750b2 100644 --- a/media/scripts/common.js +++ b/media/scripts/common.js @@ -40,7 +40,7 @@ define([ getUrl: function(options) { var siteRoot = app.config.siteRoot; switch (options.name) { - case 'get_lib_dirents': return siteRoot + 'ajax/lib/' + options.repo_id + '/dirents/'; + case 'list_lib_dir': return siteRoot + 'ajax/lib/' + options.repo_id + '/dir/'; case 'star_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/star/'; case 'unstar_file': return siteRoot + 'ajax/repo/' + options.repo_id + '/file/unstar/'; case 'del_dir': return siteRoot + 'ajax/repo/' + options.repo_id + '/dir/delete/'; diff --git a/seahub/templates/base_for_backbone.html b/seahub/templates/base_for_backbone.html index 7e59ec18ac..bfb2386b05 100644 --- a/seahub/templates/base_for_backbone.html +++ b/seahub/templates/base_for_backbone.html @@ -149,12 +149,12 @@ diff --git a/seahub/templates/myhome.html b/seahub/templates/myhome.html index a0d10ad18a..1c6ed7972f 100644 --- a/seahub/templates/myhome.html +++ b/seahub/templates/myhome.html @@ -203,18 +203,13 @@ {% block extra_script %} {% include "js/lib-op-popups.html" %} - - + {% endblock %}