source: src/main/resources/static/js/register_business.js@ 9050790

Last change on this file since 9050790 was 9050790, checked in by Gjoko Kostadinov <gjoko.kostadinov@…>, 16 months ago

Add admin functionality for activating or deactivating companies

  • Property mode set to 100644
File size: 4.4 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-8">\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, "") + '\" class=\"form-control\" />' +
32 ' </div>' +
33 ' </div>' +
34 '</div>');
35 });
36 $("#input_service").prop('disabled', false);
37 $("#add_service").prop('disabled', false);
38 });
39
40 $("#add_service").click(function () {
41 var input_service = $("#input_service").val();
42 // clear the input
43 $("#input_service").val('');
44
45 $("#predefined_services").append(
46 '<div class="form-outline mb-4">' +
47 ' <div class="row">' +
48 ' <div class="col-md-8">\n' +
49 ' <input class="form-check-input" type="checkbox" checked value="' + -1 + '" id="' + -1 + '">\n' +
50 ' <label class="form-check-label" for="' + -1 + '">\n' +
51 input_service +
52 ' </label>\n' +
53 ' </div>' +
54 ' <div class="form-outline col-md-2 d-grid">' +
55 ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + '" class="form-control" />' +
56 ' </div>' +
57 ' </div>' +
58 '</div>');
59 event.preventDefault();
60 });
61
62 $('#signup_business_button').click(function () {
63 let businessObj = {};
64 let ownerObj = {};
65
66 ownerObj['firstName'] = $('#firstName').val();
67 ownerObj['lastName'] = $('#lastName').val();
68 ownerObj['email'] = $('#email').val();
69 ownerObj['username'] = $('#username').val();
70 ownerObj['password'] = $('#password').val();
71 businessObj['owner'] = ownerObj;
72
73 businessObj['companyName'] = $('#companyName').val();
74
75 businessObj['businessType'] = {'value': $('#companyType').val()};
76
77 servicesObj = [];
78
79 $.each($('#predefined_services input:checked').siblings(), function(index, label) {
80
81 let service = {};
82 var id = $(label).prop('for');
83 var text = $(label).text();
84 var time = $($($(label).parent()).siblings()[0]).children()[0].value;
85
86 var serviceType = {}
87 if(parseInt(id) != -1) {
88 serviceType['id'] = id;
89 }
90 serviceType['name'] = text.trim();
91 service['serviceType'] = serviceType;
92 service['duration'] = time;
93 servicesObj.push(service);
94 });
95 businessObj['services'] = servicesObj;
96 console.log(JSON.stringify(businessObj));
97 $.ajax({
98 url: "http://localhost:8080/api/business",
99 type:"POST",
100 data: JSON.stringify(businessObj),
101 contentType:"application/json; charset=utf-8",
102 dataType: 'text',
103 success: function(succ){
104 alert( "Well done! You have finished the registration process. " +
105 "Please check periodically to see if the company has been approved." );
106 window.location.href = "/homepage";
107 },
108 error: function(err) {
109 alert(err);
110 }
111 });
112 event.preventDefault();
113 });
114});
Note: See TracBrowser for help on using the repository browser.