source: src/main/resources/static/js/register_business.js@ 77205be

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

Add entire code

  • 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/nomenclatures/businessTypes"
5 }).then(function (data) {
6 enumerations = data;
7 var $el = $("#companyType");
8 //$el.empty(); // remove old options
9
10 $.each(data, function (index, obj) {
11 $el.append("<option value=" + obj.value + ">" + obj.text + "</option>");
12 });
13 });
14
15 $("#companyType").change(function () {
16 var selectedVal = $(this).find(':selected').val();
17 var selectedObj = enumerations[selectedVal - 1];
18 var $el = $("#predefined_services");
19 $el.empty();
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>');
38 });
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">' +
51 ' <div class="col-md-6">\n' +
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">' +
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" />' +
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 ownerObj['phoneNumber'] = $('#phoneNumber').val();
78 businessObj['owner'] = ownerObj;
79
80 businessObj['companyName'] = $('#companyName').val();
81
82 businessObj['businessType'] = {'value': $('#companyType').val()};
83
84 servicesObj = [];
85
86 $.each($('#predefined_services input:checked').siblings(), function(index, label) {
87
88 let service = {};
89 var id = $(label).prop('for');
90 var text = $(label).text();
91 var time = $($($(label).parent()).siblings()[0]).children()[0].value;
92 var price = $($($(label).parent()).siblings()[1]).children()[0].value;
93
94 var serviceType = {}
95 if(parseInt(id) != -1) {
96 serviceType['id'] = id;
97 }
98 serviceType['name'] = text.trim();
99 service['serviceType'] = serviceType;
100 service['duration'] = time;
101 service['price'] = price;
102 servicesObj.push(service);
103 });
104 businessObj['services'] = servicesObj;
105 console.log(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(success){
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 });
123});
Note: See TracBrowser for help on using the repository browser.