From 244edfe69a11f8a3f287e2ed8e5860333232a61c Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 21 Jun 2019 16:35:23 +0300 Subject: [PATCH] Document info: undo changes by Esc button --- apps/common/main/lib/component/InputField.js | 2 ++ .../main/app/view/FileMenuPanels.js | 19 +++++++++++++++---- .../main/app/view/FileMenuPanels.js | 19 +++++++++++++++---- .../main/app/view/FileMenuPanels.js | 19 +++++++++++++++---- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/apps/common/main/lib/component/InputField.js b/apps/common/main/lib/component/InputField.js index 199a2d9ab..054721355 100644 --- a/apps/common/main/lib/component/InputField.js +++ b/apps/common/main/lib/component/InputField.js @@ -239,6 +239,8 @@ define([ }, onKeyDown: function(e) { + this.trigger('keydown:before', this, e); + if (e.isDefaultPrevented()) return; diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index b6564fa6a..d231b889e 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -783,6 +783,17 @@ define([ // this.lblEditTime = $('#id-info-edittime'); // edited info + var keyDownBefore = function(input, e){ + if (e.keyCode === Common.UI.Keys.ESC) { + var newVal = input._input.val(), + oldVal = input.getValue(); + if (newVal !== oldVal) { + input.setValue(oldVal); + e.stopPropagation(); + } + } + }; + this.inputTitle = new Common.UI.InputField({ el : $('#id-info-title'), style : 'width: 200px;', @@ -793,7 +804,7 @@ define([ me.coreProps.asc_putTitle(me.inputTitle.getValue()); me.api.asc_setCoreProps(me.coreProps); } - }); + }).on('keydown:before', keyDownBefore); this.inputSubject = new Common.UI.InputField({ el : $('#id-info-subject'), style : 'width: 200px;', @@ -804,7 +815,7 @@ define([ me.coreProps.asc_putSubject(me.inputSubject.getValue()); me.api.asc_setCoreProps(me.coreProps); } - }); + }).on('keydown:before', keyDownBefore); this.inputComment = new Common.UI.InputField({ el : $('#id-info-comment'), style : 'width: 200px;', @@ -815,7 +826,7 @@ define([ me.coreProps.asc_putDescription(me.inputComment.getValue()); me.api.asc_setCoreProps(me.coreProps); } - }); + }).on('keydown:before', keyDownBefore); // modify info this.lblModifyDate = $('#id-info-modify-date'); @@ -866,7 +877,7 @@ define([ me.api.asc_setCoreProps(me.coreProps); } } - }); + }).on('keydown:before', keyDownBefore); this.rendered = true; diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index 25ea27280..ad7b59477 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -673,6 +673,17 @@ define([ this.lblUploaded = $('#id-info-uploaded'); // edited info + var keyDownBefore = function(input, e){ + if (e.keyCode === Common.UI.Keys.ESC) { + var newVal = input._input.val(), + oldVal = input.getValue(); + if (newVal !== oldVal) { + input.setValue(oldVal); + e.stopPropagation(); + } + } + }; + this.inputTitle = new Common.UI.InputField({ el : $('#id-info-title'), style : 'width: 200px;', @@ -683,7 +694,7 @@ define([ me.coreProps.asc_putTitle(me.inputTitle.getValue()); me.api.asc_setCoreProps(me.coreProps); } - }); + }).on('keydown:before', keyDownBefore); this.inputSubject = new Common.UI.InputField({ el : $('#id-info-subject'), style : 'width: 200px;', @@ -694,7 +705,7 @@ define([ me.coreProps.asc_putSubject(me.inputSubject.getValue()); me.api.asc_setCoreProps(me.coreProps); } - }); + }).on('keydown:before', keyDownBefore); this.inputComment = new Common.UI.InputField({ el : $('#id-info-comment'), style : 'width: 200px;', @@ -705,7 +716,7 @@ define([ me.coreProps.asc_putDescription(me.inputComment.getValue()); me.api.asc_setCoreProps(me.coreProps); } - }); + }).on('keydown:before', keyDownBefore); // modify info this.lblModifyDate = $('#id-info-modify-date'); @@ -756,7 +767,7 @@ define([ me.api.asc_setCoreProps(me.coreProps); } } - }); + }).on('keydown:before', keyDownBefore); this.rendered = true; diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index f1ab49c2d..3c9cb7ffe 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -1124,6 +1124,17 @@ define([ this.lblUploaded = $('#id-info-uploaded'); // edited info + var keyDownBefore = function(input, e){ + if (e.keyCode === Common.UI.Keys.ESC) { + var newVal = input._input.val(), + oldVal = input.getValue(); + if (newVal !== oldVal) { + input.setValue(oldVal); + e.stopPropagation(); + } + } + }; + this.inputTitle = new Common.UI.InputField({ el : $('#id-info-title'), style : 'width: 200px;', @@ -1134,7 +1145,7 @@ define([ me.coreProps.asc_putTitle(me.inputTitle.getValue()); me.api.asc_setCoreProps(me.coreProps); } - }); + }).on('keydown:before', keyDownBefore); this.inputSubject = new Common.UI.InputField({ el : $('#id-info-subject'), style : 'width: 200px;', @@ -1145,7 +1156,7 @@ define([ me.coreProps.asc_putSubject(me.inputSubject.getValue()); me.api.asc_setCoreProps(me.coreProps); } - }); + }).on('keydown:before', keyDownBefore); this.inputComment = new Common.UI.InputField({ el : $('#id-info-comment'), style : 'width: 200px;', @@ -1156,7 +1167,7 @@ define([ me.coreProps.asc_putDescription(me.inputComment.getValue()); me.api.asc_setCoreProps(me.coreProps); } - }); + }).on('keydown:before', keyDownBefore); // modify info this.lblModifyDate = $('#id-info-modify-date'); @@ -1207,7 +1218,7 @@ define([ me.api.asc_setCoreProps(me.coreProps); } } - }); + }).on('keydown:before', keyDownBefore); this.rendered = true;