source: src/main/resources/static/js/admin.js@ 1413ee2

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

Add all bug fixes.

  • Property mode set to 100755
File size: 2.9 KB
RevLine 
[46fd0c7]1$(document).ready(function() {
[77205be]2 let companies = [];
[46fd0c7]3
[77205be]4 getCompanies().then(function (data) {
[9050790]5 companies = data;
6 });
7
8 $('#save_button').click(function () {
[77205be]9 var companiesToSave = [];
[9050790]10 $.each($('#table_body tr'), function(index, row) {
[77205be]11 if((companies[index].businessStatus === "NEW" || companies[index].businessStatus === "DEACTIVATED") && $($($(row).children() [3]).children()[0]).is(':checked')) {
12 let cloneCompany = { ...companies[index] }
13 cloneCompany['businessStatus'] = 'ACTIVE';
14 companiesToSave.push(cloneCompany);
[9050790]15 }
[77205be]16 if(companies[index].businessStatus === "ACTIVE" && !$($($(row).children() [3]).children()[0]).is(':checked')) {
17 let cloneCompany = { ...companies[index] }
18 cloneCompany['businessStatus'] = 'DEACTIVATED';
19 companiesToSave.push(cloneCompany);
[9050790]20 }
21 });
[77205be]22
23
[9050790]24 $.ajax({
[1413ee2]25 url: "http://localhost:8080/api/admin",
[9050790]26 type:"PATCH",
[77205be]27 data: JSON.stringify(companiesToSave),
[9050790]28 contentType:"application/json; charset=utf-8",
29 dataType: 'text',
30 success: function(succ){
[77205be]31 getCompanies().then(function (data) {
32 companies = data;
33 });
[9050790]34 alert( "Updates applied successfully" );
35 },
36 error: function(err) {
37 alert(err);
38 }
39 });
40 event.preventDefault();
41 });
[77205be]42
43 function getCompanies() {
44 return $.ajax({
45 url: "http://localhost:8080/api/business"
46 }).then(function (data) {
47 var $el = $("#table_body");
48 $("#new_table tbody").html("");
49 $.each(data, function (index, obj) {
50 if(obj.businessStatus == "NEW" || obj.businessStatus == "DEACTIVATED") {
51 $el.append("<tr>\n" +
52 " <th scope=\"row\">" + obj.id + "</th>\n" +
53 " <td>" + obj.companyName + "</td>\n" +
54 " <td>" + obj.owner.firstName + " " + obj.owner.lastName + "</td>\n" +
55 " <td><input class=\"form-check-input\" type=\"checkbox\" value=\"" + obj.id +"\"></td>\n" +
56 " </tr>")
57 }
58 if (obj.businessStatus == "ACTIVE") {
59 $el.append("<tr>\n" +
60 " <th scope=\"row\">" + obj.id + "</th>\n" +
61 " <td>" + obj.companyName + "</td>\n" +
62 " <td>" + obj.owner.firstName + " " + obj.owner.lastName + "</td>\n" +
63 " <td><input class=\"form-check-input\" type=\"checkbox\" checked value=\"" + obj.id +"\"></td>\n" +
64 " </tr>")
65 }
66 });
67 return data;
68 });
69 }
[46fd0c7]70});
Note: See TracBrowser for help on using the repository browser.