Ext.ns('Ext.pv.inbox');
Ext.pv.inbox.InboxOptionsForm = Ext.extend(Ext.form.FormPanel, {
	border : true,
	labelWidth : 1,
	bodyStyle : 'padding: 10 10 10 10px',
	
	contextPath : null,
	personId : 0,
	record : null,
	
	// Localized string
	sendModeratedEmailsLabel : 'Send me an email when there are shared items to review in my inbox.',
	allowInboxAdminLabel : 'Allow funeral home administrators to manage my inbox.',
	
	isInboxManagerEnabled : false,


	/**
	 * initComponent
	 * 
	 * @protected
	 */
	initComponent : function() {

		// Build the form fields
		this.items = this.buildFormFields();

		// super
		Ext.pv.inbox.InboxOptionsForm.superclass.initComponent.call(this);
	},
	
	/**
	 * loadRecord
	 * 
	 * @param {Record} rec
	 */
	loadRecord : function(rec) {
		this.record = rec;
		if (rec != null) {
			this.getForm().loadRecord(rec);
		} else {
			this.getForm().reset();
		}
	},
	
	/**
	 * load
	 * 
	 * @param {int} vendorId
	 */
	load : function(personId) {
		if (this.dataStore==null) {
			this.dataStore = new Ext.data.Store({
				url: this.contextPath + '/siteAdmin/inbox/loadSiteOptionsJSON.inboxInfo',
				reader : new Ext.data.JsonReader({
					idProperty : 'personId',
					root : 'rows',
					fields : [
					    {name : 'personId'},
						{name : 'enableInboxEmails'},
						{name : 'allowInboxAdmin'}
					]
				}),
				form: this,
				listeners : { 
					load : function(store, records, options) {
						if (records.length>0) {
							this.form.loadRecord(records[0]);
						}
					}
				}
			});
		}
		this.dataStore.load({
			params: { 
				personId: personId
			}
		});
	},
	
	/**
	 * buildform
	 * 
	 * @private
	 */
	buildFormFields : function() {

		var items = new Array();

		items[items.length] = {
			xtype : 'hidden',
			name : 'personId'
		};
		
		items[items.length] = new Ext.form.Checkbox( {
			boxLabel : this.sendModeratedEmailsLabel,
			labelSeparator: '',
			name : 'enableInboxEmails',
			checked : false,
			style: {marginBottom: '0px', marginTop: '0px'}
		});
		
		if (this.isInboxManagerEnabled) {
			items[items.length] = new Ext.form.Checkbox( {
				boxLabel : this.allowInboxAdminLabel,
				labelSeparator: '',
				name : 'allowInboxAdmin',
				checked : false,
				style: {marginBottom: '0px', marginTop: '0px'}
			});
		}
		
		return items;
	}

});
