9 onPageDestruct : function()
11 App.Event.removeListener('stockGridSuFilter', 'SuChange');
14 onStockPageTemplateReady : function( template, event, eventData )
16 _w.tcstock.ti = _t[template];
17 App.DataStore.setData('stockstatuses',
19 {"value":"Auction", "label":"Auction"},
20 {"value":"Trade Center", "label":"Trade Center"},
21 {"value":"Sold", "label":"Sold"},
22 {"value":"Relist", "label":"Relist"}
25 App.DataStore.loadSelectListData('tcdealers', true, 'Company', 'Company.TcDealerSelectList');
26 _w.tcstock.ti.hydrate({
27 'gridTitle': 'Trade Stock Control',
28 'gridTitleSubtext': 'Please use the filters below to narrow down the view',
30 constructor: 'Button',
34 id: 'exportStockGrid',
35 handler: _w.tcstock.exportStockGrid
39 'gridContextFilter': {
40 constructor: 'GridContextFilter',
43 style: 'filter-input-wrapper',
44 id: 'gridStockContext_RegNo',
45 placeholder: 'Registration number',
46 context: 'gridStockContext'
49 style: 'filter-input-wrapper',
50 id: 'gridStockContext_RefNo',
51 placeholder: 'Ref number',
52 context: 'gridStockContext'
55 style : 'input-append date filter-input-wrapper-date mobile-width12p dfrom',
56 title: ' Date created',
57 id: 'gridStockContext_DateFrom',
59 context: 'gridStockContext',
60 append: '<i class="icon-calendar"></i>',
63 $('#gridStockContext_DateFrom').change(function() {
64 _w.tcstock.dFrom = $(this).val();
69 style : 'input-append date filter-input-wrapper-date mobile-width12p dto',
70 id: 'gridStockContext_DateTo',
72 context: 'gridStockContext',
73 append: '<i class="icon-calendar"></i>',
76 $('#gridStockContext_DateTo').change(function() {
77 _w.tcstock.dTo = $(this).val();
83 clearId: 'clearStockGridContext',
84 bindClear: _w.tcstock.clearStockGridContext,
85 searchId: 'searchStockGrid',
86 bindSearch: _w.tcstock.searchStockGrid
90 'gridColumnHeaders': {
91 constructor: 'GridColumnHeader',
94 id: 'gridStockColumn_Company',
97 id: 'gridStockOrder_CompanyAsc',
98 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'company.name', 'ASC')
101 id: 'gridStockOrder_CompanyDesc',
102 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'company.name', 'DESC')
106 id: 'gridStockColumn_VIN',
109 id: 'gridStockOrder_VinAsc',
110 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.vinNumber', 'ASC')
113 id: 'gridStockOrder_VinDesc',
114 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.vinNumber', 'DESC')
116 style: 'hidden-phone hidden-tablet'
119 id: 'gridStockColumn_Make',
122 id: 'gridStockOrder_MakeAsc',
123 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'make.name', 'ASC')
126 id: 'gridStockOrder_MakeDesc',
127 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'make.name', 'DESC')
131 id: 'gridStockColumn_Model',
134 id: 'gridStockOrder_ModelAsc',
135 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'model.name', 'ASC')
138 id: 'gridStockOrder_ModelDesc',
139 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'model.name', 'DESC')
141 style: 'hidden-phone hidden-tablet'
144 id: 'gridStockColumn_Type',
147 id: 'gridStockOrder_TypeAsc',
148 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'type.name', 'ASC')
151 id: 'gridStockOrder_TypeDesc',
152 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'type.name', 'DESC')
157 id: 'gridStockColumn_Year',
160 id: 'gridStockOrder_YearAsc',
161 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'vehicleYear.name', 'ASC')
164 id: 'gridStockOrder_YearDesc',
165 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'vehicleYear.name', 'DESC')
170 id: 'gridStockColumn_KM',
173 id: 'gridStockOrder_KmAsc',
174 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.km', 'ASC')
177 id: 'gridStockOrder_KmDesc',
178 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.km', 'DESC')
180 style: 'kms hidden-phone hidden-tablet'
183 id: 'gridStockColumn_Trade',
186 id: 'gridStockOrder_TradeAsc',
187 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.tradePrice', 'ASC')
190 id: 'gridStockOrder_TradeDesc',
191 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.tradePrice', 'DESC')
193 style: 'hidden-phone hidden-tablet'
196 id: 'gridStockColumn_Retail',
199 id: 'gridStockOrder_RetailAsc',
200 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.retailPrice', 'ASC')
203 id: 'gridStockOrder_RetailDesc',
204 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.retailPrice', 'DESC')
206 style: 'hidden-phone hidden-tablet'
209 id: 'gridStockColumn_List',
210 title: 'NEW LIST PRICE',
212 id: 'gridStockOrder_ListAsc',
213 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.listPrice', 'ASC')
216 id: 'gridStockOrder_ListDesc',
217 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.listPrice', 'DESC')
219 style: 'hidden-phone hidden-tablet'
222 id: 'gridStockColumn_Bid',
225 id: 'gridStockOrder_BidAsc',
226 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.highestBid', 'ASC')
229 id: 'gridStockOrder_BidDesc',
230 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.highestBid', 'DESC')
232 style: 'hidden-phone hidden-tablet'
235 id: 'gridStockColumn_Status',
238 id: 'gridStockOrder_JobstateAsc',
239 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.jobState', 'ASC')
242 id: 'gridStockOrder_JobstateDesc',
243 bind: $.proxy(_w.tcstock.orderStockGrid, this, 'stock.jobState', 'DESC')
250 'gridColumnFilters': {
251 constructor: 'GridColumnFilter',
254 id: 'gridStockFilter_Company',
255 context: 'gridStockFilter',
256 dataStoreId : 'tcdealers',
260 id: 'gridStockFilter_VIN',
261 context: 'gridStockFilter'
264 id: 'gridStockFilter_Make',
265 context: 'gridStockFilter'
268 id: 'gridStockFilter_Model',
269 context: 'gridStockFilter'
272 id: 'gridStockFilter_Type',
273 context: 'gridStockFilter'
276 id: 'gridStockFilter_Year',
277 context: 'gridStockFilter'
280 id: 'gridStockFilter_KM',
281 context: 'gridStockFilter'
284 id: 'gridStockFilter_Trade',
285 context: 'gridStockFilter'
288 id: 'gridStockFilter_Retail',
289 context: 'gridStockFilter'
292 id: 'gridStockFilter_Bid',
293 context: 'gridStockFilter'
296 id: 'gridStockFilter_Status',
297 context: 'gridStockFilter',
298 dataStoreId : 'stockstatuses',
303 'gridRowRepeater': {},
307 // Retrieve initial grid data.
308 if (null == App.API.taskContract('gridTCStock'))
311 'gridTCStock', 'Stock', 'Stock.TradeCenterGrid', null,
312 {}, _w.tcstock.loadStockGrid, _w.taskContractError
317 _w.tcstock.loadStockGrid( null, {}, {} );
321 onStockPublished : function()
323 $(".gridStockFilter").keyup(function (evt) {
324 var charCode = evt.charCode || evt.keyCode;
325 if (charCode == 13) { //Enter key's keycode
326 $('#searchStockGrid').click();
330 $(".gridStockContext").keyup(function (evt) {
331 var charCode = evt.charCode || evt.keyCode;
332 if (charCode == 13) { //Enter key's keycode
333 $('#searchStockGrid').click();
337 var _p = App.permissions;
338 var _createStockDisabled = false == _p.stockCreateNew && false == _p.stockCreateAuction
340 $('#newStock').prop('disabled', _createStockDisabled);
341 $('#exportStockGrid').prop('disabled', !App.permissions.stockGridExport);
342 App.Event.listen('stockGridSuFilter', 'SuChange', $.proxy(_w.tcstock.loadStockGrid, this), 'Recurring');
343 $('.dfrom').datepicker({format:"yyyy-mm-dd"});
344 $('.dto').datepicker({format:"yyyy-mm-dd"});
345 $('#gridStockContext_DateFrom').val(_w.tcstock.dFrom);
346 $('#gridStockContext_DateTo').val(_w.tcstock.dTo);
348 setTimeout(_w.tcstock.refreshGrid, 120000);
351 refreshGrid : function()
353 if ('stock' != App.activePage)
357 _w.tcstock.loadStockGrid( null, {}, {} );
358 setTimeout(_w.tcstock.refreshGrid, 120000);
361 pageStockGrid : function( page )
363 _w.tcstock.loadStockGrid( {}, {"Grid":{"Page":page}} );
366 loadStockGrid : function( contract, data, options )
369 'gridTCStock', data, options,
370 _w.tcstock._onStockGridDataReceived, _w.taskExecError
374 _onStockGridDataReceived : function( response )
376 _w.tcstock.ti.hydrateParam('gridRowRepeater', {});
377 _w.populateFilters(response.Data.Meta.Filters, {
378 'stock.registrationNumber': 'gridStockContext_RegNo',
379 'stock.referenceNumber': 'gridStockContext_RefNo',
380 'company.id': 'gridStockFilter_Company',
381 'stock.vinNumber': 'gridStockFilter_VIN',
382 'make.name': 'gridStockFilter_Make',
383 'model.name': 'gridStockFilter_Model',
384 'type.name': 'gridStockFilter_Type',
385 'vehicleYear.name': 'gridStockFilter_Year',
386 'stock.km': 'gridStockFilter_KM',
387 'stock.tradePrice': 'gridStockFilter_Trade',
388 'stock.retailPrice': 'gridStockFilter_Retail',
389 'stock.listPrice': 'gridStockFilter_List',
390 'stock.highestBid': 'gridStockFilter_Bid',
391 'stock.jobState': 'gridStockFilter_Status'
393 $('select.gridStockFilter').each(function(i, elem) {
394 $(elem).selectpicker('refresh');
397 for (var i = 0; i < response.Data.DataSet.length; i++)
399 var row = response.Data.DataSet[i];
401 url: ('Trade Center' == row.jobState) ? 'tcstockview' : 'limitedtcstockview',
408 VIN : 'hidden-phone hidden-tablet',
409 Model : 'hidden-phone hidden-tablet',
410 KM : 'kms hidden-phone hidden-tablet',
411 Trade : 'hidden-phone hidden-tablet',
412 Retail : 'hidden-phone hidden-tablet',
413 Bid : 'hidden-phone hidden-tablet'
417 'Company' : row.company.name,
418 'VIN' : row.vinNumber,
419 'Make' : row.type.model.make.name,
420 'Model' : row.type.model.name,
421 'Type' : row.type.name,
422 'Year' : row.vehicleYear.name,
424 'Trade' : row.tradePrice,
425 'Retail' : row.retailPrice,
426 'List' : row.listPrice,
427 'Bid' : row.highestBid,
428 'Status' : row.auction.jobState == 'Undone' || row.auction.jobState == 'Relist' ? 'Relist' : row.jobState
432 _w.tcstock.ti.hydrateParam('gridRowRepeater', {
433 constructor : 'GridDataRow',
436 response.Data.Meta.itemName = 'stockPager';
437 response.Data.Meta.bind = _w.tcstock.pageStockGrid;
438 _w.tcstock.ti.hydrateParam('gridPager', {
439 constructor : 'GridPager',
440 items : [response.Data.Meta]
444 exportStockGrid : function()
447 'gridTCStock', {}, {'ExportToExcel': true},
448 _w.tcstock._onExportReceived, _w.taskExecError,
453 newStock : function()
455 window.location.hash = '/tcstockview?id=0';
458 _onExportReceived : function( response )
460 var win = window.open();
461 win.document.write(response);
464 clearStockGridContext : function()
468 $('select.gridStockFilter').each(function(i, elem) {
469 $(elem).selectpicker('val', '');
470 $(elem).selectpicker('refresh');
473 catch (err) { console.log(err); }
474 $('.gridStockContext').val('');
475 $('.gridStockFilter').val('');
476 _w.tcstock.searchStockGrid(true);
479 searchStockGrid : function(resetOrder)
485 filter = _w.filterIfnotEmpty(filter, 'gridStockContext_RegNo', 'stock.registrationNumber');
486 filter = _w.filterIfnotEmpty(filter, 'gridStockContext_RefNo', 'stock.referenceNumber');
487 filter = _w.filterIfnotEmpty(filter, 'gridStockContext_DateFrom', 'stock.created', '>=');
488 filter = _w.filterIfnotEmpty(filter, 'gridStockContext_DateTo', 'stock.created', '<=', ' 23:59:59');
490 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Company', 'company.id');
491 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_VIN', 'stock.vinNumber');
492 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Make', 'make.name');
493 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Model', 'model.name');
494 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Type', 'type.name');
495 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Year', 'vehicleYear.name');
496 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_KM', 'stock.km');
497 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Trade', 'stock.tradePrice');
498 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Retail', 'stock.retailPrice');
499 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_List', 'stock.listPrice');
500 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Offer', 'stock.highestOffer');
501 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Status', 'stock.jobState');
502 var request = {"Grid":{
504 "Filter": filter.filters
508 request.Grid.OrderBy = {'stock.created': 'DESC'};
510 _w.tcstock.loadStockGrid( null, request, {} );
513 orderStockGrid : function(field, direction)
516 order[field] = direction;
517 _w.tcstock.loadStockGrid( {}, {"Grid":{"Page": 1, "OrderBy": order}} );