| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * QControl.class.php contains QControl Class |
|---|
| 4 | * @package Controls |
|---|
| 5 | */ |
|---|
| 6 | /** |
|---|
| 7 | * QControl is the user overridable Base-Class for all Controls. |
|---|
| 8 | * |
|---|
| 9 | * This class is intended to be modified. Please place any custom modifications to QControl in the file. |
|---|
| 10 | * The RenderWithName function provided here is a basic rendering. Feel free to make your own modifcations. |
|---|
| 11 | * Please note: All custom render methods should start with a RenderHelper call and end with a RenderOutput call. |
|---|
| 12 | * |
|---|
| 13 | * @package Controls |
|---|
| 14 | */ |
|---|
| 15 | abstract class QControl extends QControlBase { |
|---|
| 16 | |
|---|
| 17 | /** |
|---|
| 18 | * By default, wrappers are turned on for all controls. Wrappers create an extra <div> tag around |
|---|
| 19 | * QControls, and were historically used to help manipulate QControls, and to group a name and error |
|---|
| 20 | * message with a control. However, they can at times get in the way. Now that we are using jQuery to |
|---|
| 21 | * manipulate controls, they are not needed as much, but they are still useful for grouping names and |
|---|
| 22 | * error messages with a control. If you want to turn global wrappers off and rather set a wrapper for |
|---|
| 23 | * individual controls, uncomment the line below. |
|---|
| 24 | */ |
|---|
| 25 | protected $blnUseWrapper = false; |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * Renders the control with an attached name |
|---|
| 29 | * |
|---|
| 30 | * This will call {@link QControlBase::GetControlHtml()} for the bulk of the work, but will add layout html as well. It will include |
|---|
| 31 | * the rendering of the Controls' name label, any errors or warnings, instructions, and html before/after (if specified). |
|---|
| 32 | * As this is the parent class of all controls, this method defines how ALL controls will render when rendered with a name. |
|---|
| 33 | * If you need certain controls to display differently, override this function in that control's class. |
|---|
| 34 | * |
|---|
| 35 | * @param boolean $blnDisplayOutput true to send to display buffer, false to just return then html |
|---|
| 36 | * @return string HTML of rendered Control |
|---|
| 37 | */ |
|---|
| 38 | |
|---|
| 39 | public function RenderWithName($blnDisplayOutput = true) { |
|---|
| 40 | //////////////////// |
|---|
| 41 | // Call RenderHelper |
|---|
| 42 | $this->RenderHelper(func_get_args(), __FUNCTION__); |
|---|
| 43 | //////////////////// |
|---|
| 44 | |
|---|
| 45 | $strDataRel=''; |
|---|
| 46 | $strWrapperAttributes=''; |
|---|
| 47 | if($this->blnUseWrapper==false) { |
|---|
| 48 | //there is no wrapper --> add the special attribute data-rel to the name control |
|---|
| 49 | $strDataRel = sprintf("data-rel='#%s'",$this->strControlId); |
|---|
| 50 | $strWrapperAttributes = "data-hasrel='1'"; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | // Custom Render Functionality Here |
|---|
| 54 | |
|---|
| 55 | // Because this example RenderWithName will render a block-based element (e.g. a DIV), let's ensure |
|---|
| 56 | // that IsBlockElement is set to true |
|---|
| 57 | $this->blnIsBlockElement = true; |
|---|
| 58 | |
|---|
| 59 | // Render the Control's Dressing |
|---|
| 60 | $strToReturn = '<div class="renderWithName" ' . $strDataRel . '>'; |
|---|
| 61 | |
|---|
| 62 | // Render the Left side |
|---|
| 63 | $strLeftClass = "left"; |
|---|
| 64 | if ($this->blnRequired) |
|---|
| 65 | $strLeftClass .= ' required'; |
|---|
| 66 | if (!$this->blnEnabled) |
|---|
| 67 | $strLeftClass .= ' disabled'; |
|---|
| 68 | |
|---|
| 69 | if ($this->strInstructions) |
|---|
| 70 | $strInstructions = '<br/><span class="instructions">' . $this->strInstructions . '</span>'; |
|---|
| 71 | else |
|---|
| 72 | $strInstructions = ''; |
|---|
| 73 | |
|---|
| 74 | $strToReturn .= sprintf('<div class="%s"><label for="%s">%s</label>%s</div>' , $strLeftClass, $this->strControlId, $this->strName, $strInstructions); |
|---|
| 75 | |
|---|
| 76 | // Render the Right side |
|---|
| 77 | if ($this->strValidationError) |
|---|
| 78 | $strMessage = sprintf('<span class="error">%s</span>', $this->strValidationError); |
|---|
| 79 | else if ($this->strWarning) |
|---|
| 80 | $strMessage = sprintf('<span class="error">%s</span>', $this->strWarning); |
|---|
| 81 | else |
|---|
| 82 | $strMessage = ''; |
|---|
| 83 | |
|---|
| 84 | try { |
|---|
| 85 | $strToReturn .= sprintf('<div class="right">%s%s%s%s</div>', |
|---|
| 86 | $this->strHtmlBefore, $this->GetControlHtml(), $this->strHtmlAfter, $strMessage); |
|---|
| 87 | } catch (QCallerException $objExc) { |
|---|
| 88 | $objExc->IncrementOffset(); |
|---|
| 89 | throw $objExc; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | $strToReturn .= '</div>'; |
|---|
| 93 | |
|---|
| 94 | //////////////////////////////////////////// |
|---|
| 95 | // Call RenderOutput, Returning its Contents |
|---|
| 96 | return $this->RenderOutput($strToReturn, $blnDisplayOutput,false,$strWrapperAttributes); |
|---|
| 97 | //////////////////////////////////////////// |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | } |
|---|
| 101 | ?> |
|---|