Changeset 46fd0c7 for src/main/resources/static/js
- Timestamp:
- 03/13/23 00:58:07 (21 months ago)
- Branches:
- master
- Children:
- 9050790
- Parents:
- 2b0a4db
- Location:
- src/main/resources/static/js
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/resources/static/js/register_business.js
r2b0a4db r46fd0c7 3 3 $.ajax({ 4 4 url: "http://localhost:8080/api/nomenclatures/businessTypes" 5 }).then(function (data) {5 }).then(function (data) { 6 6 enumerations = data; 7 7 var $el = $("#companyType"); 8 8 //$el.empty(); // remove old options 9 9 10 $.each(data, function (index, obj) {10 $.each(data, function (index, obj) { 11 11 $el.append("<option value=" + obj.value + ">" + obj.text + "</option>"); 12 12 }); 13 13 }); 14 14 15 $("#companyType").change(function () {15 $("#companyType").change(function () { 16 16 var selectedVal = $(this).find(':selected').val(); 17 alert(JSON.stringify(enumerations[selectedVal-1])); 18 var selectedObj = enumerations[selectedVal-1]; 17 var selectedObj = enumerations[selectedVal - 1]; 19 18 var $el = $("#predefined_services"); 20 19 $el.empty(); 21 20 $.each(selectedObj['serviceTypes'], function (index, obj) { 22 21 $el.append( 23 '<div class="form-check">\n' + 24 ' <input class="form-check-input" type="checkbox" value=\"' + obj.id + '\" id=\"'+ obj.id +'\">\n' + 25 ' <label class="form-check-label" for=\"' + obj.id + '\">\n' + 26 obj.name + 27 ' </label>\n' + 28 ' </div>') 22 '<div class=\"form-outline mb-4\">' + 23 ' <div class="row">' + 24 ' <div class="col-md-8">\n' + 25 ' <input class="form-check-input" type="checkbox" value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' + 26 ' <label class="form-check-label" for=\"' + obj.id + '\">\n' + 27 obj.name + 28 ' </label>\n' + 29 ' </div>' + 30 ' <div class=\"form-outline col-md-2 d-grid\">' + 31 ' <input type=\"text\" id=\"' + obj.id + obj.name.replace(/\s/g, "") + '\" class=\"form-control\" />' + 32 ' </div>' + 33 ' </div>' + 34 '</div>'); 29 35 }); 30 }) 36 $("#input_service").prop('disabled', false); 37 $("#add_service").prop('disabled', false); 38 }); 39 40 $("#add_service").click(function () { 41 var input_service = $("#input_service").val(); 42 // clear the input 43 $("#input_service").val(''); 44 45 /*$("#predefined_services").append( 46 '<div class="form-check">\n' + 47 ' <input class="form-check-input" type="checkbox" checked value=\"' + -1 + '\" id=\"'+ -1 +'\">\n' + 48 ' <label class="form-check-label" for=\"' + -1 + '\">\n' + 49 input_service + 50 ' </label>\n' + 51 ' </div>' 52 );*/ 53 54 $("#predefined_services").append( 55 '<div class="form-outline mb-4">' + 56 ' <div class="row">' + 57 ' <div class="col-md-8">\n' + 58 ' <input class="form-check-input" type="checkbox" checked value="' + -1 + '" id="' + -1 + '">\n' + 59 ' <label class="form-check-label" for="' + -1 + '">\n' + 60 input_service + 61 ' </label>\n' + 62 ' </div>' + 63 ' <div class="form-outline col-md-2 d-grid">' + 64 ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + '" class="form-control" />' + 65 ' </div>' + 66 ' </div>' + 67 '</div>'); 68 event.preventDefault(); 69 }); 70 71 $('#signup_business_button').click(function () { 72 let businessObj = {}; 73 let ownerObj = {}; 74 75 ownerObj['firstName'] = $('#firstName').val(); 76 ownerObj['lastName'] = $('#lastName').val(); 77 ownerObj['email'] = $('#email').val(); 78 ownerObj['username'] = $('#username').val(); 79 ownerObj['password'] = $('#password').val(); 80 businessObj['owner'] = ownerObj; 81 82 businessObj['companyName'] = $('#companyName').val(); 83 84 businessObj['businessType'] = {'value': $('#companyType').val()}; 85 86 servicesObj = []; 87 88 $.each($('#predefined_services input:checked').siblings(), function(index, label) { 89 90 let service = {}; 91 var id = $(label).prop('for'); 92 var text = $(label).text(); 93 var time = $($($(label).parent()).siblings()[0]).children()[0].value; 94 95 var serviceType = {} 96 if(parseInt(id) != -1) { 97 serviceType['id'] = id; 98 } 99 serviceType['name'] = text.trim(); 100 service['serviceType'] = serviceType; 101 service['duration'] = time; 102 servicesObj.push(service); 103 }); 104 businessObj['services'] = servicesObj; 105 console.log(JSON.stringify(businessObj)); 106 $.ajax({ 107 url: "http://localhost:8080/api/business", 108 type:"POST", 109 data: JSON.stringify(businessObj), 110 contentType:"application/json; charset=utf-8", 111 dataType: 'text', 112 success: function(succ){ 113 alert( "Well done! You have finished the registration process. " + 114 "Please check periodically to see if the company has been approved." ); 115 window.location.href = "/homepage"; 116 }, 117 error: function(err) { 118 alert(err); 119 } 120 }); 121 event.preventDefault(); 122 }); 31 123 });
Note:
See TracChangeset
for help on using the changeset viewer.