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

145 lines
3.4 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 TooltipMixin from '../../mixins/tooltip';
import NotifierMixin from '../../mixins/notifier';
2016-07-07 18:54:16 -07:00
export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
documentService: Ember.inject.service('document'),
sectionService: Ember.inject.service('section'),
sessionService: Ember.inject.service('session'),
2016-07-08 16:08:23 -07:00
appMeta: Ember.inject.service(),
userService: Ember.inject.service('user'),
localStorage: Ember.inject.service(),
pinned: Ember.inject.service(),
menuOpen: false,
2016-11-21 19:27:18 -08:00
pinState : {
isPinned: false,
pinId: '',
newName: '',
},
saveTemplate: {
name: "",
description: ""
},
init() {
this._super(...arguments);
},
2016-07-07 18:54:16 -07:00
didReceiveAttrs() {
this._super(...arguments);
2016-07-07 18:54:16 -07:00
this.set('saveTemplate.name', this.get('document.name'));
this.set('saveTemplate.description', this.get('document.excerpt'));
this.set('pinState.pinId', this.get('pinned').isDocumentPinned(this.get('document.id')));
2016-11-21 19:27:18 -08:00
this.set('pinState.isPinned', this.get('pinState.pinId') !== '');
this.set('pinState.newName', this.get('document.name'));
2016-07-07 18:54:16 -07:00
},
didRender() {
this.destroyTooltips();
2016-07-07 18:54:16 -07:00
if (this.get('permissions.documentEdit')) {
this.addTooltip(document.getElementById("document-activity-button"));
}
},
actions: {
onMenuOpen() {
this.set('menuOpen', !this.get('menuOpen'));
2016-11-20 13:41:43 -08:00
},
onDeleteDocument() {
this.attrs.onDocumentDelete();
},
2016-11-20 13:41:43 -08:00
onPrintDocument() {
2017-04-10 17:21:13 +01:00
$("#sidebar-zone-more-button").click();
window.print();
2016-11-20 13:41:43 -08:00
},
2016-11-21 19:27:18 -08:00
2017-03-07 16:10:13 +00:00
onPageSequenceChange(changes) {
this.get('onPageSequenceChange')(changes);
},
2017-03-07 16:10:13 +00:00
onPageLevelChange(changes) {
this.get('onPageLevelChange')(changes);
},
2017-03-07 16:10:13 +00:00
onGotoPage(id) {
this.get('onGotoPage')(id);
},
2017-03-07 16:10:13 +00:00
onUnpin() {
2016-11-21 19:27:18 -08:00
this.get('pinned').unpinItem(this.get('pinState.pinId')).then(() => {
this.set('pinState.isPinned', false);
this.set('pinState.pinId', '');
this.eventBus.publish('pinChange');
});
},
onPin() {
2016-11-21 19:27:18 -08:00
let pin = {
pin: this.get('pinState.newName'),
documentId: this.get('document.id'),
folderId: this.get('folder.id')
};
if (is.empty(pin.pin)) {
$("#pin-document-name").addClass("error").focus();
return false;
}
this.get('pinned').pinItem(pin).then((pin) => {
this.set('pinState.isPinned', true);
this.set('pinState.pinId', pin.get('id'));
this.eventBus.publish('pinChange');
});
return true;
},
onSaveTemplate() {
var name = this.get('saveTemplate.name');
var excerpt = this.get('saveTemplate.description');
if (is.empty(name)) {
$("#new-template-name").addClass("error").focus();
return false;
}
if (is.empty(excerpt)) {
$("#new-template-desc").addClass("error").focus();
return false;
}
this.showNotification('Template saved');
this.attrs.onSaveTemplate(name, excerpt);
return true;
},
onLayoutChange(layout) {
let doc = this.get('document');
doc.set('layout', layout);
if (this.get('permissions.documentEdit')) {
this.get('documentService').save(doc);
}
2016-11-21 19:27:18 -08:00
return true;
}
}
2016-11-20 13:41:43 -08:00
});