/* initials and fixes */
jQuery(function(){
$j(window).resize(function(){
var window_width = $j(window).width();
var max_width = $j('body').width() * 0.5;
if($j('fieldset .col-xs-11').length) max_width = $j('fieldset .col-xs-11').width() - 109;
$j('.select2-container:not(.option_list)').css({ 'max-width' : max_width + 'px', 'width': '100%' });
fix_table_responsive_width();
var full_img_factor = 0.9; /* xs */
if(window_width >= 992) full_img_factor = 0.6; /* md, lg */
else if(window_width >= 768) full_img_factor = 0.9; /* sm */
$j('.detail_view .img-responsive').css({'max-width' : parseInt($j('.detail_view').width() * full_img_factor) + 'px'});
});
setTimeout(function(){ $j(window).resize(); }, 1000);
setTimeout(function(){ $j(window).resize(); }, 3000);
/* don't allow saving detail view while an ajax request is in progress */
jQuery(document).ajaxStart(function(){ jQuery('#update, #insert').prop('disabled', true); });
jQuery(document).ajaxStop(function(){ jQuery('#update, #insert').prop('disabled', false); });
/* don't allow responsive images to initially exceed the smaller of their actual dimensions, or .6 container width */
jQuery('.detail_view .img-responsive').each(function(){
var pic_real_width, pic_real_height;
var img = jQuery(this);
jQuery('') // Make in memory copy of image to avoid css issues
.attr('src', img.attr('src'))
.load(function() {
pic_real_width = this.width;
pic_real_height = this.height;
if(pic_real_width > $j('.detail_view').width() * .6) pic_real_width = $j('.detail_view').width() * .6;
img.css({ "max-width": pic_real_width });
});
});
jQuery('.table-responsive .img-responsive').each(function(){
var pic_real_width, pic_real_height;
var img = jQuery(this);
jQuery('
') // Make in memory copy of image to avoid css issues
.attr('src', img.attr('src'))
.load(function() {
pic_real_width = this.width;
pic_real_height = this.height;
if(pic_real_width > $j('.table-responsive').width() * .6) pic_real_width = $j('.table-responsive').width() * .6;
img.css({ "max-width": pic_real_width });
});
});
/* toggle TV action buttons based on selected records */
jQuery('.record_selector').click(function(){
var id = jQuery(this).val();
var checked = jQuery(this).prop('checked');
update_action_buttons();
});
/* select/deselect all records in TV */
jQuery('#select_all_records').click(function(){
jQuery('.record_selector').prop('checked', jQuery(this).prop('checked'));
update_action_buttons();
});
/* fix behavior of select2 in bootstrap modal. See: https://github.com/ivaynberg/select2/issues/1436 */
jQuery.fn.modal.Constructor.prototype.enforceFocus = function(){};
update_action_buttons();
});
/* show/hide TV action buttons based on whether records are selected or not */
function update_action_buttons(){
if(jQuery('.record_selector:checked').length){
jQuery('.selected_records').removeClass('hidden');
jQuery('#select_all_records')
.prop('checked', (jQuery('.record_selector:checked').length == jQuery('.record_selector').length));
}else{
jQuery('.selected_records').addClass('hidden');
}
}
/* fix table-responsive behavior on Chrome */
function fix_table_responsive_width(){
var resp_width = jQuery('div.table-responsive').width();
var table_width;
if(resp_width){
jQuery('div.table-responsive table').width('100%');
table_width = jQuery('div.table-responsive table').width();
resp_width = jQuery('div.table-responsive').width();
if(resp_width == table_width){
jQuery('div.table-responsive table').width(resp_width - 1);
}
}
}
function laboratori_validateData(){
$j('.has-error').removeClass('has-error');
if($j('#VleraTotale').val() == ''){ modal_window({ message: '