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

200 lines
5.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';
2016-07-07 18:54:16 -07:00
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
import TooltipMixin from '../../mixins/tooltip';
2016-07-07 18:54:16 -07:00
export default Component.extend(TooltipMixin, {
2017-01-21 14:29:36 -08:00
documentService: service('document'),
2016-07-07 18:54:16 -07:00
deleteChildren: false,
menuOpen: false,
2017-01-21 14:29:36 -08:00
blockTitle: "",
blockExcerpt: "",
2017-01-22 14:12:10 -08:00
documentList: [], //includes the current document
documentListOthers: [], //excludes the current document
selectedDocument: null,
2016-07-07 18:54:16 -07:00
checkId: computed('page', function () {
let id = this.get('page.id');
return `delete-check-button-${id}`;
}),
menuTarget: computed('page', function () {
let id = this.get('page.id');
return `page-menu-${id}`;
}),
deleteButtonId: computed('page', function () {
2016-07-07 18:54:16 -07:00
let id = this.get('page.id');
return `delete-page-button-${id}`;
}),
publishButtonId: computed('page', function () {
let id = this.get('page.id');
return `publish-button-${id}`;
}),
publishDialogId: computed('page', function () {
let id = this.get('page.id');
return `publish-dialog-${id}`;
}),
2017-01-21 14:29:36 -08:00
blockTitleId: computed('page', function () {
let id = this.get('page.id');
return `block-title-${id}`;
}),
blockExcerptId: computed('page', function () {
let id = this.get('page.id');
2017-01-21 14:29:36 -08:00
return `block-excerpt-${id}`;
}),
2017-01-22 14:12:10 -08:00
copyButtonId: computed('page', function () {
let id = this.get('page.id');
return `copy-page-button-${id}`;
}),
copyDialogId: computed('page', function () {
let id = this.get('page.id');
return `copy-dialog-${id}`;
}),
moveButtonId: computed('page', function () {
let id = this.get('page.id');
return `move-page-button-${id}`;
}),
moveDialogId: computed('page', function () {
let id = this.get('page.id');
return `move-dialog-${id}`;
}),
2016-07-07 18:54:16 -07:00
hasMenuPermissions: computed('permissions', function() {
let permissions = this.get('permissions');
return permissions.get('documentDelete') || permissions.get('documentCopy') ||
permissions.get('documentMove') || permissions.get('documentTemplate');
}),
2016-07-07 18:54:16 -07:00
didRender() {
2017-01-21 14:29:36 -08:00
$("#" + this.get('blockTitleId')).removeClass('error');
$("#" + this.get('blockExcerptId')).removeClass('error');
2016-07-07 18:54:16 -07:00
},
actions: {
onMenuOpen() {
if ($('#' + this.get('publishDialogId')).is( ":visible" )) {
return;
}
if ($('#' + this.get('copyDialogId')).is( ":visible" )) {
return;
}
if ($('#' + this.get('moveDialogId')).is( ":visible" )) {
return;
}
this.set('menuOpen', !this.get('menuOpen'));
},
onEdit() {
this.attrs.onEdit();
2016-07-07 18:54:16 -07:00
},
deletePage() {
this.attrs.onDeletePage(this.get('deleteChildren'));
2016-07-07 18:54:16 -07:00
},
onSavePageAsBlock() {
let page = this.get('page');
2017-01-21 14:29:36 -08:00
let titleElem = '#' + this.get('blockTitleId');
let blockTitle = this.get('blockTitle');
if (is.empty(blockTitle)) {
$(titleElem).addClass('error');
return;
}
2017-01-21 14:29:36 -08:00
let excerptElem = '#' + this.get('blockExcerptId');
let blockExcerpt = this.get('blockExcerpt');
blockExcerpt = blockExcerpt.replace(/\n/g, "");
if (is.empty(blockExcerpt)) {
$(excerptElem).addClass('error');
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('menuOpen', false);
this.set('blockTitle', '');
this.set('blockExcerpt', '');
$(titleElem).removeClass('error');
$(excerptElem).removeClass('error');
return true;
});
},
2017-01-22 14:12:10 -08:00
// Copy/move actions
2017-01-22 14:12:10 -08:00
onCopyDialogOpen() {
// Fetch document targets once.
2017-01-22 14:12:10 -08:00
if (this.get('documentList').length > 0) {
return;
}
this.get('documentService').getPageMoveCopyTargets().then((d) => {
let me = this.get('document');
this.set('documentList', d);
this.set('documentListOthers', d.filter((item) => item.get('id') !== me.get('id')));
});
},
onTargetChange(d) {
this.set('selectedDocument', d);
},
onCopyPage() {
// can't proceed if no data
2017-01-22 15:45:43 -08:00
if (this.get('documentList.length') === 0) {
return;
}
2017-01-22 14:12:10 -08:00
let targetDocumentId = this.get('document.id');
if (is.not.null(this.get('selectedDocument'))) {
targetDocumentId = this.get('selectedDocument.id');
2017-01-22 14:12:10 -08:00
}
this.attrs.onCopyPage(targetDocumentId);
2017-01-22 14:12:10 -08:00
return true;
},
onMovePage() {
// can't proceed if no data
if (this.get('documentListOthers.length') === 0) {
return;
}
if (is.null(this.get('selectedDocument'))) {
this.set('selectedDocument', this.get('documentListOthers')[0]);
}
let targetDocumentId = this.get('selectedDocument.id');
this.attrs.onMovePage(targetDocumentId);
return true;
}
2016-07-07 18:54:16 -07:00
}
});