[a436340] | 1 | $(document).ready(function() {
|
---|
| 2 | var enumerations = {};
|
---|
| 3 | $.ajax({
|
---|
[53765dd] | 4 | url: "http://localhost:8080/api/nomenclature/businessTypes"
|
---|
[46fd0c7] | 5 | }).then(function (data) {
|
---|
[a436340] | 6 | enumerations = data;
|
---|
| 7 | var $el = $("#companyType");
|
---|
| 8 |
|
---|
[46fd0c7] | 9 | $.each(data, function (index, obj) {
|
---|
[2b0a4db] | 10 | $el.append("<option value=" + obj.value + ">" + obj.text + "</option>");
|
---|
[a436340] | 11 | });
|
---|
| 12 | });
|
---|
| 13 |
|
---|
[46fd0c7] | 14 | $("#companyType").change(function () {
|
---|
[a436340] | 15 | var selectedVal = $(this).find(':selected').val();
|
---|
[46fd0c7] | 16 | var selectedObj = enumerations[selectedVal - 1];
|
---|
[2b0a4db] | 17 | var $el = $("#predefined_services");
|
---|
| 18 | $el.empty();
|
---|
[f29cd58] | 19 | console.log(selectedObj['serviceTypes']);
|
---|
[2b0a4db] | 20 | $.each(selectedObj['serviceTypes'], function (index, obj) {
|
---|
| 21 | $el.append(
|
---|
[f29cd58] | 22 | '<div class="form-outline mb-4">' +
|
---|
[46fd0c7] | 23 | ' <div class="row">' +
|
---|
[8bcd64c] | 24 | ' <div class="col-md-6">\n' +
|
---|
[f29cd58] | 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' +
|
---|
[46fd0c7] | 27 | obj.name +
|
---|
| 28 | ' </label>\n' +
|
---|
| 29 | ' </div>' +
|
---|
[f29cd58] | 30 | ' <div class="form-outline col-md-2 d-grid">' +
|
---|
| 31 | ' <input type="text" id="' + obj.id + obj.name.replace(/\s/g, "") + "duration" + '" class="form-control" placeholder="time" />' +
|
---|
[8bcd64c] | 32 | ' </div>' +
|
---|
[f29cd58] | 33 | ' <div class="form-outline col-md-2 d-grid">' +
|
---|
| 34 | ' <input type="text" id="' + obj.id + obj.name.replace(/\s/g, "") + "price" + '" class="form-control" placeholder="price" />' +
|
---|
| 35 | ' </div>' +
|
---|
| 36 | ' </div>' +
|
---|
| 37 | ' <div class="row" style="margin-top:10px;">' +
|
---|
| 38 | ' <div class="form-outline col-md-10 d-grid">' +
|
---|
| 39 | ' <input type="text" id="' + obj.id + obj.name.replace(/\s/g, "") + "description" + '" class="form-control" placeholder="description" />' +
|
---|
[46fd0c7] | 40 | ' </div>' +
|
---|
| 41 | ' </div>' +
|
---|
| 42 | '</div>');
|
---|
[2b0a4db] | 43 | });
|
---|
[46fd0c7] | 44 | $("#input_service").prop('disabled', false);
|
---|
| 45 | $("#add_service").prop('disabled', false);
|
---|
| 46 | });
|
---|
| 47 |
|
---|
| 48 | $("#add_service").click(function () {
|
---|
| 49 | var input_service = $("#input_service").val();
|
---|
| 50 | // clear the input
|
---|
| 51 | $("#input_service").val('');
|
---|
| 52 |
|
---|
| 53 | $("#predefined_services").append(
|
---|
| 54 | '<div class="form-outline mb-4">' +
|
---|
| 55 | ' <div class="row">' +
|
---|
[950fa0d] | 56 | ' <div class="col-md-6">\n' +
|
---|
[46fd0c7] | 57 | ' <input class="form-check-input" type="checkbox" checked value="' + -1 + '" id="' + -1 + '">\n' +
|
---|
| 58 | ' <label class="form-check-label" for="' + -1 + '">\n' +
|
---|
| 59 | input_service +
|
---|
| 60 | ' </label>\n' +
|
---|
| 61 | ' </div>' +
|
---|
| 62 | ' <div class="form-outline col-md-2 d-grid">' +
|
---|
[8bcd64c] | 63 | ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + "duration" + '" class="form-control" placeholder="time" />' +
|
---|
| 64 | ' </div>' +
|
---|
| 65 | ' <div class="form-outline col-md-2 d-grid">' +
|
---|
[f29cd58] | 66 | ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + "price" + '" class="form-control" placeholder="price" />' +
|
---|
| 67 | ' </div>' +
|
---|
[943857c] | 68 | ' </div>' +
|
---|
| 69 | ' <div class="row" style="margin-top:10px;">' +
|
---|
| 70 | ' <div class="form-outline col-md-10 d-grid">' +
|
---|
| 71 | ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + "description" + '" class="form-control" placeholder="description" />' +
|
---|
[46fd0c7] | 72 | ' </div>' +
|
---|
| 73 | ' </div>' +
|
---|
| 74 | '</div>');
|
---|
| 75 | event.preventDefault();
|
---|
| 76 | });
|
---|
| 77 |
|
---|
| 78 | $('#signup_business_button').click(function () {
|
---|
| 79 | let businessObj = {};
|
---|
| 80 | let ownerObj = {};
|
---|
| 81 |
|
---|
| 82 | ownerObj['firstName'] = $('#firstName').val();
|
---|
| 83 | ownerObj['lastName'] = $('#lastName').val();
|
---|
| 84 | ownerObj['email'] = $('#email').val();
|
---|
| 85 | ownerObj['username'] = $('#username').val();
|
---|
| 86 | ownerObj['password'] = $('#password').val();
|
---|
[77205be] | 87 | ownerObj['phoneNumber'] = $('#phoneNumber').val();
|
---|
[46fd0c7] | 88 | businessObj['owner'] = ownerObj;
|
---|
| 89 |
|
---|
| 90 | businessObj['companyName'] = $('#companyName').val();
|
---|
| 91 |
|
---|
| 92 | businessObj['businessType'] = {'value': $('#companyType').val()};
|
---|
| 93 |
|
---|
| 94 | servicesObj = [];
|
---|
| 95 |
|
---|
| 96 | $.each($('#predefined_services input:checked').siblings(), function(index, label) {
|
---|
| 97 |
|
---|
| 98 | let service = {};
|
---|
| 99 | var id = $(label).prop('for');
|
---|
| 100 | var text = $(label).text();
|
---|
| 101 | var time = $($($(label).parent()).siblings()[0]).children()[0].value;
|
---|
[8bcd64c] | 102 | var price = $($($(label).parent()).siblings()[1]).children()[0].value;
|
---|
[f29cd58] | 103 | var description = $($($($($($(label).parent())).parent()).siblings()[0]).children()[0]).children()[0].value;
|
---|
[46fd0c7] | 104 |
|
---|
| 105 | var serviceType = {}
|
---|
| 106 | if(parseInt(id) != -1) {
|
---|
| 107 | serviceType['id'] = id;
|
---|
| 108 | }
|
---|
| 109 | serviceType['name'] = text.trim();
|
---|
| 110 | service['serviceType'] = serviceType;
|
---|
| 111 | service['duration'] = time;
|
---|
[8bcd64c] | 112 | service['price'] = price;
|
---|
[f29cd58] | 113 | service['description'] = description;
|
---|
[46fd0c7] | 114 | servicesObj.push(service);
|
---|
| 115 | });
|
---|
| 116 | businessObj['services'] = servicesObj;
|
---|
| 117 | $.ajax({
|
---|
| 118 | url: "http://localhost:8080/api/business",
|
---|
| 119 | type:"POST",
|
---|
| 120 | data: JSON.stringify(businessObj),
|
---|
| 121 | contentType:"application/json; charset=utf-8",
|
---|
| 122 | dataType: 'text',
|
---|
[77205be] | 123 | success: function(success){
|
---|
[46fd0c7] | 124 | alert( "Well done! You have finished the registration process. " +
|
---|
| 125 | "Please check periodically to see if the company has been approved." );
|
---|
[53765dd] | 126 | window.location.href = "/login";
|
---|
[46fd0c7] | 127 | },
|
---|
| 128 | error: function(err) {
|
---|
| 129 | alert(err);
|
---|
| 130 | }
|
---|
| 131 | });
|
---|
| 132 | event.preventDefault();
|
---|
| 133 | });
|
---|
[2b0a4db] | 134 | }); |
---|