-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.html
More file actions
507 lines (372 loc) · 13.9 KB
/
cart.html
File metadata and controls
507 lines (372 loc) · 13.9 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Cart</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.6.14.min.js"></script>
<script type="text/javascript" src="mandrill.js"></script>
<script src="node_modules/node-uuid/uuid.js"></script>
<link rel="stylesheet" href="bootstrap-table.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.0/bootstrap-table.min.js"></script>
</head>
<body>
<nav class=" navbar navbar-default">
<div class="container-fluid">
<!-- logo -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collaspe" data-target="#mainnavbar">
<!-- make the three line icon found on chrome in the menu bar for settings-->
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.html" class="navbar-brand">LPX</a>
</div>
<!-- MENU ITEMS-->
<div class="collaspe navbar-collaspe" id="mainnavbar">
<ul class="nav navbar-nav">
<li class="active"><a href="dashboard.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
<!-- right align menu item for login and sign uo buttons-->
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">My Profile <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="dashboard/dashboard.html">Dashboard</a></li>
<li><a href="search.html">Database</a></li>
<li><a href="#">Log Out</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div class="dropdown" id="dropdownbutton">
<button class="btn btn-link dropdown-toggle pull-right" type="button" data-toggle="dropdown">Saved Order Gudes
<span class="caret"></span></button>
<ul class="dropdown-menu pull-right" id="dropdownmenu">
</ul>
</div>
<div class="container">
<h4>Current order <span><h1 id="cartnote">To ensure the highest procurement possible, If you make a mistake, Please cancel your order and start again. Another option is to contact your Suppliers and let them know that you made user error. </h1></span></h4>
<br />
<div id="table">
<table id="order-table" class="table" data-row-style="rowStyle">
<thead>
<tr>
<th data-field="state" data-checkbox="true"></th>
<th data-field="name">Item</th>
<th data-field="brand">Brand</th>
<th data-field="amount">Amount</th>
<th data-field="size">Size</th>
<th data-field="pack">Pack</th>
</tr>
</thead>
</table>
</div>
<input type="button" class="btn btn-primary pull-right" onclick="ShowSalesRepInfo()" value="Prepare Order">
<input type="button" class="btn btn-warning " value="Back to Search" name="backtosearch" onclick="BacktoSearch()">
<input type="button" class="btn btn-danger " value="Cancel Order" name="cancelorder" onclick="CancelOrder()">
<input type="button" class="btn btn-warning " value="Save Order Guide" name="saveorderguide" onclick="SaveOrderGuude()">
</div>
<br />
<div id="formarea">
<form>
<fieldset>
<legend>Sales rep info<span><input type="button" class="btn btn-danger btn-sm pull-right" value="Close" name="submitorder" id="close" onclick="CloseSellerPane()"></span></legend>
<input type="text" class="form-control" placeholder="Please enter the email address of the seller you would like to send the order to" id="addemail"/>
<br />
<h4 class="center">Please select and confrim suppliers</h4>
<br />
<select multiple="multiple" class="form-control" id="select">
</select>
<br />
<input type="button" class="btn btn-success btn-sm " value="Submit Order" name="submitorder" id="submitbutton" onclick="CreateOrder()">
</fieldset>
</form>
</div>
<script type="text/javascript">
$("#formarea").toggle();
Parse.initialize("bmobCoB17mgSf7S9J6ZntiQGq5NEm2eIyHroyP9t", "Wut80Nd7rKFVvHEvT7K9jQMCV2HIO67OEH0pWaBe");
Parse.serverURL = 'https://rayfoodapp.herokuapp.com/parse'
poplatedropdown();
var saveditemsarray = []
var sellersarray = [];
var currentuser = Parse.User.current();
var isfurfilled = false;
var amountnum;
var itemfromproductpage = JSON.parse(localStorage.getItem("Item"))
console.log(itemfromproductpage)
// this is the table we are going to fill
var tablejson = new Object();
tablejson.items = []
// this code is ran when there is something in the cart
if (localStorage.getItem("SavedCart") != null)
{
var savedcart = JSON.parse(localStorage.getItem("SavedCart"))
console.log(savedcart)
for(var i = 0; i < savedcart.length; i++)
{
var item = savedcart[i].name;
var brand = savedcart[i].brand;
var pack = savedcart[i].pack
var size = savedcart[i].size
var amount = '<input type="number" id="quanity" class="form-control text-center" value=1 name="amount">'
console.log(amountnum)
saveditemsarray.push({name: item, brand:brand, amount:amount,pack: pack, size: size})
tablejson.items.push({name: item, brand:brand, amount:amount,pack: pack, size: size});
}
}
// puts new item in the cart
for(var i = 0; i < itemfromproductpage.length; i++)
{
var item = itemfromproductpage[i].item;
var brand = itemfromproductpage[i].brand
var pack = itemfromproductpage[i].pack
var size = itemfromproductpage[i].size
var amount = '<input type="number" id="quanity" class="form-control text-center" value="1" name="amount">'
$("#quanity").each(function() {
amountnum = this.value;
console.log(amountnum)
});
saveditemsarray.push({name: item, brand:brand, amount:amount,pack: pack, size: size})
tablejson.items.push({name: item, brand:brand, amount:amount,pack: pack, size: size});
}
$('#order-table').bootstrapTable({
data: tablejson.items
});
console.log(tablejson.items)
console.log(saveditemsarray)
function BacktoSearch()
{
localStorage.setItem("SavedCart", JSON.stringify(saveditemsarray))
window.location.href = "search.html"
localStorage.removeItem("selectedItem")
}
function ShowSalesRepInfo()
{
console.log(saveditemsarray)
$("#formarea").toggle();
//console.log(currentuser.id)
// get sellers
var index = 0;
var Loggedin = Parse.User.current();
var users = Parse.Object.extend("_User")
var query = new Parse.Query(users);
query.get(currentuser.id, {
success: function(results) {
console.log(results)
var sellers = results.get("salesreps")
console.log(sellers)
var selecttag = document.getElementById("select")
for(seller in sellers)
{
var option = document.createElement("option")
option.value = index
option.innerHTML = sellers[seller]
selecttag.appendChild(option)
index++
}
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
}
function CreateOrder()
{
console.log(saveditemsarray)
var values = [];
$("input[name='amount']").each(function() {
values.push($(this).val());
});
console.log(values)
var table = $('#order-table')
var sellersarray = []
var data = table.bootstrapTable('getAllSelections')
console.log(data)
//finalorder.push({json: data})
//console.log(finalorder)
var order = Parse.Object.extend("Order");
var orderobj = new order();
console.log(currentuser);
var select = document.getElementById("select")
for (var i = 0; i < select.options.length; i++) {
if(select.options[i].selected ==true){
console.log(select.options[i].innerHTML);
sellersarray.push(select.options[i].innerHTML)
}
}
var addemailvalue = document.getElementById("addemail").value
if (addemailvalue.length != 0)
{
console.log("text has changed")
console.log(addemailvalue)
sellersarray.push(addemailvalue)
console.log(sellersarray)
}
for(var j = 0; j < saveditemsarray.length; j++)
{
saveditemsarray[j].amount = values[j]
}
orderobj.set("order", saveditemsarray)
orderobj.set("submitedbyusername", currentuser.get("username"))
orderobj.set("selectedsellers", sellersarray)
orderobj.set("isfurfilled", isfurfilled)
orderobj.set("returnemail", currentuser.get("email"))
orderobj.save(null, {
success: function(submiitedorder) {
// create unique link
alert('Your order has been submitted ' + submiitedorder.id);
SendEmail(sellersarray, submiitedorder);
localStorage.removeItem("SavedCart")
localStorage.removeItem("Item")
localStorage.removeItem("selectedItem")
//window.location.href = "dashboard.html"
},
error: function(submiitedorder, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
alert('Failed to create new object, with error code: ' + error.message);
}
});
}
function CancelOrder()
{
orderarray = [];
localStorage.removeItem("currentcart");
BacktoSearch();
itemidsarray = []
localStorage.removeItem("jsonitems")
returnedjson.items = []
localStorage.removeItem("selectedItem")
localStorage.removeItem("selectedsupplier")
localStorage.removeItem("SavedCart")
localStorage,removeItem("Item")
index = 0
userdata = []
}
function SendEmail(array, pobject)
{
console.log("the sellers are " + array)
// loop through sellers arrays
for (object in array)
{
var email = new mandrill.Mandrill('TMc9w9HepAG7nUI1amdO3g'); // This will be public
var params = {
"template_name": "LPXCart",
"template_content": [
{
"name": "test",
"content": "testing"
}
],
"message": {
"from_email":"orders@lpxco.com",
"to":[{"email":array[object], "name": "Confidental"}],
"subject": "LPX order " + pobject.id + " needs to be furfilled " ,
"text": "Hello, your LPX order number " + pobject.id + " has been furfilled " + " please check out the dashboard to see pricing"
}
};
email.messages.sendTemplate(params, function(res) {
log(res);
}, function(err) {
log(err);
});
}
}
function SaveOrderGuude()
{
console.log(saveditemsarray)
var SavedOrederGuide = Parse.Object.extend("OrderGuides");
var orderguide = new SavedOrederGuide();
var retVal = prompt("Give your order guide a name ", "your name here");
orderguide.set("orderguidedata", JSON.stringify(saveditemsarray));
orderguide.set("name", retVal)
orderguide.set("user", currentuser.get("username"))
orderguide.save(null, {
success: function(gameScore) {
// Execute any logic that should take place after the object is saved.
alert('Your Order Guide was saved.' + orderguide.id);
},
error: function(gameScore, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
alert('Error Saving Order Guide.' + error.message);
}
});
}
// poplates drop down
function poplatedropdown()
{
var loggedinuser = Parse.User.current();
console.log(loggedinuser)
var Orderguide = Parse.Object.extend("OrderGuides");
var query = new Parse.Query(Orderguide);
query.equalTo("user", loggedinuser.get("username"));
query.find({
success: function(results) {
// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
var object = results[i];
var dropdownmenu = document.getElementById("dropdownmenu")
var li = document.createElement("li")
//li.innerHTML = results[i].id
var atag = document.createElement("a")
atag.href = "#"
atag.innerHTML = object.get("name")
li.appendChild(atag)
dropdownmenu.appendChild(li)
}
// click event
$("#dropdownmenu a").click(function() {
var orderguidename = this.innerHTML;
var ordergudes = Parse.Object.extend("OrderGuides");
var query = new Parse.Query(ordergudes);
query.equalTo("name", orderguidename);
query.equalTo("user", loggedinuser.get("username"))
query.find({
success: function(results) {
alert("Successfully retrieved " + results.length);
// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
var object = results[i];
console.log(object.get("orderguidedata"))
var jsondata = object.get("orderguidedata")
var formattedjson = JSON.parse(jsondata)
console.log(formattedjson)
for(var j = 0; j < formattedjson.length; j++)
{
var amounthtml = $(formattedjson[j].amount)
var amountvalue = amounthtml.val();
console.log(amountvalue)
tablejson.items.push({name: formattedjson[j].name, brand: formattedjson[j].brand, amount: amountvalue, size: formattedjson[j].size, pack: formattedjson[j].pack})
saveditemsarray.push({name: formattedjson[j].name, brand:formattedjson[j].brand, amount:amountvalue, size: formattedjson[j].size, pack: formattedjson[j].pack})
}
$('#order-table').bootstrapTable({
data: tablejson.items
});
}
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
})
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
}
</script>
</body>
</html>