File: /www/wwwroot/oa.sanjiangapp.com/app/cash/trade/js/showimport.js
var $selectedItem;
var selectItem = function(item)
{
$selectedItem = $(item).first();
$('#ajaxModal').modal('hide');
};
$(document).ready(function()
{
var showSearchModal = function(e)
{
$('.selected').removeClass('selected');
if(e.hasClass('no-results'))
{
var key = e.parents('.chosen-container').find('.chosen-results > li.no-results > span').text();
e.parents('.chosen-container').prev('select').addClass('selected');
}
else
{
var key = e.next('.chosen-container').find('.chosen-results > li.no-results > span').text();
e.addClass('selected');
}
var relation = e.parents('tr').find('[name^=type]').val() == 'in' ? 'client' : 'provider';
var link = createLink('customer', 'ajaxSearchCustomer', 'key=' + key + '&relation=' + relation);
$.zui.modalTrigger.show({url: link, backdrop: 'static'});
};
$(document).on('change', 'select[name^=trader]', function()
{
if($(this).val() === 'showmore')
{
showSearchModal($(this));
}
});
$(document).on('click', '.chosen-container[id^=trader] .chosen-results > li.no-results', function(){showSearchModal($(this));});
$(document).on('hide.zui.modal', '#ajaxModal', function()
{
var key = '';
var $trader = $('.selected');
var type = $trader.parents('tr').find('[name*=type]').val();
if($selectedItem && $selectedItem.length)
{
key = $selectedItem.data('key');
$('select[name^=trader]').each(function()
{
if(!$(this).children('option[value="' + key + '"]').length)
{
$(this).prepend('<option value="' + key + '">' + $selectedItem.text() + '</option>');
}
$(this).trigger('chosen:updated');
});
}
$trader.val(key).trigger('chosen:updated');
$selectedItem = null;
});
removeDitto();//Remove 'ditto' in first row.
$('table.datatable').datatable({fixedHeader: true, fixedHeaderOffset: 44}).remove();
var defaults = {disableEmptySearch: true, maxListCount: 0, searchDelay: 500};
$('.datatable .select-picker').each(function()
{
var options = defaults;
if($(this).data('url')) options = $.extend({remote: $(this).data('url')}, defaults);
$(this).picker(options);
});
$('.datatable .form-date').fixedDate().datetimepicker(
{
language: config.clientLang,
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
minView: 2,
forceParse: 0,
format: 'yyyy-mm-dd'
});
$('.datatable .type').change(function()
{
var index = $(this).parents('tr').data('index');
var type = $(this).val();
var key = $(this).data('key');
var $tr = $('.datatable .datatable-rows .flexarea table tr[data-index=' + index + ']');
var $fakeDepositor = $('<input>').attr({id: 'fakeDepositor' + key, class: 'form-control', disabled: true});
var $fakeCategory = $('<input>').attr({id: 'fakeCategory' + key, class: 'form-control', disabled: true});
var $fakeTrader = $('<input>').attr({id: 'fakeTrader' + key, class: 'form-control', disabled: true});
var $fakeProduct = $('<input>').attr({id: 'fakeProduct' + key, class: 'form-control', disabled: true});
$tr.find('[id^=fakeDepositor], [id^=fakeCategory], [id^=fakeTrader], [id^=fakeProduct]').remove();
if(type == 'fee') type = $(this).next('input:hidden').val();
if(type == 'in' || type == 'out')
{
$tr.find('[name^=otherDepositor]').next('.picker').hide().after($fakeDepositor);
$tr.find('[name^=category]').attr('disabled', true).next('.picker').hide();
$tr.find('[name^=category].' + type).attr('disabled', false).next('.picker').show();
$tr.find('[name^=trader]').parent().hide().attr('disabled', true).find('*').attr('disabled', true);
$tr.find('[name^=trader]').parent('.' + type).show().attr('disabled', false).find('*').attr('disabled', false);
$tr.find('[name^=product]').next('.picker').show();
}
if(type == 'transferin' || type == 'transferout')
{
$tr.find('[name^=otherDepositor]').next('.picker').show();
$tr.find('[name^=category]').next('.picker').hide().parent().append($fakeCategory);
$tr.find('[name^=trader]').parent().hide().parents('td').append($fakeTrader);
$tr.find('[name^=product]').next('.picker').hide().after($fakeProduct);
}
})
$('.datatable .type').change();
$('.datatable [name*=createTrader]').each(function()
{
if($(this).prop('checked')) $(this).parents('.out').find('.picker').hide();
})
$('.datatable [name*=createCustomer]').each(function()
{
if($(this).prop('checked')) $(this).parents('.in').find('.picker').hide();
})
/* Toggle create trader items. */
$('.datatable [name*=createTrader]').change(function()
{
var $inputGroup = $(this).parents('.input-group');
if($(this).prop('checked'))
{
$inputGroup.find('select').hide();
$inputGroup.find('.picker').hide();
$inputGroup.find('input[type=text][id*=traderName]').show().focus();
$(this).parents('.input-group-addon').find('.icon-help-circle').hide();
}
else
{
$inputGroup.find('.picker').show();
$inputGroup.find('input[type=text][id*=traderName]').hide();
}
$inputGroup.fixInputGroup();
})
$('.datatable [name*=createCustomer]').change(function()
{
var $inputGroup = $(this).parents('.input-group');
if($(this).prop('checked'))
{
$inputGroup.find('select').hide();
$inputGroup.find('.picker').hide();
$inputGroup.find('input[type=text][id*=customerName]').show().focus();
$(this).parents('.input-group-addon').find('.icon-help-circle').hide();
}
else
{
$inputGroup.find('.picker').show();
$inputGroup.find('input[type=text][id*=customerName]').hide();
}
$inputGroup.fixInputGroup();
})
$('.datatable .toggleHide').click(function()
{
if($(this).hasClass('showed'))
{
$(this).attr('title', v.showExistTrade);
}
else
{
$(this).attr('title', v.hideExistTrade);
}
$(this).toggleClass('showed');
$(this).find('i').toggleClass('icon-plus icon-minus');
$('.datatable .existTrades' + $(this).data('key')).toggle();
$('.datatable .similarTrades' + $(this).data('key')).toggle();
});
$('.datatable .hasViewLink td:not(.hasCheckbox)').click(function()
{
var url = $(this).parents('tr').find('[name^=viewLink]').val();
if(url) window.open(url);
return false;
});
$('.input-group').fixInputGroup();
$('.picker-selection-text').bind('DOMNodeInserted',function()
{
$(this).closest('.picker-selections').attr('title', $(this).text());
});
$(window).scroll(function()
{
fixScrollWrapper();
}).resize(function()
{
fixScrollWrapper();
});
fixScrollWrapper();
});
function fixScrollWrapper()
{
var tbHeight = $(document).height();
var wHeight = $(window).height();
var wScrollTop = $(window).scrollTop();
var marginBtm = parseInt($('div.datatable').parents('.panel').css('margin-bottom'));
var paddingBtm = parseInt($('div.datatable').parent('.panel-body').css('padding-bottom'));
var fHeight = $('div.table-footer').outerHeight();
if(tbHeight - wScrollTop - wHeight - marginBtm - paddingBtm - fHeight > 0)
{
$('div.datatable > div.scroll-wrapper').css('bottom', tbHeight - wHeight - wScrollTop - marginBtm - paddingBtm - fHeight);
}
else
{
$('div.datatable > div.scroll-wrapper').css('bottom', 0);
}
}