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

227 lines
5.9 KiB
JavaScript
Raw Normal View History

2017-12-05 11:47:10 +00: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 $ from 'jquery';
2017-12-05 11:47:10 +00:00
import { inject as service } from '@ember/service';
2018-12-20 13:05:22 +00:00
import { computed } from '@ember/object';
2017-12-05 11:47:10 +00:00
import AuthMixin from '../../mixins/auth';
2017-12-05 19:03:38 +00:00
import ModalMixin from '../../mixins/modal';
2018-07-29 10:59:24 -04:00
import Notifier from '../../mixins/notifier';
2018-03-15 17:11:53 +00:00
import Component from '@ember/component';
2017-12-05 11:47:10 +00:00
export default Component.extend(ModalMixin, AuthMixin, Notifier, {
store: service(),
spaceSvc: service('folder'),
2017-12-05 11:47:10 +00:00
session: service(),
appMeta: service(),
pinned: service(),
2018-07-29 10:59:24 -04:00
browserSvc: service('browser'),
documentSvc: service('document'),
2022-03-09 13:36:48 -05:00
i18n: service(),
2018-12-20 13:05:22 +00:00
showRevisions: computed('permissions', 'document.protection', function() {
if (!this.get('session.authenticated')) return false;
if (!this.get('session.viewUsers')) return false;
if (this.get('document.protection') === this.get('constants').ProtectionType.None) return true;
if (this.get('document.protection') === this.get('constants').ProtectionType.Review && this.get('permissions.documentApprove')) return true;
return false;
}),
showActivity: computed('permissions', function() {
if (this.get('appMeta.edition') !== this.get('constants').Product.EnterpriseEdition) return false;
if (!this.get('session.authenticated')) return false;
if (!this.get('session.viewUsers')) return false;
if (this.get('permissions.spaceView')) return true;
return false;
}),
2019-01-13 09:39:42 +00:00
hasToolbar: computed('permissions', 'showRevisions', 'showActivity', function() {
if (this.get('showRevisions') || this.get('showActivity')) return true;
if (this.get('permissions.documentAdd') || this.get('permissions.documentDelete')) return true;
if (this.get('appMeta.edition') === this.get('constants').Product.EnterpriseEdition &&
this.get('permissions.documentEdit')) return true;
}),
duplicateName: '',
2017-12-05 11:47:10 +00:00
2018-01-24 13:23:11 +00:00
init() {
this._super(...arguments);
this.pinState = {
isPinned: false,
pinId: '',
newName: ''
};
this.saveTemplate = {
name: '',
description: ''
};
},
2018-01-24 13:23:11 +00:00
2017-12-05 11:47:10 +00:00
didReceiveAttrs() {
this._super(...arguments);
let doc = this.get('document');
this.get('pinned').isDocumentPinned(doc.get('id')).then((pinId) => {
this.set('pinState.pinId', pinId);
this.set('pinState.isPinned', pinId !== '');
this.set('pinState.newName', doc.get('name'));
});
2017-12-05 19:03:38 +00:00
this.set('saveTemplate.name', this.get('document.name'));
this.set('saveTemplate.description', this.get('document.excerpt'));
2017-12-05 11:47:10 +00:00
},
willDestroyElement() {
this._super(...arguments);
},
actions: {
onShowTemplateModal() {
this.modalOpen("#document-template-modal", {show:true}, "#new-template-name");
},
onShowDuplicateModal() {
this.modalOpen("#document-duplicate-modal", {show:true}, "#duplicate-name");
},
onShowDeleteModal() {
this.modalOpen("#document-delete-modal", {show:true});
},
2017-12-05 19:03:38 +00:00
onDocumentDelete() {
2017-12-15 13:41:20 +00:00
this.modalClose('#document-delete-modal');
let cb = this.get('onDocumentDelete');
cb();
2017-12-05 19:03:38 +00:00
},
2019-05-31 19:41:34 +01:00
onShowPrintModal() {
let pages = this.get('pages');
// By default we select everything for print.
pages.forEach((item) => {
item.set('printSelected', true);
});
this.set('pages', pages);
this.modalOpen("#document-print-modal", {show:true});
},
onPrintSelection() {
this.modalClose('#document-print-modal');
let pages = this.get('pages');
pages.forEach((item) => {
let pageId = item.get('page.id');
let selected = item.get('printSelected');
$(`#page-${pageId}`).addClass('non-printable');
$(`#page-spacer-${pageId}`).addClass('non-printable');
if (selected) {
$(`#page-${pageId}`).removeClass('non-printable');
$(`#page-spacer-${pageId}`).removeClass('non-printable');
}
});
2017-12-05 11:47:10 +00:00
window.print();
},
onUnpin() {
this.get('pinned').unpinItem(this.get('pinState.pinId')).then(() => {
this.set('pinState.isPinned', false);
this.set('pinState.pinId', '');
this.eventBus.publish('pinChange');
});
},
onPin() {
let pin = {
pin: this.get('pinState.newName'),
documentId: this.get('document.id'),
spaceId: this.get('space.id')
2017-12-05 11:47:10 +00:00
};
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;
},
2017-12-05 19:03:38 +00:00
onSaveTemplate() {
let name = this.get('saveTemplate.name');
let excerpt = this.get('saveTemplate.description');
if (_.isEmpty(name)) {
2017-12-05 19:03:38 +00:00
$("#new-template-name").addClass("is-invalid").focus();
return;
}
if (_.isEmpty(excerpt)) {
2017-12-05 19:03:38 +00:00
$("#new-template-desc").addClass("is-invalid").focus();
return;
}
$("#new-template-name").removeClass("is-invalid");
$("#new-template-desc").removeClass("is-invalid");
this.set('saveTemplate.name', '');
this.set('saveTemplate.description', '');
let cb = this.get('onSaveTemplate');
cb(name, excerpt);
2017-12-05 19:03:38 +00:00
this.modalClose('#document-template-modal');
return true;
},
2018-07-29 10:59:24 -04:00
onDuplicate() {
let name = this.get('duplicateName');
if (_.isEmpty(name)) {
$("#duplicate-name").addClass("is-invalid").focus();
return;
}
$("#duplicate-name").removeClass("is-invalid");
this.set('duplicateName', '');
this.get('onDuplicate')(name);
this.modalClose('#document-duplicate-modal');
return true;
},
2018-07-29 10:59:24 -04:00
onExport() {
let spec = {
2019-01-13 09:39:42 +00:00
spaceId: this.get('document.spaceId'),
2018-07-29 10:59:24 -04:00
data: [],
filterType: 'document',
};
spec.data.push(this.get('document.id'));
this.get('documentSvc').export(spec).then((htmlExport) => {
this.get('browserSvc').downloadFile(htmlExport, this.get('document.slug') + '.html');
2022-03-09 13:36:48 -05:00
this.notifySuccess(this.i18n.localize('exported'));
2018-07-29 10:59:24 -04:00
});
}
2017-12-05 11:47:10 +00:00
}
});