jsm

net/sf/jsm/widgets/jsmCheckBox.js

Summary

No overview generated for 'net/sf/jsm/widgets/jsmCheckBox.js'


Class Summary
JsmCheckBox Represents a checkbox

/**
 * Creates a new JsmCheckBox
 * @extends JsmWidget
 * @class Represents a checkbox
 * @param {boolean} selected Is this checkbox selected
 * @param {String} selectedValue The value to display if the checkbox is select
 * @param {String} notSelectedValue The value to display if the checkbox is not select 
 * @constructor
 */   
  function JsmCheckBox(selected, selectedValue, notSelectedValue) {
  	/** @ignore */
  	this.id=new Date().getTime() + "" + Math.random();  	
  	/** Is this checkbox selected */  	
  	this.selected = selected;
  	/** The value to display if the checkbox is select */
  	this.selectedValue = selectedValue;
  	/** The value to display if the checkbox is not select */
  	this.notSelectedValue = notSelectedValue;
  	logger.info("Created: " + this);   	
  }

  JsmCheckBox.extendClass(JsmWidget);

  /** @ignore */
  JsmCheckBox.prototype.className="JsmCheckBox";
   
  /** @ignore */
  JsmCheckBox.prototype.toString = function() {
  	return "[JsmCheckBox - id: " + this.id + " selectedValue: " + this.selectedValue + " - notSelectedValue: " + this.notSelectedValue + "]\n"; 	
  }   
   
  /** Specify if this checkbox is selected or not
  * @param {boolean} selected
  * @return this
  */
  JsmCheckBox.prototype.setSelected = function(selected) {
	this.selected=selected;
	return this;
  }      
  
  /** Is this checkbox selected
  * @return {boolean}
  */
  JsmCheckBox.prototype.isSelected = function() {
	return this.selected;
  }        
    
  /** Set the value to display if the checkbox is selected 
  * @param {String} selectedValue
  * @return this
  */
  JsmCheckBox.prototype.setSelectedValue = function(selectedValue) {
	this.selectedValue=selectedValue;
	return this;
  }    
  
  /** Set the value to display if the checkbox is not selected 
  * @param {String} notSelectedValue
  * @return this  
  */
  JsmCheckBox.prototype.setNotSelectedValue = function(notSelectedValue) {
	this.notSelectedValue=notSelectedValue;
	return this;
  }      
  
  /** Get the value to display if the checkbox is selected 
  * @return {String}  
  */
  JsmCheckBox.prototype.getSelectedValue = function(selectedValue) {
	return this.selectedValue;
  }    
  
  /** Get the value to display if the checkbox is not selected 
  * @return {String}
  */
  JsmCheckBox.prototype.getNotSelectedValue = function(notSelectedValue) {
	return this.notSelectedValue;
  }           
  
  /** Init this text field's value from with the tabel cells value
  * @param {JsmTd} theTd The cell in which this widget is displayed
  */  
  JsmCheckBox.prototype.init = function(theTd) {
  	if (this.getSelectedValue() == theTd.getValue()) {
  		logger.debug("Init checkbox as selected");
  		this.setSelected(true);
  	} else {
  		logger.debug("Init checkbox as not selected");  	
  		this.setSelected(false);
  	}
  	return this;
  } 
  
  /** Update the tabel model if all validators are passed;  will update the value on the hosting {@JsmTd} object
   * @param {JsmTable} table The table this widget is attached to
   * @param {int} rowIdx The index of the row
   * @param {int} columnIdx The index of the column
   * @param theViewComponent   
   */  
  JsmCheckBox.prototype.updateModel = function(table, rowIdx, columnIdx, theViewComponent) {
   	if (jsm.noud(theViewComponent)) {return;}
	if (!this.validate(table, rowIdx, columnIdx, theViewComponent)) {
		return;
	}
	logger.debug("JsmCheckBox - updateModel: The view component is selected: " + theViewComponent.checked);	
	this.setSelected(theViewComponent.checked);
	var newValue = theViewComponent.checked?this.getSelectedValue():this.getNotSelectedValue();
  	td = table.getTd(rowIdx, columnIdx);
  	if (td.getValue() != newValue) {
		logger.debug("The cell value is different - will set it to the selected value and set cell dirty");	  	
  		td.setDirty(true);
		td.setValue(newValue); 
  	}	 	
  }   
  
  /** Returns the node of the view component; the model (this) will be attached to the node as property 'model' 
  * @return theViewComponent The node of the view component (for example to append to a table cell)
  */
  JsmCheckBox.prototype.getNode = function() {
  	var checkbox = document.createElement("input"); 
	checkbox.model=this;  	
  	checkbox.setAttribute("id", this.id);
  	checkbox.setAttribute("name", this.id);  
  	checkbox.setAttribute("type", "checkbox");
  	checkbox.checked = this.isSelected(); 
  	this.addAttributesToViewComponent(checkbox); 
  	return checkbox;
  }  
  
  /** Clones this JsmCheckBox
  * @return {JsmCheckBox}
  */
  JsmCheckBox.prototype.clone = function() {
	var clonedWidget = new JsmCheckBox();
   	//TODO is it sufficient to copy the Array or do we have to iterate and copy each entry
   	clonedWidget._attributes = this._attributes;
   	clonedWidget._metaData = this._metaData;   
   	clonedWidget.selectedValue = this.selectedValue;   		
   	clonedWidget.notSelectedValue = this.notSelectedValue;   		   	
   	return clonedWidget;	
  }   
  
  

jsm

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