/* Copyright 2009 Palm, Inc.  All rights reserved. */

var AddressEditAssistant = Class.create({
	initialize: function(address, listModel, cb){
		this.address = address;
		this.listModel = listModel;
		this.cb = cb;
	},
	
	setup: function(){
		this.controller.get("FieldGroup").update(Mojo.View.render({
			template:'address-edit/fields',
			object: this.address
		}));
		
    this.controller.setupWidget('streetAddressField', {modelProperty:'streetAddress',multiline:true, enterSubmits:true}, this.address);
    this.controller.setupWidget('cityField', {modelProperty:'city',multiline:true, enterSubmits:true}, this.address);
    this.controller.setupWidget('stateField', {modelProperty:'state',multiline:true, enterSubmits:true}, this.address);
    this.controller.setupWidget('zipField', {modelProperty:'zipCode',multiline:true, enterSubmits:true}, this.address);
    this.controller.setupWidget('countryField', {modelProperty:'country',multiline:true, enterSubmits:true}, this.address);

	},
	
	cleanup: function(){
		this.address.freeformAddress = null;
		this.address.freeformAddress = this.address.getOneLine();
		this.address.setDirty();
		this.cb(this.address);
	}
	
});
