/// class PD.Manage.Modules.ObjectModel.ExplorerFolderCreateCommand

PD.Manage.Modules.ObjectModel.ExplorerFolderCreateCommand =
PD.Commands.Command.extend({

    //===================================
    // PUBLIC METHODS
    //===================================

    setDefaults: function () {

        this.props("id", this.inits("id") || "explorer-folder/create");
        this.props("enabled", true);
        this.props("label", "");
        this.props("tooltip", "");

        this.state("folderId", null);
        this.state("folderTypeId", null);

        this._loadByType();

    },

    setState: function (state) {
        this._super(state);
        this.props("enabled", this.state("folderId") != null);
    },

    execute: function (e) {
        this._super(e);

        var that = this;

        PD.monitor.execute(function () {
            that._executeServiceCall(that.state("folderId"), that.state("folderTypeId"));
        });

    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _loadByType: function () {

        var formTypeId = null,
            formTypeName = null,
            formTypeIcon = null;

        switch (this.inits("folderType")) {
            case "canvas":
                formTypeId = "canvas";
                formTypeIcon = "TEXT_RICH_COLORED.PNG";
                formTypeName = "Canvas";
                break;
            case "content-list":
                formTypeId = "content.list";
                formTypeIcon = "FOLDER_CUBES.PNG";
                formTypeName = "Content List";
                break;
            case "document-folder":
                formTypeId = "file.folder";
                formTypeIcon = "FOLDER.PNG";
                formTypeName = "Document Folder";
                break;
            case "document-explorer":
                formTypeId = "file.explorer";
                formTypeIcon = "FOLDER_VIEW.PNG";
                formTypeName = "Document Explorer";
                break;
            case "tabbed-form":
                formTypeId = "tabbed";
                formTypeIcon = "FOLDER_WINDOW.PNG";
                formTypeName = "Tabbed Form";
                break;
            case "empty-folder":
                formTypeId = null;
                formTypeIcon = null;
                formTypeName = "Empty Folder";
                break;
        }

        this.props("label", "New " + (formTypeName));
        this.props("icon", formTypeIcon != null ? ProspectDirector.RUNTIME.resolveUrl("~/application/icons/16x16/" + formTypeIcon) : null);
        this.state("folderTypeId", formTypeId);

    },

    _executeServiceCall: function (parentId, folderTypeId) {

        var service = new PD.Manage.Services.ExplorerModelService();

        service.addFolder(parentId, folderTypeId, function (data) {

            PD.context.get_default().get_events().publish("explorer-folder/create", {
                node: data.node,
                parentId: parentId
            });

        });

    }

});