Ignore:
Timestamp:
05/24/23 23:18:47 (16 months ago)
Author:
Gjoko Kostadinov <gjoko.kostadinov@…>
Branches:
master
Children:
77205be
Parents:
8bcd64c
Message:

Periodic update

File:
1 edited

Legend:

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

    r8bcd64c r950fa0d  
    11$(document).ready(function() {
     2    var businessTypes = {};
     3    var businesses = {};
    24    var date = new Date();
    35    var d = date.getDate();
     
    1113    */
    1214
    13 
     15    $.ajax({
     16        type: 'GET',
     17        url: "http://localhost:8080/api/user/me",
     18        success: function(data, textStatus, request) {
     19            if (data) {
     20                $('#create').parent().removeClass('hidden-button');
     21                $('#profile').parent().removeClass('hidden-button');
     22                $('#logout').parent().removeClass('hidden-button');
     23                $('#login').parent().addClass('hidden-button');
     24            } else {
     25                $('#create').parent().addClass('hidden-button');
     26                $('#profile').parent().addClass('hidden-button');
     27                $('#logout').parent().addClass('hidden-button');
     28                $('#login').parent().removeClass('hidden-button');
     29            }
     30        },
     31        error: function (request, textStatus, errorThrown) {
     32            console.log(errorThrown);
     33        }
     34    });
    1435    /* initialize the external events
    1536    -----------------------------------------------------------------*/
     
    3556    });
    3657
     58    $.ajax({
     59        url: "http://localhost:8080/api/nomenclatures/businessTypes"
     60    }).then(function (data) {
     61        businessTypes = data;
     62        var $el = $("#companyType");
     63        emptyDropdown($el);
     64
     65        $.each(data, function (index, obj) {
     66            $el.append("<option value=" + obj.value + ">" + obj.text + "</option>");
     67        });
     68    });
     69
     70    $("#companyType").change(function () {
     71        var selectedVal = $(this).find(':selected').val();
     72        var selectedObj = businessTypes[selectedVal - 1];
     73        $.ajax({
     74            url: "http://localhost:8080/api/business/" + selectedObj.value
     75        }).then(function (data) {
     76            businesses = data;
     77            console.log(data);
     78            var $el = $("#company");
     79            var $servicesEl = $("#service");
     80            emptyDropdown($el);
     81            emptyDropdown($servicesEl);
     82
     83            $.each(data, function (index, obj) {
     84                $el.append("<option value=" + obj.id + ">" + obj.companyName + "</option>");
     85            });
     86        });
     87    });
     88
     89    $("#company").change(function () {
     90        var selectedVal = $(this).find(':selected').val();
     91        $.ajax({
     92            url: "http://localhost:8080/api/appointment/business/" + selectedVal
     93        }).then(function (data) {
     94            console.log(data);
     95            var $el = $("#service");
     96            emptyDropdown($el);
     97
     98            var services = businesses.find(item => item.id == selectedVal)['services'];
     99            console.log(services);
     100
     101            $.each(services, function (index, obj) {
     102                $el.append("<option value=" + obj.id + ">" + obj.serviceType.name + "</option>");
     103            });
     104        });
     105    });
     106
    37107
    38108    /* initialize the calendar
     
    47117        editable: false,
    48118        edit: function (start, end, allDay) {
    49 
     119            console.log(start);
     120            console.log(end);
    50121        },
    51122        firstDay: 1, //  1(Monday) this can be changed to 0(Sunday) for the USA system
     
    131202                start: new Date(y, m, d, 10, 30),
    132203                allDay: false,
    133                 className: 'important'
     204                className: 'info'
    134205            },
    135206            {
     
    138209                end: new Date(y, m, d, 14, 0),
    139210                allDay: false,
    140                 className: 'important'
     211                className: 'info'
    141212            },
    142213            {
     
    155226        ],
    156227    });
    157     $("#search").click(function () {
    158         alert("qweqew");
     228
     229    $("#createAppointment").click(function() {
     230        var appointment = {};
     231        appointment['business'] = {'id': parseInt($("#company").val())};
     232        appointment['service'] = {'id': parseInt($("#service").val())};
     233        appointment['startTime'] = $("#startdatetime").val();
    159234
    160235        $.ajax({
    161             url: "http://localhost:8080/events"
    162         }).then(function(data) {
    163             console.log(data);
    164         });
    165     });
     236            url: "http://localhost:8080/api/appointment",
     237            type:"POST",
     238            data: JSON.stringify(appointment),
     239            contentType:"application/json; charset=utf-8",
     240            dataType: 'text',
     241            success: function(succ){
     242                console.log('success');
     243            },
     244            error: function(err) {
     245                console.log(JSON.stringify(err));
     246            }
     247        });
     248    })
    166249
    167250});
    168251
    169 function search() {
    170 
     252document.getElementById("login").addEventListener("click", function(event){
     253   window.location = "/login";
     254});
     255
     256function emptyDropdown(element) {
     257    var defaultOption = element.children().get(0);
     258    element.children().remove().end().append(defaultOption);
    171259}
Note: See TracChangeset for help on using the changeset viewer.