Ignore:
Timestamp:
12/26/23 18:50:43 (6 months ago)
Author:
gjoko kostadinov <gjokokostadinov@…>
Branches:
master
Children:
1413ee2
Parents:
950fa0d
Message:

Add entire code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/resources/static/js/business_admin.js

    • Property mode changed from 100644 to 100755
    r950fa0d r77205be  
    11$(document).ready(function() {
    2 
    32    var business = {};
    43
    5     $.ajax({
    6         url: "http://localhost:8080/api/business/me"
    7     }).then(function (data) {
    8         business = data;
    9         var $header = $("#header");
    10 
    11         // header
    12         $header.text($header.text() + " " + business["owner"]['firstName'] + " " + business['owner']['lastName']);
    13 
    14         // business info
    15         if(business['businessStatus'] == 'NEW') {
    16             $('#new_business_warning').removeAttr("hidden");
    17         }
    18         $('#business_status').val(business['businessStatus']);
    19         $('#business_type').val(business['businessType']['text']);
    20 
    21         // owner info
    22         $('#firstName').val(business['owner']['firstName']);
    23         $('#lastName').val(business['owner']['lastName']);
    24         $('#email').val(business['owner']['email']);
    25         $('#username').val(business['owner']['username']);
    26 
    27         // services info
    28         var $el = $("#predefined_services_admin_panel");
    29         $el.empty();
    30         $.each(business['services'], function (index, obj) {
    31             $el.append(
    32                 '<div class=\"form-outline mb-4\">' +
    33                 '    <div class="row">' +
    34                 '        <div class="col-md-6">\n' +
    35                 '            <input class="form-check-input" type="checkbox" checked value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' +
    36                 '            <label class="form-check-label" for=\"' + obj.id + '\">\n' +
    37                 obj['serviceType'].name +
    38                 '            </label>\n' +
    39                 '        </div>' +
    40                 '        <div class=\"form-outline col-md-2 d-grid\">' +
    41                 '            <input type=\"text\" id=\"' + obj.id + obj['serviceType'].name.replace(/\s/g, "") + "duration" + '\" class=\"form-control\" placeholder="time" value=\"' + obj.duration + '" />' +
    42                 '        </div>' +
    43                 '        <div class=\"form-outline col-md-2 d-grid\">' +
    44                 '            <input type=\"text\" id=\"' + obj.id + obj['serviceType'].name.replace(/\s/g, "") + "price" + '\" class=\"form-control\" placeholder="price" value=\"' + obj.price + '" />' +
    45                 '        </div>' +
    46                 '    </div>' +
    47                 '</div>');
    48         });
    49     });
     4    getBusinessInfo(business);
     5
     6    getAppointments();
    507
    518    $("#add_service").click(function () {
     
    12279    $("#update_owner_button").click(function() {
    12380        businesses = [];
    124         console.log("Gjoko");
    12581        business['owner']['firstName'] = $('#firstName').val();
    12682        business['owner']['lastName'] = $('#lastName').val();
    12783        business['owner']['email'] = $('#email').val();
     84        business['owner']['phoneNumber'] = $('#phoneNumber').val();
    12885        business['owner']['username'] = $('#username').val();
    12986
     
    147104    event.preventDefault();
    148105});
     106
     107function cancelAppointment(appointmentId) {
     108    if (confirm("Are you sure you want to cancel the appointment?")) {
     109        $.ajax({
     110            url: "http://localhost:8080/api/appointment/" + appointmentId,
     111            type:"DELETE"
     112        }).success(function (data) {
     113            alert("Appointment successfully canceled.")
     114            getAppointments();
     115        }).error(function (error) {
     116            alert("Something went wrong.");
     117        });
     118    }
     119}
     120
     121function getAppointments() {
     122    $.ajax({
     123        url: "http://localhost:8080/api/appointment/future/me"
     124    }).then(function (data) {
     125        console.log(data);
     126        var $el = $("#bookings-table-body");
     127        $el.empty();
     128        $.each(data, function (index, obj) {
     129            var element =
     130                '<tr>' +
     131                '   <th scope="row">' + (parseInt(index) + 1) + '</th>' +
     132                '   <td>' + obj['fullName'] + '</td>' +
     133                '   <td>' + obj['email'] + '</td>' +
     134                '   <td>' + obj['phoneNumber'] + '</td>' +
     135                '   <td>' + obj['timePeriod'] + '</td>' +
     136                '   <td>' + obj['serviceName'] + '</td>';
     137
     138            switch (obj['status']) {
     139                case 'NEW':
     140                    element += '   <td><button type="button" class="btn btn-danger" onclick="cancelAppointment(' + obj['appointmentId'] + ')">Cancel appointment</button></td>';
     141                    break;
     142                case 'CANCELLED_BY_CUSTOMER':
     143                    element += '   <td><button type="button" class="btn btn-secondary" disabled>Cancelled by customer</button></td>';
     144                    break;
     145                case 'CANCELLED_BY_BUSINESS_OWNER':
     146                    element += '   <td><button type="button" class="btn btn-secondary" disabled>Cancelled by business owner</button></td>';
     147                    break;
     148            }
     149            element+='</tr>';
     150
     151            $el.append(element);
     152        });
     153    });
     154}
     155
     156function getBusinessInfo(business) {
     157    $.ajax({
     158        url: "http://localhost:8080/api/business/me"
     159    }).then(function (data) {
     160        business = data;
     161        var $header = $("#header");
     162
     163        // header
     164        $header.text($header.text() + " " + business["owner"]['firstName'] + " " + business['owner']['lastName']);
     165
     166        // business info
     167        if(business['businessStatus'] == 'NEW') {
     168            $('#new_business_warning').removeAttr("hidden");
     169        }
     170        $('#business_status').val(business['businessStatus']);
     171        $('#business_type').val(business['businessType']['text']);
     172
     173        // owner info
     174        $('#firstName').val(business['owner']['firstName']);
     175        $('#lastName').val(business['owner']['lastName']);
     176        $('#phoneNumber').val(business['owner']['phoneNumber']);
     177        $('#email').val(business['owner']['email']);
     178        $('#username').val(business['owner']['username']);
     179
     180        // services info
     181        var $el = $("#predefined_services_admin_panel");
     182        $el.empty();
     183        $.each(business['services'], function (index, obj) {
     184            $el.append(
     185                '<div class=\"form-outline mb-4\">' +
     186                '    <div class="row">' +
     187                '        <div class="col-md-6">\n' +
     188                '            <input class="form-check-input" type="checkbox" checked value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' +
     189                '            <label class="form-check-label" for=\"' + obj.id + '\">\n' + obj['serviceType'].name + '</label>\n' +
     190                '        </div>' +
     191                '        <div class=\"form-outline col-md-2 d-grid\">' +
     192                '            <input type=\"text\" id=\"' + obj.id + obj['serviceType'].name.replace(/\s/g, "") + "duration" + '\" class=\"form-control\" placeholder="time" value=\"' + obj.duration + '" />' +
     193                '        </div>' +
     194                '        <div class=\"form-outline col-md-2 d-grid\">' +
     195                '            <input type=\"text\" id=\"' + obj.id + obj['serviceType'].name.replace(/\s/g, "") + "price" + '\" class=\"form-control\" placeholder="price" value=\"' + obj.price + '" />' +
     196                '        </div>' +
     197                '    </div>' +
     198                '</div>');
     199        });
     200    });
     201}
Note: See TracChangeset for help on using the changeset viewer.