@@ -5,7 +5,7 @@ sap.ui.define([
5
5
"sap/ui/model/Sorter" ,
6
6
"sap/m/ViewSettingsDialog" ,
7
7
"sap/m/ViewSettingsItem"
8
- ] , function (
8
+ ] , function (
9
9
BaseController ,
10
10
Filter ,
11
11
FilterOperator ,
@@ -18,25 +18,45 @@ sap.ui.define([
18
18
return BaseController . extend ( "com.mrb.UI5-Navigation-and-Routing.controller.employee.overview.EmployeeOverviewContent" , {
19
19
20
20
onInit : function ( ) {
21
+
22
+ var oRouter = this . getRouter ( ) ;
23
+
21
24
this . _oTable = this . byId ( "employeesTable" ) ;
22
25
this . _oVSD = null ;
23
26
this . _sSortField = null ;
24
27
this . _bSortDescending = false ;
25
28
this . _aValidSortFields = [ "EmployeeID" , "FirstName" , "LastName" ] ;
26
29
this . _sSearchQuery = null ;
30
+ this . _oRouterArgs = null ;
27
31
28
32
this . _initViewSettingsDialog ( ) ;
33
+
34
+ // make the search bookmarkable
35
+ oRouter . getRoute ( "employeeOverview" ) . attachMatched ( this . _onRouteMatched , this ) ;
36
+ } ,
37
+
38
+ _onRouteMatched : function ( oEvent ) {
39
+ // save the current query state
40
+ this . _oRouterArgs = oEvent . getParameter ( "arguments" ) ;
41
+ //make sure we either have a value or empty hand empty object
42
+ this . _oRouterArgs [ "?query" ] = this . _oRouterArgs [ "?query" ] || { } ;
43
+ // search/filter via URL hash
44
+ this . _applySearchFilter ( this . _oRouterArgs [ "?query" ] . search ) ;
29
45
} ,
30
46
31
- onSortButtonPressed : function ( ) {
47
+ onSortButtonPressed : function ( ) {
32
48
this . _oVSD . open ( ) ;
33
49
} ,
34
50
35
- onSearchEmployeesTable : function ( oEvent ) {
36
- this . _applySearchFilter ( oEvent . getSource ( ) . getValue ( ) ) ;
51
+ onSearchEmployeesTable : function ( oEvent ) {
52
+ //this._applySearchFilter(oEvent.getSource().getValue());
53
+ var oRouter = this . getRouter ( ) ;
54
+ // update the hash with the current search term
55
+ this . _oRouterArgs [ "?query" ] . search = oEvent . getSource ( ) . getValue ( ) ;
56
+ oRouter . navTo ( "employeeOverview" , this . _oRouterArgs , true /*no history*/ ) ;
37
57
} ,
38
58
39
- _initViewSettingsDialog : function ( ) {
59
+ _initViewSettingsDialog : function ( ) {
40
60
this . _oVSD = new ViewSettingsDialog ( "vsd" , {
41
61
confirm : function ( oEvent ) {
42
62
var oSortItem = oEvent . getParameter ( "sortItem" ) ;
@@ -48,7 +68,7 @@ sap.ui.define([
48
68
this . _oVSD . addSortItem ( new ViewSettingsItem ( {
49
69
key : "EmployeeID" ,
50
70
text : "Employee ID" ,
51
- selected : true // by default the MockData is sorted by EmployeeID
71
+ selected : true // by default the MockData is sorted by EmployeeID
52
72
} ) ) ;
53
73
54
74
this . _oVSD . addSortItem ( new ViewSettingsItem ( {
@@ -64,7 +84,7 @@ sap.ui.define([
64
84
} ) ) ;
65
85
} ,
66
86
67
- _applySearchFilter : function ( sSearchQuery ) {
87
+ _applySearchFilter : function ( sSearchQuery ) {
68
88
var aFilters , oFilter , oBinding ;
69
89
70
90
// first check if we already have this search value
@@ -79,7 +99,10 @@ sap.ui.define([
79
99
if ( sSearchQuery && sSearchQuery . length > 0 ) {
80
100
aFilters . push ( new Filter ( "FirstName" , FilterOperator . Contains , sSearchQuery ) ) ;
81
101
aFilters . push ( new Filter ( "LastName" , FilterOperator . Contains , sSearchQuery ) ) ;
82
- oFilter = new Filter ( { filters : aFilters , and : false } ) ; // OR filter
102
+ oFilter = new Filter ( {
103
+ filters : aFilters ,
104
+ and : false
105
+ } ) ; // OR filter
83
106
} else {
84
107
oFilter = null ;
85
108
}
@@ -95,7 +118,7 @@ sap.ui.define([
95
118
* @param {string } sortDescending true or false as a string or boolean value to specify a descending sorting
96
119
* @private
97
120
*/
98
- _applySorter : function ( sSortField , sortDescending ) {
121
+ _applySorter : function ( sSortField , sortDescending ) {
99
122
var bSortDescending , oBinding , oSorter ;
100
123
101
124
// only continue if we have a valid sort field
@@ -105,7 +128,7 @@ sap.ui.define([
105
128
if ( typeof sortDescending === "string" ) {
106
129
bSortDescending = sortDescending === "true" ;
107
130
} else if ( typeof sortDescending === "boolean" ) {
108
- bSortDescending = sortDescending ;
131
+ bSortDescending = sortDescending ;
109
132
} else {
110
133
bSortDescending = false ;
111
134
}
@@ -127,7 +150,7 @@ sap.ui.define([
127
150
}
128
151
} ,
129
152
130
- _syncViewSettingsDialogSorter : function ( sSortField , bSortDescending ) {
153
+ _syncViewSettingsDialogSorter : function ( sSortField , bSortDescending ) {
131
154
// the possible keys are: "EmployeeID" | "FirstName" | "LastName"
132
155
// Note: no input validation is implemented here
133
156
this . _oVSD . setSelectedSortItem ( sSortField ) ;
@@ -136,4 +159,4 @@ sap.ui.define([
136
159
137
160
} ) ;
138
161
139
- } ) ;
162
+ } ) ;
0 commit comments