<%@ Page Title="" Language="C#" MasterPageFile="~/SiteMaster.Master" AutoEventWireup="true" CodeBehind="RecConfigEditorPage.aspx.cs" Inherits="MKInsight.Online.ActionTracking.Methodology.RecConfigEditorPage" %>

<%@ Register Src="../UIControls/Methodology/AvailabilityGrid.ascx" TagName="AvailabilityGrid" TagPrefix="uc1" %>
<%@ Register Src="../UIControls/Header.ascx" TagName="Header" TagPrefix="uc2" %>
<%@ Register Src="~/UIControls/MessageBox.ascx" TagPrefix="uc1" TagName="MessageBox" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Assembly="UIWebControls" Namespace="UIWebControls" TagPrefix="cc4" %>
<%@ Register Assembly="MKinsight.Online.UIServices" Namespace="Geekees.Common.Controls" TagPrefix="ct" %>

<%@ Register Src="../UIControls/Interface/TextBoxEx.ascx" TagName="TextBoxEx" TagPrefix="uc3" %>
<%@ Register Src="../UIControls/Interface/MultilineTextBoxEx.ascx" TagName="MultilineTextBoxEx" TagPrefix="uc4" %>
<%@ Register Src="~/UIControls/TrackingControls/FieldAccessList.ascx" TagPrefix="uc1" TagName="FieldAccessList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <style>
        .reddot {
            height: 5px;
            width: 5px;
            background-color: red;
            display: inline-block;
        }

        .bluedot {
            height: 5px;
            width: 5px;
            background-color: blue;
            display: inline-block;
        }

        .greendot {
            height: 5px;
            width: 5px;
            background-color: green;
            display: inline-block;
        }

        .blackdot {
            height: 5px;
            width: 5px;
            background-color: black;
            display: inline-block;
        }

        .reddotlg {
            height: 10px;
            width: 10px;
            background-color: red;
            display: inline-block;
        }

        .bluedotlg {
            height: 10px;
            width: 10px;
            background-color: blue;
            display: inline-block;
        }

        .greendotlg {
            height: 10px;
            width: 10px;
            background-color: green;
            display: inline-block;
        }

        .blackdotlg {
            height: 10px;
            width: 10px;
            background-color: black;
            display: inline-block;
        }
    </style>
    <script type="text/javascript" src="../scripts/jquery/jquery_min.js"></script>
    <script type="text/javascript" src="../scripts/jquery/jquery.box-min.js"></script>
    <link rel="stylesheet" type="text/css" href="../scripts/jquery/jqbox.css" />
    <script type="text/javascript" src="JavaScript1.js"></script>
    <link href="<%:ResolveUrl("~/scripts/ASTJavascript/astreeview/astreeview.css")%>" type="text/css" rel="stylesheet" />
    <script src="<%:ResolveUrl("~/scripts/ASTJavascript/astreeview/astreeview_packed.js")%>" type="text/javascript"></script>
    <script type="text/javascript">

        function nodeSelectHandler(elem) {

            document.getElementById('<%:txtSelectedNode.ClientID%>').value = elem.parentNode.getAttribute("treeNodeValue");
            document.getElementById('<%:btnSelectionPBTrigger.ClientID%>').click();
        }

        function startDrag() {

            $("#top").hover(function () {

                $("#<%:pnl_g.ClientID%>").animate({ scrollTop: 0 }, "slow");
            });

            $("#bottom").hover(function () {
                $("#<%:pnl_g.ClientID%>").animate({ scrollTop: $(window).scrollTop() + $(window).height() }, "slow");
            });
        }

        function dndCompleteHandler(elem, newParent) {

            try {
                $("#top").off();
                $("#bottom").off();
            }
            catch (err) {
            }

            try {

                var allowDrop = false;
                var onDroppedItemValue;
                var rebuildGraph = false;
                var alertMessage;
                var requirePostback = false;


                if (droppedOnItem != null)
                    onDroppedItemValue = droppedOnItem.getAttribute("treeNodeValue");
                else
                    onDroppedItemValue = newParent.getAttribute("treeNodeValue");

                $.ajax({
                    url: "RecConfigEditorPage.aspx/MoveItems",   // Current Page, Method  
                    async: false,
                    data: JSON.stringify({ SelectedItemId: elem.getAttribute("treeNodeValue"), ParentId: newParent.getAttribute("treeNodeValue"), OnDroppedItem: onDroppedItemValue }),
                    type: "POST", // data has to be POSTed  
                    contentType: "application/json", // posting JSON content      
                    dataType: "JSON",  // type of data is JSON (must be upper case!)  
                    timeout: 10000,    // AJAX timeout  
                    success: function (result) {

                        try {
                            var f = eval("(" + result.d + ")");

                            allowDrop = f.Result;
                            rebuildGraph = f.RebuildGraph;
                            alertMessage = f.Message;
                            requirePostback = f.RequirePostBack;
                        }
                        catch (err) {
                        }

                    },
                    error: function (xhr, status) {
                        allowDrop = false;
                    }
                });

                if (rebuildGraph) {
                    document.getElementById('ctl00_ctl00_c_c_M_btn_UpdatePanelRefresh').click();
                }

                if (requirePostback) {
                    window.location.href = 'RecConfigEditorPage.aspx';
                }

                if (allowDrop == false && alertMessage != '')
                    alert(alertMessage);

                return allowDrop;

            }
            catch (err) {
                return false;
            }

            function OnComplete(result, userContext, methodName) {
                return result;
            }

            function OnError(error, userContext, methodName) {
                return false;
            }

        }

    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="c_M" runat="server">

    <uc2:Header ID="u_H" runat="server" />
    <div style="height: 5px;"></div>

    <asp:UpdatePanel ID="up" runat="server">
        <ContentTemplate>

            <uc1:MessageBox runat="server" ID="u_M" />

            <asp:Panel ID="tbP" runat="server" CssClass="w-bar">

                <asp:LinkButton runat="server" ID="tbl_TemplateDesign" CssClass="w-button" Style="background: url(../images/design32.png); " PostBackUrl="~/Methodology/RecConfigEditorPage.aspx">
                    <asp:Label ID="tbl_TemplateDesignLabel" runat="server"></asp:Label>

                </asp:LinkButton>

                <asp:LinkButton runat="server" ID="tbl_Availability" CssClass="w-button" Style="background: url(../images/user32.png); " PostBackUrl="~/Methodology/AvailabilityPage.aspx">
                    <asp:Label ID="tbl_AvailabilityLabel" runat="server"></asp:Label>

                </asp:LinkButton>

                <asp:LinkButton runat="server" ID="tbl_Save" CssClass="w-button" Style="background: url(../images/save32.png); " OnClick="OnSaveChanges">
                    <asp:Label ID="tbl_SaveLabel" runat="server"></asp:Label>

                </asp:LinkButton>

            </asp:Panel>

            <cc1:CollapsiblePanelExtender ID="cpe_d" runat="server" CollapseControlID="pnl_dHeader" Collapsed="false" CollapsedImage="~/images/expand16.png"
                ExpandControlID="pnl_dHeader"
                ExpandedImage="~/images/collapse16.png" ImageControlID="img_d"
                SuppressPostBack="true" TargetControlID="pnl_d">
            </cc1:CollapsiblePanelExtender>

            <asp:Panel ID="pnl_dHeader" runat="server" CssClass="panelheader"
                Height="30px" Width="99%">
                <div style="padding: 5px; cursor: pointer; vertical-align: middle;">
                    <div style="color: #000000;" class="divfleft">
                        <asp:Label ID="lbl_dHeader" runat="server"></asp:Label>
                    </div>

                    <div style="vertical-align: middle;" class="divfright">
                        <asp:Image ID="img_d" runat="server" ImageUrl="~/images/expand16.png" />
                    </div>
                </div>
            </asp:Panel>

            <asp:Panel ID="pnl_d" runat="server" CssClass="panelbody" Width="99%">

                <div style="height: 5px;"></div>

                <asp:Panel ID="p_template" runat="server" CssClass="w-bar" Width="99%">

                    <asp:LinkButton runat="server" ID="tbl_AddTemplate" CssClass="w-button" Style="background: url(../images/plus32.png); " OnClientClick="$.colorbox({ transition: 'none', top:'10', width: '95%', height: '90%', iframe: true,href:'NewTemplatePage.aspx' });return false;">
                        <asp:Label ID="tbl_AddTemplateLabel" runat="server"></asp:Label>
                    </asp:LinkButton>

                    <asp:LinkButton runat="server" ID="tbl_Delete" CssClass="w-button" Style="background: url(../images/delete32.png); " OnClick="OnDeleteTemplate">
                        <asp:Label ID="tbl_DeleteLabel" runat="server"></asp:Label>
                    </asp:LinkButton>

                </asp:Panel>
                <div style="height: 5px;"></div>

                <cc4:MKGridView ID="g" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                    BorderStyle="None" CellPadding="3" DataKeyNames="ID"
                    OnSorting="OnGridSorting" OnRowCommand="OnRowSelectedIndexChanged">
                    <AlternatingRowStyle CssClass="alternatingrowstyle" />
                    <FooterStyle BackColor="White" ForeColor="#000066" />
                    <HeaderStyle CssClass="headerstyle" Font-Bold="True" HorizontalAlign="Left" Wrap="False" />
                    <PagerStyle HorizontalAlign="Left" />
                    <Columns>
                        <asp:CommandField HeaderText="Select" ShowSelectButton="True" />
                        <asp:BoundField DataField="ID" Visible="false" />
                        <asp:BoundField DataField="origin" SortExpression="origin" />
                        <asp:BoundField DataField="usertype" SortExpression="usertype" />
                        <asp:BoundField DataField="type" SortExpression="type" />
                    </Columns>

                    <SelectedRowStyle BackColor="#D6E8FF" Font-Bold="True" />
                </cc4:MKGridView>
            </asp:Panel>
            <div style="height: 5px;"></div>
            <cc1:CollapsiblePanelExtender ID="cpe_r" runat="server" CollapseControlID="pnl_rHeader" Collapsed="false" CollapsedImage="~/images/expand16.png"
                ExpandControlID="pnl_rHeader"
                ExpandedImage="~/images/collapse16.png" ImageControlID="img_r"
                SuppressPostBack="true" TargetControlID="pnl_r">
            </cc1:CollapsiblePanelExtender>

            <asp:Panel ID="pnl_rHeader" runat="server" CssClass="panelheader"
                Height="30px" Width="99%">
                <div style="padding: 5px; cursor: pointer; vertical-align: middle;">
                    <div style="color: #000000;" class="divfleft">
                        <asp:Label ID="lbl_rHeader" runat="server"></asp:Label>
                    </div>

                    <div style="vertical-align: middle;" class="divfright">
                        <asp:Image ID="img_r" runat="server" ImageUrl="~/images/expand16.png" />
                    </div>
                </div>
            </asp:Panel>

            <asp:Panel ID="pnl_r" runat="server" CssClass="panelbody" Width="99%">
                <table>
                    <tr>
                        <td>
                            <asp:CheckBox ID="mki_RequireEndDateBeforeAgreed" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:CheckBox ID="mki_RequireCloseDateBeforeTerminal" runat="server" />
                        </td>
                    </tr>

                </table>
            </asp:Panel>

            <div style="height: 5px;"></div>

            <asp:Panel ID="pnl_gHeader" runat="server" CssClass="panelheader" Height="30px" Width="99%">
                <div style="padding: 5px; cursor: pointer; vertical-align: middle;">
                    <div style="color: #000000;" class="divfleft">
                        <asp:Label ID="lbl_gHeader" runat="server"></asp:Label>
                    </div>

                </div>
            </asp:Panel>

            <div>
                <table style="border-spacing: 8px;">
                    <tr>

                        <td>
                            <span class="blackdotlg"></span>
                            <asp:Label ID="lbl_blackdot" runat="server"></asp:Label>
                        </td>


                        <td>
                            <span class="reddotlg"></span>
                            <asp:Label ID="lbl_reddot" runat="server"></asp:Label>
                        </td>


                        <td>
                            <span class="greendotlg"></span>
                            <asp:Label ID="lbl_greendot" runat="server"></asp:Label>
                        </td>


                        <td>
                            <span class="bluedotlg"></span>
                            <asp:Label ID="lbl_bluedot" runat="server"></asp:Label>
                        </td>


                        <td>
                            <img src="../images/metabase12.gif" />
                            <asp:Label ID="lbl_metalabelinfo" runat="server"></asp:Label>
                        </td>

                    </tr>
                </table>

            </div>
            <asp:UpdateProgress ID="pr" runat="server" AssociatedUpdatePanelID="up" DisplayAfter="20">
                <ProgressTemplate>
                    <div class="UpdateProgressBackground">
                        <center>
                                        <div class="UpdateProgressContent">
                                            <h3>
                                                <asp:Label ID="lbl_Wait" runat="server"></asp:Label></h3>
                                            <br />
                                            <img src="../images/ajax.gif" alt="" />
                                        </div>
                                    </center>
                    </div>
                </ProgressTemplate>
            </asp:UpdateProgress>

            <table style="width: 100%">
                <tr>
                    <td>
                        <asp:LinkButton ID="btn_CreateSection" runat="server" OnClick="OnCreateNewSection"></asp:LinkButton>
                        &nbsp;<asp:ImageButton ID="btn_Expand" runat="server" ImageUrl="../images/expand16.png" Style="padding-top: 5px;" OnClick="OnExpand" />
                        &nbsp;<asp:ImageButton ID="btn_colps" runat="server" ImageUrl="../images/collapse16.png" OnClick="OnCollapse" />

                    </td>
                </tr>
                <tr>
                    <td style="width: 30%; vertical-align: top;">
                        <div id="top" style="height: 30px; opacity: 0.4; filter: alpha(opacity=40);"></div>
                        <asp:Panel ID="pnl_g" runat="server" CssClass="panelbody" Width="99%" ScrollBars="Vertical" Height="600px">

                            <div style="display: none;">
                                <asp:Button ID="btnSelectionPBTrigger" runat="server" OnClick="OnSelectNode" />
                                <asp:TextBox ID="txtSelectedNode" runat="server"></asp:TextBox>
                                <asp:TextBox ID="txtMessage" runat="server"></asp:TextBox>
                                <asp:Button ID="btn_UpdatePanelRefresh" runat="server" OnClick="OnMoveSection" />

                            </div>

                            <ct:ASTreeView ID="tree" runat="server"
                                BasePath="~/scripts/ASTJavascript/astreeview/"
                                DataTableRootNodeValue="0"
                                EnableRoot="false"
                                EnableNodeSelection="true"
                                EnableCheckbox="false"
                                EnableDragDrop="true"
                                EnableTreeLines="false"
                                EnableNodeIcon="true"
                                EnableCustomizedNodeIcon="true"
                                EnableContextMenu="false"
                                EnableDebugMode="false"
                                EnableAjaxOnEditDelete="true"
                                EnableFixedDepthDragDrop="true"
                                EnableContainerDragDrop="true"
                                OnNodeDragAndDropCompleteScript="dndCompleteHandler(elem, newParent );"
                                OnNodeDragAndDropStartScript="startDrag();"
                                OnNodeSelectedScript="nodeSelectHandler(elem);"
                                EnableParentNodeExpand="true"
                                EnableHorizontalLock="true"
                                EnableDragDropOnIcon="true"
                                EnableOnNodeDragAndDropCompleteScriptReturn="true" />
                        </asp:Panel>

                        <div id="bottom" style="height: 40px; opacity: 0.4; filter: alpha(opacity=40);"></div>

                        <div style="height: 5px;"></div>
                        <asp:Label ID="lbl_EmptySectionNote" runat="server" ForeColor="Red" Font-Size="Smaller" Font-Italic="true"> </asp:Label>
                    </td>
                    <td style="width: 70%; padding-top: 40px; vertical-align: top;">
                        <asp:Panel ID="pnl_gSectionDetails" runat="server" Visible="false">
                            <uc3:TextBoxEx ID="u_SectionName" runat="server" />
                            <div style="height: 5px;"></div>
                            <uc4:MultilineTextBoxEx ID="u_SectionToolTip" runat="server" />
                            <asp:Button ID="btn_SectionDetailsSave" runat="server" OnClick="OnSectionDetailsOK" />
                        </asp:Panel>

                        <asp:Panel ID="pnl_gChildSection" runat="server" Visible="false">
                            <table>
                                <tr>
                                    <td>
                                        <asp:CheckBox ID="mki_ItemMandatory" runat="server" AutoPostBack="True" OnCheckedChanged="OnItemMandatory" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:CheckBox ID="mki_AssignmentForAvailability" runat="server" AutoPostBack="True" OnCheckedChanged="OnRepresentsUserAssignment" />
                                    </td>
                                </tr>

                                <tr>
                                    <td>
                                        <asp:CheckBox ID="mki_AssignmentForChange" runat="server" AutoPostBack="True" OnCheckedChanged="OnRepresentsUserAssignment" />
                                    </td>
                                </tr>

                                <tr>
                                    <td>
                                        <asp:CheckBox ID="mki_RepresentsEntityLinks" runat="server" AutoPostBack="True" OnCheckedChanged="OnFieldAssignmentForEditRights" />
                                        <div   style="padding-left:20px;">
                                        <asp:RadioButtonList ID="rdl_MetaUserGroup" runat="server" AutoPostBack="true" OnSelectedIndexChanged="OnMetaUserGroupChanged" Visible="false" RepeatDirection="Horizontal">
                                            <asp:ListItem  Value="1"></asp:ListItem>
                                            <asp:ListItem  Value="2"></asp:ListItem>
                                            <asp:ListItem  Value="3"></asp:ListItem>
                                            <asp:ListItem  Value="4"></asp:ListItem>

                                        </asp:RadioButtonList>
                                            </div>
                                    </td>
                                </tr>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="mki_ItemUseDefaultRights" runat="server" AutoPostBack="True" OnCheckedChanged="OnChangeDefaultRights" />
                    </td>
                </tr>

            </table>
            </asp:Panel>

                        <asp:Panel ID="pnl_gAccess" runat="server" Visible="false">
                            <uc1:FieldAccessList runat="server" ID="u_ChangeRights" />
                            <asp:Button ID="btn_SaveAccessList" runat="server" OnClick="OnAccessListSave" />
                        </asp:Panel>
            </td>
                </tr>
            </table>

        </ContentTemplate>
    </asp:UpdatePanel>

    <div style="height: 5px;"></div>

</asp:Content>

