<?xml version="1.0" encoding="UTF-8"?>
<dynaForm name="dynaforms_Edit" type="xmlform" width="100%" enableTemplate="1">
  <DYN_UID type="hidden" showInTable="0"/>
  <ACTION type="hidden" showInTable="0"/>
  <PRO_UID type="hidden" showInTable="0"/>
  <LANG type="private"/>
  <TITLE type="title" group="1">
    <en><![CDATA[Dynaform Information]]></en>
  </TITLE>
  <ADD_TABLE type="dropdown" sqlConnection="dbarray" required="1">
  SELECT * FROM ADDITIONAL_TABLES
  <en><![CDATA[Create from a PM Table]]></en>
</ADD_TABLE>
  <DYN_TITLE type="text" maxlength="256" size="48" required="1">
    <en><![CDATA[Title]]></en>
  </DYN_TITLE>
  <DYN_TYPE type="dropdown" colWidth="80" align="center">
    <en><![CDATA[Type]]><option name="xmlform"><![CDATA[Normal]]></option><option name="grid"><![CDATA[Grid]]></option></en>
  </DYN_TYPE>
  <DYN_DESCRIPTION type="textarea" cols="45" rows="8">
    <en><![CDATA[Description]]></en>
  </DYN_DESCRIPTION>
  <CONTINUE type="button" onclick="assignVariables( this.form, false );">
    <en><![CDATA[Save]]></en>
  </CONTINUE>
  <SAVE_DYNAFORM type="button" onclick="dynaformSave( this.form, false );">
    <en><![CDATA[Save]]></en>
  </SAVE_DYNAFORM>
  <SAVE_OPEN type="button" onclick="dynaformSave( this.form, true );">
    <en><![CDATA[Save & Open]]></en>
  </SAVE_OPEN>
  <BTN_CANCEL type="button" onclick="cancel();">
    <en><![CDATA[Cancel]]></en>
  </BTN_CANCEL>
  <!--Copy dynaform-->
  <COPY_PROCESS_UID type="dropdown" dependentfields="COPY_DYNAFORM_UID"><![CDATA[
    SELECT PRO.PRO_UID, CON.CON_VALUE
    FROM   PROCESS AS PRO, CONTENT AS CON
    WHERE  PRO.PRO_UID = CON.CON_ID AND CON.CON_CATEGORY = 'PRO_TITLE' AND CON.CON_LANG = '@#LANG'
    ORDER BY CON.CON_VALUE ASC
    ]]><en><![CDATA[Process]]><option name=""><![CDATA[- Select a process -]]></option></en></COPY_PROCESS_UID>
  <COPY_TYPE type="dropdown" dependentfields="COPY_DYNAFORM_UID">
    <en><![CDATA[Showing forms of type]]><option name="xmlform"><![CDATA[Normal]]></option><option name="grid"><![CDATA[Grid]]></option></en>
  </COPY_TYPE>
  <COPY_DYNAFORM_UID type="dropdown" dependentfields="COPY_DYNAFORM_DESCRIPTION"><![CDATA[
    SELECT DYN.DYN_UID, CON.CON_VALUE
    FROM   DYNAFORM AS DYN, CONTENT AS CON
    WHERE  DYN.PRO_UID = '@#COPY_PROCESS_UID' AND DYN.DYN_TYPE = '@#COPY_TYPE' AND
           DYN.DYN_UID = CON.CON_ID AND CON.CON_CATEGORY = 'DYN_TITLE' AND CON.CON_LANG = '@#LANG'
    ORDER BY CON.CON_VALUE ASC
    ]]><en><![CDATA[Dynaform to copy/import]]><option name=""><![CDATA[- Select a dynaform -]]></option></en></COPY_DYNAFORM_UID>
  <COPY_DYNAFORM_TITLE type="text" size="48" maxlength="256" required="1">
    <en><![CDATA[Title of the new dynaform]]></en>
  </COPY_DYNAFORM_TITLE>
  <COPY_DYNAFORM_DESCRIPTION type="textarea" rows="8" cols="45"><![CDATA[
    SELECT CON.CON_VALUE
    FROM   CONTENT AS CON
    WHERE  CON.CON_ID = '@#COPY_DYNAFORM_UID' AND CON.CON_CATEGORY = 'DYN_DESCRIPTION' AND CON.CON_LANG = '@#LANG'
    ]]><en><![CDATA[Description of the new dynaform]]></en></COPY_DYNAFORM_DESCRIPTION>
  <BTNCOPYSAVE type="button" onclick="dynaformSave(this.form, false);">
    <en><![CDATA[Copy/Import]]></en>
  </BTNCOPYSAVE>
  <BTNCOPYSAVEOPEN type="button" onclick="dynaformSave(this.form, true);">
    <en><![CDATA[Copy/Import and Open]]></en>
  </BTNCOPYSAVEOPEN>
  <BTNCOPYCANCEL type="button" onclick="cancel();">
    <en><![CDATA[Cancel]]></en>
  </BTNCOPYCANCEL>
  <JS type="javascript"><![CDATA[
    function checkDynaformSource()
    {
        var action = "@#ACTION";

        switch (action) {
            case "pmtable":
                document.getElementById("pmtableform").style.display="";
                document.getElementById("pmtabledrop").style.display="";
                document.getElementById("normalform").style.display="none";
                //document.getElementById("form[DYN_TYPE]").value = "xmlform";
                break;
            case "copy":
                document.getElementById("title").style.display = "none";
                document.getElementById("description").style.display = "none";

                document.getElementById("form[TITLE]").innerHTML = "@G::LoadTranslation(ID_DYNAFORM_COPY)";
                document.getElementById("copyProcess").style.display = "";
                document.getElementById("copyType").style.display = "";
                document.getElementById("copyDynaform").style.display = "";
                document.getElementById("copyDynTitle").style.display = "";
                document.getElementById("copyDynDescription").style.display = "";
                document.getElementById("copyButton").style.display = "";
                break;
            default:
                //normal
                document.getElementById("normalform").style.display="";
                document.getElementById("normalformdrop").style.display="";
                document.getElementById("pmtableform").style.display="none";
                break;
        }

        /*
        if ("@#ACTION" == "normal"){
            hideRow("ADD_TABLE");
            hideRow("CONTINUE");
            hideRow("PROCESS_VARIABLES");
            hideRow("PRO_VAR_ASSIGN");
        } else {
            document.getElementById("form[DYN_TYPE]").value = "xmlform";
            hideRow("DYN_TYPE");
        }
        */
    }

    var cbocopyDynaformUid = getField("COPY_DYNAFORM_UID")
    var txtcopyDynTitle = getField("COPY_DYNAFORM_TITLE");

    leimnud.event.add(
        getField("COPY_PROCESS_UID"),
        "change",
        function ()
        {
            txtcopyDynTitle.value = "";
        }
    );

    leimnud.event.add(
        getField("COPY_TYPE"),
        "change",
        function ()
        {
            txtcopyDynTitle.value = "";
        }
    );

    leimnud.event.add(
        cbocopyDynaformUid,
        "change",
        function ()
        {
            txtcopyDynTitle.value = "";

            if (cbocopyDynaformUid.value != "") {
                txtcopyDynTitle.value = cbocopyDynaformUid.options[cbocopyDynaformUid.selectedIndex].text;
            }
        }
    );

    txtcopyDynTitle.form.onsubmit = function () { return false; };
    getField("DYN_TITLE").form.onsubmit = function () { return false; };

    checkDynaformSource();

leimnud.event.add(getField('DYN_TITLE'), 'blur', function()
{
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
document.getElementById('form[DYN_TITLE]').value = document.getElementById('form[DYN_TITLE]').value.trim();
});

  leimnud.event.add(document.getElementById('form[ADD_TABLE]'), 'change', setPMTableDynaformTitle);
  function setPMTableDynaformTitle(){
    if(document.getElementById('form[ADD_TABLE]').value!=''){
        document.getElementById('form[DYN_TITLE]').value = document.getElementById('form[ADD_TABLE]')[document.getElementById('form[ADD_TABLE]').selectedIndex].innerHTML;
    }
  }
  var oPanel;
  function assignVariables(){
    
    if ((document.getElementById('form[ADD_TABLE]').value.trim() != '') && (document.getElementById('form[DYN_TITLE]').value.trim() != '')) {
        table_uid = document.getElementById('form[ADD_TABLE]').value;
       	oPanel = new leimnud.module.panel();
      	oPanel.options = {
            limit    : true,
            size     : {w:450,h:350},
            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}
        };
        oPanel.make();
        oPanel.loader.show();

        var PRO_UID = document.getElementById('form[PRO_UID]').value;
        var DYN_UID = document.getElementById('form[DYN_UID]').value;
        var ADD_TABLE = document.getElementById('form[ADD_TABLE]').value;
        var DYN_TITLE = document.getElementById('form[DYN_TITLE]').value.trim();
        var DYN_TYPE = document.getElementById('form[DYN_TYPE]').value;
        var ACTION = document.getElementById('form[ACTION]').value;
        var DYN_DESCRIPTION = document.getElementById('form[DYN_DESCRIPTION]').value;

        oRPC = new leimnud.module.rpc.xmlhttp({
            url    : '../dynaforms/dynaforms_AssignVariables',
            method : 'POST',
            args   : 'PRO_UID=' + PRO_UID + '&DYN_UID=' + DYN_UID + '&ADD_TABLE=' + ADD_TABLE + '&DYN_TITLE=' + DYN_TITLE + '&DYN_TYPE=' + DYN_TYPE + '&DYN_DESCRIPTION=' + DYN_DESCRIPTION + '&ACTION=' + ACTION
        });
        
        oRPC.callback = function(oRPC) {
            oPanel.loader.hide();
            var scs = oRPC.xmlhttp.responseText.extractScript();
            oPanel.addContent(oRPC.xmlhttp.responseText);
            scs.evalScript();
        }.extend(this);
        oRPC.make();
        lastPopupWindow.remove();
    } else { 
      if (document.getElementById('form[ADD_TABLE]').value.trim() == '') {
        msgBox("@G::LoadTranslation(ID_PMTABLE_REQUIRED)", "alert");
        return false;
      } else {  
        msgBox("@G::LoadTranslation(ID_REQUIRED_NAME_DYNAFORM)", "alert");        
        return false;
      }
    }    
  }

  function cancel(){
    lastPopupWindow.remove();
  }

]]></JS>
</dynaForm>
