jsm

net/sf/jsm/++jsmCore.js

Summary

No overview generated for 'net/sf/jsm/++jsmCore.js'


Class Summary
Jsm Singleton holding global variables and functions; do not instantiate; use the existing variable jsm

Method Summary
static void jsmEmptyFunction()
           an empty function doing nothing

/**
* Singleton holding global variables and functions; do not instantiate; use the existing variable jsm
* @class Singleton holding global variables and functions; do not instantiate; use the existing variable jsm
*/
function Jsm() {
	if (jsmSingletonAlreadyCreated) {throw new Error("JsmObject is a singleton: Use the global variable 'jsm'");}
	jsmSingletonAlreadyCreated=true;
	
	/** 
	 * should we resize (true if the mouse button is clicked)
	 * @private 
	 */
	this.resize=false;

	/** 
	 * which column to resize
	 * @private 
	 */
	this.resizeColumn=-1;

	/** 
	 * original width of the column
	 * @private 
	 */
	this.resizeOriginalWidth=-1;

	/** 
	 * x-position where we started the resize
	 * @private 
	 */
	this.resizeStartX=-1;			
};

/**
* Null or undefined
* @param The item to inspect
* @return {boolean} True if null or undefined
*/
Jsm.prototype.noud = function(item) {
	if (item == null || typeof item == 'undefined') {return true;} else {return false;}
}	

/**
* Trims string left and right
* @param {String} theString The string to trim
* @return {String} 
*/
Jsm.prototype.trim = function(theString) {
	if (typeof theString == 'string') {
		return theString.replace(/^\s+|\s+$/g, '');	
	} else {
		return theString;
	}
}	

/**
* Gets the index of an element in an array. -1 if not found
* @param theArray 
* @param obj
* @param fromIndex  
* @return {int}
*/
Jsm.prototype.arrayIndexOf = function(theArray, obj, fromIndex) {
	logger.debug("JsmCore: arrayIndexOf: theArray " + theArray + " - obj " + obj + " - fromIndex " + fromIndex);
    if (fromIndex == null) {
      fromIndex = 0;
   	} else if (fromIndex < 0) {
      fromIndex = Math.max(0, this.length + fromIndex);
    }
    for (var i=fromIndex; i<theArray.length; i++) {
      if (jsm.trim(theArray[i]) == obj) {
        return i;
      }
    }
    return -1;
}

/**
* Does the array contain this object
* @param theArray 
* @param obj
* @return {boolean}
*/
Jsm.prototype.arrayContains = function(theArray, obj) {
  return this.arrayIndexOf(theArray, obj) != -1;
}

/**
* Do the two arrays contain the same values?
* @param theArray 
* @param theOtherArray
* @return {boolean}
*/
Jsm.prototype.arrayOfSameValues = function(theArray, theOtherArray) {
	if (theArray.length != theOtherArray.length) { 
		logger.debug("JsmCore: arrayOfSameValues: The lengths of the two arrays does not match.");
		return false;
	}
	for (var idx=0;idx<theOtherArray.length;idx++) {
  		if (!this.arrayContains(theArray, jsm.trim(theOtherArray[idx]))) {
			logger.debug("JsmCore: arrayOfSameValues: Not element of firt array: " + jsm.trim(theOtherArray[idx]));  		
  			return false;
  		}
  	}
  	return true;
}


/** Opens a window in the center of the screen to display a message;
* @param {} message The message to display: can contain HTML-Tags
* @param {} width The widht; can be null; default: 400
* @param {} height The height; can be null; default: 170
* @param {} bgColor The background color of the window; can be null; default: #FFFFFF
*/
  Jsm.prototype.openMessageWindow = function(message, width, height, bgColor) {
  	myWidth=(width == null || typeof width == 'undefined')?"400":width;
  	myHeight=(height == null || typeof height == 'undefined')?"170":height;
  	myBgColor=(bgColor == null || typeof bgColor == 'undefined')?"#FFFFFF":bgColor;
  	myTop = screen.availHeight/2-myHeight/2;
  	myLeft = screen.availWidth/2-myWidth/2;
	myWindow = window.open("about:blank", "myXWindow", "top=" + myTop + ",left=" + myLeft + ",width=" + myWidth +",height=" + myHeight + ",dependent=yes,resizable=yes");  
  	myWindow.document.open();
  	myWindow.document.write('<html><head></head><body bgcolor="' + myBgColor + '">');
  	myWindow.document.write(message);  
	myWindow.document.write('</body></html>');  
  	myWindow.document.close();  
  }

/** On the specified table will remove all filters then iterate thru all form elements and create filters 
* for appropriate ones (based on a naming convention 'jsmFilter@[tableVariableName]@[columnIdx]')
* @param {String} tableVariableName The name of the variable holding the JsmTable
*/  
  Jsm.prototype.jsmApplyTableFilter = function (tableVariableName) {
	eval(tableVariableName + ".removeFilters();");
	var formElements = [];	
	var inputElements = document.getElementsByTagName("input");
	for (var idx=0; idx<inputElements.length;idx++) {formElements.push(inputElements[idx]);}
	var selectElements = document.getElementsByTagName("select");
	for (var idx=0;idx<selectElements.length;idx++) {formElements.push(selectElements[idx]);}	
	for (var elementIdx=0;elementIdx<formElements.length;elementIdx++) {
		var formElement = formElements[elementIdx];
		var name = formElement.name;
		var value;
		logger.trace("jsmApplyTableFilter: Found element of name: " + name);					
		if (name && name.indexOf("jsmFilter@" + tableVariableName) == 0) {
			//select boxes
			try {
				value = new Array();
				var options = formElement.options;
				for (var i=0;i<options.length;i++) {
					var option = options[i];
					if (option.selected) {
						if (option.value == '') {
							logger.debug("jsmApplyTableFilter: Value of selectbox is '' - Will skip");
							continue;
						}
						value.push(option.text);	
					}		
				}	
				//make sure that value is only an array if there are more options selected
				if (value.length==0) {value="";}										
				if (value.length==1) {value=value[0];}														
			} catch (e) {
				//text fields
				value = formElement.value;
			}			
			logger.debug("jsmApplyTableFilter: " + name + " - " + value);			
			var columnIdx = (name.lastIndexOf('@')==-1?'NaN':name.substr(name.lastIndexOf('@')+1));
			if (!isNaN(columnIdx)) {
				if (value != '') {
					var filterConfig = eval(tableVariableName + ".getFilterConfig(" + columnIdx + ");");
					var filter = filterConfig[1];
					if (filter.className == 'JsmRegExFilter') {
						if (typeof value == 'object') { // if it is an array
							for (var arrayIndex=0;arrayIndex<value.length;arrayIndex++) {
								value[arrayIndex] = ".*" + value[arrayIndex] + ".*";
							}
						} else {
							value = ".*" + value + ".*";
						}
					}			
					logger.debug("jsmApplyTableFilter: Add filter on column " + columnIdx + " with value: " + value + " using filter: " + filter);
					myTable.addFilter(filter.clone().setColumn(columnIdx).setValue(value));			  	
				}
			} else {
				logger.error('jsmApplyTableFilter: Could not extract columnIdx from value: ' + value);
			}				
		}
	}	
	eval(tableVariableName + ".render();");	
 }

/** Resets values on filter elements for specified table
* @param {String} tableVariableName The name of the variable holding the JsmTable
*/  
  Jsm.prototype.jsmResetTableFilter = function (tableVariableName) {
	var formElements = [];	
	var inputElements = document.getElementsByTagName("input");
	for (var idx=0;idx<inputElements.length;idx++) {formElements.push(inputElements[idx]);}
	var selectElements = document.getElementsByTagName("select");
	for (var idx=0;idx<selectElements.length;idx++) {formElements.push(selectElements[idx]);}	
	for (var elementIdx=0;elementIdx<formElements.length;elementIdx++) {
		var formElement = formElements[elementIdx];
		var name = formElement.name;
		logger.trace("jsmResetTableFilter: Found element of name: " + name);					
		if (name && name.indexOf("jsmFilter@" + tableVariableName) == 0) {
			try {				
				formElement.value ='';
				if (formElement.multiple) {//deselect everything from a multi-selectbox
					formElement.selectedIndex=-1;								
				} else { // select first item on single-selectbox
					formElement.selectedIndex=0;								
				}								
			} catch (ignored) {}									
		}
	}	
	this.jsmApplyTableFilter(tableVariableName);
 }

var jsmSingletonAlreadyCreated = false;		
var jsm = new Jsm();

/** an empty function doing nothing */
function jsmEmptyFunction() {};

/**
* Adds inheritance
* @param superClass The class to inherit from
*/
Function.prototype.extendClass = function(superClass) {
	var f = new Function;
	f.prototype = superClass.prototype;
	this.prototype = new f;	
	this.prototype.constructor = this;
};

jsm

Documentation generated by JSDoc on Tue Sep 26 08:42:57 2006