/*
 * 特别声明：本技术材料受《中华人民共和国著作权法》、《计算机软件保护条例》等法律、法规、行政
 * 规章以及有关国际条约的保护，赞同科技享有知识产权、保留一切权利并视其为技术秘密。未经本公司书
 * 面许可，任何人不得擅自（包括但不限于：以非法的方式复制、传播、展示、镜像、上载、下载）使用，
 * 不得向第三方泄露、透露、披露。否则，本公司将依法追究侵权者的法律责任。特此声明！
 *
 * Special Declaration: These technical material reserved as the technical secrets by AGREE
 * TECHNOLOGY have been protected by the "Copyright Law" "ordinances on Protection of Computer
 * Software" and other relevant administrative regulations and international treaties. Without
 * the written permission of the Company, no person may use (including but not limited to the
 * illegal copy, distribute, display, image, upload, and download) and disclose the above
 * technical documents to any third party. Otherwise, any infringer shall afford the legal
 * liability to the company.
 */
/**
 * Created by huangdeyun on 2015/7/10.
 */
define(["adoreapp/widget/BaseWidget", "adoreapp/util/WidgetUtil"], function (BaseWidget, WidgetUtil) {
    return BaseWidget.extend(function (base) {
        return {
            _initWidget: function (attrs) {
                this.templates = attrs.template.split("<!-- split -->");
                this.jqueryNode = $(this.templates[0]).attr("id", this.id);
                this.shellContent = this.jqueryNode.find("div.modal-content");
                this.attachNode = this.shellContent;
                this.children = new Array();
                //测试用，先把小窗口交易宽度和高度拉大
                this.style = attrs.style;
            },

            _setTitle: function (attrs) {
                var text = attrs.title;
                this.jqueryNode.find("h4")[0].innerHTML = text;
            },

            addChild: function (child) {
                this.children.push(child);
            },

            _layout: function () {
                this.jqueryNode.appendTo(document.body);
                //测试用，先把小窗口交易宽度和高度拉大
                if ((this.style & 0xf000) === 0xf000) {
                    this.jqueryNode.addClass("adore_shell_debug");
                }
            },

            _show: function () {
                this.jqueryNode.openModal({dismissible: false});
                /*用自己的蒙板，方便控制*/
                $("#lean-overlay").remove();
                $(".lean-overlay").remove();
                //多窗口弹出时， 需保证只有一层蒙板
                $(".adore_lean_overlay").remove();
                $(this.templates[1]).appendTo(document.body);
                WidgetUtil.refreshDialogZIndex(this.jqueryNode[0]);
            },

            _dispose: function () {
                this.jqueryNode.closeModal();
                /*删除蒙板（再次删除底层控制的蒙板，防止出现漏网之鱼）*/
                $("#lean-overlay").remove();
                $(".lean-overlay").remove();
                $(".adore_lean_overlay").remove();
                while (this.children.length !== 0) {
                    this.children.pop();
                }
                base._dispose.call(this);
            }
        };
    });
})