<?xml version="1.0" encoding="UTF-8"?>
<dynaForm type="xmlmenu">
  <PRO_UID type="private"/>
  <cases_New type="private" defaultValue="../cases/cases_New"/>
  <cases_Edit type="private" defaultValue="../cases/cases_Edit"/>
  <cases_Open type="private" defaultValue="../cases/cases_Open"/>
  <cases_Delete type="private" defaultValue="../cases/cases_Delete"/>
  <PAGED_TABLE_ID type="private"/>
  <!-- Default Search option -->
  <PROCESS_FILTER type="dropdown" colWidth="350" sqlconnection="dbarray" colAlign="left">
    select PRO_UID, APP_PRO_TITLE from _PROCESSES
    <en><![CDATA[Process]]><option name="0"><![CDATA[All]]></option></en>
</PROCESS_FILTER>
  <READ_FILTER type="link" link="#" onclick="javascript:applyAdditionalFilter('READ'); return false" value="" colWidth="2%" colAlign="bottom">
    <en><![CDATA[Read]]></en>
  </READ_FILTER>
  <UNREAD_FILTER type="link" link="#" onclick="javascript:applyAdditionalFilter('UNREAD'); return false" value="" colWidth="2%" colAlign="bottom">
    <en><![CDATA[Unread]]></en>
  </UNREAD_FILTER>
  <ALL_FILTER type="link" link="#" onclick="javascript:applyAdditionalFilter('ALL'); return false" value="" colWidth="2%" colAlign="bottom">
    <en><![CDATA[All]]></en>
  </ALL_FILTER>
  <SEARCH_FILTER_FORM type="private"/>
  <!--<MNU_NEW type="link" label="@G::LoadTranslation(ID_START_CASE)" value='' link="@G::encryptLink(@#cases_New)" colAlign="left" colWidth="85"/>-->
  <PAGED_TABLE_ID type="private"/>
  <PAGED_TABLE_FAST_SEARCH type="FastSearch" label=""/>
  <MNU_FAST_SEARCH type="button" label="@G::LoadTranslation(ID_SEARCH)" colAlign="right" colWidth="50" onclick="@#PAGED_TABLE_ID.doFastSearch(getField('PAGED_TABLE_FAST_SEARCH',this.form).value);"/>
  <PAGED_TABLE_JUMP type="text" colAlign="right" colWidth="80" size="4" maxlength="5" label=""/>
  <MNU_JUMP type="button" label="@G::LoadTranslation(ID_JUMP)" colAlign="right" colWidth="50" onclick="Jump()"/>
  <!--<MNU_SEARCH type="link" value='' link="#" onclick="showHideSearch('@#SEARCH_FILTER_FORM',this); return false;" colAlign="right" colWidth="130">
  <en>Advanced Search</en>
</MNU_SEARCH>-->
  <JS type="javascript"><![CDATA[
param = getURLParam("filter");
selectionHighlight(param);

function getURLParam(strParamName){
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("&") > -1 ){
        var strQueryString = strHref.substr(strHref.indexOf("&")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
            if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
    return strReturn;
}

function casesDelete(app) {
  ajax_function('cases_Delete','','APP_UID='+encodeURIComponent(app));
  @#PAGED_TABLE_ID.refresh();
}

var cancelCase = function(sUID, iIndex) {
  new leimnud.module.app.confirm().make({
    label : G_STRINGS.ID_CONFIRM_CANCEL_CASE,
    action: function() {
      var oRPC = new leimnud.module.rpc.xmlhttp({
        url:  'cases_Ajax',
        args: 'action=cancelCase&amp;sApplicationUID=' + sUID + '&amp;iIndex=' + iIndex
      });
      oRPC.callback = function(oRPC) {
        @#PAGED_TABLE_ID.refresh();
      }.extend(this);
      oRPC.make();
    }.extend(this)
  });
};

var pauseCase = function(sUID, iIndex)
{
  new leimnud.module.app.confirm().make({
    label : G_STRINGS.ID_CONFIRM_PAUSE_CASE,
    action: function() {
      var oRPC = new leimnud.module.rpc.xmlhttp({
        url:  'cases_Ajax',
        args: 'action=pauseCase&amp;sApplicationUID=' + sUID + '&amp;iIndex=' + iIndex
      });
      oRPC.callback = function(oRPC) {
        @#PAGED_TABLE_ID.refresh();
      }.extend(this);
      oRPC.make();
    }.extend(this)
  });
};

var reactivateCase = function(sUID, iIndex) {
  new leimnud.module.app.confirm().make({
    label : G_STRINGS.ID_MSG_CONFIRM_REACTIVATE_CASES,
    action: function() {
      var oRPC = new leimnud.module.rpc.xmlhttp({
        url:  'cases_Ajax',
        args: 'action=reactivateCase&amp;sApplicationUID=' + sUID + '&amp;iIndex=' + iIndex
      });
      oRPC.callback = function(oRPC) {
        @#PAGED_TABLE_ID.refresh();
      }.extend(this);
      oRPC.make();
    }.extend(this)
  });
};

var unpauseCase = function(sUID, iIndex)
{
  new leimnud.module.app.confirm().make({
    label : G_STRINGS.ID_CONFIRM_UNPAUSE_CASE,
    action: function() {
      var oRPC = new leimnud.module.rpc.xmlhttp({
        url:  'cases_Ajax',
        args: 'action=unpauseCase&amp;sApplicationUID=' + sUID + '&amp;iIndex=' + iIndex
      });
      oRPC.callback = function(oRPC) {
        @#PAGED_TABLE_ID.refresh();
      }.extend(this);
      oRPC.make();
    }.extend(this)
  });
};

getField("PAGED_TABLE_JUMP").onkeypress = function(event) {
  event = window.event ? window.event : event;
  if (event.keyCode===13) Jump();
};

function Jump(){
  window.location.href='@#cases_Open?APP_NUMBER='+encodeURIComponent(getField('PAGED_TABLE_JUMP').value)+"&content=inner";
}

// Additional filter -- By Erik
leimnud.event.add(getField('PROCESS_FILTER'), 'change', function() {
    loc = new String(window.location);
    tmp = (loc.indexOf('&') != -1 )? loc.indexOf('&'): loc.length;
    uri = loc.substring(0, tmp); 
    
    if(uri.indexOf('?l=to_do')==-1) uri=uri+'?l=to_do';
    
	document.location.href =  uri + '&PROCESS_UID='+this.value+'&r='+Math.floor(Math.random()*999999);
}.extend(getField('PROCESS_FILTER')));

function selectionHighlight(filter) {
    switch (param.toUpperCase()) {
    case 'READ'  :  getField("READ_FILTER").style.fontWeight = 'bold';
                    getField("UNREAD_FILTER").style.fontWeight = 'normal';
                    getField("ALL_FILTER").style.fontWeight = 'normal';
                    break;
    case 'UNREAD':  getField("READ_FILTER").style.fontWeight = 'normal';
                    getField("UNREAD_FILTER").style.fontWeight = 'bold';
                    getField("ALL_FILTER").style.fontWeight = 'normal';
                    break;
    case 'ALL'   :  getField("READ_FILTER").style.fontWeight = 'normal';
                    getField("UNREAD_FILTER").style.fontWeight = 'normal';
                    getField("ALL_FILTER").style.fontWeight = 'bold';
                    break;
    default      :  getField("READ_FILTER").style.fontWeight = 'normal';
                    getField("UNREAD_FILTER").style.fontWeight = 'normal';
                    getField("ALL_FILTER").style.fontWeight = 'bold';
                    break;
    }
}

function applyAdditionalFilter(filter){
    selectionHighlight(filter);
    loc = new String(window.location);
    tmp = (loc.indexOf('&') != -1 )? loc.indexOf('&'): loc.length;
    uri = loc.substring(0, tmp);
    
    location.href = uri + '&PROCESS_UID='+getField('PROCESS_FILTER').value + '&' + filter + '=1'+'&r='+Math.floor(Math.random()*999999) + '&filter=' + filter;
}

]]></JS>
</dynaForm>
