<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Main.Master" AutoEventWireup="true" CodeBehind="TekEkranFormu.aspx.cs" Inherits="Giza.Web.Moduller.TekEkran.TekEkranFormu" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderHeader" runat="server">
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-select/dist/js/bootstrap-select.js") %>"></script>
    <link href="<%=Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-select/dist/css/bootstrap-select.css") %>" rel="stylesheet" />
    <link href="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/bootstrap-table.min.css")%>" rel="stylesheet" />
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/bootstrap-table.min.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/locale/bootstrap-table-tr-TR.js")%>"></script>
    <script src="<%= Page.ResolveUrl("~/Content/vendors/bower_components/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js")%>"></script>
    <script type="text/javascript">
    
        function pageLoad(sender, args) {
            if (args.get_isPartialLoad()) {
                $('.selectpicker').selectpicker();
            }
        }

        function getDashboardDetayListesi(params) {
            var limit = params.data.limit;
            var offset = params.data.offset;
            var search = params.data.search;
            var sort = params.data.sort;
            var order = params.data.order;
            var dashID = <%=dashID%>;
            $.ajax({
                url: "<%=Page.ResolveUrl("~/DataService.asmx/GetDashboardDetayList")%>",
                data: { limit: limit, offset: offset, search: search, sort: sort, order: order, dashID: dashID },
                success: function (result) {
                    params.success({
                        total: result.total,
                        rows: result.rows
                    });
                }
            });
        }

        function SayfaTemizle() {
            $("#txtSira").val("1");

            $("#ddlRapor").val(0);
            $('#ddlRapor').selectpicker('refresh')
            $("#ddlUstRapor").val(0);
            $('#ddlUstRapor').selectpicker('refresh')
            $("#ddlKolonIsmi").val(0);
            $('#ddlKolonIsmi').selectpicker('refresh')
            $("#ddlKolonIsmiUst").val(0);
            $('#ddlKolonIsmiUst').selectpicker('refresh')
        }

        function dropDoldur(cntrl, refreshctrl, secilendeger) {
            __doPostBack(cntrl, secilendeger);
            $('#' + refreshctrl).selectpicker('refresh');
        }

        function loadDashboardRapor(id) {
            if (id==0) {
                $('#hdnsecilenGridId').val(0);
                PopupAc(1);
                return
            }
            $('#hdnsecilenGridId').val(id);
            $.ajax({
                type: "GET",
                dataType: 'json',
                url: "<%= Page.ResolveUrl("~/DataService.asmx/GetDashboardDetay")%>",
                data: { id: id},
                success: function (result) {
                    var gelenveri = result.veri;
                    if (result.status == 1) {
                        PopupAc(1);
                        $("#txtSira").val(gelenveri.Sira);

                        
                        
                        setTimeout(function(){
                            //alert("Çalıştı")
                            $("#ddlUstRapor").val(gelenveri.UstID);
                            $("#ddlUstRapor").selectpicker('refresh');
                            __doPostBack('ddlUstRapor', gelenveri.KolonIsmiUst);
                            $("#ddlKolonIsmiUst").selectpicker('refresh');
                        }, 1); 

                        setTimeout(function(){      
                            $("#ddlRapor").val(gelenveri.RaporID);
                            $("#ddlRapor").selectpicker('refresh');
                            __doPostBack('ddlRapor', gelenveri.KolonIsmi);
                        }, 2000); 

                        
                    }
                    else
                        notify(result.message, "danger", "", 10000);
                },
                error: function (e) {
                    notify("Tek ekran detay bilgileri getirilirken bir hata oluştu. Hata:" + e.responseText.substring(0,200) + "...", "danger", "", 10000);
                    console.log(e.responseText)
                }
            });
        }
        function dashboardDetayKaydet() {
            var kulid = <%=KullaniciId%>;
            var id = $('#hdnsecilenGridId').val();
            var ustid = $('#ddlUstRapor').val();
            var dashboardid = <%=dashID%>;
            var raporid = $('#ddlRapor').val();
            var kolonismi = $('#ddlKolonIsmi').val();
            var kolonismiust = $('#ddlKolonIsmiUst').val();

            var sira = $('#txtSira').val();
            
            if (raporid == 0 || kolonismi == null || kolonismi == "" || sira == "") {
                notify("Zorunlu alanları doldurunuz. (RaporAdı,Eşleşme Kolon Adı,Sıra)", "warning");

                return;
            }

            if (ustid != 0 && kolonismiust == "") {
                notify("Üst raporun eşleşme kolonunu seçmediniz.", "warning");
                return;
            }
            $.ajax({
                type: "GET",
                dataType: 'json',
                url: "<%=Page.ResolveUrl("~/DataService.asmx/DashboardDetayKaydet")%>",
                data: { id: id, kulid:kulid, ustid:ustid, dashboardid:dashboardid, raporid:raporid, kolonismi:kolonismi, sira:sira, kolonismiust:kolonismiust},
                success: function (result) {
                    if (result.status == 1) {
                        $("#hdnSecilenDDId").val(0);
                        if (id>0) 
                            notify('Kayıt güncellendi', 'success');
                        else
                            notify('Kayıt eklendi', 'success');
                        
                        setTimeout(location.reload(true),2000);
                        $('#table').bootstrapTable('refresh');
                    }
                    else
                        notify(result.message, "warning", "", 10000);
                },
                error: function (e) {
                    notify("Tek Ekran detay bilgileri kaydedilirken bir hata oluştu. Hata:" + e.responseText.substring(0,200) + "...", "danger", "", 10000);
                }
            });
        }

        function PopupAc(temizle) {
            if (temizle==1) {
    
                SayfaTemizle();
            }
            $('#Popup').modal({backdrop:false});
        }
       

        function getEditDeleteLink(value, row) {
            return "<a title='Düzenle' class=\"btn bgm-orange waves-effect\" onClick=\"loadDashboardRapor(" + row.Id + ");\" \"> <span style=\"width:6px \" class=\"zmdi zmdi-edit c-white\"> </span> </a> " +
             "<a title='Sil' class=\"btn btn-danger waves-effect\" onclick=\"Delete( " + row.Id + ")\"> <span style=\"width:6px \" class=\"zmdi zmdi-delete c-white\"> </span> </a> ";
        }
        function Delete(Id) {
            swal({
                title: "Seçilen kaydı silmek istiyor musunuz?",
                text: "Kaydı sildikten sonra işlemi geri alamazsınız.",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Evet",
                cancelButtonText: "Hayır",
                closeOnConfirm: true,
                closeOnCancel: true
            }, function (isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        type: "GET",
                        dataType: 'json',
                        url: "<%=Page.ResolveUrl("~/DataService.asmx/DeleteDashboardDetay")%>",
                        data: { Id: Id },
                        success: function (data) {
                            if (data.status == 1) {
                                notify(data.message, "success");
                                $('#table').bootstrapTable('refresh');
                                location.reload(true);
                            }
                            else {
                                notify(data.message, "warning");
                            }
                        },
                        error: function (e) {
                            notify("Kayıt silinirken hata oluştu. Hata:" + e.responseText.substring(0,200) + "...", "danger", "", 10000);
                        }
                    });
                } else {
                    notify("İşlem iptal edildi.", "info");
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderBreadcrumbs" runat="server">
    <ol class="breadcrumb" style="margin-bottom: 5px;">
        <li><a href="<%= Page.ResolveUrl("~/AnaSayfa.aspx") %>">Anasayfa</a></li>
        <li><a href="<%= Page.ResolveUrl("~/Moduller/TekEkran/TekEkranListesi.aspx") %>">TekEkran Listesi</a></li>
        <li class="active">Tek Ekran Tanımlama</li>
    </ol>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderMain" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:HiddenField runat="server" ID="hdnsecilenGridId" ClientIDMode="Static" Value="0" />

    <div class="row">
        <div class="card">
            <div class="card-header">
                <h2>Tek Ekran Üst Bilgileri</h2>
            </div>
            <div class="card-body card-padding">
                <div class="row">
                    <div class="col-sm-8">
                        <div class="form-group fg-line">
                            <p class="f-500 m-b-5 f-700">Tek Ekran Adı</p>
                            <asp:TextBox ID="txtDashboardBaslik" class="form-control input-sm" runat="server" placeholder="Baslik" ValidationGroup="Tek Ekran"></asp:TextBox>
                        </div>
                    </div>


                    <div class="col-sm-2">
                        <div class="form-group fg-line">
                            <p class="f-500 m-b-5 f-700">Menüde Göster</p>

                            <label class="checkbox checkbox-inline m-r-20" style="margin-top: 5px;">
                                <asp:CheckBox ID="chkDashboardMenudeGoster" ClientIDMode="Static" runat="server" />
                                <i class="input-helper"></i>
                            </label>

                        </div>
                    </div>

                    <div class="col-sm-2">
                        <div class="form-group fg-line">
                            <p class="f-500 m-b-5 f-700">Aktif Mi</p>

                            <label class="checkbox checkbox-inline m-r-20" style="margin-top: 5px;">
                                <asp:CheckBox ID="chkDashboardAktifMi" ClientIDMode="Static" runat="server" />
                                <i class="input-helper"></i>
                            </label>

                        </div>
                    </div>


                </div>

            </div>
        </div>
    </div>

    <div id="divDashboardDetay" class="row" runat="server">
        <div class="card">
            <div class="card-header">
                <h2>Tek Ekran Detay Bilgileri</h2>
            </div>
            <div class="card-body card-padding">

                <div id="toolbar" style="padding-right: 25px; padding-left: 5px">
                    <div id="btnRaporEkle" class="btn bgm-teal waves-effect" onclick="loadDashboardRapor(0)">Tek Ekrana Rapor Ekle</div>
                </div>
                <div style="overflow-x: auto;">
                    <table id="table"
                        data-toggle="table"
                        data-toolbar="#toolbar"
                        data-ajax="getDashboardDetayListesi"
                        data-search="false"
                        data-search-align="left"
                        data-show-refresh="true"
                        data-show-toggle="false"
                        data-show-columns="true"
                        data-show-export="true"
                        data-minimum-count-columns="2"
                        data-show-pagination-switch="false"
                        data-pagination="true"
                        data-id-field="Id"
                        data-page-list="[10, 25, 50, 100, TÜMÜ]"
                        data-locale="tr-TR"
                        data-show-footer="false"
                        data-side-pagination="server"
                        data-sort-name="Id"
                        data-sort-order="asc"
                        data-export-types=""
                        data-export-options='{"fileName": "Tek Ekran Listesi", "worksheetName": "Tek Ekran Listesi"}'>
                        <thead>
                            <tr>
                                <th data-formatter="getEditDeleteLink" data-switchable="false">İşlemler</th>
                                <th data-field="RaporAdi" data-sortable="true">Rapor Adı</th>
                                <th data-field="UstRaporAdi" data-sortable="true">Üst Rapor Adı</th>
                                <th data-field="KolonIsmi" data-sortable="true">Kolon İsmi</th>
                                <th data-field="KolonIsmiUst" data-sortable="true">Kolon İsmi Üst</th>
                                <th data-field="Sira" data-sortable="true">Sırası</th>
                            </tr>
                        </thead>
                    </table>
                </div>

            </div>
        </div>
    </div>
    <div class="row">
        <div class="alert alert-warning alert-dismissible" role="alert" style="visibility: hidden;">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
            <asp:CustomValidator ID="Validator" ValidationGroup="Kullanici" runat="server" CssClass="control-label" ErrorMessage="Lütfen boş geçilemeyecek alanları doldurunuz" OnServerValidate="Validator_ServerValidate"></asp:CustomValidator>
        </div>
        <div>
            <asp:Button ID="btnDashboardKaydet" runat="server" Text="Kaydet" class="btn bgm-green waves-effect pull-right" OnClick="btnDashboardKaydet_Click" />

            <div style="clear: both;"></div>
        </div>
    </div>

    <div id="Popup" class="modal fade  bd-example-modal-sm" role="dialog">
        <div class="modal-dialog">

            <!-- Modal content-->
            <div class="modal-content" style="width: 60%; left: 20%;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Rapor Tanımla</h4>
                </div>
                <div class="modal-body">
                    <asp:UpdatePanel ID="UP1" runat="server">
                        <ContentTemplate>
                            <div class="row">
                                <div class="col-sm-6">
                                    <div class="form-group fg-line">
                                        <p class="f-500 m-b-5 f-700">Üst Rapor</p>
                                        <asp:DropDownList ID="ddlUstRapor" OnSelectedIndexChanged="ddlUstRapor_SelectedIndexChanged" AutoPostBack="true" data-live-search="true" ClientIDMode="Static" class="selectpicker" runat="server" Style="width: 100%;">
                                        </asp:DropDownList>
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group fg-line">
                                        <p class="f-500 m-b-5 f-700">Üst Raporun Eşleşme Kolon Adı</p>
                                        <asp:DropDownList ID="ddlKolonIsmiUst" data-live-search="true" ClientIDMode="Static" class="selectpicker" runat="server" Style="width: 100%;">
                                        </asp:DropDownList>
                                    </div>
                                </div>

                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group fg-line">
                                        <p class="f-500 m-b-5 f-700">Rapor Adı</p>
                                        <asp:DropDownList ID="ddlRapor" AutoPostBack="true" OnSelectedIndexChanged="ddlRapor_SelectedIndexChanged" data-live-search="true" ClientIDMode="Static" class="selectpicker" runat="server" Style="width: 100%;">
                                        </asp:DropDownList>
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group fg-line">
                                        <p class="f-500 m-b-5 f-700">Eşleşme Kolon Adı</p>
                                        <asp:DropDownList ID="ddlKolonIsmi" data-live-search="true" ClientIDMode="Static" class="selectpicker" runat="server" Style="width: 100%;">
                                        </asp:DropDownList>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <p class="f-500 m-b-5 f-700">Sıra</p>
                                    <asp:TextBox ID="txtSira" class="form-control input-sm" ClientIDMode="Static" runat="server" placeholder="Sıra" TextMode="Number" Text="1" ValidationGroup="TekEkran"></asp:TextBox>
                                </div>
                            </div>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="ddlRapor" EventName="SelectedIndexChanged" />
                            <asp:AsyncPostBackTrigger ControlID="ddlUstRapor" EventName="SelectedIndexChanged" />

                        </Triggers>
                    </asp:UpdatePanel>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-info waves-effect" data-dismiss="modal">Kapat</button>
                    <button type="button" onclick="dashboardDetayKaydet();" class="btn btn-success waves-effect" data-dismiss="modal">Kaydet</button>
                    <%--<asp:Button ID="btnRaporEkleKaydet" class="btn btn-info" OnClick="btnRaporEkleKaydet_Click" runat="server" Text="Kaydet" />--%>
                </div>
            </div>

        </div>



    </div>

</asp:Content>
