<%@ Page Language="vb" ValidateRequest="false" AutoEventWireup="false" CodeBehind="NinkiMobileEdit.aspx.vb" Inherits="WF.Ninki.UI.NinkiMobileEdit" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Src="~/WFAdmin/TagHeadAdmin.ascx" TagPrefix="wf" TagName="TagHeadAdmin" %>
<%@ Register Src="~/WFAdmin/Ninki/NinkiSettings.ascx" TagPrefix="wf" TagName="NinkiSettings" %>
<%@ Register Src="~/WFAdmin/Ninki/fieldsEditor.ascx" TagPrefix="wf" TagName="fieldsEditor" %>
<%@ Register Src="~/WFAdmin/Ninki/fieldsConfig.ascx" TagPrefix="wf" TagName="fieldsConfig" %>
<%@ Register Src="~/WFAdmin/Ninki/NinkiData.ascx" TagPrefix="wf" TagName="NinkiData" %>
<%@ Register TagPrefix="wff" Namespace="WebFoundations.ServerControls" Assembly="WebFoundations.ServerControls" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>
	<script src="../../WFResources/Themes/js/jquery.js" type="text/javascript"></script>
    <wf:TagHeadAdmin runat="server" id="TagHeadAdmin" />
    <script type="text/javascript">
        var formId = '';
        $(window).unload(function () {
            if (formId) {
                try {                    
                    $.ajax({
                        url: '../../api/ninki/forms/' + formId + '/unlock/',
                        contentType: 'text/xml; charset=utf-8',
                        type: 'POST',
                        async: false
                    });
                } catch (error) { }
            }
            if (window.opener && window.opener.refreshGrid) {
                try {
                    window.opener.refreshGrid();
                } catch (error) { }
            }
        });

        function UpdateDataPanel() {
            __doPostBack('updDataPanel', 'UpdateDataPanel');
        }

        (function($){
            
            $(document).ready(function (){
                $("a.form-config").click(function(){
                    var isopen = $("div.form-config").is(":visible");
                    if(!isopen){
                        $("div.form-config").css({display:"inline-block"});
                        $("aside.sidebar").addClass("active");
                    }else{
                        $("div.form-config .form-save").click();
                    }
                    return false;
                });
                window.focus();

                if (!formId) {
                    $(document.body).addClass("start");
                }
            });

            window.onFormSaved = function(){
                if (window) {
                    var o = window.opener;
                    if (o && o.refreshGrid) {
                        try { o.refreshGrid();} catch (error) { }
                    }
                    try {
                        $(document.body).removeClass("start");
                        $("aside.sidebar").removeClass("active");
                        $("div.form-config").hide();
                    } catch (error) { }
                }
            };

            window.onTitleChange = function(value){
                $("h2#form-title").text(value||"");
            }

        })($)
    </script>

</head>
<body class="wf-designer forms-designer forms-designer-mobile">
    <form runat="server">
        <asp:ScriptManager runat="server" />
        <header>
            <h1><asp:Literal ID="ltTitle" runat="server" /></h1>
            <h2 id="form-title"><asp:Literal ID="ltName" runat="server" /></h2>
            <menu type="toolbar" id="toolbar">
                <li class="controls">
                    <input type="radio" name="toolgroup" id="toolgroup-formula" checked="checked" />
                    <label for="toolgroup-formula"><asp:Literal ID="ltControls" runat="server" Text="Controles" /></label>
                    <div class="content">
                        <asp:ImageButton runat="server" ID="addTextBox" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/textbox.png" />
                        <asp:ImageButton runat="server" ID="addLabel" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/label.png" />
                        <asp:ImageButton runat="server" ID="addSelection" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/selection.png" />
                        <asp:ImageButton runat="server" ID="addCheckBox" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/checkbox.png" />
                        <asp:ImageButton runat="server" ID="addDataTime" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/datetime.png" />
                        <asp:ImageButton runat="server" ID="addScale" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/rating.png" />
                        <asp:ImageButton runat="server" ID="addLocation" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/location.png" />
                        <asp:ImageButton runat="server" ID="addMap" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/maps.png" />
                        <asp:ImageButton runat="server" ID="addQRCode" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/qrcode.png" />
                        <asp:ImageButton runat="server" ID="addDelimeter" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/delimeter.png" />
                        <asp:ImageButton runat="server" ID="addAttachment" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/attachment.png" />
                        <asp:ImageButton runat="server" ID="addAction" OnCommand="AddControl" ImageUrl="../../WFResources/FormsMobile/Images/Editor/action.png" />
                    </div>
                </li>
                <li class="data">
                    <input type="radio" name="toolgroup" id="toolgroup-data" />
                    <label for="toolgroup-data">
                        <asp:Literal ID="ltData" runat="server" Text="Dados" /></label>
                    <div class="content">
                        <asp:HyperLink ID="lnkInsertData" CssClass="add" runat="server" Text="Adicionar" />
                        <asp:UpdatePanel ID="updDataPanel" class="data-sources" runat="server" UpdateMode="Conditional">
                            <ContentTemplate>
                                <wf:NinkiData runat="server" id="NinkiData" />
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </div>
                </li>
            </menu>
        </header>
        <main>
            <asp:UpdatePanel ID="updFormFields" class="data-sources" runat="server" UpdateMode="Conditional">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="addTextBox" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addLabel" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addSelection" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addCheckBox" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addDataTime" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addScale" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addLocation" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addMap" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addQRCode" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addDelimeter" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addAttachment" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="addAction" EventName="Click" />
                </Triggers>
                <ContentTemplate>
                    <wf:fieldsEditor runat="server" id="fieldsEditor" visible="false" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </main>
        <aside class="sidepanel props">
            <asp:UpdatePanel ID="updConfigs" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <wf:fieldsConfig runat="server" id="fieldsConfig" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </aside>
        <aside class="sidebar form-info">
            <menu>
                <li class="activate">
                    <asp:LinkButton ID="lnkGenerate" runat="server" />
                </li>
                <li class="test">
                    <asp:HyperLink ID="lnkTest" runat="server" />
                </li>
                <li class="config">
                    <asp:LinkButton ID="lnkSettings" CssClass="form-config" runat="server" />
                </li>
            </menu>
            <asp:UpdatePanel runat="server" class="fields form-config" ID="uppFormInfo">
                <ContentTemplate>
                    <wf:NinkiSettings runat="server" id="NinkiSettings" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </aside>
        <wff:WindowManager ID="EditWindow" runat="server">
            <Windows>
                <telerik:RadWindow ID="EditDialog" runat="server" Behaviors="Close,Move,Reload,Resize" Height="450px" VisibleStatusbar="false" Width="700px" ReloadOnShow="true" Modal="true" />
            </Windows>
        </wff:WindowManager>
    </form>
</body>
</html>
