text: sap.ui.define([
  	"./BaseController",
  	"sap/ui/model/json/JSONModel",
  	"sap/ui/core/routing/History",
  	"../model/formatter"
  ], function (BaseController, JSONModel, History, formatter) {
  	"use strict";
  
  	return BaseController.extend("ns.mitigations.controller.Object", {
  
  		formatter: formatter,
  
  		/* =========================================================== */
  		/* lifecycle methods                                           */
  		/* =========================================================== */
  
  		/**
  		 * Called when the worklist controller is instantiated.
  		 * @public
  		 */
  		onInit : function () {
  			// Model used to manipulate control states. The chosen values make sure,
  			// detail page shows busy indication immediately so there is no break in
  			// between the busy indication for loading the view's meta data
  			var oViewModel = new JSONModel({
  					busy : true,
  					delay : 0
  				});
  			this.getRouter().getRoute("object").attachPatternMatched(this._onObjectMatched, this);
  			this.setModel(oViewModel, "objectView");
  		},
  		/* =========================================================== */
  		/* event handlers                                              */
  		/* =========================================================== */
  
  		/**
  		 * Event handler when the share in JAM button has been clicked
  		 * @public
  		 */
  		onShareInJamPress : function () {
  			var oViewModel = this.getModel("objectView"),
  				oShareDialog = sap.ui.getCore().createComponent({
  					name: "sap.collaboration.components.fiori.sharing.dialog",
  					settings: {
  						object:{
  							id: location.href,
  							share: oViewModel.getProperty("/shareOnJamTitle")
  						}
  					}
  				});
  			oShareDialog.open();
  		},
  
  
  		/* =========================================================== */
  		/* internal methods                                            */
  		/* =========================================================== */
  
  		/**
  		 * Binds the view to the object path.
  		 * @function
  		 * @param {sap.ui.base.Event} oEvent pattern match event in route 'object'
  		 * @private
  		 */
  		_onObjectMatched : function (oEvent) {
  			var sObjectId =  oEvent.getParameter("arguments").objectId;
  			this._bindView("/Mitigations" + sObjectId);
  		},
  
  		/**
  		 * Binds the view to the object path.
  		 * @function
  		 * @param {string} sObjectPath path to the object to be bound
  		 * @private
  		 */
  		_bindView : function (sObjectPath) {
  			var oViewModel = this.getModel("objectView");
  
  			this.getView().bindElement({
  				path: sObjectPath,
  				events: {
  					change: this._onBindingChange.bind(this),
  					dataRequested: function () {
  						oViewModel.setProperty("/busy", true);
  					},
  					dataReceived: function () {
  						oViewModel.setProperty("/busy", false);
  					}
  				}
  			});
  		},
  
  		_onBindingChange : function () {
  			var oView = this.getView(),
  				oViewModel = this.getModel("objectView"),
  				oElementBinding = oView.getElementBinding();
  
  			// No data for the binding
  			if (!oElementBinding.getBoundContext()) {
  				this.getRouter().getTargets().display("objectNotFound");
  				return;
  			}
  
  			var oResourceBundle = this.getResourceBundle();
  
  			oView.getBindingContext().requestObject().then((function (oObject) {
  				var sObjectId = oObject.ID,
  					sObjectName = oObject.ID;
  
  				// Add the object page to the flp routing history
  				this.addHistoryEntry({
  					title: this.getResourceBundle().getText("objectTitle") + " - " + sObjectName,
  					icon: "sap-icon://enter-more",
  					intent: "#Mitigations-display&/Mitigations(" + sObjectId + ")"
  				});
  
  				oViewModel.setProperty("/busy", false);
  				oViewModel.setProperty("/saveAsTileTitle", oResourceBundle.getText("saveAsTileTitle", [sObjectName]));
  				oViewModel.setProperty("/shareOnJamTitle", sObjectName);
  				oViewModel.setProperty("/shareSendEmailSubject",
  					oResourceBundle.getText("shareSendEmailObjectSubject", [sObjectId]));
  				oViewModel.setProperty("/shareSendEmailMessage",
  					oResourceBundle.getText("shareSendEmailObjectMessage", [sObjectName, sObjectId, location.href]));
  			}).bind(this));
  		}
  
  	});
  
  });