<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<link type="text/css" rel="stylesheet" href="/Styles/app/control.css" />
<script type="text/javascript" src="/Scripts/jquery.min.js"></script>
<script type="text/javascript" src="/Scripts/avalon.mobile.min.js"></script>
<script type="text/javascript">
    var vm = avalon.define({
        $id: 'curtain',
        curtainMsg: [],
        gauzeMsg: [],
        groupAddress: '',
        Status: '',
        curtainClick: function (curtainModal, curtain) {
            if (curtainModal.Status != 0) {
                curtain.CurtainOpen.Status = 0;
                curtain.CurtainClose.Status = 0;
            } else {
                curtain.CurtainOpen.Status = 0;
                curtain.CurtainClose.Status = 0;
                curtainModal.Status = 1;
            }
            setCurtain(curtain.CurtainOpen.Address, 0);
            setCurtain(curtain.CurtainClose.Address, 0);
            setCurtain(curtainModal.Address, curtainModal.Status);
        }
    });

    function setCurtain(groupAddress, status, callback) {
        $.ajax({
            url: '/App/CurtainControl/',
            type: 'POST',
            async: false,
            dataType: 'JSON',
            data: {
                roomNumber: RoomConfig.RoomNumber,
                GroupAddress: groupAddress,
                Status: status
            },
            success: callback || function (r) {
                hideLoading();
            }
        });
    }

    $(function () {
        showLoading();
        $.ajax({
            url: "/App/LoadCurtain/",
            data: { roomNumber: RoomConfig.RoomNumber, deviceType: 'Curtain' },
            type: "POST",
            dataType: "JSON",
            success: function (r) {
                hideLoading();
                if (r.IsSuccess) {
                    vm.curtainMsg = r.Data;
                } else {
                    showTip(r.Message);
                }
            }
        });

        $.ajax({
            url: "/App/LoadCurtain/",
            data: { roomNumber: RoomConfig.RoomNumber, deviceType: 'Gauze' },
            type: "POST",
            dataType: "JSON",
            success: function (r) {
                if (r.IsSuccess) {
                    vm.gauzeMsg = r.Data;
                } else {
                    showTip(r.Message);
                }
            }
        });

    });  

</script>
<div id="cmain" ms-controller="curtain">
    <dl id="curtain" class="curtain cmain-list clearfix">
        <dd ms-repeat="curtainMsg">
            <a href="javascript:void(0)" class="btn-curtain-open" ms-class="active:(el.CurtainOpen.Status!=0)"
                ms-click='curtainClick(el.CurtainOpen,el)'>
                <label class="curtain-span">
                    {{el.CurtainOpen.Name}}</label></a><a href="javascript:void(0)" class="btn-curtain-close"
                        ms-class="active:(el.CurtainClose.Status!=0)" ms-click='curtainClick(el.CurtainClose,el)'><label
                            class="curtain-span">
                            {{el.CurtainClose.Name}}</label>
                    </a>
        </dd>
    </dl>
    <dl id="Gauze" class="curtain cmain-list clearfix">
        <dd ms-repeat="gauzeMsg">
            <a href="javascript:void(0)" class="btn-windowScreening-open" ms-class="active:(el.CurtainOpen.Status!=0)"
                ms-click='curtainClick(el.CurtainOpen,el)'>
                <label class="curtain-span">
                    {{el.CurtainOpen.Name}}</label></a> <a href="javascript:void(0)" class="btn-windowScreening-close"
                        ms-class="active:(el.CurtainClose.Status!=0)" ms-click='curtainClick(el.CurtainClose,el)'>
                        <label class="curtain-span">
                            {{el.CurtainClose.Name}}</label></a>
        </dd>
    </dl>
</div>
