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:
parent
fb76295140
commit
167eb79888
19
media/scripts/app/collections/groups.js
Normal file
19
media/scripts/app/collections/groups.js
Normal 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;
|
||||
});
|
10
media/scripts/app/models/group.js
Normal file
10
media/scripts/app/models/group.js
Normal file
@ -0,0 +1,10 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone'
|
||||
], function(_, Backbone) {
|
||||
'use strict';
|
||||
|
||||
var Group = Backbone.Model.extend({});
|
||||
|
||||
return Group;
|
||||
});
|
31
media/scripts/app/views/group-nav.js
Normal file
31
media/scripts/app/views/group-nav.js
Normal 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;
|
||||
});
|
@ -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() {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
17
seahub/templates/js/group-nav.html
Normal file
17
seahub/templates/js/group-nav.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user