;(function(){
_App.ElementLibrary = function()
{
this.initialize();
};
_App.ElementLibrary.prototype =
{
initialize : function()
{
// Nothing to do.
},
Button : {
html : function( meta )
{
if (null == meta)
{
return '';
}
if (meta.preset)
{
var disabledclass = undefined != meta.permission && false == meta.permission
? 'disabled'
: '';
switch(meta.preset)
{
case 'GridExport':
return '';
case 'NewValuation':
return '';
case 'ValuationReport':
return ' ';
case 'NewStock':
return '';
case 'AuctionReport':
return '';
case 'BulkImporter':
return '';
case 'SellVehicle':
return '';
case 'Print':
return '';
case 'PrintTC':
return '';
}
}
else
{
return '';
}
},
bind : function( meta )
{
if (null == meta)
{
return;
}
if (meta.preset)
{
switch(meta.preset)
{
case 'NewValuation':
case 'ValuationReport':
case 'NewStock':
case 'AuctionReport':
case 'BulkImporter':
case 'Print':
case 'PrintTC':
case 'GridExport':
$("#" + meta.id).click(meta.handler);
break;
}
}
else
{
if (meta['bind'])
{
meta['bind'](meta);
}
}
}
},
GridContextFilter : {
html : function( meta )
{
if (null == meta)
{
return '
';
}
var style = undefined != meta.style ? meta.style : 'span2';
var divStyle = undefined != meta.divStyle ? meta.divStyle : '';
var readonly = meta.readonly ? " readonly" : '';
var prepend = meta.prepend ? '' + meta.prepend + '' : '';
var append = meta.append ? '' + meta.append + '' : '';
if (meta.actions)
{
return '
'
+ ''
+ ''
+ '
';
}
else
{
if (meta.dataStoreId)
{
if (!meta.options)
{
meta.options = [];
}
if (!meta.selected)
{
meta.selected = '';
}
var selectMe = '';
var html = '
';
html += '
';
html += (meta.title ? meta.title : ' ');
html += '
';
html += '
' + prepend
html += '';
html += append + '
';
html += '
';
return html;
}
else
{
return '
'
+ '
'
+ (meta.title ? meta.title : ' ')
+ '
'
+ '
' + prepend
+ ''
+ append + '
'
+ '
';
}
}
},
bind : function( meta )
{
if (null != meta && meta.dataStoreId)
{
App.DataStore.listen(
meta.id, meta.dataStoreId,
$.proxy(App.ElementLibrary.BuildSelectOptions, this, null, meta),
'Recurring'
);
}
if (meta && meta.actions)
{
$("#" + meta.clearId).click(meta.bindClear);
$("#" + meta.searchId).click(meta.bindSearch);
}
else
{
if (null != meta && meta['bind'])
{
meta['bind'](meta);
}
}
}
},
GridColumnHeader : {
html : function( meta )
{
if (null == meta)
{
return '
';
return html;
},
bind : function( meta )
{
if (meta && meta.bind)
{
$('.' + meta.itemName).click(function () {
meta['bind']($(this).attr('data-page'));
});
}
}
},
BuildSelectOptions : function ( tid, meta, dataId, options )
{
App.DataStore.setItem('BuildSelect:' + meta.id, true);
var selected = $('#' + meta.id).val();
if (!selected)
{
if (meta.value)
{
if (meta.multiple)
{
selected = [];
for (var ii = 0; ii < meta.value.length; ii++)
{
selected.push(meta.value[ii]['id']);
}
}
else
{
selected = meta.value;
}
}
else
{
selected = '';
}
}
else if (meta.multiple)
{
selected = null != selected
? ('string' == typeof selected ? selected.split(',') : [selected])
: [];
}
var html = '';
if (meta.selectEmpty)
{
html += '';
}
for (var i = 0; i < options.length; i++)
{
html += '';
}
$('#' + meta.id).html(html);
$('#' + meta.id).selectpicker('refresh');
$('#' + meta.id).selectpicker('val', selected);
App.DataStore.removeItem('BuildSelect:' + meta.id);
},
BuildSelectOptions2 : function ( tid, meta, dataId, options )
{
var elemId = meta.filterId
? meta.filterId
: meta.id;
App.DataStore.setItem('BuildSelect:' + elemId, true);
var selected = $('#' + elemId).val();
if (!selected)
{
if (meta.value)
{
if (meta.multiple)
{
selected = [];
var selectMulti = {};
for (var ii = 0; ii < meta.value.length; ii++)
{
selected.push(meta.value[ii].toString());
selectMulti['x' + meta.value[ii]] = true;
}
}
else
{
selected = meta.value;
}
}
else
{
selected = '';
}
}
else if (meta.multiple)
{
selected = [];
var selectMulti = {};
for (var ii = 0; ii < meta.value.length; ii++)
{
selected.push(meta.value[ii]['id'].toString());
selectMulti['x' + meta.value[ii]['id']] = true;
}
}
var opts = '';
if (meta.selectEmpty)
{
opts += '';
}
var doSelect = '';
for (var i = 0; i < options.length; i++)
{
if (meta.multiple)
{
var val = options[i].value;
doSelect = (selectMulti['x' + val])
? 'selected'
: '';
}
else
{
doSelect = (options[i].value == selected)
? 'selected'
: '';
}
opts += '';
}
$('#' + elemId).html(opts);
$('#' + elemId).select2('updateResults', true);
$('#' + elemId).select2('val', selected);
App.DataStore.removeItem('BuildSelect:' + elemId);
},
BuildCheckGroupHtml : function ( meta, options )
{
var items = {};
if (undefined != meta.data)
{
for (var i = 0; i < meta.data.length; i++)
{
items['i' + meta.data[i]] = true;
}
}
var sectiontMax = Math.ceil(options.length / 2);
var divClass = 'control-group column-right';
if (meta.split && 4 == meta.split)
{
var sectiontMax = Math.ceil(options.length / 4);
var divClass = 'span3';
}
var html = (meta.split && 4 == meta.split)
? '
'
: '
';
var r = 0;
for (var i = 0; i < options.length; i++)
{
if (r == sectiontMax)
{
html += '
';
html += '
';
r = 0;
}
var itemId = options[i].value;
var label = options[i].label;
var checked = items['i' + itemId]
? ' checked'
: '';
html += '';
r++;
}
html += '
';
if ((meta.split && 4 == meta.split))
{
html += '
';
}
return html;
},
BuildCheckGroup : function ( tid, meta, dataId, options )
{
var elem = $('#' + meta.id);
if (!elem)
{
return;
}
$('#' + meta.id).empty();
var html = App.ElementLibrary.BuildCheckGroupHtml(meta, options);
$('#' + tid + '_' + meta.id).html(html);
for (var i = 0; i < options.length; i++)
{
App.Util.updateCheckboxStyle($('#' + meta.itemName + options[i].value + 'Check'));
}
},
BuildAmountCheckGroupHtml : function ( meta, options )
{
var damages = {};
if (undefined != meta.data)
{
for (var i = 0; i < meta.data.length; i++)
{
damages['d' + meta.data[i].damage] = meta.data[i].amount;
}
}
var html = '';
var disabled = meta.disabled
? ' disabled'
: '';
for (var i = 0; i < options.length; i++)
{
var dmgId = options[i].value;
var label = options[i].label;
var amount = damages['d' + dmgId]
? damages['d' + dmgId]
: '0.00';
var checked = '0.00' == amount
? ''
: ' checked';
var disable = '0.00' == amount || meta.disabled
? ' disabled'
: '';
html += '
';
html += '';
html += '
';
html += '';
html += '
';
html += '
';
}
return html;
},
BuildAmountCheckGroup : function ( tid, meta, dataId, options )
{
var elem = $('#' + meta.id);
if (!elem)
{
return;
}
$('#' + meta.id).empty();
var html = App.ElementLibrary.BuildAmountCheckGroupHtml(meta, options);
$('#' + tid + '_' + meta.id).html(html);
for (var i = 0; i < options.length; i++)
{
var elem = $('#damage' + options[i].value + 'Check');
App.Util.updateCheckboxStyle(elem);
elem.change(function () {
var checked = $(this).prop('checked');
var amntElem = $('#' + $(this).attr('data-target'));
amntElem.val('0.00');
amntElem.prop('disabled', !checked);
amntElem.trigger('change');
});
}
$('.rand-input').change(function () {
var total = 0.00;
$.each($.find('.damage-input'), function(i, input) {
total += parseFloat($(input).val());
});
$('#' + tid + '_damageTotal').html('R ' + total);
});
var total = 0.00;
$.each($.find('.damage-input'), function(i, input) {
total += parseFloat($(input).val());
});
$('#' + tid + '_damageTotal').html('R ' + total);
App.DataStore.removeItem('BuildAmountCheck:' + meta.id);
},
Field : {
html : function ( meta, value )
{
if (null == meta)
{
return ' ';
}
var disabled = undefined != meta.disabled && meta.disabled
? ' disabled'
: '';
switch(meta.type)
{
case 'input':
var max = meta.maxlength
? ' maxlength="' + meta.maxlength + '"'
: '';
var placeholder = meta.placeholder
? meta.placeholder
: '';
if ('rand-input' == meta.style)
{
placeholder = '0.00';
}
var html = '';
html += '
';
html += '';
html += '
';
return html;
break;
case 'date':
var attr = meta.attrib
? meta.attrib
: '';
var html = '';
html += '
';
html += '';
html += '
';
return html;
break;
case 'mobile':
var html = '';
html += '
';
html += '+264';
html += '';
html += '
';
return html;
break;
case 'checkbox':
var html = '';
return html;
break;
case 'checkGroup':
var options = App.DataStore.dataStore[meta.dataStoreId]
? App.DataStore.dataStore[meta.dataStoreId]
: {};
var html = App.ElementLibrary.BuildCheckGroupHtml(meta, options);
return html;
break;
case 'damageDetails':
var options = App.DataStore.dataStore[meta.dataStoreId]
? App.DataStore.dataStore[meta.dataStoreId]
: {};
var html = App.ElementLibrary.BuildAmountCheckGroupHtml(meta, options);
return html;
break;
case 'amountCheck':
var html = '';
html += '
';
html += '';
html += '
';
return html;
break;
case 'amount':
var html = '';
html += '
';
html += '';
html += '
';
return html;
break;
case 'amountAuction':
var html = '';
html += '
';
html += '';
html += '
';
return html;
break;
case 'select2': //select2
if (meta.dataStoreId)
{
if (meta.dataList)
{
App.DataStore.setData(meta.dataStoreId, meta.dataList);
}
else if (meta.dataQuery)
{
App.dataStoreId.loadSelectListData(
meta.dataStoreId,
meta.dataQuery.isStatic,
meta.dataQuery.workspace,
meta.dataQuery.task,
meta.dataQuery.jobId,
meta.dataQuery.data,
meta.dataQuery.options,
meta.dataQuery.callback
);
}
}
if (!meta.options)
{
meta.options = [];
}
if (!meta.value)
{
meta.value = !meta.multiple
? ''
: [];
}
var eid = meta.id;
var attrib = '';
var label = '';
var labelStyle = '';
var inputStyle = '';
var inputWrapperStyle = '';
var labelSpan = '';
var inputSpan = '';
if (meta.multiple)
{
attrib += ' multiple';
}
attrib += meta.title
? ' data-placeholder="' + meta.title + '"'
: ((meta.title && !meta.selectEmpty)
? ' data-placeholder="' + meta.title + '"'
: '');
var options = '';
if (meta.selectEmpty)
{
options += '';
}
for (var i = 0; i < meta.options.length; i++)
{
options += '';
}
if (meta.title)
{
// the check here
if (undefined != meta.options.query)
{
var html = ''
+ '
'
+ '
'
+ '
'
+ '
';
}
else
{
var html = ''
+ '
'
+ ''
+ '
';
}
}
else
{
if (undefined != meta.options.query)
{
var html = '
'
+ '
'
+ '
'
+ '
';
}
else
{
var html = '
'
+ ''
+ '
';
}
}
return html;
break;
case 'select':
if (!meta.options)
{
meta.options = [];
}
if (!meta.value)
{
meta.value = !meta.multiple
? ''
: [];
}
var multi = meta.multiple
? ' multiple title="' + meta.title + '"'
: ' title="' + meta.title + '"';
var selectMe = '';
var html = '';
if (meta.title)
{
html += '';
}
html += '';
return html;
break;
case 'textarea-small':
var html = '';
html += '';
return html;
break;
case 'htmltext':
//var html = ' ';
//html += '';
var html = '';
html += '
';
html += ' ';
html += ' ';
html += ' ';
html += ' ';
html += '
';
html += '
';
html += '
';
html += '';
html += '
';
return html;
break;
case 'textarea-styled':
var style = meta.areaStyle
? meta.areaStyle
: 'textbox';
var html = '
' + meta.title + ':
';
html += '';
return html;
break;
case 'image':
var html = '';
html += '';
html += '';
html += '';
return html;
break;
case 'bidMainImage':
var html = '';
html += '';
return html;
break;
case 'bidimage':
var html = '';
html += '';
html += ''; // width="80%" height="80%"
html += '';
return html;
break;
case 'attachment':
var html = '';
html += '
';
html += '';
html += '
';
html += '';
return html;
break;
case 'document':
var html = '';
html += '
';
html += '';
html += '';
if (App.userData && 'test9@nirph.com' == App.userData.email)
{
html += '';
}
html += '
';
html += '';
return html;
break;
case 'document_button':
var html = '';
html += '
';
html += '';
html += '';
html += '';
if (App.userData && 'test9@nirph.com' == App.userData.email)
{
html += '';
}
html += '
';
html += '';
//html += '';
return html;
break;
case 'collector':
var html = '';
html += '