1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 08:28:11 +00:00

[myhome lib] added 'more', hide 'loading-tip' when necessary, fixed some bugs

This commit is contained in:
llj
2015-02-03 13:47:22 +08:00
committed by Daniel Pan
parent 02ec7cfc94
commit 4a1d11d0fc
6 changed files with 73 additions and 28 deletions

View File

@@ -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;

View File

@@ -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);
},

View File

@@ -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;

View File

@@ -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/';

View File

@@ -149,12 +149,12 @@
</div><!-- wrapper -->
<script type="text/javascript">
app = window.app = {
var app = {
config: {
mediaUrl: '{{ MEDIA_URL }}',
siteRoot: '{{ SITE_ROOT }}',
_tmplRoot: '{{ SITE_ROOT }}_templates/js/'
},
}
};
</script>
<script type="text/javascript" src="{% url 'seahub.views.i18n.cached_javascript_catalog' %}"></script>

View File

@@ -203,18 +203,13 @@
{% block extra_script %}
{% include "js/lib-op-popups.html" %}
<script>
<script type="text/javascript">
app["pageOptions"] = {
base_url: "{{ SITE_ROOT }}" + "home/my/",
csrfToken: "{{ csrf_token }}",
reposUrl: "{% url 'api2-repos' %}"
};
app.config = {
siteRoot: "{{ SITE_ROOT }}",
_tmplRoot: "{{ SITE_ROOT }}" + "_templates/js/",
mediaURL: "{{ MEDIA_URL }}",
};
app.globalState = {};
</script>
<script data-main="{{ MEDIA_URL }}scripts/myhome" src="{{ MEDIA_URL }}scripts/lib/require.js"></script>
<script type="text/javascript" data-main="{{ MEDIA_URL }}scripts/myhome" src="{{ MEDIA_URL }}scripts/lib/require.js"></script>
{% endblock %}