<?xml version="1.0" encoding="UTF-8"?>
<dynaForm name="events/eventsNew" type="xmlform" width="98%" labelwidth="200px" enabletemplate="1">
  <EVN_UID type="hidden"/>
  <PRO_UID type="hidden"/>
  <EVN_TYPE type="hidden"/>
  <TITLE type="title">
    <en><![CDATA[]]></en>
  </TITLE>
  <NOTE type="subtitle">
    <en><![CDATA[Event execution is related to the due date of the cases or the estimated duration if you select "Multiple Tasks"]]></en>
  </NOTE>
  <EVN_DESCRIPTION type="text" size="36" maxlength="255" required="1">
    <en><![CDATA[Description]]></en>
  </EVN_DESCRIPTION>
  <EVN_STATUS type="dropdown" required="0">
    <en><![CDATA[Status]]><option name="ACTIVE"><![CDATA[Active]]></option><option name="INACTIVE"><![CDATA[Inactive]]></option></en>
  </EVN_STATUS>
  <SUBTITLE1 type="subtitle">
    <en><![CDATA[Behaviour]]></en>
  </SUBTITLE1>
  <EVN_WHEN_OCCURS type="dropdown" required="0">
    <en><![CDATA[Execution time]]><option name="AFTER_TIME"><![CDATA[After interval ends]]></option><option name="TASK_STARTED"><![CDATA[After interval starts]]></option></en>
  </EVN_WHEN_OCCURS>
  <EVN_RELATED_TO type="dropdown" required="0">
    <en><![CDATA[Type]]><option name="SINGLE"><![CDATA[Single Task]]></option><option name="MULTIPLE"><![CDATA[Multiple Tasks]]></option></en>
  </EVN_RELATED_TO>
  <TAS_UID type="dropdown" sqlconnection="dbarray" required="1">
SELECT TAS_UID, TAS_TITLE FROM tasks
  <en><![CDATA[The time starts with task]]></en>
</TAS_UID>
  <EVN_TAS_UID_FROM type="dropdown" sqlconnection="dbarray" required="0">
SELECT TAS_UID, TAS_TITLE FROM tasks
  <en><![CDATA[The time starts from task]]></en>
</EVN_TAS_UID_FROM>
  <EVN_TAS_UID_TO type="dropdown" sqlconnection="dbarray" required="0">
SELECT TAS_UID, TAS_TITLE FROM tasks
  <en><![CDATA[To]]></en>
</EVN_TAS_UID_TO>
  <EVN_TAS_ESTIMATED_DURATION type="text" size="4" maxlength="4" validate="Real" required="1" defaultvalue="1">
    <en><![CDATA[Estimated Task duration]]></en>
  </EVN_TAS_ESTIMATED_DURATION>
  <EVN_TIME_UNIT type="dropdown" required="1">
    <en><![CDATA[]]><option name="DAYS"><![CDATA[Days]]></option><option name="HOURS"><![CDATA[Hours]]></option></en>
  </EVN_TIME_UNIT>
  <EVN_WHEN type="text" size="4" maxlength="4" validate="Real" required="1" defaultvalue="1">
    <en><![CDATA[days]]></en>
  </EVN_WHEN>
  <TITLE2 type="title">
    <en><![CDATA[Action]]></en>
  </TITLE2>
  <EVN_CONDITIONS type="textarea" rows="2" cols="32" required="1">
    <en><![CDATA[Condition]]></en>
  </EVN_CONDITIONS>
  <EVN_ACTION type="dropdown" required="0" style="display:none">
    <en><![CDATA[Execute trigger]]><option name="SEND_MESSAGE"><![CDATA[Message]]></option><option name="EXECUTE_CONDITIONAL_TRIGGER"><![CDATA[Conditional]]></option><option name="EXECUTE_TRIGGER"><![CDATA[Multiple]]></option></en>
  </EVN_ACTION>
  <TRI_UID type="dropdown" required="0" sqlconnection="dbarray">
  SELECT * FROM TMP_TRIGGERS
  <en><![CDATA[]]><option name=""><![CDATA[Create a new trigger]]></option></en>
</TRI_UID>
  <TITLE3 type="title">
    <en><![CDATA[Event scheduled graph]]></en>
  </TITLE3>
  <BTN_CANCEL type="button" onclick="cancel();">
    <en><![CDATA[Cancel]]></en>
  </BTN_CANCEL>
  <CONTINUE type="button" onclick="eventsNewAction(this.form);">
    <en><![CDATA[Continue]]></en>
  </CONTINUE>
  <JS type="JavaScript"><![CDATA[

var onChangeRelatedTo = function() {
  onGraphChange ();
  if (getField('EVN_RELATED_TO').value == 'SINGLE') {
    hideRowById('EVN_TAS_UID_FROM');
    hideRowById('EVN_TAS_UID_TO');
    showRowById('TAS_UID');
  }
  else {
    hideRowById('TAS_UID');
    showRowById('EVN_TAS_UID_FROM');
    showRowById('EVN_TAS_UID_TO');
    showRowById('EVN_TAS_ESTIMATED_DURATION');
    enableRequiredById('EVN_TAS_ESTIMATED_DURATION');
  }
};

var onGraphChange = function(oForm) {
  oRelatedTo  = getField('EVN_RELATED_TO');
  oWhenOccurs = getField('EVN_WHEN_OCCURS');
  oStatus     = getField('EVN_STATUS');
  oWhen       = getField('EVN_WHEN');
  timeUnit    = getField('EVN_TIME_UNIT');
  oEstimated  = getField('EVN_TAS_ESTIMATED_DURATION');

  query = "";
  if ( oRelatedTo.value == 'SINGLE' )
    query = "?t=s";
  else
    query = "?t=m";

  if ( oWhenOccurs.value == 'TASK_STARTED' )
    query = query + "&o=s";
  else
    query = query + "&o=a";
  if ( oStatus.value == 'ACTIVE' )
    query = query + "&s=a";
  else
    query = query + "&s=i";

  query = query + "&w=" + oWhen.value;
  query = query + "&e=" + oEstimated.value;
  query = query + "&t=" + timeUnit.value;

  var x = document.getElementsByName('theImage');
  x[0].src = '../events/eventsSetupGraph'+query;
};

leimnud.event.add(getField('EVN_RELATED_TO'), 'change', onChangeRelatedTo);

leimnud.event.add(getField('EVN_WHEN_OCCURS'), 'change', onGraphChange);
leimnud.event.add(getField('EVN_WHEN'), 'keyup', onGraphChange);
leimnud.event.add(getField('EVN_STATUS'), 'change', onGraphChange);
leimnud.event.add(getField('EVN_TIME_UNIT'), 'change', onGraphChange);
leimnud.event.add(getField('EVN_TAS_ESTIMATED_DURATION'), 'keyup', onGraphChange);

onChangeRelatedTo();


//alert(getField('EVN_ACTION').value);

getField('TITLE').innerHTML = 'Event '+ getField('EVN_ACTION').options[getField('EVN_ACTION').selectedIndex].text;

if(getField('EVN_ACTION').value != 'SEND_MESSAGE'){
  showRowById('EVN_ACTION');
} else {
  hideRowById('EVN_ACTION');
}
if(getField('EVN_ACTION').value == 'EXECUTE_CONDITIONAL_TRIGGER'){
  showRowById('EVN_CONDITIONS');
} else {
  hideRowById('EVN_CONDITIONS');
}



getField('EVN_DESCRIPTION').focus();

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

]]></JS>
</dynaForm>
