<?xml version="1.0" encoding="UTF-8"?>
<dynaForm name="processes_NewObjectPermission" width="100%" enableTemplate="1">
<TITLE type="title">
  <en>New Specific Permission</en>
</TITLE>
<LANG type="private"/>
<PRO_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>
  </en>
</OP_ACTION>

<BTN_CANCEL type="button" onclick="cancel();">
  <en>Cancel</en>
</BTN_CANCEL>

<CREATE type="button" onclick="saveObjectPermission(this.form);">
  <en>Create</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++) {
    aOptions.push({label:oAux.options[i].text, value: oAux.options[i].value});
  }
};
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;
  }
};
leimnud.event.add(getField('OP_OBJ_TYPE'), 'change', function() {
  var vValue = getField('OP_OBJ_TYPE').value;
  switch (vValue) {
    case 'ANY':
    case 'ANY_DYNAFORM':
    case 'ANY_INPUT':
    case 'ANY_OUTPUT':
      getField('ALL').value = '';
      getField('DYNAFORMS').value = '';
      getField('INPUTS').value = '';
      getField('OUTPUTS').value = '';
      hideRowById('ALL');
      hideRowById('DYNAFORMS');
      hideRowById('INPUTS');
      hideRowById('OUTPUTS');
      showRowById('OP_ACTION');
    break;
    case 'DYNAFORM':
      getField('ALL').value = '';
      getField('DYNAFORMS').value = (getField('DYNAFORMS').options[0] ? getField('DYNAFORMS').options[0].value : '');
      getField('INPUTS').value = '';
      getField('OUTPUTS').value = '';
      hideRowById('ALL');
      showRowById('DYNAFORMS');
      hideRowById('INPUTS');
      hideRowById('OUTPUTS');
      showRowById('OP_ACTION');
    break;
    case 'INPUT':
      getField('ALL').value = '';
      getField('DYNAFORMS').value = '';
      getField('INPUTS').value = (getField('INPUTS').options[0] ? getField('INPUTS').options[0].value : '');
      getField('OUTPUTS').value = '';
      hideRowById('ALL');
      hideRowById('DYNAFORMS');
      showRowById('INPUTS');
      hideRowById('OUTPUTS');
      showRowById('OP_ACTION');
    break;
    case 'OUTPUT':
      getField('ALL').value = '';
      getField('DYNAFORMS').value = '';
      getField('INPUTS').value = '';
      getField('OUTPUTS').value = (getField('OUTPUTS').options[0] ? getField('OUTPUTS').options[0].value : '');
      hideRowById('ALL');
      hideRowById('DYNAFORMS');
      hideRowById('INPUTS');
      showRowById('OUTPUTS');
      showRowById('OP_ACTION');
    break;
    case 'CASES_NOTES':
    /*----------------------------------********---------------------------------*/
    case 'SUMMARY_FORM':
    /*----------------------------------********---------------------------------*/
      getField('ALL').value = '';
      getField('DYNAFORMS').value = '';
      getField('INPUTS').value = '';
      getField('OUTPUTS').value = '';
      getField('OP_ACTION').value = 'VIEW';
      hideRowById('ALL');
      hideRowById('DYNAFORMS');
      hideRowById('INPUTS');
      hideRowById('OUTPUTS');
      hideRowById('OP_ACTION');
    break;
    case 'MSGS_HISTORY':
      getField('ALL').value = '';
      getField('DYNAFORMS').value = '';
      getField('INPUTS').value = '';
      getField('OUTPUTS').value = (getField('OUTPUTS').options[0] ? getField('OUTPUTS').options[0].value : '');
      hideRowById('ALL');
      hideRowById('DYNAFORMS');
      hideRowById('INPUTS');
      hideRowById('OUTPUTS');
      showRowById('OP_ACTION');
    break;
  }
  rebuildOptions(vValue);
});
var vValue = getField('OP_OBJ_TYPE').value;
switch (vValue) {
  case 'ANY':
  case 'ANY_DYNAFORM':
  case 'ANY_INPUT':
  case 'ANY_OUTPUT':
    getField('ALL').value = '';
    getField('DYNAFORMS').value = '';
    getField('INPUTS').value = '';
    getField('OUTPUTS').value = '';
    hideRowById('ALL');
    hideRowById('DYNAFORMS');
    hideRowById('INPUTS');
    hideRowById('OUTPUTS');
    showRowById('OP_ACTION');
  break;
  case 'DYNAFORM':
    getField('ALL').value = '';
    getField('DYNAFORMS').value = (getField('DYNAFORMS').options[0] ? getField('DYNAFORMS').options[0].value : '');
    getField('INPUTS').value = '';
    getField('OUTPUTS').value = '';
    hideRowById('ALL');
    showRowById('DYNAFORMS');
    hideRowById('INPUTS');
    hideRowById('OUTPUTS');
    showRowById('OP_ACTION');
  break;
  case 'INPUT':
    getField('ALL').value = '';
    getField('DYNAFORMS').value = '';
    getField('INPUTS').value = (getField('INPUTS').options[0] ? getField('INPUTS').options[0].value : '');
    getField('OUTPUTS').value = '';
    hideRowById('ALL');
    hideRowById('DYNAFORMS');
    hideRowById('INPUTS');
    showRowById('OUTPUTS');
    showRowById('OP_ACTION');
  break;
  case 'OUTPUT':
    getField('ALL').value = '';
    getField('DYNAFORMS').value = '';
    getField('INPUTS').value = '';
    getField('OUTPUTS').value = (getField('OUTPUTS').options[0] ? getField('OUTPUTS').options[0].value : '');
    hideRowById('ALL');
    hideRowById('DYNAFORMS');
    hideRowById('INPUTS');
    showRowById('OUTPUTS');
    showRowById('OP_ACTION');
  break;
  case 'CASES_NOTES':
  /*----------------------------------********---------------------------------*/
  case 'SUMMARY_FORM':
  /*----------------------------------********---------------------------------*/
      getField('ALL').value = '';
      getField('DYNAFORMS').value = '';
      getField('INPUTS').value = '';
      getField('OUTPUTS').value = '';
      getField('OP_ACTION').value = 'VIEW';
      hideRowById('ALL');
      hideRowById('DYNAFORMS');
      hideRowById('INPUTS');
      hideRowById('OUTPUTS');
      hideRowById('OP_ACTION');
    break;
}
getOptions();
rebuildOptions(vValue);

/*
var dynaformOnload = function()
{ var oAux = document.getElementById('form[TASKS]');
	if(document.getElementById('form[PROCESS]').value=='')
  	hideRowById(oAux);
  else
  	showRowById(oAux);
};
*/
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);
  }
});

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

]]></JS>
</dynaForm>