-
David Hoese authored
Closes !2
David Hoese authoredCloses !2
quicklooks-interactive.js 3.35 KiB
/* return the value of the input, or its placeholder if it has no value
*/
var val_or_place = function(jquery_str){
return ($(jquery_str).val() != '')? $(jquery_str).val() : $(jquery_str).attr('placeholder');
};
var update_quicklooks_no_forms = function(){
//parse the requested date range from the Timeframe form
var ndays;
var start_date;
var end_date;
if($("#last_x_days").is(":checked")){
ndays = Number(val_or_place('#x_days'));
if((ndays < 32) && (ndays > 0)){
start_date= moment.utc();
end_date = ndays;
}else{
return;//return if too many days are being requested
}
}else if($("#date_range").is(":checked")){
var date1 = moment.utc(val_or_place('#Start-date-picker'));
var date2 = moment.utc(val_or_place('#End-date-picker'));
ndays = dayRange(date1,date2).length;
if((ndays < 32) && (ndays > 0)){
start_date = date1;
end_date = date2;
}else{
return;//return if too many days are being requested
}
}
$(".imageStripsContainer").css('width',120*ndays);
updateQuickLooks(start_date,end_date);
};
var table_scroll_func = _.throttle(function(){
$('.table-holder').not($(this)).scrollLeft($(this).scrollLeft());
},30);
$(document).ready(function(){
$.ajax({
url: METOBS_API_URL + "/api/archive/info",
type: "GET"
}).then(function(data){
//create the form options from the recieved json
QuicklooksArchive.setStructure(data);
update_quicklooks_no_forms();
});
//Set up the date range inputs as datepicker objects
$('#Start-date-picker').datepicker({
changeMonth: true,
changeYear: true,
});
$('#Start-date-picker').datepicker('option','dateFormat','yy-mm-dd');
$('#End-date-picker').datepicker({
changeMonth: true,
changeYear: true,
});
$('#End-date-picker').datepicker('option','dateFormat','yy-mm-dd');
//bind the enabling/disabling of forms to radio buttons
$('[type=text]').prop("disabled",true);
$("#last_x_days").click(function(){
$("#x_days").prop("disabled",false);
$("#Start-date-picker").prop("disabled",true);
$("#Start-date-picker").val("");
$("#End-date-picker").prop("disabled",true);
$("#End-date-picker").val("");
update_quicklooks_no_forms();
});
$("#date_range").click(function(){
$("#x_days").prop("disabled",true);
$("#x_days").val("");
$("#Start-date-picker").prop("disabled",false);
$("#End-date-picker").prop("disabled",false);
update_quicklooks_no_forms();
});
//add placeholder values for the order forms
$('#x_days').attr('placeholder','7');
$('#Start-date-picker').attr('placeholder',moment.utc().subtract(6,'days').format('YYYY-MM-DD'));
$('#End-date-picker').attr('placeholder',moment.utc().format('YYYY-MM-DD'));
$('#x_days').change(update_quicklooks_no_forms);
$('#End-date-picker').change(update_quicklooks_no_forms);
$('#Start-date-picker').change(update_quicklooks_no_forms);
$('.select-all').click(select_all_click_func);
$('.table-holder').scroll(table_scroll_func);
if($("#date_range").is(":checked")) $("#date_range").trigger('click');
else if($("#last_x_days").is(":checked")) $("#last_x_days").trigger('click');
});