瀏覽代碼

N.1041 configuration editor : add focus and ctrl+s shortcut

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4963 a333f486-631f-4898-b8df-5754b55c2be0
pgoiffon 7 年之前
父節點
當前提交
5e714d4027
共有 1 個文件被更改,包括 28 次插入8 次删除
  1. 28 8
      datamodels/2.x/itop-config/config.php

+ 28 - 8
datamodels/2.x/itop-config/config.php

@@ -190,11 +190,24 @@ try
 		$oP->add("</form>");
 	
 		$sConfirmCancel = addslashes(Dict::S('config-confirm-cancel'));
+		$oP->add_script(
+			<<<EOF
+function UpdateConfigEditorButtonState()
+{
+    var editor = ace.edit("new_config");
+    var isSameContent = editor.getValue() == $('#prev_config').val();
+    var hasNoError = $.isEmptyObject(editor.getSession().getAnnotations());
+    $('#cancel_button').attr('disabled', isSameContent);
+    $('#submit_button').attr('disabled', isSameContent || !hasNoError);
+}
+EOF
+		);
         $oP->add_ready_script(
             <<<EOF
 var editor = ace.edit("new_config");
 var textarea = $('input[name="new_config"]');
 editor.getSession().setValue(textarea.val());
+
 editor.getSession().on('change', function()
 {
   textarea.val(editor.getSession().getValue());
@@ -204,16 +217,23 @@ editor.getSession().on("changeAnnotation", function()
 {
   UpdateConfigEditorButtonState();
 });
+
 editor.setTheme("ace/theme/eclipse");
 editor.getSession().setMode("ace/mode/php");
-function UpdateConfigEditorButtonState()
-{
-    var editor = ace.edit("new_config");
-    var isSameContent = editor.getValue() == $('#prev_config').val();
-    var hasNoError = $.isEmptyObject(editor.getSession().getAnnotations());
-    $('#cancel_button').attr('disabled', isSameContent);
-    $('#submit_button').attr('disabled', isSameContent || !hasNoError);
-}
+editor.commands.addCommand({
+    name: 'save',
+    bindKey: {win: "Ctrl-S", "mac": "Cmd-S"},
+    exec: function(editor) {
+        \$editorContainer = \$(editor.container);
+        \$submitButton = $('#submit_button');
+        
+        if (\$submitButton.is(":enabled")) {
+            \$editorContainer.closest("form").submit();
+        }
+    }
+})
+
+editor.focus();
 EOF
         );