-
Notifications
You must be signed in to change notification settings - Fork 0
/
newProduct.html
245 lines (220 loc) · 12.7 KB
/
newProduct.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>New Product</title>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Custom fonts for this template -->
<!--
<link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
-->
<!-- Plugin CSS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="css/main.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" href="js/bootstrap.min.css">
<script src="js/web3.min.js"></script>
<script src="js/truffle-contract.js"></script>
<script src="js/app.js"></script>
</head>
<body>
<style type="text/css">
.bs-example{
margin-top: 0;
margin: 20px;
}
</style>
<div class="container">
<!--
<div class="row">
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" onclick="this.parentNode.parentNode.removeChild(this.parentNode);" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<strong><i class="fa fa-warning"></i> Warning!</strong> <marquee><p style="font-family: Impact; font-size: 18pt">YOU MUST HAVE AN ACCOUNT (MANUFACTURER) TO REGISTER A NEW PRODUCT !</p></marquee>
</div>
</div>
-->
</div>
<div class="bs-example">
<nav class="navbar navbar-default">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a href="http://127.0.0.1:3000/index.html" class="navbar-brand">EWASTE MANAGEMENT</a>
</div>
<!-- Collection of nav links and other content for toggling -->
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<!--<li><a href="http://127.0.0.1:3000/newProduct.html">Register Product</a></li>-->
<div id="logged" class="nav navbar-nav navbar-right">
<li ><a href="http://127.0.0.1:3000/products.html">Products Owned</a></li>
<!--<li ><a href="http://127.0.0.1:3000/traceProduct.html">Trace Product</a></li>-->
<li ><a href="http://127.0.0.1:3000/transferProduct.html">Transfer Product</a></li>
<li ><a href="http://127.0.0.1:3000/index.html">Logout</a></li>
</div>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
<!-- <ul class="nav navbar-nav navbar-right">
<li><a href="http://127.0.0.1:3000/login">Login</a></li>
<li><a href="http://127.0.0.1:3000/account">Sign Up</a></li>
</ul>-->
</div>
</nav>
</div>
<div class="container">
<script>
console.log(sessionStorage.getItem("address"));
if(sessionStorage.getItem("usertype")=="Manufacturer"){
$('#logged').show();
}
else
$('#logged').hide();
</script>
<h1 class="text-center"></h1>
<div id="signupbox" style="margin-top:50px" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">Product Registration</div>
</div>
<div class="panel-body" >
<form id="signupform" class="form-horizontal" role="form">
<div id="signupalert">
</div>
<span id="insTrans" ></span>
<!--<div class="form-group">
<label class="col-md-3 control-label">Account ID</label>
<div class="col-md-9">
<input type="text" class="form-control" name="uid" id="u_id" placeholder="Account number" required>
</div>
</div>-->
<div class="form-group">
<label class="col-md-3 control-label">Product Name</label>
<div class="col-md-9">
<input type="text" class="form-control" id="product_name" name="pname" placeholder="Enter product name" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product Cost</label>
<div class="col-md-9">
<input type="text" class="form-control" id="p_cost" name="pcost" placeholder="Enter product cost" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product Specifications</label>
<div class="col-md-9">
<textarea class="form-control" id="specs" rows="3"></textarea> </div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Product Type</label>
<div class="col-md-9">
<input type="text" class="form-control" id="type" name="type" placeholder="Enter product type" required> </div>
</div>
<div class="form-group">
<!-- Button -->
<div class="col-md-offset-3 col-md-9">
<button id="btnnew" type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal"><i class="icon-hand-right"></i>   Register Product</button>
</div>
</div>
</form>
</div>
</div>
<!--<h1 id="response"></h1>
<ul id="data">
<li id="productName"></li>
<li id="productCost"></li>
<li id="productSpecs"></li>
<li id="productDesc"></li>
<li id="productOwner"></li>
<li id="ManufactureDate"></li>
</ul>-->
<!--
<script>
$(document).ready(function(){
$('#data').hide();
$('#btnnew').click(function (event){
event.preventDefault();
$.ajax({
type: 'POST',
url:"http://127.0.0.1:3000/newProduct",
headers: {
"content-type":"application/x-www-form-urlencoded"
},
data: {
"uid":$('#u_id').val(),
"prdt_name":$('#product_name').val(),
"prdt_cost":$('#p_cost').val(),
"prdt_specs":$('#specs').val(),
"prdt_desc":$('#desp').val(),
},
success: function (data){
console.log("data: ", data);
if(data != "Invalid User"){
$('#response').html('<p>Your product is registered and its ID id </p> <strong>'+data[0]+' </strong>');
$('#productName').html('<p>Your product name </p> <strong>'+data[1]+'</strong>');
$('#productCost').html('<p>Your product cost </p> <strong>'+data[2]+'</strong>');
$('#productSpecs').html('<p>Your product specifications </p> <strong>'+data[3]+'</strong>');
$('#productDesc').html('<p>Your product is description </p> <strong>'+data[4]+'</strong>');
$('#productOwner').html('<p>Your Address </p> <strong>'+data[5]+'</strong>');
$('#ManufactureDate').html('<p>Product Registered on </p> <strong>'+data[6]+'</strong>');
$('#data').show();
}
alert(data);
//var number i=0;
// window.location.href = "/trace";
}
})
//console.log("Type: " , $('#myselect').val()+ " pass: " + $('#password').val() + " User: "+ $('#name').val() )
});
})
</script>
-->
<script>
var getaccount1;
web3.eth.getCoinbase(function(err, account) {
if (err === null) {
getaccount1 = account;
console.log("Your Account: " + account);
$("#btnnew").click(function() {
$("#signupalert").show();
console.log(sessionStorage.getItem("address")+$("#product_name").val()+$("#p_cost").val()+$("#specs").val()+$("#type").val())
ewaste.newProduct(getaccount1,$("#product_name").val(), $("#p_cost").val(),$("#specs").val(),$("#type").val(), (err, res) => {
if (err)
console.log('oh no');
else{
$("#signupalert").html('successfully added product');
console.log(res);
}
});
} );
var addprodEvent = ewaste.prodadded({},'latest');
addprodEvent.watch(function (err, result) {
if (!err) {
// if (result.blockHash != $("#instrans").html())
// $("#loader").hide();
$("#insTrans").show();
//$("#insTrans").html('Block hash: ' +result.blockHash);
console.log(web3.toAscii(result.args.name) + ' ' + web3.toAscii(result.args.pid));
$("#insTrans").html(web3.toAscii(result.args.name) + ' ' + web3.toAscii(result.args.pid) );
} else {
console.log("oh no");
//$("#loader").hide();
}
});
}
});
</script>
</body>
</html>