1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-02 15:57:31 +00:00

[backbone] Add model, template and view for group navigation popup

This commit is contained in:
Daniel Pan 2015-01-27 22:41:16 +08:00
parent fb76295140
commit 167eb79888
7 changed files with 106 additions and 8 deletions

View File

@ -0,0 +1,19 @@
define([
'underscore',
'backbone',
'app/models/group'
], function(_, Backbone, Group) {
'use strict';
var GroupCollection = Backbone.Collection.extend({
model: Group,
url: app.config.siteRoot + 'api2/groups/?with_msg=false',
initialize: function() {
}
});
return GroupCollection;
});

View File

@ -0,0 +1,10 @@
define([
'underscore',
'backbone'
], function(_, Backbone) {
'use strict';
var Group = Backbone.Model.extend({});
return Group;
});

View File

@ -0,0 +1,31 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'app/collections/groups',
'text!' + app.config._tmplRoot + 'group-nav.html',
], function($, _, Backbone, Common, GroupCollection, GroupNavTemplate) {
'use strict';
var GroupNavView = Backbone.View.extend({
template: _.template(GroupNavTemplate),
initialize: function(options) {
this.groups = new GroupCollection();
this.listenTo(this.groups, 'reset', this.reset);
},
reset: function() {
console.log(this.template({groups: this.groups.models}));
},
fetch: function() {
this.groups.fetch({reset: true});
},
});
return GroupNavView;
});

View File

@ -4,10 +4,13 @@ define([
'backbone',
'app/collections/repos',
'app/collections/dirents',
'app/collections/groups',
'app/views/repos',
'app/views/dirents',
'app/views/dir'
], function($, _, Backbone, Repos, DirentCollection, RepoView, DirentView, DirView) {
'app/views/dir',
'app/views/group-nav'
], function($, _, Backbone, Repos, DirentCollection, GroupCollection,
RepoView, DirentView, DirView, GroupNavView) {
'use strict';
var MyHomeView = Backbone.View.extend({
@ -21,6 +24,9 @@ define([
this.$repoTabs = this.$('#repo-tabs');
this.$repoList = this.$('#my-own-repos table tbody');
this.dirView = new DirView();
this.groupView = new GroupNavView();
this.groupView.fetch();
},
initializeRepos: function() {

View File

@ -110,11 +110,11 @@ define([
// TODO: Change to jquery function like $.disableButtion(btn)
enableButton: function(btn) {
btn.removeAttr('disabled').removeClass('btn-disabled');
btn.removeAttr('disabled').removeClass('btn-disabled');
},
disableButton: function(btn) {
btn.attr('disabled', 'disabled').addClass('btn-disabled');
btn.attr('disabled', 'disabled').addClass('btn-disabled');
},
prepareCSRFToken: function(xhr, settings) {

View File

@ -2653,14 +2653,29 @@ class UnseenMessagesCountView(APIView):
########## Groups related
class Groups(APIView):
authentication_classes = (TokenAuthentication, )
authentication_classes = (TokenAuthentication, SessionAuthentication)
permission_classes = (IsAuthenticated,)
throttle_classes = (UserRateThrottle, )
def get(self, request, format=None):
group_json, replynum = get_groups(request.user.username)
res = {"groups": group_json, "replynum": replynum}
return Response(res)
with_msg = request.GET.get('with_msg', 'true')
# To not broken the old API, we need to make with_msg default
if with_msg == 'true':
group_json, replynum = get_groups(request.user.username)
res = {"groups": group_json, "replynum": replynum}
return Response(res)
else:
groups_json = []
joined_groups = get_personal_groups_by_user(request.user.username)
for g in joined_groups:
group = {
"id": g.id,
"name": g.group_name,
"creator": g.creator_name,
"ctime": g.timestamp,
}
groups_json.append(group)
return Response(groups_json)
def put(self, request, format=None):
# modified slightly from groups/views.py::group_list

View File

@ -0,0 +1,17 @@
<div id="top-nav-grp-info" class="top-info-popup hide">
<div class="outer-caret up-outer-caret">
<div class="inner-caret"></div>
</div>
<ul id="top-nav-grp-list">
<% for (var i = 0; i < groups.length; i++) { %>
<li class="item" data-url="/group/1/" title="test">
<img src="/media/avatars/groups/default.png" alt="" width="36" height="36" class="avatar">
<span class="name ellipsis vam">test</span>
<a href="/group/1/discuss/" title="Discussion" class="a fright vh">
<img src="/media/img/msgs.png" alt="">
</a>
</li>
<% } %>
</ul>
<a href="/groups/" class="item all-grp">All Groups</a>
</div>