/*
 * 特别声明：本技术材料受《中华人民共和国著作权法》、《计算机软件保护条例》等法律、法规、行政
 * 规章以及有关国际条约的保护，赞同科技享有知识产权、保留一切权利并视其为技术秘密。未经本公司书
 * 面许可，任何人不得擅自（包括但不限于：以非法的方式复制、传播、展示、镜像、上载、下载）使用，
 * 不得向第三方泄露、透露、披露。否则，本公司将依法追究侵权者的法律责任。特此声明！
 *
 * 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 liushuai on 2015/1/13.
 */
define(["adoreapp/widget/BaseWidget", "adoreapp/widget/EventHub"], function (BaseWidget, EventHub) {
    return BaseWidget.extend(function (base) {
        return {
            _initWidget: function (attrs) {
                this.jqueryNode = $(attrs.template).attr("id", this.id);
                this.jqueryNode.find("textarea").attr("id", this.id).on("input", function (e) {
                    EventHub.dispatchEvent(EventHub.MSG_TYPE.WIDGET, {
                        id: this.id,
                        text: $(this).val(),
                        evtType: EventHub.MODIFY,
                        syncAttrName: "text"
                    })
                });
            },

            _setEnabled: function (attrs) {
                var enabled = attrs.enabled;
                if (enabled) {
                    this.jqueryNode.find("textarea").removeAttr("disabled");
                    this.jqueryNode.find("i").removeClass("icon_disabled");
                } else {
                    this.jqueryNode.find("textarea").attr("disabled", "disabled");
                    this.jqueryNode.find("i").addClass("icon_disabled");
                }
            },

            _setText: function (attrs) {
                var text = attrs.text;
                this.jqueryNode.find("textarea").val(text);
                if (text.length > 0)
                    this.jqueryNode.find("textarea").siblings('label, i').addClass('active');
            },

            _setIcon: function (attrs) {
                var icon = attrs.icon;
                this.jqueryNode.find("i").addClass(icon);
                if (this.jqueryNode.find("textarea").val().length > 0)
                    this.jqueryNode.find("textarea").siblings('label, i').addClass('active');
            },

            _setName: function (attrs) {
                var name = attrs.name;
                this.jqueryNode.find("label").text(name);
            },

            _layout: function () {
                base._layout.call(this);
            },

            _setEditable: function (attrs) {
                this.editable = attrs.editable;
                if (this.editable) {
                    this.jqueryNode.find("textarea").removeAttr("readOnly");
                } else {
                    this.jqueryNode.find("textarea").attr("readOnly", "readOnly");
                }
            }
        }
    })
})