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
|
|
|
|
|
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
const {
|
|
|
|
computed,
|
|
|
|
} = Ember;
|
|
|
|
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
drop: null,
|
|
|
|
busy: false,
|
2017-03-22 10:24:30 +00:00
|
|
|
mousetrap: null,
|
2017-02-28 03:25:06 +00:00
|
|
|
hasNameError: computed.empty('page.title'),
|
2017-03-22 10:24:30 +00:00
|
|
|
containerId: Ember.computed('page', function () {
|
|
|
|
let page = this.get('page');
|
|
|
|
return `base-editor-inline-container-${page.id}`;
|
|
|
|
}),
|
2017-02-28 03:25:06 +00:00
|
|
|
pageId: Ember.computed('page', function () {
|
|
|
|
let page = this.get('page');
|
|
|
|
return `page-editor-${page.id}`;
|
|
|
|
}),
|
2017-02-28 13:43:46 +00:00
|
|
|
cancelId: Ember.computed('page', function () {
|
|
|
|
let page = this.get('page');
|
|
|
|
return `cancel-edits-button-${page.id}`;
|
|
|
|
}),
|
|
|
|
dialogId: Ember.computed('page', function () {
|
|
|
|
let page = this.get('page');
|
|
|
|
return `discard-edits-dialog-${page.id}`;
|
|
|
|
}),
|
2017-03-05 19:11:01 +00:00
|
|
|
contentLinkerButtonId: Ember.computed('page', function () {
|
|
|
|
let page = this.get('page');
|
|
|
|
return `content-linker-button-${page.id}`;
|
|
|
|
}),
|
|
|
|
previewButtonId: Ember.computed('page', function () {
|
|
|
|
let page = this.get('page');
|
|
|
|
return `content-preview-button-${page.id}`;
|
|
|
|
}),
|
2017-02-28 03:25:06 +00:00
|
|
|
|
|
|
|
didRender() {
|
2017-03-22 10:24:30 +00:00
|
|
|
let msContainer = document.getElementById(this.get('containerId'));
|
2017-04-13 10:57:57 +01:00
|
|
|
let mousetrap = this.get('mousetrap');
|
|
|
|
|
|
|
|
if (is.null(mousetrap)) {
|
|
|
|
mousetrap = new Mousetrap(msContainer);
|
|
|
|
}
|
2017-03-22 10:24:30 +00:00
|
|
|
|
|
|
|
mousetrap.bind('esc', () => {
|
|
|
|
this.send('onCancel');
|
2017-02-28 03:25:06 +00:00
|
|
|
return false;
|
|
|
|
});
|
2017-03-22 10:24:30 +00:00
|
|
|
mousetrap.bind(['ctrl+s', 'command+s'], () => {
|
|
|
|
this.send('onAction');
|
2017-02-28 03:25:06 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-03-22 10:24:30 +00:00
|
|
|
this.set('mousetrap', mousetrap);
|
|
|
|
|
2017-02-28 03:25:06 +00:00
|
|
|
$('#' + this.get('pageId')).focus(function() {
|
|
|
|
$(this).select();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
let drop = this.get('drop');
|
|
|
|
if (is.not.null(drop)) {
|
|
|
|
drop.destroy();
|
|
|
|
}
|
2017-02-28 17:50:03 +00:00
|
|
|
|
2017-03-22 10:24:30 +00:00
|
|
|
let mousetrap = this.get('mousetrap');
|
|
|
|
if (is.not.null(mousetrap)) {
|
|
|
|
mousetrap.unbind('esc');
|
|
|
|
mousetrap.unbind(['ctrl+s', 'command+s']);
|
|
|
|
}
|
2017-02-28 03:25:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
onCancel() {
|
|
|
|
if (this.attrs.isDirty() !== null && this.attrs.isDirty()) {
|
2017-02-28 13:43:46 +00:00
|
|
|
$('#' + this.get('dialogId')).css("display", "block");
|
2017-02-28 03:25:06 +00:00
|
|
|
|
|
|
|
let drop = new Drop({
|
2017-02-28 13:43:46 +00:00
|
|
|
target: $('#' + this.get('cancelId'))[0],
|
|
|
|
content: $('#' + this.get('dialogId'))[0],
|
2017-02-28 03:25:06 +00:00
|
|
|
classes: 'drop-theme-basic',
|
|
|
|
position: "bottom right",
|
|
|
|
openOn: "always",
|
2017-02-28 13:43:46 +00:00
|
|
|
constrainToWindow: true,
|
2017-02-28 17:50:03 +00:00
|
|
|
constrainToScrollParent: false,
|
2017-02-28 03:25:06 +00:00
|
|
|
tetherOptions: {
|
|
|
|
offset: "5px 0",
|
|
|
|
targetOffset: "10px 0"
|
|
|
|
},
|
|
|
|
remove: false
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set('drop', drop);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.attrs.onCancel();
|
|
|
|
},
|
|
|
|
|
|
|
|
onAction() {
|
2017-02-28 13:43:46 +00:00
|
|
|
if (this.get('busy') || is.empty(this.get('page.title'))) {
|
2017-02-28 03:25:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-28 17:50:03 +00:00
|
|
|
if (this.get('isDestroyed') || this.get('isDestroying')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-28 03:25:06 +00:00
|
|
|
this.attrs.onAction(this.get('page.title'));
|
|
|
|
},
|
|
|
|
|
|
|
|
keepEditing() {
|
|
|
|
let drop = this.get('drop');
|
|
|
|
drop.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
discardEdits() {
|
|
|
|
this.attrs.onCancel();
|
2017-03-05 19:11:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onInsertLink(selection) {
|
|
|
|
return this.get('onInsertLink')(selection);
|
|
|
|
},
|
|
|
|
|
|
|
|
onPreview() {
|
|
|
|
return this.get('onPreview')();
|
|
|
|
},
|
2017-02-28 03:25:06 +00:00
|
|
|
}
|
|
|
|
});
|