Ext.namespace('com.comrades');

com.comrades.UserGroupDataStore = Ext.extend(Ext.data.Store, {
	listeners:{
		loadexception:showErrorMsg,
		load:loadInspector
	}
	,proxy: new Ext.data.HttpProxy({ 
		 url:frontControllerURL
		,metod:'POST'
		,jsonData:Ext.encode(new Array(new Dispatcher({page:'UserGroup',action:'GetUserGroups'}))) }
	)
    ,reader :new Ext.data.JsonReader( {
		root :"result",
		id :"id"}
    	, [{name :'name', mapping: 'name'},
		   {name :'email', mapping: 'email'} 
    	  ]
    )
	,initComponent : function() {
		Ext.apply(this, {
			name :'com.comrades.UserGroupDataStore'
		});// eo apply

		// call parent initComponent
		com.comrades.UserGroupDataStore.superclass.initComponent.apply(this);
	}// eo intiComponent;

}); // eo UserGroupDataStore

com.comrades.RoleDataStore = Ext.extend(Ext.data.Store, {
	listeners:{
		loadexception:showErrorMsg,
		load:loadInspector
	}
	,proxy: new Ext.data.HttpProxy({ 
		 url:frontControllerURL
		,metod:'POST'
		,jsonData:Ext.encode(new Array(new Dispatcher({page:'User',action:'GetUserRoles'}))) }
	)
    ,reader :new Ext.data.JsonReader( {
		root :"result",
		id :0}
    	, [{name :'code', mapping: 'code'},
    	   {name :'description', mapping: 'description'}]
    )
	,initComponent : function() {
		Ext.apply(this, {
			name :'com.comrades.RoleDataStore'
		});// eo apply

		// call parent initComponent
		com.comrades.RoleDataStore.superclass.initComponent.apply(this);
	}// eo intiComponent;

}); // eo RoleDataStore

com.comrades.TopMemberDataStore = Ext.extend(Ext.data.Store, {
	listeners:{
		loadexception:showErrorMsg,
		load:loadInspector
	}
	,proxy: new Ext.data.HttpProxy({ 
		 url:frontControllerURL
		,metod:'POST'
		,jsonData:Ext.encode(new Array(new Dispatcher({page:'Attendance',action:'GetTopMembers'}))) }
	)
    ,reader :new Ext.data.JsonReader( {
		root :"result",
		id :0}
    	, [{name :'name', mapping: 'name'},
    	   {name :'rating', mapping: 'rating'},
		   {name :'accepted', mapping: 'accepted'}]
    )
	,initComponent : function() {
		Ext.apply(this, {
			name :'com.comrades.TopMemberDataStore'
		});// eo apply

		// call parent initComponent
		com.comrades.TopMemberDataStore.superclass.initComponent.apply(this);  
	}// eo intiComponent;

}); // eo TopMemberStore


com.comrades.LevelDataStore = Ext.extend(Ext.data.Store, {
	listeners:{
		loadexception:showErrorMsg,
		load:loadInspector
	}
	,proxy: new Ext.data.HttpProxy({ 
		 url:frontControllerURL
		,metod:'POST'
		,jsonData:Ext.encode(new Array(new Dispatcher({page:'User',action:'GetUserLevels'}))) }
	)
    ,reader :new Ext.data.JsonReader( {
		root :"result",
		id :0}
    	, [{name :'code', mapping: 'code'},
    	   {name :'description', mapping: 'description'}]
    )
	,initComponent : function() {
		Ext.apply(this, {
			name :'com.comrades.LevelDataStore'
		});// eo apply

		// call parent initComponent
		com.comrades.LevelDataStore.superclass.initComponent.apply(this);
	}// eo intiComponent;

}); // eo LevelDataStore


com.comrades.TypeDataStore = Ext.extend(Ext.data.Store, {
	listeners:{
		loadexception:showErrorMsg,
		load:loadInspector
	}
	,proxy: new Ext.data.HttpProxy({ 
		 url:frontControllerURL
		,metod:'POST'
		,jsonData:Ext.encode(new Array(new Dispatcher({page:'User',action:'GetUserTypes'}))) }
	)
    ,reader :new Ext.data.JsonReader( {
		root :"result",
		id :0}
    	, [{name :'code', mapping: 'code'},
    	   {name :'description', mapping: 'description'}]
    )
	,initComponent : function() {
		Ext.apply(this, {
			name :'com.comrades.TypeDataStore'
		});// eo apply

		// call parent initComponent
		com.comrades.TypeDataStore.superclass.initComponent.apply(this);
	}// eo intiComponent;

}); // eo TypeDataStore



com.comrades.UserDataStore = function(config){
	//apply configuration passed during intitialization
	var d = new Dispatcher();
	d.page = 'User';
	if (config.xaction != null)
		d.action = config.xaction;
	
	else
		d.action = 'Unknown';
	
	var ug = new UserGroup();
	if (config.xusergroupid != null)
		ug.id = config.xusergroupid;
	
	var p = new Array();
	p[0]=d;
	if (config.xusergroupid != null)
		p[1]=ug;
	
	this.proxy.conn.jsonData = Ext.encode(p);
		
	Ext.apply(this, config);
	//non-configurable parameters
	
	Ext.apply(this, {
		buttonAlign:'center',
		name:'com.comrades.UserDataStore'	
	});			
	
	//call superclass constructor afterall
	com.comrades.UserDataStore.superclass.constructor.call(this);
};// end of com.comrades.UserDataStore

Ext.extend(com.comrades.UserDataStore,Ext.data.Store, {
	xaction: null,
	xusergroupid:null,
	listeners:{
		loadexception:showErrorMsg,
		load:loadInspector
	}
	,proxy: new Ext.data.HttpProxy({ 
		 url:frontControllerURL
		,metod:'POST'
	})
    ,reader :new Ext.data.JsonReader( {
		root :"result",
		id :"id"}
    	, [
    		{name:'firstName',mapping:'firstName'},
    	    {name:'lastName', mapping:'lastName'}, 
    	    {name:'email', mapping:'email'}, 
    	    {name:'role',mapping:'role'},
    	    {name:'type',mapping:'type'},
    	    {name:'type.description',mapping:'type.description'},
    	    {name:'password',mapping:'password'}, 
    	    {name:'phoneNumber',mapping:'phoneNumber'},
    	    {name:'level', mapping:'level'},
            {name:'level.description',mapping:'level.description'},
    	    {name:'isActive', mapping:'isActive'},
            {name:'number',mapping:'number'},
    	    {name:'newEventAlert',mapping:'newEventAlert'},
            {name:'picture',mapping:'picture'},
    	    {name:'userGroup',mapping:'userGroup'}
    	  ]
    )

	,setUserGroup : function(usergroupid){
	 	this.xusergroupid = usergroupid;
	 	var ug = new UserGroup();
	 	ug.id = this.xusergroupid;
	 	this.proxy.conn.jsonData = Ext.encode([new Dispatcher({page:'User',action:this.xaction}),ug]);
	}	

}); // eo UserDataStore


com.comrades.LocationDataStore = Ext.extend(Ext.data.Store, {
	listeners:{
		loadexception:showErrorMsg,
		load:loadInspector
	}
	,proxy: new Ext.data.HttpProxy({ 
		 url:frontControllerURL
		,metod:'POST'
		,jsonData:Ext.encode(new Array(new Dispatcher({page:'Location',action:'GetLocations'}))) }
	)
    ,reader :new Ext.data.JsonReader( {
		root :"result",
		id :"id"}
    	,[{name :'name', mapping: 'name'},
    	  {name :'address1', mapping: 'address1'},
    	  {name :'address2', mapping: 'address2'},    	
    	  {name :'city', mapping: 'city'},
    	  {name :'postalCd', mapping: 'postalCd'},
    	  {name :'province', mapping: 'province'},    	  
    	]
    )
	,initComponent : function() {
		Ext.apply(this, {
			name :'com.comrades.LocationDataStore'
		});// eo apply

		// call parent initComponent
		com.comrades.LocationDataStore.superclass.initComponent.apply(this);
	}// eo intiComponent;

}); // eo TypeDataStore



com.comrades.EventDataStore = function(config){
	//apply configuration passed during intitialization
	this.xaction = 'GetEvents';
	var p = new Array();

	
	if (config !=null){
		if (config.xdaterange != null){
			this.xdaterange = config.xdaterange;
			p[p.length] = this.xdaterange;
		};	
		if (config.xattendance != null){
			this.xattendance = config.xattendance;
			p[p.length] = this.xattendance;
		};
		if (config.xaction != null){
			this.xaction = config.xaction;
		};
	};	
	var d = new Dispatcher({page:'Event',action:this.xaction});
	p[p.length]=d;

	this.proxy.conn.jsonData = Ext.encode(p);
		
	Ext.apply(this, config);
	//non-configurable parameters
	
	Ext.apply(this, {
		buttonAlign:'center',
		name:'com.comrades.EventDataStore'	
	});			
	
	//call superclass constructor afterall
	com.comrades.EventDataStore.superclass.constructor.call(this);
};// end of com.comrades.EventDataStore

Ext.extend(com.comrades.EventDataStore,Ext.data.Store, {
	xattendance: null,
	xdaterange:null,
	xaction:null,
	listeners:{
		loadexception:showErrorMsg,
		load:loadInspector
	}
	,proxy: new Ext.data.HttpProxy({ 
		 url:frontControllerURL
		,metod:'POST'
	})
    ,reader :new Ext.data.JsonReader( {
		root :"result",
		id :0}
    	, [
   	    	{name:'id',mapping:'id'},
    		{name:'description',mapping:'description'},
    	    {name:'startDate', mapping:'startDate', type:'date' , dateFormat: fulldatetimeformat}, 
    	    {name:'endDate', mapping:'endDate', type: 'date', dateFormat: fulldatetimeformat}, 
    	    {name:'location',mapping:'location'},
    	    {name:'location.name',mapping:'location.name'},
    	    {name:'cost',mapping:'cost',type:'float'},
    	    {name:'spaceLimit',mapping:'spaceLimit', type:'float'}, 
    	    {name:'minRequired',mapping:'minRequired'},
    	    {name:'recurGroupId', mapping:'recurGroupId'},
    	    {name:'frequency', mapping:'frequency'},
    	    {name:'occurence',mapping:'occurence'},
    	    {name:'attendance',mapping:'attendance'},
    	    {name:'notify',mapping:'notify'},
    	    {name:'restrictLevel',mapping:'restrictLevel'},
    	    {name:'restrictLevel.description',mapping:'restrictLevel.description'},
    	    {name:'notes',mapping:'notes'}      	    
    	  ]
    )

	,setAction:function(_action){
		if (_action == null)
			return;
		
		this.xaction = _action;
	    var d = new Dispatcher({page:'Event', action:this.xaction});
	    var p = new Array();
		p[0]=d;
		
		if (this.xdaterange != null)
			p[p.length] = this.xdaterange;
		
		if (this.xattendee != null)
			p[p.length] = this.xattendance;

	 	this.proxy.conn.jsonData = Ext.encode(p);		
	}
	
	,setSearchCriteria : function(daterange, attendee){
	    var d = new Dispatcher({page:'Event', action:this.xaction});
	    var p = new Array();
		p[0]=d;
		
		this.xdaterange = daterange;
		if (daterange != null)
			p[p.length] = this.xdaterange;
		
		this.xattendance = attendee;
		if (attendee != null)
			p[p.length] = this.xattendance;

	 	this.proxy.conn.jsonData = Ext.encode(p);
	}

	,getDateRange:function(){
		return this.xdaterange;
	}
	,getAttendance:function(){
		return this.xattendance;
	}
	
	,getAction:function(){
		return this.xaction;
	}

}); // eo EventDataStore


com.comrades.HomeEventDataStore = function(config){
	var d = new Dispatcher({page:'Event',action:'GetHomeEvents'});
	var p = new Array();
	p[0]=d;
	if (config !=null && config.xdaterange != null){
			this.xdaterange = config.xdaterange;
			p[p.length] = this.xdaterange;
	};	

	this.proxy.conn.jsonData = Ext.encode(p);
	Ext.apply(this, config);
	com.comrades.HomeEventDataStore.superclass.constructor.call(this);
};// end of com.comrades.HomeEventDataStore


Ext.extend(com.comrades.HomeEventDataStore,Ext.data.Store, {
	xdaterange:null
	,proxy: new Ext.data.HttpProxy({ 
		 url:frontControllerURL
		,metod:'POST'
		,jsonData:Ext.encode(new Array()) }
	)
    ,reader :new Ext.data.JsonReader( {
		root :"result",
		id :0}
    	, [
    	    {name:'id',mapping:'id'},
   			{name:'description',mapping:'description'},
   			{name:'startDate', mapping:'startDate', type:'date' , dateFormat: fulldatetimeformat}, 
   			{name:'endDate', mapping:'endDate', type: 'date', dateFormat: fulldatetimeformat}, 
   			{name:'location',mapping:'location'},
   			{name:'location.name',mapping:'location.name'},
   			{name:'location.address1',mapping:'location.address1'},
   			{name:'location.address2',mapping:'location.address2'},
			{name:'location.city',mapping:'location.city'},
			{name:'cost',mapping:'cost',type:'float'},
   			{name:'spaceLimit',mapping:'spaceLimit', type:'float'}, 
   			{name:'restrictLevel',mapping:'restrictLevel'},
    	    {name:'restrictLevel.description',mapping:'restrictLevel.description'},	
   			{name:'spaceRemain',mapping:'spaceRemain'},
   			{name:'notes',mapping:'notes'}      	    
   		  ]
    )
	
	,initComponent : function() {
		Ext.apply(this, {
			name :'com.comrades.HomeEventDataStore'
		});// eo apply

		// call parent initComponent
		com.comrades.HomeEventDataStore.superclass.initComponent.apply(this);
	}// eo intiComponent

}); // eo HomeEventDataStore
