/* * Author: Chenghao (Peter) Pan, Kish * * This file contains all custom js functions intended for facility staff registration * */ function changeFacilityStaffType(dropdown){ var staff_type = $(dropdown).find("option:selected").val(); $("input#facility_staff_type").val(staff_type); switch(staff_type){ case 'RN': return window.location.href = '/register/RN'; break; case 'AO': return window.location.href = '/register/AO'; break; case 'other': return window.location.href = '/register/other'; break; default: return window.location.href = '/register'; break; } } //Verify the if the login crendential is unique function verifyRegistration(input, option){ var input_field = $(input); input_field.closest('.col-md-4').removeClass('has-error'); input_field.closest('.col-md-4').removeClass('has-success'); input_field.siblings('.fa-warning, .fa-check').addClass('hidden'); var value = $(input).val(); if( $.trim(value) != '' ){ $.ajax({url: "/register/verifyRegistration", data: { option : option, value : value }, success: function(result){ if(result == 1){ // taken input_field.siblings('.fa-warning').removeClass('hidden'); input_field.closest('.col-md-4').addClass('has-error'); }else if( result == 0 ){ // available input_field.siblings('.fa-check').removeClass('hidden'); input_field.closest('.col-md-4').addClass('has-success');; } } }); } } // function to display modal and auto fill selection function facilityName(dropdown){ var facility = $(dropdown).find("option:selected").val(); // check if value is numeric then prefill address if($.isNumeric(facility)){ // SELECTED // Fetch address information through ajax $.ajax({url: "/facility/ajax/address_details", data: {"facility_id": facility }, success: function(result){ // Update address details // STREET ADDRESS $('#facility_street').val(result.street_address); // SUBURB $('#facility_suburb').val(result.suburb); //STATE $('#state').select2('val', result.state); // POSTCODE $('#facility_postcode').val(result.postcode); // PHONE NUMBER $('#phone_number').val(result.phone); // Fax $('#fax_number').val(result.fax); // DISABLE ALL FIELDS TO PREVENT ERROR / CHANGE //$("#facility_street, #facility_suburb, #state, #facility_postcode, #phone_number, #fax_number").attr('disabled','disabled'); }}); } // Display modal and advise about new facility being created else{ // NEW // ENABLE FIELDS & CLEAR FIELDS $("#facility_street, #facility_suburb, #facility_postcode, #phone_number, #fax_number").val(''); $("#state").select2('val', 'nsw'); //$("#facility_street, #facility_suburb, #state, #facility_postcode, #phone_number, #fax_number").removeAttr('disabled'); } } // Select 2 element, detect tab key pressed $(document).on('select2:close', 'select.select2', function(evt) { var context = $(evt.target); $(document).on('keydown.select2', function(e) { if (e.which === 9) { // tab var highlighted = context .data('select2') .$dropdown .find('.select2-results__option--highlighted'); if (highlighted) { var id = highlighted.data('data').id; context.val(id).trigger('change'); } } }); // unbind the event again to avoid binding multiple times setTimeout(function() { $(document).off('keydown.select2'); }, 1); }); var ComponentsSelect2 = function() { var registrationForm = function() { // Set the "bootstrap" theme as the default theme for all Select2 // widgets. // // @see https://github.com/select2/select2/issues/2927 $.fn.select2.defaults.set("theme", "bootstrap"); // Placeholders var placeholder_1 = 'Please select'; // application Placeholders $("#facility_name").select2({ placeholder: "Please select or enter", width: null, tags: true }); $("#facility_staff_type").select2({ placeholder: placeholder_1, width: null, minimumResultsForSearch: -1 }); $("#state").select2({ placeholder: placeholder_1, width: null, minimumResultsForSearch: -1 }); } return { //main function to initiate the module init: function() { registrationForm(); } }; }(); if (App.isAngularJsApp() === false) { jQuery(document).ready(function() { ComponentsSelect2.init(); }); }