"use strict";

define([], function () {

    var WidgetBase = function (propertyDesc) {
        this.el = $("<div/>");

        this.propertyValue = propertyDesc.value;
        this.originalValue = propertyDesc.value;
        this.propertyName = propertyDesc.name;
        this.propertyID = propertyDesc.id;
        this.propertyText = propertyDesc.text;
        this.valueItems = propertyDesc.valueItems;
        this.valueType = propertyDesc.valueType || typeof propertyDesc.value;

        this._isReadOnly = false;

        //The function to be called on change.
        this.__onChange = undefined;

        // The function to be called on finishing change.
        this.__onFinishChange = undefined;
    };

    WidgetBase.prototype.onChange = function (fnc) {
        this.__onChange = fnc;
        return this;
    };

    WidgetBase.prototype.onFinishChange = function (fnc) {
        this.__onFinishChange = fnc;
        return this;
    };

    WidgetBase.prototype.setValue = function (newValue) {
        var _oldValue = this.propertyValue;

        if (this._isReadOnly !== true) {
            if (newValue !== _oldValue) {
                this.propertyValue = newValue;
                if (this.__onChange) {
                    this.__onChange.call(this, { "id": this.propertyID,
                        "oldValue": _oldValue,
                        "newValue": newValue });
                }
                this.updateDisplay();
            }
        }

        return this;
    };

    WidgetBase.prototype.fireFinishChange = function () {
        if (this.originalValue !== this.propertyValue) {
            if (this.__onFinishChange) {
                this.__onFinishChange.call(this, { "id": this.propertyID,
                    "oldValue": this.originalValue,
                    "newValue": this.propertyValue });
            }
            this.originalValue = this.propertyValue;
        }
    };

    WidgetBase.prototype.getValue = function () {
        return this.propertyValue;
    };

    WidgetBase.prototype.updateDisplay = function () {
        return this;
    };

    WidgetBase.prototype.remove = function () {
        this.__onChange = undefined;
        this.__onFinishChange = undefined;
        this.el.remove();
    };

    WidgetBase.prototype.setReadOnly = function (isReadOnly) {
        this._isReadOnly = isReadOnly;
    };

    return WidgetBase;
});
@@ -2134,32 +2134,56 @@
 = function () %7B%0A
+        this.destroy();%0A
         this.__o
@@ -2386,24 +2386,81 @@
 ly;%0A    %7D;%0A%0A
+    WidgetBase.prototype.destroy = function () %7B%0A    %7D;%0A%0A
     return W

add destroy method to WidgetBase which is beaing called on remove