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/page-heading.js

160 lines
4.2 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 Component from '@ember/component';
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
2017-12-06 19:56:51 +00:00
import { A } from "@ember/array"
import ModalMixin from '../../mixins/modal';
2016-07-07 18:54:16 -07:00
2017-12-06 19:56:51 +00:00
export default Component.extend(ModalMixin, {
2017-01-21 14:29:36 -08:00
documentService: service('document'),
2016-07-07 18:54:16 -07:00
deleteChildren: false,
2017-01-21 14:29:36 -08:00
blockTitle: "",
blockExcerpt: "",
2017-12-06 19:56:51 +00:00
documentList: A([]), //includes the current document
documentListOthers: A([]), //excludes the current document
hasMenuPermissions: computed('permissions', function() {
let permissions = this.get('permissions');
return permissions.get('documentDelete') || permissions.get('documentCopy') ||
permissions.get('documentMove') || permissions.get('documentTemplate');
}),
2017-12-06 19:56:51 +00:00
didReceiveAttrs() {
this._super(...arguments);
// Fetch document targets once
if (this.get('documentList').length > 0) {
return;
}
2017-12-08 17:24:39 +00:00
this.modalInputFocus('#publish-page-modal-' + this.get('page.id'), '#block-title-' + this.get('page.id'));
2017-12-06 19:56:51 +00:00
this.load();
2016-07-07 18:54:16 -07:00
},
2017-12-06 19:56:51 +00:00
load() {
2017-12-19 16:52:40 +00:00
let permissions = this.get('permissions');
if (permissions.get('documentMove') || permissions.get('documentCopy')) {
this.get('documentService').getPageMoveCopyTargets().then((d) => {
let me = this.get('document');
d.forEach((i) => {
i.set('selected', false);
});
if (this.get('isDestroyed') || this.get('isDestroying')) {
return;
}
this.set('documentList', A(d));
this.set('documentListOthers', A(d.filter((item) => item.get('id') !== me.get('id'))));
2017-12-06 19:56:51 +00:00
});
2017-12-19 16:52:40 +00:00
}
2017-12-06 19:56:51 +00:00
},
actions: {
onEdit() {
this.attrs.onEdit();
2016-07-07 18:54:16 -07:00
},
2017-12-06 19:56:51 +00:00
onDeletePage() {
this.attrs.onDeletePage(this.get('deleteChildren'));
2017-12-06 19:56:51 +00:00
this.load();
this.modalClose('#delete-page-modal-' + this.get('page.id'));
2016-07-07 18:54:16 -07:00
},
onSavePageAsBlock() {
let page = this.get('page');
2017-12-06 19:56:51 +00:00
let titleElem = '#block-title-' + page.get('id');
2017-01-21 14:29:36 -08:00
let blockTitle = this.get('blockTitle');
if (is.empty(blockTitle)) {
2017-12-06 19:56:51 +00:00
$(titleElem).addClass('is-invalid');
return;
}
2017-12-06 19:56:51 +00:00
let excerptElem = '#block-desc-' + page.get('id');
2017-01-21 14:29:36 -08:00
let blockExcerpt = this.get('blockExcerpt');
blockExcerpt = blockExcerpt.replace(/\n/g, "");
if (is.empty(blockExcerpt)) {
2017-12-06 19:56:51 +00:00
$(excerptElem).addClass('is-invalid');
2017-01-21 14:29:36 -08:00
return;
}
this.get('documentService').getPageMeta(this.get('document.id'), page.get('id')).then((pm) => {
let block = {
folderId: this.get('folder.id'),
contentType: page.get('contentType'),
pageType: page.get('pageType'),
title: blockTitle,
body: page.get('body'),
excerpt: blockExcerpt,
rawBody: pm.get('rawBody'),
config: pm.get('config'),
externalSource: pm.get('externalSource')
};
this.attrs.onSavePageAsBlock(block);
2017-01-21 14:29:36 -08:00
this.set('blockTitle', '');
this.set('blockExcerpt', '');
2017-12-06 19:56:51 +00:00
$(titleElem).removeClass('is-invalid');
$(excerptElem).removeClass('is-invalid');
2017-01-22 14:12:10 -08:00
2017-12-06 19:56:51 +00:00
this.load();
2017-01-22 14:12:10 -08:00
2017-12-06 19:56:51 +00:00
this.modalClose('#publish-page-modal-' + this.get('page.id'));
2017-01-22 14:12:10 -08:00
});
},
onCopyPage() {
// can't proceed if no data
2017-01-22 15:45:43 -08:00
if (this.get('documentList.length') === 0) {
return;
}
2017-12-06 19:56:51 +00:00
let targetDocumentId = this.get('documentList').findBy('selected', true).get('id');
// fall back to self
if (is.null(targetDocumentId)) {
targetDocumentId = this.get('document.id');
2017-01-22 14:12:10 -08:00
}
this.attrs.onCopyPage(targetDocumentId);
2017-12-06 19:56:51 +00:00
this.load();
this.modalClose('#copy-page-modal-' + this.get('page.id'));
},
onMovePage() {
// can't proceed if no data
if (this.get('documentListOthers.length') === 0) {
return;
}
2017-12-06 19:56:51 +00:00
let targetDocumentId = this.get('documentListOthers').findBy('selected', true).get('id');
2017-12-06 19:56:51 +00:00
// fall back to first document
if (is.null(targetDocumentId)) {
targetDocumentId = this.get('documentListOthers')[0].get('id');
}
this.attrs.onMovePage(targetDocumentId);
2017-12-06 19:56:51 +00:00
this.load();
this.modalClose('#move-page-modal-' + this.get('page.id'));
}
2016-07-07 18:54:16 -07:00
}
});