1
1
sap . 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"
3
4
] , function (
4
- BaseController
5
+ BaseController ,
6
+ JSONModel
5
7
) {
6
8
"use strict" ;
9
+ var _aValidTabKeys = [ "Info" , "Projects" , "Hobbies" , "Notes" ] ;
7
10
return BaseController . extend ( "com.mrb.UI5-Navigation-and-Routing.controller.employee.Resume" , {
8
11
onInit : function ( ) {
9
12
var oRouter = this . getRouter ( ) ;
13
+ this . getView ( ) . setModel ( new JSONModel ( ) , "view" ) ;
10
14
oRouter . getRoute ( "employeeResume" ) . attachMatched ( this . _onRouteMatched , this ) ;
11
15
} ,
12
16
_onRouteMatched : function ( oEvent ) {
13
- var oArgs , oView ;
17
+ var oArgs , oView , oQuery ;
18
+ //Read the passed in arguments
14
19
oArgs = oEvent . getParameter ( "arguments" ) ;
15
20
oView = this . getView ( ) ;
16
21
oView . bindElement ( {
@@ -25,12 +30,35 @@ sap.ui.define([
25
30
}
26
31
}
27
32
} ) ;
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
+ }
28
45
} ,
29
46
_onBindingChange : function ( oEvent ) {
30
47
// No data for the binding
31
48
if ( ! this . getView ( ) . getBindingContext ( ) ) {
32
49
this . getRouter ( ) . getTargets ( ) . display ( "notFound" ) ;
33
50
}
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*/ ) ;
34
62
}
35
63
} ) ;
36
64
} ) ;
0 commit comments