Migrate NoteEditos to TS

This commit is contained in:
Paulo Gustavo Veiga 2022-06-23 21:10:20 -07:00
parent bd4656c227
commit 95da8db7a1
2 changed files with 13 additions and 9 deletions

View File

@ -114,7 +114,7 @@ class BootstrapDialog extends Options {
return header; return header;
} }
onAcceptClick() { onAcceptClick(event) {
throw new Error('Unsupported operation'); throw new Error('Unsupported operation');
} }
@ -122,7 +122,7 @@ class BootstrapDialog extends Options {
// Overwrite default behaviour ... // Overwrite default behaviour ...
} }
onRemoveClick() { onRemoveClick(event) {
throw new Error('Unsupported operation'); throw new Error('Unsupported operation');
} }

View File

@ -20,8 +20,13 @@ import $ from 'jquery';
import BootstrapDialog from '../../../../editor/src/classes/bootstrap/BootstrapDialog'; import BootstrapDialog from '../../../../editor/src/classes/bootstrap/BootstrapDialog';
import { $msg } from '../Messages'; import { $msg } from '../Messages';
interface NoteEditorModel {
getValue(): string;
setValue(value: string): void;
}
class NoteEditor extends BootstrapDialog { class NoteEditor extends BootstrapDialog {
constructor(model) { constructor(model: NoteEditorModel) {
$assert(model, 'model can not be null'); $assert(model, 'model can not be null');
super($msg('NOTE'), { super($msg('NOTE'), {
cancelButton: true, cancelButton: true,
@ -30,13 +35,12 @@ class NoteEditor extends BootstrapDialog {
removeButton: typeof model.getValue() !== 'undefined', removeButton: typeof model.getValue() !== 'undefined',
onEventData: { model }, onEventData: { model },
}); });
this._model = model;
this.css({ margin: '150px auto' }); this.css({ margin: '150px auto' });
const panel = this._buildPanel(model); const panel = this._buildPanel(model);
this.setContent(panel); this.setContent(panel);
} }
_buildPanel(model) { _buildPanel(model: NoteEditorModel) {
const result = $('<div></div>').css('padding-top', '5px'); const result = $('<div></div>').css('padding-top', '5px');
const form = $('<form></form>').attr({ const form = $('<form></form>').attr({
@ -68,20 +72,20 @@ class NoteEditor extends BootstrapDialog {
return result; return result;
} }
onAcceptClick(event) { onAcceptClick(event): void {
event.data.dialog._submitForm(event.data.model); event.data.dialog._submitForm(event.data.model);
} }
_submitForm(model) { _submitForm(model: NoteEditorModel) {
const textarea = this._native.find('textarea'); const textarea = this._native.find('textarea');
if (textarea.val()) { if (textarea.val()) {
model.setValue(textarea.val()); model.setValue(textarea.val() as string);
} }
this.close(); this.close();
} }
onDialogShown() { onDialogShown() {
$(this).find('textarea').focus(); $(this).find('textarea').trigger('focus');
} }
onRemoveClick(event) { onRemoveClick(event) {