source: src/main/resources/static/js/admin.js@ 8bcd64c

Last change on this file since 8bcd64c 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: 2.3 KB
Line 
1$(document).ready(function() {
2 var companies = {};
3
4 $.ajax({
5 url: "http://localhost:8080/api/business"
6 }).then(function (data) {
7 companies = data;
8 var $el = $("#table_body");
9
10 $.each(data, function (index, obj) {
11 if(obj.businessStatus == "NEW" || obj.businessStatus == "DEACTIVATED") {
12 $el.append("<tr>\n" +
13 " <th scope=\"row\">" + obj.id + "</th>\n" +
14 " <td>" + obj.companyName + "</td>\n" +
15 " <td>" + obj.owner.firstName + " " + obj.owner.lastName + "</td>\n" +
16 " <td><input class=\"form-check-input\" type=\"checkbox\" value=\"" + obj.id +"\"></td>\n" +
17 " </tr>")
18 }
19 if (obj.businessStatus == "ACTIVE") {
20 $el.append("<tr>\n" +
21 " <th scope=\"row\">" + obj.id + "</th>\n" +
22 " <td>" + obj.companyName + "</td>\n" +
23 " <td>" + obj.owner.firstName + " " + obj.owner.lastName + "</td>\n" +
24 " <td><input class=\"form-check-input\" type=\"checkbox\" checked value=\"" + obj.id +"\"></td>\n" +
25 " </tr>")
26 }
27 });
28 });
29
30 $('#save_button').click(function () {
31 $.each($('#table_body tr'), function(index, row) {
32 if(companies[index].businessStatus == "NEW" && $($($(row).children() [3]).children()[0]).is(':checked')) {
33 companies[index]['businessStatus'] = 'ACTIVE';
34 }
35 if(companies[index].businessStatus == "ACTIVE" && ! $($($(row).children() [3]).children()[0]).is(':checked')) {
36 companies[index]['businessStatus'] = 'DEACTIVATED';
37 }
38 });
39 console.log(JSON.stringify(companies));
40 $.ajax({
41 url: "http://localhost:8080/api/business",
42 type:"PATCH",
43 data: JSON.stringify(companies),
44 contentType:"application/json; charset=utf-8",
45 dataType: 'text',
46 success: function(succ){
47 alert( "Updates applied successfully" );
48 },
49 error: function(err) {
50 alert(err);
51 }
52 });
53 event.preventDefault();
54 });
55});
Note: See TracBrowser for help on using the repository browser.