source: src/main/resources/static/js/register_business.js@ 53765dd

Last change on this file since 53765dd was 53765dd, checked in by gjoko kostadinov <gjokokostadinov@…>, 6 months ago

Fix bugs.

  • Property mode set to 100755
File size: 5.1 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 $.each(selectedObj['serviceTypes'], function (index, obj) {
20 $el.append(
21 '<div class=\"form-outline mb-4\">' +
22 ' <div class="row">' +
23 ' <div class="col-md-6">\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>' +
29 ' <div class=\"form-outline col-md-2 d-grid\">' +
30 ' <input type=\"text\" id=\"' + obj.id + obj.name.replace(/\s/g, "") + "duration" + '\" class=\"form-control\" placeholder="time" />' +
31 ' </div>' +
32 ' <div class=\"form-outline col-md-2 d-grid\">' +
33 ' <input type=\"text\" id=\"' + obj.id + obj.name.replace(/\s/g, "") + "price" + '\" class=\"form-control\" placeholder="price" />' +
34 ' </div>' +
35 ' </div>' +
36 '</div>');
37 });
38 $("#input_service").prop('disabled', false);
39 $("#add_service").prop('disabled', false);
40 });
41
42 $("#add_service").click(function () {
43 var input_service = $("#input_service").val();
44 // clear the input
45 $("#input_service").val('');
46
47 $("#predefined_services").append(
48 '<div class="form-outline mb-4">' +
49 ' <div class="row">' +
50 ' <div class="col-md-6">\n' +
51 ' <input class="form-check-input" type="checkbox" checked value="' + -1 + '" id="' + -1 + '">\n' +
52 ' <label class="form-check-label" for="' + -1 + '">\n' +
53 input_service +
54 ' </label>\n' +
55 ' </div>' +
56 ' <div class="form-outline col-md-2 d-grid">' +
57 ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + "duration" + '" class="form-control" placeholder="time" />' +
58 ' </div>' +
59 ' <div class="form-outline col-md-2 d-grid">' +
60 ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + "price"+ '" class="form-control" placeholder="price" />' +
61 ' </div>' +
62 ' </div>' +
63 '</div>');
64 event.preventDefault();
65 });
66
67 $('#signup_business_button').click(function () {
68 let businessObj = {};
69 let ownerObj = {};
70
71 ownerObj['firstName'] = $('#firstName').val();
72 ownerObj['lastName'] = $('#lastName').val();
73 ownerObj['email'] = $('#email').val();
74 ownerObj['username'] = $('#username').val();
75 ownerObj['password'] = $('#password').val();
76 ownerObj['phoneNumber'] = $('#phoneNumber').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;
91 var price = $($($(label).parent()).siblings()[1]).children()[0].value;
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;
100 service['price'] = price;
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(success){
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 = "/login";
114 },
115 error: function(err) {
116 alert(err);
117 }
118 });
119 event.preventDefault();
120 });
121});
Note: See TracBrowser for help on using the repository browser.