Subversion Repositories munaweb

Rev

Rev 5 | Rev 10 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
<!DOCTYPE html>
2
<html lang="en">
3
 
4
<head>
5
    <title>eBay Listing Upload</title>
6
    <meta charset="UTF-8">
7
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
9
    <link rel="icon" href="favicon.ico" type="image/x-icon">
10
 
11
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
12
    <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
13
    <link rel="stylesheet" href="css/style.css">
14
    <script src="js/XMLWriter.js"></script>
15
    <script src="js/lodash.min.js"></script>
16
    <script src="js/XMLparse.js"></script>
17
    <script src="js/muna-tools.js"></script>
18
</head>
19
 
20
<body onload="return initConfig();">
21
    <div class="w3-main">
22
        <div class="w3-container w3-padding w3-margin w3-card-4">
23
            <div class="w3-container w3-gray" style="height:100px">
24
                <img class="w3-image" src="images/MUNA%20-%20Logo%20100x100.png" alt="MUNA Trading Logo" style="height:100px">
25
                <p id="connected" class="w3-xxlarge w3-right">eBay Listing Upload
26
                    <input id="login" type="button" class="w3-btn w3-large w3-green w3-margin w3-round-large w3-ripple w3-right w3-hide" onclick="eBayLogin();" value="Login" />
27
                </p>
28
            </div>
29
 
30
            <div class="w3-row">
31
                <div>
32
                    <form id="searchForm" class="w3-container w3-light-grey w3-padding w3-small">
33
                        <div class="w3-container w3-card-2 w3-cell w3-padding">
6 - 34
                            <input id="startButton" type="button" class="w3-btn w3-large w3-red w3-margin w3-round-large w3-ripple" onclick="uploadListings();" value="Start" />
35
                            <p id="numberOfListings" class="w3-right"></p>
2 - 36
                        </div>
37
                    </form>
38
                </div>
39
                <div id="progressBarDiv" class="w3-container w3-padding w3-margin w3-card-4 w3-hide">
40
                    <h2 id="progressBarHeader"></h2>
41
                    <div class="w3-light-grey">
42
                        <div id="progressBar" class="w3-container w3-green w3-center" style="width:0%">0%</div>
43
                    </div>
44
                </div>
45
                <div id="logging" class="w3-container w3-padding"></div>
46
                <div id="results" class="w3-container w3-padding w3-card-4 w3-hide"></div>
47
            </div>
48
        </div>
49
 
50
        <footer class="w3-container w3-center w3-border-top w3-margin">
51
            Copyright &#169; 2018 MUNA Trading. All rights reserved.
52
        </footer>
53
 
54
    </div>
55
 
56
    <script>
57
 
58
// Globals
59
var configGetRecommendations = true;
60
var xml = '';
61
var listItems = [];
62
 
63
// Initialize Configuration Variables
64
function initConfig() {
6 - 65
    var i;
66
    var j;
2 - 67
 
6 - 68
    eBayAuthToken = readCookie();
69
    if (eBayAuthToken.length > 0) {
70
        connected();
71
    }
2 - 72
 
6 - 73
    if (eBayAuthTokenFlag === false) {
74
        var x = document.getElementById("login");
75
        if (x.className.indexOf("w3-show") == -1) {
76
            x.className += " w3-show";
77
        }
78
    }
2 - 79
 
6 - 80
    var xhttp = new XMLHttpRequest();
81
    xhttp.onreadystatechange = function() {
82
        if (this.readyState == 4 && this.status == 200) {
83
            //window.alert(this.responseText);
2 - 84
 
6 - 85
            var parser = new DOMParser();
86
            var htmlDoc = parser.parseFromString(this.responseText, "text/html");
87
            var x = htmlDoc.getElementsByTagName("a");
2 - 88
 
6 - 89
            listItems = [];
2 - 90
 
6 - 91
            for (i = 0, j = 0; i < x.length; i++) {
92
                if (htmlDoc.getElementsByTagName("a")[i].innerHTML.endsWith(".xml")) {
93
                    var n = htmlDoc.getElementsByTagName("a")[i].innerHTML.lastIndexOf(".xml");
94
                    listItems[j] = htmlDoc.getElementsByTagName("a")[i].innerHTML.substr(0, n);
95
                    j++;
96
                }
97
            }
2 - 98
 
6 - 99
            document.getElementById('numberOfListings').innerHTML = j + ' Listing(s) Ready for eBay Upload';
100
        }
101
    };
2 - 102
 
6 - 103
    xhttp.open("GET", configListingUrl + '?t=' + Math.random(), true);
104
    xhttp.send();
2 - 105
}
106
 
107
function requireNewLogin() {
6 - 108
    // dummy
2 - 109
}
110
 
111
function uploadListings() {
6 - 112
    var i = 0;
2 - 113
 
6 - 114
    document.getElementById("logging").innerHTML = '';
115
    document.getElementById("results").innerHTML = '';
2 - 116
 
6 - 117
    initProgressBar('Uploading Listings');
2 - 118
 
6 - 119
    function for1() {
120
        updateProgressBar(listItems.length, i);
121
        uploadListing(listItems[i]);
122
        for2();
123
    }
2 - 124
 
6 - 125
    function for2() {
126
        if (i == listItems.length) {
127
            endProgressBar();
128
            return false;
129
        }
2 - 130
 
6 - 131
        setTimeout(function() {
132
            i++;
133
            document.getElementById("logging").innerHTML = 'Uploading No. ' + i + '/' + listItems.length;
134
            for1();
135
        }, 500);
136
    }
2 - 137
 
6 - 138
    for1();
2 - 139
}
140
 
141
function uploadListing(name) {
6 - 142
    var xhttp;
2 - 143
 
6 - 144
    xhttp = new XMLHttpRequest();
2 - 145
 
6 - 146
    xhttp.onreadystatechange = function() {
147
        if (this.readyState == 4 && this.status == 200) {
148
            //			verifyListing(name, xhttp.responseText);
149
            submitListing(name, xhttp.responseText);
150
        }
151
    };
2 - 152
 
6 - 153
    xhttp.open("GET", configListingUrl + name + '.xml', true);
154
    xhttp.send();
2 - 155
}
156
 
157
function verifyListing(name, itemXML) {
6 - 158
    var i;
159
    var authErrorFlag = false;
2 - 160
 
6 - 161
    if (eBayAuthTokenFlag === false) {
162
        return;
163
    }
2 - 164
 
6 - 165
    var xw = new XMLWriter('UTF-8', '1.0');
166
    var xhr = new XMLHttpRequest();
2 - 167
 
6 - 168
    createAddXML(xw, xhr, 'VerifyAddItemRequest', 'VerifyAddItem', itemXML);
2 - 169
 
6 - 170
    xml = xw.flush();
171
    xw.close();
2 - 172
 
6 - 173
    xhr.onload = function() {
174
        var obj = XMLparse(xhr.responseXML);
2 - 175
 
6 - 176
        var returnCode = obj.Ack;
2 - 177
 
6 - 178
        var x = document.getElementById("results");
179
        if (x.className.indexOf("w3-show") == -1) {
180
            x.className += " w3-show";
181
        }
2 - 182
 
6 - 183
        if (returnCode == 'Success' || (returnCode == 'Warning' && obj.Errors.ErrorCode == '21917108')) {
184
            x.innerHTML += '<p><strong>' + returnCode + ' (' + name + ')</strong></p>';
2 - 185
 
6 - 186
            if (returnCode == 'Warning') {
187
                x.innerHTML += "<p>" + obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "</p>";
188
            }
189
            var fees = getJsonArray(obj.Fees);
190
            x.innerHTML += "<p>";
191
            for (i = 0; i < fees.length; i++) {
192
                if (fees[i].Fee.text !== "0.0") {
193
                    x.innerHTML += fees[i].Name + ": $" + Number(fees[i].Fee.text).toFixed(2) + "<br/>";
194
                }
195
            }
196
            x.innerHTML += "</p>";
2 - 197
 
6 - 198
            if (obj.DiscountReason) {
199
                x.innerHTML += "<p>Discount Reason: " + obj.DiscountReason + "</p>";
200
            }
2 - 201
 
6 - 202
            var recommendations = getJsonArray(obj.ListingRecommendations);
203
            for (i = 0; i < recommendations.length; i++) {
204
                x.innerHTML += decode(recommendations[i]);
205
            }
206
        } else {
207
            x.innerHTML += '<p class="w3-red"><strong>' + returnCode + ' (' + name + ')</strong></p>';
2 - 208
 
6 - 209
            var errors = getJsonArray(obj.Errors);
210
            x.innerHTML += "<p>";
211
            for (i = 0; i < errors.length; i++) {
212
                x.innerHTML += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
213
                if (errors[i].LongMessage.includes('Auth')) {
214
                    authErrorFlag = true;
215
                }
216
            }
2 - 217
 
6 - 218
            x.innerHTML += "</p>";
2 - 219
 
6 - 220
            if (obj.DuplicateInvocationDetails) {
221
                x.innerHTML += '<p>Duplicate Invocation Id ' + obj.DuplicateInvocationDetails.DuplicateInvocationID + ' Tracking Id' + obj.DuplicateInvocationDetails.InvocationTrackingID + ' Status ' + obj.DuplicateInvocationDetails.Status + '</p>';
222
            }
2 - 223
 
6 - 224
            if (authErrorFlag === true) {
225
                eBayAuthTokenFlag = false;
226
                x = document.getElementById("login");
227
                if (x.className.indexOf("w3-show") == -1) {
228
                    x.className += " w3-show";
229
                }
230
            }
231
        }
2 - 232
 
6 - 233
        if (obj.Message) {
234
            x.innerHTML += obj.Message;
235
        }
236
    };
2 - 237
 
6 - 238
    xhr.send(xml);
2 - 239
}
240
 
241
function decode(recommendation) {
6 - 242
    var str = "<p>";
243
    var i;
2 - 244
 
6 - 245
    str += recommendation.Code + " (" + recommendation.Type + "/" + recommendation.Group + ") for '" + recommendation.FieldName;
246
    if (recommendation.Value) {
247
        str += "': " + recommendation.Value;
248
    }
2 - 249
 
6 - 250
    if (recommendation.Message) {
251
        str += "<br/>" + recommendation.Message;
252
    }
2 - 253
 
6 - 254
    var metadata = recommendation.Metadata;
255
    if (metadata) {
256
        if (metadata.length > 0) {
257
            for (i = 0; i < metadata.length; i++) {
258
                if (metadata[i].Name != "correlationId" &&
259
                    metadata[i].Name != "currency" &&
260
                    metadata[i].Name != "similarItems") {
261
                    str += "<br/>" + metadata[i].Name + " = " + metadata[i].Value;
262
                }
263
            }
264
        } else {
265
            if (metadata.Name != "correlationId" &&
266
                metadata.Name != "currency" &&
267
                metadata.Name != "similarItems") {
268
                str += "<br/>" + metadata.Name + " = " + metadata.Value;
269
            }
270
        }
271
    }
2 - 272
 
6 - 273
    str += "</p>";
2 - 274
 
6 - 275
    return str;
2 - 276
}
277
 
278
function submitListing(name, itemXML) {
6 - 279
    var i;
280
    var authErrorFlag = false;
2 - 281
 
6 - 282
    if (document.getElementById("startButton").className.indexOf("w3-green") == -1) {
283
        return;
284
    }
2 - 285
 
6 - 286
    var xw = new XMLWriter('UTF-8', '1.0');
287
    var xhr = new XMLHttpRequest();
2 - 288
 
6 - 289
    createAddXML(xw, xhr, 'AddItemRequest', 'AddItem', itemXML);
2 - 290
 
6 - 291
    xml = xw.flush();
292
    xw.close();
2 - 293
 
6 - 294
    xhr.onload = function() {
295
        var obj = XMLparse(xhr.responseXML);
2 - 296
 
6 - 297
        var returnCode = obj.Ack;
2 - 298
 
6 - 299
        var x = document.getElementById("results");
300
        if (x.className.indexOf("w3-show") == -1) {
301
            x.className += " w3-show";
302
        }
2 - 303
 
6 - 304
        if (returnCode == 'Success' || (returnCode == 'Warning' && obj.Errors.ErrorCode == '21917108')) {
305
            x.innerHTML += '<p><strong>' + returnCode + '</strong>, Item Id <a href="https://www.ebay.com/itm/' + obj.ItemID + '" target="_blank">' + obj.ItemID + '</a> (' + name + ')</p>';
306
            if (returnCode == 'Warning') {
307
                x.innerHTML += "<p>" + obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "</p>";
308
            }
2 - 309
 
6 - 310
            var fees = obj.Fees;
311
            x.innerHTML += "<p>";
312
            for (i = 0; i < fees.length; i++) {
313
                if (fees[i].Fee.text !== "0.0") {
314
                    x.innerHTML += fees[i].Name + ": $" + Number(fees[i].Fee.text).toFixed(2) + "<br/>";
315
                }
316
            }
317
            x.innerHTML += "</p>";
2 - 318
 
6 - 319
            if (obj.DiscountReason) {
320
                x.innerHTML += "<p>Discount Reason: " + obj.DiscountReason + "</p>";
321
            }
322
        } else {
323
            x.innerHTML += '<p class="w3-red"><strong>' + returnCode + ' (' + name + ')</strong></p>';
2 - 324
 
6 - 325
            var errors = getJsonArray(obj.Errors);
326
            x.innerHTML += "<p>";
327
            for (i = 0; i < errors.length; i++) {
328
                x.innerHTML += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
329
                if (errors[i].LongMessage.includes('Auth')) {
330
                    authErrorFlag = true;
331
                }
332
            }
333
            x.innerHTML += "</p>";
2 - 334
 
6 - 335
            if (obj.DuplicateInvocationDetails) {
336
                x.innerHTML += '<p>Duplicate Invocation Id ' + obj.DuplicateInvocationDetails.DuplicateInvocationID + ' Tracking Id' + obj.DuplicateInvocationDetails.InvocationTrackingID + ' Status ' + obj.DuplicateInvocationDetails.Status + '</p>';
337
            }
2 - 338
 
6 - 339
            if (authErrorFlag === true) {
340
                eBayAuthTokenFlag = false;
341
                x = document.getElementById("login");
342
                if (x.className.indexOf("w3-show") == -1) {
343
                    x.className += " w3-show";
344
                }
345
            }
346
        }
347
    };
2 - 348
 
6 - 349
    xhr.send(xml);
2 - 350
}
351
 
352
function createAddXML(xw, xhr, xmlrequest, callname, itemXML) {
6 - 353
    xw.writeStartDocument();
354
    xw.writeStartElement(xmlrequest);
355
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
2 - 356
 
6 - 357
    xw.writeStartElement('RequesterCredentials');
358
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
359
    xw.writeEndElement(); /* RequesterCredentials */
2 - 360
 
6 - 361
    xw.writeXML(itemXML);
2 - 362
 
6 - 363
    xw.writeElementString('ErrorLanguage', 'en_US');
364
    xw.writeElementString('Version', configeBayTradingVersion);
365
    xw.writeElementString('WarningLevel', configWarningLevel);
2 - 366
 
6 - 367
    xw.writeEndElement(); /* xmlrequest */
368
    xw.writeEndDocument();
2 - 369
 
6 - 370
    xhr.open('POST', configProxyUrl, true);
371
    xhr.setRequestHeader('Content-Type', 'text/xml');
372
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
373
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
374
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
375
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
376
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
377
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
378
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
2 - 379
}
380
 
381
function clearStatusWindows() {
6 - 382
    var x = document.getElementById("results");
383
    x.innerHTML = "";
384
    x.className = x.className.replace(" w3-show", "");
2 - 385
}
386
 
387
function connected() {
6 - 388
    var x;
2 - 389
 
6 - 390
    eBayAuthTokenFlag = true;
391
    document.getElementById("connected").innerHTML += " (Connected)";
2 - 392
 
6 - 393
    x = document.getElementById("startButton");
394
    x.className = x.className.replace(" w3-red", " w3-green");
2 - 395
 
6 - 396
    x = document.getElementById("login");
397
    x.className = x.className.replace(" w3-show", "");
2 - 398
}
399
 
400
    </script>
401
 
402
</body>
403
</html>