/// class ProspectDirector.Web.UI.FeatureSets.Editors.Macro.CanvasEditor
/// using ProspectDirector.Web.UI.FeatureSets.MacroEditorBase

ProspectDirector.Web.UI.FeatureSets.Editors.Macro.CanvasEditor =
    ProspectDirector.Web.UI.FeatureSets.MacroEditorBase.extend({

        //==============================
        // FIELDS
        //==============================

        _viewBox: null,

        //==============================
        // PROPERTIES
        //==============================

        get_node: function () {
            return $("#" + this.getId());
        },
        
        //==============================
        // EVENT HANDLERS
        //==============================
        
        //==============================
        // PUBLIC METHODS
        //==============================

        activate: function () {

            this._viewBox = new PDJS.Canvas.Actual.CanvasViewBoxOnCreate({
                container: $("#" + this.getId() + " [role=canvas-view-box]"),
                documentState: this.getPrimaryValue()
            });

        },

        render: function () {

            return [
                "<div id=\"" + this.getId() + "\">",
                    "<div role='canvas-view-box' style='position:absolute;top:0;left:0;right:0;bottom:0;overflow:auto;'>",
                    "</div>",
                "</div>"
            ].join("");

        },

        onValidationError: function (validationError) {

            var response = validationError._data.error.tags["canvas-response"];

            PDJS.Canvas.Actual.CanvasRefresh.validate({
                formId: null,
                validationErrors: response.validationErrors
            });

            PDJS.Canvas.Actual.Forms.FormFieldAnimation.start(this.formId, 1500,
                PDJS.Canvas.Actual.Forms.FormFieldAnimationType.error);

        },

        commit: function () {
            this.setPrimaryValue(this._viewBox.getDocumentJSON());
        }
        
    });