FrontAppBootstrap.prototype = new PastelBaseBootstrap();
FrontAppBootstrap.prototype.constructor = FrontAppBootstrap;

function FrontAppBootstrap() {
	
	// set default error handler for ajax requests
	this.setDefaultAjaxErrorHandler($.proxy(function(responseText, failedAction) {
		var error = $.evalJSON(responseText);
		var errorCode = parseInt(error.code);
		switch (errorCode) {
			case 900: // common error
				this._showError(error);
				break;
		}
	}, this));
	
	this._showError = function(error) {
		var error = {
				title: translate('Error'),
				subtitle: translate('Unexpected error'),
				text: translate('Prevent_further_errors'),
				feedback: true,
				buttons: ["cancel", "send"],
				onAction: function(type, data, sender){
								if (type == "send"){
									var logId = data.payload.logId;
									$.ajax({
										url: "/bg/error/feedback",
										data: {logId: logId, feedback: data.feedback},
										type: "POST"
									});
								}
			    		  },
				payload: {logId: error.logId, url: error.url }
		};
		this.alertManager.show(error);
	};
	
	// set global options to searchBox plugin
	jQuery.searchBox.globalOptions.onSearchError = $.proxy(function(XMLHttpRequest, textStatus, errorThrown) {
		var responseText = XMLHttpRequest.responseText;
		this.getDefaultAjaxErrorHandler()(responseText);
	}, this);
	
	// set validator highlight class
	PastelValidator.options.highlightClass = "error";	
}
_APP = new FrontAppBootstrap();
