mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 07:27:04 +00:00
[backbone] Add model, template and view for group navigation popup
This commit is contained in:
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',
|
'backbone',
|
||||||
'app/collections/repos',
|
'app/collections/repos',
|
||||||
'app/collections/dirents',
|
'app/collections/dirents',
|
||||||
|
'app/collections/groups',
|
||||||
'app/views/repos',
|
'app/views/repos',
|
||||||
'app/views/dirents',
|
'app/views/dirents',
|
||||||
'app/views/dir'
|
'app/views/dir',
|
||||||
], function($, _, Backbone, Repos, DirentCollection, RepoView, DirentView, DirView) {
|
'app/views/group-nav'
|
||||||
|
], function($, _, Backbone, Repos, DirentCollection, GroupCollection,
|
||||||
|
RepoView, DirentView, DirView, GroupNavView) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var MyHomeView = Backbone.View.extend({
|
var MyHomeView = Backbone.View.extend({
|
||||||
@@ -21,6 +24,9 @@ define([
|
|||||||
this.$repoTabs = this.$('#repo-tabs');
|
this.$repoTabs = this.$('#repo-tabs');
|
||||||
this.$repoList = this.$('#my-own-repos table tbody');
|
this.$repoList = this.$('#my-own-repos table tbody');
|
||||||
this.dirView = new DirView();
|
this.dirView = new DirView();
|
||||||
|
|
||||||
|
this.groupView = new GroupNavView();
|
||||||
|
this.groupView.fetch();
|
||||||
},
|
},
|
||||||
|
|
||||||
initializeRepos: function() {
|
initializeRepos: function() {
|
||||||
|
@@ -110,11 +110,11 @@ define([
|
|||||||
|
|
||||||
// TODO: Change to jquery function like $.disableButtion(btn)
|
// TODO: Change to jquery function like $.disableButtion(btn)
|
||||||
enableButton: function(btn) {
|
enableButton: function(btn) {
|
||||||
btn.removeAttr('disabled').removeClass('btn-disabled');
|
btn.removeAttr('disabled').removeClass('btn-disabled');
|
||||||
},
|
},
|
||||||
|
|
||||||
disableButton: function(btn) {
|
disableButton: function(btn) {
|
||||||
btn.attr('disabled', 'disabled').addClass('btn-disabled');
|
btn.attr('disabled', 'disabled').addClass('btn-disabled');
|
||||||
},
|
},
|
||||||
|
|
||||||
prepareCSRFToken: function(xhr, settings) {
|
prepareCSRFToken: function(xhr, settings) {
|
||||||
|
@@ -2653,14 +2653,29 @@ class UnseenMessagesCountView(APIView):
|
|||||||
|
|
||||||
########## Groups related
|
########## Groups related
|
||||||
class Groups(APIView):
|
class Groups(APIView):
|
||||||
authentication_classes = (TokenAuthentication, )
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
throttle_classes = (UserRateThrottle, )
|
throttle_classes = (UserRateThrottle, )
|
||||||
|
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
group_json, replynum = get_groups(request.user.username)
|
with_msg = request.GET.get('with_msg', 'true')
|
||||||
res = {"groups": group_json, "replynum": replynum}
|
# To not broken the old API, we need to make with_msg default
|
||||||
return Response(res)
|
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):
|
def put(self, request, format=None):
|
||||||
# modified slightly from groups/views.py::group_list
|
# 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>
|
Reference in New Issue
Block a user