Some template cleanup

This commit is contained in:
2021-01-28 18:37:41 +00:00
parent 2351201e13
commit cc233e0223
7 changed files with 28 additions and 56 deletions

View File

@@ -11,14 +11,6 @@
<script src="{% static 'js/moment.js' %}"></script>
<script src="{% static 'js/main.min.js' %}"></script>
<script>
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
viewToUrl = {
'timeGridWeek':'week',
'timeGridDay':'day',
@@ -78,7 +70,7 @@
'url': $(this).attr('url')
}
if($(this).attr('is_rig')==true || $(this).attr('status') == "Cancelled"){
if($(this).attr('is_rig')===true || $(this).attr('status') === "Cancelled"){
thisEvent['color'] = colours[$(this).attr('status')];
}else{
thisEvent['color'] = colours['non-rig'];
@@ -95,31 +87,35 @@
$('#calendar-header').text(view.title);
// Enable/Disable "Today" button as required
let $today = $('#today-button');
if(moment().isBetween(view.currentStart, view.currentEnd)){
//Today is within the current view
$('#today-button').prop('disabled', true);
$today.prop('disabled', true);
}else{
$('#today-button').prop('disabled', false);
$today.prop('disabled', false);
}
// Set active view select button
let $month = $('#month-button');
let $week = $('#week-button');
let $day = $('#day-button');
switch(view.type){
case 'dayGridMonth':
$('#month-button').addClass('active');
$('#week-button').removeClass('active');
$('#day-button').removeClass('active');
$month.addClass('active');
$week.removeClass('active');
$day.removeClass('active');
break;
case 'timeGridWeek':
$('#month-button').removeClass('active');
$('#week-button').addClass('active');
$('#day-button').removeClass('active');
$month.removeClass('active');
$week.addClass('active');
$day.removeClass('active');
break;
case 'timeGridDay':
$('#month-button').removeClass('active');
$('#week-button').removeClass('active');
$('#day-button').addClass('active');
$month.removeClass('active');
$week.removeClass('active');
$day.addClass('active');
break;
}
history.replaceState(null,null,"{% url 'web_calendar' %}"+viewToUrl[view.type]+'/'+moment(view.currentStart).format('YYYY-MM-DD')+'/');

View File

@@ -30,21 +30,6 @@
{% include 'partials/datetime-fix.html' %}
<script>
function setTime23Hours() {
$('#{{ form.end_time.id_for_label }}').val('23:00');
}
function setTime02Hours() {
var id_start = "{{ form.start_date.id_for_label }}";
var id_end_date = "{{ form.end_date.id_for_label }}";
var id_end_time = "{{ form.end_time.id_for_label }}";
if ($('#'+id_start).val() == $('#'+id_end_date).val()) {
var end_date = new Date($('#'+id_end_date).val());
end_date.setDate(end_date.getDate() + 1);
$('#'+id_end_date).val(end_date.getISOString());
}
$('#'+id_end_time).val('02:00');
}
const matches = window.matchMedia("(prefers-reduced-motion: reduce)").matches || window.matchMedia("(update: slow)").matches;
$(document).ready(function () {
dur = matches ? 0 : 500;
@@ -53,14 +38,14 @@
$('.form-is_rig').slideUp(dur);
});
{% elif not object.pk and form.errors %}
if ($('#{{form.is_rig.auto_id}}').attr('checked') != 'checked') {
if ($('#{{form.is_rig.auto_id}}').attr('checked') !== 'checked') {
$('.form-is_rig').hide();
}
{% endif %}
{% if not object.pk %}
$('#is_rig-selector button').on('click', function () {
$('.form-non_rig').slideDown(dur);
if ($(this).data('is_rig') == 1) {
if ($(this).data('is_rig') === 1) {
$('#{{form.is_rig.auto_id}}').prop('checked', true);
if ($('.form-non_rig').is(':hidden')) {
$('.form-is_rig').show();

View File

@@ -27,12 +27,7 @@
<script>
function parseBool(str) {
if (str.toLowerCase() == 'true') {
return true
}
else {
return false
}
return str.toLowerCase() == 'true';
}
$('input[type=radio][name=big_power]').change(function() {
$('#{{ form.power_mic.id_for_label }}').prop('required', parseBool(this.value));

View File

@@ -14,11 +14,7 @@
$('#' + String(ID)).val(CSA);
}
function checkIfCableHidden() {
if (document.getElementById("id_is_cable").checked) {
document.getElementById("cable-table").hidden = false;
} else {
document.getElementById("cable-table").hidden = true;
}
document.getElementById("cable-table").hidden = !document.getElementById("id_is_cable").checked;
}
checkIfCableHidden();
</script>

View File

@@ -4,7 +4,7 @@
{% load widget_tweaks %}
{% block js %}
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script src="{% static 'js/jquery-ui.js' %}"></script>
<script src="{% static "js/interaction.js" %}"></script>
<script src="{% static "js/modal.js" %}"></script>
<script>
@@ -23,7 +23,7 @@
success: function(){
$link = $(this);
// Anti modal inception
if ($link.parents('#modal').length == 0) {
if ($link.parents('#modal').length === 0) {
modaltarget = $link.data('target');
modalobject = "";
$('#modal').load(url, function (e) {

View File

@@ -30,19 +30,19 @@
//Get query string value
var searchUrl=location.search;
if(key!="") {
if(key!=="") {
oldValue = getParameterByName(key);
removeVal=key+"="+oldValue;
if(searchUrl.indexOf('?'+removeVal+'&')!= "-1") {
if(searchUrl.indexOf('?'+removeVal+'&')!== "-1") {
urlValue=urlValue.replace('?'+removeVal+'&','?');
}
else if(searchUrl.indexOf('&'+removeVal+'&')!= "-1") {
else if(searchUrl.indexOf('&'+removeVal+'&')!== "-1") {
urlValue=urlValue.replace('&'+removeVal+'&','&');
}
else if(searchUrl.indexOf('?'+removeVal)!= "-1") {
else if(searchUrl.indexOf('?'+removeVal)!== "-1") {
urlValue=urlValue.replace('?'+removeVal,'');
}
else if(searchUrl.indexOf('&'+removeVal)!= "-1") {
else if(searchUrl.indexOf('&'+removeVal)!== "-1") {
urlValue=urlValue.replace('&'+removeVal,'');
}
}

View File

@@ -16,7 +16,7 @@
param = $(value).val();
val = $(value).prop('checked');
if(val != defaultVal){
if(val !== defaultVal){
url = url+param+"="+val+"&";
}
});