@@ -20,13 +20,13 @@ function init() {
2020}
2121
2222function populateCustomerNames ( ) {
23- populateSelection ( $ ( '#input-customerName' ) [ 0 ] , ' /api/customers/names' )
23+ populateSelection ( $ ( '#input-customerName' ) [ 0 ] , ` ${ window . location . origin } /api/customers/names` )
2424}
2525
2626function populateDepartmentNames ( ) {
2727 let customer = $ ( '#input-customerName' ) [ 0 ] . value
2828 if ( customer === undefined || customer === '' ) return
29- populateSelection ( $ ( '#input-departmentName' ) [ 0 ] , ' /api/customers/' + customer + ' /departments' )
29+ populateSelection ( $ ( '#input-departmentName' ) [ 0 ] , ` ${ window . location . origin } /api/customers/${ customer } /departments` )
3030}
3131
3232async function populateSelection ( selectTag , optionsUrl ) {
@@ -51,11 +51,27 @@ function toLocalISOString(date) {
5151}
5252
5353function submitCreateEntry ( ) {
54- var data = $ ( 'form' ) . serializeArray ( )
54+ let data = {
55+ 'customerInfo' : {
56+ 'name' : $ ( '#input-customerName' ) [ 0 ] . value ,
57+ 'department' : $ ( '#input-departmentName' ) [ 0 ] . value
58+ } ,
59+ 'startTime' : $ ( '#input-startTime' ) [ 0 ] . value ,
60+ 'endTime' : $ ( '#input-endTime' ) [ 0 ] . value ,
61+ 'notes' : $ ( '#input-notes' ) [ 0 ] . value
62+ }
5563
56- fetch ( {
57- method : 'POST' , url : 'api/timetableEntries/create' , headers : {
64+ fetch ( `${ window . location . origin } /api/timetableEntries/create` , {
65+ method : 'POST' ,
66+ headers : {
5867 'Content-Type' : 'application/json'
59- } , body : JSON . stringify ( data )
68+ } ,
69+ body : JSON . stringify ( data )
70+ } ) . then ( response => {
71+ if ( Math . floor ( response . status / 100 ) === 2 ) {
72+ window . location . href = `${ window . location . origin } /timetable/${ data . customerInfo . name } /${ data . customerInfo . department } /${ data . startTime } `
73+ return
74+ }
75+ response . text ( ) . then ( alert )
6076 } )
6177}
0 commit comments