Commit b7ae91fac1b14d4e78c1342e1cfd39c71e8baaaf
1 parent
46e717e3
Added global dec and some functions
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@684 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
58 additions
and
6 deletions
lib/visualpatterns/PatternListBox.inc
| @@ -26,8 +26,21 @@ class PatternListBox { | @@ -26,8 +26,21 @@ class PatternListBox { | ||
| 26 | var $sSelectName; | 26 | var $sSelectName; |
| 27 | /** Where clause */ | 27 | /** Where clause */ |
| 28 | var $sWhereClause; | 28 | var $sWhereClause; |
| 29 | + /**from clause, use to add extra inner joins. The default selected table gets | ||
| 30 | + a name of ST and the two selected columns are 'value' and 'display' */ | ||
| 31 | + var $sFromClause; | ||
| 29 | /** Order columns ascending*/ | 32 | /** Order columns ascending*/ |
| 30 | var $bOrderAsc; | 33 | var $bOrderAsc; |
| 34 | + /** set this to true to cause the list box to post back on a change */ | ||
| 35 | + var $bPostBackOnChange = false; | ||
| 36 | + /** action to perform on a postback */ | ||
| 37 | + var $sOnChangeAction = "document.MainForm.submit();"; | ||
| 38 | + /** currently selected value */ | ||
| 39 | + var $selectedValue; | ||
| 40 | + /** error message for an empty list box */ | ||
| 41 | + var $sEmptyErrorMessage = "No values"; | ||
| 42 | + /** whether to include 'None' as an option*/ | ||
| 43 | + var $bIncludeDefaultValue = true; | ||
| 31 | 44 | ||
| 32 | /** | 45 | /** |
| 33 | * Constructor | 46 | * Constructor |
| @@ -47,6 +60,34 @@ class PatternListBox { | @@ -47,6 +60,34 @@ class PatternListBox { | ||
| 47 | $this->bOrderAsc = $bNewOrderAsc; | 60 | $this->bOrderAsc = $bNewOrderAsc; |
| 48 | } | 61 | } |
| 49 | 62 | ||
| 63 | + function setPostBackOnChange($bNewValue) { | ||
| 64 | + $this->bPostBackOnChange = $bNewValue; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + function setOnChangeAction($sNewValue) { | ||
| 68 | + $this->sOnChangeAction = $sNewValue; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + function setSelectedValue($NewValue) { | ||
| 72 | + $this->selectedValue = $NewValue; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + function setWhereClause($sNewValue) { | ||
| 76 | + $this->sWhereClause = $sNewValue; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + function setFromClause($sNewValue) { | ||
| 80 | + $this->sFromClause = $sNewValue; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + function setEmptyErrorMessage($sNewValue) { | ||
| 84 | + $this->sEmptyErrorMessage = $sNewValue; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + function setIncludeDefaultValue($bNewValue) { | ||
| 88 | + $this->bIncludeDefaultValue = $bNewValue; | ||
| 89 | + } | ||
| 90 | + | ||
| 50 | /** | 91 | /** |
| 51 | * Create the HTML string that will be used to render the list box | 92 | * Create the HTML string that will be used to render the list box |
| 52 | * | 93 | * |
| @@ -62,13 +103,24 @@ class PatternListBox { | @@ -62,13 +103,24 @@ class PatternListBox { | ||
| 62 | $sQuery .= "WHERE " . $this->sWhereClause . " "; | 103 | $sQuery .= "WHERE " . $this->sWhereClause . " "; |
| 63 | } | 104 | } |
| 64 | 105 | ||
| 65 | - $sQuery .= "ORDER BY $this->sDisplayColumn " . ($this->bOrderAsc ? "ASC" : "DESC"); | 106 | + $sQuery .= "ORDER BY $this->sDisplayColumn " . ($this->bOrderAsc ? "ASC" : "DESC"); |
| 66 | $sql->query($sQuery); | 107 | $sql->query($sQuery); |
| 67 | - $sToRender = "<SELECT NAME = \"$this->sSelectName\">\n"; | ||
| 68 | - while ($sql->next_record()) { | ||
| 69 | - $sToRender .= "<OPTION value=\"" . $sql->f("value") . "\">" . $sql->f("display") . "</OPTION>\n"; | ||
| 70 | - } | ||
| 71 | - $sToRender .= "</SELECT><br><br>"; | 108 | + if ($sql->num_rows() > 0) { |
| 109 | + $sToRender = "<SELECT NAME = \"$this->sSelectName\" ". ($this->bPostBackOnChange ? "onChange=\"$this->sOnChangeAction\" " : " ") . ">\n"; | ||
| 110 | + if ($this->bIncludeDefaultValue) { | ||
| 111 | + $sToRender .= "<OPTION value=\"-1\">None</OPTION>\n"; | ||
| 112 | + } | ||
| 113 | + while ($sql->next_record()) { | ||
| 114 | + if ($this->selectedValue == $sql->f("value")) { | ||
| 115 | + $sToRender .= "<OPTION value=\"" . $sql->f("value") . "\" SELECTED>" . $sql->f("display") . "</OPTION>\n"; | ||
| 116 | + } else { | ||
| 117 | + $sToRender .= "<OPTION value=\"" . $sql->f("value") . "\">" . $sql->f("display") . "</OPTION>\n"; | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + $sToRender .= "</SELECT>\n"; | ||
| 121 | + } else { | ||
| 122 | + $sToRender .= "<label class=\"errorText\">$this->sEmptyErrorMessage</label>\n"; | ||
| 123 | + } | ||
| 72 | return $sToRender; | 124 | return $sToRender; |
| 73 | } | 125 | } |
| 74 | } | 126 | } |