2017-02-28 03:25:06 +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
|
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Component from '@ember/component';
|
2017-02-28 03:25:06 +00:00
|
|
|
import TooltipMixin from '../../mixins/tooltip';
|
|
|
|
|
2018-01-10 16:07:17 +00:00
|
|
|
export default Component.extend(TooltipMixin, {
|
2017-11-16 13:28:05 +00:00
|
|
|
documentService: service('document'),
|
|
|
|
sectionService: service('section'),
|
2017-02-28 03:25:06 +00:00
|
|
|
editMode: false,
|
2018-01-22 10:31:03 +00:00
|
|
|
editPage: null,
|
|
|
|
editMeta: null,
|
2017-02-28 03:25:06 +00:00
|
|
|
|
2017-03-07 16:10:13 +00:00
|
|
|
didReceiveAttrs() {
|
2017-03-06 18:30:55 +00:00
|
|
|
this._super(...arguments);
|
2018-02-04 15:51:14 +00:00
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
if (this.get('isDestroyed') || this.get('isDestroying')) return;
|
2017-03-06 18:30:55 +00:00
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
if (this.get('session.authenticated')) {
|
|
|
|
this.workflow();
|
2017-03-22 09:40:34 +00:00
|
|
|
}
|
2018-01-24 13:23:11 +00:00
|
|
|
|
|
|
|
if (this.get('toEdit') === this.get('page.id') && this.get('permissions.documentEdit')) this.send('onEdit');
|
2018-01-22 10:31:03 +00:00
|
|
|
},
|
2017-03-22 09:40:34 +00:00
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
workflow() {
|
|
|
|
this.set('editPage', this.get('page'));
|
|
|
|
this.set('editMeta', this.get('meta'));
|
2017-03-06 18:30:55 +00:00
|
|
|
},
|
|
|
|
|
2017-02-28 03:25:06 +00:00
|
|
|
actions: {
|
2017-03-06 19:11:54 +00:00
|
|
|
onSavePage(page, meta) {
|
2018-01-22 10:31:03 +00:00
|
|
|
let constants = this.get('constants');
|
|
|
|
|
|
|
|
if (this.get('document.protection') === constants.ProtectionType.Review) {
|
|
|
|
if (this.get('page.status') === constants.ChangeState.Published) {
|
|
|
|
page.set('relativeId', this.get('page.id'));
|
|
|
|
}
|
|
|
|
if (this.get('page.status') === constants.ChangeState.PendingNew) {
|
|
|
|
page.set('relativeId', '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-06 19:11:54 +00:00
|
|
|
this.set('editMode', false);
|
2018-01-22 10:31:03 +00:00
|
|
|
let cb = this.get('onSavePage');
|
|
|
|
cb(page, meta);
|
2017-03-06 19:11:54 +00:00
|
|
|
},
|
|
|
|
|
2017-03-02 20:30:26 +00:00
|
|
|
onSavePageAsBlock(block) {
|
2018-01-22 10:31:03 +00:00
|
|
|
let cb = this.get('onSavePageAsBlock');
|
|
|
|
cb(block);
|
2017-02-28 03:25:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onCopyPage(documentId) {
|
2018-01-22 10:31:03 +00:00
|
|
|
let cb = this.get('onCopyPage');
|
|
|
|
cb(this.get('page.id'), documentId);
|
2017-02-28 03:25:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onMovePage(documentId) {
|
2018-01-22 10:31:03 +00:00
|
|
|
let cb = this.get('onMovePage');
|
|
|
|
cb(this.get('page.id'), documentId);
|
2017-02-28 03:25:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onDeletePage(deleteChildren) {
|
|
|
|
let page = this.get('page');
|
|
|
|
|
|
|
|
if (is.undefined(page)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let params = {
|
|
|
|
id: page.get('id'),
|
|
|
|
title: page.get('title'),
|
|
|
|
children: deleteChildren
|
|
|
|
};
|
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
let cb = this.get('onDeletePage');
|
|
|
|
cb(params);
|
2017-02-28 03:25:06 +00:00
|
|
|
},
|
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
// Calculate if user is editing page or a pending change as per approval process
|
2017-02-28 03:25:06 +00:00
|
|
|
onEdit() {
|
2018-01-22 10:31:03 +00:00
|
|
|
if (this.get('editMode')) return;
|
2017-03-09 17:18:50 +00:00
|
|
|
this.get('toEdit', '');
|
2017-03-06 18:30:55 +00:00
|
|
|
this.set('editMode', true);
|
2017-02-28 03:25:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onCancelEdit() {
|
|
|
|
this.set('editMode', false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|