2017-02-27 17:07:49 +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 { empty } from '@ember/object/computed';
|
2018-01-21 14:08:03 +00:00
|
|
|
import { computed } from '@ember/object';
|
2017-11-16 13:28:05 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2018-06-15 14:25:05 +01:00
|
|
|
import Notifier from '../../mixins/notifier';
|
2017-11-16 13:28:05 +00:00
|
|
|
import Component from '@ember/component';
|
2017-02-27 17:07:49 +00:00
|
|
|
|
2018-06-15 14:25:05 +01:00
|
|
|
export default Component.extend(Notifier, {
|
|
|
|
documentSvc: service('document'),
|
2017-02-27 17:07:49 +00:00
|
|
|
docName: '',
|
|
|
|
docExcerpt: '',
|
2017-11-16 13:28:05 +00:00
|
|
|
hasNameError: empty('docName'),
|
2017-02-27 17:07:49 +00:00
|
|
|
|
2018-06-15 14:25:05 +01:00
|
|
|
noEdits: computed('permssions', 'document', function() {
|
2018-01-21 14:08:03 +00:00
|
|
|
let constants = this.get('constants');
|
|
|
|
let permissions = this.get('permissions');
|
|
|
|
|
2018-06-17 14:50:43 +01:00
|
|
|
if (!permissions.get('documentEdit')) {
|
|
|
|
return true;
|
2018-01-21 14:08:03 +00:00
|
|
|
}
|
|
|
|
|
2018-06-17 14:50:43 +01:00
|
|
|
if (!permissions.get('documentApprove') && this.get('document.protection') === constants.ProtectionType.Review) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.get('document.protection') === constants.ProtectionType.Lock) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2018-01-21 14:08:03 +00:00
|
|
|
}),
|
|
|
|
|
2017-03-22 10:24:30 +00:00
|
|
|
keyUp(e) {
|
|
|
|
if (e.keyCode === 27) { // escape key
|
|
|
|
this.send('onCancel');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-06-15 14:25:05 +01:00
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
2017-03-22 10:24:30 +00:00
|
|
|
|
2018-06-15 14:25:05 +01:00
|
|
|
this.set('docName', this.get('document.name'));
|
|
|
|
this.set('docExcerpt', this.get('document.excerpt'));
|
|
|
|
},
|
2017-02-27 17:07:49 +00:00
|
|
|
|
2018-06-15 14:25:05 +01:00
|
|
|
actions: {
|
2017-03-22 10:24:30 +00:00
|
|
|
onSave() {
|
2018-06-07 14:23:54 +01:00
|
|
|
if (this.get('hasNameError')) return;
|
2017-02-27 17:07:49 +00:00
|
|
|
|
2018-06-15 14:25:05 +01:00
|
|
|
let constants = this.get('constants');
|
|
|
|
|
2017-02-27 17:07:49 +00:00
|
|
|
this.set('document.name', this.get('docName'));
|
2018-06-07 14:23:54 +01:00
|
|
|
this.set('document.excerpt', this.get('docExcerpt').trim());
|
2018-06-15 14:25:05 +01:00
|
|
|
|
|
|
|
let lifecycle = this.get('lifecycle.selected');
|
|
|
|
this.set('document.lifecycle', lifecycle);
|
2017-12-04 14:47:44 +00:00
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
let cb = this.get('onSaveDocument');
|
|
|
|
cb(this.get('document'));
|
2017-02-27 17:07:49 +00:00
|
|
|
|
2018-06-15 14:25:05 +01:00
|
|
|
if (lifecycle === constants.Lifecycle.Draft) {
|
|
|
|
this.get('activitySvc').clearChangeHistory(this.get('document.id'));
|
|
|
|
}
|
2017-02-27 17:07:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|