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