-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostbook.html
930 lines (401 loc) · 16.6 KB
/
postbook.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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>books2go</title>
<link rel="stylesheet" href="css/jquery.mobile-1.4.3.min.css" />
<link rel="stylesheet" href="css/styles.css" />
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery.mobile-1.4.3.min.js"></script>
<script src="js/main.js"></script>
<script>
</script>
<script id="panel-init">
$(function() {
$( "body>[data-role='panel']" ).panel();
});
</script>
<style>
#autocomplete1{margin-top:-8px !important}
</style>
</head>
<body >
<div id="postBookPage" data-role="page" >
<div data-role="header" data-position="fixed" data-theme="a" id="header"> <div data-role="navbar" id="head-buttons" data-iconpos="top"> </div> </div><!-- header -->
<div data-role="content" id="content"> <p id="info"></p> <div id="deviceready" class="blink" style="display:none"> <p class="event listening">Connecting to Device</p> <p class="event received">Device is Ready</p> </div>
<p class='logop'><img class='logo' src="images/logo3.png" alt="" /></p>
<div id="title" class="title">Post a textbook</div>
<div id="crumbdiv" style="display:none">
<ul id="crumb" data-role="listview" data-filter="false" data-inset="false" data-theme="a" >
<li><a class='ui-btn ui-btn-icon-left ui-icon-carat-l' href='javascript:ResetView()' data-ajax='false'>Post a textbook</a></li>
</ul>
</div>
<div id="search"> <a href="#" id="scan" class="ui-btn ui-icon-camera ui-btn-icon-left ui-corner-all">Scan a barcode</a> <p style="text-align:center">or</p>
<select id="ddlPostType" onchange="ChangeType()">
<option value="0">Post by ISBN</option>
<option value="1">Post by Title/Author</option>
</select>
<div id="type-isbn">
<form id="isbn-form">
<input type="text" placeholder="<enter isbn>" id="txt-isbn" maxlength="18" data-clear-btn="true" />
<button id="btnisbn" type="submit" style="background-color: #BCED91">Search</button>
</form>
<div class="title">What is an ISBN?</div>
<p>The International Standard Book Number (ISBN) is a 10 or 13-digit number that uniquely identifies books published internationally.</p>
<p>This number is generally found on the back cover of your textbook. It is the quickest way to list your books. Give it a try.</p>
<p style="text-align:center"><img src="http://www.books2go.ca/books/images/isbn.gif" /></p>
</div>
<div id="type-title" style="display:none">
<form id="title-form">
<input type="text" placeholder="<enter title>" id="txt-title" data-clear-btn="true" />
<input type="text" placeholder="<enter author>" id="txt-author" data-clear-btn="true" />
<button id="btntitle" type="submit" style="background-color: #BCED91">Search</button>
</form>
</div>
</div>
<div id="results-msg"></div>
<div id="results">
</div>
<div style="clear:both;height:20px"></div>
<div id="post" style="display:none;">
<form id="post-form">
<select id="ddlSchool"></select>
<input type="text" id="txt-course" data-type="search" placeholder="course" data-clear-btn="true" />
<ul id="autocomplete1" data-role="listview" data-inset="true" data-filter="true" data-input="#txt-course" style="display:block !important;list-style:none !important"></ul>
<input type="text" id="txt-course2" data-type="search" placeholder="course 2" data-clear-btn="true" />
<ul id="autocomplete2" data-role="listview" data-inset="true" data-filter="true" data-input="#txt-course2" style="display:block !important;list-style:none !important"></ul>
<input type="number" id="txt-price" placeholder="price" data-clear-btn="true" />
<textarea id="txt-desc" placeholder="description"></textarea>
<select id="ddlCondition">
<option value="0">Book condition</option>
<option value="1">Excellent</option>
<option value="2">Very Good</option>
<option value="3">Good</option>
<option value="4">Average</option>
<option value="5">Poor</option>
<option value="6">Very Poor</option>
<option value="7">Horrible</option>
</select>
<button type="submit" style="background-color: #BCED91">Post Textbook</button>
<button type="button" style="background-color: #FFDCDD" onclick='ResetView()'>Cancel</button>
</form>
</div>
<div id="err"></div>
</div>
<div data-role="popup" id="pop" data-overlay-theme="a" data-theme="a" data-dismissible="true" style="max-width:400px;font-size:12px">
<p id="err"></p>
</div>
<div data-role="panel" id="mypanel" data-theme="a" style='padding:0;margin:0;'>
<img src="images/logo3.png" width="100%" />
<div style="height:30px"></div>
<ul data-role="listview" id="menu">
<li><a href="javascript:GoHome()" data-rel="close" data-ajax="false">Home</a></li>
<li><a href="search.html" data-rel="close" data-ajax="false">Search</a></li>
<li id="uprofile" style="display:none" data-role="collapsible" data-iconpos="right" data-inset="false">
<h2>Profile</h2>
<ul data-role="listview" data-theme="a">
<li><a href="mybooks.html" data-rel="close" data-ajax="false"> - My books</a></li>
<li><a href="postbook.html" data-rel="close" data-ajax="false"> - Post a textbook</a></li>
<li><a href="inbox.html" data-rel="close" data-ajax="false"> - Inbox</a></li>
<li><a href="wishlist.html" data-rel="close" data-ajax="false"> - Wish list</a></li>
<li><a href="editprofile.html" data-rel="close" data-ajax="false"> - Edit profile</a></li>
<li><a href="editschools.html" data-rel="close" data-ajax="false"> - Edit schools</a></li>
<li><a href="changepassword.html" data-rel="close" data-ajax="false"> - Change password</a></li>
</ul>
</li>
<li style="display:none" id="logout"><a href="logout.html" data-rel="user" data-ajax="false">Log out</a></li>
<li style="display:none" id="login"><a href="login.html" data-rel="user" data-ajax="false">Log In</a></li>
</ul>
</div><!-- /panel -->
<script>
$(document).on('pagebeforecreate', '#postBookPage', function(){ LoadHeader();});
$(document).on("pagebeforeshow","#postBookPage",function(){ // When entering pagetwo
if(window.localStorage.getItem("user_id")){
if(window.localStorage.getItem("user_id") > 0){
$("#uprofile").show();
$("#logout").show();
$("#login").hide();
}
}else{
localStorage.clear();
window.location = "index.html";
} $( "#autocomplete1" ).on( "filterablebeforefilter", function ( e, data ) {
var $ul = $( this ),
$input = $( data.input ),
value = $input.val(),
html = "";
$ul.html( "" );
var sid = $("#ddlSchool").val();
if ( value && value.length > 1 ) {
$ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
$ul.listview( "refresh" );
$.ajax({
type: "POST",
url: "http://www.books2go.ca/mobiservice/get_autocomplete.php",
data: {'Q' : value, 'SID' : sid, 'CNUM' : '1'},
dataType: "json",
success: function(data) {
$("#autocomplete1").empty().append(data.result);
$("#autocomplete1").listview("refresh");
},
error: function(xhr, desc, err) {
showErrorMessage(xhr + " Details: " + desc + "\nError:" + err, $("#err"), 0);
}
})
}
});
$( "#autocomplete2" ).on( "filterablebeforefilter", function ( e, data ) {
var $ul = $( this ),
$input = $( data.input ),
value = $input.val(),
html = "";
$ul.html( "" );
var sid = $("#ddlSchool").val();
if ( value && value.length > 1 ) {
$ul.html( "<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>" );
$ul.listview( "refresh" );
$.ajax({
type: "POST",
url: "http://www.books2go.ca/mobiservice/get_autocomplete.php",
data: {'Q' : value, 'SID' : sid, 'CNUM' : '2'},
dataType: "json",
success: function(data) {
$("#autocomplete2").empty().append(data.result);
$("#autocomplete2").listview("refresh");
},
error: function(xhr, desc, err) {
showErrorMessage(xhr + " Details: " + desc + "\nError:" + err, $("#err"), 0);
}
})
}
});
GetInboxCount();
});
function SetCourse1(num,cnum){
if(cnum == '1'){
$("#txt-course").val(num);
$("#autocomplete1").empty();
$("#autocomplete1").listview("refresh");
}else{
$("#txt-course2").val(num);
$("#autocomplete2").empty();
$("#autocomplete2").listview("refresh");
}
}
function AddBook(id){
$(".book").hide();
$("#book" + id).show();
$("#search").hide();
$("#post").show();
$("#btnReset").show();
window.localStorage.setItem("ADDID",id);
$("#crumbdiv").show();
$("#title").hide();
$(".loadmore").hide();
$("#results-msg").hide();
$(".btnpost").hide();
}
function PostBook(){
var id = window.localStorage.getItem("ADDID");
var course = $("#txt-course").val();
var course2 = $("#txt-course2").val();
var schoolid = $("#ddlSchool").val();
var price = $("#txt-price").val();
var condition = $("#ddlCondition").val();
var UID = window.localStorage.getItem("user_id");
var email = window.localStorage.getItem("email");
var desc = $("#txt-desc").val();
if(id){
if(schoolid > 0 && price > 0 && condition > 0){
$.ajax({
type: "POST",
url: "http://www.books2go.ca/mobiservice/add_book.php?",
data: {'id' : id, 'course' : course, 'course2' : course2, 'schoolid' : schoolid, 'price' : price, 'condition' : condition, 'UID' : UID, 'email' : email, 'desc' : desc},
dataType: "json",
success: function(data) {
showErrorMessage("Your book has been posted!", $("#err"), 0);
window.location = "mybooks.html";
},
error: function(xhr, desc, err) {
showErrorMessage(xhr + " Details: " + desc + "\nError:" + err, $("#err"), 0);
}
});
}else{
showErrorMessage("Please ensure you have entered a school, book price, and book condition.", $("#err"), 0);
}
}
}
function PostISBN(page){
getisbn = $("#txt-isbn").val();
author = $("#txt-author").val();
title = $("#txt-title").val();
var UID = window.localStorage.getItem("user_id");
$("#btnisbn").html("Searching...");
$("#btntitle").html("Searching...");
$.ajax({
type: "POST",
url: "http://www.books2go.ca/mobiservice/get_newbook.php?search=new&wl=0",
data: {'getisbn' : getisbn, 'author' : author, 'title' : title, 'UID' : UID, 'page' : page},
dataType: "json",
success: function(data) {
if(data.error == ''){
if(data.count > 0){
$("#results-msg").html(data.count + " books found");
if(page > 1){
$("#p" + page).hide();
$("#results").append(data.result);
}else{
$("#results").html('');
$("#results").html(data.result);
}
SetWidth();
$("#ddlSchool").empty().append(data.schools);
$( "#ddlSchool" ).selectmenu( "refresh" );
if(data.single == 1){
$("#search").hide();
$("#post").show();
$("#btnReset").show();
window.localStorage.setItem("ADDID", $("#theid").html());
}
}else{ $("#results-msg").html("No books were found"); } ///
}else{
showErrorMessage(data.error, $("#err"), 0);
}
$("#btnisbn").html("Search");
$("#btntitle").html("Search");
},
error: function(xhr, desc, err) {
showErrorMessage(xhr + " Details: " + desc + "\nError:" + err, $("#err"), 0);
}
});
}
function LoadMore(page){
PostISBN(page);
$("#a" + page).html("Loading...");
}
function ChangeType(){
$("#txt-isbn").val('');
$("#txt-author").val('');
$("#txt-title").val('');
var sType = $("#ddlPostType").val();
if(sType == 0){
$("#type-isbn").show();
$("#type-title").hide();
}else{
$("#type-isbn").hide();
$("#type-title").show();
}
}
function SetWidth(){
var tw = $("#postBookPage").width();
var w = $("#postBookPage").width() - 190;
$(".info").css("width", w);
}
$('#isbn-form').submit(function (e) {
e.preventDefault();
PostISBN(1);
});
$('#title-form').submit(function (e) {
e.preventDefault();
PostISBN(1);
});
$('#post-form').submit(function (e) {
e.preventDefault();
PostBook();
});
function ResetView(){
$("#title").hide();
$(".book").show();
$(".btnpost").show();
$("#post").hide();
$("#search").show();
$("#btnReset").hide();
$("#crumbdiv").hide();
$(".loadmore").hide();
$("#btnisbn").html("Search");
$("#btntitle").html("Search");
$("#results-msg").show();
var id = window.localStorage.getItem("ADDID");
if(id){
$('html, body').animate({
scrollTop: $('#book' + id).offset().top - 50
});
}
}
</script>
</div><!-- /page -->
<script type="text/javascript" src="phonegap.js"></script><script type="text/javascript" src="barcodescanner.js"></script><script> var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // `load`, `deviceready`, `offline`, and `online`. bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); document.getElementById('scan').addEventListener('click', this.scan, false); //document.getElementById('encode').addEventListener('click', this.encode, false); }, // deviceready Event Handler // // The scope of `this` is the event. In order to call the `receivedEvent` // function, we must explicity call `app.receivedEvent(...);` onDeviceReady: function() { app.receivedEvent('deviceready'); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); }, scan: function() { var scanner = cordova.require("cordova/plugin/BarcodeScanner"); scanner.scan( function (result) { $("#txt-isbn").val(result.text); PostISBN(1); /* if (args.format == "QR_CODE") { window.plugins.childBrowser.showWebPage(args.text, { showLocationBar: false }); } */ }, function (error) { } ); }, encode: function() { var scanner = cordova.require("cordova/plugin/BarcodeScanner"); scanner.encode(scanner.Encode.TEXT_TYPE, "http://www.nhl.com", function(success) { }, function(fail) { } ); } }; </script><script> app.initialize();</script>
</body>
</html>