﻿// Copyright (C) 2008 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexander Ilyin
// Created:    2008.09.10


Ext.namespace("Xtensive");

Xtensive.ObservableDataProxy = function(config){
    Ext.apply(this, config);
    Xtensive.ObservableDataProxy.superclass.constructor.call(this);
    this.addEvents('datarequested');
};

Ext.extend(Xtensive.ObservableDataProxy, Ext.data.DataProxy, {
  load: function(params, reader, callback, scope, arg) {
    params = params || {};
    if (!params.start)
      params.start = 0;

    var datarequestedArgs = { 
      params: params,
      callback : function(data) {
        var result = reader.readRecords(data);
        callback.call(scope, result, arg, true);
      },
      errorcallback : function(message) {
        alert(message);
        callback.call(scope, null, arg, false);
      }
    };
    this.fireEvent('datarequested', datarequestedArgs);
  }
});
if(typeof(Sys)!=='undefined')
    Sys.Application.notifyScriptLoaded();