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