1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149:
<?php
namespace Nethgui\Widget\Xhtml;
class Button extends \Nethgui\Widget\XhtmlWidget
{
protected function getJsWidgetTypes()
{
return array_merge(array('Nethgui:inputcontrol'), parent::getJsWidgetTypes());
}
private function getDefaultValue($name) {
if(! isset($this->view[$name])) {
return NULL;
}
$value = $this->view[$name];
if($value instanceof \Nethgui\View\ViewInterface) {
return $value->getModuleUrl();
}
return $value;
}
protected function renderContent()
{
$name = $this->getAttribute('name');
$flags = $this->getAttribute('flags');
$label = $this->getAttribute('label', $this->getTranslateClosure($name . '_label'));
$content = '';
$attributes = array();
$cssClass = 'Button';
if ($this->hasAttribute('receiver')) {
$attributes['id'] = $this->view->getUniqueId($this->getAttribute('receiver'));
} else {
$attributes['id'] = FALSE;
}
if ($flags & (\Nethgui\Renderer\WidgetFactoryInterface::BUTTON_LINK | \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_CANCEL | \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_HELP)) {
$value = $this->getAttribute('value', $this->getDefaultValue($name));
if (empty($value)) {
$value = '';
} elseif (is_array($value)) {
$label = $value[1];
$value = $value[0];
}
if ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_CANCEL) {
$cssClass .= ' cancel';
$flags |= \Nethgui\Renderer\WidgetFactoryInterface::STATE_UNOBTRUSIVE;
} elseif ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_HELP) {
if ($value === '') {
$value = $this->view->getModuleUrl('/Help/Read/' . \Nethgui\array_head($this->view->getModulePath()) . '.html');
}
$cssClass .= ' Help';
} else {
$cssClass .= ' link ' . $this->getClientEventTarget();
}
if ($flags & \Nethgui\Renderer\WidgetFactoryInterface::STATE_DISABLED) {
$cssClass .= ' disabled';
$tag = 'span';
} else {
$attributes['href'] = $value;
$tag = 'a';
}
$attributes['class'] = $cssClass;
$attributes['title'] = $this->getAttribute('title', FALSE);
$content .= $this->openTag($tag, $attributes);
$content .= htmlspecialchars($label);
$content .= $this->closeTag($tag);
} else {
if ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_SUBMIT) {
$attributes['type'] = 'submit';
$cssClass .= ' submit';
} elseif ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_RESET) {
$attributes['type'] = 'reset';
$cssClass .= ' reset';
} elseif ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_CUSTOM) {
$attributes['type'] = 'button';
$cssClass .= ' custom';
} elseif ($flags & \Nethgui\Renderer\WidgetFactoryInterface::BUTTON_DROPDOWN) {
$attributes['type'] = 'button';
$attributes['name'] = FALSE;
$cssClass .= ' dropdown';
$childContent = $this->renderChildren();
}
$attributes['value'] = $label;
$content .= $this->controlTag('button', $name, $flags, $this->getAttribute('class', $cssClass), $attributes);
if (isset($childContent)) {
$content .= $childContent;
}
}
if($this->canEscapeUnobstrusive($flags)) {
return $this->escapeUnobstrusive($content);
}
return $content;
}
public function executeCommand(\Nethgui\View\ViewInterface $origin, $selector, $name, $arguments)
{
$this->getLog()->deprecated(sprintf("%%s %%s: %s() command is DEPRECATED on Xhtml widget!", __CLASS__, $name));
switch ($name) {
case 'setLabel':
$this->setAttribute('label', $arguments[0]);
break;
default:
parent::executeCommand($origin, $selector, $name, $arguments);
}
}
}