setActionName($actionName); } if ($control) { $this->setControl($control); } if ($labelName) { $this->setLabelName($labelName); } } /** * Get the action to trigger * * @api * @return string */ public function getActionName() { return $this->actionName; } /** * Set the action to trigger * * @api * @param string $actionName Action name * @return static */ public function setActionName($actionName) { $this->actionName = (string)$actionName; return $this; } /** * Get the Control that should trigger the action * * @api * @return Control */ public function getControl() { return $this->control; } /** * Set the Control that should trigger the action * * @api * @param Control $control Action Control * @return static */ public function setControl(Control $control = null) { if ($control) { $control->checkId(); if ($control instanceof Scriptable) { $control->setScriptEvents(true); } } $this->control = $control; return $this; } /** * Get the script label name * * @api * @return string */ public function getLabelName() { return $this->labelName; } /** * Set the script label name * * @api * @param string $labelName Script Label name * @return static */ public function setLabelName($labelName) { $this->labelName = (string)$labelName; return $this; } /** * @see ScriptFeature::prepare() */ public function prepare(Script $script) { $script->appendGenericScriptLabel($this->labelName, $this->getScriptText()); return $this; } /** * Get the script text * * @return string */ protected function getScriptText() { $actionName = Builder::escapeText($this->actionName); if ($this->control) { // Control event $controlId = Builder::escapeText($this->control->getId()); $scriptText = " if (Event.Control.ControlId == {$controlId}) { TriggerPageAction({$actionName}); }"; } else { // Other $scriptText = " TriggerPageAction({$actionName});"; } return $scriptText; } }