QueryStringBuilder.js (2643B)
1 /** 2 * 3 * Create a Query String from the current widget status 4 * 5 * Example of a KeywordSearch query: 6 * [Amazon URL]?t=[Associates ID goes here]&dev-t=[Developer Token goes here]&KeywordSearch=[subject keyword goes here]&mode=[product line goes here]&type=[lite or heavy]&page=[page # goes here]&f=xml 7 * 8 * @FileName: QueryStringBuilder.js 9 * @$LastChangedDate: 2004-07-04 22:42:15 +0200 (Sun, 04 Jul 2004) $ 10 * @Author: Fabio Serra AKA Faser - faser@faser.net 11 * @Copyright: Fabio Serra 12 * @Licenze: MPL 1.1 13 * 14 */ 15 16 function QueryStringBuilder(ProductLineController) { 17 this.myProductLineController = ProductLineController; 18 this.elSearchTerm = document.getElementById('find-text'); 19 20 this.query = trim(this.elSearchTerm.value); 21 this.locale = this.myProductLineController.getLocale(); 22 23 this.amazonURL = AWSURL[this.locale]; 24 this.t = ASSID[this.locale]; 25 //Catalog (Request Search) 26 this.catalog = this.myProductLineController.getCatalogValue(); 27 //Search Type 28 this.search = this.myProductLineController.getSearch(); 29 //Sort 30 this.sort = this.myProductLineController.getSortValue(); 31 } 32 33 QueryStringBuilder.prototype.createQueryString = function(pageStart,type) { 34 var qString = ""; 35 var page = pageStart; 36 var requestType = type; 37 38 if(this.query == "") { 39 alert("Please, insert a search term"); 40 this.elSearchTerm.focus(); 41 return false; 42 } 43 44 if(!this.catalog) { 45 alert("The selected catalog is invalid"); 46 this.myProductLineController.elCatalog.focus(); 47 return false; 48 } 49 50 if(!this.search) { 51 alert("The selected search type is invalid"); 52 this.myProductLineController.elSearch.focus(); 53 return false; 54 } 55 56 if(!this.sort) { 57 alert("The selected sort type is invalid"); 58 this.myProductLineController.elSort.focus(); 59 return false; 60 } 61 62 //Prepare Query String 63 qString += this.amazonURL + "?t=" + this.t + "&dev-t=" + DEVT; 64 65 66 //Blended search must be treated in a particular way 67 if(this.catalog == "blended") { 68 qString += "&BlendedSearch=" + this.query; 69 //Asin Search doesn't need mode 70 } else if (this.search == "AsinSearch") { 71 qString += "&AsinSearch=" + this.query; 72 } else { 73 qString += "&" + this.search + "=" + this.query + "&mode=" + this.catalog + "&sort=" + this.sort; 74 } 75 76 //Type (Lite or heavy) - page - format (xml) 77 qString += "&type="+ requestType + "&page=" + page + "&f=xml"; 78 79 if(this.locale != "us") { 80 qString += "&locale=" + this.locale; 81 } 82 83 //Jp Short term fix 84 if(this.locale == "jp") { 85 qString += '&__mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A'; 86 } 87 return encodeURI(trim(qString)); 88 } 89 90