2017-11-23 18:09:36 -05:00
|
|
|
(function(){
|
2018-04-13 17:41:05 -04:00
|
|
|
$("#time_input").flatpickr({enableTime:true, minDate: "today",time_24hr:true, onChange: function(date, dateStr, instance) {
|
|
|
|
$("#time_input_js").val(date[0].toISOString());
|
2017-11-23 18:09:36 -05:00
|
|
|
}});
|
2018-04-13 17:41:05 -04:00
|
|
|
$("#end_time").flatpickr({enableTime:true, minDate: "today",time_24hr:true, onChange: function(date, dateStr, instance) {
|
|
|
|
$("#end_time_js").val(date[0].toISOString()); // iso date str
|
2017-11-23 18:09:36 -05:00
|
|
|
}});
|
|
|
|
|
|
|
|
|
|
|
|
var classes = ["panel panel-danger", "panel panel-warning", "panel panel-primary", "panel panel-success"];
|
|
|
|
var icons = ["fa fa-times", "fa fa-exclamation", "fa fa-info", "fa fa-check"];
|
|
|
|
|
|
|
|
$("body").on("change","#new-incident select", function(){
|
2018-04-20 11:39:34 -04:00
|
|
|
var val = parseInt($(this).val()); //this should make exploitation harder
|
2017-11-23 18:09:36 -05:00
|
|
|
|
|
|
|
$("#new-incident .panel.new .panel-heading i").get(0).className = icons[val];
|
|
|
|
$("#new-incident .panel.new").get(0).className = classes[val] + " new";
|
2018-08-23 14:54:35 -04:00
|
|
|
$("#time_input").val("");
|
|
|
|
$("#end_time").val("");
|
2017-11-23 18:09:36 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#new-incident select").trigger("change");
|
|
|
|
|
|
|
|
$("body").on("submit","#new-incident",function(){
|
2018-08-23 14:54:35 -04:00
|
|
|
var time = Date.parse($("#time_input").val());
|
|
|
|
var end_time = Date.parse($("#end_time").val());
|
2018-04-20 11:39:34 -04:00
|
|
|
var type = $("#type").val() || 0;
|
2017-11-23 18:09:36 -05:00
|
|
|
|
2018-08-23 14:54:35 -04:00
|
|
|
if (parseInt(type) === 2 &&(isNaN(time) || isNaN(end_time)))
|
2017-11-23 18:09:36 -05:00
|
|
|
{
|
2017-12-13 05:58:33 -05:00
|
|
|
if (isNaN(end_time))
|
|
|
|
{
|
2018-08-23 14:54:35 -04:00
|
|
|
$("#time_input").addClass("error");
|
2017-12-13 05:58:33 -05:00
|
|
|
$.growl.error({ message: "Start time is invalid!" });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isNaN(end_time))
|
|
|
|
{
|
2018-08-23 14:54:35 -04:00
|
|
|
$("#end_time").addClass("error");
|
2017-12-13 05:58:33 -05:00
|
|
|
$.growl.error({ message: "End time is invalid!" });
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-23 14:54:35 -04:00
|
|
|
else if (parseInt(type) === 2 && time >= end_time)
|
2017-12-13 05:58:33 -05:00
|
|
|
{
|
|
|
|
$.growl.error({ message: "End time is either the same or earlier than start time!" });
|
2018-08-23 14:54:35 -04:00
|
|
|
$("#time").addClass("error");
|
|
|
|
$("#end_time").addClass("error");
|
2017-11-23 18:09:36 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-23 14:54:35 -04:00
|
|
|
if($("#status-container :checkbox:checked").length === 0)
|
2017-11-23 18:09:36 -05:00
|
|
|
{
|
2017-12-13 05:58:33 -05:00
|
|
|
$.growl.error({ message: "Please check at least one service!" });
|
2018-08-23 14:54:35 -04:00
|
|
|
$("#status-container").addClass("error");
|
2017-11-23 18:09:36 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|
2017-12-12 07:56:03 -05:00
|
|
|
|