FML Update
This commit is contained in:
		| @@ -33,6 +33,7 @@ class CheckBoxFeature extends ScriptFeature { | ||||
| 	protected $quad = null; | ||||
| 	/** @var Entry $entry */ | ||||
| 	protected $entry = null; | ||||
| 	protected $default = null; | ||||
| 	/** @var CheckBoxDesign $enabledDesign */ | ||||
| 	protected $enabledDesign = null; | ||||
| 	/** @var CheckBoxDesign $disabledDesign */ | ||||
| @@ -44,7 +45,7 @@ class CheckBoxFeature extends ScriptFeature { | ||||
| 	 * @param Quad  $quad  (optional) CheckBox Quad | ||||
| 	 * @param Entry $entry (optional) Hidden Entry | ||||
| 	 */ | ||||
| 	public function __construct(Quad $quad = null, Entry $entry = null) { | ||||
| 	public function __construct(Quad $quad = null, Entry $entry = null, $default = null) { | ||||
| 		$this->setQuad($quad); | ||||
| 		$this->setEntry($entry); | ||||
| 		$this->setEnabledDesign(CheckBoxDesign::defaultEnabledDesign()); | ||||
| @@ -98,10 +99,21 @@ class CheckBoxFeature extends ScriptFeature { | ||||
| 		return $this->entry; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the default Value | ||||
| 	 * | ||||
| 	 * @param bool $default Default Value | ||||
| 	 * @return \FML\Script\Features\CheckBoxFeature | ||||
| 	 */ | ||||
| 	public function setDefault($default) { | ||||
| 		$this->default = (bool)$default; | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the Enabled Design | ||||
| 	 * | ||||
| 	 * @param CheckBoxDesign $checkBoxDesign CheckBox Design | ||||
| 	 * @param CheckBoxDesign $checkBoxDesign Enabled CheckBox Design | ||||
| 	 * @return \FML\Script\Features\CheckBoxFeature | ||||
| 	 */ | ||||
| 	public function setEnabledDesign(CheckBoxDesign $checkBoxDesign) { | ||||
| @@ -112,7 +124,7 @@ class CheckBoxFeature extends ScriptFeature { | ||||
| 	/** | ||||
| 	 * Set the Disabled Design | ||||
| 	 * | ||||
| 	 * @param CheckBoxDesign $checkBoxDesign CheckBox Design | ||||
| 	 * @param CheckBoxDesign $checkBoxDesign Disabled CheckBox Design | ||||
| 	 * @return \FML\Script\Features\CheckBoxFeature | ||||
| 	 */ | ||||
| 	public function setDisabledDesign(CheckBoxDesign $checkBoxDesign) { | ||||
| @@ -126,7 +138,7 @@ class CheckBoxFeature extends ScriptFeature { | ||||
| 	public function prepare(Script $script) { | ||||
| 		if ($this->getQuad()) { | ||||
| 			$script->setScriptInclude(ScriptInclude::TEXTLIB); | ||||
| 			$script->addScriptFunction(self::FUNCTION_UPDATE_QUAD_DESIGN, $this->buildSetQuadDesignFunction()); | ||||
| 			$script->addScriptFunction(self::FUNCTION_UPDATE_QUAD_DESIGN, $this->buildUpdateQuadDesignFunction()); | ||||
| 			$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildInitScriptText(), true); | ||||
| 			$script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $this->buildClickScriptText()); | ||||
| 		} | ||||
| @@ -138,7 +150,7 @@ class CheckBoxFeature extends ScriptFeature { | ||||
| 	 * | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	protected function buildSetQuadDesignFunction() { | ||||
| 	protected function buildUpdateQuadDesignFunction() { | ||||
| 		$functionText = " | ||||
| Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) { | ||||
| 	declare " . self::VAR_CHECKBOX_ENABLED . " as Enabled for _Quad = True; | ||||
| @@ -173,13 +185,11 @@ Void " . self::FUNCTION_UPDATE_QUAD_DESIGN . "(CMlQuad _Quad) { | ||||
| 	 */ | ||||
| 	protected function buildInitScriptText() { | ||||
| 		$quadId  = $this->getQuad()->getId(true); | ||||
| 		$default = true; | ||||
| 		$entryId = ''; | ||||
| 		if ($this->entry) { | ||||
| 			$default = $this->entry->getDefault(); | ||||
| 			$entryId = $this->entry->getId(true); | ||||
| 		} | ||||
| 		$default              = Builder::getBoolean($default); | ||||
| 		$default              = Builder::getBoolean($this->default); | ||||
| 		$enabledDesignString  = $this->enabledDesign->getDesignString(); | ||||
| 		$disabledDesignString = $this->disabledDesign->getDesignString(); | ||||
| 		$scriptText           = " | ||||
|   | ||||
| @@ -7,9 +7,9 @@ use FML\Controls\Control; | ||||
| /** | ||||
|  * A Page Control | ||||
|  * | ||||
|  * @author steeffeen | ||||
|  * @author    steeffeen | ||||
|  * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder | ||||
|  * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||
|  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||
|  */ | ||||
| class PagingPage { | ||||
| 	/* | ||||
| @@ -21,8 +21,8 @@ class PagingPage { | ||||
| 	/** | ||||
| 	 * Construct a new Paging Page | ||||
| 	 * | ||||
| 	 * @param Control $control (optional) Page Control | ||||
| 	 * @param int $pageNumber (optional) Number of the Page | ||||
| 	 * @param Control $control    (optional) Page Control | ||||
| 	 * @param int     $pageNumber (optional) Number of the Page | ||||
| 	 */ | ||||
| 	public function __construct(Control $control = null, $pageNumber = 1) { | ||||
| 		$this->setControl($control); | ||||
| @@ -57,7 +57,7 @@ class PagingPage { | ||||
| 	 * @return \FML\Script\Features\PagingPage | ||||
| 	 */ | ||||
| 	public function setPageNumber($pageNumber) { | ||||
| 		$this->number = (int) $pageNumber; | ||||
| 		$this->number = (int)$pageNumber; | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
|   | ||||
							
								
								
									
										226
									
								
								application/core/Libs/FML/Script/Features/ValuePickerFeature.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										226
									
								
								application/core/Libs/FML/Script/Features/ValuePickerFeature.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,226 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script\Features; | ||||
|  | ||||
| use FML\Controls\Entry; | ||||
| use FML\Controls\Label; | ||||
| use FML\Script\Builder; | ||||
| use FML\Script\Script; | ||||
| use FML\Script\ScriptInclude; | ||||
| use FML\Script\ScriptLabel; | ||||
|  | ||||
| /** | ||||
|  * Script Feature for creating a ValuePicker Behavior | ||||
|  * | ||||
|  * @author    steeffeen | ||||
|  * @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder | ||||
|  * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3 | ||||
|  */ | ||||
| class ValuePickerFeature extends ScriptFeature { | ||||
| 	/* | ||||
| 	 * Constants | ||||
| 	 */ | ||||
| 	const FUNCTION_UPDATE_PICKER_VALUE = 'FML_UpdatePickerValue'; | ||||
| 	const VAR_PICKER_VALUES            = 'FML_Picker_Values'; | ||||
| 	const VAR_PICKER_DEFAULT_VALUE     = 'FML_Picker_Default_Value'; | ||||
| 	const VAR_PICKER_ENTRY_ID          = 'FML_Picker_EntryId'; | ||||
|  | ||||
| 	/* | ||||
| 	 * Protected Properties | ||||
| 	 */ | ||||
| 	/** @var Label $label */ | ||||
| 	protected $label = null; | ||||
| 	/** @var Entry $entry */ | ||||
| 	protected $entry = null; | ||||
| 	protected $values = null; | ||||
| 	protected $default = null; | ||||
|  | ||||
| 	/** | ||||
| 	 * Construct a new ValuePicker Feature | ||||
| 	 * | ||||
| 	 * @param Label  $label   (optional) ValuePicker Label | ||||
| 	 * @param Entry  $entry   (optional) Hidden Entry | ||||
| 	 * @param array  $values  (optional) Possible Values | ||||
| 	 * @param string $default (optional) Default Value | ||||
| 	 */ | ||||
| 	public function __construct(Label $label = null, Entry $entry = null, array $values = array(), $default = null) { | ||||
| 		$this->setLabel($label); | ||||
| 		$this->setEntry($entry); | ||||
| 		$this->setValues($values); | ||||
| 		$this->setDefault($default); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the ValuePicker Label | ||||
| 	 * | ||||
| 	 * @param Label $label ValuePicker Label | ||||
| 	 * @return \FML\Script\Features\ValuePickerFeature | ||||
| 	 */ | ||||
| 	public function setLabel(Label $label = null) { | ||||
| 		if ($label) { | ||||
| 			$label->checkId(); | ||||
| 			$label->setScriptEvents(true); | ||||
| 		} | ||||
| 		$this->label = $label; | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Get the ValuePicker Label | ||||
| 	 * | ||||
| 	 * @return \FML\Controls\Label | ||||
| 	 */ | ||||
| 	public function getLabel() { | ||||
| 		return $this->label; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the hidden Entry | ||||
| 	 * | ||||
| 	 * @param Entry $entry Hidden Entry | ||||
| 	 * @return \FML\Script\Features\ValuePickerFeature | ||||
| 	 */ | ||||
| 	public function setEntry(Entry $entry = null) { | ||||
| 		if ($entry) { | ||||
| 			$entry->checkId(); | ||||
| 		} | ||||
| 		$this->entry = $entry; | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Get the hidden Entry | ||||
| 	 * | ||||
| 	 * @return \FML\Controls\Entry | ||||
| 	 */ | ||||
| 	public function getEntry() { | ||||
| 		return $this->entry; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the possible Values | ||||
| 	 * | ||||
| 	 * @param array $values Possible Values | ||||
| 	 * @return \FML\Script\Features\ValuePickerFeature | ||||
| 	 */ | ||||
| 	public function setValues(array $values) { | ||||
| 		$this->values = array(); | ||||
| 		foreach ($values as $value) { | ||||
| 			array_push($this->values, (string)$value); | ||||
| 		} | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Set the default Value | ||||
| 	 * | ||||
| 	 * @param string $default Default Value | ||||
| 	 * @return \FML\Script\Features\ValuePickerFeature | ||||
| 	 */ | ||||
| 	public function setDefault($default) { | ||||
| 		$this->default = (string)$default; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Get the default Value | ||||
| 	 * | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	public function getDefault() { | ||||
| 		if ($this->default) { | ||||
| 			return $this->default; | ||||
| 		} | ||||
| 		if ($this->values) { | ||||
| 			return reset($this->values); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * @see \FML\Script\Features\ScriptFeature::prepare() | ||||
| 	 */ | ||||
| 	public function prepare(Script $script) { | ||||
| 		if ($this->label) { | ||||
| 			$script->setScriptInclude(ScriptInclude::TEXTLIB); | ||||
| 			$script->addScriptFunction(self::FUNCTION_UPDATE_PICKER_VALUE, $this->buildUpdatePickerValueFunction()); | ||||
| 			$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildInitScriptText(), true); | ||||
| 			$script->appendGenericScriptLabel(ScriptLabel::ONINIT, $this->buildClickScriptText()); | ||||
| 		} | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Build the Function Text | ||||
| 	 * | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	protected function buildUpdatePickerValueFunction() { | ||||
| 		$functionText = " | ||||
| Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) { | ||||
| 	declare " . self::VAR_PICKER_VALUES . " as Values for _Label = Text[]; | ||||
| 	declare NewValueIndex = 0; | ||||
| 	if (Values.exists(_Label.Value) { | ||||
| 		declare ValueIndex = _Label.keyof(_Label.Value); | ||||
| 		ValueIndex += 1; | ||||
| 		if (Values.existskey(ValueIndex)) { | ||||
| 			NewValueIndex = ValueIndex; | ||||
| 		} | ||||
| 	} | ||||
| 	declare NewValue = \"\"; | ||||
| 	if (Values.existskey(NewValueIndex)) { | ||||
| 		NewValue = Values[NewValueIndex]; | ||||
| 	} else { | ||||
| 		declare " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for _Label = \"\"; | ||||
| 		NewValue = Default; | ||||
| 	} | ||||
| 	_Label.Value = NewValue; | ||||
| 	declare " . self::VAR_PICKER_ENTRY_ID . " as EntryId for _Label = \"\"; | ||||
| 	if (EntryId != \"\") { | ||||
| 		declare Entry <=> (Page.GetFirstChild(EntryId) as CMlEntry); | ||||
| 		Entry.Value = NewValue; | ||||
| 	} | ||||
| }"; | ||||
| 		return $functionText; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Build the Init Script Text | ||||
| 	 * | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	protected function buildInitScriptText() { | ||||
| 		$labelId = $this->label->getId(true); | ||||
| 		$entryId = ''; | ||||
| 		if ($this->entry) { | ||||
| 			$entryId = $this->entry->getId(true); | ||||
| 		} | ||||
| 		$values     = Builder::getArray($this->values); | ||||
| 		$default    = $this->getDefault(); | ||||
| 		$scriptText = " | ||||
| declare Label_Picker <=> (Page.GetFirstChild(\"{$labelId}\") as CMlLabel); | ||||
| declare Text[] " . self::VAR_PICKER_VALUES . " as Values for Label_Picker; | ||||
| Values = {$values}; | ||||
| declare Text " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for Label_Picker; | ||||
| Default = \"{$default}\"; | ||||
| declare Text " . self::VAR_PICKER_ENTRY_ID . " as EntryId for Label_Picker; | ||||
| EntryId = \"{$entryId}\"; | ||||
| " . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker); | ||||
| "; | ||||
| 		return $scriptText; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Build the Script Text for Label Clicks | ||||
| 	 * | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	protected function buildClickScriptText() { | ||||
| 		$labelId    = $this->label->getId(true); | ||||
| 		$scriptText = " | ||||
| if (Event.ControlId == \"{$labelId}\") { | ||||
| 	declare Label_Picker <=> (Event.Control as CMlLabel); | ||||
| 	" . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker); | ||||
| }"; | ||||
| 		return $scriptText; | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user