Source for file WEventButton.class.php

Documentation is available at WEventButton.class.php

  1. <?php
  2. /**
  3. * @since Jul 20, 2005
  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: WEventButton.class.php,v 1.15 2007/09/19 14:04:51 adamfranco Exp $
  10. */
  11.  
  12. /**
  13. * This is a base class for any button in a {@link Wizard} that will throw an event when
  14. * it is activated.
  15. *
  16. * @since Jul 20, 2005
  17. * @package polyphony.wizard.components
  18. *
  19. * @copyright Copyright &copy; 2005, Middlebury College
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  21. *
  22. * @version $Id: WEventButton.class.php,v 1.15 2007/09/19 14:04:51 adamfranco Exp $
  23. */
  24. class WEventButton
  25. extends WizardComponent
  26. {
  27. var $_event = "nop";
  28. var $_label = "NO LABEL";
  29. var $_pressed = false;
  30. var $_onclick = null;
  31. /**
  32. * virtual constructor
  33. * @param string $event
  34. * @param string $label
  35. * @access public
  36. * @return ref object
  37. * @static
  38. */
  39. function withEventAndLabel ($event, $label) {
  40. $obj = new WEventButton();
  41. $obj->setEventAndLabel($event, $label);
  42. return $obj;
  43. }
  44. /**
  45. * virtual constructor - creates the button with a "nop" event
  46. * @param string $label
  47. * @access public
  48. * @return ref object
  49. */
  50. function withLabel ($label) {
  51. $obj = new WEventButton();
  52. $obj->_label = $label;
  53. return $obj;
  54. }
  55. /**
  56. * Sets the event type and label for the button.
  57. * @param string $event
  58. * @param string $label
  59. * @param optional string $textDomain the gettext() text domain to use for the label.
  60. * @access public
  61. * @return void
  62. */
  63. function setEventAndLabel ($event, $label) {
  64. $this->_label = $label;
  65. $this->_event = $event;
  66. }
  67. /**
  68. * Sets the label for the button.
  69. * @param string $label
  70. * @param optional string $textDomain the gettext() text domain to use for the label.
  71. * @access public
  72. * @return void
  73. */
  74. function setLabel ($label) {
  75. $this->_label = $label;
  76. }
  77. /**
  78. * Sets the on-click javascript to be called.
  79. * @param string $javascript
  80. * @access public
  81. * @return void
  82. */
  83. function addOnClick ($javascript) {
  84. $this->_onclick .= " ".$javascript;
  85. }
  86. /**
  87. * Add a confirmation question that will be present in a javascript 'confirm'
  88. * dialog on button press.
  89. *
  90. * @param string $confirmText
  91. * @return void
  92. * @access public
  93. * @since 6/7/06
  94. */
  95. function addConfirm ($confirmText) {
  96. if (!isset($this->_confirms))
  97. $this->_confirms = array();
  98. $this->_confirms[] = $confirmText;
  99. }
  100. /**
  101. * Tells the wizard component to update itself - this may include getting
  102. * form post data or validation - whatever this particular component wants to
  103. * do every pageload.
  104. * @param string $fieldName The field name to use when outputting form data or
  105. * similar parameters/information.
  106. * @access public
  107. * @return boolean - TRUE if everything is OK
  108. */
  109. function update ($fieldName) {
  110. $val = RequestContext::value($fieldName);
  111. if ($val) {
  112. // trigger the save event on the wizard
  113. $wizard =$this->getWizard();
  114. $wizard->triggerLater($this->_event, $wizard);
  115. $this->_pressed = true;
  116. }
  117. }
  118. /**
  119. * Returns the values of wizard-components. Should return an array if children are involved,
  120. * otherwise a whatever type of object is expected.
  121. * @access public
  122. * @return mixed
  123. */
  124. function getAllValues () {
  125. $val = $this->_pressed;
  126. $this->_pressed = false;
  127. return $val;
  128. }
  129. /**
  130. * Returns a block of XHTML-valid code that contains markup for this specific
  131. * component.
  132. * @param string $fieldName The field name to use when outputting form data or
  133. * similar parameters/information.
  134. * @access public
  135. * @return string
  136. */
  137. function getMarkup ($fieldName) {
  138. $name = RequestContext::name($fieldName);
  139. $label = htmlspecialchars($this->_label, ENT_QUOTES);
  140. $onclick = '';
  141. if ($this->_onclick) $onclick = addslashes($this->_onclick) . ";";
  142. $m = "<input type='hidden' name='$name' id='$name' value='0' />\n";
  143. $m .= "<input type='button' value='$label' onclick='";
  144. if (isset($this->_confirms) && count($this->_confirms)) {
  145. $m .= "var confirmed = (confirm(\"";
  146. $m .= implode("\") && confirm(\"", $this->_confirms);
  147. $m .= "\"));";
  148. } else {
  149. $m .= "var confirmed = true; ";
  150. }
  151. $m .= " if (confirmed) { ";
  152. $m .= $onclick;
  153. $m .= " if (validateWizard(this.form)) { ";
  154. $m .= " getWizardElement(\"$name\").value=\"1\";";
  155. $m .= " this.form.submit();";
  156. $m .= " }";
  157. $m .= " }";
  158. $m .= "'".($this->isEnabled()?"":" disabled='disabled'")." />";
  159. return $m;
  160. }
  161. }
  162.  
  163. ?>

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