/**
 * ECナビ
 * @author maruuo
 */

Ext.namespace("Ext.my.api");

Ext.my.api.EcNavi = function(){
	this.getRecord = function () {
		this.record = Ext.data.Record.create([
			{name: 'originalId', mapping: 'item_id'},
			{name: 'model', mapping: 'item_name'},
			{name: 'lowPrice', mapping: 'price_min'},
			{name: 'shopCount', mapping: 'number_of_shop'},
			{name: 'imageUrl', mapping: 'img'},
			{name: 'url', mapping: 'item_url'}
		]);
		return this.record;
	};

	this.getReader = function(record) {
		if (arguments.length == 0) {
			record = this.getRecord();
		}
		this.reader = new Ext.data.JsonReader(
			{
				root: 'response.docs'
			},
			record
		);
		return this.reader;
	} ;

	this.getProxy = function () {
		this.proxy = new Ext.data.ScriptTagProxy({
			url:'http://api.ecnavi.jp/shopping/navic_search/select?sort=price_min+asc&',
			method:'GET',
			callbackParam: 'json.wrf'
		});
		return this.proxy;
	};

	this.getStore = function(params) {
		this.store = new Ext.data.Store({
			reader: this.getReader(),
			proxy:  this.getProxy(),
			listeners:{
				load:params.func
			},
			baseParams: {
				wt: 'json',
				rows: 1
			}
		});
		this.store.load({
			params: {
				q: encodeURI(params.model)
			},
			model: params.model,
			specId: params.specId,
			elmnt:   params.elmnt
		});
		return this.store;
	};
};
