Procházet zdrojové kódy

[spark] Move JVM memory input to ko_components.mako

Johan Ahlen před 10 roky
rodič
revize
40869175cd

+ 1 - 41
apps/spark/src/spark/templates/editor.mako

@@ -834,47 +834,7 @@ ${ commonheader(_('Query'), app_name, user, "68px") | n,unicode }
   <div><a class="pointer demi-modal-chevron" data-dismiss="modal"><i class="fa fa-chevron-up"></i></a></div>
 </div>
 
-<template id="jvm-memory-input-template">
-  <input type="text" class="input-small" data-bind="textInput: value" /> <select class="input-mini" data-bind="options: units, value: selectedUnit" />
-</template>
-
-<script type="text/javascript" charset="utf-8">
-  (function() {
-    var JVM_MEM_PATTERN = /([0-9]+)([MG])$/;
-    var UNITS = { 'MB' : 'M', 'GB' : 'G' };
-
-    function JvmMemoryInputViewModel(params) {
-      this.valueObservable = params.value;
-      this.units = Object.keys(UNITS);
-      this.selectedUnit = ko.observable();
-      this.value = ko.observable().extend({ 'numeric' : 0 });
-
-      var match = JVM_MEM_PATTERN.exec(this.valueObservable());
-      if (match.length === 3) {
-        this.value(match[1]);
-        this.selectedUnit(match[2] === 'M' ? 'MB' : 'GB');
-      }
-
-      this.value.subscribe(this.updateValueObservable, this);
-      this.selectedUnit.subscribe(this.updateValueObservable, this);
-    }
-
-    JvmMemoryInputViewModel.prototype.updateValueObservable = function() {
-      if (isNaN(this.value()) || this.value() === '') {
-        this.valueObservable(undefined);
-      } else {
-        this.valueObservable(this.value() + UNITS[this.selectedUnit()]);
-      }
-    };
-
-    ko.components.register('jvm-memory-input', {
-      viewModel: JvmMemoryInputViewModel,
-      template: { element: 'jvm-memory-input-template' }
-    });
-  }());
-</script>
-
-
+${ koComponents.jvmMemoryInput() }
 ${ koComponents.assistPanel() }
 
 <script type="text/javascript" charset="utf-8">

+ 42 - 0
desktop/core/src/desktop/templates/ko_components.mako

@@ -244,3 +244,45 @@ from django.utils.translation import ugettext as _
     }());
   </script>
 </%def>
+
+<%def name="jvmMemoryInput()">
+  <template id="jvm-memory-input-template">
+    <input type="text" class="input-small" data-bind="textInput: value" /> <select class="input-mini" data-bind="options: units, value: selectedUnit" />
+  </template>
+
+  <script type="text/javascript" charset="utf-8">
+    (function() {
+      var JVM_MEM_PATTERN = /([0-9]+)([MG])$/;
+      var UNITS = { 'MB' : 'M', 'GB' : 'G' };
+
+      function JvmMemoryInputViewModel(params) {
+        this.valueObservable = params.value;
+        this.units = Object.keys(UNITS);
+        this.selectedUnit = ko.observable();
+        this.value = ko.observable().extend({ 'numeric' : 0 });
+
+        var match = JVM_MEM_PATTERN.exec(this.valueObservable());
+        if (match.length === 3) {
+          this.value(match[1]);
+          this.selectedUnit(match[2] === 'M' ? 'MB' : 'GB');
+        }
+
+        this.value.subscribe(this.updateValueObservable, this);
+        this.selectedUnit.subscribe(this.updateValueObservable, this);
+      }
+
+      JvmMemoryInputViewModel.prototype.updateValueObservable = function() {
+        if (isNaN(this.value()) || this.value() === '') {
+          this.valueObservable(undefined);
+        } else {
+          this.valueObservable(this.value() + UNITS[this.selectedUnit()]);
+        }
+      };
+
+      ko.components.register('jvm-memory-input', {
+        viewModel: JvmMemoryInputViewModel,
+        template: { element: 'jvm-memory-input-template' }
+      });
+    }());
+  </script>
+</%def>