wekan/client/components/sidebar/sidebar.js
Maxime Quandalle dcc64f44f9 UI improvements
* Implement visibility choice on board creation;

* Rework the board header bar. Remove links to un-implemented
features;

* Implement a board star counter (visible if the board have >2 stars);

* Define a new icon (a thin cross) to close elements;

* Remove $(document).on('mouseover') event handlers that were
basically fired hundreds of times for nothing, we now define a proper
Tracker dependency to execute jquery-ui plugin initialization only
when something has changed;

* Bug fixes related to list scrolling.
2015-05-27 17:23:25 +02:00

119 lines
2.9 KiB
JavaScript

var defaultView = 'home';
Sidebar = null;
BlazeComponent.extendComponent({
template: function() {
return 'sidebar';
},
mixins: function() {
return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
},
onCreated: function() {
this._isOpen = new ReactiveVar(! Session.get('currentCard'));
this._view = new ReactiveVar(defaultView);
Sidebar = this;
},
onDestroyed: function() {
Sidebar = null;
},
isOpen: function() {
return this._isOpen.get();
},
open: function() {
if (! this._isOpen.get()) {
this._isOpen.set(true);
}
},
hide: function() {
if (this._isOpen.get()) {
this._isOpen.set(false);
}
},
toogle: function() {
this._isOpen.set(! this._isOpen.get());
},
calculateNextPeak: function() {
var altitude = this.find('.js-board-sidebar-content').scrollHeight;
this.callFirstWith(this, 'setNextPeak', altitude);
},
reachNextPeak: function() {
var activitiesComponent = this.componentChildren('activities')[0];
activitiesComponent.loadNextPage();
},
isTongueHidden: function() {
return this.isOpen() && this.getView() !== defaultView;
},
getView: function() {
return this._view.get();
},
setView: function(view) {
view = view || defaultView;
this._view.set(view);
},
getViewTemplate: function() {
return this.getView() + 'Sidebar';
},
// Board members can assign people or labels by drag-dropping elements from
// the sidebar to the cards on the board. In order to re-initialize the
// jquery-ui plugin any time a draggable member or label is modified or
// removed we use a autorun function and register a dependency on the both
// members and labels fields of the current board document.
onRendered: function() {
var self = this;
if (! Meteor.userId() || ! Meteor.user().isBoardMember())
return;
self.autorun(function() {
var currentBoardId = Tracker.nonreactive(function() {
return Session.get('currentBoard');
});
Boards.findOne(currentBoardId, {
fields: {
members: 1,
labels: 1
}
});
Tracker.afterFlush(function() {
self.$('.js-member,.js-label').draggable({
appendTo: 'body',
helper: 'clone',
revert: 'invalid',
revertDuration: 150,
snap: false,
snapMode: 'both',
start: function() {
EscapeActions.executeLowerThan('popup');
}
});
});
});
},
events: function() {
// XXX Hacky, we need some kind of `super`
var mixinEvents = this.getMixin(Mixins.InfiniteScrolling).events();
return mixinEvents.concat([{
'click .js-toogle-sidebar': this.toogle
}]);
}
}).register('sidebar');
EscapeActions.register('sidebarView',
function() { return Sidebar && Sidebar.getView() !== defaultView; },
function() { Sidebar.setView(defaultView); }
);