Index: trunk/extensions/SemanticForms/includes/forminputs/SF_FormInput.php |
— | — | @@ -25,12 +25,12 @@ |
26 | 26 | protected $mInputNumber; |
27 | 27 | protected $mCurrentValue; |
28 | 28 | protected $mInputName; |
29 | | - protected $mIsMandatory; |
| 29 | + protected $mIsMandatory; // @deprecated, check for array_key_exists('mandatory', $this->mOtherArgs) instead |
30 | 30 | protected $mIsDisabled; |
31 | 31 | protected $mOtherArgs; |
32 | 32 | |
33 | | - private $mJsInitFunctionData = array(); |
34 | | - private $mJsValidationFunctionData = array(); |
| 33 | + protected $mJsInitFunctionData = array(); |
| 34 | + protected $mJsValidationFunctionData = array(); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Constructor for the SFFormInput class. |
— | — | @@ -48,11 +48,13 @@ |
49 | 49 | * An associative array of other parameters that were present in the |
50 | 50 | * input definition. |
51 | 51 | */ |
52 | | - public function __construct( $input_number, $cur_value, $input_name, $other_args ) { |
| 52 | + public function __construct( $input_number, $cur_value, $input_name, $disabled, $other_args ) { |
53 | 53 | $this->mInputNumber = $input_number; |
54 | 54 | $this->mCurrentValue = $cur_value; |
55 | 55 | $this->mInputName = $input_name; |
56 | 56 | $this->mOtherArgs = $other_args; |
| 57 | + $this->mIsDisabled = $disabled; |
| 58 | + $this->mIsMandatory = array_key_exists( 'mandatory', $other_args ); |
57 | 59 | } |
58 | 60 | |
59 | 61 | /** |
— | — | @@ -72,7 +74,7 @@ |
73 | 75 | |
74 | 76 | /** |
75 | 77 | * Returns the set of SMW property types which this input can |
76 | | - * handle. |
| 78 | + * handle. See SMW's SMW_DataValueFactory.php |
77 | 79 | * |
78 | 80 | * @return Array of Strings |
79 | 81 | */ |
— | — | @@ -150,7 +152,7 @@ |
151 | 153 | * |
152 | 154 | * This function is not used yet. |
153 | 155 | */ |
154 | | - final public function getJsInitFunctionData() { |
| 156 | + public function getJsInitFunctionData() { |
155 | 157 | return $this->mJsInitFunctionData; |
156 | 158 | } |
157 | 159 | |
— | — | @@ -160,7 +162,7 @@ |
161 | 163 | * |
162 | 164 | * This function is not used yet. |
163 | 165 | */ |
164 | | - final public function getJsValidationFunctionData() { |
| 166 | + public function getJsValidationFunctionData() { |
165 | 167 | return $this->mJsValidationFunctionData; |
166 | 168 | } |
167 | 169 | |
— | — | @@ -188,7 +190,7 @@ |
189 | 191 | * @param String $name The name of the initialization function. |
190 | 192 | * @param String $param The parameter passed to the initialization function. |
191 | 193 | */ |
192 | | - final public function addJsInitFunctionData( $name, $param ) { |
| 194 | + public function addJsInitFunctionData( $name, $param = 'null' ) { |
193 | 195 | $this->mJsInitFunctionData[] = array( 'name' => $name, 'param' => $param ); |
194 | 196 | } |
195 | 197 | |
— | — | @@ -216,8 +218,8 @@ |
217 | 219 | * @param String $name The name of the initialization function. |
218 | 220 | * @param String $param The parameter passed to the initialization function. |
219 | 221 | */ |
220 | | - final public function addJsValidationFunctionData( $name, $param ) { |
221 | | - $this->mJsInitFunctionData[] = array( 'name' => $name, 'param' => $param ); |
| 222 | + public function addJsValidationFunctionData( $name, $param = 'null' ) { |
| 223 | + $this->mJsValidationFunctionData[] = array( 'name' => $name, 'param' => $param ); |
222 | 224 | } |
223 | 225 | |
224 | 226 | /** |
— | — | @@ -268,4 +270,44 @@ |
269 | 271 | return array(); |
270 | 272 | } |
271 | 273 | |
| 274 | + /** |
| 275 | + * Method to make new style input types compatible with old-style call from |
| 276 | + * the SF parser. |
| 277 | + * |
| 278 | + * @deprecated Do not use/override this in new input type classes |
| 279 | + * |
| 280 | + * TODO: remove/refactor once SF uses forminput objects properly |
| 281 | + */ |
| 282 | + public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args ) { |
| 283 | + |
| 284 | + global $sfgFieldNum, $wgOut; |
| 285 | + |
| 286 | + // create an input of the called class |
| 287 | + $calledClass = get_called_class(); |
| 288 | + $input = new $calledClass ( $sfgFieldNum, $cur_value, $input_name, $is_disabled, $other_args ); |
| 289 | + |
| 290 | + // create calls to JS initialization and validation |
| 291 | + // TODO: This data should be transferred as a JSON blob and then be evaluated from a dedicated JS file |
| 292 | + $jstext = ''; |
| 293 | + |
| 294 | + foreach ( $input->getJsInitFunctionData() as $jsInitFunctionData ) { |
| 295 | + |
| 296 | + $jstext .= <<<JAVASCRIPT |
| 297 | +jQuery(function(){ jQuery('#input_$sfgFieldNum').SemanticForms_registerInputInit({$jsInitFunctionData['name']}, {$jsInitFunctionData['param']} ); }); |
| 298 | +JAVASCRIPT; |
| 299 | + } |
| 300 | + |
| 301 | + foreach ( $input->getJsValidationFunctionData() as $jsValidationFunctionData ) { |
| 302 | + |
| 303 | + $jstext .= <<<JAVASCRIPT |
| 304 | +jQuery(function(){ jQuery('#input_$sfgFieldNum').SemanticForms_registerInputValidation( {$jsValidationFunctionData['name']}, {$jsValidationFunctionData['param']}); }); |
| 305 | +JAVASCRIPT; |
| 306 | + } |
| 307 | + |
| 308 | + // write JS code directly to the page's code |
| 309 | + $wgOut->addScript( Html::inlineScript( $jstext ) ); |
| 310 | + |
| 311 | + return $input->getHtmlText(); |
| 312 | + } |
| 313 | + |
272 | 314 | } |