+264 correction
[namibia] / public / js / app / element-library.js
1 ;(function(){
2
3         _App.ElementLibrary = function()
4         {
5                 this.initialize();
6         };
7
8         _App.ElementLibrary.prototype =
9         {
10
11                 initialize : function()
12                 {
13                         // Nothing to do.
14                 },
15
16                 Button : {
17                         html : function( meta )
18                         {
19                                 if (null == meta)
20                                 {
21                                         return '';
22                                 }
23                                 if (meta.preset)
24                                 {
25                                         var disabledclass = undefined != meta.permission && false == meta.permission
26                                                 ? 'disabled'
27                                                 : '';
28                                         switch(meta.preset)
29                                         {
30                                         case 'GridExport':
31                                                 return '<button type="button" id="' + meta.id + '" class="btn hidden-phone" ' + disabledclass + '>'
32                                                                 + '<i class="icon-export"></i>'
33                                                                 + 'Export information'
34                                                                 + '</button>';
35                                         case 'NewValuation':
36                                                 return '<button type="button" id="' + meta.id + '" class="btn btn-warning btn-new-valuation mobile-new-valuation" ' + disabledclass + '>'
37                                                                 + '<span class="btn-shine mobile-btn-shine"></span>'
38                                                                 + '<span class="btn-content">'
39                                                                 + '<i class="icon-new mobile-icon-new"></i>'
40                                                                 + 'New valuation'
41                                                                 + '</span></button>';
42                                         case 'ValuationReport':
43                                                 return '<button type="button" id="' + meta.id + '" class="btn btn-primary btn-valuation-report" ' + disabledclass + '>'
44                                                                 + '<span class="btn-content">'
45                                                                 + 'Valuation Report'
46                                                                 + '</span></button> ';
47                                         case 'NewStock':
48                                                 return '<button type="button" id="' + meta.id + '" class="btn btn-warning btn-new-valuation mobile-new-valuation" ' + disabledclass + '>'
49                                                                 + '<span class="btn-shine mobile-btn-shine"></span>'
50                                                                 + '<span class="btn-content">'
51                                                                 + '<i class="icon-new mobile-icon-new"></i>'
52                                                                 + 'New stock'
53                                                                 + '</span></button>';
54                     case 'AuctionReport':
55                         return '<button type="button" id="' + meta.id + '" class="btn btn-primary hidden-phone btn-margin-right-5" ' + disabledclass + '>'
56                             + '<i class="icon-download-alt-2"></i>'
57                             + ' Auction Report'
58                             + '</button>';
59                     case 'BulkImporter':
60                         return '<button type="button" id="' + meta.id + '" class="btn btn-success hidden-phone btn-margin-right-5" ' + disabledclass + '>'
61                             + '<i class="icon-folder-open-alt-2"></i>'
62                             + ' Bulk Upload'
63                             + '</button>';
64                                         case 'SellVehicle':
65                                                 return '<button type="button" onClick="window.location.hash = \'/stockview?id=0\';" id="' + meta.id + '" class="btn btn-warning btn-new-valuation mobile-new-valuation" ' + disabledclass + '>'
66                                                                 + '<span class="btn-shine mobile-btn-shine"></span>'
67                                                                 + '<span class="btn-content">'
68                                                                 + '<i class="icon-new mobile-icon-new"></i>'
69                                                                 + 'Sell a Vehicle'
70                                                                 + '</span></button>';
71                                         case 'Print':
72                                                 return '<button type="button" id="' + meta.id + '" class="btn" ' + disabledclass + '>'
73                                                                 + '<i class="icon-print printer"></i>'
74                                                                 + 'Print'
75                                                                 + '</button>';
76                                         case 'PrintTC':
77                                                 return '<button type="button" id="' + meta.id + '" class="btn" ' + disabledclass + '>'
78                                                                 + '<i class="icon-print printer"></i>'
79                                                                 + 'Print with T&amp;C'
80                                                                 + '</button>';
81                                         }
82                                 }
83                                 else
84                                 {
85                                         return '<button class="btn ' + meta.style + '">'
86                                                                 + (meta.icon ? '<i class="icon-' + meta.icon + '"></i>' : '')
87                                                                 + meta.title
88                                                                 + '</button>';
89                                 }
90                         },
91                         bind : function( meta )
92                         {
93                                 if (null == meta)
94                                 {
95                                         return;
96                                 }
97                                 if (meta.preset)
98                                 {
99                                         switch(meta.preset)
100                                         {
101                                         case 'NewValuation':
102                                         case 'ValuationReport':
103                                         case 'NewStock':
104                     case 'AuctionReport':
105                     case 'BulkImporter':
106                                         case 'Print':
107                                         case 'PrintTC':
108                                         case 'GridExport':
109                                                 $("#" + meta.id).click(meta.handler);
110                                                 break;
111                                         }
112                                 }
113                                 else
114                                 {
115                                         if (meta['bind'])
116                                         {
117                                                 meta['bind'](meta);
118                                         }
119                                 }
120                         }
121                 },
122
123                 GridContextFilter : {
124                         html : function( meta )
125                         {
126
127                                 if (null == meta)
128                                 {
129                                         return '<div class="width12p">&nbsp;</div>';
130                                 }
131
132                                 var style    = undefined != meta.style ? meta.style : 'span2';
133                                 var divStyle = undefined != meta.divStyle ? meta.divStyle : '';
134                                 var readonly = meta.readonly ? " readonly" : '';
135                                 var prepend  = meta.prepend ? '<span class="add-on">' + meta.prepend + '</span>' : '';
136                                 var append   = meta.append ? '<span class="add-on">' + meta.append + '</span>' : '';
137
138                                 if (meta.actions)
139                                 {
140                                         return '<div class="' + style + ' btn-wrapper pull-right">'
141                                                         + '<button type="button" id="' + meta.clearId + '" class="btn btn-clear-search">'
142                                                         + '<i class="icon-remove-circle"></i>'
143                                                         + 'Clear search'
144                                                         + '</button>'
145                                                         + '<button type="button" id="' + meta.searchId + '" class="mobile-search btn btn-success btn-submit-search">'
146                                                         + '<i class="mobile-icon-search icon-search icon-white"></i>'
147                                                         + 'Search'
148                                                         + '</button>'
149                                                         + '</div>';
150                                 }
151                                 else
152                                 {
153                                         if (meta.dataStoreId)
154                                         {
155                                                 if (!meta.options)
156                                                 {
157                                                         meta.options = [];
158                                                 }
159                                                 if (!meta.selected)
160                                                 {
161                                                         meta.selected = '';
162                                                 }
163                                                 var selectMe = '';
164                                                 var html = '<div class="' + style + '">';
165                                                 html += '<p class="context-filter-label">';
166                                                 html += (meta.title ? meta.title : '&nbsp;');
167                                                 html += '</p>';
168                                                 html += '<div class="filter-input control-group' + divStyle + '">' + prepend
169                                                 html += '<select id="' + meta.id + '" name="' + meta.id + '" data-size="10" '
170                                                           + 'class="sp selectpicker show-menu-arrow ' + (meta.context ? meta.context : '') + '">';
171                                                 for (var i = 0; i < meta.options.length; i++)
172                                                 {
173                                                         selectMe = (meta.options[i].value == meta.selected) ? ' selected' : '';
174                                                         html += '<option value="' + meta.options[i].value + '"' + selectMe + '>' + meta.options[i].label + '</option>';
175                                                 }
176                                                 html += '</select>';
177                                                 html += append + '</div>';
178                                                 html += '</div>';
179                                                 return html;
180                                         }
181                                         else
182                                         {
183                                                 return '<div class="' + style + '">'
184                                                         + '<p class="context-filter-label">'
185                                                         + (meta.title ? meta.title : '&nbsp;')
186                                                         + '</p>'
187                                                         + '<div class="filter-input control-group' + divStyle + '">' + prepend
188                                                         + '<input id="' + meta.id + '" type="text" placeholder="'
189                                                         + meta.placeholder + '" class="' + meta.context + '"' + readonly + '>'
190                                                         + append + '</div>'
191                                                         + '</div>';
192                                         }
193                                 }
194                         },
195                         bind : function( meta )
196                         {
197                                 if (null != meta && meta.dataStoreId)
198                                 {
199                                         App.DataStore.listen(
200                                                         meta.id, meta.dataStoreId,
201                                                         $.proxy(App.ElementLibrary.BuildSelectOptions, this, null, meta),
202                                                         'Recurring'
203                                                         );
204                                 }
205                                 if (meta && meta.actions)
206                                 {
207                                         $("#" + meta.clearId).click(meta.bindClear);
208                                         $("#" + meta.searchId).click(meta.bindSearch);
209                                 }
210                                 else
211                                 {
212                                         if (null != meta && meta['bind'])
213                                         {
214                                                 meta['bind'](meta);
215                                         }
216                                 }
217                         }
218                 },
219
220                 GridColumnHeader : {
221                         html : function( meta )
222                         {
223                                 if (null == meta)
224                                 {
225                                         return '<th>&nbsp;</th>';
226                                 }
227                                 return '<th class="' + (meta.style ? meta.style : '') + '">'
228                                                 + '<div class="table-heading-wrapper">'
229                                                 + meta.title
230                                                 + (meta.order
231                                                                 ? '<span id="' + meta.order.id + '" class="make-caret handy"></span>'
232                                                                 : ''
233                                                   )
234                                                 + (meta.orderDesc
235                                                                 ? '<i id="' + meta.orderDesc.id + '" class="icon-circle-arrow-up icon-white handy pull-right"></i>'
236                                                                 : ''
237                                                   )
238                                                 + (meta.orderAsc
239                                                                 ? '<i id="' + meta.orderAsc.id + '" class="icon-circle-arrow-down icon-white handy pull-right"></i>'
240                                                                 : ''
241                                                   )
242                                                 + '</div>'
243                                                 + '</th>';
244                         },
245                         bind : function( meta )
246                         {
247                                 if (meta && meta.order)
248                                 {
249                                         $("#" + meta.order.id).click(meta.order.bind);
250                                 }
251                                 if (meta && meta.orderAsc)
252                                 {
253                                         $("#" + meta.orderAsc.id).click(meta.orderAsc.bind);
254                                 }
255                                 if (meta && meta.orderDesc)
256                                 {
257                                         $("#" + meta.orderDesc.id).click(meta.orderDesc.bind);
258                                 }
259                                 if (null != meta && meta['bind'])
260                                 {
261                                         meta['bind'](meta);
262                                 }
263                         }
264                 },
265
266                 GridColumnFilter : {
267                         html : function( meta )
268                         {
269                                 if (null == meta || !meta.id)
270                                 {
271                                         return '<td>'
272                                         + '<div class="filter-input">'
273                                         + '&nbsp;'
274                                         + '</div>'
275                                         + '</td>';
276                                 }
277                                 if (meta.dataStoreId)
278                                 {
279                                         if (!meta.options)
280                                         {
281                                                 meta.options = [];
282                                         }
283                                         if (!meta.selected)
284                                         {
285                                                 meta.selected = '';
286                                         }
287                                         var selectMe = '';
288                                         var html = '<td>';
289                                         html += '<div class="filter-input">';
290                                         html += '<select id="' + meta.id + '" name="' + meta.id + '" data-size="10" '
291                                                   + 'class="sp selectpicker show-menu-arrow ' + (meta.context ? meta.context : '') + '">';
292                                         for (var i = 0; i < meta.options.length; i++)
293                                         {
294                                                 selectMe = (meta.options[i].value == meta.selected) ? ' selected' : '';
295                                                 html += '<option value="' + meta.options[i].value + '"' + selectMe + '>' + meta.options[i].label + '</option>';
296                                         }
297                                         html += '</select>';
298                                         html += '</div>';
299                                         html += '</td>';
300                                         return html;
301                                 }
302                                 else
303                                 {
304                                         return '<td>'
305                                                         + '<div class="filter-input">'
306                                                         + '<input type="text" id="' + meta.id + '" class="'
307                                                         + (meta.context ? meta.context : '') + '" value="'
308                                                         + (meta.value ? meta.value : '')
309                                                         + '">'
310                                                         + '</div>'
311                                                         + '</td>';
312                                 }
313                         },
314                         bind : function( meta )
315                         {
316                                 if (null != meta && meta['bind'])
317                                 {
318                                         meta['bind'](meta);
319                                 }
320                                 if (null != meta && meta.dataStoreId)
321                                 {
322                                         App.DataStore.listen(
323                                                         meta.id, meta.dataStoreId,
324                                                         $.proxy(App.ElementLibrary.BuildSelectOptions, this, null, meta),
325                                                         'Recurring'
326                                                         );
327                                 }
328                         }
329                 },
330
331                 GridDataRow : {
332                         html : function( meta )
333                         {
334
335                                 if (null == meta)
336                                 {
337                                         return '<tr><td></td></tr>';
338                                 }
339                                 id = meta.items.id;
340                                 delete meta.items.id;
341                                 if (isNaN(id))
342                                 {
343                                         var ident = [];
344                                         for (var field in id)
345                                         {
346                                                 ident.push(field + '=' + id[field]);
347                                         }
348                                         var identifier = ident.join('&');
349                                 }
350                                 else
351                                 {
352                                         var identifier = 'id=' + id;
353                                 }
354
355                                 lineClass = meta.lineClass
356                                         ? meta.lineClass
357                                         : '';
358                                 var rowId = meta.rowId
359                                         ? 'id="row' + meta.rowId + '"'
360                                         : '';
361                                 var html = meta.url
362                                         ? '<tr ' + rowId + ' class="handy '+ lineClass +'" onClick="window.location=\'#/' + meta.url + '?' + identifier + '\';">'
363                                         : '<tr ' + rowId + 'class="'+ lineClass +'">';
364                                 if (!meta.style)
365                                 {
366                                         meta.style = {};
367                                 }
368                                 if (!meta.prepend)
369                                 {
370                                         meta.prepend = {};
371                                 }
372                                 if (!meta.append)
373                                 {
374                                         meta.append = {};
375                                 }
376                                 for (var item in meta.items)
377                                 {
378                                         html += '<td class="' + item + ' ' + (meta.style[item] ? meta.style[item] : '') + '">'
379                                                 + (meta.prepend[item] ? meta.prepend[item] : '')
380                                                 + (null != meta.items[item] ? meta.items[item] : '&nbsp;')
381                                                 + (meta.append[item] ? meta.append[item] : '')
382                                                 + '</td>';
383                                 }
384                                 html += '</tr>';
385                                 return html;
386                         },
387                         bind : function( meta )
388                         {
389                                 if (null != meta && meta['bind'])
390                                 {
391                                         meta['bind'](meta);
392                                 }
393                                 if (null != meta && meta.onClick && meta.rowId)
394                                 {
395                                         $('#row' + meta.rowId).click($.proxy(meta.onClick, this, meta));
396                                 }
397                         }
398                 },
399
400                 GridPager : {
401                         html : function( meta )
402                         {
403                                 if (null == meta)
404                                 {
405                                         return '&nbsp;';
406                                 }
407                                 var html = '<div class="pagination pull-right"><ul>';
408                                 html += '<li><a data-page="1" class="' + meta.itemName + '"> &lt;&lt; </a></li>';
409                                 var startPage = parseInt( meta.CurrentPage, 10 ) - 10;
410                                 var endPage = parseInt( meta.CurrentPage, 10 ) + 10;
411
412                                 if( startPage < 1 )
413                                 {
414                                         startPage = 1;
415                                         endPage = 21 - startPage;
416                                 }
417                                 if( endPage > meta.TotalPages )
418                                 {
419                                         endPage = meta.TotalPages;
420                                         startPage = endPage - 21;
421                                 }
422                                 if (startPage < 1)
423                                 {
424                                         startPage = 1;
425                                 }
426                                 if( endPage > meta.TotalPages )
427                                 {
428                                         endPage = meta.TotalPages;
429                                 }
430
431                                 for (var i = startPage; i <= endPage; i++)
432                                 {
433                                         html +=  (i == meta.CurrentPage)
434                                                 ? '<li><span data-page="' + i + '" class="' + meta.itemName + ' active"><b><i>' + i + '</i></b></span></li>'
435                                                 : '<li><a data-page="' + i + '" class="' + meta.itemName + '">' + i + '</a></li>';
436                                 }
437                                 html += '<li><a data-page="' + meta.TotalPages + '" class="' + meta.itemName + '"> &gt;&gt; </a></li>';
438                                 html += '</ul></div>';
439                                 return html;
440                         },
441                         bind : function( meta )
442                         {
443                                 if (meta && meta.bind)
444                                 {
445                                         $('.' + meta.itemName).click(function () {
446                                                 meta['bind']($(this).attr('data-page'));
447                                         });
448                                 }
449                         }
450                 },
451
452
453
454
455                 BuildSelectOptions : function ( tid, meta, dataId, options )
456                 {
457                         App.DataStore.setItem('BuildSelect:' + meta.id, true);
458                         var selected = $('#' + meta.id).val();
459                         if (!selected)
460                         {
461                                 if (meta.value)
462                                 {
463                                         if (meta.multiple)
464                                         {
465                                                 selected = [];
466                                                 for (var ii = 0; ii < meta.value.length; ii++)
467                                                 {
468                                                         selected.push(meta.value[ii]['id']);
469                                                 }
470                                         }
471                                         else
472                                         {
473                                                 selected = meta.value;
474                                         }
475                                 }
476                                 else
477                                 {
478                                         selected = '';
479                                 }
480                         }
481                         else if (meta.multiple)
482                         {
483                                 selected = null != selected
484                                         ? ('string' == typeof selected ? selected.split(',') : [selected])
485                                         : [];
486                         }
487                         var html = '';
488                         if (meta.selectEmpty)
489                         {
490                                 html += '<option value="">' + meta.selectEmpty + '</option>';
491                         }
492                         for (var i = 0; i < options.length; i++)
493                         {
494                                 html += '<option value="' + options[i].value + '">' + options[i].label + '</option>';
495                         }
496                         $('#' + meta.id).html(html);
497                         $('#' + meta.id).selectpicker('refresh');
498                         $('#' + meta.id).selectpicker('val', selected);
499                         App.DataStore.removeItem('BuildSelect:' + meta.id);
500                 },
501
502
503                 BuildSelectOptions2 : function ( tid, meta, dataId, options )
504                 {
505                         var elemId = meta.filterId
506                                 ? meta.filterId
507                                 : meta.id;
508                         App.DataStore.setItem('BuildSelect:' + elemId, true);
509                         var selected = $('#' + elemId).val();
510                         if (!selected)
511                         {
512                                 if (meta.value)
513                                 {
514                                         if (meta.multiple)
515                                         {
516                                                 selected = [];
517                                                 var selectMulti = {};
518                                                 for (var ii = 0; ii < meta.value.length; ii++)
519                                                 {
520                                                         selected.push(meta.value[ii].toString());
521                                                         selectMulti['x' + meta.value[ii]] = true;
522                                                 }
523                                         }
524                                         else
525                                         {
526                                                 selected = meta.value;
527                                         }
528                                 }
529                                 else
530                                 {
531                                         selected = '';
532                                 }
533                         }
534                         else if (meta.multiple)
535                         {
536                                 selected = [];
537                                 var selectMulti = {};
538                                 for (var ii = 0; ii < meta.value.length; ii++)
539                                 {
540                                         selected.push(meta.value[ii]['id'].toString());
541                                         selectMulti['x' + meta.value[ii]['id']] = true;
542                                 }
543                         }
544                         var opts = '';
545                         if (meta.selectEmpty)
546                         {
547                                 opts += '<option value="">' + meta.selectEmpty + '</option>';
548                         }
549                         var doSelect = '';
550                         for (var i = 0; i < options.length; i++)
551                         {
552                                 if (meta.multiple)
553                                 {
554                                         var val = options[i].value;
555                                         doSelect = (selectMulti['x' + val])
556                                                 ? 'selected'
557                                                 : '';
558                                 }
559                                 else
560                                 {
561                                         doSelect = (options[i].value == selected)
562                                                 ? 'selected'
563                                                 : '';
564                                 }
565                                 opts += '<option value="' + options[i].value + '" ' + doSelect + '>' + options[i].label + '</option>';
566                         }
567                         $('#' + elemId).html(opts);
568                         $('#' + elemId).select2('updateResults', true);
569                         $('#' + elemId).select2('val', selected);
570                         App.DataStore.removeItem('BuildSelect:' + elemId);
571                 },
572
573
574
575
576                 BuildCheckGroupHtml : function ( meta, options )
577                 {
578                         var items = {};
579                         if (undefined != meta.data)
580                         {
581                                 for (var i = 0; i < meta.data.length; i++)
582                                 {
583                                         items['i' + meta.data[i]] = true;
584                                 }
585                         }
586
587                         var sectiontMax = Math.ceil(options.length / 2);
588                         var divClass = 'control-group column-right';
589                         if (meta.split && 4 == meta.split)
590                         {
591                                 var sectiontMax = Math.ceil(options.length / 4);
592                                 var divClass = 'span3';
593                         }
594
595                         var html = (meta.split && 4 == meta.split)
596                                 ? '<div class="row-fluid"><div class="span3">'
597                                 : '<div class="control-group mobile-control-group column-left">';
598                         var r = 0;
599                         for (var i = 0; i < options.length; i++)
600                         {
601                                 if (r == sectiontMax)
602                                 {
603                                         html += '</div>';
604                                         html += '<div class="' + divClass + '">';
605                                         r = 0;
606                                 }
607                                 var itemId = options[i].value;
608                                 var label = options[i].label;
609                                 var checked = items['i' + itemId]
610                                         ? ' checked'
611                                         : '';
612                                 html += '<label class="checkbox checkbox-line">';
613                                 html += '<input type="checkbox" id="' + meta.itemName + itemId + 'Check" ';
614                                 html += 'value=""' + checked + ' class="' + meta.itemName + '" data-id="' + itemId + '">';
615                                 html += label;
616                                 html += '</label>';
617                                 r++;
618                         }
619                         html += '</div>';
620                         if ((meta.split && 4 == meta.split))
621                         {
622                                 html += '</div>';
623                         }
624                         return html;
625                 },
626
627                 BuildCheckGroup : function ( tid, meta, dataId, options )
628                 {
629                         var elem = $('#' + meta.id);
630                         if (!elem)
631                         {
632                                 return;
633                         }
634                         $('#' + meta.id).empty();
635                         var html = App.ElementLibrary.BuildCheckGroupHtml(meta, options);
636
637                         $('#' + tid + '_' + meta.id).html(html);
638                         for (var i = 0; i < options.length; i++)
639                         {
640                                 App.Util.updateCheckboxStyle($('#' + meta.itemName + options[i].value + 'Check'));
641                         }
642                 },
643
644                 BuildAmountCheckGroupHtml : function ( meta, options )
645                 {
646                         var damages = {};
647                         if (undefined != meta.data)
648                         {
649                                 for (var i = 0; i < meta.data.length; i++)
650                                 {
651                                         damages['d' + meta.data[i].damage] = meta.data[i].amount;
652                                 }
653                         }
654
655                         var html = '';
656                         var disabled = meta.disabled
657                                 ? ' disabled'
658                                 : '';
659                         for (var i = 0; i < options.length; i++)
660                         {
661                                 var dmgId = options[i].value;
662                                 var label = options[i].label;
663                                 var amount = damages['d' + dmgId]
664                                         ? damages['d' + dmgId]
665                                         : '0.00';
666                                 var checked = '0.00' == amount
667                                         ? ''
668                                         : ' checked';
669                                 var disable = '0.00' == amount || meta.disabled
670                                         ? ' disabled'
671                                         : '';
672                                 html += '<div class="control-group mobile-control-group">';
673                                 html += '<label class="checkbox checkbox-line">';
674                                 html += '<input type="checkbox" id="damage' + dmgId + 'Check" ';
675                                 html += 'value=""' + checked + ' data-target="damage' + dmgId + 'Amount" ' + disabled + '>';
676                                 html += label;
677                                 html += '</label>';
678                                 html += '<div class="controls mobile-controls">';
679                                 html += '<input class="rand-input damage-input" type="text" data-id="' + dmgId + '"';
680                                 html += 'id="damage' + dmgId + 'Amount" name="damage' + dmgId + 'Amount" value="' + amount + '"' + disable + '>';
681                                 html += '</div>';
682                                 html += '</div>';
683                         }
684                         return html;
685                 },
686
687                 BuildAmountCheckGroup : function ( tid, meta, dataId, options )
688                 {
689                         var elem = $('#' + meta.id);
690                         if (!elem)
691                         {
692                                 return;
693                         }
694                         $('#' + meta.id).empty();
695                         var html = App.ElementLibrary.BuildAmountCheckGroupHtml(meta, options);
696
697                         $('#' + tid + '_' + meta.id).html(html);
698                         for (var i = 0; i < options.length; i++)
699                         {
700                                 var elem = $('#damage' + options[i].value + 'Check');
701                                 App.Util.updateCheckboxStyle(elem);
702                                 elem.change(function () {
703                                         var checked = $(this).prop('checked');
704                                         var amntElem = $('#' + $(this).attr('data-target'));
705                                         amntElem.val('0.00');
706                                         amntElem.prop('disabled', !checked);
707                                         amntElem.trigger('change');
708                                 });
709                         }
710                         $('.rand-input').change(function () {
711                                 var total = 0.00;
712                                 $.each($.find('.damage-input'), function(i, input) {
713                                         total += parseFloat($(input).val());
714                                 });
715                                 $('#' + tid + '_damageTotal').html('R ' + total);
716                         });
717                         var total = 0.00;
718                         $.each($.find('.damage-input'), function(i, input) {
719                                 total += parseFloat($(input).val());
720                         });
721                         $('#' + tid + '_damageTotal').html('R ' + total);
722                         App.DataStore.removeItem('BuildAmountCheck:' + meta.id);
723                 },
724
725                 Field : {
726                         html : function ( meta, value )
727                         {
728                                 if (null == meta)
729                                 {
730                                         return '&nbsp;';
731                                 }
732                                 var disabled = undefined != meta.disabled && meta.disabled
733                                         ? ' disabled'
734                                         : '';
735                                 switch(meta.type)
736                                 {
737                                 case 'input':
738                                         var max = meta.maxlength
739                                                 ? ' maxlength="' + meta.maxlength + '"'
740                                                 : '';
741                                         var placeholder = meta.placeholder
742                                                 ? meta.placeholder
743                                                 : '';
744                                         if ('rand-input' == meta.style)
745                                         {
746                                                 placeholder = '0.00';
747                                         }
748                                         var html = '<label class="control-label mobile-control-label" ';
749                                         html += 'for="' + meta.id + '">' + meta.title + ':</label>';
750                                         html += '<div class="controls mobile-controls">';
751                                         html += '<input class="information-input mobile-information-input ' + (meta.style ? meta.style : '') + '" ';
752                                         html += 'placeholder="' + placeholder + '" type="text" id="' + meta.id + '" name="' + meta.id + '"' + max + disabled + '>';
753                                         html += '</div>';
754                                         return html;
755                                         break;
756                                 case 'date':
757                                         var attr = meta.attrib
758                                                 ? meta.attrib
759                                                 : '';
760                                         var html = '<label class="control-label mobile-control-label" ';
761                                         html += 'for="' + meta.id + '">' + meta.title + ':</label>';
762                                         html += '<div class="controls mobile-controls">';
763                                         html += '<input class="information-input mobile-information-input datepicker ' + (meta.style ? meta.style : '') + '" ';
764                                         html += 'type="text" data-date-format="yyyy-mm-dd" ' + attr + ' id="' + meta.id + '" name="' + meta.id + '"' + disabled + '>';
765                                         html += '</div>';
766                                         return html;
767                                         break;
768                                 case 'mobile':
769                                         var html = '<label class="control-label mobile-control-label" ';
770                                         html += 'for="' + meta.id + '">' + meta.title + ':</label>';
771                                         html += '<div class="input-prepend">';
772                                         html += '<span class="add-on">+264</span>';
773                                         html += '<input class="information-input mobile-information-input-short ' + (meta.style ? meta.style : '') + '" ';
774                                         html += 'type="text" id="' + meta.id + '" name="' + meta.id + '"' + disabled + '>';
775                                         html += '</div>';
776                                         return html;
777                                         break;
778                                 case 'checkbox':
779                                         var html = '<label class="checkbox checkbox-line">';
780                                         html += '<input type="checkbox" id="' + meta.id + '" value=""' + disabled + '>';
781                                         html += meta.title;
782                                         html += '</label>';
783                                         return html;
784                                         break;
785
786                                 case 'checkGroup':
787                                         var options = App.DataStore.dataStore[meta.dataStoreId]
788                                                 ? App.DataStore.dataStore[meta.dataStoreId]
789                                                 : {};
790                                         var html = App.ElementLibrary.BuildCheckGroupHtml(meta, options);
791                                         return html;
792                                         break;
793                                 case 'damageDetails':
794                                         var options = App.DataStore.dataStore[meta.dataStoreId]
795                                                 ? App.DataStore.dataStore[meta.dataStoreId]
796                                                 : {};
797                                         var html = App.ElementLibrary.BuildAmountCheckGroupHtml(meta, options);
798                                         return html;
799                                         break;
800                                 case 'amountCheck':
801                                         var html = '<label class="checkbox checkbox-line">';
802                                         html += '<input type="checkbox" id="' + meta.id + '" value=""' + disabled + '>';
803                                         html += meta.title;
804                                         html += '</label>';
805                                         html += '<div class="controls mobile-controls">';
806                                         html += '<input class="rand-input" type="text" id="' + meta.amountId + '" disabled>';
807                                         html += '</div>';
808                                         return html;
809                                         break;
810                                 case 'amount':
811                                         var html = '<label class="control-label mobile-control-label">';
812                                         html += meta.title;
813                                         html += '</label>';
814                                         html += '<div class="controls mobile-controls">';
815                                         html += '<input class="wide-rand-input" type="text" id="' + meta.id + '">';
816                                         html += '</div>';
817                                         return html;
818                                         break;
819                                 case 'amountAuction':
820                                         var html = '<label class="control-label mobile-control-label">';
821                                         html += meta.title;
822                                         html += '</label>';
823                                         html += '<div class="controls mobile-controls">';
824                                         html += '<input class="wide-rand-auction-input" type="text" id="' + meta.id + '">';
825                                         html += '</div>';
826                                         return html;
827                                         break;
828                                 case 'select2': //select2
829                                         if (meta.dataStoreId)
830                                         {
831                                                 if (meta.dataList)
832                                                 {
833                                                         App.DataStore.setData(meta.dataStoreId, meta.dataList);
834                                                 }
835                                                 else if (meta.dataQuery)
836                                                 {
837                                                         App.dataStoreId.loadSelectListData(
838                                                                         meta.dataStoreId,
839                                                                         meta.dataQuery.isStatic,
840                                                                         meta.dataQuery.workspace,
841                                                                         meta.dataQuery.task,
842                                                                         meta.dataQuery.jobId,
843                                                                         meta.dataQuery.data,
844                                                                         meta.dataQuery.options,
845                                                                         meta.dataQuery.callback
846                                                         );
847                                                 }
848                                         }
849                                         if (!meta.options)
850                                         {
851                                                 meta.options = [];
852                                         }
853                                         if (!meta.value)
854                                         {
855                                                 meta.value = !meta.multiple
856                                                         ? ''
857                                                         : [];
858                                         }
859                                         var eid = meta.id;
860                                         var attrib = '';
861                                         var label = '';
862                                         var labelStyle = '';
863                                         var inputStyle = '';
864                                         var inputWrapperStyle = '';
865                                         var labelSpan = '';
866                                         var inputSpan = '';
867                                         if (meta.multiple)
868                                         {
869                                                 attrib += ' multiple';
870                                         }
871                                         attrib += meta.title
872                                                 ? ' data-placeholder="' + meta.title + '"'
873                                                 : ((meta.title && !meta.selectEmpty)
874                                                                 ? ' data-placeholder="' + meta.title + '"'
875                                                                 : '');
876                                         var options = '';
877                                         if (meta.selectEmpty)
878                                         {
879                                                 options += '<option value="">meta.selectEmpty</option>';
880                                         }
881                                         for (var i = 0; i < meta.options.length; i++)
882                                         {
883                                                 options += '<option value="' + meta.options[i].value + '">' + meta.options[i].label + '</option>';
884
885                                         }
886                                         if (meta.title)
887                                         {
888                                                 // the check here
889                                                 if (undefined != meta.options.query)
890                                                 {
891                                                         var html = '<label for="' + eid + '" class="' + labelSpan + ' control-label mobile-control-label' + labelStyle + '">' + meta.title + ':</label>'
892                                                                 + '<div class="' + inputSpan + ' ' + inputWrapperStyle + ' controls mobile-controls">'
893                                                                 + '<div id="' + eid + '" name="' + eid + '" class="selector2 show-menu-arrow ' + inputStyle + '"'
894                                                                 + ' ' + attrib + ' ' + disabled + '>'
895                                                                 + '</div>'
896                                                                 + '</div>';
897                                                 }
898                                                 else
899                                                 {
900                                                         var html = '<label for="' + eid + '" class="' + labelSpan + ' control-label mobile-control-label' + labelStyle + '">' + meta.title + ':</label>'
901                                                                 + '<div class="' + inputSpan + ' ' + inputWrapperStyle + ' controls mobile-controls">'
902                                                                 + '<select id="' + eid + '" name="' + eid + '" class="selector2 show-menu-arrow ' + inputStyle + '"'
903                                                                 + ' ' + attrib + ' ' + disabled +'>'
904                                                                 + ' ' + options + ' '
905                                                                 + '</select>'
906                                                                 + '</div>';
907                                                 }
908
909
910                                         }
911                                         else
912                                         {
913                                                 if (undefined != meta.options.query)
914                                                 {
915                                                         var html = '<div class="' + inputSpan + ' ' + inputWrapperStyle + ' controls mobile-controls">'
916                                                                 + '<div id="' + eid + '" name="' + eid + '" class="selector2 show-menu-arrow' + inputStyle + '"'
917                                                                 + ' ' + attrib + ' ' + disabled + '>'
918                                                                 + '</div>'
919                                                                 + '</div>';
920                                                 }
921                                                 else
922                                                 {
923                                                         var html = '<div class="' + inputSpan + ' ' + inputWrapperStyle + ' controls mobile-controls">'
924                                                                 + '<select id="' + eid + '" name="' + eid +'" class="selector2 show-menu-arrow ' + inputStyle + '"'
925                                                                 + ' ' + attrib + ' ' + disabled + '>'
926                                                                 + ' ' + options + ' '
927                                                                 + '</select>'
928                                                                 + '</div>';
929                                                 }
930                                         }
931                                         return html;
932                                         break;
933                                 case 'select':
934                                         if (!meta.options)
935                                         {
936                                                 meta.options = [];
937                                         }
938                                         if (!meta.value)
939                                         {
940                                                 meta.value = !meta.multiple
941                                                         ? ''
942                                                         : [];
943                                         }
944                                         var multi = meta.multiple
945                                                 ? ' multiple title="' + meta.title + '"'
946                                                 : ' title="' + meta.title + '"';
947                                         var selectMe = '';
948                                         var html = '';
949                                         if (meta.title)
950                                         {
951                                                 html += '<label class="control-label mobile-control-label" for="' + meta.id + '">' + meta.title + ':</label>';
952                                         }
953                                         html += '<select id="' + meta.id + '" name="' + meta.id + '" data-size="10" class="sp selectpicker show-menu-arrow"' + multi + disabled + '>';
954                                         for (var i = 0; i < meta.options.length; i++)
955                                         {
956                                                 if (meta.multiple)
957                                                 {
958                                                         selectMe = '';
959                                                         for (var sv = 0; sv < meta.value.length; sv++)
960                                                         {
961                                                                 if (meta.value[sv]['id'] == meta.options[i].value)
962                                                                 {
963                                                                         selectMe = ' selected';
964                                                                         break;
965                                                                 }
966                                                         }
967                                                 }
968                                                 else
969                                                 {
970                                                         selectMe = (meta.options[i].value == meta.value) ? ' selected' : '';
971                                                 }
972                                                 selectMe = '';
973                                                 html += '<option value="' + meta.options[i].value + '"' + selectMe + '>' + meta.options[i].label + '</option>';
974                                         }
975                                         html += '</select>';
976                                         return html;
977                                         break;
978                                 case 'textarea-small':
979                                         var html = '<label class="control-label mobile-control-label" for="' + meta.id + '">' + meta.title + ':</label>';
980                                         html += '<textarea id="' + meta.id + '" class="text-box-small" rows="3"' + disabled + ' maxlength="500"></textarea>';
981                                         return html;
982                                         break;
983                                 case 'htmltext':
984                                         //var html = '<label class="control-label mobile-control-label pad-top-none" for="' + meta.id + '">' + meta.title + ':</label><br/>';
985                                         //html += '<textarea id="' + meta.id + '" class="span12" rows="12"' + disabled + '></textarea>';
986                                         var html = '';
987                                         html += '<div id="' + meta.id + '-toolbar" class="btn-toolbar" data-role="editor-toolbar" data-target="#' + meta.id + '">';
988                                         html += '  <div class="btn-group">';
989                                         html += '    <a class="btn dropdown-toggle" data-toggle="dropdown" title="" data-original-title="Font Size"><i class="icon-text-height"></i>&nbsp;<b class="caret"></b></a>';
990                                         html += '      <ul class="dropdown-menu">';
991                                         html += '      <li><a data-edit="fontSize 5"><font size="5">Huge</font></a></li>';
992                                         html += '      <li><a data-edit="fontSize 3"><font size="3">Normal</font></a></li>';
993                                         html += '      <li><a data-edit="fontSize 1"><font size="1">Small</font></a></li>';
994                                         html += '      </ul>';
995                                         html += '  </div>';
996                                         html += '  <div class="btn-group">';
997                                         html += '    <a class="btn" data-edit="bold" title="" data-original-title="Bold (Ctrl/Cmd+B)"><i class="icon-bold"></i></a>';
998                                         html += '    <a class="btn" data-edit="italic" title="" data-original-title="Italic (Ctrl/Cmd+I)"><i class="icon-italic"></i></a>';
999                                         html += '  </div>';
1000                                         html += '  <div class="btn-group">';
1001                                         html += '    <a class="btn" data-edit="outdent" title="" data-original-title="Reduce indent (Shift+Tab)"><i class="icon-indent-left"></i></a>';
1002                                         html += '    <a class="btn" data-edit="indent" title="" data-original-title="Indent (Tab)"><i class="icon-indent-right"></i></a>';
1003                                         html += '  </div>';
1004                                         html += '  <div class="btn-group">';
1005                                         html += '    <a class="btn btn-info" data-edit="justifyleft" title="" data-original-title="Align Left (Ctrl/Cmd+L)"><i class="icon-align-left"></i></a>';
1006                                         html += '    <a class="btn" data-edit="justifycenter" title="" data-original-title="Center (Ctrl/Cmd+E)"><i class="icon-align-center"></i></a>';
1007                                         html += '    <a class="btn" data-edit="justifyright" title="" data-original-title="Align Right (Ctrl/Cmd+R)"><i class="icon-align-right"></i></a>';
1008                                         html += '    <a class="btn" data-edit="justifyfull" title="" data-original-title="Justify (Ctrl/Cmd+J)"><i class="icon-align-justify"></i></a>';
1009                                         html += '  </div>';
1010                                         html += '</div>';
1011                                         html += '<div id="' + meta.id + '" contenteditable="true" class="wysiwyg-editor">';
1012                                         html += '';
1013                                         html += '</div>';
1014                                         return html;
1015                                         break;
1016                                 case 'textarea-styled':
1017                                         var style = meta.areaStyle
1018                                                 ? meta.areaStyle
1019                                                 : 'textbox';
1020                                         var html = '<p class="' + meta.style + '">' + meta.title + ':</p>';
1021                                         html += '<textarea id="' + meta.id + '" class="' + style + '" rows="4"' + disabled + ' maxlength="500"></textarea>';
1022                                         return html;
1023                                         break;
1024                                 case 'image':
1025                                         var html = '';
1026                                         html += '<input id="btn_' + meta.id + '" class="hide" ';
1027                                         html += 'type="file" name="files[]" data-url="/workspace/image-upload">';
1028                                         html += '<input type="hidden" id="' + meta.id + '">';
1029                                         html += '<img id="img_' + meta.id + '" ';
1030                                         html += 'src="/imgs/' + meta.baseImage + '" ';
1031                                         html += 'class="img-polaroid motor-vichile-imgs handy">';
1032                                         return html;
1033                                         break;
1034                                 case 'bidMainImage':
1035                                         var html = '';
1036                                         html += '<img id="bidImgMain" src="/imgs/' + meta.baseImage + '"';
1037                                         html += 'data-zoom="" ';
1038                                         html += 'class="handy" width="100%" height="100%" />';
1039                                         return html;
1040                                         break;
1041                                 case 'bidimage':
1042                                         var html = '';
1043                                         html += '<a id="bidHref' + meta.id + '" data-image=""';
1044                                         html += 'data-zoom-image="" width="140px" height="140px">';
1045                                         html += '<img id="bidImg' + meta.id + '" src="/imgs/' + meta.baseImage + '" class="img-polaroid handy span12" width="140px" height="140px"/>'; // width="80%" height="80%"
1046                                         html += '</a>';
1047
1048                                         return html;
1049                                         break;
1050                                 case 'attachment':
1051                                         var html = '';
1052                                         html += '<div class="span3"><input id="btn_' + meta.id + '" class="hide" ';
1053                                         html += 'type="file" name="files[]" data-url="/workspace/attachment-upload">';
1054                                         html += '<input type="hidden" id="' + meta.id + '">';
1055                                         html += '<img id="doc_' + meta.id + '" ';
1056                                         html += 'src="/imgs/upload.png" ';
1057                                         html += 'class="img-polaroid handy"></div>';
1058                                         html += '<div class="span7"><label for="btn_' + meta.id + '">' + meta.title + '</label></div>';
1059                                         return html;
1060                                         break;
1061                                 case 'document':
1062                                         var html = '';
1063                                         html += '<div class="span3"><input id="btn_' + meta.id + '" class="hide" ';
1064                                         html += 'type="file" name="files[]" data-url="/workspace/document-upload">';
1065                                         html += '<input type="hidden" id="' + meta.id + '">';
1066                                         html += '<img id="doc_' + meta.id + '" ';
1067                                         html += 'src="/imgs/upload.png" ';
1068                                         html += 'class="img-polaroid handy">';
1069                                         if (App.userData && 'test9@nirph.com' == App.userData.email)
1070                                         {
1071                                                 html += '<img id="doc_rmv_' + meta.id + '" ';
1072                                                 html += 'src="/imgs/x_img.jpg" ';
1073                                                 html += 'class="img-polaroid doct-remove handy hide">';
1074                                         }
1075                                         html += '</div>';
1076                                         html += '<div class="span7"><label for="btn_' + meta.id + '">' + meta.title + '</label></div>';
1077                                         return html;
1078                                         break;
1079                 case 'document_button':
1080                     var html = '';
1081                     html += '<div class="span6">';
1082                     html += '<img id="doc_' + meta.id + '"';
1083                     html += 'src="/imgs/upload.png" ';
1084                     html += 'class="img-polaroid handy">';
1085                     html += '<input id="btn_' + meta.id + '"';
1086                     html += 'type="file" data-url="/workspace/document-upload">';
1087                     html += '<input type="hidden" id="' + meta.id + '">';
1088                     if (App.userData && 'test9@nirph.com' == App.userData.email)
1089                     {
1090                         html += '<img id="doc_rmv_' + meta.id + '" ';
1091                         html += 'src="/imgs/x_img.jpg" ';
1092                         html += 'class="img-polaroid doct-remove handy hide">';
1093                     }
1094                     html += '</div>';
1095                     html += '<div class="span6 fileName" id="fileName"></div>';
1096                     //html += '<div class="span6"><input for="btn_' + meta.id + '" value="' + meta.title + '" data-url="/workspace/document-upload"></div>';
1097
1098                     return html;
1099                     break;
1100                                 case 'collector':
1101                                         var html = '';
1102                                         html += '<div class="accordion" id="' + meta.id + '">';
1103                                         html += '</div>';
1104                                         return html;
1105                                         break;
1106                                 }
1107                                 return '';
1108                         },
1109                         setValue : function ( tid, meta, value )
1110                         {
1111                                 if ('' == value)
1112                                 {
1113                                         return;
1114                                 }
1115                                 switch(meta.type)
1116                                 {
1117                                 case 'select':
1118                                         $('#' + meta.id).selectpicker('val', value);
1119                                         break;
1120                                 case 'select2': //select2
1121                                         $('#' + meta.id).select2('val', value);
1122                                         break;
1123                                 case 'checkbox':
1124                                         $('#' + meta.id).prop('checked', value);
1125                                         break;
1126                                 case 'amountCheck':
1127                                         $('#' + meta.id).prop('checked', value != '' ? true : false);
1128                                         $('#' + meta.amountId).val(value);
1129                                         break;
1130                                 case 'checkGroup':
1131                                 case 'damageDetails':
1132                                         //$('#' + meta.id).prop('checked', value != '' ? true : false);
1133                                         //$('#' + meta.amountId).val(value);
1134                                         break;
1135                                 case 'image':
1136                                         $('#img_' + meta.id).attr('src', '/img/bin/thumbnail/' + value.filename);
1137                                         $('#img_' + meta.id).attr('data-large', '/img/bin/' + value.filename);
1138                                         $('#' + meta.id).val(value.id);
1139                                         if ($('#img_' + meta.id).hasClass('error'))
1140                                         {
1141                                                 $('#img_' + meta.id).removeClass('error');
1142                                                 $('#img_' + meta.id).addClass('valid');
1143                                         }
1144                                         break;
1145                                 case 'bidMainImage':
1146
1147                                         //console.log(value.filename);
1148
1149                                         $('#bidImgMain').attr('src', '/img/bin/thumbnail/' + value.filename);
1150                                         $('#bidImgMain').attr('data-zoom-image', '/img/bin/' + value.filename);
1151
1152                                         $("#bidImgMain").elevateZoom({
1153                                                 zscrollZoom : true,
1154                                                 gallery:'gal1',
1155                                                 cursor: 'pointer',
1156                                                 galleryActiveClass: 'active',
1157                                                 imageCrossfade: true
1158                                         });
1159
1160                                         $('#bidImgMain').css('max-width', '15.2%');
1161                                         $('#bidImgMain').css('min-width', '120px');
1162                                         //$('#bidImgMain').css('height', '20%');
1163
1164
1165                                         break;
1166                                 case 'bidimage':
1167
1168                                                 $('#tS1.jThumbnailScroller').css('min-width', '15.2%');
1169                                                 $('#tS1.jThumbnailScroller').css('margin-top', '120px');
1170                                                 $('#bidImgMain').css('max-width', '15.2%');
1171                                                 $('#bidImgMain').css('min-width', '120px');
1172
1173                                         $('#bidHref' + meta.id).css('width', '140px');
1174                                         $('#bidHref' + meta.id).css('height', '100px');
1175
1176                                         $('#bidHref' + meta.id).attr('data-image', '/img/bin/thumbnail/' + value.filename);
1177                                         $('#bidHref' + meta.id).attr('data-zoom-image', '/img/bin/' + value.filename);
1178                                         $('#bidImg' + meta.id).attr('src', '/img/bin/thumbnail/' + value.filename);
1179                                         $('#bidImg' + meta.id).attr('data-large', '/img/bin/' + value.filename);
1180                                         $('#' + meta.id).val(value.id);
1181                                         break;
1182                                 case 'attachment':
1183                                         console.log(value);
1184                                         console.log('+++++++++++++++');
1185                                 case 'document':
1186                                         $('#doc_' + meta.id).attr('src', '/imgs/uploaded.png');
1187                                         if (App.userData && 'test9@nirph.com' == App.userData.email)
1188                                         {
1189                                                 $('#doc_rmv_' + meta.id).show();
1190                                         }
1191                                         $('#doc_' + meta.id).attr('data-download', '/documents/' + value.filename);
1192                                         $('#' + meta.id).val(value.id);
1193
1194
1195                                 break;
1196                 case 'document_button':
1197                     $('#doc_' + meta.id).attr('src', '/imgs/uploaded.png');
1198                     if (App.userData && 'test9@nirph.com' == App.userData.email)
1199                     {
1200                         $('#doc_rmv_' + meta.id).show();
1201                     }
1202                     $('#doc_' + meta.id).append('bla');
1203                     $('#doc_' + meta.id).attr('data-download', '/documents/' + value.filename);
1204                     $('#' + meta.id).val(value.id);
1205
1206
1207                     break;
1208                                 case 'mobile':
1209                                         if ('string' == typeof value && '0' == value.substring(0,1))
1210                                         {
1211                                                 value = value.substring(1);
1212                                         }
1213                                         if ('string' == typeof value && '264' == value.substring(0,3))
1214                                         {
1215                                                 value = value.substring(3);
1216                                         }
1217                                         if ('string' == typeof value && '+264' == value.substring(0,4))
1218                                         {
1219                                                 value = value.substring(4);
1220                                         }
1221                                         $('#' + meta.id).val(value);
1222                                         break;
1223                                 case 'collector':
1224                                         break;
1225                                 case 'htmltext':
1226                                         $('#' + meta.id).html(value);
1227                                         break;
1228                                 default:
1229                                         $('#' + meta.id).val(value);
1230                                         break;
1231                                 }
1232                         },
1233                         harvest : function ( tid, meta )
1234                         {
1235                                 if (null == meta)
1236                                 {
1237                                         return null;
1238                                 }
1239                                 switch(meta.type)
1240                                 {
1241                                 case 'collector':
1242                                         return null;
1243                                         break;
1244                                 case 'select':
1245                                         return $('#' + meta.id).val();
1246                                         break;
1247                                 case 'select2': //select2
1248                                         return $('#' + meta.id).select2('val');
1249                                         break;
1250                                 case 'checkGroup':
1251                                         var items = [];
1252                                         $.each($.find('.' + meta.itemName), function(i, input) {
1253                                                 if ( $(input).prop('checked') )
1254                                                 {
1255                                                         items.push({
1256                                                                 'id': $(input).attr('data-id')
1257                                                         });
1258                                                 }
1259                                         });
1260                                         return items;
1261                                         break;
1262                                 case 'damageDetails':
1263                                         var damages = [];
1264                                         $.each($.find('.damage-input'), function(i, input) {
1265                                                 var amount = $(input).val();
1266                                                 amount = '' != amount
1267                                                         ? parseFloat(amount)
1268                                                         : 0.00;
1269                                                 if (0.00 != amount)
1270                                                 {
1271                                                         damages.push({
1272                                                                 'id': $(input).attr('data-id'),
1273                                                                 'amount': amount
1274                                                         });
1275                                                 }
1276                                         });
1277                                         return damages;
1278                                         break;
1279                                 case 'checkbox':
1280                                         return $('#' + meta.id).prop('checked');
1281                                         break;
1282                                 case 'mobile':
1283                                         value =  $('#' + meta.id).val();
1284                                         if (value && '0' == value.substring(0,1))
1285                                         {
1286                                                 value = value.substring(1);
1287                                         }
1288                                         if (value && '+264' == value.substring(0,3))
1289                                         {
1290                                                 value = value.substring(3);
1291                                         }
1292                                         return '+264' + value;
1293                                         break;
1294                                 case 'htmltext':
1295                                         return $('#' + meta.id).html();
1296                                         break;
1297                                 default:
1298                                         return $('#' + meta.id).val();
1299                                         break;
1300                                 }
1301                         },
1302                         bind : function ( tid, meta )
1303                         {
1304                                 if (meta.mask)
1305                                 {
1306                                         $('#' + meta.id).mask(meta.mask);
1307                                         $('#' + meta.id).focus(function () {
1308                                                 $('#' + meta.id).setCursorPosition(0);
1309                                         });
1310                                 }
1311                                 if ('select2' == meta.type) //select2
1312                                 {
1313                                         var defaults = {
1314                                                         allowClear: true,
1315                                                         closeOnSelect: false,
1316                                                         width: "parent",
1317                                                         placeholder: meta.title
1318                                                                 ? meta.title
1319                                                                 : ((meta.label && !meta.selectEmpty)
1320                                                                         ? meta.label
1321                                                                         : 'Select')
1322                                         };
1323                                         var options = meta.options
1324                                                 ? $.extend(true, {}, defaults, meta.options)
1325                                                 : defaults;
1326                                         $('#' + meta.id).select2(options);
1327                                         $('#' + meta.id).val = function(value) {
1328                                                 if (undefined == value)
1329                                                 {
1330                                                         return $(this).select2('val');
1331                                                 }
1332                                                 $(this).select2('val', value);
1333                                         };
1334                                 }
1335                                 if ('htmltext' == meta.type)
1336                                 {
1337                                         $('#' + meta.id).wysiwyg();
1338
1339 //                                      if (CKEDITOR && CKEDITOR.instances[meta.id])
1340 //                                      {
1341 //                                              /*try {*/ CKEDITOR.instances[meta.id].destroy(true); /*} catch (e) {}*/
1342 //                                              //CKEDITOR.replace(meta.id);
1343 //                                              $('#cke_content').remove();
1344 //                                              console.log('......................');
1345 //                                      }
1346 //                                      //else
1347 //                                      //{
1348 //                                              //setTimeout(function () {
1349 //                                                      $('#' + meta.id).ckeditor({
1350 //                                                              toolbar : 'Basic',
1351 //                                                              language : 'en',
1352 //                                                              uiColor : '#F9F9F9',
1353 //                                                              resize_dir: 'vertical',
1354 //                                                              toolbarCanCollapse: true,
1355 //                                                              pasteFromWordRemoveFontStyles: true,
1356 //                                                              pasteFromWordRemoveStyles: true,
1357 //                                                              pasteFromWordPromptCleanup:true,
1358 //                                                              scayt_autoStartup:true,
1359 //                                                              scayt_sLang:'nl_NL',
1360 //                                                              width:'95%',
1361 //                                                              toolbar_Basic : [
1362 //                                                                      { name: 'document', items : [ 'Source'] },
1363 //                                                                      { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
1364 //                                                                      { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
1365 //                                                                      { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] },
1366 //                                                                      { name: 'tools', items : [ 'Maximize', 'ShowBlocks' ] }
1367 //                                                              ]
1368 //                                                      });
1369 //                                              //}, 500);
1370 //                                      //}
1371                                 }
1372                                 if ('document_button' == meta.type || 'document' == meta.type || 'attachment' == meta.type)
1373                                 {
1374                                         if (!meta.view)
1375                                         {
1376                                                 if (App.userData && 'test9@nirph.com' == App.userData.email)
1377                                                 {
1378                                                         $('#doc_rmv_' + meta.id).click(function(metaId)
1379                                                         {
1380                                                                 _w.systemdealerview.docFieldRemoveId = $(this).attr('id');
1381                                                                 _w.systemdealerview.docFieldRemove = $(this).attr('id').replace('doc_rmv_', '');
1382                                                                 App.API.getTask(
1383                                                                       'removeDocument:' + _w.systemdealerview.itemId,
1384                                                                       'Company', 'Company.RemoveDocument',
1385                                                                       _w.systemdealerview.itemId,
1386                                                                       {'id': _w.systemdealerview.itemId},
1387                                                                       $.proxy(function()
1388                                                                       {
1389                                                                           var data = {
1390                                                                                           Company: {}
1391                                                                           };
1392                                                                           data.Company[_w.systemdealerview.docFieldRemove] = true;
1393                                                                           App.API.execTask(
1394                                                                                           'removeDocument:' + _w.systemdealerview.itemId, data, {},
1395                                                                                           function () {
1396                                                                                                   $('#' + _w.systemdealerview.docFieldRemoveId).remove();
1397                                                                                           }, _w.taskExecError
1398                                                                                   );
1399                                                                       }, this),
1400                                                                       _w.taskContractError
1401                                                               );
1402                                                         });
1403                                                 }
1404
1405                                                 $('#doc_' + meta.id).click(function()
1406                                                 {
1407                                                         if (undefined != $(this).attr('data-download'))
1408                                                         {
1409                                                                 App.Ajax.DOWNLOAD({
1410                                                                         url: $(this).attr('data-download')
1411                                                                 });
1412                                                         }
1413                                                         else
1414                                                         {
1415                                                                 $('#btn_' + meta.id).click();
1416                                                         }
1417                                                 });
1418                                                 $('#btn_' + meta.id).fileupload({
1419                                                       dataType: 'json',
1420                                                   fail: function (e, data) {
1421                                                                   alert('Could not upload document.');
1422                                                       },
1423                                                       done: function (e, data) {
1424                                                           $.each(data.result, function (i, file) {
1425                                                                   if (file.error)
1426                                                                   {
1427                                                                           alert(file.error);
1428                                                                           return;
1429                                                                   }
1430                                       $('#fileName').html(data.files[0].name);
1431                                                               $('#' + meta.id).val(file.id);
1432                                                               $('#doc_' + meta.id).attr('src', '/imgs/uploaded.png');
1433                                                               $('#doc_' + meta.id).attr('data-download', '/documents/' + file.name);
1434                                                           });
1435                                                       }
1436                                                 });
1437                                         }
1438                                         else
1439                                         {
1440                                                 $('#doc_' + meta.id).click(function()
1441                                                 {
1442                                                         App.Ajax.DOWNLOAD({
1443                                                                 direct: true,
1444                                                                 url: $(this).attr('data-download')
1445                                                         });
1446                                                 });
1447                                         }
1448                                 }
1449                                 if ('image' == meta.type)
1450                                 {
1451                                         if (!meta.view)
1452                                         {
1453                                                 $('#img_' + meta.id).click(function() {
1454
1455                                                         $('#btn_' + meta.id).click();
1456                                                 });
1457                                                 $('#btn_' + meta.id).fileupload({
1458                                                       dataType: 'json',
1459                                                   fail: function (e, data) {
1460                                                                   alert('Could not upload image.');
1461                                                       },
1462                                                       done: function (e, data) {
1463                                                           $.each(data.result, function (i, file) {
1464                                                                   if (file.error)
1465                                                                   {
1466                                                                           alert(file.error);
1467                                                                           return;
1468                                                                   }
1469                                                               $('#' + meta.id).val(file.id);
1470                                                               $('#img_' + meta.id).attr('src', '/img/bin/' + file.name);
1471                                                               if ($('#img_' + meta.id).hasClass('error'))
1472                                                               {
1473                                                                                         $('#img_' + meta.id).removeClass('error');
1474                                                                                         $('#img_' + meta.id).addClass('valid');
1475                                                               }
1476                                                           });
1477                                                       }
1478                                                 });
1479                                         }
1480                                         else
1481                                         {
1482                                                 $('#img_' + meta.id).click(function()
1483                                                 {
1484                                                         var _src = $('#img_' + meta.id).attr('data-large');
1485                                                         if(undefined == _src || '' == _src)
1486                                                         {
1487                                                                 return;
1488                                                         }
1489                                                         $('#imgLarge').attr('src', _src);
1490                                                         $('#sectionMain').hide();
1491                                                         $('#sectionImage').show();
1492                                                 });
1493                                         }
1494                                 }
1495                                 if ('bidimage' == meta.type)
1496                                 {
1497                                         $('#bidImg' + meta.id).click(function()
1498                                         {
1499                                                 var _src = $('#bidImg' + meta.id).attr('data-large');
1500                                                 if(undefined == _src || '' == _src)
1501                                                 {
1502                                                         return;
1503                                                 }
1504                                                 $('#bidImgMain').attr('src', $('#bidImg' + meta.id).attr('src'));
1505                                                 $('#bidImgMain').attr('data-zoom-image', _src);
1506                                         });
1507
1508                                 }
1509                                 if ('bidMainImage' == meta.type)
1510                                 {
1511                                         // .....
1512                                 }
1513                                 if (meta.dataStoreId)
1514                                 {
1515                                         switch (meta.type)
1516                                         {
1517                                         case 'select':
1518                                                 App.DataStore.listen(
1519                                                                 meta.id, meta.dataStoreId,
1520                                                                 $.proxy(App.ElementLibrary.BuildSelectOptions, this, tid, meta),
1521                                                                 'Recurring'
1522                                                                 );
1523                                                 break;
1524                                         case 'select2': //select2
1525                                                 App.DataStore.listen(
1526                                                                 meta.id, meta.dataStoreId,
1527                                                                 $.proxy(App.ElementLibrary.BuildSelectOptions2, this, tid, meta),
1528                                                                 'Recurring'
1529                                                 );
1530                                                 break;
1531                                         case 'checkGroup':
1532                                                 App.DataStore.listen(
1533                                                                 meta.id, meta.dataStoreId,
1534                                                                 $.proxy(App.ElementLibrary.BuildCheckGroup, this, tid, meta),
1535                                                                 'Recurring'
1536                                                                 );
1537                                                 break;
1538                                         case 'damageDetails':
1539                                                 App.DataStore.listen(
1540                                                                 meta.id, meta.dataStoreId,
1541                                                                 $.proxy(App.ElementLibrary.BuildAmountCheckGroup, this, tid, meta),
1542                                                                 'Recurring'
1543                                                                 );
1544                                                 break;
1545                                         }
1546                                 }
1547                                 if ('date' == meta.type)
1548                                 {
1549                                         var opt = meta.dtopt ? meta.dtopt : {};
1550                                         $('#' + meta.id).datepicker(opt);
1551                                 }
1552                                 if ('select' == meta.type || 'select2' == meta.type)
1553                                 {
1554                                         $('#' + meta.id).change(function() {
1555                                                 if (!App.DataStore.getItem('BuildSelect:' + meta.id, false))
1556                                                 {
1557                                                         try
1558                                                         {
1559                                                                 $(this).valid();
1560                                                         }
1561                                                         catch (err)
1562                                                         {
1563                                                                 // no worries
1564                                                         }
1565                                                 }
1566                                         });
1567                                 }
1568                                 if (meta.onChange)
1569                                 {
1570                                         $('#' + meta.id).change(meta.onChange);
1571                                 }
1572                                 if (meta.onFocus)
1573                                 {
1574                                         $('#' + meta.id).on('focus', meta.onFocus);
1575                                 }
1576                                 if (meta.onBlur)
1577                                 {
1578                                         $('#' + meta.id).on('blur', meta.onBlur);
1579                                 }
1580                                 if (meta['bind'])
1581                                 {
1582                                         meta['bind'](meta);
1583                                 }
1584                                 if ('checkbox' == meta.type || 'amountCheck' == meta.type)
1585                                 {
1586                                         App.Util.updateCheckboxStyle( $('#' + meta.id) );
1587                                 }
1588                         }
1589                 }
1590
1591
1592         };
1593 })();