<?xml version="1.0" encoding="UTF-8"?>
<dynaForm name="triggers_Edit" type="xmlform" width="100%" labelWidth="2px" enableTemplate="1">
  <PRO_UID type="hidden"/>
  <TRI_UID type="hidden"/>
  <TRI_TYPE type="hidden"/>
  <STEP_UID type="hidden"/>
  <ST_TYPE type="hidden"/>
  <TRI_WEBBOT type="textareapm" class="formLabel" cols="115" rows="28" width="100%" height="380px" showVars="1" process="@#PRO_UID">
</TRI_WEBBOT>
  <BTN_CANCEL type="button" onclick="cancel();">
    <en><![CDATA[Cancel]]></en>
  </BTN_CANCEL>
  <SAVE type="button" onclick="document.getElementById('form[TRI_WEBBOT]').value = triggerEditor.getValue();                              triggerSave1(this.form);">
    <en><![CDATA[Save]]></en>
  </SAVE>
  <JS type="JavaScript"><![CDATA[

CodeMirror.commands.autocomplete = function(cm) {
    CodeMirror.showHint(cm, CodeMirror.phpHint);
}

var triggerEditor = CodeMirror.fromTextArea(document.getElementById("form[TRI_WEBBOT]"), {
    lineNumbers: true,
    matchBrackets: true,
    mode: "application/x-httpd-php-open",
    PMEnabled: true,
    indentUnit: 2,
    indentWithTabs: false,
    extraKeys: {"Ctrl-Space": "autocomplete"}
});
triggerEditor.setSize(890, 440);

var _oVarsPanel_;
var showDynaformsFormVars = function(sFieldName, sAjaxServer, sProcess, sSymbol) {
	_oVarsPanel_ = new leimnud.module.panel();
	_oVarsPanel_.options = {
    limit    : true,
    size     : {w:600,h:420},
    position : {x:0,y:0,center:true},
    title    : '',
    theme    : 'processmaker',
    statusBar: false,
    control  : {drag:false,resize:true,close:true},
    fx       : {opacity:true,rolled:false,modal:true}
  };
  _oVarsPanel_.make();
  _oVarsPanel_.events = {
    remove:function() {
      delete _oVarsPanel_;
    }.extend(this)
  };
  _oVarsPanel_.loader.show();
  oRPC = new leimnud.module.rpc.xmlhttp({
    url   : sAjaxServer,
    method: 'POST',
    args  : 'sFieldName=' + sFieldName + '&sProcess=' + sProcess + '&sSymbol=' + sSymbol
  });
  oRPC.callback = function(oRPC) {
    _oVarsPanel_.loader.hide();
    var scs = oRPC.xmlhttp.responseText.extractScript();
    _oVarsPanel_.addContent(oRPC.xmlhttp.responseText);
    scs.evalScript();
  }.extend(this);
  oRPC.make();
};

var insertFormVar = function(sFieldName, sValue) {
    if (triggerEditor.getSelection() == "") {
	    triggerEditor.replaceRange(sValue, triggerEditor.getCursor());
    } else {
        triggerEditor.replaceSelection(sValue);
    }
    _oVarsPanel_.remove();
    triggerEditor.focus();
};

function cancel(){
    if(opener) {
        opener.windowCode[document.getElementById('form[TRI_UID]').value] = false;
    }
    window.close();
}
window.onbeforeunload=function(){
    if(opener) {
        opener.windowCode[document.getElementById('form[TRI_UID]').value] = false;
    }
};

function triggerSave1(form)
{
    ajax_post(
        form.action,
        form,
        "POST",
        function (responseText)
        {
            var dataResponse = eval("(" + responseText + ")"); //json

            if (dataResponse.success) {
                if (opener) {
                    if (@QSTEP_UID != "" && @QST_TYPE != "" && opener.showTriggers) {
                        opener.showTriggers(@QSTEP_UID, @QST_TYPE);
                    }

                    if (opener.reloadTriggersShortList) {
                        opener.reloadTriggersShortList();
                    }
                }

                window.close();
            } else {
                new leimnud.module.app.alert().make({
                    label: dataResponse.msg
                });
            }
        },
        true
    );
}
]]>
</JS>
</dynaForm>

