From 5704998d48618d7b67b478daf11d6aa412b2dddb Mon Sep 17 00:00:00 2001
From: Xiaowu Zhang <xiaowu.zhang@nexedi.com>
Date: Wed, 12 Apr 2017 14:31:30 +0000
Subject: [PATCH] erp5_ace_editor: improve portal callables scripts

Fix error display after save
Fix parameters not recognized
Fix python linting
the same way as ERP5 Script Python
---
 .../erp5_ace_editor/ace_editor_support.zpt           | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/bt5/erp5_ace_editor/SkinTemplateItem/portal_skins/erp5_ace_editor/ace_editor_support.zpt b/bt5/erp5_ace_editor/SkinTemplateItem/portal_skins/erp5_ace_editor/ace_editor_support.zpt
index 388b326ed8..92f9449333 100644
--- a/bt5/erp5_ace_editor/SkinTemplateItem/portal_skins/erp5_ace_editor/ace_editor_support.zpt
+++ b/bt5/erp5_ace_editor/SkinTemplateItem/portal_skins/erp5_ace_editor/ace_editor_support.zpt
@@ -3,6 +3,7 @@
                        div_id string:${id}_ace;
                        mode python: here.Base_getAceEditorMode();
                        container_div_id string:${div_id}_container;
+                       params python: getattr(here, "getParameterSignature", None)
                        '>
   <style type="text/css">
   .ace_scroller {
@@ -149,6 +150,7 @@
   ace_editor_container_div = null;
   ace_editor = null;
   var mode = '${mode}';
+  var params = '${params}';
 
   function maximizeFullscreenRemoveSaveMessage() {
     $('.ace_editor_maximize_fullscreen_message').remove();
@@ -391,17 +393,21 @@
 
     ace.require('ace/ext/language_tools');
     ace_editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true });
-
+    var data_options = {};
+    if (params !== 'None') {
+      data_options.bound_names = ['context','container','script','traverse_subpath','printed','same_type','string','sequence','random','DateTime','whrandom','reorder','sets','test','math'],
+      data_options.params = params;
+    }
     timer = 0;
     function checkPythonSourceCode() {
       if (timer) {
         window.clearTimeout(timer);
         timer = 0;
       }
+      data_options.code = ace_editor.getSession().getValue();
       timer = window.setTimeout(function() {
         $.post('${portal_url}/ERP5Site_checkPythonSourceCodeAsJSON',
-          {'data': JSON.stringify(
-          { code: ace_editor.getSession().getValue() })},
+          {'data': JSON.stringify(data_options)},
           function(data){
             ace_editor.getSession().setAnnotations(data.annotations);
           }
-- 
2.30.9