Subversion Repositories munaweb

Rev

Rev 30 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
function findProductInfo(IDValue) {
2
	// Construct the findProduct request
3
	url = configeBayShopping;
4
	url += "?callname=FindProducts";
5
	url += "&responseencoding=JSON";
6
	url += "&appid=" + configAppid;
7
	url += "&version=1061";
8
	url += "&siteid=0";
9
	url += "&AvailableItemsOnly=true";
10
	url += "&MaxEntries=1";
11
	url += "&ProductID.Type=Reference";
12
	url += "&ProductID.Value=";
13
	url += IDValue;
14
 
15
	// Submit the request
16
	var xhttp = new XMLHttpRequest();
17
 
18
	xhttp.onreadystatechange = function() {
19
    	if (this.readyState == 4) {
20
    		_cb_FindProducts(JSON.parse(this.responseText));
21
        }
22
    };
23
 
24
	xhttp.open("GET", configProxyUrl, true);
25
	xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
26
   	xhttp.send();
27
}
28
 
29
// Create new page for product info
30
function _cb_FindProducts(root) {
31
	var ack = root.Ack;
32
	if (ack != 'Success') {
33
		var x = document.getElementById("warnings");
34
		x.innerHTML = "<h2>eBAy API Error<h2>";
35
		x.innerHTML += "<p>Id: " + root.Errors[0].ErrorCode + "<br/>";
36
		x.innerHTML += "<p>Domain: " + root.Errors[0].ErrorClassification + "<br/>";
37
		x.innerHTML += "<p>Severity: " + root.Errors[0].SeverityCode + "<br/>";
38
		x.innerHTML += "<p>Category: " + root.Errors[0].category + "<br/>";
39
		x.innerHTML += "<p>Short Message: " + root.Errors[0].ShortMessage + "<br/>";
40
		x.innerHTML += "<p>Long Message: " + root.Errors[0].LongMessage + "<br/>";
41
		x.innerHTML += "<p>Build/Version: " + root.Build + '/' + root.Version + "</p>";
42
		x.innerHTML += "<p>URL: " + "<a href=\"" + url + "\" target=\"_blank\">" + url + "</a>" + "</p>";
43
 
44
		if (x.className.indexOf("w3-show") == -1) {
45
			x.className += " w3-show";
46
		}
47
 
48
		if (ack == 'Failure' || ack == 'PartialFailure') {
49
			x.scrollIntoView(true);
50
			return;
51
		}
52
	}
53
 
54
	var str = "";
55
	var i = 0;
56
 
57
	var JsonObj = typeof root.Product != 'object' ? JSON.parse(root.Product) : root.Product;
58
	var Title = JsonObj[0].Title;
59
 
60
	str = '<!DOCTYPE html>';
61
	str += '<html lang="en">';
62
	str += '<head>';
63
	str += '<title>' + Title + '</title>';
64
	str += '<meta charset="UTF-8">';
65
	str += '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
66
	str += '<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">';
67
	str += '<link rel="icon" href="favicon.ico" type="image/x-icon">';
68
	str += '<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">';
69
	str += '<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">';
70
	str += '<link rel="stylesheet" href="css/style.css">';
71
	str += '<style>.w3-table td,.w3-table th{padding: 0 10px 0 10px;display:table-cell;text-align:left;vertical-align:top}</style>';
72
	str += '</head>';
73
	str += '<body>';
74
	str += '<div class="w3-main">';
75
	str += '<div class="w3-container w3-padding w3-margin w3-card-4">';
76
	str += '<img class="w3-image w3-right" src="images/MUNA%20-%20Logo%20100x100.png" alt="MUNA Trading Logo" style="height:100px">';
77
	str += '<p class="w3-xlarge">' + Title + '</p>';
78
	str += '</div>';
79
 
80
	str += '<div class="w3-container w3-padding w3-margin w3-card-4">';
81
	str += '<div class="w3-cell-row">';
82
	str += '<div class="w3-container w3-card-2 w3-cell w3-padding">';
83
 
84
	str += '<h2>Detailed Product Information</h2>';
85
 
86
	if (JsonObj[0].StockPhotoURL) {
87
		str += '<a href="' + JsonObj[0].DetailsURL + '" target="_blank">';
88
		str += '<img src="' + JsonObj[0].StockPhotoURL + '">';
89
		str += '</a>';
90
	}
91
 
92
	if (JsonObj[0].ItemSpecifics) {
93
		str += '<p>';
94
		for (i = 0; i < JsonObj[0].ItemSpecifics.NameValueList.length; i++) {
95
			str += JsonObj[0].ItemSpecifics.NameValueList[i].Name + ': ' + JsonObj[0].ItemSpecifics.NameValueList[i].Value + '<br/>';
96
		}
97
		str += '</p>';
98
	}
99
 
100
	if (JsonObj[0].ProductID) {
101
		str += '<p>';
102
		for (i = 0; i < JsonObj[0].ProductID.length; i++) {
103
			str += JsonObj[0].ProductID[i].Type + ': ' + JsonObj[0].ProductID[i].Value + '<br/>';
104
		}
105
		str += '</p>';
106
	}
107
 
108
	str += '</div>';
109
	str += '</div>';
110
	str += '</div>';
111
 
112
 
113
	str += '<footer class="w3-container w3-center w3-border-top w3-margin">';
114
	str += 'Copyright &#169; ' + new Date().getFullYear() + ' MUNA Trading. All rights reserved.';
115
	str += '</footer>';
116
	str += '</div>';
117
	str += '</body>';
118
	str += '</html>';
119
 
120
	var newWin = window.open("", Title);
121
	if (newWin) {
122
		newWin.document.open().write(str);
123
		newWin.document.close();
124
	}
125
}
126