﻿/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />



Type.registerNamespace("UI.Controls");

//
UI.Controls.ReportUltimosBehavior = function(element) {
    /// <summary>
    /// Administra el panel para localización en el mapa
    /// </summmary>
    /// <param name="element" type="Sys.UI.DomElement">The element to attach to</param>
    UI.Controls.ReportUltimosBehavior.initializeBase(this, [element]);
    // Referencia a Controles y objetos
    this._parentControl = null;         // Referencia al control de mapas
    this._container = null;             // contenedor
    this._divThrobber = null;           // Contenedor del throbber
    this._divReport = null;             // Contenedor del reporte
    // Fields
    this._loadReportTimer = 0;          // Temporizador utilizado para programar la carga del reporte
    // Propiedades
    this._ReportUltimosPanelId = null;    // Id del Panel para desarrollar controles
    this._ServicePath = null;           // Ruta del servicio web con el método para insertar un delito
    this._CfgReportParams = null;       // Parámetros propios del reporte
    // Eventos
}

UI.Controls.ReportUltimosBehavior.prototype = {
    initialize: function() {
        UI.Controls.ReportUltimosBehavior.callBaseMethod(this, 'initialize');
        //
        this._parentControl = this.get_element().control;
        this._container = $get(this._ReportUltimosPanelId);
        // Attach events
        // Construye elementos
        this.buildControls();
    },
    dispose: function() {
        // Detach Handlers
        UI.Controls.ReportUltimosBehavior.callBaseMethod(this, 'dispose');
    },
    get_PlugInId: function() {
        /// <value type="string" mayBeNull="false">
        /// Gets de plugIn unique id
        /// </value>
        return 'ui.controls.ReportUltimos';
    },
    load: function(container) {
        /// <summary>
        // loads the current plugin into the main map container, creates menu, toolbar, atach events, etc
        /// </summary>
        /// <param name="container" type="SGis.MapToolkit.MapControl">
        /// The map control container
        /// </param>
        this.programLoadReport(3000);
    },
    unload: function() {
        // Unloads Plugin
    },
    buildControls: function() {
        /// <summary>
        /// Construye los controles contenidos 
        /// </summary>
        /// <returns />
        Sys.UI.DomElement.addCssClass(this._container, "ui_repult_container");
        //
        this._divThrobber = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_repult_waiting"],
            visible: true,
            properties: {
            innerHTML: "<span>Cargando....</span>"
        }
    }, this._container);
    //
    this._divReport = $common.createElementFromTemplate(
        {
            nodeName: "div",
            cssClasses: ["ui_repult_report"],
            visible: false
        }, this._container);

},
// Invalida el reporte
invalidate: function() {
    this.programLoadReport(2000);
},
// Programa la carga del reporte
programLoadReport: function(ms) {
    Sys.UI.DomElement.setVisible(this._divThrobber, true);
    Sys.UI.DomElement.setVisible(this._divReport, false);
    window.clearTimeout(this._loadReportTimer);
    this._loadReportTimer = window.setTimeout(Function.createDelegate(this, this.invokeGetReportWebService), ms);
},
// Invoca al servicio web para obtener reporte
invokeGetReportWebService: function() {
    var f = $find('EventFilter');
    if (f) {
        var pfiltro = Sys.Serialization.JavaScriptSerializer.serialize(f._CfgFiltro);
        var pparams = Sys.Serialization.JavaScriptSerializer.serialize(this._CfgReportParams);
        Sys.Net.WebServiceProxy.invoke(this._ServicePath, "GetReportUltimos", false,
                { pFiltro: pfiltro, pParams: pparams },
                Function.createDelegate(this, this.onGetReportMethodComplete),
                Function.createDelegate(this, this.onGetReportMethodError), null, 50000);
    } else {
        this.invalidate();
    }
},
// Se completo invocación al web service - GetLocalidades
onGetReportMethodComplete: function(result, userContext, methodName) {
    Sys.UI.DomElement.setVisible(this._divThrobber, false);
    Sys.UI.DomElement.setVisible(this._divReport, true);
    if (result.IsValid) {
        this._divReport.innerHTML = result.InnerHTML;
    } else {
        // Reintenta
        this.programLoadReport(5000);
    }

},
// Error al invocar web service
onGetReportMethodError: function(webServiceError, userContext, methodName) {
    // Reintenta
    this.programLoadReport(3000);
},


//--------------------------------------------------------------------------
// Acceso a Propiedades
//--------------------------------------------------------------------------
get_ReportUltimosPanelId: function() {
    return this._ReportUltimosPanelId;
},
set_ReportUltimosPanelId: function(value) {
    if (this._ReportUltimosPanelId != value) {
        this._ReportUltimosPanelId = value;
        this.raisePropertyChanged('ReportUltimosPanelId');
    }
},
get_ServicePath: function() {
    return this._ServicePath;
},
set_ServicePath: function(value) {
    if (this._ServicePath != value) {
        this._ServicePath = value;
        this.raisePropertyChanged('ServicePath');
    }
},

get_CfgReportParams: function() {
    return this._CfgReportParams;
},
set_CfgReportParams: function(value) {
    if (this._CfgReportParams != value) {
        this._CfgReportParams = value;
        this.raisePropertyChanged('CfgReportParams');
    }
}
//--------------------------------------------------------------------------
// Manejadores de Eventos
//--------------------------------------------------------------------------



}
UI.Controls.ReportUltimosBehavior.registerClass('UI.Controls.ReportUltimosBehavior', AjaxControlToolkit.BehaviorBase, SGis.MapToolkit.IPlugIn);



if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();