<commit_before>var xmlEditor = null;
var jsEditor  = null;

var clientWinSize = null;

if (typeof(dynaformEditor)==="undefined")
{
var dynaformEditor={
  A:"",
  dynUid:"",
  ajax:"",
  currentView:"preview",
  views:{},
  toolbar:{},
  htmlEditorLoaded:false,
  loadPressLoaded:true,
  codePressLoaded:false,
  currentJS:false,
  _run:function()
  {
    //LOADING PARTS
    this.toolbar = document.getElementById("fields_Toolbar")
    mainPanel.elements.headerBar.style.backgroundColor="#CBDAEF";
    mainPanel.elements.headerBar.style.borderBottom="1px solid #808080";
    mainPanel.elements.headerBar.appendChild(this.toolbar);
    mainPanel.events.remove = function(){
    }
// note added by <NAME> carlos[at]colosa[dot]com    
// the following line of code has been commented because it was executing twice the JavaScript code
// when the DynaForm was first loaded.
//    this.refresh_preview();
    this.changeToJavascripts();
    this.changeToPreview();
  },
  _review:function()
  {

  },
  save:function(){
    /*this.saveProperties();*/
    try {
      this.saveCurrentView();
    } catch (e) {
      alert(e);
    }
    res=this.ajax.save(this.A,this.dynUid);
    if(res=='noSub'){
      alert(G_STRINGS.ID_DONT_SAVE_XMLFORM);
      return false;
    }
    if (res==0) {
      alert(G_STRINGS.ID_SAVED);
    }
    else
    {
                if(typeof(res.innerHTML) == 'undefined')
                  G.alert(res["*message"]);
                else
                  alert(G_STRINGS.ID_LOST_SESSION_XMLFORM);
    }
  },
  save_as:function(){
    /*this.saveProperties();*/
    try {
      this.saveCurrentView();
    } catch (e) {
      alert(e);
    }
    url='dynaforms_Saveas';
    popupWindow('Save as', url+'?DYN_UID='+this.dynUid+'&AA='+this.A , 500, 350);
  },
  close:function()
  {
    var modified=this.ajax.is_modified(this.A,this.dynUid);
    if (typeof(modified)==="boolean")
    {
      if (!modified || confirm(G_STRINGS.ID_EXIT_WITHOUT_SAVING))
      {
        res=this.ajax.close(this.A);
        if (res==0) {
          //alert(G_STRINGS.ID_DYNAFORM_NOT_SAVED);
        }
        else
        {
          //alert(res["response"]);
          alert(res["*message"]);
        }
        return true;
      }
      else
      {
        return false;
      }
    }
    else
    {
      if (typeof(modified["*message"])==="string") G.alert(modified["*message"]);
      return false;
    }
  },
  // Save functions
  saveCurrentView:function()
  {
    switch(this.currentView)
    {
      case "xmlcode":
        this.saveXmlCode();
        break;
      case "htmlcode":
        this.saveHtmlCode();
        break;
      case "javascripts":
        this.saveJavascript();
        break;
      case "properties":
        this.saveProperties();
        break;
    }
  },

  saveShowHide:function()
  {
    ///-- this.save();
    try {
      this.saveCurrentView();
    } catch (e) {
      alert(e);
    }
    res=this.ajax.save(this.A,this.dynUid);
    switch(this.currentView)
    {
      case "xmlcode":
        this.saveXmlCode();
        break;
      case "htmlcode":
        this.saveHtmlCode();
        break;
      case "javascripts":
        this.saveJavascript();
        break;
      case "properties":
        this.saveProperties();
        break;
    }
  },

  saveXmlCode:function()
  {
    //var xmlCode = getField("XML").value;
    var xmlCode = this.getXMLCode();
    var todoRefreshXmlCode = xmlCode === null;
    if (todoRefreshXmlCode) return;
    var res = this.ajax.set_xmlcode(this.A, encodeURIComponent(xmlCode));
    if (res!=="") G.alert(res);
  },
  saveHtmlCode:function()
  {
    var htmlCode = getField("HTML");
    todoRefreshHtmlCode = htmlCode === null;
    if (todoRefreshHtmlCode) return;
    var response=this.ajax.set_htmlcode(this.A,htmlCode.value);
    if (response) G.alert(response["*message"],"Error");
  },
  saveJavascript:function()
  {
    var field=getField("JS_LIST","dynaforms_JSEditor");
    var code=this.getJSCode();
    var meta=jsMeta;

    if (field.value)
    {
      var res = this.ajax.set_javascript(this.A,field.value, encodeURIComponent(code), meta);
      if (typeof(res["*message"])==="string")
      {
        G.alert(res["*message"]);
      }
    }
  },
  saveProperties:function()
  {
    var form=this.views["properties"].getElementsByTagName("form")[0];
    var post=ajax_getForm(form);
    var response=this.ajax.set_properties(this.A,this.dynUid,post);
                if (response!=0){
                   G.alert(response["*message"]);
    } 
  },
  // Change view point functions
  changeToPreview:function()
  {
    //to adecuate the view perspective @Neyek
    content_div = getElementByPMClass('panel_content___processmaker')
    content_div.style.overflow='auto';
    if (this.currentView!="preview")this.refresh_preview();
    this.currentView="preview";
  },
  changeToXmlCode:function()
  {
    content_div = getElementByPMClass('panel_content___processmaker')
    content_div.style.overflow='auto';
    
    this.refresh_xmlcode();
    this.currentView="xmlcode";
    if( ! xmlEditor ) {
      clientWinSize = getClientWindowSize();

        xmlEditor = CodeMirror.fromTextArea('form[XML]', {
        height: (clientWinSize.height - 120) + "px",<commit_msg>BUG 7751 On error XML at least open a XML editor SOLVED<commit_after>var xmlEditor = null;
var jsEditor  = null;

var clientWinSize = null;

var strError = "";
var h3OK = 1;
function checkErrorXML(xmlParse)
{
    strError = "";
    h3OK = 1;
    checkXML(xmlParse);
}

function checkXML(nodeXml)
{
    var line, i, nNode;
    nNode = nodeXml.nodeName;
    if (nNode == "h3") {
        if (h3OK == 0) {
            return;
        }
        h3OK = 0;
    }
    if (nNode == "#text") {
        strError = nodeXml.nodeValue + "\n";
    }
    line = nodeXml.childNodes.length;
    for (i = 0;i < line; i++) {
        checkXML(nodeXml.childNodes[i]);
    }
}

function validateXML(xmlString)
{
    // code for IE
    if (window.ActiveXObject) {
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(xmlString);
        if (xmlDoc.parseError.errorCode != 0) {
            xmlString = "Error Code: " + xmlDoc.parseError.errorCode + "\n";
            xmlString = xmlString + "Error Reason: " + xmlDoc.parseError.reason;
            xmlString = xmlString + "Error Line: " + xmlDoc.parseError.line;
            alert(xmlString);
            return false;
        } else {
            return true;
        }
    } else {
        // code for Mozilla, Firefox, Opera, etc.
        if (document.implementation.createDocument) {
            var parser = new DOMParser();
            var text = xmlString;
            var xmlDoc = parser.parseFromString(text, "text/xml");

            if (xmlDoc.getElementsByTagName("parsererror").length > 0) {
                checkErrorXML(xmlDoc.getElementsByTagName("parsererror")[0]);
                alert(strError);
                return false;
            } else {
                return true;
            }
        } else {
            alert('Your browser cannot handle XML validation');
            return false;
        }
    }
}

if (typeof(dynaformEditor)==="undefined")
{
var dynaformEditor={
  A:"",
  dynUid:"",
  ajax:"",
  currentView:"preview",
  views:{},
  toolbar:{},
  htmlEditorLoaded:false,
  loadPressLoaded:true,
  codePressLoaded:false,
  currentJS:false,
  responseAction:true,
  _run:function()
  {
    //LOADING PARTS
    this.toolbar = document.getElementById("fields_Toolbar")
    mainPanel.elements.headerBar.style.backgroundColor="#CBDAEF";
    mainPanel.elements.headerBar.style.borderBottom="1px solid #808080";
    mainPanel.elements.headerBar.appendChild(this.toolbar);
    mainPanel.events.remove = function(){
    }
// note added by <NAME> carlos[at]colosa[dot]com    
// the following line of code has been commented because it was executing twice the JavaScript code
// when the DynaForm was first loaded.
//    this.refresh_preview();
    this.changeToJavascripts();
    this.changeToPreview();
  },
  _review:function()
  {

  },
  save:function() {
    /*this.saveProperties();*/
    try {
      this.saveCurrentView();
    } catch (e) {
      alert(e);
    }
    if (this.responseAction == true) {
        res = this.ajax.save(this.A,this.dynUid);
        if (res == 'noSub') {
            alert(G_STRINGS.ID_DONT_SAVE_XMLFORM);
            return false;
        }
        if (res==0) {
            alert(G_STRINGS.ID_SAVED);
        } else {
            if (typeof(res.innerHTML) == 'undefined') {
                G.alert(res["*message"]);
            } else {
                alert(G_STRINGS.ID_LOST_SESSION_XMLFORM);
            }
        }
    }
  },
  save_as:function(){
    /*this.saveProperties();*/
    try {
      this.saveCurrentView();
    } catch (e) {
      alert(e);
    }
    url='dynaforms_Saveas';
    popupWindow('Save as', url+'?DYN_UID='+this.dynUid+'&AA='+this.A , 500, 350);
  },
  close:function()
  {
    var modified=this.ajax.is_modified(this.A,this.dynUid);
    if (typeof(modified)==="boolean")
    {
      if (!modified || confirm(G_STRINGS.ID_EXIT_WITHOUT_SAVING))
      {
        res=this.ajax.close(this.A);
        if (res==0) {
          //alert(G_STRINGS.ID_DYNAFORM_NOT_SAVED);
        }
        else
        {
          //alert(res["response"]);
          alert(res["*message"]);
        }
        return true;
      }
      else
      {
        return false;
      }
    }
    else
    {
      if (typeof(modified["*message"])==="string") G.alert(modified["*message"]);
      return false;
    }
  },
  // Save functions
  saveCurrentView:function()
  {
    switch(this.currentView)
    {
      case "xmlcode":
        this.saveXmlCode();
        break;
      case "htmlcode":
        this.saveHtmlCode();
        break;
      case "javascripts":
        this.saveJavascript();
        break;
      case "properties":
        this.saveProperties();
        break;
    }
  },

  saveShowHide:function()
  {
    ///-- this.save();
    try {
      this.saveCurrentView();
    } catch (e) {
      alert(e);
    }
    res=this.ajax.save(this.A,this.dynUid);
    switch(this.currentView)
    {
      case "xmlcode":
        this.saveXmlCode();
        break;
      case "htmlcode":
        this.saveHtmlCode();
        break;
      case "javascripts":
        this.saveJavascript();
        break;
      case "properties":
        this.saveProperties();
        break;
    }
  },

  saveXmlCode:function()
  {
    //var xmlCode = getField("XML").value;
    var xmlCode = this.getXMLCode();
    if (validateXML(xmlCode) == true) {
        var todoRefreshXmlCode = xmlCode === null;
        if (todoRefreshXmlCode) return;
        var res = this.ajax.set_xmlcode(this.A, encodeURIComponent(xmlCode));
        if (res!=="") G.alert(res);
        this.responseAction = true;
    } else {
        this.responseAction = false;
    }
  },
  saveHtmlCode:function()
  {
    var htmlCode = getField("HTML");
    todoRefreshHtmlCode = htmlCode === null;
    if (todoRefreshHtmlCode) return;
    var response=this.ajax.set_htmlcode(this.A,htmlCode.value);
    if (response) {
        G.alert(response["*message"],"Error");
        this.responseAction = false;
    } else {
        this.responseAction = true;
    }
  },
  saveJavascript:function()
  {
    var field=getField("JS_LIST","dynaforms_JSEditor");
    var code=this.getJSCode();
    var meta=jsMeta;

    if (field.value)
    {
      var res = this.ajax.set_javascript(this.A,field.value, encodeURIComponent(code), meta);
      if (typeof(res["*message"])==="string")
      {
        G.alert(res["*message"]);
      }
    }
    this.responseAction = true;
  },
  saveProperties:function()
  {
    var form=this.views["properties"].getElementsByTagName("form")[0];
    var post=ajax_getForm(form);
    var response=this.ajax.set_properties(this.A,this.dynUid,post);
                if (response!=0){
                   G.alert(response["*message"]);
    }
    this.responseAction = true;
  },
  // Change view point functions
  changeToPreview:function()
  {
    //to adecuate the view perspective @Neyek
    content_div = getElementByPMClass('panel_content___processmaker')
    content_div.style.overflow='auto';
    if (this.currentView!="preview")this.refresh_preview();
    this.currentView="preview";
  },
  changeToXmlCode:function()
  {
    content_div = getElementByPMClass('panel_content___processmaker')
    content_div.style.overflow='auto';
    
    this.refresh_xmlcode();
    this.currentView="xmlcode";
    if( ! xmlEditor ) {
      clientWinSize = getClientWindowSize();

        xmlEditor = CodeMirror.fromTextArea('form[XML]', {
        height: (clientWinSize.height - 120) + "px",
{'fraction_non_alphanumeric': 0.14387587179688113, 'fraction_numerical': 0.0044667345819293155, 'mean_word_length': 2.4214477211796246, 'pattern_counts': {'":': 16, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 47}, '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': '1689844', 'n_tokens_mistral': 4178, 'n_tokens_neox': 4109, 'n_words': 689}