Ext.ns('Ext.pv.profile');
Ext.pv.profile.UploadPhotoDialog = Ext.extend(Ext.Window, {
	frame : true,
	layout : 'fit',
	forceLayout : true,
	autoScroll : true,
	width : 420,
	height : 150,
	modal : true,
	resizable : false,
	
	// Localized strings
	title : 'Upload new profile photo',
	okButtonText : 'OK',
	cancelButtonText : 'Cancel',
	alertTitle : 'Message',

	direction : 'ltr',
	personId : 0,
	contextPath : null,
	callback : null,
	

	/**
	 * initComponent
	 * 
	 * @protected
	 */
	initComponent : function() {
		
		if (this.direction=='rtl') {
			this.style = 'direction:rtl';
		}
	
		this.form = new Ext.pv.profile.UploadPhotoForm({
			contextPath : this.contextPath,
			personId : this.personId
		});
		this.items = [this.form];
		
		// Build the buttons
		this.buttons = [ {
			text : this.okButtonText,
			handler : this.onOk,
			scope : this
		},{
			text : this.cancelButtonText,
			handler : this.onCancel,
			scope : this
		} ];
		
		// super
		Ext.pv.profile.UploadPhotoDialog.superclass.initComponent.call(this);
		
	},

	onOk : function() {
		var errorMessage = this.form.validate();
		if (errorMessage!=null) {
			Ext.Msg.alert(this.alertTitle,errorMessage);
			return;
		}
		
		var myThis = this;
		this.form.saveRecord(
			function() {
				myThis.callback();
				myThis.close();
			}
		);
	},
	
	onCancel : function() {
		this.close();
	}

});
