<?xml version="1.0" encoding="UTF-8"?>
<dynaForm name="processes_EditObjectPermission" width="100%" enableTemplate="1">
<TITLE type="title">
  <en>Edit Specific Permission</en>
</TITLE>
<LANG type="private"/>
<PRO_UID type="hidden"/>
<OP_UID type="hidden"/>

<OP_CASE_STATUS type="dropdown" mode="edit">
  <en>Status Case
  <option name="ALL">All</option>
  <option name="DRAFT">Draft</option>
  <option name="TO_DO">To Do</option>
  <option name="PAUSED">Paused</option>
  <option name="COMPLETED">Completed</option>
  </en>
</OP_CASE_STATUS>

<TAS_UID type="dropdown" mode="edit">
  <![CDATA[SELECT TAS_UID, CON_VALUE AS TAS_TITLE FROM TASK LEFT JOIN CONTENT ON (TAS_UID = CON_ID AND CON_CATEGORY = 'TAS_TITLE' AND CON_LANG = @@LANG) WHERE PRO_UID = @@PRO_UID AND TAS_TYPE = 'NORMAL' ORDER BY TAS_TITLE]]>
  <en>Target Task
    <option name="">All Tasks</option>
  </en>
</TAS_UID>

<GROUP_USER type="text" mode="view">
  <en>Group or User</en>
</GROUP_USER>

<GROUP_USER_DROPDOWN type="title" mode="view" enableHtml="1" label="@#GROUP_USER" />

<OP_TASK_SOURCE type="dropdown" mode="edit">
  <![CDATA[SELECT TAS_UID, CON_VALUE AS TAS_TITLE FROM TASK LEFT JOIN CONTENT ON (TAS_UID = CON_ID AND CON_CATEGORY = 'TAS_TITLE' AND CON_LANG = @@LANG) WHERE PRO_UID = @@PRO_UID AND TAS_TYPE = 'NORMAL' ORDER BY TAS_TITLE]]><en>Origin Task<option name="">All Tasks</option></en>
</OP_TASK_SOURCE>

<OP_PARTICIPATE type="yesno" defaultvalue="1" mode="edit">
  <en>Participation required?</en>
</OP_PARTICIPATE>
<OP_OBJ_TYPE type="dropdown" mode="edit" dependentfields="OP_OBJ_UID">
  <en>Type
    <option name="ANY">All</option>
    <option name="DYNAFORM">Dynaform</option>
    <option name="INPUT">Input Document</option>
    <option name="OUTPUT">Output Document</option>
    <option name="CASES_NOTES">Cases Notes</option>
    <option name="MSGS_HISTORY">Messages History</option>
    <!--//////////////////////////////////********//////////////////////////////////-->
    <option name="SUMMARY_FORM">Summary Form</option>
    <!--//////////////////////////////////********//////////////////////////////////-->
  </en>
</OP_OBJ_TYPE>
<ALL type="dropdown" mode="edit" sqlConnection="dbarray">
  SELECT * FROM allObjects
  <en>Object
    <option name="">All</option>
  </en>
</ALL>
<DYNAFORMS type="dropdown" mode="edit" sqlConnection="dbarray">
  SELECT * FROM allDynaforms
  <en>DynaForm<option name="">All</option></en>
</DYNAFORMS>
<INPUTS type="dropdown" mode="edit" sqlConnection="dbarray">
  SELECT * FROM allInputs
  <en>Input Document<option name="">All</option></en>
</INPUTS>
<OUTPUTS type="dropdown" mode="edit" sqlConnection="dbarray">
  SELECT * FROM allOutputs
  <en>Output Document<option name="">All</option></en>
</OUTPUTS>
<OP_ACTION type="dropdown" mode="edit">
  <en>Permission
      <option name="VIEW">View</option>
      <option name="BLOCK">Block</option>
      <option name="DELETE">Delete</option>
      <option name="RESEND">Resend</option>
  </en>
</OP_ACTION>

<CREATE type="button" onclick="saveObjectPermission(this.form);">
  <en>Save</en>
</CREATE>
<ID_DELETE type="private"/>
<ID_RESEND type="private"/>
<JS type="javascript"><![CDATA[
var aOptions = [];
var getOptions = function() {
    var oAux = getField('OP_ACTION');
    for (var i = 0; i < oAux.options.length; i++) {
    if (oAux.options[i].value != 'DELETE' && oAux.options[i].value != 'RESEND') {
            aOptions.push({label:oAux.options[i].text, value: oAux.options[i].value});
        }
    }
};
var rebuildOptionsWhenLoad = function(sType) {
    var selectedValue = getField('OP_ACTION').value;
    var oAux = getField('OP_ACTION');
    while (oAux.options.length) {
        oAux.remove(0);
    }
    for (var i = 0; i < aOptions.length; i++) {
        var oOption = document.createElement('OPTION');
        oOption.value = aOptions[i].value;
        oOption.text = aOptions[i].label;
        if (oOption.value == selectedValue) {
          oOption.selected = true;
        }
        oAux.options.add(oOption);
    }

    switch (sType) {
        case 'INPUT':
        case 'OUTPUT':
            var oOption = document.createElement('OPTION');
            oOption.value = 'DELETE';
            oOption.text = '@#ID_DELETE';
            if (oOption.value == selectedValue) {
              oOption.selected = true;
            }
            oAux.options.add(oOption);
        break;
        case 'MSGS_HISTORY':
            var oOption = document.createElement('OPTION');
            oOption.value = 'RESEND';
            oOption.text = '@#ID_RESEND';
            if (oOption.value == selectedValue) {
              oOption.selected = true;
            }
            oAux.options.add(oOption);
        break;
        default:
        break;
    }

    oAux.value = selectedValue;
};
var rebuildOptions = function(sType) {
    var oAux = getField('OP_ACTION');
    while (oAux.options.length) {
        oAux.remove(0);
    }
    for (var i = 0; i < aOptions.length; i++) {
        var oOption = document.createElement('OPTION');
        oOption.value = aOptions[i].value;
        oOption.text = aOptions[i].label;
        oAux.options.add(oOption);
    }

    switch (sType) {
        case 'INPUT':
        case 'OUTPUT':
            var oOption = document.createElement('OPTION');
            oOption.value = 'DELETE';
            oOption.text = '@#ID_DELETE';
            oAux.options.add(oOption);
        break;
        case 'MSGS_HISTORY' :
            var oOption = document.createElement('OPTION');
            oOption.value = 'RESEND';
            oOption.text = '@#ID_RESEND';
            oAux.options.add(oOption);
        break;
        default:
        break;
    }

};
if (getField('OP_OBJ_TYPE').value=='ANY') {
    hideRowById('ALL' );
    hideRowById( 'DYNAFORMS' );
    hideRowById( 'INPUTS' );
    hideRowById( 'OUTPUTS' );
    showRowById( 'OP_ACTION' );
}
if (getField('OP_OBJ_TYPE').value=='DYNAFORM') {
    hideRowById( 'ALL' );
    hideRowById( 'INPUTS' );
    hideRowById( 'OUTPUTS' );
    showRowById( 'OP_ACTION' );
}
if (getField('OP_OBJ_TYPE').value=='INPUT') {
    hideRowById( 'ALL' );
    hideRowById( 'DYNAFORMS' );
    hideRowById( 'OUTPUTS' );
    showRowById( 'OP_ACTION' );
}
if (getField('OP_OBJ_TYPE').value=='OUTPUT') {
    hideRowById( 'ALL' );
    hideRowById( 'DYNAFORMS' );
    hideRowById( 'INPUTS' );
    showRowById( 'OP_ACTION' );
}
if (getField('OP_OBJ_TYPE').value=='CASES_NOTES' 
/*----------------------------------********---------------------------------*/
|| getField('OP_OBJ_TYPE').value=='SUMMARY_FORM')
/*----------------------------------********---------------------------------*/
{
    hideRowById( 'ALL' );
    hideRowById( 'DYNAFORMS' );
    hideRowById( 'INPUTS' );
    hideRowById( 'OUTPUTS' );
    hideRowById( 'OP_ACTION' );
}
if (getField('OP_OBJ_TYPE').value=='MSGS_HISTORY') {
    hideRowById('ALL');
    hideRowById('DYNAFORMS');
    hideRowById('INPUTS');
    hideRowById('OUTPUTS');
    showRowById('OP_ACTION');
}

getOptions();
rebuildOptionsWhenLoad(getField('OP_OBJ_TYPE').value);

leimnud.event.add(document.getElementById('form[OP_OBJ_TYPE]'), 'change', function() {
    if (getField('OP_OBJ_TYPE').value=='DYNAFORM') {
        hideRowById( 'ALL' );
        hideRowById( 'INPUTS' );
        hideRowById( 'OUTPUTS' );
        showRowById( 'DYNAFORMS' );
        showRowById( 'OP_ACTION' );
    }
    if (getField('OP_OBJ_TYPE').value=='INPUT') {
        hideRowById( 'ALL' );
        hideRowById( 'DYNAFORMS' );
        hideRowById( 'OUTPUTS' );
        showRowById( 'INPUTS' );
        showRowById( 'OP_ACTION' );
    }
    if (getField('OP_OBJ_TYPE').value=='OUTPUT') {
        hideRowById( 'ALL' );
        hideRowById( 'DYNAFORMS' );
        hideRowById( 'INPUTS' );
        showRowById( 'OUTPUTS' );
        showRowById( 'OP_ACTION' );
    }
    if (getField('OP_OBJ_TYPE').value=='CASES_NOTES' 
    /*----------------------------------********---------------------------------*/
    || getField('OP_OBJ_TYPE').value=='SUMMARY_FORM')
    /*----------------------------------********---------------------------------*/
    {
        hideRowById( 'ALL' );
        hideRowById( 'DYNAFORMS' );
        hideRowById( 'INPUTS' );
        hideRowById( 'OUTPUTS' );
        hideRowById( 'OP_ACTION' );
    }
    if (getField('OP_OBJ_TYPE').value=='ANY') {
        hideRowById('ALL' );
        hideRowById( 'DYNAFORMS' );
        hideRowById( 'INPUTS' );
        hideRowById( 'OUTPUTS' );
        showRowById( 'OP_ACTION' );
    }
    if (getField('OP_OBJ_TYPE').value=='MSGS_HISTORY') {
        hideRowById('ALL');
        hideRowById('DYNAFORMS');
        hideRowById('INPUTS');
        hideRowById('OUTPUTS');
        showRowById('OP_ACTION');
    }

    rebuildOptions(getField('OP_OBJ_TYPE').value);
});

leimnud.event.add(document.getElementById('form[OP_CASE_STATUS]'), 'change', function() {
    var target = document.getElementById('form[TAS_UID]');
    var origin = document.getElementById('form[OP_TASK_SOURCE]');
    var participate = document.getElementById('form[OP_PARTICIPATE]');
    if (document.getElementById('form[OP_CASE_STATUS]').value=='COMPLETED') {
        hideRowById(target);
        hideRowById(origin);
        hideRowById(participate);
    } else {
        showRowById(target);
        showRowById(origin);
        showRowById(participate);
    }
});

]]></JS>
</dynaForm>
