<%@ page language="C#" autoeventwireup="true" inherits="Pages_MobileView_MySetting, App_Web_d0esffkd" masterpagefile="~/Pages/Common/MasterPages/MobileViewMasterPage.master" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        //var Day;
        var Flag = 0;
        var Id = 0;

        $(document).ready(function () {
            $("#HeaderLabel").text("My Setting");
            DashletBind();
            AttentionDetails();
            DayDetail();

            $("#CancelFlagButton").click(function () {
                //alert("hii");
                var Id = $("#drpFlad").val(-1);
            });
            $(document).on("click", "#chkall", function () {
                if ($(this).prop('checked') == true) {
                    $('.chkDashlet').not(this).prop('checked', true);
                }
                else {
                    $('.chkDashlet').not(this).prop('checked', false);
                }
            });
            $(document).on("click", ".chkDashlet", function () {
                if ($(this).prop('checked') == true) {
                    $(this + 'input').prop('checked', true);
                }
                else {
                    $(this + 'input').prop('checked', false);
                }
                var check = ('.chkDashlet:checked').length;
                var uncheck = ('.chkDashlet:visible').length;
                alert(check);
                alert(uncheck);
                if (check == uncheck) {
                    $('#chkall').prop('checked', true);
                }
                else {
                    $('#chkall').prop('checked', false);
                }
            });
        });
        function OnSuccess(response) {

            //   alert('Hey');
            // alert(response.d);
        }
        function DashletBind() {
            $.ajax({
                type: "POST",
                url: "MySetting.aspx/DashletBind",
                //data: JSON.stringify({ "OrgId": OrgId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var total = 0;
                    var tblDashlet = "";
                    if (obj != "") {
                        tblDashlet += "<thead><tr><th><label class='material-checkbox'><input type='checkbox' class='chkall' id='chkall'><span></span></label></th><th>Dashlet Name</th></tr></thead><tbody>";
                        $.each(obj, function (i, item) {
                            // alert(item.DepartmentName);
                            //alert(item.IsCheck);
                            if (item.IsCheck == true) {
                                tblDashlet += "<tr><td><label class='material-checkbox'><input type='checkbox' class='chkDashlet' checked=checked id=" + item.RoleDashletId + " name='vehicle(this)'><span></span></label></td><td>" + item.DashletName + "</td></tr>"
                            }
                            else { tblDashlet += "<tr><td><label class='material-checkbox'><input type='checkbox' class='chkDashlet' id=" + item.RoleDashletId + " name='vehicle(this)'><span></span></label></td><td>" + item.DashletName + "</td></tr>" }

                        });
                        tblDashlet += "</tbody>";
                    }
                    else { tblDashlet += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblDashlet").innerHTML = tblDashlet;
                    //ReHeader = document.getElementById("HeaderTitle").innerHTML;
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function AttentionDetails() {
            $.ajax({
                type: "POST",
                url: "MySetting.aspx/AttentionDetails",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var configObj = {};
                    configObj.attend = [];
                    configObj.attendKey = [];
                    if (obj != "") {
                        $.each(obj, function (i, item) {
                            configObj.attend.push(item.ID);
                            if (item.ID == 268 && item.ItemKey == 'Dashboard.AbsentStudentLimit') {
                                $("#AbsentStudentLimitText").val(item.ItemValue);
                                $("#AbsentStudentLimitHidden").val(item.ID);
                            }
                            else if (item.ID == 269 && item.ItemKey == 'Dashboard.AbsentEmployeeLimit') {
                                $("#AbsentEmployeeLimitText").val(item.ItemValue);
                                $("#AbsentEmployeeLimitHidden").val(item.ID);
                            }
                            else if (item.ID == 270 && item.ItemKey == 'Dashboard.HomeworkNotGiven') {
                                $("#HomeworkNotGivenText").val(item.ItemValue);
                                $("#HomeworkNotGivenHidden").val(item.ID);
                            }
                            else if (item.ID == 271 && item.ItemKey == 'Dashboard.AttendanceNotAdded') {
                                $("#AttendanceNotAddedText").val(item.ItemValue);
                                $("#AttendanceNotAddedHidden").val(item.ID);
                            }


                        });
                        
                    }
                    else {
                        $.each(obj, function (i, item) {
                            if (item.ID == 268 && item.ItemKey == 'Dashboard.AbsentStudentLimit') {
                                $("#AbsentStudentLimitText").val(item.DefaultValue);
                                // $("#AbsentStudentLimitHidden").val(item.ItemValue);
                            }
                            else if (item.ID == 269 && item.ItemKey == 'Dashboard.AbsentEmployeeLimit') {
                                $("#AbsentEmployeeLimitText").val(item.DefaultValue);
                            }
                            else if (item.ID == 270 && item.ItemKey == 'Dashboard.HomeworkNotGiven') {
                                $("#HomeworkNotGivenText").val(item.DefaultValue);
                            }
                            else if (item.ID == 271 && item.ItemKey == 'Dashboard.AttendanceNotAdded') {
                                $("#AttendanceNotAddedText").val(item.DefaultValue);
                            }

                        });
                    }
                }, error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }

        function DayDetail() {
            $.ajax({
                type: "POST",
                url: "MySetting.aspx/DayDetail",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var configDayObj = {};
                    configDayObj.attend = [];
                    configDayObj.attendKey = [];
                    if (obj != "") {
                        $.each(obj, function (i, item) {
                            configDayObj.attend.push(item.ID);
                            if (item.ID == 273 && item.ItemKey == 'Dashboard.DefaultDay') {
                                $("#drpFlad").val(item.ItemValue);
                                $("#drpFladHidden").val(item.ID);
                            }
                            else if (item.ID == 274 && item.ItemKey == 'Dashboard.PendingFeeUptoDays') {
                                $("#PendingFeeText").val(item.ItemValue);
                                $("#PendingFeeHidden").val(item.ID);
                            }
                        });
                    }
                    else {
                        $.each(obj, function (i, item) {
                            if (item.ID == 273 && item.ItemKey == 'Dashboard.DefaultDay') {
                                $("#drpFlad").val(item.DefaultValue);
                                // $("#AbsentStudentLimitHidden").val(item.ItemValue);
                            }
                            else if (item.ID == 274 && item.ItemKey == 'Dashboard.PendingFeeUptoDays') {
                                $("#PendingFeeText").val(item.DefaultValue);
                            }
                        });
                    }
                }, error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }

        function SaveDeshlet() {
            var Bool = 1;
            // config = '';
            Id = $("#drpFlad").val();
            var someObj = {};
            someObj.fruitsGranted = [];
            $(".chkDashlet").each(function () {
                var $this = $(this);

                if ($this.is(":checked")) {
                    someObj.fruitsGranted.push($this.attr("id"));
                }
            })
            var configObj = {};
            configObj.attend = [];
            configObj.attendKey = [];
            $(".attend").each(function () {
                configObj.attend.push($(this).val());
            })

            $(".HiddenKey").each(function () {
                configObj.attendKey.push($(this).val());
            })
            
            //config.attend.push();

            //var configDayObj = {};
            //configDayObj.attend = [];
            //configDayObj.attendKey = [];
            //$(".attend").each(function () {
            //    configDayObj.attend.push($(this).val());
            //})

            //$(".HiddenKey").each(function () {
            //    configDayObj.attendKey.push($(this).val());
            //})
            //alert(configDayObj.attend);
            //alert(configDayObj.attendKey);
            $.ajax({
                type: "POST",
                url: "MySetting.aspx/SaveDeshlet",
                data: JSON.stringify({ "list": someObj.fruitsGranted.toString() }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {

                },
                error: function (xhr, status, error) {
                    Bool = 0;
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
            $.ajax({
                type: "POST",
                url: "MySetting.aspx/SetSession",
                data: '{Id:"'+parseInt(Id)+'"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                }, error: function (xhr, status, error) {
                    Bool = 0;
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
            $.ajax({
                type: "POST",
                url: "MySetting.aspx/UpdateSettings",
                data: '{list: "' + configObj.attendKey.toString() + '", updtVal: "' + configObj.attend.toString() + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    //alert(result.d);
                    //alert(JSON.parse(result.d));
                },
                error: function (xhr, status, error) {
                    Bool = 0;
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
            
            if(Bool == 1)
            {
                alert("Save successfully")
            }
        }

        function BackOrgFunction() { window.location.href = "../MobileView/DashBoard.aspx"; }
        function DashBoard() { window.location.href = "../MobileView/DashBoard.aspx"; }
    </script>
    <asp:UpdatePanel ID="DoctorScheduleUpdatePanel" runat="server">
        <ContentTemplate>
            <div class="col-md-12 ptb12 d-inline-flex">
                <span class='btn btn-home btn-icon' onclick='DashBoard()' title='home'><span><i class='material-icons'>home</i></span></span>
                <div class="d-inline-flex w-100">
                    <label class="header-topic justify-content-center" id="HeaderLabel"></label>
                </div>
                <input type="button" value="&#xf3e5;" id="bntBackOrg" onclick="BackOrgFunction()" skinid="0" class="float-right btn btn-back btn-icon fas" />
            </div>
            <div class="page-header mb37">
                <div class="col-xl-12 col-sm-12 col-xs-12 border-bottom-inline xs-padd0">
                    <div class="main-topic inner" id="HeaderTitle">
                    </div>
                </div>
            </div>
            <div class="bg-body-dark row center-block">
                <div class="container-fluid">
                    <div class="gutters-tiny push js-appear-enabled animated fadeIn" data-toggle="appear">
                        <div class="tab row">
                            <div class="block newdb height252 row arrow-up">

                                <div class="col-xl-12 col-md-12 col-sm-12 col-xs-12" id="Deshlet">
                                    <div class="card table-card box box-primary">
                                        <div class="card-header box-header yellow-border">
                                            <h3><i class="material-icons dp48">error_outline</i>Dashlet Permission</h3>
                                        </div>
                                        <div class="card-block row padd-0">
                                            <div class="col-xl-4 col-md-6 col-sm-12 col-xs-12 pTop15">
                                                <div class="controlLabelWidth">
                                                    <label>Dashlet Check</label>
                                                </div>
                                                <div class='table-responsive'>
                                                    <div class="card-body fixed-h">
                                                        <table id='tblDashlet' class='table table-striped table-bordered dashlet'>
                                                            <tbody></tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-xl-4 col-md-6 col-sm-12 col-xs-12 pTop15">
                                                <div class="controlLabelWidth">
                                                    <label>Days</label>
                                                </div>
                                                <div class="custom-select ">
                                                    <div class=''>
                                                        <select id="drpFlad" class="attend">
                                                            <option value='0' selected="selected">Yesterday</option>
                                                            <option value='1'>Today</option>
                                                        </select>
                                                        <input type="hidden" id="drpFladHidden" class="HiddenKey" />
                                                           <div class="controlLabelWidth">
                                                        <label>Pending Fee Day</label>
                                                    </div>
                                                    <div class="">
                                                        <input type="Text" class="form-control attend" value="" id="PendingFeeText">
                                                        <input type="hidden" id="PendingFeeHidden" class="HiddenKey" />
                                                    </div>

                                                    </div>
                                                    <%--onclick="SaveFlagButton()"--%>
                                                </div>
                                            </div>
                                            <div class="col-xl-4 col-md-6 col-sm-12 col-xs-12 pTop15">
                                                <div class="col-xs-12 padd-0">
                                                    <div class="controlLabelWidth">
                                                        <label>AbsentEmployeeLimit</label>
                                                    </div>
                                                    <div class="">
                                                        <input type="Text" class="form-control attend" value="" id="AbsentEmployeeLimitText">
                                                        <input type="hidden" id="AbsentEmployeeLimitHidden" class="HiddenKey" />
                                                    </div>
                                                </div>
                                                <div class="col-xs-12 padd-0">
                                                    <div class="controlLabelWidth">
                                                        <label>AbsentStudentLimit</label>
                                                    </div>
                                                    <div class="">
                                                        <input type="Text" class="form-control attend" value="" id="AbsentStudentLimitText">
                                                        <input type="hidden" id="AbsentStudentLimitHidden" class="HiddenKey" />
                                                    </div>
                                                </div>
                                                <div class="col-xs-12 padd-0">
                                                    <div class="controlLabelWidth">
                                                        <label>AttendanceNotAdded</label>
                                                    </div>
                                                    <div class="">
                                                        <input type="Text" class="form-control attend" value="" id="AttendanceNotAddedText">
                                                        <input type="hidden" id="AttendanceNotAddedHidden" class="HiddenKey" />
                                                    </div>
                                                </div>
                                                <div class="col-xs-12 padd-0">
                                                    <div class="controlLabelWidth">
                                                        <label>HomeworkNotGiven</label>
                                                    </div>
                                                    <div class="">
                                                        <input type="Text" class="form-control attend" value="" id="HomeworkNotGivenText">
                                                        <input type="hidden" id="HomeworkNotGivenHidden" class="HiddenKey" />
                                                    </div>
                                                </div>

                                            </div>
                                            <div class="col-md-12 col-xl-12 col-sm-12 pt-3 pb-4 text-center">

                                                <input type="button" value="&#xf0c7; Save" id="SaveDashletButton" class="btn btn-search fas" onclick="SaveDeshlet()" skinid="0" />
                                                <input type="button" value="&#xf00d; Cancel" id="CancelDashletButton" onclick="BackOrgFunction()" skinid="0" class="fas btn btn-clear" />
                                            </div>
                                        </div>
                                        <div class="se-pre-con"></div>
                                    </div>
                                </div>

                                <%--  <div class="col-xl-4 col-md-6 col-sm-12 col-xs-12 min-h" id="YesterdayTodayFlag">
                                    <div class="card table-card box box-primary">
                                        <div class="card-header box-header red-border">
                                            <h3><i class="material-icons dp48">error_outline</i>Yesterday Today Flag</h3>
                                        </div>
                                        <div class="card-block">
                                            <div class="custom-select ">
                                                <div class='fLeft pRight5'>
                                                    <select id="drpFlad">
                                                        <option value='0' selected="selected">Yesterday</option>
                                                        <option value='1'>Today</option>
                                                    </select>
                                                </div>
                                                <%--onclick="SaveFlagButton()"--%>
                            </div>
                            <div class="col-md-12 col-xl-12 col-sm-12 pTop5">

                                <%--<input type="button" value="&#xf00d; Cancel" id="CancelFlagButton" onclick="BackFlagButton()" skinid="0" class="fas btn btn-cancel" />--%>
                            </div>
                        </div>
                        <div class="se-pre-con"></div>
                    </div>
                </div>

            </div>
            </div>
                    </div>
                </div>
            </div>
            <%--  <div class="bg-white row center-block">
                <div class="container-fluid">
                    <div class="gutters-tiny push js-appear-enabled animated fadeIn overflow-hidden" data-toggle="appear">
                        <label id="ann"></label>

                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="ReceiptHead" style="display: block">
                            <h3 class="table-topic">Receipt Book</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> 
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblDashlet' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                         <div class="col-md-12 col-xl-12 col-sm-12 pTop5">
                                    <input type="button" value="&#xf0c7; Save" id="SaveDashletButton" onclick="SaveDeshlet()" skinid="0" class="fas btn btn-save" />
                                    <input type="button" value="&#xf00d; Cancel" id="CancelDashletButton" onclick="BackOrgFunction()" skinid="0" class="fas btn btn-cancel" />
                                </div>

                    </div>
                </div>
            </div>--%>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
