Source for file WVerifiedChangeInput.class.php

Documentation is available at WVerifiedChangeInput.class.php

  1. <?php
  2. /**
  3. * @since 2005/10/20
  4. * @package polyphony.wizard.components
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: WVerifiedChangeInput.class.php,v 1.11 2007/09/19 14:04:51 adamfranco Exp $
  10. */
  11.  
  12. /**
  13. * This component provides a checkbox next to the input field with which the
  14. * user can confirm that they wish to change this field. This is useful when
  15. * making forms which allow for the editing of many fields across multiple items
  16. * where the user may only wish to change one of the fields across all items.
  17. *
  18. * @since 2005/10/20
  19. * @package polyphony.wizard.components
  20. *
  21. * @copyright Copyright &copy; 2005, Middlebury College
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  23. *
  24. * @version $Id: WVerifiedChangeInput.class.php,v 1.11 2007/09/19 14:04:51 adamfranco Exp $
  25. */
  26.  
  27. class WVerifiedChangeInput
  28. extends WizardComponentWithChildren
  29. {
  30.  
  31. var $_input;
  32. var $_checkbox;
  33. var $_label;
  34. /*******************************************************
  35. * Class Methods - Instance creation
  36. *********************************************************/
  37.  
  38. /**
  39. * Create a new VerifiedChangeInput with the component specified
  40. *
  41. * @param object WComponent $input
  42. * @return object
  43. * @access public
  44. * @since 10/20/05
  45. */
  46. function withInputComponent ( $input ) {
  47. $obj = new WVerifiedChangeInput();
  48. $obj->setInput($input);
  49. return $obj;
  50. }
  51. /*******************************************************
  52. * Instance Methods
  53. *********************************************************/
  54.  
  55. /**
  56. * $this is a shallow copy, subclasses should override to copy fields as
  57. * necessary to complete the full copy.
  58. *
  59. * @return object
  60. * @access public
  61. * @since 7/11/05
  62. */
  63. function postCopy () {
  64. $this->_checkbox =$this->_checkbox->copy();
  65. $this->_input =$this->_input->copy();
  66. return $this;
  67. }
  68. /**
  69. * Constructor
  70. *
  71. * @return object
  72. * @access public
  73. * @since 10/20/05
  74. */
  75. function WVerifiedChangeInput() {
  76. $this->_checkbox = new WCheckBox;
  77. $this->_checkbox->setParent($this);
  78. $this->_label = dgettext("polyphony", "Apply to All");
  79. $this->setChecked(true);
  80. }
  81. /**
  82. * Set the input component
  83. *
  84. * @param object WComponent $input
  85. * @return object WComponent
  86. * @access public
  87. * @since 10/20/05
  88. */
  89. function setInputComponent ( $input ) {
  90. ArgumentValidator::validate($input,
  91. ExtendsValidatorRule::getRule("WizardComponent"));
  92. ArgumentValidator::validate($input,
  93. HasMethodsValidatorRule::getRule("addOnChange"));
  94. $this->_input =$input;
  95. $this->_input->setParent($this);
  96. return $this->_input;
  97. }
  98. /**
  99. * Set the value of the input component
  100. *
  101. * @param string $value
  102. * @access public
  103. * @return void
  104. * @since 10/21/05
  105. */
  106. function setValue ($value) {
  107. if (is_array($value)) {
  108. $this->_checkbox->setValue($value['checked']);
  109. $this->_input->setValue($value['value']);
  110. } else
  111. $this->_input->setValue($value);
  112. }
  113. /**
  114. * Sets the text of the field to display until the user enters the field.
  115. * @param string $text
  116. * @access public
  117. * @return void
  118. */
  119. function setStartingDisplayText ($text) {
  120. $this->_input->setStartingDisplayText($text);
  121. }
  122. /**
  123. * Set the checked state of the checkbox
  124. *
  125. * @param boolean $checked
  126. * @return void
  127. * @access public
  128. * @since 10/24/05
  129. */
  130. function setChecked ($checked) {
  131. $this->_checkbox->setValue($checked);
  132. }
  133. /**
  134. * Sets if this component will be enabled or disabled.
  135. * @param boolean $enabled
  136. * @param boolean $sticky If true, future calls to setEnabled without sticky
  137. * will have no effect.
  138. * @access public
  139. * @return void
  140. */
  141. function setEnabled ($enabled, $sticky = false) {
  142. $this->_input->setEnabled($enabled, $sticky);
  143. }
  144. /**
  145. * Sets the label for this checkbox element.
  146. * @param string $label;
  147. * @access public
  148. * @return void
  149. */
  150. function setLabel ($label) {
  151. $this->_label = $label;
  152. }
  153. /**
  154. * Returns true if this component (and all child components if applicable) have valid values.
  155. * By default, this will just return TRUE. Validate should be called usually before a save event
  156. * is handled, to make sure everything went smoothly.
  157. * @access public
  158. * @return boolean
  159. */
  160. function validate () {
  161. return $this->_input->validate();
  162. }
  163. /**
  164. * Tells the wizard component to update itself - this may include getting
  165. * form post data or validation - whatever this particular component wants to
  166. * do every pageload.
  167. * @param string $fieldName The field name to use when outputting form data or
  168. * similar parameters/information.
  169. * @access public
  170. * @return boolean - TRUE if everything is OK
  171. */
  172. function update ($fieldName) {
  173. $this->_checkbox->update($fieldName."_checked");
  174. return $this->_input->update($fieldName);
  175. }
  176. /**
  177. * Returns the values of wizard-components. Should return an array if children are involved,
  178. * otherwise a whatever type of object is expected.
  179. * @access public
  180. * @return mixed
  181. */
  182. function getAllValues () {
  183. $array = array();
  184. $array['checked'] = $this->_checkbox->getAllValues();
  185. $array['value'] = $this->_input->getAllValues();
  186. return $array;
  187. }
  188. /**
  189. * Returns a block of XHTML-valid code that contains markup for this specific
  190. * component.
  191. * @param string $fieldName The field name to use when outputting form data or
  192. * similar parameters/information.
  193. * @access public
  194. * @return string
  195. */
  196. function getMarkup ($fieldName) {
  197. if (isset($this->_input->_startingDisplay)) {
  198. $v = htmlspecialchars($this->_input->_startingDisplay, ENT_QUOTES);
  199. $this->_input->addOnChange(
  200. "if (this.value != '$v') {".$this->_checkbox->getCheckJS($fieldName."_checked")."}");
  201. } else {
  202. $this->_input->addOnChange($this->_checkbox->getCheckJS($fieldName."_checked"));
  203. }
  204. $m = "\n<table><tr>";
  205. $m .= "\n\t<td title='".$this->_label."' style='vertical-align: top; padding: 0px; margin: 0px;'>";
  206. $m .= "\n\t\t".$this->_checkbox->getMarkup($fieldName."_checked");
  207. $m .= "\n\t</td>\n\t<td style='padding: 0px; margin: 0px;'>";
  208. $m .= "\n\t\t".$this->_input->getMarkup($fieldName);
  209. $m .= "\n\t</td>";
  210. $m .= "\n</tr></table>";
  211. return $m;
  212. }
  213. }
  214. ?>

Documentation generated on Wed, 19 Sep 2007 10:28:27 -0400 by phpDocumentor 1.3.0RC3