$("body").on("submit","form",function(e) { var errors = false; $('input[type="date"]').each(function() { var date = new Date($(this).val()); if(date.getFullYear() > 2060) { $(this).addClass("is-invalid"); errors = true; } if(date.getFullYear() < 2003) { $(this).addClass("is-invalid"); } }); if(errors) { e.preventDefault(); return false; } return true; }); $(document).bind('ready ajaxComplete', function() { $(".form-ajax").unbind(); $("div.form-material.floating input").unbind(); $(".form-ajax").submit(function(e) { var redirect = $(this).data("redirect") == 1 ? true : false; var redirecturl = $(this).data("redirect-url"); $.ajax({ type: 'POST', url: 'https://swms.sevenways.co.uk/index.php', data: $(this).serialize(), success: function(result) { if(redirect) window.location = redirecturl; else location.reload(); }, dataType: 'html' }); e.preventDefault(); }); $(".btn-refresh-notifications").on("click",function() { refreshNotifications(false); }); $(".btn-show-all-notifications").on("click",function() { refreshNotifications(true); }); $(".btn-dismiss-notification").on("click",function() { dismissNotification($(this).data("notificationid")); }); $(".btn-note-update").on("click",function() { $("#note_resolution_id_field").val($(this).data("noteid")); }); $("div.form-material.floating input").change(function (event) { if(this.value != "") $(this).parent().addClass("open"); else $(this).parent().removeClass("open"); }); $(":password").on("keyup",function() { if($("#password_status").length) { var password = $("#user_password").val(); var confirm_password = $("#confirm_user_password").val(); if(password == confirm_password) { $("#password_status").html("Passwords Match"); $("#password_status").addClass("alert-success"); $("#password_status").removeClass("alert-danger"); } else { $("#password_status").html("Passwords Do Not Match"); $("#password_status").addClass("alert-danger"); $("#password_status").removeClass("alert-success"); } } }); }); $("#customer_site_service_log_requested_by_party").on("change",function() { var party = $(this).val(); if(party != "") { var url; if(party == "customer") { var siteId = $("#site-id").data("siteid"); url = 'https://swms.sevenways.co.uk/site_contacts_json/' + siteId + '/'; } else if(party == "supplier") { var supplierId = $("#supplier-id").data("supplierid"); url = 'https://swms.sevenways.co.uk/supplier_contacts_json/' + supplierId + '/'; } else if(party == "Seven Ways") { var siteId = 576; url = 'https://swms.sevenways.co.uk/site_contacts_json/' + siteId + '/'; } $.getJSON(url,function (data) { console.log(data); $("#customer_site_service_log_requested_by").removeAttr("disabled"); $("#customer_site_service_log_requested_by").html(""); $("#customer_site_service_log_requested_by").append(""); $.each(data, function(key,contact) { $("#customer_site_service_log_requested_by").append( "" ); }); }); } }); $("#customer_site_service_log_type").on("change",function() { var terminationFields = [ "customer_site_service_log_termination_status", "customer_site_service_log_request_media", "customer_site_service_log_contract_end_date", "customer_site_service_log_last_lift_date", "customer_site_service_log_removal_date", "customer_site_service_log_accounts_notified_no", "customer_site_service_log_accounts_notified_yes", "customer_site_service_log_termination_reason" ]; var extraLiftFields = [ "customer_site_service_log_po_number", ]; $("#termination-form-fields").hide(); terminationFields.forEach(function(val) { $("#" + val).prop("disabled",true); }); $("#extra-lift-form-fields").hide(); extraLiftFields.forEach(function(val) { $("#" + val).prop("disabled",true); }); switch($(this).val()) { case "Termination": $("#termination-form-fields").show(); terminationFields.forEach(function(val) { $("#" + val).removeAttr("disabled"); }); break; case "Extra Lift": $("#extra-lift-form-fields").show(); extraLiftFields.forEach(function(val) { $("#" + val).removeAttr("disabled"); }); break; } }); if($("#customer_site_service_log_type").length) { $("#customer_site_service_log_type").trigger("change"); } $(document).bind('ready', function() { $("#supplier_link_product").on("submit",function(e) { var form = $(this); var table = $("#supplier_link_product_table").dataTable(); table.$('input[type="checkbox"]').each(function() { if(!$.contains(document,this)) { if(this.checked) $(form).append($("").attr("type","hidden").attr("name",this.name).val(this.value)); } }); }); $(".show-contact").on("click",function() { if($(this).data("contactid") != undefined) { var contactid = $(this).data("contactid"); var url = "https://swms.sevenways.co.uk/get_contact_modal/" + contactid + "/"; $.ajax({ "url" : url }).done(function(result) { $("#contact-details-modal").html(result); $("#btn-archive-contact").data("id",contactid); $("#show-contact").modal(); }); } }); $(".set-doc-contact").on("click",function() { $("#btnAcceptDutyOfCareContactChange").attr("href","https://swms.sevenways.co.uk/set_customer_site_duty_of_care_contact/" + $(this).data("siteid") + "/" + $(this).data("contactid") + "/"); $("#set-site-dutyofcare-contact-modal").modal(); }); $("#close-dutyofcare-contact-modal").on("click",function() { $("#set-site-dutyofcare-contact-modal").modal('hide'); }); Dropzone.options.attachmentDropzone = { success: function(file, response) { this.removeFile(file); location.reload(true); } }; // disable mousewheel on a input number field when in focus // (to prevent Cromium browsers change the value when scrolling) $('form').on('focus', 'input[type=number]', function (e) { $(this).on('mousewheel.disableScroll', function (e) { e.preventDefault() }) }) $('form').on('blur', 'input[type=number]', function (e) { $(this).off('mousewheel.disableScroll') }) $(".report-date-selector").change(function() { setReportDate(); }); setReportDate(); $(".address-selector").on("change",function(e) { var url = "https://swms.sevenways.co.uk/get_address_json/" + $(this).val() + "/"; $.ajax({ "url" : url }).done(function(result) { var address = ""; if(result.address_1 != "") address += result.address_1 + "\n"; if(result.address_2 != "") address += result.address_2 + "\n"; if(result.address_town != "") address += result.address_town + "\n"; if(result.address_county != "") address += result.address_county + "\n"; if(result.address_postcode != "") address += result.address_postcode + "\n"; console.log(address); $("#address_view").html(address); }); console.log($(this).val()); }); if($(".address-selector").val() != "Select Address") $(".address-selector").change(); $("#customer_site_service_frequency").on("change",function(e) { clearDaySelections(); $("#customer_site_service_day_monthly_dropdown").hide(); $("#customer_site_service_day_checkbox").hide(); $("#customer_site_service_day").parent().parent().parent().parent().show(); switch($(this).val()) { case "Monthly": case "Quarterly": case "Bi-Annually": case "Annually": case "On-Request": $("#customer_site_service_day").val("n/a"); $("#customer_site_service_day").parent().parent().parent().parent().hide(); break; case "Weekly": case "Fortnightly": $("#customer_site_service_day_checkbox").show(); $("#customer_site_service_day").parent().parent().parent().parent().hide(); break; /*case "Monthly": case "Quarterly": case "Bi-Annually": case "Annually": $("#customer_site_service_day_monthly_dropdown").show(); $("#customer_site_service_day").parent().parent().parent().parent().hide(); break;*/ default: $("#customer_site_service_day").val(""); break; } }); $("#customer_site_service_day_checkbox input[type=checkbox]").on("change",function(e) { updateDaysFromCheckboxes(); }); $("#customer_site_service_day_monthly_dropdown_select").on("change",function(e) { $("#customer_site_service_day").val($("#customer_site_service_day_monthly_dropdown_select").val()); }); $("tbody").on("click",".show-change-details",function(e) { var id = $(this).data("id"); $.get('https://swms.sevenways.co.uk/view_change_modal/' + id + '/', function( result ) { $("#change-detail-body").html(result); }); $("#change-approve-button").data("id",id); $("#change-cancel-button").data("id",id); $("#change-view-button").attr("href","https://swms.sevenways.co.uk/view_change/" + id + "/"); if($(this).data("status") != "Open") { $("#change-approve-button").attr("disabled",true); $("#change-cancel-button").attr("disabled",true); } else { $("#change-approve-button").attr("disabled",false); $("#change-cancel-button").attr("disabled",false); } }); $("#change-approve-button").on("click",function(e) { window.location = "https://swms.sevenways.co.uk/approve_change/" + $(this).data("id") + "/"; }); $("#change-cancel-button").on("click",function(e) { window.location = "https://swms.sevenways.co.uk/cancel_change/" + $(this).data("id") + "/"; }); $(".row-link tbody").on("click","tr",function(e) { if($(this).data("href") != undefined) window.location = $(this).data("href"); }); $(".userlog tbody").on("click","tr",function(e) { $("#request_data").html($(this).data('request')); }); $(".confirm-archive-button").on("click",function(e) { let type = $(this).data("type"); let id = $(this).data("id"); const url = "https://swms.sevenways.co.uk/archive_" + type + "/" + id + "/" if(confirm("Are you sure you wish to archive this contact?")) { $.ajax({ url: url, success: function(result) { location.reload(); } }); } }); $("#confirm-archive-button").on("click",function(e) { /**/ }); $("tbody").on("click",".confirm-delete",function(e) { var type = $(this).data("type"); var id = $(this).data("id"); var label = $(this).data("label"); var description = $(this).data("description"); $("#confirm-delete-message").html("Are you sure you would like to delete this " + label + "?

ID: " + id + "
Description: " + description); $("#confirm-delete-button").attr("href","https://swms.sevenways.co.uk/delete_" + type + "/" + id + "/"); return; }); $("#customer_supplier_id").on("change",function(e) { var supplierId = $(this).val(); var serviceType = $("#customer_site_service_type").val(); getSupplierContacts(supplierId); populateNewSupplierContact("Supplier","supplier",supplierId); if(serviceType == "Please select") return; getProducts(supplierId,serviceType); getDisposalSites(supplierId); }); $("#customer_site_service_type").on("change",function(e) { var supplierId = $("#customer_supplier_id").val(); var serviceType = $("#customer_site_service_type").val(); if(serviceType == "") return; if(supplierId != "Please select") getProducts(supplierId,serviceType); }); }); function populateNewSupplierContact(typeDescription,contactType,contactLinkId) { var data = { "typeDescription" : typeDescription, "contactType" : contactType, "contactLinkId" : contactLinkId, "action" : "new_contact_modal", "url" : window.location.href }; var pageurl = 'https://swms.sevenways.co.uk/'; $.ajax({ "url" : pageurl, "type": "POST", "data" : data, }).done(function(result) { //console.log(result); $("#new_supplier_contact div.block-content").html(result); }); } function getSupplierContacts(supplierId) { var data = null; var pageurl = 'https://swms.sevenways.co.uk/supplier_contacts_json/' + supplierId + '/'; $.getJSON(pageurl,function (data) { $("#customer_site_service_supplier_contact").html(""); $("#customer_site_service_supplier_contact").append(""); $.each(data, function(key,contact) { //console.log(contact) $("#customer_site_service_supplier_contact").append( "" ); }); }); } function getProducts(supplierId,serviceType) { var data = null; if($("#customer_site_service_product_id").length) { $("#customer_site_service_product_id").html(""); $("#customer_site_service_product_id").append(""); var pageurl = 'https://swms.sevenways.co.uk/supplier_products_json/' + supplierId + '/'; $.get('https://swms.sevenways.co.uk/new_supplier_product_modal/' + supplierId + '/', function( result ) { $("#new_supplier_product_modal").html(result); }); $.getJSON(pageurl,function (data) { //console.log(data); $.each(data, function(key,product) { if(product.supplier_product_type == serviceType) $("#customer_site_service_product_id").append( "" ); }); }); } } function getDisposalSites(supplierId) { var data = null; if($("#customer_site_service_disposal_site_id").length) { $("#customer_site_service_disposal_site_id").html(""); $("#customer_site_service_disposal_site_id").append(""); var pageurl = 'https://swms.sevenways.co.uk/supplier_disposal_sites_json/' + supplierId + '/'; $.getJSON(pageurl,function (data) { //console.log(data); $.each(data, function(key,disposalSite) { console.log(disposalSite); $("#customer_site_service_disposal_site_id").append( "" ); }); }); } } function setReportDate() { $(".date-filtered-report").each(function() { var startDate = $("#report_start_date").val(); var endDate = $("#report_end_date").val();; $(this).attr("href",$(this).data("href") + "&startDate=" + startDate + "&endDate=" + endDate); }); } function confirmDelete(element) { } function clearDaySelections() { var days = ["monday","tuesday","wednesday","thursday","friday","saturday","sunday"]; var value = ""; $(days).each(function() { $("#customer_site_service_day_checkbox_" + this).prop("checked",false); }); $("#customer_site_service_day_monthly_dropdown_select").val(""); } function updateDaysFromCheckboxes() { var days = ["monday","tuesday","wednesday","thursday","friday","saturday","sunday"]; var value = ""; $(days).each(function() { if($("#customer_site_service_day_checkbox_" + this).prop("checked")) value += $("#customer_site_service_day_checkbox_" + this).val() + " "; }) $("#customer_site_service_day").val(value.trim()); } function toggleNavigationSession() { $.get("https://swms.sevenways.co.uk/toggle_navigation/"); } function customerSiteServiceLogTypeChanged() { } function refreshNotifications(showAll) { let url = 'https://swms.sevenways.co.uk/notifications/'; if(showAll) url += "showAll/"; $.get(url, function( result ) { $("#notification-modal-body").html(result); }); } function dismissNotification(notificationId) { let url = 'https://swms.sevenways.co.uk/dismiss_notification/' + notificationId + '/'; $.get(url,function(result) { refreshNotifications(false); }); }