1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-20 13:49:42 +02:00
documize/gui/app/components/folder/folder-toolbar.js

92 lines
2.3 KiB
JavaScript
Raw Normal View History

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 NotifierMixin from '../../mixins/notifier';
import TooltipMixin from '../../mixins/tooltip';
import AuthMixin from '../../mixins/auth';
2016-07-07 18:54:16 -07:00
const {
2016-10-24 19:20:29 -07:00
computed
2016-07-07 18:54:16 -07:00
} = Ember;
export default Ember.Component.extend(NotifierMixin, TooltipMixin, AuthMixin, {
2016-10-06 19:28:57 -07:00
folderService: Ember.inject.service('folder'),
2016-10-24 19:20:29 -07:00
session: Ember.inject.service(),
2016-10-06 19:28:57 -07:00
appMeta: Ember.inject.service(),
2016-10-06 14:13:02 -07:00
showToolbar: false,
2016-10-24 19:20:29 -07:00
folder: {},
busy: false,
isFolderOwner: computed.equal('folder.userId', 'session.user.id'),
moveFolderId: "",
2016-10-07 10:42:20 -07:00
drop: null,
2016-07-07 18:54:16 -07:00
2016-10-24 19:20:29 -07:00
didReceiveAttrs() {
this.set('isFolderOwner', this.get('folder.userId') === this.get("session.user.id"));
2016-07-07 18:54:16 -07:00
let show = this.get('session.authenticated') || this.get('isFolderOwner') || this.get('hasSelectedDocuments') || this.get('folderService').get('canEditCurrentFolder');
2016-10-06 14:13:02 -07:00
this.set('showToolbar', show);
2016-07-07 18:54:16 -07:00
2016-10-24 19:20:29 -07:00
let targets = _.reject(this.get('folders'), {
id: this.get('folder').get('id')
});
2016-07-07 18:54:16 -07:00
2016-10-24 19:20:29 -07:00
this.set('movedFolderOptions', targets);
},
2016-07-07 18:54:16 -07:00
didRender() {
2016-10-24 19:20:29 -07:00
if (this.get('hasSelectedDocuments')) {
this.addTooltip(document.getElementById("move-documents-button"));
this.addTooltip(document.getElementById("delete-documents-button"));
} else {
if (this.get('isFolderOwner')) {
this.addTooltip(document.getElementById("folder-share-button"));
this.addTooltip(document.getElementById("folder-settings-button"));
}
}
},
2016-10-24 19:20:29 -07:00
willDestroyElement() {
2016-10-07 10:42:20 -07:00
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
}
2016-10-24 19:20:29 -07:00
this.destroyTooltips();
},
2016-07-07 18:54:16 -07:00
2016-10-24 19:20:29 -07:00
actions: {
deleteDocuments() {
2016-07-07 18:54:16 -07:00
this.attrs.onDeleteDocument();
2016-10-24 19:20:29 -07:00
},
2016-07-07 18:54:16 -07:00
2016-10-24 19:20:29 -07:00
setMoveFolder(folderId) {
this.set('moveFolderId', folderId);
2016-07-07 18:54:16 -07:00
2016-10-24 19:20:29 -07:00
let folders = this.get('folders');
2016-07-07 18:54:16 -07:00
2016-10-24 19:20:29 -07:00
folders.forEach(folder => {
folder.set('selected', folder.id === folderId);
});
},
2016-07-07 18:54:16 -07:00
2016-10-24 19:20:29 -07:00
moveDocuments() {
if (this.get("moveFolderId") === "") {
return false;
}
2016-07-07 18:54:16 -07:00
2016-10-24 19:20:29 -07:00
this.attrs.onMoveDocument(this.get('moveFolderId'));
2016-07-07 18:54:16 -07:00
2016-11-21 19:27:18 -08:00
return true;
}
2016-10-24 19:20:29 -07:00
}
2016-07-07 18:54:16 -07:00
});