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/section/base-editor-inline.js

107 lines
2.4 KiB
JavaScript
Raw Normal View History

// 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 { empty } from '@ember/object/computed';
import { computed } from '@ember/object';
2017-12-07 19:43:46 +00:00
import TooltipMixin from '../../mixins/tooltip';
import ModalMixin from '../../mixins/modal';
import Component from '@ember/component';
2017-12-07 19:43:46 +00:00
export default Component.extend(TooltipMixin, ModalMixin, {
busy: false,
mousetrap: null,
2017-12-07 19:43:46 +00:00
showLinkModal: false,
hasNameError: empty('page.title'),
pageId: computed('page', function () {
let page = this.get('page');
return `page-editor-${page.id}`;
}),
didRender() {
2017-12-07 19:43:46 +00:00
let msContainer = document.getElementById('section-editor-' + this.get('containerId'));
2017-04-13 10:57:57 +01:00
let mousetrap = this.get('mousetrap');
if (is.null(mousetrap)) {
mousetrap = new Mousetrap(msContainer);
}
mousetrap.bind('esc', () => {
this.send('onCancel');
return false;
});
mousetrap.bind(['ctrl+s', 'command+s'], () => {
this.send('onAction');
return false;
});
this.set('mousetrap', mousetrap);
$('#' + this.get('pageId')).focus(function() {
$(this).select();
});
2017-12-07 19:43:46 +00:00
this.renderTooltips();
},
willDestroyElement() {
2017-12-07 19:43:46 +00:00
this._super(...arguments);
this.removeTooltips();
let mousetrap = this.get('mousetrap');
if (is.not.null(mousetrap)) {
mousetrap.unbind('esc');
mousetrap.unbind(['ctrl+s', 'command+s']);
}
},
actions: {
onAction() {
2017-02-28 13:43:46 +00:00
if (this.get('busy') || is.empty(this.get('page.title'))) {
return;
}
if (this.get('isDestroyed') || this.get('isDestroying')) {
return;
}
this.attrs.onAction(this.get('page.title'));
},
2017-12-07 19:43:46 +00:00
onCancel() {
if (this.attrs.isDirty() !== null && this.attrs.isDirty()) {
this.modalOpen('#discard-modal-' + this.get('page.id'), {show: true});
return;
}
this.attrs.onCancel();
},
2017-12-07 19:43:46 +00:00
onDiscard() {
this.modalClose('#discard-modal-' + this.get('page.id'));
this.attrs.onCancel();
},
onPreview() {
return this.get('onPreview')();
2017-12-07 19:43:46 +00:00
},
onShowLinkModal() {
this.set('showLinkModal', true);
},
onInsertLink(selection) {
this.set('showLinkModal', false);
return this.get('onInsertLink')(selection);
}
}
});