From 929e0f69c2f255912291e97b6e5fe48bae21cd48 Mon Sep 17 00:00:00 2001 From: Phil Marshall Date: Wed, 23 Jan 2019 15:15:24 -0600 Subject: [PATCH] add confirm type change dialog when note not empty --- src/public/javascripts/services/note_type.js | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/public/javascripts/services/note_type.js b/src/public/javascripts/services/note_type.js index 6e9b29ad5..80e70dc6c 100644 --- a/src/public/javascripts/services/note_type.js +++ b/src/public/javascripts/services/note_type.js @@ -110,35 +110,49 @@ function NoteTypeModel() { self.updateExecuteScriptButtonVisibility(); } - this.selectText = function() { + function confirmChangeIfContent() { + if (noteDetailService.getCurrentNote().content && !confirm( + "It is not recommended to change note type when note content is not empty. Do you want to continue?") + ) { + return false; + } + return true; + } + + this.selectText = async function() { + if (!(await confirmChangeIfContent())) { return; } self.type('text'); self.mime(''); save(); }; - this.selectRender = function() { + this.selectRender = async function() { + if (!(await confirmChangeIfContent())) { return; } self.type('render'); self.mime('text/html'); save(); }; - this.selectRelationMap = function() { + this.selectRelationMap = async function() { + if (!(await confirmChangeIfContent())) { return; } self.type('relation-map'); self.mime('application/json'); save(); }; - this.selectCode = function() { + this.selectCode = async function() { + if (!(await confirmChangeIfContent())) { return; } self.type('code'); self.mime(''); save(); }; - this.selectCodeMime = function(el) { + this.selectCodeMime = async function(el) { + if (!(await confirmChangeIfContent())) { return; } self.type('code'); self.mime(el.mime);