Gitter migration: Point people to app.gitter.im (rollout pt. 1)
[gitter.git] / public / js / views / org-directory / org-directory-header-view.js
blob99ce694bb4ed5e95a2be9fcb86564df33ce36612
1 'use strict';
3 var Marionette = require('backbone.marionette');
4 var toggleClass = require('../../utils/toggle-class');
5 var context = require('gitter-web-client-context');
7 var ProfileMenu = require('../../views/profile-menu/profile-menu-view.js');
8 var headerViewTemplate = require('./org-directory-header-view.hbs');
10 require('../behaviors/isomorphic');
11 require('../behaviors/tooltip');
13 var HeaderView = Marionette.LayoutView.extend({
14   el: 'header',
15   template: headerViewTemplate,
17   ui: {
18     favourite: '.js-group-favourite-button',
19     favouriteIcon: '.js-group-favourite-button-icon'
20   },
22   events: {
23     'click @ui.favourite': 'onFavouriteButtonClicked'
24   },
26   modelEvents: {
27     'change:favourite': 'onFavouriteChange'
28   },
30   behaviors: function() {
31     var behaviors = {
32       Isomorphic: {},
33       Tooltip: {
34         '.js-group-favourite-button': { placement: 'left' }
35       }
36     };
38     if (context.isLoggedIn()) {
39       behaviors.Isomorphic.profileMenuView = {
40         el: '#profile-menu',
41         init: 'initProfileMenuView'
42       };
43     }
45     return behaviors;
46   },
48   initProfileMenuView: function(optionsForRegion) {
49     this.profileMenuView = new ProfileMenu(
50       optionsForRegion({
51         // ...
52       })
53     );
54     return this.profileMenuView;
55   },
57   onFavouriteChange: function() {
58     var isFavourited = !!this.model.get('favourite');
59     toggleClass(this.ui.favouriteIcon[0], 'favourite', isFavourited);
60   },
62   onFavouriteButtonClicked: function() {
63     var isFavourited = !!this.model.get('favourite');
64     this.model.save(
65       {
66         favourite: !isFavourited
67       },
68       {
69         wait: true,
70         patch: true
71       }
72     );
73   }
74 });
76 module.exports = HeaderView;