<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<meta charset="UTF-8">
	<title>SAPUI5 Walkthrough</title>
	<script
		id="sap-ui-bootstrap"
		src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js'
		data-sap-ui-theme="sap_bluecrystal"
    data-sap-ui-libs="sap.m"
    data-sap-ui-xx-bindingSyntax="complex"
		data-sap-ui-resourceroots='{
				"sap.ui.demo.wt": "./"
			}'>
	</script>
	<style>
	  .labelStyle{
      font-size: 0.975rem;
      font-weight: bold;
      margin-top: 15px;
    }
    .hBoxStyle{
    margin-left:35%;
    }  
    .inputStyle{
    margin-left:5%;
    }
	</style>
	<script>
				new sap.m.Shell("ShellId",{title: "Model Demo",
					showLogout: false,
					app: new sap.ui.core.ComponentContainer({
						name: "sap.ui.demo.wt"		
					})
				}).placeAt("content");
	</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
// Code goes here

/* Styles go here */

.labelStyle{
      font-size: 0.975rem;
      font-weight: bold;
      margin-top: 18%;
}
.hBoxStyle{
  margin-left:35%;
}
.inputStyle{
  margin-left:10%;
}
jQuery.sap.declare("sap.ui.demo.wt.Component");  
sap.ui.core.UIComponent.extend("sap.ui.demo.wt.Component", {  
   createContent : function () {  
  // create root view  
	  var oView = sap.ui.view({  
		  id : "app",  
		  viewName : "sap.ui.demo.wt.Home",  
		  type : "JS",  
	  });  
	  
	var dataObject = [
				{Product: "Power Projector 4713", Weight: "33"},
				{Product: "Gladiator MX", Weight: "33"},
				{Product: "Hurricane GX", Weight: "45"},
				{Product: "Webcam", Weight: "33"},
				{Product: "Monitor Locking Cable", Weight: "41"},
				{Product: "Laptop Case", Weight: "64"}];
	
	var model = new sap.ui.model.json.JSONModel();
		model.setData({
			modelData: {
			productsData : []
			}
			});
		oView.setModel(model);
		oView.getModel().setProperty("/modelData/productsData", dataObject); 
       
return oView;  
  }  
});  
sap.ui.jsview("sap.ui.demo.wt.Home", {  
  /** Specifies the Controller belonging to this View. 
  * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller. 
  * @memberOf routingdemo.App 
  */  
  getControllerName : function() {  
  return "sap.ui.demo.wt.Home";  
  },  
  /** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. 
  * Since the Controller is given to this method, its event handlers can be attached right away. 
  * @memberOf routingdemo.App 
  */  
  createContent : function(oController) {  
  this.setDisplayBlock(true); 
  var oBusyDialog_Global = new sap.m.BusyDialog("GlobalBusyDialog",{title:"Please wait. . . "});
	this.app = new sap.m.App("mainApp",{initialPage:"FirstPage"});

		var page = sap.ui.jsview("FirstPage", "sap.ui.demo.wt.FirstPage");
		this.app.addPage(page);
  return this.app;  
  }  
});
sap.ui.controller("sap.ui.demo.wt.Home", {

/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf zui5_sample.Home
*/
//	onInit: function() {
//
//	},

/**
* Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered
* (NOT before the first rendering! onInit() is used for that one!).
* @memberOf zui5_sample.Home
*/
//	onBeforeRendering: function() {
//
//	},

/**
* Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.
* This hook is the same one that SAPUI5 controls get after being rendered.
* @memberOf zui5_sample.Home
*/
//	onAfterRendering: function() {
//
//	},

/**
* Called when the Controller is destroyed. Use this one to free resources and finalize activities.
* @memberOf zui5_sample.Home
*/
//	onExit: function() {
//
//	}

});
sap.ui.jsview("sap.ui.demo.wt.FirstPage", {  
  /** Specifies the Controller belonging to this View. 
  * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller. 
  * @memberOf routingdemo.App 
  */  
  getControllerName : function() {  
  return "sap.ui.demo.wt.FirstPage";  
  },  
  /** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. 
  * Since the Controller is given to this method, its event handlers can be attached right away. 
  * @memberOf routingdemo.App 
  */  
  createContent : function(oController) {  
  var controller = this.oController;
	var page = new sap.m.Page({
		title:"First Page",
		enableScrolling: true
	}); 
	
	var oList = new sap.m.List({mode : sap.m.ListMode.SingleSelectMaster
		,showSeparators : sap.m.ListSeparators.All
		,swipeDirection : sap.m.SwipeDirection.Both
		,rememberSelections : false
		,selectionChange : function(oEvent){
		  controller.onPress(oEvent);
		}});

	var oTemplate = new sap.m.StandardListItem({
		title : "{Product}"
		,info :"{Weight}"
			,icon : "sap-icon://product"
				,type : sap.m.ListType.Navigation
	});

	var oSorter = new sap.ui.model.Sorter("Product", false, false);
	oList.bindItems("/modelData/productsData",oTemplate,oSorter);
	page.addContent(oList);
	return page;
  }  
});
sap.ui.controller("sap.ui.demo.wt.FirstPage", {

/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf table_v01.Main
*/

	onInit: function() {

	},
	
	onPress: function(oEvent){
  var oBindingPath = this.getView().getModel().getProperty(oEvent.getSource().getBinding("items").getContexts()[oEvent.getSource().indexOfItem(oEvent.getParameters().listItem)].sPath);
  var oSelectedTitle = oBindingPath.Product;
  var oSelectedInfo = oBindingPath.Weight;
  var app = sap.ui.getCore().byId("mainApp");
		var page = app.getPage("SecondPage");
	if(page === null )
	{
	var page = new sap.ui.jsview("SecondPage", "sap.ui.demo.wt.SecondPage");
		app.addPage(page);
	}

	app.to(page,"slide",{oTitle:oSelectedTitle,oInfo:oSelectedInfo});
	}

});
sap.ui.jsview("sap.ui.demo.wt.SecondPage", {  
  /** Specifies the Controller belonging to this View. 
  * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller. 
  * @memberOf routingdemo.App 
  */  
  getControllerName : function() {  
  return "sap.ui.demo.wt.SecondPage";  
  },  
  /** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. 
  * Since the Controller is given to this method, its event handlers can be attached right away. 
  * @memberOf routingdemo.App 
  */  
  createContent : function(oController) {  
    var oFirstTitle;
    var oFirstInfo;
  var controller = this.oController;
	var page = new sap.m.Page({
		title:"Second Page",
		showNavButton : true,
		navButtonPress: controller.onPress,
		enableScrolling: true
	}); 
	
	this.addEventDelegate({
           					onBeforeShow: function(event) {
           var oBusyDialog = sap.ui.getCore().byId("GlobalBusyDialog");
			    oBusyDialog.open();
					var params = event.data;
					var oFirstTitle = params.oTitle;
					var oFirstInfo = params.oInfo;
					sap.ui.getCore().byId("oLabel").setText(oFirstTitle);
					sap.ui.getCore().byId("oInput").setValue(oFirstInfo);
       				 	},
       				 	onAfterShow: function(event){
       				 	 var oBusyDialog = sap.ui.getCore().byId("GlobalBusyDialog");
			          oBusyDialog.close();
       				 	}
       		 		}, this);
       		 		
    var oProductText = new sap.m.Label("oLabel").addStyleClass("labelStyle");
    var oWeightInput = new sap.m.Input("oInput").addStyleClass("inputStyle");
    var oHBox = new sap.m.HBox({justifyContent:"Center", items:[oProductText,oWeightInput]});
    page.addContent(oHBox);

	return page;
  }  
});
sap.ui.controller("sap.ui.demo.wt.SecondPage", {

/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf table_v01.Main
*/

	onInit: function() {

	},
	
	onPress: function(oEvent){
		var app = sap.ui.getCore().byId("mainApp");
		app.back();
	}

});