浏览代码

HUE-5230 [metadata] Enable ESC to cancel tag editing

Johan Ahlen 9 年之前
父节点
当前提交
f81f8d96f9
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

+ 12 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -191,10 +191,18 @@
             options.onSave(currentSelectize.getValue());
           }
           $(document).off('click', saveOnClickOutside);
+          $(document).off('keyup', hideOnEscape);
           showReadOnly();
         }
       };
 
+      var hideOnEscape = function (event) {
+        if (event.which === 27) {
+          showReadOnly();
+          $(document).off('click', saveOnClickOutside);
+          $(document).off('keyup', hideOnEscape);
+        }
+      };
 
       var showEdit = function () {
         optionsBeforeEdit = options.setTags().concat();
@@ -210,13 +218,16 @@
           }
           showReadOnly();
           $(document).off('click', saveOnClickOutside);
+          $(document).off('keyup', hideOnEscape);
         }).appendTo($editActions);
         $('<i>').addClass('fa fa-close').click(function () {
           showReadOnly();
           $(document).off('click', saveOnClickOutside);
+          $(document).off('keyup', hideOnEscape);
         }).appendTo($editActions);
         window.setTimeout(function () {
           $(document).on('click', saveOnClickOutside);
+          $(document).on('keyup', hideOnEscape);
         }, 0);
       };
 
@@ -224,6 +235,7 @@
         if (currentSelectize) {
           currentSelectize.destroy();
           $element.hide();
+          $element.val(options.setTags().join(','))
         }
         $readOnlyContainer.empty();
         var $readOnlyInner = $('<div>').addClass('selectize-input items not-full has-options has-items').appendTo($readOnlyContainer);