11sap . ui . define ( [
2- "com/mrb/UI5-Navigation-and-Routing/controller/BaseController"
2+ "com/mrb/UI5-Navigation-and-Routing/controller/BaseController" ,
3+ "sap/ui/model/json/JSONModel"
34] , function (
4- BaseController
5+ BaseController ,
6+ JSONModel
57) {
68 "use strict" ;
9+ var _aValidTabKeys = [ "Info" , "Projects" , "Hobbies" , "Notes" ] ;
710 return BaseController . extend ( "com.mrb.UI5-Navigation-and-Routing.controller.employee.Resume" , {
811 onInit : function ( ) {
912 var oRouter = this . getRouter ( ) ;
13+ this . getView ( ) . setModel ( new JSONModel ( ) , "view" ) ;
1014 oRouter . getRoute ( "employeeResume" ) . attachMatched ( this . _onRouteMatched , this ) ;
1115 } ,
1216 _onRouteMatched : function ( oEvent ) {
13- var oArgs , oView ;
17+ var oArgs , oView , oQuery ;
18+ //Read the passed in arguments
1419 oArgs = oEvent . getParameter ( "arguments" ) ;
1520 oView = this . getView ( ) ;
1621 oView . bindElement ( {
@@ -25,12 +30,35 @@ sap.ui.define([
2530 }
2631 }
2732 } ) ;
33+ oQuery = oArgs [ "?query" ] ;
34+ if ( oQuery && _aValidTabKeys . indexOf ( oQuery . tab ) > - 1 ) {
35+ oView . getModel ( "view" ) . setProperty ( "/selectedTabKey" , oQuery . tab ) ;
36+ } else {
37+ // the default query param should be visible at all time
38+ this . getRouter ( ) . navTo ( "employeeResume" , {
39+ employeeId : oArgs . employeeId ,
40+ "?query" : {
41+ tab : _aValidTabKeys [ 0 ]
42+ }
43+ } , true /*no history*/ ) ;
44+ }
2845 } ,
2946 _onBindingChange : function ( oEvent ) {
3047 // No data for the binding
3148 if ( ! this . getView ( ) . getBindingContext ( ) ) {
3249 this . getRouter ( ) . getTargets ( ) . display ( "notFound" ) ;
3350 }
51+ } ,
52+ onTabSelect : function ( oEvent ) {
53+ var oCtx = this . getView ( ) . getBindingContext ( ) ;
54+ //https://sapui5.hana.ondemand.com/#/api/sap.ui.core.routing.Router%23methods/navTo
55+ //:?queryParameter: -> :: -> optional | {someParameter} -> {} -> mandatory
56+ this . getRouter ( ) . navTo ( "employeeResume" , {
57+ employeeId : oCtx . getProperty ( "EmployeeID" ) ,
58+ "?query" : {
59+ tab : oEvent . getParameter ( "selectedKey" )
60+ }
61+ } , true /*without history*/ ) ;
3462 }
3563 } ) ;
3664} ) ;
0 commit comments