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
RevLine 
[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();
19 $.each(selectedObj['serviceTypes'], function (index, obj) {
20 $el.append(
[46fd0c7]21 '<div class=\"form-outline mb-4\">' +
22 ' <div class="row">' +
[8bcd64c]23 ' <div class="col-md-6">\n' +
[46fd0c7]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\">' +
[8bcd64c]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" />' +
[46fd0c7]34 ' </div>' +
35 ' </div>' +
36 '</div>');
[2b0a4db]37 });
[46fd0c7]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">' +
[950fa0d]50 ' <div class="col-md-6">\n' +
[46fd0c7]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">' +
[8bcd64c]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" />' +
[46fd0c7]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();
[77205be]76 ownerObj['phoneNumber'] = $('#phoneNumber').val();
[46fd0c7]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',
[77205be]110 success: function(success){
[46fd0c7]111 alert( "Well done! You have finished the registration process. " +
112 "Please check periodically to see if the company has been approved." );
[53765dd]113 window.location.href = "/login";
[46fd0c7]114 },
115 error: function(err) {
116 alert(err);
117 }
118 });
119 event.preventDefault();
120 });
[2b0a4db]121});
Note: See TracBrowser for help on using the repository browser.