/*
 * Copyright (c) 2008 The Olympos Development Team.
 * 
 * http://sourceforge.net/projects/olympos/
 * 
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html. If redistributing this code, this
 * entire header must remain intact.
 */
Ext.namespace("cwe.transaction");

/**
 * @class Routes requests of a grid store through persistency layer.
 * 
 * @extends Ext.data.DataProxy
 * @constructor
 * @param {Object}
 *            config The configuration object.
 * @config modelDescription The Model Description to load object of.
 */
cwe.transaction.Proxy = function(config) {
	this.modelDescription = config.modelDescription;
	this.account = config.account;

	cwe.transaction.Proxy.superclass.constructor.call(this, Ext.apply(this, {}, config));
};

Ext.extend(cwe.transaction.Proxy, chi.model.Proxy);

/**
 * Loads the data.
 * 
 * <p>
 * Refer to Ext.data.DataProxy for details.
 * </p>
 */
cwe.transaction.Proxy.prototype.load = function(params, reader, callback, scope, arg) {
	if (this.fireEvent("beforeload", this, params) !== false) {
		var self = this;

		chi.persistency.Persistency.getInstance().listTransactions(this.account.getOid(), false, this.query, params.limit, params.start, params.sort, params.dir ? params.dir.toLowerCase() : undefined,
		        function(data) {
			        self.loadResponse(params, data, callback, scope, arg);
		        }, function(data, errorMsg) {
			        self.loadFailed(params, data, errorMsg, callback, scope, arg);
		        });
	} else {
		callback.call(scope || this, null, arg, false);
	}
};
