Ext.define("Portfolio.registry.tree.store.Registry", {
	extend: "Ext.data.TreeStore",

	model: "Portfolio.registry.tree.model.Registry",

	alias: "store.registry-store",

	alternateClassName: [
		"Ext.registry.tree.store.Registry"
	],

	requires: [
		"Portfolio.registry.tree.model.Registry",
		"Portfolio.registry.tree.proxy.Registry"
	],

	constructor: function (o_config) {

		var i_store = this;

		var o_clone = Ext.apply({}, o_config);

		var o_proxy = {
			$configStrict: false,
			type: "registry",
			paramsAsJson: true,
			url: "/ip2-services/ip2transaction.aspx",
			dataStore: o_clone.dataStore,
			getMethod: function(request) {
				return "POST";
			}
		};

		Ext.apply(o_config, {
			proxy: o_proxy
		});

		i_store.callParent([o_config]);
	},

	listeners: {
		beforeload: {
			fn: function(i_store, i_operation) {

				var i_node = i_operation.node;

				var i_proxy = i_store.getProxy();
				var o_params = i_operation.getParams();
				var o_options = i_store.options || {};

				var s_registry = o_options.library || o_options.library.file;

				if (o_options.library && o_options.file) {
					s_registry = o_options.library + "/" + o_options.file;
				}

				Ext.apply(o_params, {
					action: "ip2registry.getNode",
					key: i_node.get("key"),
					registry: s_registry
				});

				if (i_proxy.dataStore) {
					Ext.apply(o_params, {
						datastore: i_proxy.dataStore
					});
				}

				i_proxy.idParam = "key";

				delete i_operation.node;
			}
		}
	}
});
