-
Notifications
You must be signed in to change notification settings - Fork 2
/
order_add_form2.html
851 lines (689 loc) · 27.1 KB
/
order_add_form2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Daakiya - Route Optimization and Delivery Management</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<link href="./css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="css/theme.css" rel="stylesheet"/>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="icon" href="./img/favicon-d.png">
<script type="text/javascript" src="./accessKeys.js"></script>
</head>
<html>
<body>
<div id="navbarLoader"></div>
<style type="text/css">
.body {
font-family: 'Raleway', sans-serif;
}
.thumbnail {
padding: 4px;
line-height: 1.42857143;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
-webkit-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
display: inline-block;
max-width: 100%;
height: auto;
box-shadow: 0 1px 2px rgba(0, 0, 0, .075);
}
.header {
margin-top: -19px;
margin-bottom: 29px;
background: linear-gradient(45deg, #083100 0%, #336d61 100%);
box-shadow: 0px 8px 31px 0px #0e0b0b96 inset;
padding-top: 28px;
padding-bottom: 27px;
color: #ececec;
text-shadow: 1px 1px 1px #000;
background: linear-gradient(45deg, #0e1d0c 0%, #335a6d 100%);
}
.header .dropdown-menu {
text-shadow: 0px 0px 0px #000;
/*display:table;*/
}
.dropdown-menu {
top: 27px;
left: 0px;
/*display: table;*/
width: 556px;
}
</style>
<div class="">
<div class="container">
<div class="">
<div class="row">
<div class="col-xs-12 col-md-12 col-lg-6" style="height: 450px;">
<div class="">
<div class="dropdown">
<input onchange="this.value = strip(this.value);" class="form-control"
id="typeahead"
class=" typeahead"
placeholder="Start typing order address here to geocode."
style="
height: 38px;
/*box-shadow: 0px 0px 4px 0px #0000005c inset;*/
/*border: 1px solid #CCC;*/
/*margin-bottom: 0px;*/
/*z-index: 3;*/
/*position: absolute;*/
/*margin-top: 31px;*/
/*width: 77%;*/
/*height: 38px;*/
/*box-shadow: 0px 0px 4px 0px #000 inset;*/
/*border: 1px solid black;*/
/* color: #000; */
/* font-size: 23px; */
/*margin-left: 67px;*/
"
type="search"
autocomplete="off" data-provide="typeahead"/>
</div>
</div>
<br/>
<div class="col-xs-12 col-md-12 col-lg-12" style="height: 480px; border:1px solid #CCC;">
<div id="map"
style="height: 100%;width: 100%;position: absolute;top: 0px;left: 0px;
background-color: transparent;
box-shadow: 1px 1px 7px 4px #CCC;
border: 1px solid #CCC;"
></div>
</div>
</div>
<div class="col-xs-12 col-md-12 col-lg-6" style="margin-top: 33px;">
<h1>Order Details</h1>
<br/>
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-3">Order Number *: </label>
<div class="col-sm-9">
<div class="input-group">
<input type="text" class="form-control" id="orderNumber" autocomplete="new-order" placeholder="Order Number" readonly required/>
<span class="input-group-btn">
<button class="btn btn-default" type="button" onclick="genrerateNumber()">Generate Number</button>
</span>
</div><!-- /input-group -->
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Customer*: </label>
<div class="col-sm-9">
<input autocomplete="new-customer" id="customerName" type="text" class="form-control" id="customerName" placeholder="Enter Customer Name" required/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Order alias: </label>
<div class="col-sm-9">
<input autocomplete="new-customer" id="orderName" type="text" class="form-control" placeholder="Your order alias (Eg. Jack's Order)">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Edit Address*:</label>
<div class="col-sm-9">
<input autocomplete="new-address" id="address" type="text" class="form-control" id="address" placeholder="Enter address" required/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Delivery ETA:</label>
<div class="col-sm-9">
<input type="datetime-local" class="form-control" id="eta" placeholder="Deliver before">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Latitude: </label>
<div class="col-sm-9">
<input type="text" class="form-control" id="lat" placeholder="lat"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Longitude :</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="long" placeholder="long">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" id="addOrderSubmit" onclick="addOrder()" class="btn btn-primary">Add Order</button>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel"><span id="myMessage">New message</span></h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="window.location.reload();">Add an another order</button>
<a href="./order_list_view.html" type="button" class="btn btn-primary">View all orders</a>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="container" role="main">
<div class="row">
</div>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="./js/vendor/jquery-3.4.1.min.js"><\/script>')</script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/docs.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
<script type="text/javascript">
function genrerateNumber () {
//Set new Date().getTime() to order number
document.getElementById("orderNumber").value = new Date().getTime()
}
function strip(html)
{
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
$("ul.dropdown-menu").css('display', 'table');
//$('.example').css('background-color', 'red');
return tmp.textContent || tmp.innerText || " ";
}
/**
* Moves the map to display over Berlin
*
* @param {H.Map} map A HERE Map instance within the application
*/
let latitude = 19.075983;
let longitude = 72.877655;
function moveMap(map){
map.setCenter({lat: latitude, lng: longitude});
map.setZoom(14);
}
//Get Geolocation
function getLocation(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
console.log("Geolocation is not supported");
//Showing Default Map Location
moveMap(map)
//moveMyMapAndMarker(latitude, longitude);
}
}
function showPosition(position){
console.log(position.coords.latitude + " " + position.coords.longitude);
latitude = position.coords.latitude;
longitude = position.coords.longitude;
moveMyMapAndMarker(latitude, longitude);
}
/**
* Boilerplate map initialization code starts below:
*/
//Step 1: initialize communication with the platform
var platform = new H.service.Platform({
app_id: module_HEREDeveloperAccess.app_id,
app_code: module_HEREDeveloperAccess.app_code,//'IulCKZdfTxT9b5NPveT_og',
useCIT: true,
useHTTPS: true
});
var defaultLayers = platform.createDefaultLayers();
//Step 2: initialize a map - not specificing a location will give a whole world view.
var map = new H.Map(document.getElementById('map'),
defaultLayers.normal.map);
// Create a MapTileService instance to request base tiles (i.e.
// base.map.api.here.com):
var mapTileService = platform.getMapTileService({'type': 'base'});
// Enable the event system on the map instance:
var mapEvents = new H.mapevents.MapEvents(map);
const clicked = {onMapMarker: false, outsideMapMarker: false}
// Add event listener:
map.addEventListener('tap', function (evt){
// Log 'tap' and 'mouse' events:
console.log(evt)
let target = evt.target
console.log(evt.type, evt.currentPointer.type);
});
// disable the default draggability of the underlying map
// when starting to drag a marker object:
map.addEventListener('dragstart', function (ev){
var target = ev.target;
// if (target instanceof H.map.Marker || target instanceof H.map.DomMarker ) {
// behavior.disable();
// }
if (target instanceof H.map.Marker || target instanceof H.map.DomMarker) {
behavior.disable();
}
}, false);
// re-enable the default draggability of the underlying map
// when dragging has completed
map.addEventListener('dragend', function (ev){
var target = ev.target;
if (target instanceof H.map.Marker || target instanceof H.map.DomMarker) {
behavior.enable();
latitude = target.getPosition().lat;
longitude = target.getPosition().lng;
document.getElementById("lat").value = latitude;
document.getElementById("long").value = longitude;
console.log(target.getPosition().lat + " " + target.getPosition().lng)
//Optionally : Reverse Geocode an address and print it in
}
}, false);
// Listen to the drag event and move the position of the marker
// as necessary
map.addEventListener('drag', function (ev){
var target = ev.target,
pointer = ev.currentPointer;
if (target instanceof H.map.Marker || target instanceof H.map.DomMarker) {
target.setPosition(map.screenToGeo(pointer.viewportX, pointer.viewportY));
}
}, false);
//Step 3: make the map interactive
// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(mapEvents);
// Create the default UI components
//var ui = H.ui.UI.createDefault(map, defaultLayers);
// Add info bubble to the UI:
// Create an info bubble object at a specific geographic location:
var bubble = new H.ui.InfoBubble({lng: longitude, lat: latitude}, {
content: '<div><a href=\'http://www.mcfc.co.uk\' style="color:cornflowerblue" >Manchester City</a>' +
'</div><div >City of Manchester Stadium<br>Capacity: 48,000</div>'
});
//Adding markers
//create dom icon and add/remove opacity listeners
var outerElement = document.createElement('div'),
innerElement = document.createElement('span');
outerElement.style.userSelect = 'none';
outerElement.style.webkitUserSelect = 'none';
outerElement.style.msUserSelect = 'none';
outerElement.style.mozUserSelect = 'none';
outerElement.style.cursor = 'default';
/**
* color: #bd3a3a;
background-color: #bd3a3a;
border: 2px solid white;
border-radius: 10px;
font: 12px/12px arial;
padding-top: 2px;
padding-left: 4px;
width: 20px;
height: 20px;
margin-top: -10px;
margin-left: -10px;
opacity: 1;
box-shadow: 1px 1px 10px 1px #000;
*/
innerElement.style.color = '#bd3a3a';
innerElement.style.backgroundColor = '#bd3a3a';
innerElement.style.boxShadow = "1px 1px 7px 1px #000";
innerElement.style.border = '2px solid white';
innerElement.style.borderRadius = '10px';
innerElement.style.borderRadius = '10px';
innerElement.style.font = 'normal 12px arial';
innerElement.style.lineHeight = '12px';
//Add icon
innerElement.setAttribute("class", "glyphicon glyphicon-map-marker")
//Add bootstrap popvers
innerElement.setAttribute("data-toggle", "popover")
innerElement.setAttribute("data-placement", "top")
innerElement.setAttribute("data-content", "Your order location")
innerElement.setAttribute("data-original-title", "Order")
innerElement.style.paddingTop = '2px';
innerElement.style.paddingLeft = '4px';
innerElement.style.width = '20px';
innerElement.style.height = '20px';
// add negative margin to inner element
// to move the anchor to center of the div
innerElement.style.marginTop = '-10px';
innerElement.style.marginLeft = '-10px';
outerElement.appendChild(innerElement);
// Add text to the DOM element
innerElement.innerHTML = '';
function changeOpacity(evt) {
evt.target.style.opacity = 0.6;
};
function changeOpacityToOne(evt) {
evt.target.style.opacity = 1;
};
var domIcon = new H.map.DomIcon(outerElement, {
// the function is called every time marker enters the viewport
onAttach: function(clonedElement, domIcon, domMarker) {
clonedElement.addEventListener('mouseover', changeOpacity);
clonedElement.addEventListener('mouseout', changeOpacityToOne);
},
// the function is called every time marker leaves the viewport
onDetach: function(clonedElement, domIcon, domMarker) {
clonedElement.removeEventListener('mouseover', changeOpacity);
clonedElement.removeEventListener('mouseout', changeOpacityToOne);
}
});
let coords = {lat: latitude, lng: longitude};
//let marker = new H.map.Marker(coords);
//Change marker to dom marker
let marker = new H.map.DomMarker(coords, { icon: domIcon });
marker.draggable = true;
// Add the marker to the map and center the map at the location of the marker:
map.addObject(marker);
map.setCenter(coords);
var forMarker = true;
marker.addEventListener("tap", function (evt){
// Log 'tap' and 'mouse' events:
console.log("On Marker: " + evt)
forMarker = true;
// Add info bubble to the UI:
//ui.addBubble(bubble);
bubble.open();
console.log(evt.type, evt.currentPointer.type);
})
// Now use the map as required...
moveMap(map);
getLocation();
//moveMyMapAndMarker(latitude, longitude)
//moveMap(map);
function dropDownHide(){
$(".dropdown-menu").css("display", "false")
}
/**
* Will Navigate to area selected on autocomplete
*/
function autocompleteNavigateToArea (location) {
if (location && location.name != "") {
latitude = location.position[0];
longitude = location.position[1];
//Navigate marker to the position which is selected on dropdown
moveMyMapAndMarker(latitude, longitude)
document.getElementById("address").value = location.name;
}
}
function moveMyMapAndMarker(lat, long){
coords = {lat: lat, lng: long}
map.setCenter(coords);
map.setZoom(14);
//Move Marker
//coords = {lat: 11, lng: 12}
// Add the marker to the map and center the map at the location of the marker:
//map.addObject(marker);
console.log("Moving Map : "+marker.getPosition())
marker.setPosition(coords)
//Set Lat Lon on Text fields
document.getElementById("lat").value = lat;
document.getElementById("long").value = long;
}
</script>
<script type="text/javascript" src="./js/autocomplete/typeahead.js"></script>
<script type="text/javascript">
var data = [];
// use this hash to cache search results
window.query_cache = {};
$('#typeahead').typeahead({
updater: function(item) {
// do what you want with the item here
console.log(item);
autocompleteNavigateToArea(item);
return item;
},
source:function(query,process){
// if in cache use cached value, if don't wanto use cache remove this if statement
if(query_cache[query]){
process(query_cache[query]);
return;
}
if( typeof searching != "undefined") {
clearTimeout(searching);
process([]);
}
searching = setTimeout(function() {
return $.getJSON(
"https://places.cit.api.here.com/places/v1/" +
"autosuggest?at="+(latitude || 19.15175231269505)+","+(longitude || 72.88745407619615)+"" +
"&q="+""+query+
"&app_id=BpplrrmjrB6JKrACzYmi" +
"&app_code=P_DAr6Tm3U-aqDvSmzkpgg",
//{ q:query },
function(data){
// save result to cache, remove next line if you don't want to use cache
let array = [];
data.results.map((location, index) => {
let json =
{
name: strip(location.highlightedTitle) + " " + strip((location.highlightedVicinity || " ")),
highlightedTitle : location.highlightedTitle,
highlightedVicinity : location.highlightedVicinity,
position : location.position,
id : location.id
}
//Push the resultset only when there is a location object
if (json && json.position && json.position !== undefined){
//array.push(location.highlightedTitle + "# " + (location.highlightedVicinity || "") + " "+"#"+location.id);
array.push(json);
}
})
data = array;
console.log("DATA:", data)
query_cache[query] = array;
// only search if stop typing for 300ms aka fast typers
return process(array);
}
);
}, 150); // 300 ms
}
});
function getPlacesAPI (placeName) {
return new Promise ((resolve, reject) => {
$.ajax({url: "https://places.cit.api.here.com/places/v1/" +
"autosuggest?at=19.111743,72.9095206" +
"&q="+placeName+
"&app_id="+module_HEREDeveloperAccess.app_id +
"&app_code="+module_HEREDeveloperAccess.app_code,
success: function(result){
//$("#div1").html(result);
resolve(result);
},
error: function(xhr, status, error){
reject({status : xhr.status , statusText : xhr.statusText, error, status});
console.log('Error - ' + xhr.status +" : "+ xhr.statusText);
}
});
});
}
//
// $.get("https://next.json-generator.com/api/json/get/V1cGoKmDV", function(data){
// console.log(data);
// // use a data source with 'id' and 'name' keys
// $("#typeahead").typeahead({ source:data });
// },'json');
function getPlaces(){
let placeName = document.getElementById("typeahead").value
$.get("https://next.json-generator.com/api/json/get/V1cGoKmDV", function(data){
console.log(data);
// use a data source with 'id' and 'name' keys
$("#typeahead").typeahead({ source:data });
},'json');
//console.log("Searching for : "+placeName);
//var placesResults = await getPlacesAPI(placeName);
//await console.log(placesResults)
//
//
// var options = {
// url: "https://places.cit.api.here.com/places/v1/" +
// "autosuggest?at=19.111743,72.9095206" +
// "&q="+placeName+
// "&app_id=BpplrrmjrB6JKrACzYmi" +
// "&app_code=P_DAr6Tm3U-aqDvSmzkpgg",
// getValue:
// "name",
// list: {
// match: {
// enabled: true
// }
// },
// theme: "square"
// };
// $("#typeahead").easyAutocomplete(options);
//
}
$(document).ready(function (){
//typeahead.initialize();
genrerateNumber();
$("#navbarLoader").load('./templates/navbar_standard.html')
//
// let onSubmitAdd = document.getElementById("addOrderSubmit");
// onSubmitAdd.addEventListener("submit" , (e) => {
// e.preventDefault();
// })
});
</script>
<!-- Firebase App (the core Firebase SDK) is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-app.js"></script>
<!-- Add Firebase products that you want to use -->
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.1.1/firebase-firestore.js"></script>
<style type="text/css">
.background-input {
background-color:#d9edff;
color:#000;
}
</style>
<script type="text/javascript">
// Your web app's Firebase configuration
var firebaseConfig = module_firebaseConfig;
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Get a reference to the database service
//var database = firebase.database();
var db = firebase.firestore();
var userId = "";
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
console.log("Loaded ", user)
$("#emailId").text(user.email)
//Fetch all orders belonging to that user id - auth.currentUser.uid
let currentUserId = firebase.auth().currentUser.uid; //W0snQdSu0hdDUmTH85BlJKzkPTr2
console.log("currentUserId: ",currentUserId)
userId = currentUserId;
} else {
// No user is signed in.
window.location.href = "/";
}
});
async function addOrder () {
let validationFailed = false;
document.getElementById("addOrderSubmit").setAttribute("disabled", "true")
//Get Order Details
let orderNumber = document.getElementById("orderNumber").value;
if (orderNumber == ""){
$("#orderNumber").addClass("background-input");
validationFailed = true;
//return;
}
let orderName = document.getElementById("orderName").value;
let customerName = document.getElementById("customerName").value;
if (customerName == ""){
$("#customerName").addClass("background-input");
validationFailed = true;
//return;
}
let eta = document.getElementById("eta").value;
// if (eta == ""){
// $("#customerName").addClass("background-input");
// validationFailed = true;
// //return;
// }
let custAddress = document.getElementById("address").value;
if (custAddress == ""){
$("#address").addClass("background-input");
validationFailed = true;
//return;
}
let lat = document.getElementById("lat").value;
let long = document.getElementById("long").value;
if (validationFailed){
document.getElementById("addOrderSubmit").removeAttribute("disabled")
return;
}
let creationDate = new Date().getTime();
let status = "NEW";
let doc = {
orderNumber : orderNumber,
orderName : orderName,
customerName : customerName,
custAddress : custAddress,
eta : eta,
position : [lat, long],
creationDate : creationDate,
status : status,
createdBy : userId
}
console.log(doc);
try{
let documentAdd = await db.collection("orders").add(doc);
console.log(documentAdd)
if (documentAdd){
console.log("document successfully added..")
genrerateNumber();
$("#myMessage").text("Order successfully added..")
document.getElementById("addOrderSubmit").removeAttribute("disabled")
$('#myModal').modal({show : true})
}
else{
$("#myMessage").text("Error in adding order..")
document.getElementById("addOrderSubmit").removeAttribute("disabled")
}
} catch (err) {
console.log("Unable to add order ", doc)
document.getElementById("addOrderSubmit").removeAttribute("disabled")
$("#myMessage").text("Error in adding order..")
}
}
//
// $('#exampleModal').on('show.bs.modal', function (event) {
// var button = $(event.relatedTarget) // Button that triggered the modal
// var recipient = button.data('whatever') // Extract info from data-* attributes
// // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
// // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
// var modal = $(this)
// modal.find('.modal-title').text('New message to ' + recipient)
// modal.find('.modal-body input').val(recipient)
// })
</script>
<svg xmlns="http://www.w3.org/2000/svg" width="1140" height="500" viewBox="0 0 1140 500" preserveAspectRatio="none"
style="display: none; visibility: hidden; position: absolute; top: -100%; left: -100%;">
<defs>
<style type="text/css"></style>
</defs>
<text x="0" y="57" style="font-weight:bold;font-size:57pt;font-family:Arial, Helvetica, Open Sans, sans-serif">
</text>
</svg>
</body>
</html>