<commit_before>/*
Copyright 2006-2007, Open Source Applications Foundation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

//Functions for interacting with the remote
/***************************************/
windmill.ui.remote = new function() {
    this.selectedElement = null;

    this.scrollRecorderTextArea = function() {
        var obj = $("ide");
        obj.scrollTop = obj.scrollHeight;

    };

    this.clearIDE = function() {
        input_box = confirm("Are you sure you want to delete all the data in the IDE?");
        if (input_box == true) {
            fleegix.fx.fadeOut($('ideForm'));
            d = function() {
                $('ideForm').innerHTML = '';
                windmill.ui.recorder.recordOff();
                fleegix.fx.fadeIn($('ideForm'));

            };
            setTimeout("d()", 800);

        }

    };

    this.methodChange = function(id) {
        var selected = $(id + 'method').selectedIndex;
        var methodObj = $(id + 'method');
        var method = methodObj[selected].value;
        //Preserve the value that was in there
        try {
          var oldLocator = $(id + "locator").value;
          var oldLocatorType = $(id + "locatorType").value;
        }
        catch(err) { }
        var newAction = this.buildAction(method, {
            'uuid': id
        });
        $(id).innerHTML = newAction.innerHTML;
        //only try to replace them if this particular action had a locator to begin with
        try {
          if (typeof(oldLocator) != 'undefined') {
            $(id + "locator").value = oldLocator;
            $(id + "locatorType").value = oldLocatorType;
          }
        }
        catch(err) {}

        //safari hack for resizing the suite div to accomodate the new action
        $(id).style.height = '';
        
        //if the action was an open, automatically insert a waits.forPageLoad
        //but only if the next action isn't already forPageLoad
        var nextAction = $(id).nextSibling;
        var nextMethod = null;
        if (nextAction){
          nextMethod = $(nextAction.id+"method").value;
        } 
        if (method == "open" && nextMethod != "waits.forPageLoad"){
          this.addActionBelow(id,this.buildAction("waits.forPageLoad", {timeout:8000}));
          $(id+"option").focus();
        }
    };

    this.setRemoteElem = function(id) {
      this.selectedElement = id;
    };

    this.addActionAbove = function(uuid) {
        var newAction = this.buildAction(null, {});
        var parent = $(uuid).parentNode;
        parent.insertBefore(newAction, $(uuid));
        //IE hack
        if (windmill.browser.isIE) {
          $(newAction.id).innerHTML = newAction.innerHTML;
        }
        else {
          $(newAction.id + "locator").focus();
        }
        fleegix.fx.fadeIn($(newAction.id));
    };

    this.addActionBelow = function(uuid, action) {
        if (!action){ var action = this.buildAction(null, {}); }
        var parent = $(uuid).parentNode;
        parent.insertBefore(action, $(uuid).nextSibling);
        //IE Hack
        if (windmill.browser.isIE) { $(action.id).innerHTML = action.innerHTML; }
        else {
          var loc = $(action.id + "locator");
          if (loc){ loc.focus(); }
        }
        fleegix.fx.fadeIn($(action.id));
    };

    this.deleteAction = function(uuid) {
        //input_box=confirm("Are you sure you want to continue deleting?");
        //if (input_box==true) {
        fleegix.fx.fadeOut($(uuid));
        d = function() {
            var pElement = $(uuid).parentNode;
            pElement.removeChild($(uuid));

            //So that we don't leave the selected element
            //variable turned on when there are no actions in the IDE
            if (pElement.id == 'ideForm') {
                windmill.ui.remote.selectedElement = null;

            }

        };
        setTimeout("d()", 800);

    };

    this.addAction = function(action) {
        var suite = this.getSuite();
        if (typeof(action) == 'undefined') {
            var action = this.buildAction(null, {});

        }
        //A hack to make it draw the UI correctly in IE
        suite.appendChild(action);
        if (windmill.browser.isIE) {
            $(action.id).innerHTML = action.innerHTML;
        }
        else {
            $(action.id + "locator").focus();
        }
        return action.id;

    };

    this.actionFromJSON = function(){
      var json = prompt("Enter JSON String", '{"params": {"xpath": "/html/body"}, "method": "click"}');
      try { 
        var actionObj = eval('('+json+')');
        var action = windmill.ui.remote.buildAction(actionObj.method, actionObj.params);
        windmill.ui.remote.addAction(action);
      }
      catch(err){alert('Please enter valid JSON');}
    }

    this.getSuite = function(suiteName) {

        if (!suiteName) {
            var suiteName = 'recordingSuite' + windmill.ui.recordSuiteNum;
        }

        var suite = $(suiteName);
        if (suite == null) {
            var ide = $('ideForm');
            suite = document.createElement('div');
            suite.style.position = 'relative';
            suite.id = suiteName;<commit_msg>Small fix for adding actions from json strings<commit_after>/*
Copyright 2006-2007, Open Source Applications Foundation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

//Functions for interacting with the remote
/***************************************/
windmill.ui.remote = new function() {
    this.selectedElement = null;

    this.scrollRecorderTextArea = function() {
        var obj = $("ide");
        obj.scrollTop = obj.scrollHeight;

    };

    this.clearIDE = function() {
        input_box = confirm("Are you sure you want to delete all the data in the IDE?");
        if (input_box == true) {
            fleegix.fx.fadeOut($('ideForm'));
            d = function() {
                $('ideForm').innerHTML = '';
                windmill.ui.recorder.recordOff();
                fleegix.fx.fadeIn($('ideForm'));

            };
            setTimeout("d()", 800);

        }

    };

    this.methodChange = function(id) {
        var selected = $(id + 'method').selectedIndex;
        var methodObj = $(id + 'method');
        var method = methodObj[selected].value;
        //Preserve the value that was in there
        try {
          var oldLocator = $(id + "locator").value;
          var oldLocatorType = $(id + "locatorType").value;
        }
        catch(err) { }
        var newAction = this.buildAction(method, {
            'uuid': id
        });
        $(id).innerHTML = newAction.innerHTML;
        //only try to replace them if this particular action had a locator to begin with
        try {
          if (typeof(oldLocator) != 'undefined') {
            $(id + "locator").value = oldLocator;
            $(id + "locatorType").value = oldLocatorType;
          }
        }
        catch(err) {}

        //safari hack for resizing the suite div to accomodate the new action
        $(id).style.height = '';
        
        //if the action was an open, automatically insert a waits.forPageLoad
        //but only if the next action isn't already forPageLoad
        var nextAction = $(id).nextSibling;
        var nextMethod = null;
        if (nextAction){
          nextMethod = $(nextAction.id+"method").value;
        } 
        if (method == "open" && nextMethod != "waits.forPageLoad"){
          this.addActionBelow(id,this.buildAction("waits.forPageLoad", {timeout:8000}));
          $(id+"option").focus();
        }
    };

    this.setRemoteElem = function(id) {
      this.selectedElement = id;
    };

    this.addActionAbove = function(uuid) {
        var newAction = this.buildAction(null, {});
        var parent = $(uuid).parentNode;
        parent.insertBefore(newAction, $(uuid));
        //IE hack
        if (windmill.browser.isIE) {
          $(newAction.id).innerHTML = newAction.innerHTML;
        }
        else {
          $(newAction.id + "locator").focus();
        }
        fleegix.fx.fadeIn($(newAction.id));
    };

    this.addActionBelow = function(uuid, action) {
        if (!action){ var action = this.buildAction(null, {}); }
        var parent = $(uuid).parentNode;
        parent.insertBefore(action, $(uuid).nextSibling);
        //IE Hack
        if (windmill.browser.isIE) { $(action.id).innerHTML = action.innerHTML; }
        else {
          var loc = $(action.id + "locator");
          if (loc){ loc.focus(); }
        }
        fleegix.fx.fadeIn($(action.id));
    };

    this.deleteAction = function(uuid) {
        //input_box=confirm("Are you sure you want to continue deleting?");
        //if (input_box==true) {
        fleegix.fx.fadeOut($(uuid));
        d = function() {
            var pElement = $(uuid).parentNode;
            pElement.removeChild($(uuid));

            //So that we don't leave the selected element
            //variable turned on when there are no actions in the IDE
            if (pElement.id == 'ideForm') {
                windmill.ui.remote.selectedElement = null;

            }

        };
        setTimeout("d()", 800);

    };

    this.addAction = function(action) {
        var suite = this.getSuite();
        if (typeof(action) == 'undefined') {
            var action = this.buildAction(null, {});

        }
        //A hack to make it draw the UI correctly in IE
        suite.appendChild(action);
        if (windmill.browser.isIE) {
            $(action.id).innerHTML = action.innerHTML;
        }
        else {
            $(action.id + "locator").focus();
        }
        return action.id;

    };

    this.actionFromJSON = function(){
      var json = prompt("Enter JSON String", '{"params": {"xpath": "/html/body"}, "method": "click"}');
      if (json != null){
        try { 
          var actionObj = eval('('+json+')');
          var action = windmill.ui.remote.buildAction(actionObj.method, actionObj.params);
          windmill.ui.remote.addAction(action);
        }
        catch(err){alert('Please enter valid JSON');}
      }
    }

    this.getSuite = function(suiteName) {

        if (!suiteName) {
            var suiteName = 'recordingSuite' + windmill.ui.recordSuiteNum;
        }

        var suite = $(suiteName);
        if (suite == null) {
            var ide = $('ideForm');
            suite = document.createElement('div');
            suite.style.position = 'relative';
            suite.id = suiteName;
{'fraction_non_alphanumeric': 0.13778632628081833, 'fraction_numerical': 0.003846826368246197, 'mean_word_length': 2.065934065934066, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2250234', 'n_tokens_mistral': 3235, 'n_tokens_neox': 3109, 'n_words': 849}