text changes to registration mail content
[namibia] / public / js / app / admin-workspace / systemusers.js
1 ;(function(){
2
3         window._w.systemusers = {
4
5                 itemId        : null,
6                 itemData      : null,
7                 formMeta      : null,
8                 offerId       : null,
9                 offerData     : null,
10                 formOfferMeta : null,
11                 ti            : null,
12                 limited       : false,
13                 newItem       : false,
14
15                 onTemplateReady : function( template, event, eventData )
16                 {
17                         _w.systemusers.ti = _t[template];
18
19                         _w.systemusers.initGrids();
20
21                         // User grid
22                         if (null == App.API.taskContract('gridSystemUser'))
23                         {
24                                 App.API.getTask(
25                                                 'gridSystemUser', 'User', 'Profile.AdminGrid', null,
26                                                 {}, _w.systemusers.loadUserGrid, _w.taskContractError
27                                                 );
28                         }
29                         else
30                         {
31                                 _w.systemusers.loadUserGrid( null, {}, {} );
32                         }
33                 },
34
35                 onTemplatePublished : function( template, event, eventData )
36                 {
37                         $(".gridUserFilter").keypress(function (evt) {
38                                 var charCode = evt.charCode || evt.keyCode;
39                                 if (charCode  == 13) { //Enter key's keycode
40                                         $('#btnUserSearch').click();
41                                 }
42                         });
43
44                         _w.systemusers.ti = _t[template];
45
46                         // User grid
47                         $('#btnUserAdd').click(function() {
48                                 window.location.hash = '/systemuserview?id=0';
49                         });
50             $('#btnUserClearSearch').click(_w.systemusers.clearUserGridContext);
51             $('#btnUserSearch').click(_w.systemusers.searchUserGrid);
52
53                 },
54
55                 exportUserGrid : function()
56                 {
57                         App.API.execTask(
58                                         'gridSystemUser', {}, {'ExportToExcel': true},
59                                         _w.systemusers._onExportReceived, _w.taskExecError,
60                                         'EXPORT', true
61                                         );
62                 },
63
64                 _onExportReceived : function( response )
65                 {
66                         var win = window.open();
67                         win.document.write(response);
68                 },
69
70                 initGrids : function()
71                 {
72
73                         _w.systemusers.ti.hydrate({
74                                 // User grid
75                                 'gridUserTitle': 'Manage system users',
76                                 'gridTitleButtons': {
77                                         constructor: 'Button',
78                                         items: {
79                                                 Export: {
80                                                         preset: 'GridExport',
81                                                         id: 'exportUserGrid',
82                                                         handler: _w.systemusers.exportUserGrid
83                                                 }
84                                         }
85                                 },
86                                 'gridUserColumnHeaders': {
87                                         constructor: 'GridColumnHeader',
88                                         items: {
89                                                 Company: {
90                                                         id: 'gridUserColumn_Company',
91                                                         title: 'DEALERSHIP',
92                                                         orderAsc: {
93                                                                 id: 'gridUserOrder_CompanyAsc',
94                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'company.name', 'ASC')
95                                                         },
96                                                         orderDesc: {
97                                                                 id: 'gridUserOrder_CompanyDesc',
98                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'company.name', 'DESC')
99                                                         }
100                                                 },
101                                                 Name: {
102                                                         id: 'gridUserColumn_Name',
103                                                         title: 'NAME',
104                                                         orderAsc: {
105                                                                 id: 'gridUserOrder_NameAsc',
106                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'profile.firstName', 'ASC')
107                                                         },
108                                                         orderDesc: {
109                                                                 id: 'gridUserOrder_NameDesc',
110                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'profile.firstName', 'DESC')
111                                                         }
112                                                 },
113                                                 Surname: {
114                                                         id: 'gridUserColumn_Surname',
115                                                         title: 'SURNAME',
116                                                         orderAsc: {
117                                                                 id: 'gridUserOrder_SurnameAsc',
118                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'profile.familyName', 'ASC')
119                                                         },
120                                                         orderDesc: {
121                                                                 id: 'gridUserOrder_SurnameDesc',
122                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'profile.familyName', 'DESC')
123                                                         }
124                                                 },
125                                                 Email: {
126                                                         id: 'gridUserColumn_Email',
127                                                         title: 'EMAIL',
128                                                         orderAsc: {
129                                                                 id: 'gridUserOrder_EmailAsc',
130                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'profile.email', 'ASC')
131                                                         },
132                                                         orderDesc: {
133                                                                 id: 'gridUserOrder_EmailDesc',
134                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'profile.email', 'DESC')
135                                                         }
136                                                 },
137                                                 Mobile: {
138                                                         id: 'gridUserColumn_Mobile',
139                                                         title: 'MOBILE',
140                                                         orderAsc: {
141                                                                 id: 'gridUserOrder_MobileAsc',
142                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'profile.mobile', 'ASC')
143                                                         },
144                                                         orderDesc: {
145                                                                 id: 'gridUserOrder_MobileDesc',
146                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'profile.mobile', 'DESC')
147                                                         }
148                                                 },
149                                                 UserType: {
150                                                         id: 'gridUserColumn_UserType',
151                                                         title: 'USER TYPE',
152                                                         orderAsc: {
153                                                                 id: 'gridUserOrder_UserTypeAsc',
154                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'permissions.name', 'ASC')
155                                                         },
156                                                         orderDesc: {
157                                                                 id: 'gridUserOrder_UserTypeDesc',
158                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'permissions.name', 'DESC')
159                                                         }
160                                                 },
161                                                 AssignedTo: {
162                                                         id: 'gridUserColumn_AssignedTo',
163                                                         title: 'ASSIGNED TO',
164                                                         orderAsc: {
165                                                                 id: 'gridUserOrder_AssignedToAsc',
166                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'manager.firstName', 'ASC')
167                                                         },
168                                                         orderDesc: {
169                                                                 id: 'AssignedToDesc',
170                                                                 bind: $.proxy(_w.systemusers.orderUserGrid, this, 'manager.firstName', 'DESC')
171                                                         }
172                                                 }
173                                         }
174                                 },
175                                 'gridUserColumnFilters': {
176                                         constructor: 'GridColumnFilter',
177                                         items: {
178                                                 Company : {
179                                                         id: 'gridUserFilter_Company',
180                                                         context: 'gridUserFilter'
181                                                 },
182                                                 Name: {
183                                                         id: 'gridUserFilter_Name',
184                                                         context: 'gridUserFilter'
185                                                 },
186                                                 Surname: {
187                                                         id: 'gridUserFilter_Surname',
188                                                         context: 'gridUserFilter'
189                                                 },
190                                                 Email: {
191                                                         id: 'gridUserFilter_Email',
192                                                         context: 'gridUserFilter'
193                                                 },
194                                                 Mobile: {
195                                                         id: 'gridUserFilter_Mobile',
196                                                         context: 'gridUserFilter'
197                                                 },
198                                                 UserType: {
199                                                         id: 'gridUserFilter_UserType',
200                                                         context: 'gridUserFilter'
201                                                 },
202                                                 AssignedTo: {
203                                                         id: 'gridUserFilter_AssignedTo',
204                                                         context: 'gridUserFilter'
205                                                 }
206                                         }
207                                 },
208                                 'gridUserRowRepeater': {},
209                                 'gridUserPager': {}
210                         });
211
212                 },
213
214                 loadUserGrid : function( contract, data, options )
215                 {
216                         App.API.execTask(
217                                         'gridSystemUser', data, options,
218                                         _w.systemusers._onUserGridDataReceived, _w.taskExecError
219                                         );
220                 },
221
222                 pageUserGrid : function( page )
223                 {
224                         _w.systemusers.loadUserGrid( {}, {"Grid":{"Page":page}} );
225                 },
226
227                 clearUserGridContext : function()
228                 {
229                         $('.gridUserContext').val('');
230                         $('.gridUserFilter').val('');
231                         _w.systemusers.searchUserGrid();
232                 },
233
234                 searchUserGrid : function()
235                 {
236                         var filter = {
237                                         count: 0,
238                                         filters: {}
239                         };
240
241                         filter = _w.filterIfnotEmpty(filter, 'gridUserFilter_Company', 'company.name');
242                         filter = _w.filterIfnotEmpty(filter, 'gridUserFilter_Name', 'profile.firstName');
243                         filter = _w.filterIfnotEmpty(filter, 'gridUserFilter_Surname', 'profile.familyName');
244                         filter = _w.filterIfnotEmpty(filter, 'gridUserFilter_Email', 'profile.email');
245                         filter = _w.filterIfnotEmpty(filter, 'gridUserFilter_Mobile', 'profile.mobile');
246                         filter = _w.filterIfnotEmpty(filter, 'gridUserFilter_UserType', 'permissions.name');
247                         filter = _w.filterIfnotEmpty(filter, 'gridUserFilter_AssignedTo', 'manager.firstName');
248                         var request = {"Grid":{
249                             "Page": 1,
250                             "Filter": filter.filters
251                           }};
252                         _w.systemusers.loadUserGrid( null, request, {} );
253                 },
254
255                 _onUserGridDataReceived : function( response )
256                 {
257                         _w.systemusers.ti.hydrateParam('gridUserRowRepeater', {});
258                         _w.populateFilters(response.Data.Meta.Filters, {
259                                 'company.name'       : 'gridUserFilter_Company',
260                                 'profile.firstName'  : 'gridUserFilter_Name',
261                                 'profile.familyName' : 'gridUserFilter_Surname',
262                                 'profile.email'      : 'gridUserFilter_Email',
263                                 'profile.mobile'     : 'gridUserFilter_Mobile',
264                                 'permissions.name'   : 'gridUserFilter_UserType',
265                                 'manager.firstName'  : 'gridUserFilter_AssignedTo'
266                         });
267                         var gridData = [];
268                         for (var i = 0; i < response.Data.DataSet.length; i++)
269                         {
270                                 var row = response.Data.DataSet[i];
271                                 gridData.push({
272                                         url: 'systemuserview',
273                                         prepend: {},
274                                         style: {},
275                                         items: {
276                                                 'id'         : row.id,
277                                                 'Company'    : row.company ? row.company.name : '',
278                                                 'Name'       : row.firstName,
279                                                 'Surname'    : row.familyName,
280                                                 'Email'      : row.email,
281                                                 'Mobile'     : row.mobile,
282                                                 'UserType'   : row.permissions ? row.permissions.name : '',
283                                                 'AssignedTo' : row.manager ? row.manager.firstName : ''
284                                 }
285                                 });
286                         }
287                         _w.systemusers.ti.hydrateParam('gridUserRowRepeater', {
288                                 constructor : 'GridDataRow',
289                                 items       : gridData
290                         });
291                         response.Data.Meta.itemName = 'userPager';
292                         response.Data.Meta.bind = _w.systemusers.pageUserGrid;
293                         _w.systemusers.ti.hydrateParam('gridUserPager', {
294                                 constructor : 'GridPager',
295                                 items       : [response.Data.Meta]
296                         });
297                 },
298
299                 orderUserGrid : function(field, direction)
300                 {
301                         var order = {};
302                         order[field] = direction;
303                         _w.systemusers.loadUserGrid( {}, {"Grid":{"Page": 1, "OrderBy": order}} );
304                 }
305
306         };
307
308 })();