<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="condition.aspx.cs" Inherits="view.flow.condition" %>

<html><head>
  <meta http-equiv="X-UA-Compatible"content="IE=EmulateIE7"/>
  <meta http-equiv="Content-Type" content='text/html; charset=utf-8' />
  <title>workflow condition</title>
  <link href='../skin/view.css' type='text/css' rel='stylesheet'>
  <script language=javascript>document.write("<script type='text/javaScript' src='../common/view"+location.search.substring(location.search.indexOf("&lang=")+6)+".js'><\/script>");</script>
  <script type='text/javascript' src='../common/view.js'></script>
</head>

<body scroll=no>
<div style='margin:10px 10px 0px 10px;'>
<script language=javaScript>document.write(translate['condition']);</script>① <select style="width:150px;" id=oConditionF1 runat=server></select><select style="width:80px;" id=oConditionO1><option>&gt;</option><option>&gt;=</option><option>==</option><option>&lt;</option><option>&lt;=</option></select><input type=text id=oConditionV1 onkeypress='if(event.keyCode==34) return false;'>
<br><script language=javaScript>document.write(translate['condition']);</script>② <select style="width:150px;" id=oConditionF2 runat=server></select><select style="width:80px;" id=oConditionO2><option>&gt;</option><option>&gt;=</option><option>==</option><option>&lt;</option><option>&lt;=</option></select><input type=text id=oConditionV2 onkeypress='if(event.keyCode==34) return false;'>
<br><script language=javaScript>document.write(translate['condition']);</script>③ <select style="width:150px;" id=oConditionF3 runat=server></select><select style="width:80px;" id=oConditionO3><option>&gt;</option><option>&gt;=</option><option>==</option><option>&lt;</option><option>&lt;=</option></select><input type=text id=oConditionV3 onkeypress='if(event.keyCode==34) return false;'>
<br><script language=javaScript>document.write(translate['condition']);</script>④ <select style="width:150px;" id=oConditionFUser><option><script language=javaScript>document.write(translate['userRoles']);</script></option></select><select style="width:80px;" id=oConditionOUser><option><script language=javaScript>document.write(translate['belongTo']);</script></option></select><input type=text id=oConditionVUser onkeypress='if(event.keyCode==34) return false;'>
<br><script language=javaScript>document.write(translate['condition']);</script>⑤ function checkCondition()
<br><textarea style='width:460px;height:285px;line-height:1.5;' id=oCondition onkeypress='if(event.keyCode==34) return false;'></textarea>
</div>
<script language=javaScript>
    workflowActionsShow('okCancel');
    var sSource = dialogArguments.value.replace(new RegExp('<br>', 'g'), '\r\n');
    var sSeperator = '\r\n/*//*/\r\n';
    var nSeperator = sSource.indexOf(sSeperator);
    document.getElementById('oCondition').value = nSeperator > 0 ? sSource.substr(nSeperator + sSeperator.length) : sSource;
    if(nSeperator > 0)
    {
        var nLengthOfField = oConditionF1.options.length;
        var nLengthOfOp = oConditionO1.options.length;
        sSource = sSource.substr(0, nSeperator);
        var aSourceTop = sSource.split(' && ');
        var aSource = aSourceTop[0].split(' ');
        if (aSource.length == 3) {
            for (var i = 0; i < nLengthOfField; i++) {
                if (oConditionF1.options[i].innerText == aSource[0])
                { oConditionF1.options[i].selected = true; break; }
            }
            for (var i = 0; i < nLengthOfOp; i++) {
                if (oConditionO1.options[i].innerText == aSource[1])
                { oConditionO1.options[i].selected = true; break; }
            }
            document.getElementById('oConditionV1').value = aSource[2];
        }
        var aSource = aSourceTop[1].split(' ');
        if (aSource.length == 3) {
            for (var i = 0; i < nLengthOfField; i++) {
                if (oConditionF2.options[i].innerText == aSource[0])
                { oConditionF2.options[i].selected = true; break; }
            }
            for (var i = 0; i < nLengthOfOp; i++) {
                if (oConditionO2.options[i].innerText == aSource[1])
                { oConditionO2.options[i].selected = true; break; }
            }
            document.getElementById('oConditionV2').value = aSource[2];
        }
        aSource = aSourceTop[2].split(' ');
        if (aSource.length == 3) {
            for (var i = 0; i < nLengthOfField; i++) {
                if (oConditionF3.options[i].innerText == aSource[0])
                { oConditionF3.options[i].selected = true; break; }
            }
            for (var i = 0; i < nLengthOfOp; i++) {
                if (oConditionO3.options[i].innerText == aSource[1])
                { oConditionO3.options[i].selected = true; break; }
            }
            document.getElementById('oConditionV3').value = aSource[2];
        }
        document.getElementById('oConditionVUser').value = aSourceTop[3];
    }
    function onActionBefore(nActionId, sName, bPostForm) {
        if (nActionId > 0) {
            var sConditionV1 = document.getElementById('oConditionV1').value.replace(/(^\s*)|(\s*$)/g, "");
            var sConditionV2 = document.getElementById('oConditionV2').value.replace(/(^\s*)|(\s*$)/g, "");
            var sConditionV3 = document.getElementById('oConditionV3').value.replace(/(^\s*)|(\s*$)/g, "");
            var sConditionVUser = document.getElementById('oConditionVUser').value.replace(/(^\s*)|(\s*$)/g, "");
            var sCondition = document.getElementById('oCondition').value.replace(/(^\s*)|(\s*$)/g, "");
            if(sConditionV1.length == 0 && sConditionV2.length == 0 && sConditionV3.length == 0 && sConditionVUser.length == 0 && sCondition.length == 0)
            {
                dialogArguments.value = "";
            }
            else
            {
                var s = '';
                if (sConditionV1.length > 0) {
                    s += document.getElementById('oConditionF1').options[document.getElementById('oConditionF1').selectedIndex].innerText + " ";
                    s += document.getElementById('oConditionO1').options[document.getElementById('oConditionO1').selectedIndex].innerText + " ";
                    s += document.getElementById('oConditionV1').value + " && ";
                }
                else {
                    s += ' && ';
                }
                if (sConditionV2.length > 0) {
                    s += document.getElementById('oConditionF2').options[document.getElementById('oConditionF2').selectedIndex].innerText + " ";
                    s += document.getElementById('oConditionO2').options[document.getElementById('oConditionO2').selectedIndex].innerText + " ";
                    s += document.getElementById('oConditionV2').value + " && ";
                }
                else {
                    s += ' && ';
                }
                if (sConditionV3.length > 0) {
                    s += document.getElementById('oConditionF3').options[document.getElementById('oConditionF3').selectedIndex].innerText + " ";
                    s += document.getElementById('oConditionO3').options[document.getElementById('oConditionO3').selectedIndex].innerText + " ";
                    s += document.getElementById('oConditionV3').value + " && ";
                }
                else {
                    s += ' && ';
                }
                dialogArguments.value = s + sConditionVUser + sSeperator.replace(new RegExp('\r\n', 'g'), '<br>') + sCondition.replace(new RegExp('\r\n', 'g'), '<br>');
            }
        }
        self.close();
        return 0; //prevent from submitting
    }
</script>
</body>
</html>