2016-07-07 18:54:16 -07:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
|
|
|
import Ember from 'ember';
|
|
|
|
import netUtil from '../../utils/net';
|
2017-04-16 14:56:00 +01:00
|
|
|
import constants from '../../utils/constants';
|
2016-11-05 16:02:35 -07:00
|
|
|
import TooltipMixin from '../../mixins/tooltip';
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2016-08-26 13:13:26 +02:00
|
|
|
const {
|
|
|
|
inject: { service }
|
|
|
|
} = Ember;
|
|
|
|
|
2016-11-05 16:02:35 -07:00
|
|
|
export default Ember.Component.extend(TooltipMixin, {
|
2016-08-29 21:34:35 +02:00
|
|
|
folderService: service('folder'),
|
|
|
|
appMeta: service(),
|
2016-08-26 13:13:26 +02:00
|
|
|
session: service(),
|
2016-11-21 19:27:18 -08:00
|
|
|
store: service(),
|
|
|
|
folder: null,
|
2016-11-04 15:33:56 -07:00
|
|
|
view: {
|
2016-11-05 14:53:44 -07:00
|
|
|
folder: false,
|
2016-11-04 15:33:56 -07:00
|
|
|
search: false,
|
|
|
|
settings: false,
|
|
|
|
profile: false
|
|
|
|
},
|
2016-11-21 19:27:18 -08:00
|
|
|
pinned: service(),
|
|
|
|
pins: [],
|
2017-04-16 14:56:00 +01:00
|
|
|
enableLogout: true,
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2016-10-04 15:24:21 -07:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
2016-11-04 15:33:56 -07:00
|
|
|
|
2017-04-16 14:56:00 +01:00
|
|
|
if (this.get("session.authenticated") && this.get("session.user.id") !== '0') {
|
2017-04-16 15:47:39 +01:00
|
|
|
this.get("session.accounts").forEach((account) => {
|
2016-08-26 13:36:12 +02:00
|
|
|
// TODO: do not mutate account.active here
|
|
|
|
account.active = account.orgId === this.get("appMeta.orgId");
|
|
|
|
});
|
2016-07-07 18:54:16 -07:00
|
|
|
}
|
2016-11-21 19:27:18 -08:00
|
|
|
|
|
|
|
this.set('pins', this.get('pinned').get('pins'));
|
2017-04-16 14:56:00 +01:00
|
|
|
|
|
|
|
if (this.get('appMeta.authProvider') === constants.AuthProvider.Keycloak) {
|
|
|
|
let config = this.get('appMeta.authConfig');
|
|
|
|
config = JSON.parse(config);
|
|
|
|
this.set('enableLogout', !config.disableLogout);
|
|
|
|
}
|
2016-07-07 18:54:16 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
didReceiveAttrs() {
|
|
|
|
if (this.get('folder') === null) {
|
|
|
|
this.set("folder", this.get('folderService.currentFolder'));
|
|
|
|
}
|
2016-11-04 15:33:56 -07:00
|
|
|
|
|
|
|
let route = this.get('router.currentRouteName');
|
2016-11-05 14:53:44 -07:00
|
|
|
this.set('view.folder', (is.startWith(route, 'folder')) ? true : false);
|
|
|
|
this.set('view.settings', (is.startWith(route, 'customize')) ? true : false);
|
2016-11-04 15:33:56 -07:00
|
|
|
this.set('view.profile', (route === 'profile') ? true : false);
|
|
|
|
this.set('view.search', (route === 'search') ? true : false);
|
2016-07-07 18:54:16 -07:00
|
|
|
},
|
|
|
|
|
2016-11-21 19:27:18 -08:00
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
// Size the pinned items zone
|
|
|
|
if (this.get("session.authenticated")) {
|
|
|
|
this.eventBus.subscribe('resized', this, 'sizePinnedZone');
|
|
|
|
this.eventBus.subscribe('pinChange', this, 'setupPins');
|
|
|
|
this.sizePinnedZone();
|
|
|
|
this.setupPins();
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
|
|
|
|
var sortable = Sortable.create(document.getElementById('pinned-zone'), {
|
|
|
|
animation: 150,
|
|
|
|
onEnd: function () {
|
|
|
|
self.get('pinned').updateSequence(this.toArray()).then((pins) => {
|
|
|
|
self.set('pins', pins);
|
|
|
|
});
|
2017-03-19 11:37:18 +00:00
|
|
|
}
|
2016-11-21 19:27:18 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.set('sortable', sortable);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-11-05 16:02:35 -07:00
|
|
|
didRender() {
|
|
|
|
if (this.get('session.isAdmin')) {
|
|
|
|
this.addTooltip(document.getElementById("workspace-settings"));
|
|
|
|
}
|
2017-04-16 14:56:00 +01:00
|
|
|
if (this.get("session.authenticated") && this.get('enableLogout')) {
|
2016-11-05 16:02:35 -07:00
|
|
|
this.addTooltip(document.getElementById("workspace-logout"));
|
|
|
|
} else {
|
|
|
|
this.addTooltip(document.getElementById("workspace-login"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-11-21 19:27:18 -08:00
|
|
|
setupPins() {
|
2016-11-22 10:05:32 -08:00
|
|
|
if (this.get('isDestroyed') || this.get('isDestroying')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-21 19:27:18 -08:00
|
|
|
this.get('pinned').getUserPins().then((pins) => {
|
2016-11-22 10:05:32 -08:00
|
|
|
if (this.get('isDestroyed') || this.get('isDestroying')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-21 19:27:18 -08:00
|
|
|
this.set('pins', pins);
|
|
|
|
|
|
|
|
pins.forEach((pin) => {
|
|
|
|
this.addTooltip(document.getElementById(`pin-${pin.id}`));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// set height for pinned zone so ti scrolls on spill
|
|
|
|
sizePinnedZone() {
|
|
|
|
let topofBottomZone = parseInt($('#bottom-zone').css("top").replace("px", ""));
|
|
|
|
let heightOfTopZone = parseInt($('#top-zone').css("height").replace("px", ""));
|
|
|
|
let size = topofBottomZone - heightOfTopZone - 40;
|
|
|
|
$('#pinned-zone').css('height', size + "px");
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
let sortable = this.get('sortable');
|
|
|
|
|
|
|
|
if (!_.isUndefined(sortable)) {
|
|
|
|
sortable.destroy();
|
|
|
|
}
|
|
|
|
|
2017-01-24 08:48:27 -08:00
|
|
|
this.eventBus.unsubscribe('resized');
|
|
|
|
this.eventBus.unsubscribe('pinChange');
|
|
|
|
|
2016-11-21 19:27:18 -08:00
|
|
|
this.destroyTooltips();
|
|
|
|
},
|
|
|
|
|
2016-07-07 18:54:16 -07:00
|
|
|
actions: {
|
|
|
|
switchAccount(domain) {
|
|
|
|
window.location.href = netUtil.getAppUrl(domain);
|
2016-11-21 19:27:18 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
jumpToPin(pin) {
|
|
|
|
let folderId = pin.get('folderId');
|
|
|
|
let documentId = pin.get('documentId');
|
|
|
|
|
|
|
|
if (_.isEmpty(documentId)) {
|
|
|
|
// jump to space
|
|
|
|
let folder = this.get('store').peekRecord('folder', folderId);
|
|
|
|
this.get('router').transitionTo('folder', folderId, folder.get('slug'));
|
|
|
|
} else {
|
|
|
|
// jump to doc
|
|
|
|
let folder = this.get('store').peekRecord('folder', folderId);
|
|
|
|
this.get('router').transitionTo('document', folderId, folder.get('slug'), documentId, 'document');
|
|
|
|
}
|
2016-07-07 18:54:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|