diff --git a/media/css/seahub.css b/media/css/seahub.css index 3b86a1466e..183e4cb0f3 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -1,11 +1,11 @@ /** * CONTENTS - * + * * Font Icons * icon-xx ...............Font Awesome 3.2.1 by Dave Gandy * sf2-icon-xx ...........seafile-font2 * - * Reset + * Reset * tags ..................reset styles of tags * * Helper @@ -1157,12 +1157,16 @@ textarea:-moz-placeholder {/* for FF */ text-decoration:none; } /**** popover ****/ /* e.g. top notice popup, group members popup */ +.popover-container { + position:relative; +} .popover { width:240px; background:#fff; border:1px solid #c9c9c9; border-radius:3px; box-shadow:0 0 1px #f3f3f3; + position:absolute; } .popover-hd { padding:5px 0 3px; @@ -3896,3 +3900,18 @@ img.thumbnail { #dir-view .grid-item { width:134px; } +/* devices */ +.device-libs-popover { + left:-80px; + z-index:100; +} +.device-libs-item { + display:block; + padding:4px 12px; + white-space:nowrap; + color:#eb8205; +} +.device-libs-item:hover { + background:#f8f8f8; + text-decoration:none; +} diff --git a/seahub/templates/js/templates.html b/seahub/templates/js/templates.html index aacebe8000..cbbbc48991 100644 --- a/seahub/templates/js/templates.html +++ b/seahub/templates/js/templates.html @@ -845,27 +845,7 @@ - + + + diff --git a/static/scripts/app/models/device.js b/static/scripts/app/models/device.js index 026fabf3a7..d9dd25c45d 100644 --- a/static/scripts/app/models/device.js +++ b/static/scripts/app/models/device.js @@ -1,10 +1,36 @@ define([ 'underscore', - 'backbone' -], function(_, Backbone) { + 'backbone', + 'common', +], function(_, Backbone, Common) { 'use strict'; - var Device = Backbone.Model.extend({}); + var Device = Backbone.Model.extend({ + unlink: function(options) { + var data = { + 'platform': this.get('platform'), + 'device_id': this.get('device_id') + }; + + $.ajax({ + url: Common.getUrl({name: 'devices'}), + type: 'DELETE', + dataType: 'json', + beforeSend: Common.prepareCSRFToken, + data: data, + success: function() { + if (options.success) { + options.success(); + } + }, + error: function(xhr) { + if (options.error) { + options.error(xhr); + } + } + }); + }, + }); return Device; }); diff --git a/static/scripts/app/router.js b/static/scripts/app/router.js index c46dc4716b..222fd5c027 100644 --- a/static/scripts/app/router.js +++ b/static/scripts/app/router.js @@ -128,6 +128,7 @@ define([ } this.switchCurrentView(this.myHomeView); this.myHomeView.showDir('common', repo_id, path); + this.sideNavView.setCurTab('mine'); }, showSharedRepoDir: function(repo_id, path) { diff --git a/static/scripts/app/views/device.js b/static/scripts/app/views/device.js index 38123b9374..468682fd2f 100644 --- a/static/scripts/app/views/device.js +++ b/static/scripts/app/views/device.js @@ -12,13 +12,20 @@ define([ template: _.template($('#device-item-tmpl').html()), events: { - 'mouseenter': 'showAction', - 'mouseleave': 'hideAction', + 'mouseenter': 'highlight', + 'mouseleave': 'rmHighlight', 'click .unlink-device': 'unlinkDevice', - 'click .lib-num': 'showSyncedRepos' + 'click .js-toggle-repos': 'toggleSyncedRepos' }, initialize: function() { + $(document).click(function(e) { + var target = e.target || event.srcElement; + if (!$('.js-toggle-repos, .device-libs-popover').is(target)) { + $('.device-libs-popover').addClass('hide'); + $('.dir-icon').removeClass('icon-caret-up').addClass('icon-caret-down'); + } + }); }, render: function () { @@ -50,52 +57,50 @@ define([ return this; }, - showAction: function() { + highlight: function() { this.$el.addClass('hl'); this.$el.find('.op-icon').removeClass('vh'); }, - hideAction: function() { + rmHighlight: function() { this.$el.removeClass('hl'); this.$el.find('.op-icon').addClass('vh'); }, - showSyncedRepos: function(e) { - var $lib_num = $(e.currentTarget); - var lib_list = $lib_num.next('.lib-list'); - var dir_icon = $lib_num.children('.dir-icon'); + toggleSyncedRepos: function(e) { + var $current_icon= $(e.currentTarget).children('.dir-icon'), + $current_popover = $(e.currentTarget).next('.device-libs-popover'); - if (lib_list.length > 0) { - lib_list.toggleClass('hide'); - if (lib_list.hasClass('hide')) { - dir_icon.removeClass('icon-caret-up').addClass('icon-caret-down'); - } else { - dir_icon.removeClass('icon-caret-down').addClass('icon-caret-up'); - } + $('.device-libs-popover').not($current_popover).addClass('hide'); + $('.dir-icon').not($current_icon).removeClass('icon-caret-up').addClass('icon-caret-down'); + + $current_popover.toggleClass('hide'); + if ($current_icon.hasClass('icon-caret-up')) { + $current_icon.removeClass('icon-caret-up').addClass('icon-caret-down'); + } else { + $current_icon.removeClass('icon-caret-down').addClass('icon-caret-up'); } + + return false }, unlinkDevice: function() { var _this = this, - data = { - 'platform': this.model.get('platform'), - 'device_id': this.model.get('device_id') - }; + device_name = this.model.get('device_name'); - $.ajax({ - url: Common.getUrl({name: 'devices'}), - type: 'DELETE', - dataType: 'json', - beforeSend: Common.prepareCSRFToken, - data: data, + this.model.unlink({ success: function() { _this.remove(); - Common.feedback(gettext("Success"), 'success'); + + var msg = gettext("Successfully unlink %(name)s.") + .replace('%(name)s', Common.HTMLescape(device_name)); + Common.feedback(msg, 'success'); }, - error: function (xhr) { + error: function(xhr) { Common.ajaxErrorHandler(xhr); } }); + return false; } });