Subversion Repositories munaweb

Rev

Rev 68 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

function findProductInfo(IDValue) {
        // Construct the findProduct request
        url = configeBayShopping;
        url += "?callname=FindProducts";
        url += "&responseencoding=JSON";
        url += "&appid=" + configAppid;
        url += "&version=1061";
        url += "&siteid=0";
        url += "&AvailableItemsOnly=true";
        url += "&MaxEntries=1";
        url += "&ProductID.Type=Reference";
        url += "&ProductID.Value=";
        url += IDValue;

        // Submit the request 
        var xhttp = new XMLHttpRequest();

        xhttp.onreadystatechange = function() {
        if (this.readyState == 4) {
                _cb_FindProducts(JSON.parse(this.responseText));
        }
    };

        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
        xhttp.send();
}

// Create new page for product info
function _cb_FindProducts(root) {
        var ack = root.Ack;
        if (ack != 'Success') {
                var x = document.getElementById("warnings");
                x.innerHTML = "<h2>eBAy API Error<h2>";
                x.innerHTML += "<p>Id: " + root.Errors[0].ErrorCode + "<br/>";
                x.innerHTML += "<p>Domain: " + root.Errors[0].ErrorClassification + "<br/>";
                x.innerHTML += "<p>Severity: " + root.Errors[0].SeverityCode + "<br/>";
                x.innerHTML += "<p>Category: " + root.Errors[0].category + "<br/>";
                x.innerHTML += "<p>Short Message: " + root.Errors[0].ShortMessage + "<br/>";
                x.innerHTML += "<p>Long Message: " + root.Errors[0].LongMessage + "<br/>";
                x.innerHTML += "<p>Build/Version: " + root.Build + '/' + root.Version + "</p>";
                x.innerHTML += "<p>URL: " + "<a href=\"" + url + "\" target=\"_blank\">" + url + "</a>" + "</p>";

                if (x.className.indexOf("w3-show") == -1) {
                        x.className += " w3-show";
                }

                if (ack == 'Failure' || ack == 'PartialFailure') {
                        x.scrollIntoView(true);
                        return;
                }
        }

        var str = "";
        var i = 0;

        var JsonObj = typeof root.Product != 'object' ? JSON.parse(root.Product) : root.Product;
        var Title = JsonObj[0].Title;

        str = '<!DOCTYPE html>';
        str += '<html lang="en">';
        str += '<head>';
        str += '<title>' + Title + '</title>';
        str += '<meta charset="UTF-8">';
        str += '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
        str += '<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">';
        str += '<link rel="icon" href="favicon.ico" type="image/x-icon">';
        str += '<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">';
        str += '<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">';
        str += '<link rel="stylesheet" href="css/style.css">';
        str += '<style>.w3-table td,.w3-table th{padding: 0 10px 0 10px;display:table-cell;text-align:left;vertical-align:top}</style>';
        str += '</head>';
        str += '<body>';
        str += '<div class="w3-main">';
        str += '<div class="w3-container w3-padding w3-margin w3-card-4">';
        str += '<img class="w3-image w3-right" src="images/MUNA%20-%20Logo%20100x100.png" alt="MUNA Trading Logo" style="height:100px">';
        str += '<p class="w3-xlarge">' + Title + '</p>';
        str += '</div>';

        str += '<div class="w3-container w3-padding w3-margin w3-card-4">';
        str += '<div class="w3-cell-row">';
        str += '<div class="w3-container w3-card-2 w3-cell w3-padding">';

        str += '<h2>Detailed Product Information</h2>';
        
        if (JsonObj[0].StockPhotoURL) {
                str += '<a href="' + JsonObj[0].DetailsURL + '" target="_blank">';
                str += '<img src="' + JsonObj[0].StockPhotoURL + '">';
                str += '</a>';
        }
        
        if (JsonObj[0].ItemSpecifics) {
                str += '<p>';
                for (i = 0; i < JsonObj[0].ItemSpecifics.NameValueList.length; i++) {
                        str += JsonObj[0].ItemSpecifics.NameValueList[i].Name + ': ' + JsonObj[0].ItemSpecifics.NameValueList[i].Value + '<br/>';
                }
                str += '</p>';
        }

        if (JsonObj[0].ProductID) {
                str += '<p>';
                for (i = 0; i < JsonObj[0].ProductID.length; i++) {
                        str += JsonObj[0].ProductID[i].Type + ': ' + JsonObj[0].ProductID[i].Value + '<br/>';
                }
                str += '</p>';
        }

        str += '</div>';
        str += '</div>';
        str += '</div>';


        str += '<footer class="w3-container w3-center w3-border-top w3-margin">';
        str += 'Copyright &#169; ' + new Date().getFullYear() + ' MUNA Trading. All rights reserved.';
        str += '</footer>';
        str += '</div>';
        str += '</body>';
        str += '</html>';

        var newWin = window.open("", Title);
        if (newWin) {
                newWin.document.open().write(str);
                newWin.document.close();
        }
}