jsm

net/sf/jsm/jsmUtil.js

Summary

No overview generated for 'net/sf/jsm/jsmUtil.js'


Method Summary
static void jsmAddMessage(<Html> theHTML, <int> timeout, <boolean> warn)
           Will add a message to the page if an element with the id='jsmMessage' has been specified
static void jsmAppendMessage(<Html> theHTML, <int> timeout, <boolean> warn)
           Will append a message to the page if an element with the id='jsmMessage' has been specified
static void jsmClearMessage()
           Clear the messages off the page in element with the id='jsmMessage'
static void jsmCopySelectedOptions(<Node> fromSelectBox,<Node> toSelectBox)
           Move selected value from one selectbox to the other
static String jsmGetLabels(<Node> selectBox, <String> delimiter)
           Get a delimiter separated list of all the select box labels
static String jsmGetValues(<Node> selectBox)
           Get a JSON-Array style list of all the select box values, eg.
static void jsmHangOntoSelectedWidgetNodes(<Node> theNode)
           Stick all selected widget nodes into the global var jsmSelectedWidgetNodes
IE will set the checked and selected flags of a widget-node to false as soon as the node is appended to another node therefore I stick the checkbox-nodes and option-nodes which are selected into an array later for example the table.render()-method will make sure they get selected
static void jsmSelectWidgetNodes()
           Select all nodes contained in this array and remove nodes from the global var jsmSelectedWidgetNodes
static void pause(<int> milliSecs)
           Pause the java script execution - will take over all processor resources because it uses a while loop

function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    if (arguments.length == 1) 
      return element;
    elements.push(element);
  }
  return elements;
}

/** Move selected value from one selectbox to the other
* @param {Node} fromSelectBox
* @param {Node} toSelectBox
*/
function jsmCopySelectedOptions(fromSelectBox,toSelectBox){ 
	if (jsm.noud(fromSelectBox) || jsm.noud(toSelectBox)) {
		logger.error("jsmCopySelectedOptions: " + fromSelectBox + " - " + toSelectBox);
		return;
	}	
  	for (var i=0;i<fromSelectBox.options.length;i++){
	    var option = fromSelectBox.options[i];
	    if (option.selected){
		    toSelectBox.options[toSelectBox.length] = new Option(option.text,option.value);
      		fromSelectBox.options[i] = null;
      		i--;
    	}
  	}
}

/** Get a delimiter separated list of all the select box labels
* @param {Node} selectBox
* @param {String} delimiter Optional: defaults to comma
* @return {String} 
*/
function jsmGetLabels(selectBox, delimiter) {
	//if (jsm.noud(selectBox.options)) return '';
	if (jsm.noud(delimiter)) {delimiter=',';}
	var retVal="";
	for (var i=0;i<selectBox.options.length;i++){
	    var option = selectBox.options[i];
	    retVal += option.text + delimiter + " ";
  	}
  	return  retVal.length>0?retVal.substr(0, retVal.length-2):'';
}

/** Get a JSON-Array style list of all the select box values, eg. ['1', '2', ...]
* @param {Node} selectBox
* @return {String} 
*/
function jsmGetValues(selectBox) {
	if (jsm.noud(selectBox.options)) return '';
	var retVal="[";
	for (var i=0;i<selectBox.options.length;i++){
	    var option = selectBox.options[i];
	    retVal += "'" + option.value + "', ";
  	}
  	retVal = retVal.length>1?retVal.substr(0, retVal.length-2):'['
  	retVal += "]";
  	return  retVal;
}

/** Array holding all selected widget nodes<br> */
jsmSelectedWidgetNodes=new Array();

/** Stick all selected widget nodes into the global var jsmSelectedWidgetNodes<br>
* IE will set the checked and selected flags of a widget-node to false as soon as the node is appended to another node
* therefore I stick the checkbox-nodes and option-nodes which are selected into an array
* later for example the table.render()-method will make sure they get selected
* @param {Node} theNode Node which can be selected (eg. checkbox node) or have selected children (eg. selectbox node) 
*/
function jsmHangOntoSelectedWidgetNodes(theNode) {
	//add checked check box nodes	  		
  	try {if (theNode.checked) {jsmSelectedWidgetNodes.push(theNode);}} catch(ignored) {}
  	//add selected option nodes
  	try {if (theNode.selected) {jsmSelectedWidgetNodes.push(theNode);}} catch(ignored) {}	  		  	
  	//add selected option nodes from select box node
	try {	
	  	for (var optionIdx=0; optionIdx<theNode.length;optionIdx++) {
	  		if (theNode.options[optionIdx].selected) {jsmSelectedWidgetNodes.push(theNode.options[optionIdx]);}
	  	}		  	
	} catch(ignored) {} 
}

/** Select all nodes contained in this array and remove nodes from the global var jsmSelectedWidgetNodes
*/
function jsmSelectWidgetNodes() {
	var theNode;
	if (!jsm.noud(jsmSelectedWidgetNodes)) {
		while (theNode = jsmSelectedWidgetNodes.pop()) {
			try {theNode.checked=true;} catch(ignored) {}
			try {theNode.selected=true;} catch(ignored) {}
		}
	}
}

/** Pause the java script execution - will take over all processor resources because it uses a while loop
*@param {int} milliSecs
*/
function pause(milliSecs) {
	var then = new Date(new Date().getTime() + milliSecs); while (new Date() < then) {}
} 

/** Will add a message to the page if an element with the id='jsmMessage' has been specified
* @param {Html} theHTML The message to render - can contain HTML tags
* @param {int} timeout (Optional) The timeout in seconds after which the message will be cleared
* @param {boolean} warn (Optional) Adds a warning style to the message box
*/
function jsmAddMessage(theHTML, timeout, warn) {
	messageBox = document.getElementById("jsmMessage");
	try {
		if (warn) {
		 	messageBox.style.backgroundColor="#FFCFB8";						
			messageBox.innerHTML="<img src='" + jsmImageFolder + "warn.gif' border='0'></img> " + theHTML;
		} else {
		 	messageBox.style.backgroundColor="#FFFFFF";
			messageBox.innerHTML=theHTML;									
		}
		messageBox.style.display = 'block';
		try {window.scrollTo(0, 0);} catch(e) {}
		if (!jsm.noud(timeout)) {window.setTimeout("jsmClearMessage()", timeout*1000);}
	} catch(e) {}	
}

/** Clear the messages off the page in element with the id='jsmMessage'
*/		
function jsmClearMessage() {
	messageBox = document.getElementById("jsmMessage");
	try {
		messageBox.innerHTML="";
		messageBox.style.display = 'none';
	} catch(e) {}
}					

/** Will append a message to the page if an element with the id='jsmMessage' has been specified
* @param {Html} theHTML The message to render - can contain HTML tags
* @param {int} timeout (Optional) The timeout in seconds after which the message will be cleared
* @param {boolean} warn (Optional) Adds a warning style to the message box
*/		
function jsmAppendMessage(theHTML, timeout, warn) {
	messageBox = document.getElementById("jsmMessage");
	try {
		if (warn) {
 			messageBox.style.backgroundColor="#FFCFB8";							
		} else {
 			messageBox.style.backgroundColor="#FFFFFF";						
		}
		messageBox.style.display = 'block';
		if (messageBox.innerHTML == '') {
			if (warn) {
					messageBox.innerHTML="<img src='" + jsmImageFolder + "warn.gif' border='0'></img>"+theHTML;						
			} else {
				messageBox.innerHTML=theHTML;				
			}				
		} else {
			if (warn) {
				messageBox.innerHTML=messageBox.innerHTML + "<br>" +  theHTML;
			} else {
				messageBox.innerHTML=messageBox.innerHTML + "<br><img src='" + jsmImageFolder + "warn.gif' border='0'></img>" +  theHTML;			
			}				
		}			
		try {window.scrollTo(0, 0);} catch(e) {}
		if (!jsm.noud(timeout)) {window.setTimeout("jsmClearMessage()", timeout*1000);}
	} catch(e) {}
}	

jsm

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