initial commit
[namibia] / public / js / app / admin-workspace / xmlrpcrequestlog.js
1 ;(function(){
2
3         window._w.xmlrpcrequestlog = {
4
5                 ti : null,
6
7                 onTemplateReady : function( template, event, eventData )
8                 {
9                         _w.xmlrpcrequestlog.ti = _t[template];
10
11                         _w.xmlrpcrequestlog.initGrids();
12
13                         // XmlRpc grid
14                         if (null == App.API.taskContract('gridSystemXmlRpcRequest'))
15                         {
16                                 App.API.getTask(
17                                                 'gridSystemXmlRpcRequest', 'Valuation', 'XmlRpcRequestLog.Grid', null,
18                                                 {}, _w.xmlrpcrequestlog.loadXmlRpcGrid, _w.taskContractError
19                                                 );
20                         }
21                         else
22                         {
23                                 _w.xmlrpcrequestlog.loadXmlRpcGrid( null, {}, {} );
24                         }
25                 },
26
27                 onTemplatePublished : function( template, event, eventData )
28                 {
29                         $(".gridXmlRpcFilter").keypress(function (evt) {
30                                 var charCode = evt.charCode || evt.keyCode;
31                                 if (charCode  == 13) { //Enter key's keycode
32                                         $('#btnXmlRpcSearch').click();
33                                 }
34                         });
35
36                         _w.xmlrpcrequestlog.ti = _t[template];
37
38                         // XmlRpc grid
39             $('#btnXmlRpcClearSearch').click(_w.xmlrpcrequestlog.clearXmlRpcGridContext);
40             $('#btnXmlRpcSearch').click(_w.xmlrpcrequestlog.searchXmlRpcGrid);
41
42                 },
43
44                 exportXmlRpcGrid : function()
45                 {
46                         App.API.execTask(
47                                         'gridSystemXmlRpcRequest', {}, {'ExportToExcel': true},
48                                         _w.xmlrpcrequestlog._onExportReceived, _w.taskExecError,
49                                         'EXPORT', true
50                                         );
51                 },
52
53                 initGrids : function()
54                 {
55
56                         _w.xmlrpcrequestlog.ti.hydrate({
57                                 // XmlRpc grid
58                                 'gridXmlRpcTitle': 'View xml-rpc request logs',
59                                 'gridTitleButtons': {
60                                         constructor: 'Button',
61                                         items: {
62                                                 /*Export: {
63                                                         preset: 'GridExport',
64                                                         id: 'exportAuctionGrid',
65                                                         handler: _w.xmlrpcrequestlog.exportXmlRpcGrid
66                                                 }*/
67                                         }
68                                 },
69                                 'gridXmlRpcColumnHeaders': {
70                                         constructor: 'GridColumnHeader',
71                                         items: {
72                                                 ClientName: {
73                                                         id: 'gridXmlRpcColumn_ClientName',
74                                                         title: 'CLIENT NAME',
75                                                         orderAsc: {
76                                                                 id: 'gridXmlRpcOrder_ClientNameAsc',
77                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcClient.clientName', 'ASC')
78                                                         },
79                                                         orderDesc: {
80                                                                 id: 'gridXmlRpcOrder_ClientNameDesc',
81                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcClient.clientName', 'DESC')
82                                                         }
83                                                 },
84                                                 ValuationNumber: {
85                                                         id: 'gridXmlRpcColumn_ValuationNumber',
86                                                         title: 'VALUATION NUMBER',
87                                                         orderAsc: {
88                                                                 id: 'gridXmlRpcOrder_ValuationNumberAsc',
89                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'valuation.valuationNumber', 'ASC')
90                                                         },
91                                                         orderDesc: {
92                                                                 id: 'gridXmlRpcOrder_ValuationNumberDesc',
93                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'valuation.valuationNumber', 'DESC')
94                                                         }
95                                                 },
96                                                 ClientApiId: {
97                                                         id: 'gridXmlRpcColumn_ClientApiId',
98                                                         title: 'API ID',
99                                                         orderAsc: {
100                                                                 id: 'gridXmlRpcOrder_ClientApiIdAsc',
101                                                                 bind: $.proxy(_w.xmlrpcclients.orderXmlRpcGrid, this, 'xmlRpcRequestLog.clientApiId', 'ASC')
102                                                         },
103                                                         orderDesc: {
104                                                                 id: 'gridXmlRpcOrder_ClientApiIdDesc',
105                                                                 bind: $.proxy(_w.xmlrpcclients.orderXmlRpcGrid, this, 'xmlRpcRequestLog.clientApiId', 'DESC')
106                                                         }
107                                                 },
108                                                 IpAddress: {
109                                                         id: 'gridXmlRpcColumn_IpAddress',
110                                                         title: 'IP ADDRESS',
111                                                         orderAsc: {
112                                                                 id: 'gridXmlRpcOrder_IpAddressAsc',
113                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcRequestLog.ipAddress', 'ASC')
114                                                         },
115                                                         orderDesc: {
116                                                                 id: 'gridXmlRpcOrder_IpAddressDesc',
117                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcRequestLog.ipAddress', 'DESC')
118                                                         }
119                                                 },
120                                                 MethodName: {
121                                                         id: 'gridXmlRpcColumn_MethodName',
122                                                         title: 'METHOD',
123                                                         orderAsc: {
124                                                                 id: 'gridXmlRpcOrder_MethodNameAsc',
125                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcRequestLog.methodName', 'ASC')
126                                                         },
127                                                         orderDesc: {
128                                                                 id: 'gridXmlRpcOrder_MethodNameDesc',
129                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcRequestLog.methodName', 'DESC')
130                                                         }
131                                                 },
132                                                 Created: {
133                                                         id: 'gridXmlRpcColumn_Created',
134                                                         title: 'CREATED',
135                                                         orderAsc: {
136                                                                 id: 'gridXmlRpcOrder_CreatedAsc',
137                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcRequestLog.created', 'ASC')
138                                                         },
139                                                         orderDesc: {
140                                                                 id: 'gridXmlRpcOrder_CreatedDesc',
141                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcRequestLog.created', 'DESC')
142                                                         }
143                                                 },
144                                                 Status: {
145                                                         id: 'gridXmlRpcColumn_Status',
146                                                         title: 'STATUS',
147                                                         orderAsc: {
148                                                                 id: 'gridXmlRpcOrder_StatusAsc',
149                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcRequestLog.status', 'ASC')
150                                                         },
151                                                         orderDesc: {
152                                                                 id: 'gridXmlRpcOrder_StatusDesc',
153                                                                 bind: $.proxy(_w.xmlrpcrequestlog.orderXmlRpcGrid, this, 'xmlRpcRequestLog.status', 'DESC')
154                                                         }
155                                                 }
156                                         }
157                                 },
158                                 'gridXmlRpcColumnFilters': {
159                                         constructor: 'GridColumnFilter',
160                                         items: {
161                                                 ClientName : {
162                                                         id: 'gridXmlRpcFilter_ClientName',
163                                                         context: 'gridXmlRpcFilter'
164                                                 },
165                                                 ValuationNumber : {
166                                                         id: 'gridXmlRpcFilter_ValuationNumber',
167                                                         context: 'gridXmlRpcFilter'
168                                                 },
169                                                 ClientApiId : {
170                                                         id: 'gridXmlRpcFilter_ClientApiId',
171                                                         context: 'gridXmlRpcFilter'
172                                                 },
173                                                 IpAddress : {
174                                                         id: 'gridXmlRpcFilter_IpAddress',
175                                                         context: 'gridXmlRpcFilter'
176                                                 },
177                                                 MethodName: {
178                                                         id: 'gridXmlRpcFilter_MethodName',
179                                                         context: 'gridXmlRpcFilter'
180                                                 },
181                                                 Created: {
182                                                         id: 'gridXmlRpcFilter_Created',
183                                                         context: 'gridXmlRpcFilter'
184                                                 },
185                                                 Status: {
186                                                         id: 'gridXmlRpcFilter_Status',
187                                                         context: 'gridXmlRpcFilter'
188                                                 }
189                                         }
190                                 },
191                                 'gridXmlRpcRowRepeater': {},
192                                 'gridXmlRpcPager': {}
193                         });
194
195                 },
196
197                 loadXmlRpcGrid : function( contract, data, options )
198                 {
199                         App.API.execTask(
200                                         'gridSystemXmlRpcRequest', data, options,
201                                         _w.xmlrpcrequestlog._onXmlRpcGridDataReceived, _w.taskExecError
202                                         );
203                 },
204
205                 pageXmlRpcGrid : function( page )
206                 {
207                         _w.xmlrpcrequestlog.loadXmlRpcGrid( {}, {"Grid":{"Page":page}} );
208                 },
209
210                 clearXmlRpcGridContext : function()
211                 {
212                         $('.gridXmlRpcContext').val('');
213                         $('.gridXmlRpcFilter').val('');
214                         _w.xmlrpcrequestlog.searchXmlRpcGrid();
215                 },
216
217                 searchXmlRpcGrid : function()
218                 {
219                         var filter = {
220                                         count: 0,
221                                         filters: {}
222                         };
223
224                         filter = _w.filterIfnotEmpty(filter, 'gridXmlRpcFilter_ClientName', 'xmlRpcClient.clientName');
225                         filter = _w.filterIfnotEmpty(filter, 'gridXmlRpcFilter_ValuationNumber', 'valuation.valuationNumber');
226                         filter = _w.filterIfnotEmpty(filter, 'gridXmlRpcFilter_ClientApiId', 'xmlRpcRequestLog.clientApiId');
227                         filter = _w.filterIfnotEmpty(filter, 'gridXmlRpcFilter_IpAddress', 'xmlRpcRequestLog.ipAddress');
228                         filter = _w.filterIfnotEmpty(filter, 'gridXmlRpcFilter_MethodName', 'xmlRpcRequestLog.methodName');
229                         filter = _w.filterIfnotEmpty(filter, 'gridXmlRpcFilter_Created', 'xmlRpcRequestLog.created');
230                         filter = _w.filterIfnotEmpty(filter, 'gridXmlRpcFilter_Status', 'xmlRpcRequestLog.status');
231                         var request = {"Grid":{
232                             "Page": 1,
233                             "Filter": filter.filters
234                           }};
235                         _w.xmlrpcrequestlog.loadXmlRpcGrid( null, request, {} );
236                 },
237
238                 _onXmlRpcGridDataReceived : function( response )
239                 {
240                         _w.xmlrpcrequestlog.ti.hydrateParam('gridXmlRpcRowRepeater', {});
241                         _w.populateFilters(response.Data.Meta.Filters, {
242                                 'xmlRpcClient.clientName'                               : 'gridXmlRpcFilter_ClientName',
243                                 'valuation.valuationNumber'                     : 'gridXmlRpcFilter_ValuationNumber',
244                                 'xmlRpcRequestLog.clientApiId'                  : 'gridXmlRpcFilter_ClientApiId',
245                                 'xmlRpcRequestLog.ipAddress'                    : 'gridXmlRpcFilter_IpAddress',
246                                 'xmlRpcRequestLog.methodName'                   : 'gridXmlRpcFilter_MethodName',
247                                 'xmlRpcRequestLog.created'                              : 'gridXmlRpcFilter_Created',
248                                 'xmlRpcRequestLog.status'                               : 'gridXmlRpcFilter_Status'
249                         });
250                         _w.xmlrpcrequestlog.packetData = {};
251                         var gridData = [];
252                         for (var i = 0; i < response.Data.DataSet.length; i++)
253                         {
254                                 var row = response.Data.DataSet[i];
255                                 _w.xmlrpcrequestlog.packetData['row' + row.id] = row.packet;
256                                 gridData.push({
257                                         rowId: row.id,
258                                         bind: function(meta) {
259                                                 $('#row' +  meta.rowId).click(function(e){
260                                                         var id = $(this).attr('id');
261                                                         var jspr = JSON.stringify(_w.xmlrpcrequestlog.packetData[id], undefined, 2);
262                                                         jspr = jspr.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
263                                                         jspr = jspr.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
264                                                         var cls = 'number';
265                                                         if (/^"/.test(match)) {
266                                                             if (/:$/.test(match)) {
267                                                                 cls = 'key';
268                                                             } else {
269                                                                 cls = 'string';
270                                                             }
271                                                         } else if (/true|false/.test(match)) {
272                                                             cls = 'boolean';
273                                                         } else if (/null/.test(match)) {
274                                                             cls = 'null';
275                                                         }
276                                                         return '<span class="' + cls + '">' + match + '</span>';
277                                                     });
278                                                         $('#modalbody').html('<pre>' + jspr + '</pre>');
279                                                         $('#myModal').modal('toggle');
280                                                 });
281                                         },
282                                         prepend: {},
283                                         style: {},
284                                         items: {
285                                                 'id'                            : row.id,
286                                                 'ClientName'                    : row.xmlRpcClient.clientName,
287                                                 'ValuationNumber'               : row.valuation.valuationNumber,
288                                                 'ClientApiId'                   : row.clientApiId,
289                                                 'IpAddress'                             : row.ipAddress,
290                                                 'MethodName'                    : row.methodName,
291                                                 'Created'                               : row.created,
292                                                 'Status'                                : row.status
293                                 }
294                                 });
295                         }
296                         _w.xmlrpcrequestlog.ti.hydrateParam('gridXmlRpcRowRepeater', {
297                                 constructor : 'GridDataRow',
298                                 items       : gridData
299                         });
300                         response.Data.Meta.itemName = 'userPager';
301                         response.Data.Meta.bind = _w.xmlrpcrequestlog.pageXmlRpcGrid;
302                         _w.xmlrpcrequestlog.ti.hydrateParam('gridXmlRpcPager', {
303                                 constructor : 'GridPager',
304                                 items       : [response.Data.Meta]
305                         });
306                 },
307
308                 orderXmlRpcGrid : function(field, direction)
309                 {
310                         var order = {};
311                         order[field] = direction;
312                         _w.xmlrpcrequestlog.loadXmlRpcGrid( {}, {"Grid":{"Page": 1, "OrderBy": order}} );
313                 },
314
315                 _onExportReceived : function( response )
316                 {
317                         var win = window.open();
318                         win.document.write(response);
319                 }
320
321         };
322
323 })();