﻿
Type.registerNamespace("SmartInvest"); SmartInvest.FinanceList = function(element) { SmartInvest.FinanceList.initializeBase(this, [element]); this._numberOfItems = null; this._updateInterval = null; this._enableLiveData = true; this._gridView = null; this._webService = null; this._listID = null; this._timer = null; this._orderBy = null; this._showLastUpdateTime = true; this._descending = null; this._skip = null; this._lastUpdateElement = null; this._listenedProperties = null; this._lastUpdateElementInitialValue = null; this._filterString; this._invokeServiceDelegate; this._pager = null; }; SmartInvest.FinanceList.prototype = { initialize: function() {
    SmartInvest.FinanceList.callBaseMethod(this, 'initialize'); this._invokeServiceDelegate = Function.createDelegate(this, this._invokeService)
    if (this._pager !== null) { this._pager.add_pageChanged(Function.createDelegate(this, this._changePageIndex)); this._pager.add_pageChanged(Function.createDelegate(this, this._invokeService)); SmartInvest.Web.WebServices.SingleFinanceEntityServiceWrapper.GetCount(this.get_webService(), this.get_listID(), Function.createDelegate(this, this._onGetCount), null); }
    else { this._invokeService(); if (this.get_enableLiveData()) { this._timer = setInterval(this._invokeServiceDelegate, this._updateInterval); } } 
}, _onGetCount: function(result) {
    this._pager.set_recordCount(result); this._pager.set_pageSize(this.get_numberOfItems()); this._pager.set_pageIndex(0); this._invokeService(); if (this.get_enableLiveData())
        this._timer = setInterval(this._invokeServiceDelegate, this._updateInterval);
}, _changePageIndex: function(sender, e) { this.get_pager().set_pageIndex(e.get_newPageIndex()); }, _invokeService: function() {
    if (this.get_gridView().get_element().childNodes.length < 3) { SmartInvest.Web.WebServices.SingleFinanceEntityServiceWrapper.GetItems(this._filterString, this.get_webService(), this.get_numberOfItems(), this.get_skip(), this.get_orderBy(), this.get_descending(), this.get_listID(), this.get_listenedProperties(), true, this._onGetIndexes, null, this); }
    else
        SmartInvest.Web.WebServices.SingleFinanceEntityServiceWrapper.GetItems(this._filterString, this.get_webService(), this.get_numberOfItems(), this.get_skip(), this.get_orderBy(), this.get_descending(), this.get_listID(), this.get_listenedProperties(), null, this._onGetIndexes, null, this);
}, get_numberOfItems: function() { return this._numberOfItems; }, set_numberOfItems: function(value) { this._numberOfItems = value; }, get_showLastUpdateTime: function() { return this._showLastUpdateTime; }, set_showLastUpdateTime: function(value) { this._showLastUpdateTime = value; }, get_listenedProperties: function() { return this._listenedProperties; }, set_listenedProperties: function(value) { this._listenedProperties = value; }, get_filterString: function() { return this._filterString; }, set_filterString: function(value) { this._filterString = value; }, get_lastUpdateElement: function() { return this._lastUpdateElement; }, set_lastUpdateElement: function(value) { this._lastUpdateElement = value; this._lastUpdateElementInitialValue = this._lastUpdateElement.innerHTML; }, get_webService: function() { return this._webService; }, set_webService: function(value) { this._webService = value; }, get_listID: function() { return this._listID; }, set_listID: function(value) { this._listID = value; }, get_enableLiveData: function() { return this._enableLiveData; }, set_enableLiveData: function(value) { this._enableLiveData = value; }, get_updateInterval: function() { return this._updateInterval; }, set_updateInterval: function(value) { this._updateInterval = value; }, get_gridView: function() { return $find(this._gridView); }, set_gridView: function(value) { this._gridView = value; }, get_pager: function() { return (this._pager); }, set_pager: function(value) { this._pager = $find(value); }, set_numberOfItems: function(value) { this._numberOfItems = value; }, get_descending: function() { return this._descending; }, set_descending: function(value) { this._descending = value; }, get_orderBy: function() { return this._orderBy; }, set_orderBy: function(value) { this._orderBy = value; }, get_skip: function() {
    if (this.get_pager() == null) { return this._skip; }
    else { return this.get_numberOfItems() * this.get_pager().get_pageIndex(); } 
}, set_skip: function(value) { this._skip = value; }, _onGetIndexes: function(result, context) {
    if (!context.get_showLastUpdateTime() || (context.get_lastUpdateElement() && result.Date == null)) { context.get_lastUpdateElement().style.visibility = "hidden"; }
    if (context.get_showLastUpdateTime() && (context.get_lastUpdateElement() != null && result.Date != null)) { context.get_lastUpdateElement().style.visibility = "visible"; context.get_lastUpdateElement().innerHTML = context._lastUpdateElementInitialValue + " " + result.Date.localeFormat("HH:mm:ss"); }
    if (result.Command == "DataBind") { var grid = context.get_gridView(); grid.set_dataSource(result.FullData); grid.dataBind(); }
    else if (result.Command == "ReDataBind") { eval(context.get_webService() + ".GetCount(this.get_listID(),  Function.createDelegate(this, this._onGetCount),null)"); }
    else if (result.Command == "Update") { var grid = context.get_gridView(); if (grid != null) { grid.processData(result.Items); } } 
}, dispose: function() {
    if (this._timer) { window.clearInterval(this._timer); this._timer = null; }
    SmartInvest.FinanceList.callBaseMethod(this, 'dispose');
} 
}; SmartInvest.FinanceList.descriptor = { properties: [{ name: 'numberOfItems', type: Number }, { name: 'gridView', type: String }, { name: 'webService', type: String }, { name: 'pager', type: String }, { name: 'listID', type: String }, { name: 'updateInterval', type: Number }, { name: 'enableLiveData', type: Boolean }, { name: 'descending', type: Boolean }, { name: 'orderBy', type: String }, { name: 'lastUpdateElement', type: Object }, { name: 'skip', type: Number}] }; SmartInvest.FinanceList.registerClass('SmartInvest.FinanceList', Sys.UI.Behavior); if (typeof (Sys) !== 'undefined') { Sys.Application.notifyScriptLoaded(); }
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();