source: src/main/resources/static/js/register_business.js@ 943857c

Last change on this file since 943857c was 943857c, checked in by gjoko kostadinov <gjokokostadinov@…>, 4 months ago

Fixing visual bug

  • Property mode set to 100755
File size: 6.0 KB
Line 
1$(document).ready(function() {
2 var enumerations = {};
3 $.ajax({
4 url: "http://localhost:8080/api/nomenclature/businessTypes"
5 }).then(function (data) {
6 enumerations = data;
7 var $el = $("#companyType");
8
9 $.each(data, function (index, obj) {
10 $el.append("<option value=" + obj.value + ">" + obj.text + "</option>");
11 });
12 });
13
14 $("#companyType").change(function () {
15 var selectedVal = $(this).find(':selected').val();
16 var selectedObj = enumerations[selectedVal - 1];
17 var $el = $("#predefined_services");
18 $el.empty();
19 console.log(selectedObj['serviceTypes']);
20 $.each(selectedObj['serviceTypes'], function (index, obj) {
21 $el.append(
22 '<div class="form-outline mb-4">' +
23 ' <div class="row">' +
24 ' <div class="col-md-6">\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, "") + "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" />' +
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" />' +
40 ' </div>' +
41 ' </div>' +
42 '</div>');
43 });
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">' +
56 ' <div class="col-md-6">\n' +
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">' +
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">' +
66 ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + "price" + '" class="form-control" placeholder="price" />' +
67 ' </div>' +
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" />' +
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();
87 ownerObj['phoneNumber'] = $('#phoneNumber').val();
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;
102 var price = $($($(label).parent()).siblings()[1]).children()[0].value;
103 var description = $($($($($($(label).parent())).parent()).siblings()[0]).children()[0]).children()[0].value;
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;
112 service['price'] = price;
113 service['description'] = description;
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',
123 success: function(success){
124 alert( "Well done! You have finished the registration process. " +
125 "Please check periodically to see if the company has been approved." );
126 window.location.href = "/login";
127 },
128 error: function(err) {
129 alert(err);
130 }
131 });
132 event.preventDefault();
133 });
134});
Note: See TracBrowser for help on using the repository browser.