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

var ProvisioningAssistant = Class.create({
    initialize: function(type, msg, isCancelabel ,errorCode) {
		this.type = type;
		this.isCancelabel = isCancelabel;
		this.errorCode = errorCode;
    },
    
    setup: function(){
		
		var onOK = this.onTapOK.bindAsEventListener(this);
		var onCancel = this.onTapCancel.bindAsEventListener(this);
		this.controller.get('okButton').addEventListener(Mojo.Event.tap, onOK);
		this.controller.get('cancelButton').addEventListener(Mojo.Event.tap, onCancel);
		if (this.isCancelabel == false)
			this.controller.get('cancelButton').disabled = true;
		if (this.errorCode != undefined) {
			this.controller.get('PVSErrorCodeId').update(this.errorCode);
			this.controller.get('PVSErrorCodeId').show();
			if (this.type == "ServerPushPRL")
				this.message = $L("PRL update could not be prepared. If the problem persists, call Sprint Customer Service.");
			else
				this.message = $L("PCS Vision Services could not be prepared. If the problem persists, call Sprint Customer Service.");
			this.controller.get('PVSnotifymsgid').update(this.message);
			this.controller.get('cancelButton').hide();
			this.controller.get('okButton').show();
		}
		else {
			if (this.type == "ServerPushPRL")
				this.message = "Updating PRL";
			else
				this.message = "Preparing Vision Services";
			this.controller.get('PVSnotifymsgid').update(this.message);
				
			this.controller.get('PVSErrorCodeId').hide();
			this.controller.get('cancelButton').show();
			this.controller.get('okButton').hide();
		}	
	},
	
	onTapOK:function(){
		this.controller.window.close();
	},
	onTapCancel:function(){
		this.cancelProvisonReq = new Mojo.Service.Request('palm://com.palm.provisioning/Cancel', {});
		this.cancelOmadmReq =  new Mojo.Service.Request('palm://com.palm.omadm/Cancel', {});
		this.controller.window.close();
	},  
	updateDisplay: function(type, msg, isCancelabel ,errorCode) {
	
		if (isCancelabel == true) {
			this.controller.get('cancelButton').disabled = false;
			this.controller.get('PVSErrorCodeId').hide();	
		}
		else if (isCancelabel == false) {
			this.controller.get('cancelButton').disabled = true;
			this.controller.get('PVSErrorCodeId').hide();	
		}
		else if (msg == "success") {
			this.controller.window.close();
		}
		else if (msg == "failure") {
			
			if (this.type == "ServerPushPRL")
				this.message = $L("PRL update could not be prepared. If the problem persists, call Sprint Customer Service.");
			else
				this.message = $L("PCS Vision Services could not be prepared. If the problem persists, call Sprint Customer Service.");
			this.controller.get('PVSnotifymsgid').update(this.message);
			
			if (errorCode !== undefined) {
				this.controller.get('PVSErrorCodeId').update(errorCode);
				this.controller.get('PVSErrorCodeId').show();	
			}
			else
				this.controller.get('PVSErrorCodeId').hide();	
		}
		
	},
	
	close: function() {
		this.controller.window.close();
	} ,
	
});

