Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to restrict user to write only one javascript function(method) inside of ui-ace editor

this is my controller code

  $scope.aceOptions = {
      workerPath: 'http://localhost:50871/Scripts/app/vendor/',     
      useWrapMode: true,
      showGutter: true,
      theme: 'chrome',
      firstLineNumber: 1,
      onLoad: function (_editor) {
          $scope.script = {};
          $scope.script.scriptCode = "function fieldName_columnName_" + "functionName(){\n\n\n}";             
          var _session = _editor.getSession();
          _session.setMode('ace/mode/javascript');
          var _renderer = _editor.renderer;

          _session.on('changeAnnotation', function () {
              $scope.annotations = [];
              $scope.annotations = _editor.getSession().getAnnotations();
          }),
          _editor.$blockScrolling = Infinity;

          _session.on("change", function (e) {               
              var currentValue = _editor.getSession().getValue();
              $scope.script.scriptCode = currentValue;
          });


      },
      require: ['ace/ext/language_tools'],
      advanced: {
          enableSnippets: true,
          enableBasicAutocompletion: true,
          enableLiveAutocompletion: true
      }
  }

i wrote directive for ui-ace this is my html code

 <javascript-editor code="script.scriptCode" ace-option="aceOptions"></javascript-editor>

and directive code is

SCSApp
.directive('javascriptEditor', [
    function () {          
        return {
            restrict: 'E',
            scope: {
                data: '=code',
                aceOption: '='
            },
            templateUrl: '/Scripts/app/shared/directives/javascripEditor/partials/javascriptEditor.html',
            link: function (scope, element, attrs) {
            }
        }
    }]);

and this is my javascriptEditor.html

<div class="e1" ui-ace="aceOption" ng-model="data"></div>

i just want to restrict user not to write morethan one javascript function in ui-ace editor

like image 898
Syed Rasheed Avatar asked Nov 09 '22 23:11

Syed Rasheed


1 Answers

You can create your own javascript simple function parser or use a lib like parser3

Then write logic rules to show the success/fail to the UI based on the content of the ACE editor.

It is string / sentences parsing like compilers do in order to create the low level code.

like image 109
cesarluis Avatar answered Nov 14 '22 21:11

cesarluis