text changes to registration mail content
[namibia] / public / js / app / portal-workspace / historyview.js
1 ;(function(){
2
3         window._w.historyview = {
4
5                 itemId        : null,
6                 itemData      : null,
7                 formMeta      : null,
8                 basketId      : null,
9                 basketData    : null,
10                 bidId         : null,
11                 bidData       : null,
12                 ti            : null,
13                 limited       : false,
14                 newItem       : false,
15                 nextBid       : false,
16                 bidType       : null,
17
18                 onHistoryViewTemplateReady : function( template, event, eventData )
19                 {
20                         console.log('onHistoryViewTemplateReady');
21                         _w.historyview.ti = _t[template];
22                         _w.historyview.limited = ('limitedhistoryview' == template)
23                                 ? true
24                                 : false;
25
26                         _w.historyview.setStockViewFormMeta();
27                         _w.historyview.ti.hydrate(_w.historyview.formMeta);
28
29                         // Retrieve initial view data.
30                         
31                         _w.historyview.itemId   = App.Util.getUrlParam('id');
32                         _w.historyview.bidId    = null;
33                         
34                         // Stock data
35                         var task = 'Auction.View';
36                         App.API.getTask(
37                                 'viewAuction:' + _w.historyview.itemId, 'Auction', task, _w.historyview.itemId,
38                                 {}, $.proxy( _w.historyview._onStockViewDataReceived, this ), _w.taskContractError
39                         );
40                 },
41
42                 onHistoryViewPublished : function( template, event, eventData )
43                 {
44                         console.log('onHistoryViewPublished');
45                         if (!_w.historyview.basketId)
46                         {
47                                 $('#btnAddToBasket').prop('disabled', false);
48                                 $('#btnAddToBasket').removeClass('addtobasketbtntrue');
49                                 $('#btnAddToBasket').addClass('addtobasketbtn');
50                         }
51
52
53                         $('#btnRequestHPI').click(function () {
54
55                                 if ('' == $('#HPIusername').val() || '' ==  $('#HPIpin').val())
56                                 {
57                                         alert('Please enter a valid username and password.');
58                                         return;
59                                 }
60
61                                 $('#HPIdropConfirm').slideToggle();
62                                 $('#HPIresponse').html('');
63                         });
64
65
66                         App.Util.updateCheckboxStyle($('#acceptHPIdisclaimer'));
67                         $('#HPIbtnConfirm').click(function () {
68                                 if ( $('#engineNumber').html() == '' || $('#vinNumber').html() == '' ) {
69                                         alert('Cannot request report without Vehicle Engine Number and VIN Number.');
70                                         return;
71                                 }
72                                 if (!$('#acceptHPIdisclaimer').is(':checked'))
73                                 {
74                                         alert('Please accept the conditions before sending.');
75                                         return;
76                                 }
77
78                                 var user = $('#HPIusername').val();
79                                 var pass = $('#HPIpin').val();
80
81                                 App.API.getTask(
82                                                 'TransUnionForHPI', 'Stock', 'Utility.TransUnionForHPI', null,
83                                                 {'Filter' : {'username' : user ,'pass' : pass , 'stock' : _w.stock.Id}},
84                                                 function() {
85                                                         App.API.execTask(
86                                                                         'TransUnionForHPI',{}, {},
87                                                                         function(data)
88                                                                         {
89                                                                                 $('#HPIdropConfirm').hide();
90                                                                                 if ('Success' == data.Status)
91                                                                                 {
92                                                                                         $('#HPIresponse').html('Success on HPI Report');
93                                                                                         alert('Success on HPI Report');
94                                                                                         App.DataStore.loadSelectListData(
95                                                                                                         'tuhpi', false, 'Stock', 'Tuhpi.List', null,{"Filter":
96                                                                                                         {
97                                                                                                                 "stock"                 : _w.historyview.itemData.stock.id,
98                                                                                                                 "company"               : App.companyData.id
99                                                                                                         }}, {},function() {
100                                                                                                         // data is retrieved
101                                                                                                         var tuHpiData = App.DataStore.getData('tuhpi');
102                                                                                                         for (var i = 0; i < tuHpiData.length; i++)
103                                                                                                         {
104                                                                                                                 var tuHpiId = tuHpiData[i].id
105                                                                                                                 var tuHpiCreated = tuHpiData[i].created
106                                                                                                                 if (tuHpiId)
107                                                                                                                 {
108                                                                                                                         $('#tuhpiDate').html(tuHpiCreated);
109                                                                                                                         $('#downloadTuhpi').show();
110                                                                                                                         $('#HPIbtnConfirm').prop('disabled', true);
111                                                                                                                         return;
112                                                                                                                 }
113                                                                                                                 else
114                                                                                                                 {
115                                                                                                                         $('#tuhpiDate').html('Not Requested Yet');
116                                                                                                                         $('#downloadTuhpi').hide();
117                                                                                                                         $('#HPIbtnConfirm').prop('disabled', false);
118                                                                                                                 }
119                                                                                                         }
120                                                                                         });
121                                                                                 }
122                                                                                 else
123                                                                                 {
124                                                                                         $('#HPIresponse').html('API call to remote host failed. No data could be retrieved from remote service.');
125                                                                                 }
126                                                                         }, function(response)
127                                                                         {
128                                                                                 $('#HPIbtnConfirm').prop('disabled', false);
129                                                                                 alert(
130                                                                                         undefined != response.StatusReason
131                                                                                                 ? response.StatusReason
132                                                                                                 : 'API call to remote host failed. No data could be retrieved from remote service.'
133                                                                                 );
134                                                                         }
135                                                         );
136                                                 }
137
138
139                                                 , _w.taskContractError
140                                 );
141                         });
142
143
144                         $('#downloadTuhpi').click(function () {
145                                 //console.log("stock id",  _w.stock.Id);
146                                 App.API.getTask(
147                                                 'printTuhpi:' + _w.stock.Id, 'Stock', 'Tuhpi.Print', _w.stock.Id,
148                                                 {}, function() {
149                                                         App.API.execTask(
150                                                                         'printTuhpi:' + _w.stock.Id, {}, {},
151                                                                         function () {}, _w.taskExecError,
152                                                                         'EXPORT', true
153                                                         );
154                                                 }, _w.taskContractError
155                                 );
156                         });
157
158
159                         $('#btnAddToBasket').click(function () {
160                                 $('#btnAddToBasket').prop('disabled', true);
161                                 if (_w.historyview.basketId)
162                                 {
163                                         App.API.execTask(
164                                                         'updateBasket:' + _w.historyview.itemId, {Basket:{archived: false}}, {},
165                                                         function() {
166                                                                 alert('Item added to basket.');
167                                                                 $('#btnAddToBasket').removeClass('addtobasketbtn');
168                                                                 $('#btnAddToBasket').addClass('addtobasketbtntrue');
169                                                         }, _w.taskExecError
170                                                 );
171                                 }
172                                 else
173                                 {
174                                         App.API.execTask(
175                                                         'createBasket:' + _w.historyview.itemId, {Basket:{auction:_w.historyview.itemId}}, {},
176                                                         function() {
177                                                                 alert('Item added to basket.');
178                                                                 $('#btnAddToBasket').removeClass('addtobasketbtn');
179                                                                 $('#btnAddToBasket').addClass('addtobasketbtntrue');
180                                                         }, _w.taskExecError
181                                                 );
182                                 }
183                         });
184                         $('#btnMakeBid').click(function () {
185                                 $('#confirm_dynamic').show();
186                                 $('#confirmation_msg').hide();
187                                 _w.historyview.ti.hydrateParam('infAmount', _w.historyview.nextBid);
188                                 $('#dropCmp').hide();
189                                 $('#dropConfirm').show();
190                                 _w.historyview.bidType = 'bid';
191                         });
192                         $('#btnAskQuestion').click(function () {
193                                 if ('' == $('#question').val())
194                                 {
195                                         alert('Please specify your question.');
196                                         return;
197                                 }
198                                 App.API.getTask(
199                                                 'askQuestion:' + _w.historyview.itemId, 'Auction', 'Question.Create', _w.historyview.itemId,
200                                                 {}, function() {
201                                                         var data = {
202                                                                         "Question": {
203                                                                                 "auction": _w.historyview.itemId,
204                                                                                 "question": $('#question').val()
205                                                                         }
206                                                         };
207                                                         App.API.execTask(
208                                                                         'askQuestion:' + _w.historyview.itemId, data, {},
209                                                                         _w.historyview._onBidUpdated, function () {
210                                                                                 alert('Your question have been submitted.');
211                                                                                 $('#dropCmp3').slideToggle();
212                                                                         }
213                                                                 );
214                                                 }, _w.taskContractError
215                                         );
216                         });
217                         $('#btnMakeAutoBid').click(function () {
218                                 $('#confirm_dynamic').show();
219                                 $('#confirmation_msg').hide();
220                                 var amount = $('#autoamount').val();
221                                 if ('' != amount && isNaN(amount))
222                                 {
223                                         alert('Please enter a numeric value.');
224                                         return;
225                                 }
226                                 if ('' == amount)
227                                 {
228                                         _w.historyview.ti.hydrateParam('infAmount', _w.historyview.nextBid);
229                                         $('#dropCmp').hide();
230                                         $('#dropConfirm').show();
231                                         _w.historyview.bidType = 'bid';
232                                 }
233                                 else
234                                 {
235                                         var parts = amount.split('.');
236                                         if (parts.length > 1)
237                                         {
238                                                 amount = parts[0];
239                                                 $('#autoamount').val(amount);
240                                         }
241                                         if (amount < _w.historyview.nextBid)
242                                         {
243                                                 $('#dropConfirm').show();
244                                                 $('#confirm_dynamic').hide();
245                                                 $('#confirmation_msg').show();
246                                                 $('#confirmation_msg').html('Autobid amount must be more than R ' + _w.historyview.nextBid);
247                                                 return;
248                                         }
249                                         _w.historyview.ti.hydrateParam('infAmount', amount);
250
251                                         $('#dropConfirm').show();
252                                         _w.historyview.bidType = 'autobid';
253                                 }
254                         });
255
256                         $('#btnConfirm').click(function () {
257                                 if ('bid' == _w.historyview.bidType)
258                                 {
259                                         var data = {
260                                                         "Bid": {
261                                                                 "amount": _w.historyview.nextBid
262                                                         }
263                                         };
264                                         App.API.execTask(
265                                                         'createBid', data, {},
266                                                         _w.historyview._onBidUpdated, function (response) {
267                                                                 $('#bidSection').hide();
268                                                                 console.log(response);
269                                                                 if (response.StatusReason && 'Your' == response.StatusReason.substring(0,4))
270                                                                 {
271                                                                         alert(response.StatusReason);
272                                                                 }
273                                                                 else
274                                                                 {
275                                                                         alert('Your bid was placed but you were just outbid. You can make another bid.');
276                                                                 }
277                                                                 App.API.getTask(
278                                                                                 'viewAuction:' + _w.historyview.itemId, 'Auction', 'Auction.View', _w.historyview.itemId,
279                                                                                 {}, $.proxy( _w.historyview._onStockViewDataReceived, this ), _w.taskContractError
280                                                                         );
281                                                         }
282                                                 );
283                                 }
284                                 else
285                                 {
286                                         var data = {
287                                                         "AutoBid": {
288                                                                 "amount": $('#autoamount').val()
289                                                         }
290                                         };
291                                         App.API.execTask(
292                                                         'createAutoBid', data, {},
293                                                         _w.historyview._onBidUpdated, function (response) {
294                                                                 console.log(response);
295                                                                 if (response.StatusReason && 'Your' == response.StatusReason.substring(0,4))
296                                                                 {
297                                                                         alert(response.StatusReason);
298                                                                 }
299                                                                 else
300                                                                 {
301                                                                         alert('Your bid was placed but you were just outbid. You can make another bid.');
302                                                                 }
303                                                                 App.API.getTask(
304                                                                                 'viewAuction:' + _w.historyview.itemId, 'Auction', 'Auction.View', _w.historyview.itemId,
305                                                                                 {}, $.proxy( _w.historyview._onStockViewDataReceived, this ), _w.taskContractError
306                                                                         );
307                                                         }
308                                                 );
309                                 }
310                         });
311
312                         App.Util.updateCheckboxStyle($('#terms_accepted'));
313                         App.Util.updateCheckboxStyle($('#terms_accepted2'));
314                         $('.showTerms').hover(
315                                 function() {
316                                         $('.moreTerms').show();
317                                 },
318                                 function() {
319                                         $('.moreTerms').hide();
320                                 }
321                         );
322                         $('#terms_accepted').click(function() {
323                                 $('#btnMakeBid').prop('disabled', $(this).prop('checked') ? false : true);
324                         });
325                         $('#terms_accepted2').click(function() {
326                                 $('#btnMakeAutoBid').prop('disabled', $(this).prop('checked') ? false : true);
327                         });
328
329                         $('.mobile-header-bottom .bottom-heading').text('BID DETAILS');
330
331                         if (null != _w.historyview.itemData)
332                         {
333                                 _w.historyview._onStockDataAndTemplate();
334                         }
335                         if (null != _w.historyview.basketData)
336                         {
337                                 _w.historyview._onBasketDataAndTemplate();
338                         }
339
340
341                 },
342
343                 setStockViewFormMeta : function( data )
344                 {
345                         data = (undefined == data)
346                                 ? {"stock":{}}
347                                 : data;
348
349
350
351                         _w.stock.Id = data.stock.id;
352
353                         var damagesHtml = '';
354                         var accessoriesHtml = '';
355                         if (undefined != data && undefined != data.stock && undefined != data.stock.damages)
356                         {
357                                 for (var i = 0; i < data.stock.damages.length; i++)
358                                 {
359                                         damagesHtml += '<div class="control-group row' + i + '">';
360                                         damagesHtml += '<label class="control-label bid-information-label">' + data.stock.damages[i].damage.name + ':</label>';
361                                         damagesHtml += '<div class="controls">';
362                                         damagesHtml += '<p class="bid-information">R ' + data.stock.damages[i].amount + '</p>';
363                                         damagesHtml += '</div>';
364                                         damagesHtml += '</div>';
365                                 }
366                         }
367                         if (undefined != data && undefined != data.stock && undefined != data.stock.accessories)
368                         {
369                                 for (var i = 0; i < data.stock.accessories.length; i+=2)
370                                 {
371                                         var acc1 = data.stock.accessories[i]
372                                                 ? data.stock.accessories[i].accessory.name
373                                                 : '&nbsp;';
374                                         var acc2 = data.stock.accessories[i+1]
375                                                 ? data.stock.accessories[i+1].accessory.name
376                                                 : '&nbsp;';
377                                         accessoriesHtml += '<div class="row-fluid">';
378                                         accessoriesHtml += '<div class="span6 textshow-black">' + acc1 + '</div>';
379                                         accessoriesHtml += '<div class="span6 textshow-black">' + acc2 + '</div>';
380                                         accessoriesHtml += '</div>';
381                                 }
382                         }
383
384
385
386
387                         if (data.currentBidPrice)
388                         {
389                                 _w.historyview.nextBid = 0.0 == data.currentBidPrice
390                                         ? parseFloat(data.reservePrice) + parseFloat(data.bidIncrement)
391                                         : parseFloat(data.currentBidPrice) + parseFloat(data.bidIncrement);
392                         }
393                         else
394                         {
395                                 _w.historyview.nextBid = 0.0;
396                         }
397                         _w.historyview.formMeta = {
398                                 'auctionId' : data.id ? '<div class="row-fluid"><div class="span12"><b>Auction ID: </b>  ' + data.id + '</div></div>' : '',
399                                 'b4cRefNo' : data.stock.referenceNumber ? '<div class="row-fluid"><div class="span12"><b>B4C reference no. ref# </b>  ' + data.stock.referenceNumber + '</div></div>' : '',
400                                 'mmCode' : data.stock.type ? '<div class="row-fluid"><div class="span12"><b>M & M Code: </b>  ' + data.stock.type.mmCode + '</div></div>' : '',
401                                 'vehicle' : data.stock.type
402                                         ? '<div class="row-fluid"><div class="span3"><h5><b>Vehicle Details:</b></h5></div><div class="span9"><h5>'
403                                                         + data.stock.vehicleYear.name + ', '
404                                                         + data.stock.type.category.name + ', '
405                                                         + data.stock.type.model.make.name + ', '
406                                                         + data.stock.type.model.name + ', '
407                                                         + data.stock.type.name +  '</h5></div>'
408                                         : '',
409
410                                 'seller' : data.stock.type
411                                         ? '<div class="row-fluid"><div class="span4"><h5><b>Seller Details:</b></h5></div><div class="span8"><h5>'
412                                                         + data.company.contact.firstName + ' ' + data.company.contact.familyName + ', '
413                                                         + data.company.contact.mobile + ', ' + data.company.name + '<br/>'
414                                                         + data.company.street + ', '
415                                                         + data.company.city.name + ', ' + data.company.region.name + ', '
416                                                         + data.company.postalCode + '</h5></div>'
417                                         : '',
418                                 'vehicleYear' : {
419                                         title       : 'Year',
420                                         style       : 'bid-information',
421                                         labelStyle  : 'bid-information-label',
422                                         value       : data.stock.vehicleYear ? data.stock.vehicleYear.name : ''
423                                 },
424                                 'category' : {
425                                         title       : 'Category',
426                                         style       : 'bid-information',
427                                         labelStyle  : 'bid-information-label',
428                                         value       : data.stock.type ? data.stock.type.category.name : ''
429                                 },
430                                 'make' : {
431                                         title       : 'Vehicle Make',
432                                         style       : 'bid-information',
433                                         labelStyle  : 'bid-information-label',
434                                         value       : data.stock.type ? data.stock.type.model.make.name : ''
435                                 },
436                                 'model' : {
437                                         id          : 'vehicleModel',
438                                         title       : 'Vehicle Model',
439                                         style       : 'bid-information',
440                                         labelStyle  : 'bid-information-label',
441                                         value       : data.stock.type ? data.stock.type.model.name : ''
442                                 },
443                                 'type' : {
444                                         title       : 'Vehicle Type',
445                                         style       : 'bid-information',
446                                         labelStyle  : 'bid-information-label',
447                                         value       : data.stock.type ? data.stock.type.name : ''
448                                 },
449                                 'fuelType' : {
450                                         title       : 'Fuel Type',
451                                         value       : data.stock.fuelType ? data.stock.fuelType.name : '',
452                                         style       : 'bid-information',
453                                         labelStyle  : 'bid-information-label'
454                                 },
455
456                                 'transmissionType' : {
457                                         title       : 'Transmission Type',
458                                         style       : 'bid-information',
459                                         labelStyle  : 'bid-information-label',
460                                         value       : data.stock.transmissionType ? data.stock.transmissionType.name : ''
461                                 },
462                                 'condition' : {
463                                         title       : 'Condition',
464                                         style       : 'bid-information',
465                                         labelStyle  : 'bid-information-label',
466                                         value       : data.stock.condition ? data.stock.condition.name : ''
467                                 },
468                                 'exteriorColour' : {
469                                         title       : 'Main ext. colour',
470                                         style       : 'bid-information',
471                                         labelStyle  : 'bid-information-label',
472                                         value       : data.stock.exteriorColour ? data.stock.exteriorColour.name : ''
473                                 },
474                                 'interiorColour' : {
475                                         title : 'Main int. colour',
476                                         style       : 'bid-information',
477                                         labelStyle  : 'bid-information-label',
478                                         value : data.stock.interiorColour ? data.stock.interiorColour.name : ''
479                                 },
480                                 'upholstery' : {
481                                         title       : 'Upholstery',
482                                         style       : 'bid-information',
483                                         labelStyle  : 'bid-information-label',
484                                         value       : data.stock.upholstery ? data.stock.upholstery.name : ''
485                                 },
486                                 'papers' : {
487                                         title       : 'Papers',
488                                         style       : 'bid-information',
489                                         labelStyle  : 'bid-information-label',
490                                         value       : data.stock.papers ? data.stock.papers.name : ''
491                                 },
492                                 'natis' : {
493                                         title       : 'Natis',
494                                         value       : data.stock.natis ? data.stock.natis.name : '',
495                                         style       : 'bid-information',
496                                         labelStyle  : 'bid-information-label'
497                                 },
498                                 'spareKeys' : {
499                                         title       : 'Spare keys',
500                                         value       : undefined == data.stock.spareKeys
501                                                                         ? ''
502                                                                         : (data.stock.spareKeys ? 'Yes' : 'No'),
503                                         style       : 'bid-information',
504                                         labelStyle  : 'bid-information-label'
505                                 },
506                                 'fullServiceHistory' : {
507                                         title       : 'Full service history',
508                                         value       : undefined == data.stock.fullServiceHistory
509                                                                         ? ''
510                                                                         : data.stock.fullServiceHistory.name,
511                                         style       : 'bid-information',
512                                         labelStyle  : 'bid-information-label'
513                                 },
514                                 'registrationNumber' : {
515                                         title : 'Registration no',
516                                         value : data.stock.registrationNumber ? data.stock.registrationNumber : '',
517                                         style       : 'bid-information',
518                                         labelStyle  : 'bid-information-label'
519                                 },
520                                 'vinNumber' : {
521                                         title : 'Vin no',
522                                         value : data.stock.vinNumber ? data.stock.vinNumber : '',
523                                         style       : 'bid-information',
524                                         labelStyle  : 'bid-information-label'
525                                 },
526                                 'engineNumber' : {
527                                         title : 'Engine no',
528                                         value : data.stock.engineNumber ? data.stock.engineNumber : '',
529                                         style       : 'bid-information',
530                                         labelStyle  : 'bid-information-label'
531                                 },
532                                 'km' : {
533                                         title : 'Kms',
534                                         value : data.stock.km ? data.stock.km : '',
535                                         style       : 'bid-information',
536                                         labelStyle  : 'bid-information-label'
537                                 },
538                                 'fshNotes' : {
539                                         title : 'FSH notes',
540                                         value : data.stock.fshNotes ? data.stock.fshNotes : ''
541                                 },
542                                 'fshNotes_title' : {
543                                         title : 'FSH notes',
544                                         style       : 'bid-information',
545                                         labelStyle  : 'bid-information-label'
546                                 },
547                                 'fshNotes_data' : {
548                                         style       : 'bid-information',
549                                         labelStyle  : 'bid-information-label',
550                                         value : data.stock.fshNotes ? data.stock.fshNotes : ''
551                                 },
552                                 'damages' : damagesHtml,
553                                 'damageTotal' : {
554                                         title : 'Total estimated repair price',
555                                         value : 'R ' + (data.stock ? data.stock.damageTotal : '0.00'),
556                                         style       : 'bid-information',
557                                         labelStyle  : 'bid-information-label'
558                                 },
559                                 'damageNotes' : {
560                                         title : 'Damages comments',
561                                         value : data.stock.damageNotes ? data.stock.damageNotes : '',
562                                         style       : 'bid-information',
563                                         labelStyle  : 'bid-information-label'
564                                 },
565                                 'damageNotes_title' : {
566                                         style       : 'bid-information',
567                                         labelStyle  : 'bid-information-label',
568                                         title : 'Damages comments',
569                                         value: ''
570                                 },
571                                 'damageNotes_data' : {
572                                         style       : 'bid-information',
573                                         labelStyle  : 'bid-information-label',
574                                         value : data.stock.damageNotes ? data.stock.damageNotes : ''
575                                 },
576                                 'previousRepairsNoted' : {
577                                         title : 'Previous repairs noted',
578                                         value : data.stock.previousRepairsNoted ? 'Yes' : 'No',
579                                         style       : 'bid-information',
580                                         labelStyle  : 'bid-information-label'
581                                 },
582                                 'previousRepairsNotes' : {
583                                         title : 'Previous repairs comments',
584                                         value : data.stock.previousRepairsNotes ? data.stock.previousRepairsNotes : '',
585                                         style       : 'bid-information',
586                                         labelStyle  : 'bid-information-label'
587                                 },
588                                 'previousRepairsNotes_title' : {
589                                         style       : 'bid-information',
590                                         labelStyle  : 'bid-information-label',
591                                         title : 'Previous repairs comments',
592                                 },
593                                 'previousRepairsNotes_data' : {
594                                         style       : 'bid-information',
595                                         labelStyle  : 'bid-information-label',
596                                         value : data.stock.previousRepairsNotes ? data.stock.previousRepairsNotes : ''
597                                 },
598
599                                 'accessories' : accessoriesHtml,
600
601
602                                 'accessoryNew' : {
603                                         value       : data.stock.accessoryNotes ? data.stock.accessoryNotes : '',
604                                         style       : 'bid-information',
605                                         labelStyle  : 'bid-information-label hidden'
606                                 },
607
608
609                                 'accessoryNotes' : {
610                                         title           : 'Comments',
611                                         value           : data.stock.accessoryNotes ? data.stock.accessoryNotes : '',
612                                         style       : 'bid-information',
613                                         labelStyle  : 'bid-information-label'
614                                 },
615                                 'accessoryNotes_title' : {
616                                         style       : 'bid-information',
617                                         labelStyle  : 'bid-information-label',
618                                         title     : 'Accessories Comments',
619                                         value: ''
620                                 },
621                                 'accessoryNotes_data' : {
622                                         style       : 'bid-information',
623                                         labelStyle  : 'bid-information-label',
624                                         value       : data.stock.accessoryNotes ? data.stock.accessoryNotes : ''
625                                 },
626
627
628
629                                 'accessoriesMobi' : accessoriesHtml,
630                                 'accessoryNotesMobi' : {
631                                         title           : 'Comments',
632                                         value           : data.stock.accessoryNotes ? data.stock.accessoryNotes : '',
633                                         style       : 'bid-information',
634                                         labelStyle  : 'bid-information-label'
635                                 },
636                                 'accessoryNotes_titleMobi' : {
637                                         style       : 'bid-information',
638                                         labelStyle  : 'bid-information-label',
639                                         title           : 'Accessories Comments',
640                                         value           : ''
641                                 },
642                                 'accessoryNotes_dataMobi' : {
643                                         style       : 'bid-information',
644                                         labelStyle  : 'bid-information-label',
645                                         title           : 'Accessories Notes',
646                                         value           : data.stock.accessoryNotes ? data.stock.accessoryNotes : ''
647                                 },
648
649                                 'accessoryNewMobi' : {
650                                         value       : data.stock.accessoryNotes ? data.stock.accessoryNotes : '',
651                                         style       : 'bid-information',
652                                         labelStyle  : 'bid-information-label'
653                                 },
654
655
656
657                                 'bidImgMain' : {
658                                         type  : 'bidMainImage',
659                                         view  : true,
660                                         id    : 'bidImgMain',
661                                         baseImage : 'main_img_car.jpg',
662                                         value : data.stock.mainImage ? data.stock.mainImage : ''
663                                 },
664                                 'mainImage' : {
665                                         type  : 'bidimage',
666                                         view  : true,
667                                         id    : 'mainImage',
668                                         baseImage : 'main_img_car.jpg',
669                                         value : data.stock.mainImage ? data.stock.mainImage : ''
670                                 },
671                                 'frontImage' : {
672                                         type  : 'bidimage',
673                                         view  : true,
674                                         id    : 'frontImage',
675                                         baseImage : 'front_car.jpg',
676                                         value : data.stock.frontImage ? data.stock.frontImage : ''
677                                 },
678                                 'leftImage' : {
679                                         type  : 'bidimage',
680                                         view  : true,
681                                         id    : 'leftImage',
682                                         baseImage : 'left_car.jpg',
683                                         value : data.stock.leftImage ? data.stock.leftImage : ''
684                                 },
685                                 'rightImage' : {
686                                         type  : 'bidimage',
687                                         view  : true,
688                                         id    : 'rightImage',
689                                         baseImage : 'right_car.jpg',
690                                         value : data.stock.rightImage ? data.stock.rightImage : ''
691                                 },
692                                 'backImage' : {
693                                         type  : 'bidimage',
694                                         view  : true,
695                                         id    : 'backImage',
696                                         baseImage : 'back_car.jpg',
697                                         value : data.stock.backImage ? data.stock.backImage : ''
698                                 },
699                                 'interiorImage' : {
700                                         type  : 'bidimage',
701                                         view  : true,
702                                         id    : 'interiorImage',
703                                         baseImage : 'interior_car.jpg',
704                                         value : data.stock.interiorImage ? data.stock.interiorImage : ''
705                                 },
706                                 'engineImage' : {
707                                         type  : 'bidimage',
708                                         view  : true,
709                                         id    : 'engineImage',
710                                         baseImage : 'engine_car.jpg',
711                                         value : data.stock.engineImage ? data.stock.engineImage : ''
712                                 },
713                                 'natisImage' : {
714                                         type  : 'bidimage',
715                                         view  : true,
716                                         id    : 'natisImage',
717                                         baseImage : 'copy_of_natis_car.jpg',
718                                         value : data.stock.natisImage ? data.stock.natisImage : ''
719                                 },
720
721                                 'infCreated': data.created ? ((data.created).split(' '))[0] : '',
722                                 'infLoadedOnAuction': data.stock.loadedOnAuction
723                                         ? ((data.stock.loadedOnAuction).split(' '))[0] : '',
724                                 'infTradePrice': {
725                                         title : '<b>Trade</b>',
726                                         value : data.stock.tradePrice ? '&nbsp;&nbsp;R ' + data.stock.tradePrice : '&nbsp;&nbsp;R 0.00',
727                                         style       : 'bid-information',
728                                         labelStyle  : 'bid-information-label'
729                                 },
730                                 'infRetailPrice': {
731                                         title : '<b>Retail</b>',
732                                         value : data.stock.retailPrice ? '&nbsp;&nbsp;R ' + data.stock.retailPrice : '&nbsp;&nbsp;0.00',
733                                         style       : 'bid-information',
734                                         labelStyle  : 'bid-information-label'
735                                 },
736                 'infListPrice': {
737                     title : '<b>New list price</b>',
738                     value : data.stock.listPrice ? '&nbsp;&nbsp;R ' + data.stock.listPrice : '&nbsp;&nbsp;R 0.00',
739                     style       : 'bid-information',
740                     labelStyle  : 'bid-information-label'
741                 },
742
743                                 'companyName' : {
744                                         title : 'Dealership name',
745                                         value : data.company ? data.company.name : '',
746                                         style       : 'bid-information',
747                                         labelStyle  : 'bid-information-label'
748                                 },
749                                 'companyContact' : {
750                                         title : 'Name and surname',
751                                         value : data.company && data.company.contact
752                                                                 ? data.company.contact.firstName + ' ' + data.company.contact.familyName
753                                                                 : '',
754                                         style       : 'bid-information',
755                                         labelStyle  : 'bid-information-label'
756                                 },
757                                 'companyMobile' : {
758                                         title : 'Mobile',
759                                         value : data.company && data.company.contact
760                                                                 ? data.company.contact.mobile
761                                                                 : '',
762                                         style       : 'bid-information',
763                                         labelStyle  : 'bid-information-label'
764                                 },
765                                 'companyEmail' : {
766                                         title : 'Email',
767                                         value : data.company && data.company.contact
768                                                                 ? data.company.contact.email
769                                                                 : '',
770                                         style       : 'bid-information',
771                                         labelStyle  : 'bid-information-label'
772                                 },
773                                 'amount' : {
774                                         type  : 'input',
775                                         id    : 'amount',
776                                         title : 'Amount',
777                                         value : _w.historyview.nextBid,
778                                         disabled: true
779                                 },
780                                 'autoamount' : {
781                                         type  : 'amountAuction',
782                                         id    : 'autoamount',
783                                         title : '',
784                                         value : '' //parseFloat(_w.historyview.nextBid) + parseFloat(data.bidIncrement)
785                                 },
786                                 'question' : {
787                                         type  : 'textarea-styled',
788                                         id    : 'question',
789                                         title : 'Question',
790                                         value : '',
791                                         style : 'span12',
792                                         areaStyle: 'span12'
793                                 },
794                                 'infAmount' : _w.historyview.nextBid,
795                                 'myAutoBid' : data.currentBid && data.currentBid.autoBid
796                                                                 && App.companyData.id == data.currentBid.autoBid.company
797                                                                 ? '<b>My auto-bid:<br/>R ' + data.currentBid.autoBid.amount + '</b>'
798                                                                 : '<b>No current auto-bid.</b>',
799                                 'nextBid' : {
800                                         title : 'Next bid',
801                                         value : '<b>R ' + _w.historyview.nextBid + '</b>'
802                                 },
803                                 'nextBid_title' : {
804                                         title : 'Next bid',
805                                 },
806                                 'nextBid_data' : {
807                                         value : '<b>R ' + _w.historyview.nextBid + '</b>',
808                                         style : 'text-large-auction'
809                                 },
810                                 'winningBid' : {
811                                         title : 'Winning bid',
812                                         value : data.currentBid ? '<b>R ' + data.currentBid.amount + '</b>' : '<b>R 0.00</b>'
813                                 },
814                                 'complaint' : {
815                                         type  : 'textarea-styled',
816                                         id    : 'complaint',
817                                         title : 'Complaint',
818                                         value : '',
819                                         areaStyle : 'span12',
820                                         style : 'span10'
821                                 },
822                                 'print': {
823                                         constructor: 'Button',
824                                         items: {
825                                                 Export: {
826                                                         preset: 'Print',
827                                                         id: 'printAuctionPdf',
828                                                         handler: _w.historyview.printAuctionPdf
829                                                 }
830                                         }
831                                 }
832                         };
833                 },
834
835                 printAuctionPdf : function()
836                 {
837                         App.API.getTask(
838                                         'printAuctionPdf:' + _w.historyview.itemId, 'Auction', 'Pdf.Print', _w.historyview.itemId,
839                                         {}, function() {
840                                                 App.API.execTask(
841                                                                 'printAuctionPdf:' + _w.historyview.itemId, {}, {},
842                                                                 function() {}, function() {},
843                                                                 'EXPORT', true
844                                                 );
845                                         }, _w.taskContractError
846                         );
847                 },
848
849                 _onBidDataAndTemplate : function ()
850                 {
851
852
853                         if ('Archived' == _w.historyview.bidData.status)
854                         {
855                                 true == App.permissions.pgUnArchive ? $('#btnUnarchive').show() : $('#btnUnarchive').hide();
856                                 $('#btnArchive').hide();
857                                 $('#optMakeBid').hide();
858                         }
859                         else
860                         {
861                                 true == App.permissions.pgArchive ? $('#btnArchive').show() : $('#btnArchive').hide();
862                                 $('#btnUnarchive').hide();
863                         }
864                 },
865
866                 _onBasketDataAndTemplate : function ()
867                 {
868                         if (true == _w.historyview.basketData.archived)
869                         {
870                                 $('#btnAddToBasket').prop('disabled', false);
871                                 $('#btnAddToBasket').removeClass('addtobasketbtntrue');
872                                 $('#btnAddToBasket').addClass('addtobasketbtn');
873                         }
874                         else
875                         {
876                                 $('#btnAddToBasket').prop('disabled', true);
877                                 $('#btnAddToBasket').removeClass('addtobasketbtn');
878                                 $('#btnAddToBasket').addClass('addtobasketbtntrue');
879                         }
880                 },
881
882                 _onStockDataAndTemplate : function ()
883                 {
884                         App.DataStore.loadSelectListData(
885                                         'tuhpi', false, 'Stock', 'Tuhpi.List', null,{"Filter":
886                                         {
887                                                 "stock"                 : _w.historyview.itemData.stock.id,
888                                                 "company"               : App.companyData.id
889                                         }}, {},function() {
890                                         // data is retrieved
891                                         var tuHpiData = App.DataStore.getData('tuhpi');
892                                         for (var i = 0; i < tuHpiData.length; i++)
893                                         {
894                                                 var tuHpiId = tuHpiData[i].id
895                                                 var tuHpiCreated = tuHpiData[i].created
896                                                 //created
897                                                 console.log("tuhpi data Created", tuHpiCreated);
898                                                 console.log("tuhpi data id", tuHpiId);
899                                                 if (tuHpiId)
900                                                 {
901                                                         console.log("tuhpi data Created", tuHpiCreated);
902                                                         console.log("tuhpi data id", tuHpiId);
903                                                         $('#tuhpiDate').html(tuHpiCreated);
904                                                         $('#downloadTuhpi').show();
905                                                 }
906                                                 else
907                                                 {
908                                                         console.log("tuhpi no data id");
909                                                         $('#tuhpiDate').html('Not Requested Yet');
910                                                         $('#downloadTuhpi').hide();
911                                                 }
912                                         }
913                         });
914                         $('#disputeSection').hide();
915
916                         //if ('Sold' == _w.historyview.itemData.jobState && _w.historyview.itemData.soldToCompany.id == App.companyData.id)
917                         if ('Sold' == _w.historyview.itemData.jobState)
918                         {
919                                 $('#bidSection').hide();
920                                 $('#disputeSection').show();
921                                 $('#btnLogDispute').click(function() {
922                                         var comp = $('#complaint').val();
923                                         if ('' == comp)
924                                         {
925                                                 alert('Please specify the complaint.');
926                                                 return;
927                                         }
928                                         var data = {
929                                                         Dispute : {
930                                                                 againstCompany : _w.historyview.itemData.company.id,
931                                                                 auction        : _w.historyview.itemId,
932                                                                 complaint      : comp
933                                                         }
934                                         };
935                                         App.API.getTask(
936                                                         'createDispute', 'Dispute', 'Dispute.Create',
937                                                         null, {}, function(){
938                                                                 App.API.execTask(
939                                                                                 'createDispute', data, {},
940                                                                                 function() {
941                                                                                         alert('Dispute logged.');
942                                                                                         _w.historyview._onBidUpdated();
943                                                                                 }, function() {}
944                                                                 );
945                                                         }, _w.taskContractError
946                                                 );
947                                 });
948                         }
949                         else if ('Active' != _w.historyview.itemData.jobState)
950                         {
951                                 $('#optMakeBid').hide();
952                         }
953                         else
954                         {
955                                 $('#autoamount').focus(function() {
956                                         $('#dropConfirm').hide();
957                                 });
958                                 App.API.getTask(
959                                                 'createBid', 'Auction', 'Bid.Create',
960                                                 _w.historyview.itemId, {}, function(){}, function(){}
961                                         );
962                                 App.API.getTask(
963                                                 'createAutoBid', 'Auction', 'AutoBid.Create',
964                                                 _w.historyview.itemId, {}, function(){}, function(){}
965                                 );
966                         }
967
968                         $("#tS1").thumbnailScroller({
969                                 /* scroller type based on mouse interaction
970                                 values: "hoverPrecise", "hoverAccelerate", "clickButtons"
971                                 default: "hoverPrecise" */
972                                 scrollerType:"hoverAccelerate",
973                                 /* scroller orientation
974                                 values: "horizontal", "vertical"
975                                 default: "horizontal" */
976                                 scrollerOrientation:"horizontal",
977                                 /* scroll easing type only for "hoverPrecise" scrollers
978                                 available values here: http://jqueryui.com/demos/effect/easing.html
979                                 default: "easeOutCirc" */
980                                 scrollEasing:"easeOutCirc",
981                                 /* scroll easing amount only for "hoverPrecise" and "clickButtons" scrollers (0 for no easing)
982                                 values: milliseconds
983                                 default: 800 */
984                                 scrollEasingAmount:300,
985                                 /* acceleration value only for "hoverAccelerate" scrollers
986                                 values: integer
987                                 default: 2 */
988                                 acceleration:0,
989                                 /* scrolling speed only for "clickButtons" scrollers
990                                 values: milliseconds
991                                 default: 600 */
992                                 scrollSpeed:100,
993                                 /* scroller null scrolling area only for "hoverAccelerate" scrollers
994                                 0 being the absolute center of the scroller
995                                 values: pixels
996                                 default: 0 */
997                                 noScrollCenterSpace:0,
998                                 /* initial auto-scrolling
999                                 0 equals no auto-scrolling
1000                                 values: amount of auto-scrolling loops (integer)
1001                                 default: 0 */
1002                                 autoScrolling:1,
1003                                 /* initial auto-scrolling speed
1004                                 values: milliseconds
1005                                 default: 8000 */
1006                                 autoScrollingSpeed:100,
1007                                 /* initial auto-scrolling easing type
1008                                 available values here: http://jqueryui.com/demos/effect/easing.html
1009                                 default: "easeInOutQuad" */
1010                                 autoScrollingEasing:"easeInOutQuad",
1011                                 /* initial auto-scrolling delay for each loop
1012                                 values: milliseconds
1013                                 default: 2500 */
1014                                 autoScrollingDelay:250
1015                         });
1016
1017
1018                         /*
1019                          * Permissions
1020                          */
1021                         if (false == App.permissions.auctionBid)
1022                         {
1023                                 $('#bidSection').hide();
1024                         }
1025
1026                         if (App.permissions.settingsHpiReport == false)
1027                         {
1028                                 $('#requestHPIreport').hide();
1029                         }
1030                         else
1031                         {
1032                                 if (App.permissions.settingsHpiReport)
1033                                 {
1034                                         $('#requestHPIreport').show();
1035                                 }
1036                         }
1037                 },
1038
1039                 _onBasketDataReceived : function( response )
1040                 {
1041                         _w.historyview.basketData = response.Data;
1042                         if (_w.historyview.ti.published)
1043                         {
1044                                 _w.historyview._onBasketDataAndTemplate();
1045                         }
1046                 },
1047
1048                 _onStockViewDataReceived : function( response )
1049                 {
1050
1051                         console.log('response', response);
1052                         _w.historyview.itemId = response.Data.id;
1053                         _w.historyview.itemData = response.Data;
1054                         _w.historyview.setStockViewFormMeta(response.Data);
1055                         _w.historyview.ti.hydrate(_w.historyview.formMeta);
1056                         if (response.Data.currentBid)
1057                         {
1058                                 _w.historyview.bidId = response.Data.currentBid.id;
1059                                 _w.historyview.bidData = response.Data.currentBid;
1060                                 if (_w.historyview.bidData.company.id != App.companyData.id)
1061                                 {
1062                                         $('#bidSection').show();
1063                                         $('#winningBid').hide();
1064                                 }
1065                                 else
1066                                 {
1067                                         $('#bidSection').hide();
1068                                         $('#winningBid').show();
1069                                 }
1070                         }
1071                         else
1072                         {
1073                                 $('#bidSection').show();
1074                                 _w.historyview.newItem = true;
1075                                 _w.historyview.bidData = {};
1076                         }
1077                         if (_w.historyview.itemData.company.id == App.companyData.id || _w.historyview.itemData.stock.company.id  == App.companyData.id)
1078                         {
1079                                 $('#bidSection').hide();
1080                         }
1081                         if (_w.historyview.ti.published)
1082                         {
1083                                 _w.historyview._onStockDataAndTemplate();
1084                         }
1085                 },
1086
1087                 _onBidUpdated : function( response )
1088                 {
1089                         window.location.hash = '/auction';
1090                 }
1091
1092         };
1093
1094  })();