From 376422c9357d2ee513b0518c060008551ea50ee5 Mon Sep 17 00:00:00 2001 From: Daniel Pan Date: Thu, 5 May 2016 13:32:39 +0800 Subject: [PATCH] Rewrite group discussion as side panel --- media/css/seahub.css | 46 ++++++++++---- seahub/templates/js/templates.html | 2 +- seahub/templates/libraries.html | 12 ++-- static/scripts/app/router.js | 3 + static/scripts/app/views/group-discussions.js | 62 +++++++++++++------ 5 files changed, 89 insertions(+), 36 deletions(-) diff --git a/media/css/seahub.css b/media/css/seahub.css index 8b50c8d98c..541ec613a4 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -800,6 +800,34 @@ textarea:-moz-placeholder {/* for FF */ .checkbox-label { display:block; } +/**** right side panel ****/ +.right-side-panel { + background:#f8f8f8; + width:400px; + position:fixed; + right:-400px; + top:0; + bottom:0; + z-index:1; + overflow-x:hidden; + border-left:1px solid #c9c9c9; + box-shadow:0 0 4px #ccc; + -webkit-transition: all 0.3s ease; + -moz-transition: all 0.3s ease; + transition: all 0.3s ease; +} +.right-side-panel-hd { + padding:10px; + border-bottom: 1px solid #c9c9c9; +} +.right-side-panel-footer { + position:absolute; + bottom:0; +} +.right-side-panel-con { + overflow-y: auto; + background: #fff; +} /**** messages ****/ .messages { position:fixed; @@ -1288,7 +1316,7 @@ button.sf-dropdown-toggle:focus { } /**** discussions/comments ****/ .msg { - padding:10px; + padding:5px 10px; } .msg-body { margin-left:44px; @@ -1313,8 +1341,9 @@ button.sf-dropdown-toggle:focus { border-top: 1px solid #c9c9c9; } .msg-input { - width:362px; + width:336px; padding:3px 5px; + height:60px; } .msg-form .submit { color:#fff; @@ -1330,6 +1359,7 @@ button.sf-dropdown-toggle:focus { } .load-more-discussion { color:#eb8205; + margin-top:1rem; cursor:pointer; text-align:center; } @@ -3329,7 +3359,7 @@ img.thumbnail { #group { position:relative; } -#group-members, #group-settings, #group-discussions { +#group-members, #group-settings { position:absolute; top:90px; right:0; @@ -3346,14 +3376,8 @@ img.thumbnail { #add-group-members-form .submit { margin:0 0 0 5px; } -#group-discussions { - width:440px; -} -#group-discussions .outer-caret { - right:30px; -} -#group-discussions .sf-popover-con { - padding:0 0; +.group-discussions-con .msg:first-child { + margin-top:0.5rem; } /****** grid view *****/ /* view mode */ diff --git a/seahub/templates/js/templates.html b/seahub/templates/js/templates.html index e1140dc2de..757761b2f5 100644 --- a/seahub/templates/js/templates.html +++ b/seahub/templates/js/templates.html @@ -606,7 +606,7 @@ {% if debug %} diff --git a/static/scripts/app/router.js b/static/scripts/app/router.js index ac80c633b7..7c89d9a89b 100644 --- a/static/scripts/app/router.js +++ b/static/scripts/app/router.js @@ -78,6 +78,9 @@ define([ this.currentView.hide(); this.currentView = newView; } + if (app.ui.groupDiscussions) { + app.ui.groupDiscussions.hide(); + } }, showRepos: function() { diff --git a/static/scripts/app/views/group-discussions.js b/static/scripts/app/views/group-discussions.js index e99372ac91..02fd22f535 100644 --- a/static/scripts/app/views/group-discussions.js +++ b/static/scripts/app/views/group-discussions.js @@ -4,20 +4,17 @@ define([ 'backbone', 'common', 'app/collections/group-discussions', - 'app/views/group-discussion', - 'app/views/widgets/popover' -], function($, _, Backbone, Common, GroupDiscussions, ItemView, PopoverView) { + 'app/views/group-discussion' +], function($, _, Backbone, Common, GroupDiscussions, ItemView) { 'use strict'; - var View = PopoverView.extend({ + var View = Backbone.View.extend({ id: 'group-discussions', - className: 'sf-popover', + className: 'right-side-panel', template: _.template($('#group-discussions-tmpl').html()), initialize: function(options) { - PopoverView.prototype.initialize.call(this); - this.groupView = options.groupView; this.collection = new GroupDiscussions(); @@ -25,9 +22,25 @@ define([ this.listenTo(this.collection, 'reset', this.reset); this.render(); + $("#main").append(this.$el); + + app.ui.groupDiscussions = this; + + var _this = this; + $(document).keydown(function(e) { + // ESCAPE key pressed + if (e.keyCode == 27) { + _this.hide(); + } + }); + + $(window).resize(function() { + _this.setConMaxHeight(); + }); }, events: { + 'click .js-close': 'close', 'click .js-load-more': 'loadMore', 'submit form': 'formSubmit' }, @@ -115,28 +128,41 @@ define([ } }); - $("#group").append(this.$el); + this.$(".msg-input").focus(); app.router.navigate('group/' + this.groupView.group.id + '/discussions/'); }, // set max-height for '.sf-popover-con' setConMaxHeight: function() { - this.$('.sf-popover-con').css({ - 'max-height': $(window).height() - this.$el.offset().top - - this.$('.sf-popover-hd').outerHeight(true) - - this.$('.sf-popover-footer').outerHeight(true) - - 2 // 2: top, bottom border width of $el, - - 10 // 10: leave some margin at the bottom + this.$('.group-discussions-con').css({ + 'height': $(window).height() - this.$el.offset().top + - this.$('.group-discussions-hd').outerHeight(true) + - this.$('.group-discussions-footer').outerHeight(true) }); }, hide: function() { - PopoverView.prototype.hide.call(this); + $(".right-side-panel").css({'right': '-400px'}); + }, + + close: function() { app.router.navigate('group/' + this.groupView.group.id + '/'); + this.hide(); return false; }, + toggle: function() { + this.show(); + return false; + }, + + show: function() { + this.showContent(); + $(".right-side-panel").css({'right': '0px'}); + this.setConMaxHeight(); + }, + replyTo: function(to_user) { var str = "@" + to_user + " "; var $input = this.$('[name="message"]').val(str); @@ -164,7 +190,7 @@ define([ sumHeight += $(this).outerHeight(true); }); // scroll - _this.$('.sf-popover-con').scrollTop(sumHeight - 50); // 50: keep at least 50px gap from the top + _this.$('.group-discussions-con').scrollTop(sumHeight - 50); // 50: keep at least 50px gap from the top }, error: function(collection, response, opts) { var err_msg; @@ -227,9 +253,9 @@ define([ return false; }, - // scroll '.sf-popover-con' to the bottom + // scroll to the bottom scrollConToBottom: function() { - var $el = this.$('.sf-popover-con'); + var $el = this.$('.group-discussions-con'); $el.scrollTop($el[0].scrollHeight - $el[0].clientHeight); }