webglade

JavaScript library to dynamically create XUL GUI from Glade XML files
git clone https://logand.com/git/webglade.git/
Log | Files | Refs | README | LICENSE

ProductLine.js (3689B)


      1 /**
      2  *
      3  *
      4  * @filename ProductLine.js
      5  * @$LastChangedDate: 2004-07-04 19:24:15 +0200 (Sun, 04 Jul 2004) $
      6  * @author Fabio Serra AKA Faser - faser@faser.net
      7  * @copyright Fabio Serra (The Initial Developer of the Original Code)
      8  * @license Mozilla Public License Version 1.1
      9 *
     10 */
     11 
     12 /**
     13  * Construct a new ProductLine object
     14  * @class This class store available Amazon catalogs and related search and sort type
     15  * because for each country Amazon has a little different catalogs (mode) with related
     16  * sort and search types.
     17  * @constructor
     18  * @return A new ProductLine object
     19  *
     20 */
     21 
     22 function ProductLine() {
     23 	this.catalog = {};
     24 }
     25 
     26 
     27 /**
     28  * Add a Catalog with the associate mode parameter and the list of valid search type
     29  * @param {string} key
     30  * @param {string} value
     31 */
     32 ProductLine.prototype.addCatalog = function(key,value) {
     33 	this.catalog[key] = new Array(3);
     34 	//Mode parameter
     35 	this.catalog[key][0] = value;
     36 	//Array of valid search type
     37 	this.catalog[key][1] = "";
     38 	//Properties of valid sort type
     39 	this.catalog[key][2] = {};
     40 }
     41 
     42 /**
     43  * @param {string} key
     44  * @return the catalog value
     45  * @type string
     46 */
     47 ProductLine.prototype.getCatalogValue = function(key) {
     48 	if(typeof this.catalog[key] == "undefined") {
     49 		return false
     50 	}else{
     51 		return this.catalog[key][0];
     52 	}
     53 }
     54 
     55 /**
     56  * Add a search type to a catalog
     57  * @param {string} catalogKey
     58  * @param {string} listSearchType
     59  * @throw catalogKey not valid
     60 */
     61 ProductLine.prototype.addSearchType = function(catalogKey,listSearchType) {
     62 	if (typeof this.catalog[catalogKey] == "undefined") {
     63 		throw("catalogKey not valid");
     64 	}
     65 	this.catalog[catalogKey][1] = listSearchType.split(',');
     66 }
     67 
     68 /**
     69  * Add sort type related a catalog
     70  * @param {string} catalogKey
     71  * @param {string} sortKey
     72  * @param {string} sortValue
     73  * @throw catalogKey not valid
     74 */
     75 ProductLine.prototype.addSort = function(catalogKey,sortKey,sortValue) {
     76 	if (typeof this.catalog[catalogKey] == "undefined") {
     77 		throw("catalogKey not valid");
     78 	}
     79 	this.catalog[catalogKey][2][sortKey] = sortValue;
     80 }
     81 
     82 /**
     83  * @param {string} catalogKey
     84  * @param {string} sortKey
     85 */
     86 ProductLine.prototype.getSortValue = function(catalogKey,sortKey) {
     87 	return this.catalog[catalogKey][2][sortKey];
     88 }
     89 
     90 /**
     91  * Check if the catalog has been added to the object
     92  * @param {string} catalogKey
     93 */
     94 ProductLine.prototype.isValidProductLine = function(catalogKey) {
     95 	var key = catalogKey;
     96 	if(typeof this.catalog[key] != "undefined") {
     97 		return true;
     98 	}else{
     99 		return false;
    100 	}
    101 }
    102 
    103 /**
    104  * Check if the search type is valid for the selected catalog
    105  * @param {string} catalogKey
    106  * @param {string} searchType
    107  * @type bool
    108 */
    109 ProductLine.prototype.isValidSearchType = function(catalogKey, searchType) {
    110 	//Check catalog
    111 	if (typeof this.catalog[catalogKey] == "undefined") {
    112 		return false;
    113 	}
    114 
    115 	//Verify searchType
    116 	for(var i=0;i<this.catalog[catalogKey][1].length;i++) {
    117 		if(this.catalog[catalogKey][1][i] == searchType) return true;
    118 	}
    119 	return false;
    120 }
    121 
    122 /**
    123  * Check if the sort type is valid for the selected catalog
    124  * @param {string} catalogKey
    125  * @param {string} sort
    126  * @type bool
    127 */
    128 ProductLine.prototype.isValidSort = function(catalogKey,sort) {
    129 	//Check catalog
    130 	if (typeof this.catalog[catalogKey] == "undefined") {
    131 		return false;
    132 	} else {
    133 		return this.propertyExist(this.catalog[catalogKey][2],sort);
    134 	}
    135 }
    136 
    137 /**
    138  * Verify if an object have a property
    139  * @param {Object} obj
    140  * @param {string} prop
    141  * @type bool
    142 */
    143 ProductLine.prototype.propertyExist = function(obj,prop) {
    144 	for (var i in obj) {
    145 		if(i == prop) return true;
    146 	}
    147 	return false;
    148 }