﻿Type.registerNamespace("Res.Commerce.Web.Composants");
Res.Commerce.Web.Composants.UpdateProgress = function (element) {
    Res.Commerce.Web.Composants.UpdateProgress.initializeBase(this, [element]);

    this.masque = null;
    this.popup = null;
    this.isVisible = null;
    this._popupId = null;
    this._groupValidation = null;
};
Res.Commerce.Web.Composants.UpdateProgress.prototype = {
    initialize: function () {
        Res.Commerce.Web.Composants.UpdateProgress.callBaseMethod(this, "initialize");

        this.popup = $get(this._popupId);
        this.masque = $get("masqueUpdateProgress");
        this.isVisible = false;

        this._onSubmitHandler = Function.createDelegate(this, this.afficher);
        this._onPartialUpdateEnd = Function.createDelegate(this, this.cacher);

        if (typeof (Sys.WebForms) !== "undefined" && typeof (Sys.WebForms.PageRequestManager) !== "undefined") {
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(this._onSubmitHandler);
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(this._onPartialUpdateEnd);
        }
        //else
        $addHandler(document.forms[0], "submit", this._onSubmitHandler);
        this.cacher();
    },
    dispose: function () {
        Res.Commerce.Web.Composants.UpdateProgress.callBaseMethod(this, "dispose");
    },
    saveClientState: function () {
        return null;
    },
    afficher: function () {
        if (!this.isVisible) {
            var show = true;
            if (typeof (Page_IsValid) != "undefined" && Page_IsValid != null) {
                show = Page_IsValid;
            }
            else {
                if (typeof (Page_ClientValidate) == 'function') {
                    if (typeof (Page_ValidationSummaries) != "undefined") {
                        var summaries = Page_ValidationSummaries;
                        Page_ValidationSummaries = new Array();
                    }
                    if (this._groupValidation === null) Page_ClientValidate();
                    else Page_ClientValidate(this._groupValidation);
                    if (typeof (Page_ValidationSummaries) != "undefined") {
                        Page_ValidationSummaries = summaries;
                    }
                    Page_BlockSubmit = false;
                    show = Page_IsValid;
                }
            }
            if (show) {
                // détermnier la taille du masque (toute la page)
                var hauteurPage = $(document).height();
                var largeurPage = $(document).width();

                // Création dynamique d'un masque, et ajout dans le body
                this.masque = $("<div id='masqueUpdateProgress'></div>")[0];
                $(this.masque).css('height', hauteurPage);
                $(this.masque).css('width', largeurPage);
                $(this.masque).css('position', 'absolute');
                $(this.masque).css('left', 0);
                $(this.masque).css('top', 0);
                $(this.masque).css('z-index', 20000);
                $("body").append($(this.masque));
                // Afficher le masque
                $(this.masque).show();

                // Afficher la popup
                //$(this.popup).show();
                this.isVisible = true;
            }
        }
        return true;
    },
    cacher: function () {
        if (this.masque != null) {
            $(this.masque).detach();
            this.masque = null;
        }
        else {
            this.masque = $get("masqueUpdateProgress");
            if (this.masque != null)
                $(this.masque).detach();
        }
        if (this.popup != null) {
            $(this.popup).hide();
        }
        this.isVisible = false;
        return true;
    },
    get_PopupId: function () {
        return this._popupId;
    },
    set_PopupId: function (value) {
        this._popupId = value;
    },
    set_GroupValidation: function (value) {
        this._groupValidation = value;
    }
};
Res.Commerce.Web.Composants.UpdateProgress.registerClass("Res.Commerce.Web.Composants.UpdateProgress", Res.Commerce.Web.Composants.ScriptControlBase);
if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded(); 
