diff --git a/doc/examples/widgets/index.php b/doc/examples/widgets/index.php new file mode 100644 index 0000000000..888b2de60e --- /dev/null +++ b/doc/examples/widgets/index.php @@ -0,0 +1,38 @@ +add(Primitive::string('name')->required()) + ->add(Primitive::boolean('like')); + $form->import($request->getGet()); + + $widget = FormWidget::create() + ->setActionUrl('') + ->setMethod(FormWidget::METHOD_GET) + ->addAction(ActionWidget::create('do')->setContent('Submit')) + ->addField(InputWidget::create('name')->setLabel('My name is')) + ->addField(CheckBoxWidget::create('like')->setLabel('and I like onPHP')) + ->importForm($form); + + $page = PageWidget::create() + ->setTitle($form->get('name')->isImported() ? ('Hello, ' . $form->get('name')->getValue()) : 'OnPHP — Widget example page') + ->setContent($widget); + + return $page; + } + + } + + $request = HttpRequest::create()->setGet($_GET)->setPost($_POST); + $controller = new Example(); + $widget = $controller->handleRequest($request); + echo $widget; + +?> + + diff --git a/global.inc.php.tpl b/global.inc.php.tpl index 7b1b39f9f2..5fef1219d0 100644 --- a/global.inc.php.tpl +++ b/global.inc.php.tpl @@ -79,7 +79,7 @@ define('ONPHP_UI_PATH', ONPHP_ROOT_PATH.'UI'.DIRECTORY_SEPARATOR); define('ONPHP_SOURCE_PATH', ONPHP_ROOT_PATH.'source'.DIRECTORY_SEPARATOR); // Default widgets templates is bootstrap - define ('ONPHP_UI_DEFAULT_WTEMPLATES_PATH', ONPHP_SOURCE_PATH.'template'.DIRECTORY_SEPARATOR.'widget'.DIRECTORY_SEPARATOR.'bootstrap'.DIRECTORY_SEPARATOR); + define ('ONPHP_UI_DEFAULT_WTEMPLATES_PATH', ONPHP_SOURCE_PATH.'template'.DIRECTORY_SEPARATOR.'widget'.DIRECTORY_SEPARATOR); if (!defined('ONPHP_META_PATH')) define( @@ -158,13 +158,10 @@ .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Filter'.PATH_SEPARATOR .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Helper'.PATH_SEPARATOR .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'View'.PATH_SEPARATOR - .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widgets'.PATH_SEPARATOR - .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widgets'.DIRECTORY_SEPARATOR.'Base'.PATH_SEPARATOR - .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widgets'.DIRECTORY_SEPARATOR.'Html'.PATH_SEPARATOR - .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widgets'.DIRECTORY_SEPARATOR.'Utils'.PATH_SEPARATOR - .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widgets'.DIRECTORY_SEPARATOR.'Making'.PATH_SEPARATOR - .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widgets'.DIRECTORY_SEPARATOR.'Tables'.PATH_SEPARATOR - .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widgets'.DIRECTORY_SEPARATOR.'Forms'.PATH_SEPARATOR + .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widget'.PATH_SEPARATOR + .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widget'.DIRECTORY_SEPARATOR.'Factory'.PATH_SEPARATOR + .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widget'.DIRECTORY_SEPARATOR.'Form'.PATH_SEPARATOR + .ONPHP_MAIN_PATH.'UI'.DIRECTORY_SEPARATOR.'Widget'.DIRECTORY_SEPARATOR.'Html'.PATH_SEPARATOR .ONPHP_MAIN_PATH.'Utils' .PATH_SEPARATOR .ONPHP_MAIN_PATH.'Utils'.DIRECTORY_SEPARATOR.'TuringTest'.PATH_SEPARATOR diff --git a/main/Markup/Html/HtmlElement.class.php b/main/Markup/Html/HtmlElement.class.php new file mode 100644 index 0000000000..2d92e246f7 --- /dev/null +++ b/main/Markup/Html/HtmlElement.class.php @@ -0,0 +1,290 @@ + + */ + class HtmlElement extends SgmlTag implements ToString + { + /** + * Regular expression for names of tags that must always be empty (i.e. may not have closing tag). + */ + const ALWAYS_EMPTY = '/^(area|base|basefont|br|col|frame|hr|img|input|isindex|link|meta|param)$/i'; + + private $sgml = null; + private $classes = array(); + private $innerHtml = ''; + + public function __construct($tagName = 'div') + { + $this->sgml = new SgmlOpenTag(); + $this->sgml->setEmpty(false); + $this->setTagName($tagName); + } + + public static function create($tagName = 'div') + { + return new static($tagName); + } + + /** + * Whether this element can have closing tag or must always be empty. + * + * @return bool + * @see ALWAYS_EMPTY + */ + public function isAlwaysEmpty() + { + return (bool)preg_match(self::ALWAYS_EMPTY, $this->getTagName()); + } + + public function setTagName($id) + { + $this->sgml->setId($id); + return $this; + } + + public function getTagName() + { + return $this->sgml->getId(); + } + + public static function attrName($name) + { + Assert::isString($name, 'HTML attribute name must be string, but ' . gettype($name) . ' given'); + return htmlspecialchars(trim($name)); + } + + public static function attrValue($value) + { + $value = strval($value); + return htmlspecialchars($value); + } + + public function setAttributesList(array $attrs) + { + foreach ($attrs as $name => $value) { + $this->setAttribute($name, $value); + } + return $this; + } + + /** + * @param string $name + * @param mixed $value Standard string (or stringable) value, + * FALSE to drop the attribute, + * or TRUE to set the boolean attribute (e.g. 'checked', 'disabled') + * @return HtmlElement + */ + public function setAttribute($name, $value) + { + $name = self::attrName($name); + if (strtolower($name) === 'class') { + $this->dropClassesList()->addClass($value); + } elseif (false === $value) { + if ($this->hasAttribute($name)) { + $this->dropAttribute($name); + } + } else { + $this->sgml->setAttribute($name, (true === $value) ? $name : self::attrValue($value)); + } + return $this; + } + + public function hasAttribute($name) + { + $name = self::attrName($name); + return (strtolower($name) === 'class') ? !empty($this->classes) : $this->sgml->hasAttribute($name); + } + + public function getAttribute($name) + { + $name = self::attrName($name); + return (strtolower($name) === 'class') ? $this->getClassesList(true) : $this->sgml->getAttribute($name); + } + + public function dropAttribute($name) + { + foreach (func_get_args() as $name) { + $name = self::attrName($name); + if (strtolower($name) === 'class') { + $this->dropClassesList(); + } else { + $this->sgml->dropAttribute($name); + } + } + return $this; + } + + public function getAttributesList($asString = false) + { + $attrs = $this->sgml->getAttributesList(); + if ($classes = $this->getAttribute('class')) { + $attrs['class'] = $classes; + } + if ($asString) { + $arr = array(); + foreach ($attrs as $name => $value) { + $arr[] = $name . '="' . $value . '"'; + } + $attrs = implode(' ', $arr); + } + return $attrs; + } + + public function dropAttributesList() + { + $this->sgml->dropAttributesList(); + $this->dropClassesList(); + return $this; + } + + public function addClass($name) + { + foreach (func_get_args() as $name) { + Assert::isTrue( + is_string($name) or is_array($name), + 'Classes must be passed as strings or arrays, but ' . gettype($name) . ' is given' + ); + if (is_array($name)) { + foreach ($name as $n) { + $this->addClass($n); + } + } else { + foreach (explode(' ', $name) as $n) { + $this->classes[self::attrValue($n)] = true; + } + } + } + return $this; + } + + public function dropClass($name) + { + foreach (func_get_args() as $name) { + Assert::isTrue( + is_string($name) or is_array($name), + 'Classes must be passed as strings or arrays, but ' . gettype($name) . ' is given' + ); + if (is_array($name)) { + foreach ($name as $n) { + $this->dropClass($n); + } + } else { + foreach (explode(' ', $name) as $n) { + $n = self::attrValue($n); + if (isset($this->classes[$n])) { + unset($this->classes[$n]); + } + } + } + } + return $this; + } + + public function hasClass($name) + { + return isset($this->classes[self::attrValue($name)]); + } + + public function dropClassesList() + { + $this->classes = array(); + return $this; + } + + public function getClassesList($asString = false) + { + $classes = array_keys($this->classes); + if ($asString) { + $classes = implode(' ', $classes); + } + return $classes; + } + + + /** + * @param string|ToString $html + * @return $this + */ + public function setInnerHtml($html) + { + Assert::isFalse( + $this->isAlwaysEmpty(), + $this->getTagName() . ' cannot have innerHTML' + ); + $this->innerHtml = strval($html); + return $this; + } + + /** + * @return string + */ + public function getInnerHtml() + { + Assert::isFalse( + $this->isAlwaysEmpty(), + $this->getTagName() . ' cannot have innerHTML' + ); + return $this->innerHtml; + } + + /** + * Get {@link SgmlOpenTag} representation of this HTML element. + * To be used with {@link HtmlAssembler}. + * + * @return SgmlOpenTag + */ + public function getOpenSgml() + { + if ($this->hasAttribute('class')) { + $this->sgml->setAttribute('class', $this->getAttribute('class')); + } else if ($this->sgml->hasAttribute('class')) { + $this->sgml->dropAttribute('class'); + } + return $this->sgml; + } + + /** + * Get {@link SgmlEndTag} that corresponds with {@link SgmlOpenTag} retrieved by {@link getOpenSgml()}. + * To be used with {@link HtmlAssembler}. + * + * @return SgmlEndTag|null Corresponding end tag, or NULL if not availbale + * @see isAlwaysEmpty() + */ + public function getEndSgml() + { + return $this->isAlwaysEmpty() ? null : SgmlEndTag::create()->setId($this->getTagName()); + } + + /** + * Get string representation of opening tag. + * + * @return string HTML + */ + public function open() + { + return HtmlAssembler::makeTag($this->getOpenSgml()); + } + + /** + * Get string representation of closing tag (if available) + * + * @return string HTML code, or empty string + */ + public function close() + { + $end = $this->getEndSgml(); + return $end ? HtmlAssembler::makeTag($end) : ''; + } + + public function __toString() + { + return $this->open() . ($this->isAlwaysEmpty() ? '' : $this->getInnerHtml()) . $this->close(); + } + + } diff --git a/main/UI/Widget/BaseWidget.class.php b/main/UI/Widget/BaseWidget.class.php new file mode 100644 index 0000000000..f773c972f8 --- /dev/null +++ b/main/UI/Widget/BaseWidget.class.php @@ -0,0 +1,71 @@ + + */ + abstract class BaseWidget extends ModelAndView implements IfaceWidget + { + /** + * Factory alias for constructor + * + * @static + * @return $this|ModelAndView + */ + public static function create() { + $factory = new ReflectionClass(get_called_class()); + return $factory->newInstanceArgs(func_get_args()); + } + + /** + * Capture {@link render()} and return the string + * + * @return string + * @see render() + */ + final public function __toString() { + try { + ob_start(); + $this->prepare(); + $this->getView()->render($this->getModel()); + return ob_get_clean(); + } catch (Exception $ex) { + return strval($ex); + } + } + + /** + * Get view object + * + * Note, that when you set template file name using {@link setView} + * (as you typically would) this method will resolve it to + * ready-to-use View object. + * + * @return View + */ + public function getView() { + $view = parent::getView(); + $view = is_string($view) ? Widget::resolveView($this, $view) : $view; + return $view; + } + + /** + * Prepare this object for rendering + * + * Typically you will override this method + * to fill {@link model() aggregated model} + * with custom private or protected data. + * + * This method is called in the very beginning of {@link __toString()} + * + * @return $this + * @see __toString() + */ + protected function prepare() { + return $this; + } + } diff --git a/main/UI/Widget/Form/ActionWidget.class.php b/main/UI/Widget/Form/ActionWidget.class.php new file mode 100644 index 0000000000..b283f7b3bf --- /dev/null +++ b/main/UI/Widget/Form/ActionWidget.class.php @@ -0,0 +1,32 @@ + element inside form. + * + * @author Peter Vyazovetskiy + */ + class ActionWidget extends FieldWidget + { + public function __construct($name) { + parent::__construct($name); + $this + ->setView('form/action') + ->setTagName('button'); + } + + public function setContent($stringable) { + $this->setInnerHtml(strval($stringable)); + return $this; + } + + protected function prepare() { + parent::prepare(); + + // Only 'submit' buttons should be form actions + // 'reset' buttons are evil, and default 'button' buttons + // have nothing to do with forms + $this->setAttribute('type', 'submit'); + + return $this; + } + + } diff --git a/main/UI/Widget/Form/CheckBoxWidget.class.php b/main/UI/Widget/Form/CheckBoxWidget.class.php new file mode 100644 index 0000000000..04bcabdcc9 --- /dev/null +++ b/main/UI/Widget/Form/CheckBoxWidget.class.php @@ -0,0 +1,40 @@ + element. + * + * @author Peter Vyazovetskiy + */ + class CheckBoxWidget extends FieldWidget + { + public function __construct($name) { + parent::__construct($name); + $this + ->setView('form/check-box') + ->setTagName('input') + ->setAttribute('type', 'checkbox'); + } + + public function setChecked($checked = true) { + $this->setAttribute('checked', (bool)$checked); + return $this; + } + + public function prepare() { + parent::prepare(); + $this->setAttribute('value', $this->getValue()); + return $this; + } + + public function importPrimitive(BasePrimitive $primitive) + { + parent::importPrimitive($primitive); + if ($primitive instanceof PrimitiveBoolean) { + $this + ->setValue(false) + ->setChecked($primitive->getValue()); + } + return $this; + } + + + } diff --git a/main/UI/Widget/Form/FieldWidget.class.php b/main/UI/Widget/Form/FieldWidget.class.php new file mode 100644 index 0000000000..91c4f2c671 --- /dev/null +++ b/main/UI/Widget/Form/FieldWidget.class.php @@ -0,0 +1,163 @@ + + */ + abstract class FieldWidget extends HtmlWidget + { + /** + * @var mixed + */ + private $value = null; + + public function __construct($name) { + parent::__construct(); + $this + ->setDescription('') + ->setError(null) + ->setLabel($name) + ->setName($name) + ->setDisabled(false) + ->setReadOnly(false) + ->setAutoFocus(false) + ->setTabIndex(false) + ; + } + + public function setRequired($required = true) + { + $this->setAttribute('required', (bool)$required); + return $this; + } + + public function setName($name) + { + $this->setAttribute('name', $name); + return $this; + } + + public function getName() { + return $this->getAttribute('name'); + } + + public function setValue($value) + { + $this->value = $value; + return $this; + } + + public function getValue() { + return $this->value; + } + + public function setLabel($label) { + $this->getModel()->set('label', $label); + return $this; + } + + public function getLabel() { + $model = $this->getModel(); + return $model->has('label') ? $model->get('label') : ''; + } + + public function setDescription($description) { + $this->getModel()->set('description', $description); + return $this; + } + + public function getDescription() { + $model = $this->getModel(); + return $model->has('description') ? $model->get('description') : ''; + } + + public function setError($error) { + $this->getModel()->set('error', $error); + return $this; + } + + public function getError() { + $model = $this->getModel(); + return $model->has('error') ? $model->get('error') : null; + } + + public function setDisabled($disabled = true) + { + $this->setAttribute('disabled', (bool)$disabled); + return $this; + } + + public function setReadOnly($readOnly = true) + { + $this->setAttribute('readonly', (bool)$readOnly); + return $this; + } + + public function setAutoFocus($autoFocus = true) { + $this->setAttribute('autofocus', (bool)$autoFocus); + return $this; + } + + /** + * Set 'tabIndex' attribute. + * + * To avoid collapse this method adjusts global {@link autoTabIndex()) sequence + * to be greater then last numeric argument. + * + * @param mixed $index NULL to set {@link autoTabIndex() auto-generated index}, + * FALSE to drop attribute value, + * or explicit integer value + * @return $this + * @see autoTabIndex() + */ + public function setTabIndex($index = null) + { + if (is_null($index)) { + // Auto + $index = self::autoTabIndex(); + } else if (false === $index) { + // Drop + $this->setAttribute('tabindex', false); + } else { + // Check + Assert::isTrue( + is_numeric($index), + 'Attribute "tabIndex" expects numeric value, but ' . gettype($index) . ' given' + ); + // Asjust auto-sequence + self::$autoTabIndex = max(self::$autoTabIndex, $index); + // Set + $this->setAttribute('tabindex', intval($index)); + } + return $this; + } + + private static $autoTabIndex = 1000; + + /** + * @static + * @return mixed + */ + final public static function autoTabIndex() + { + return ++self::$autoTabIndex; + } + + /** + * Import data from logical primitive + * + * @param BasePrimitive $primitive + * @return $this + */ + public function importPrimitive(BasePrimitive $primitive) { + $this + ->setName($primitive->getName()) + ->setValue($primitive->getValue()) + ->setRequired($primitive->isRequired()) + ->setError($primitive->getError()); + return $this; + } + + } diff --git a/main/UI/Widget/Form/FormWidget.class.php b/main/UI/Widget/Form/FormWidget.class.php new file mode 100644 index 0000000000..6b9dbb1d99 --- /dev/null +++ b/main/UI/Widget/Form/FormWidget.class.php @@ -0,0 +1,106 @@ + + */ + class FormWidget extends HtmlWidget + { + + const METHOD_GET = 'GET'; + const METHOD_POST = 'POST'; + const ENCTYPE_DEFAULT = 'application/x-www-form-urlencoded'; + const ENCTYPE_UPLOAD = 'multipart/form-data'; + const ENCTYPE_RAW = 'text/plain'; + const TARGET_BLANK = '_blank'; + const TARGET_SELF = '_self'; + const TARGET_PARENT = 'parent'; + const TARGET_TOP = '_top'; + + /** + * @var array Prepared field widgets + * @see setField(), getField() + */ + private $fields = array(); + + /** + * @var array Form actions + */ + private $actions = array(); + + public function __construct() { + parent::__construct(); + $this + ->setView('form/form') + ->setTagName('form') + ->setMethod(self::METHOD_POST) + ->setEnctype(self::ENCTYPE_DEFAULT) + ->setTarget(self::TARGET_SELF) + ->setActionUrl(''); + } + + public function setMethod($method) { + $this->setAttribute('method', $method); + return $this; + } + + public function setEnctype($enctype) { + $this->setAttribute('enctype', ($enctype === self::ENCTYPE_DEFAULT) ? false : $enctype); + return $this; + } + + public function setTarget($target) { + $this->setAttribute('target', ($target === self::TARGET_SELF) ? false : $target ); + return $this; + } + + public function setActionUrl($url) { + $this->setAttribute('action', strval($url)); + return $this; + } + + // TODO: single nameless action + public function addAction(ActionWidget $action) { + $this->actions[$action->getName()] = $action; + return $this; + } + + public function getAction($name) { + return $this->actions[$name]; + } + + public function addField(FieldWidget $widget) { + $this->fields[$widget->getName()] = $widget; + return $this; + } + + /** + * @param $name + * @return FieldWidget + */ + public function getField($name) { + return $this->fields[$name]; + } + + /** + * @param Form $form + * @return $this + * + * @see FieldWidget::importPrimitive + */ + public function importForm(Form $form) { + foreach($this->fields as $name => $field) { + if ($form->exists($name)) { + $field->importPrimitive($form->get($name)); + } + } + return $this; + } + + protected function prepare() { + parent::prepare(); + $this->getModel() + ->set('fields', $this->fields) + ->set('actions', $this->actions); + return $this; + } + + } diff --git a/main/UI/Widget/Form/InputWidget.class.php b/main/UI/Widget/Form/InputWidget.class.php new file mode 100644 index 0000000000..799a7c4e39 --- /dev/null +++ b/main/UI/Widget/Form/InputWidget.class.php @@ -0,0 +1,38 @@ + element. + * + * @author Peter Vyazovetskiy + */ + class InputWidget extends FieldWidget + { + public function __construct($name) { + parent::__construct($name); + $this + ->setView('form/input') + ->setTagName('input') + ->setInputType('text'); + } + + public function setMaxLength($length) { + $this->setAttribute('maxlength', (false === $length) ? false : intval($length)); + return $this; + } + + public function setPlaceholder($placeholder) { + $this->setAttribute('placeholder', $placeholder); + return $this; + } + + public function setInputType($type) { + $this->setAttribute('type', $type); + return $this; + } + + public function prepare() { + parent::prepare(); + $this->setAttribute('value', $this->getValue()); + return $this; + } + + } diff --git a/main/UI/Widget/Form/SelectWidget.class.php b/main/UI/Widget/Form/SelectWidget.class.php new file mode 100644 index 0000000000..3f89b507f3 --- /dev/null +++ b/main/UI/Widget/Form/SelectWidget.class.php @@ -0,0 +1,52 @@ + element. + * + * @author Peter Vyazovetskiy + */ + class SelectWidget extends FieldWidget + { + private $options = array(); + + public function __construct($name) { + parent::__construct($name); + $this + ->setView('form/select') + ->setTagName('select') + ->setOptionsList(array()); + } + + public function setValue($value) { + $value = empty($value) ? array() : is_array($value) ? $value : (array)$value; + Assert::isTrue( + $this->isMultiple() or (count($value) <= 1), + 'This instance of select widget does not allow multiple values' + ); + parent::setValue($value); + return $this; + } + + public function setMultiple($multiple = true) { + $this->setAttribute('multiple', (bool)$multiple); + return $this; + } + + public function isMultiple() { + return $this->hasAttribute('multiple'); + } + + public function setOptionsList(array $options) { + $this->options = $options; + return $this; + } + + protected function prepare() { + parent::prepare(); + $this->setAttribute('value', false); + $this->getModel() + ->set('options', $this->options) + ->set('values', $this->getValue()); + return $this; + } + + } diff --git a/main/UI/Widget/Form/TextAreaWidget.class.php b/main/UI/Widget/Form/TextAreaWidget.class.php new file mode 100644 index 0000000000..522808fed9 --- /dev/null +++ b/main/UI/Widget/Form/TextAreaWidget.class.php @@ -0,0 +1,37 @@ + element. + * + * @author Peter Vyazovetskiy + */ + class TextAreaWidget extends FieldWidget + { + public function __construct($name) { + parent::__construct($name); + $this + ->setView('form/text-area') + ->setTagName('textarea'); + } + + public function setRows($rows) { + $this->setAttribute('rows', (false === $rows) ? false : intval($rows)); + return $this; + } + + public function setCols($cols) { + $this->setAttribute('cols', (false === $cols) ? false : intval($cols)); + return $this; + } + + public function setMaxLength($length) { + $this->setAttribute('maxlength', (false === $length) ? false : intval($length)); + return $this; + } + + public function prepare() { + parent::prepare(); + $this->setInnerHtml($this->getValue()); + return $this; + } + + } diff --git a/main/UI/Widget/Html/AWidget.class.php b/main/UI/Widget/Html/AWidget.class.php new file mode 100644 index 0000000000..0eb652d383 --- /dev/null +++ b/main/UI/Widget/Html/AWidget.class.php @@ -0,0 +1,32 @@ + element. + * + * @author Peter Vyazovetskiy + */ + class AWidget extends HtmlWidget + { + public function __construct() { + parent::__construct(); + $this + ->setView('html/a') + ->setTagName('a') + ->setContent('') + ->setHref(''); + } + + public function setHref($href) { + $href = strval($href); + $this->setAttribute('href', $href); + if (!$this->getInnerHtml()) { + $this->setInnerHtml($href); + } + return $this; + } + + public function setContent($stringable) { + $this->setInnerHtml(strval($stringable)); + return $this; + } + + } diff --git a/main/UI/Widget/Html/HtmlWidget.class.php b/main/UI/Widget/Html/HtmlWidget.class.php new file mode 100644 index 0000000000..65863d7922 --- /dev/null +++ b/main/UI/Widget/Html/HtmlWidget.class.php @@ -0,0 +1,90 @@ + + */ + abstract class HtmlWidget extends BaseWidget + { + /** + * @var HtmlElement + */ + private $html; + + public function __construct() + { + parent::__construct(); + $this->html = HtmlElement::create(); + $this->setView('html'); + } + + protected function prepare() { + $this->getModel()->set('html', $this->getHtml()); + return parent::prepare(); + } + + protected function getHtml() { + return $this->html; + } + + protected function setTagName($tag) { + $this->html->setTagName($tag); + return $this; + } + + protected function getTagName() { + return $this->html->getTagName(); + } + + protected function setInnerHtml($html) { + $this->html->setInnerhtml($html); + return $this; + } + + protected function getInnerHtml() { + return $this->html->getInnerHtml(); + } + + public function addClass($name) { + call_user_func_array(array($this->html, __METHOD__), func_get_args()); + return $this; + } + + public function dropClass($name) { + call_user_func_array(array($this->html, __METHOD__), func_get_args()); + return $this; + } + + public function hasClass($name) { + return $this->html->hasClass($name); + } + + public function getClassesList($asString = false) { + return $this->html->getClassesList($asString); + } + + public function setAttribute($name, $value) { + $this->html->setAttribute($name, $value); + return $this; + } + + public function dropAttribute($name) { + $this->html->dropAttribute($name, $value); + return $this; + } + + public function hasAttribute($name) { + return $this->html->hasAttribute($name); + } + + public function getAttribute($name) { + return $this->html->getAttribute($name); + } + + public function setAttributesList(array $attrs) { + $this->html->setAttributesList($attrs); + return $this; + } + + + } diff --git a/main/UI/Widget/Html/ImgWidget.class.php b/main/UI/Widget/Html/ImgWidget.class.php new file mode 100644 index 0000000000..e2a59b75e0 --- /dev/null +++ b/main/UI/Widget/Html/ImgWidget.class.php @@ -0,0 +1,27 @@ + element. + * + * @author Peter Vyazovetskiy + */ + class ImgWidget extends HtmlWidget + { + public function __construct() { + parent::__construct(); + $this + ->setView('html/img') + ->setTagName('img') + ->setSrc('') + ->setAlt(''); + } + + public function setSrc($url) { + $this->setAttribute('src', strval($url)); + return $this; + } + + public function setAlt($alt) { + $this->setAttribute('alt', strval($alt)); + return $this; + } + } diff --git a/main/UI/Widget/Html/PageWidget.class.php b/main/UI/Widget/Html/PageWidget.class.php new file mode 100644 index 0000000000..5ac874c994 --- /dev/null +++ b/main/UI/Widget/Html/PageWidget.class.php @@ -0,0 +1,89 @@ + + */ + class PageWidget extends BaseWidget + { + public function __construct() { + parent::__construct(); + $this + ->setView('html/page') + ->setTitle('') + ->setContent(''); + } + + public function setTitle($title) { + $this->getModel()->set('title', $title); + return $this; + } + + public function setContent($stringable) { + $this->getModel()->set('content', $stringable); + return $this; + } + + protected function prepare() + { + parent::prepare(); + + // Execute content strictly before + // getStylesheets() and getScripts() + // to ensure that contained widgets + // register their resources + $content = strval($this->getModel()->get('content')); + + $this->getModel() + ->set('content', $content) + ->set('stylesheets', static::getStylesheets()) + ->set('scripts', static::getScripts()); + return $this; + } + + /////////////////////////////////////////// + // Global resource registry + + private static $stylesheets = array(); + private static $scripts = array(); + + /** + * Globally register stylesheet + * + * @static + * @param string $href Unique stylesheet URL (all duplicates will be merged) + * @param mixed $rel Stylesheet 'rel' type, or FALSE to let the method detect it automatically by file extension + */ + public static function addStylesheet($href, $rel = false) + { + static::$stylesheets[strval($href)] = strval($rel); + } + + /** + * @static + * @return array of 'href' => 'rel' + */ + public static function getStylesheets() + { + return static::$stylesheets; + } + + /** + * Globally register script + * + * @static + * @param string $src Unique script URL (all duplicates will be merged) + */ + public static function addScript($src) + { + static::$scripts[strval($src)] = true; + } + + /** + * @static + * @return array of script URLs + */ + public static function getScripts() + { + return array_keys(static::$scripts); + } + + } diff --git a/main/UI/Widget/IfaceWidget.class.php b/main/UI/Widget/IfaceWidget.class.php new file mode 100644 index 0000000000..c529d5d7f4 --- /dev/null +++ b/main/UI/Widget/IfaceWidget.class.php @@ -0,0 +1,13 @@ + + */ + interface IfaceWidget extends ToString + { + + } diff --git a/main/UI/Widget/Widget.class.php b/main/UI/Widget/Widget.class.php new file mode 100644 index 0000000000..872dc1b896 --- /dev/null +++ b/main/UI/Widget/Widget.class.php @@ -0,0 +1,112 @@ + + */ + final class Widget + { + + /////////////////////////////////////////////// + // Registry for view resolvers + + /** + * @var ViewResolver Defaults to {@link MultiPrefixPhpViewResolver} over {@link SimplePhpView} + */ + private static $defaultViewResolver; + + /** + * @var array Maps widget classes to view resolver objects + */ + private static $viewResolvers = array(); + + /** + * @static + * @return ViewResolver + */ + public static function getDefaultViewResolver() + { + return self::$defaultViewResolver ? self::$defaultViewResolver : self::setDefaultViewResolver(); + } + + /** + * Change or reset default view resolver. + * + * @static + * @param ViewResolver|null $viewResolver Resolver object, or NULL to reset default + * @return MultiPrefixPhpViewResolver New default resolver + */ + public static function setDefaultViewResolver($viewResolver = null) + { + if (!$viewResolver) { + $viewResolver = MultiPrefixPhpViewResolver::create() + ->setViewClassName('SimplePhpView') + ->setPostfix(EXT_TPL) + ->addPrefix(ONPHP_UI_DEFAULT_WTEMPLATES_PATH); + } + Assert::isTrue( + $viewResolver instanceof ViewResolver, + 'View resolver must implement "ViewResolver" interface' + ); + return self::$defaultViewResolver = $viewResolver; + } + + /** + * @static + * @param string|BaseWidget $widget Widget object or class name + * @return ViewResolver Associated or default resolver + */ + public static function getViewResolver($widget) + { + Assert::isInstance( + $widget, 'BaseWidget', + 'Widget expected, but ' . gettype($widget) . ' given' + ); + $name = is_object($widget) ? get_class($widget) : strval($widget); + return isset(self::$viewResolvers[$name]) + ? self::$viewResolvers[$name] + : self::getDefaultViewResolver(); + } + + /** + * @static + * @param string|BaseWidget $widget Widget object or class name + * @param ViewResolver|null $resolver Resolver object to associate with the widget, + * or NULL to reset current association to default resolver + * @see getDefaultViewResolver() + */ + public static function setViewResolver($widget, $resolver = null) + { + Assert::isInstance( + $widget, 'BaseWidget', + 'Widget expected, but ' . gettype($widget) . ' given' + ); + $name = is_object($widget) ? get_class($widget) : strval($widget); + if ($resolver) { + // Set + Assert::isTrue( + $resolver instanceof ViewResolver, + 'ViewResolver expected, but ' . gettype($resolver) . ' given' + ); + self::$viewResolvers[$name] = $resolver; + } else { + // Drop + if (isset(self::$viewResolvers[$name])) { + unset(self::$viewResolvers[$name]); + } + } + } + + /** + * Shorthand for self->getViewResolver()->resolveViewName(). + * + * @static + * @param string|BaseWidget $widget + * @param string $viewName + * @return View + */ + public static function resolveView($widget, $viewName) { + return self::getViewResolver($widget)->resolveViewName($viewName); + } + + } diff --git a/main/UI/Widgets/Base/BaseWidget.class.php b/main/UI/Widgets/Base/BaseWidget.class.php deleted file mode 100644 index 09b5bca0dd..0000000000 --- a/main/UI/Widgets/Base/BaseWidget.class.php +++ /dev/null @@ -1,203 +0,0 @@ -name = $name; - $this->model = new Model(); - } - - /** - * @return BaseWidget - */ - public function setTplName($tplName) - { - $this->tplName = (string)$tplName; - - return $this; - } - - /** - * @return BaseWidget - */ - public function setPrefix($prefix) - { - $this->tplPrefix = (string)$prefix; - - return $this; - } - - public function getTplName() - { - return $this->tplName; - } - - public function getTplPrefix() - { - return $this->tplPrefix - ? $this->tplPrefix.DIRECTORY_SEPARATOR - : null; - } - - /** - * @return BaseWidget - */ - public function setViewer(ViewResolver $resolver) - { - $this->resolver = $resolver; - - return $this; - } - - /** - * @return ViewResolver - */ - public function getResolver() - { - if ($this->resolver instanceof ViewResolver) - return $this->resolver; - - Assert::isInstance( - Widget::getViewResolver($this), 'ViewResolver', - 'Don`t set resolver, see Widget::setViewResolverMap() or Widget::setDefaultViewResolver()' - ); - - return Widget::getViewResolver($this); - } - - public function render($model = null, $merge=true) - { - echo $this->rendering($model, $merge); - } - - /** - * @return string result - */ - protected function rendering(/*Model*/$model = null, $merge=true) - { - $source = null; - ob_start(); - - $this->prepareModel(); - - try { - if ($model && $merge) { - $this->model->merge($model); - } - - $view = $this->getResolver()->resolveViewName( - $this->getTplPrefix().$this->tplName - ); - - $view->render($this->model); - - $source = ob_get_contents(); - } catch (WrongArgumentException $e) { - return $e->__toString(); - } catch (Exception $e) { - // TODO : прописать системный сервис информирования об ошибках - // использую разные стратегии информирования или цепочки, лог, почта, раббит.. - // а так же поведение, редирект на продакшине например - return($e->__toString()); - } - - ob_end_clean(); - - return $source; - } - - /** - * @return string - */ - public function toString() - { - return (string)$this->rendering(); - } - - /** - * @return string - */ - public function __toString() - { - return $this->toString(); - } - - /** - * @return BaseWidget - */ - public function setModel(Model $model) - { - $this->model = $model; - return $this; - } - - /** - * @return BaseWidget - */ - final public function mergeModel(Model $model, $owerwrite = false) - { - $this->model->merge($model, $owerwrite); - return $this; - } - - /** - * @return Model - */ - final public function getModel() - { - return $this->model; - } - /** - * @return Model - */ - protected function makeModel() - { - return $this->model->set('widgetName', $this->name); - } - - final protected function prepareModel() - { - $this->makeModel(); - - return $this->model-> - set( - 'parentModel', - $this->model->has('parentModel') - ? $this->model->get('parentModel') - : null - )-> - set( - 'rootModel', - $this->model->has('rootModel') - ? $this->model->get('rootModel') - : $this->model - ); - } -} - diff --git a/main/UI/Widgets/Base/IfaceWidget.class.php b/main/UI/Widgets/Base/IfaceWidget.class.php deleted file mode 100644 index 9d218a2b89..0000000000 --- a/main/UI/Widgets/Base/IfaceWidget.class.php +++ /dev/null @@ -1,19 +0,0 @@ -objects = $objects; - - return $this; - } - - /** - * @return Model - */ - protected function makeModel() - { - Assert::isNotEmpty($this->objects, "array 'objects' is empty"); - - $object = current($this->objects); - - Assert::isTrue($object instanceof Prototyped, 'Object is not Proto contents.'); - - if (empty($this->headerFields)) { - if ($object instanceof Prototyped) { - $fields = $object->proto()->getPropertyList(); - } - } else { - $fields = $this->headerFields; - } - - Assert::isNotEmpty($fields, "array 'fields of header' is empty. Set it or can use Prototyped 'objects'"); - - if ($this->filter instanceof IfaceFieldsFilter) { - $fields = $this->filter->setAllFields($fields)-> - getList(); - } - - $name = get_class($object); - - return parent::makeModel()-> - set('_objectName', $name)-> - set('_fields', $fields)-> - set('_filter', $this->filter)-> - set('_objects', $this->objects); - } - - /** - * You can specify which fields to display. - * - * @param IFieldsFilter $filter - * @return WidgetTable - */ - public function setFieldsFilter(IfaceFieldsFilter $filter) - { - $this->filter = $filter; - return $this; - } -} - diff --git a/main/UI/Widgets/Base/WidgetTableAction.class.php b/main/UI/Widgets/Base/WidgetTableAction.class.php deleted file mode 100644 index ceda769cf2..0000000000 --- a/main/UI/Widgets/Base/WidgetTableAction.class.php +++ /dev/null @@ -1,40 +0,0 @@ - Href::create(); - * save => Href::create(); - * ) - * @param array $array - */ - public function setActions(array $array) - { - $this->actions = $array; - - return $this; - } - - /** - * @return Model - */ - protected function makeModel() - { - return parent::makeModel()-> - set('_actions', $this->actions); - } -} - diff --git a/main/UI/Widgets/Base/WidgetTableSortable.class.php b/main/UI/Widgets/Base/WidgetTableSortable.class.php deleted file mode 100644 index 73140fa6df..0000000000 --- a/main/UI/Widgets/Base/WidgetTableSortable.class.php +++ /dev/null @@ -1,42 +0,0 @@ -sortField = $field; - $this->sortMode = $mode; - - return $this; - } - - protected function makeModel() - { - return parent::makeModel()-> - set('_sortField', $this->sortField)-> - set('_sortMode', $this->sortMode); - } -} - diff --git a/main/UI/Widgets/Forms/WBoolean.class.php b/main/UI/Widgets/Forms/WBoolean.class.php deleted file mode 100644 index 6ae21b17cc..0000000000 --- a/main/UI/Widgets/Forms/WBoolean.class.php +++ /dev/null @@ -1,24 +0,0 @@ -model->set('buttons', array()); - } - - /** - * @param WButton $button - */ - public function add(WButton $button) - { - $buttons = $this->model->get('buttons'); - $buttons[] = $button; - - $this->model->set('buttons', $buttons); - - return $this; - } - - - } \ No newline at end of file diff --git a/main/UI/Widgets/Forms/WCalendar.class.php b/main/UI/Widgets/Forms/WCalendar.class.php deleted file mode 100644 index d6bf7e6823..0000000000 --- a/main/UI/Widgets/Forms/WCalendar.class.php +++ /dev/null @@ -1,68 +0,0 @@ -setFormat($this->format); - } - - /** - * @example: d.m.Y - * @param string $format - * @return WCalendar - */ - public function setFormat($format) - { - $this->model->set('format', $format); - - return $this; - } - - /** - * @return Model - */ - protected function makeModel() - { - $value = $this->model->get('value'); - $format = $this->model->get('format'); - - if($value instanceof Date) - $this->setValue( - $value->toFormatString($format) - ); - elseif(is_scalar($value)) - $this->setValue( - Timestamp::create($value)->toFormatString($format) - ); - - - return parent::makeModel(); - } - - } diff --git a/main/UI/Widgets/Forms/WDropDownMenu.class.php b/main/UI/Widgets/Forms/WDropDownMenu.class.php deleted file mode 100644 index 4112fd6732..0000000000 --- a/main/UI/Widgets/Forms/WDropDownMenu.class.php +++ /dev/null @@ -1,46 +0,0 @@ -model->set('links', array()); - } - - /** - * @param WButton $button - */ - public function add(WLink $link) - { - $links = $this->model->get('links'); - $links[] = $link; - - $this->model->set('links', $links); - - return $this; - } - - - } \ No newline at end of file diff --git a/main/UI/Widgets/Forms/WEditForm.class.php b/main/UI/Widgets/Forms/WEditForm.class.php deleted file mode 100644 index 3b5c9ce7c9..0000000000 --- a/main/UI/Widgets/Forms/WEditForm.class.php +++ /dev/null @@ -1,90 +0,0 @@ -setForm($form); - } - - /** - * @param array $map - * array( 'primitiveName' => 'label' ) - * - * @return WEditForm - */ - public function setFieldsMap(array $map) - { - $this->map = $map; - return $this; - } - - /** - * @param IFieldsFilter $filter - * @return WidgetTable - */ - public function setFieldsFilter(IfaceFieldsFilter $filter) - { - $this->filter = $filter; - return $this; - } - - /** - * @return Model - */ - protected function makeModel() - { - $primitives = $this->model->get('form')->getPrimitiveList(); - - if($this->filter) - $primitives = $this->filter->setFields(array_keys( $this->map ))->apply($primitives); - - $fields = array(); - - foreach($primitives as $name => $prm) - { - $w = WMaker::make($prm); - $w->setLabel( - $this->map[$name] - ); - - $fields[]=$w; - } - - $this->model->set('fields', $fields); - - return parent::makeModel(); - } - - /** - * @return WEditForm - */ - public function setForm(Form $form) - { - $this->model->set('form', $form); - - return $this; - } -} - diff --git a/main/UI/Widgets/Forms/WFormBegin.class.php b/main/UI/Widgets/Forms/WFormBegin.class.php deleted file mode 100644 index 81bad02330..0000000000 --- a/main/UI/Widgets/Forms/WFormBegin.class.php +++ /dev/null @@ -1,105 +0,0 @@ -model->set('caption', null); - $this->model->set('description', null); - $this->model->set('action', null); - $this->model->set('method', 'GET'); - $this->model->set('enctype', 'multipart/form-data'); - } - - /** - * @return WFormBegin - */ - public function setAction($action) - { - $this->model->set('action', $action); - - return $this; - } - - /** - * @return WFormBegin - **/ - public function setMethod($method) - { - $this->model->set('method', $method); - - return $this; - } - - /** - * @return WFormBegin - **/ - public function setEnctype($enctype) - { - $this->model->set('enctype', $enctype); - - return $this; - } - - /** - * @return WFormBegin - **/ - public function setCaption($caption) - { - $this->model->set('caption', $caption); - - return $this; - } - - /** - * @return WFormBegin - */ - public function setDescription($description) - { - $this->model->set('description', $description); - - return $this; - } - - /** - * @return Model - */ - protected function makeModel() - { - return parent::makeModel(); - } - } - diff --git a/main/UI/Widgets/Forms/WFormElement.class.php b/main/UI/Widgets/Forms/WFormElement.class.php deleted file mode 100644 index 038cf9813a..0000000000 --- a/main/UI/Widgets/Forms/WFormElement.class.php +++ /dev/null @@ -1,93 +0,0 @@ -model-> - set('required', '')-> - set('disabled', '')-> - set('label', '')-> - set('name', $this->name)-> - set('message', ''); - } - - /** - * @param $name - * @return WFormElement - */ - public function setName($name) - { - $this->model->set('name', $name); - - return $this; - } - - /** - * - * @param boolean $required - * @return WFormElement - */ - public function setRequired($required = true) - { - $this->model->set('required', $required); - return $this; - } - - /** - * - * @param boolean $disabled - * @return WFormElement - */ - public function setDisabled($disabled = true) - { - $this->model->set('disabled', $disabled); - return $this; - } - /** - * - * @param string $label - * @return WFormElement - */ - public function setLabel($label) - { - $this->model->set('label', $label); - return $this; - } - - /** - * - * @param mixed $value - * @return WFormElement - */ - public function setMessage($value) - { - $this->model->set('message', $value); - return $this; - } -} diff --git a/main/UI/Widgets/Forms/WFormEnd.class.php b/main/UI/Widgets/Forms/WFormEnd.class.php deleted file mode 100644 index 2e5b9f3789..0000000000 --- a/main/UI/Widgets/Forms/WFormEnd.class.php +++ /dev/null @@ -1,25 +0,0 @@ -model->set('isMulti', null); - } - - /** - * @param array $list - * @return WSelect - */ - public function setList(array $list) - { - $this->model->set('list', $list); - - return $this; - } - - public function setMulti($boolean) - { - $this->model->set('isMulti', ($boolean === true)); - - return $this; - } - - /** - * @return Model - */ - protected function makeModel() - { - return parent::makeModel(); - } - - } \ No newline at end of file diff --git a/main/UI/Widgets/Forms/WTernary.class.php b/main/UI/Widgets/Forms/WTernary.class.php deleted file mode 100644 index eb815f756b..0000000000 --- a/main/UI/Widgets/Forms/WTernary.class.php +++ /dev/null @@ -1,65 +0,0 @@ -setTrueValue(1); - $this->setFalseValue(0); - } - - /** - * @param type $value - * @return WTernary - */ - public function setTrueValue($value) - { - $this->model->set('trueValue', $value); - - return $this; - } - - /** - * @param type $value - * @return WTernary - */ - public function setFalseValue($value) - { - $this->model->set('falseValue', $value); - - return $this; - } - - /** - * @return Model - */ - protected function makeModel() - { - return parent::makeModel(); - } - } diff --git a/main/UI/Widgets/Forms/WTextArea.class.php b/main/UI/Widgets/Forms/WTextArea.class.php deleted file mode 100644 index 21190e00c8..0000000000 --- a/main/UI/Widgets/Forms/WTextArea.class.php +++ /dev/null @@ -1,27 +0,0 @@ - diff --git a/main/UI/Widgets/Html/HtmlTable.class.php b/main/UI/Widgets/Html/HtmlTable.class.php deleted file mode 100644 index cd2ce5605b..0000000000 --- a/main/UI/Widgets/Html/HtmlTable.class.php +++ /dev/null @@ -1,23 +0,0 @@ - 'makeByBasePrimitive', // Default - - 'PrimitiveDate' => 'makeByPrimitiveDate', - 'PrimitiveTime' => 'makeByPrimitiveTime', - 'PrimitiveString' => 'makeByPrimitiveString', - 'PrimitiveBoolean' => 'makeByPrimitiveBoolean', - 'PrimitiveTernary' => 'makeByPrimitiveTernary', - 'PrimitiveEnumeration' => 'makeByPrimitiveEnumeration', - 'PrimitiveEnumerationList' => 'makeByPrimitiveEnumerationList', - 'PrimitiveEnum' => 'makeByPrimitiveEnum', - 'PrimitiveEnumList' => 'makeByPrimitiveEnumList', - - 'PrimitiveIdentifier' => 'makeByPrimitiveIdentifier', - ); - - /** - * @static - * @return WDefaultPrimitiveMakeStrategy - */ - public static function me() - { - return Singleton::getInstance(__CLASS__); - } - - - /** - * @static - * @param WFormElement $widget - * @param BasePrimitive $primitive - * @return WFormElement - */ - function fill(WFormElement $widget, BasePrimitive $primitive) - { - return $widget->setLabel( - $primitive->getName() - )->setRequired( - $primitive->isRequired() - )->setName( - $primitive->getName() - ); - } - - /** - * @static - * @param BasePrimitive $primitive - * @return WTextField - */ - protected function makeByBasePrimitive(BasePrimitive $primitive) - { - return $this->fill( - WTextField::create()->setValue($primitive->getValue()), - $primitive - ); - } - - - /** - * @static - * @param PrimitiveDate $primitive - * @return WCalendar - */ - protected function makeByPrimitiveDate(PrimitiveDate $primitive) - { - return $this->fill( - WCalendar::create()->setValue($primitive->getValue()), - $primitive - ); - } - - /** - * @static - * @param PrimitiveTime $primitive - * @return WCalendar - */ - protected function makeByPrimitiveTime(PrimitiveTime $primitive) - { - return $this->fill( - WCalendar::create()->setFormat('d.m.Y h:i')->setValue($primitive->getValue()), - $primitive - ); - } - - /** - * @static - * @param PrimitiveString $primitive - * @return WTextField|WTextArea - */ - protected function makeByPrimitiveString(PrimitiveString $primitive) - { - $w = null; - - if($primitive->getMax() > 255) - $w = WTextArea::create(); - else - $w = WTextField::create(); - - $w->setValue($primitive->getValue()); - - return $this->fill($w, $primitive); - } - - - /** - * @static - * @param PrimitiveBoolean $primitive - * @return WBoolean - */ - protected function makeByPrimitiveBoolean(PrimitiveBoolean $primitive) - { - return $this->fill( - WBoolean::create()->setValue($primitive->getValue()), - $primitive - ); - } - - /** - * @static - * @param PrimitiveTernary $primitive - * @return WTernary - */ - protected function makeByPrimitiveTernary(PrimitiveTernary $primitive) - { - return $this->fill( - WTernary::create()->setTrueValue($primitive->getTrueValue())->setFalseValue($primitive->getFalseValue())->setValue($primitive->getValue()), - $primitive - ); - } - - /** - * @static - * @param PrimitiveTernary $primitive - * @return WSelect - */ - protected function makeByPrimitiveEnumeration(PrimitiveEnumeration $primitive) - { - $className = $primitive->getClassName(); - $any = new $className( - ClassUtils::callStaticMethod( - $primitive->getClassName().'::getAnyId' - ) - ); - - return $this->fill( - WSelect::create()->setList( - $any->getNameList() - )->setValue($primitive->getValue() && $primitive->getValue()->getId() || null), - $primitive - ); - } - - /** - * @static - * @param PrimitiveTernary $primitive - * @return WTernary - */ - protected function makeByPrimitiveEnumerationList(PrimitiveEnumerationList $primitive) - { - return $this->fill( - $this->makeByPrimitiveEnumeration($primitive)->setMulti(true), - $primitive - ); - } - - /** - * @static - * @param PrimitiveTernary $primitive - * @return WSelect - */ - protected function makeByPrimitiveEnum(PrimitiveEnum $primitive) - { - return $this->fill( - WSelect::create()->setList( - ClassUtils::callStaticMethod( - $primitive->getClassName().'::getNameList' - ) - ), - $primitive - ); - } - - /** - * @static - * @param PrimitiveTernary $primitive - * @return WSelect - */ - protected function makeByPrimitiveEnumList(PrimitiveEnumList $primitive) - { - return $this->fill( - $this->makeByPrimitiveEnum($primitive)->setMulti(true), - $primitive - ); - } - - /** - * @static - * @param PrimitiveTernary $primitive - * @return WSelect - */ - protected function makeByPrimitiveIdentifier(PrimitiveIdentifier $primitive, $idField='id', $nameField='name') - { - $dao = ClassUtils::callStaticMethod($primitive->getClassName().'::dao'); - - $q = Criteria::create($dao)->setLimit(100)->toSelectQuery(); - $q->dropFields(); - $q->get($idField); - $q->get($nameField); - - $rows = $dao->getCustomList($q); - $list = array(); - - foreach($rows as $key => $value) - { - $list[$value[$idField]]=$value[$nameField]; - } - - unset($rows); - - $value = ($primitive->getValue()) - ? $primitive->getValue()->getId() - : null; - - return $this->fill( - WSelect::create()->setList( - $list - )->setValue( - $value - ), - $primitive - ); - } - - /** - * @return IfaceWidget - */ - public function makeBy($entity) - { - Assert::isInstance($entity, 'BasePrimitive', - 'entity must be instane of BasePrimitive, gived "'.gettype($entity).'"' - ); - - $widget = null; - $primitiveClassName = get_class($entity); - $widgetClassName = $primitiveClassName; - - if(isset(static::$map[$widgetClassName]) && ($name = static::$map[$widgetClassName] )) - $widget = $this->{$name}($entity); - else { - $parents = class_parents($primitiveClassName); - - foreach($parents as $parent) - { - $className = $parent; - if(isset(static::$map[$className]) && ($name = static::$map[$className] )) { - $widget = $this->{$name}($entity); - break; - } - - } - } - - if(!$widget) - throw new WrongArgumentException( - 'cannot find widget for "'.$primitiveClassName.'" primitve!' - ); - - return $widget; - } - } \ No newline at end of file diff --git a/main/UI/Widgets/Making/WDefaultMakeStrategy.class.php b/main/UI/Widgets/Making/WDefaultMakeStrategy.class.php deleted file mode 100644 index 27e48ff78d..0000000000 --- a/main/UI/Widgets/Making/WDefaultMakeStrategy.class.php +++ /dev/null @@ -1,159 +0,0 @@ - 'Primitive', - ); - - /** - * @static - * @return WDefaultMakeStrategy - */ - public static function me() - { - return Singleton::getInstance(__CLASS__); - } - - public function makeBy($object) - { - // 1. mapping class - // 2. mapping interface - // 3. other logic - - if (!is_object($object)) - throw new WrongArgumentException(); - - $method = $this->getMethodName(class_parents($object)); - - if (!$method) - $method = $this->getMethodName(class_implements($object)); - - if ($method) - return $this->{$method}($object); - - return $this->makeByDefault($object); - } - - protected function getMethodName(array $classes) - { - $list = array_intersect($classes, array_keys($this->map)); - - if (isset($this->map[current($list)])) { - return 'makeBy'.$this->map[current($list)]; - } - } - - /* - protected function makeByClassName() { } - protected function makeByIfaceName() { } - */ - - protected function makeByDefault($object) - { - throw new MissingElementException(__METHOD__.' - Other logic is not set.'); - } - - /** - * пока одним скопом, потом можно разнести на метды - * - * @param BasePrimitive $prm - * @return IfaceWidget - * @throws WrongArgumentException - */ - protected function makeByPrimitive(BasePrimitive $prm) - { - $src = null; - - if ($prm instanceof PrimitiveIdentifier) { - $src = WTextField::create($prm->getName())-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setValue( - $prm->getValue() - ? $prm->getValue()->getId() - : NULL - ); - } - elseif ($prm instanceof PrimitiveDate) { - $src = WCalendar::create($prm->getName())-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setValue($prm->getValue()); - } - elseif ($prm instanceof PrimitiveTime) { - $src = WCalendar::create($prm->getName())-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setValue($prm->getValue()); - } - elseif ($prm instanceof PrimitiveString) { - if($prm->getMax() > 128) { - $src = WTextArea::create($prm->getName())-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setParams(array('size'=>$prm->getMax()))-> - setValue($prm->getValue()); - } else { - $src = WTextField::create($prm->getName())-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setParams(array('size'=>$prm->getMax()))-> - setValue($prm->getValue()); - } - } - else if ($prm instanceof PrimitiveInteger) { - $src = WTextField::create($prm->getName())-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setValue($prm->getValue()); - } - else if ($prm instanceof PrimitiveBoolean) { - $src = WBoolean::create($prm->getName())-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setValue($prm->getValue()); - } - else if ($prm instanceof PrimitiveTernary) { - $src = WTernary::create($prm->getName())-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setTrueValue($prm->getTrueValue())-> - setFalseValue($prm->getFalseValue())-> - setValue($prm->getValue()); - } - else if ($prm instanceof PrimitiveEnumeration) { - $class = $prm->getClassName(); - $class = new TestStatus(TestStatus::getAnyId()); - - $src = WSelect::create($prm->getName())-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setArray($class->getObjectList())-> - setValue($prm->getValue()); - } - else if ($prm instanceof PrimitiveList) { - $src = WMultiSelect::create($prm)-> - setRequired($prm->isRequired())-> - setLabel($prm->getName())-> - setValue($prm->getValue()); - } - else { - throw new WrongArgumentException(); - } - - return $src; - } -} - diff --git a/main/UI/Widgets/Making/WMaker.class.php b/main/UI/Widgets/Making/WMaker.class.php deleted file mode 100644 index 2426864dba..0000000000 --- a/main/UI/Widgets/Making/WMaker.class.php +++ /dev/null @@ -1,120 +0,0 @@ - 'WDefaultPrimitiveMakeStrategy', - ); - - public static function setDefaultStrategy(IfaceWidgetMakeStrategy $strategy) - { - static::$defaultStrategy = $strategy; - } - - - /** - * @static - * @return IfaceWidgetMakeStrategy - */ - public static function getDefaultStrategy() - { - if(!static::$defaultStrategy) - static::setDefaultStrategy( - WDefaultMakeStrategy::me() - ); - - return static::$defaultStrategy; - } - - /** - * @static - * @param array $map - * @throws WrongArgumentException - */ - public static function setMap(array $map) - { - array_walk($map, function($val, $key) { - if (!$val instanceof IfaceWidgetMakeStrategy) { - throw new WrongArgumentException('Not implimentation IfaceWidgetMakeStrategy '.$key); - } - }); - - array_merge(static::$map, $map); - } - - static public function cleanup() - { - static::$map = array(); - } - - /** - * @param string $name - * @return IfaceWidgetMakeStrategy - * @throws WrongArgumentException - */ - public static function get($name = null) - { - if (isset(static::$map[$name])) { - $strategy = static::$map[$name]; - - if($strategy instanceof IfaceWidgetMakeStrategy) - return $strategy; - else { - - if(ClassUtils::isInstanceOf($strategy, 'Singleton')) - $strategy = Singleton::getInstance($strategy); - else - $strategy = new $strategy(); - - Assert::isInstance( - $strategy, - 'IfaceWidgetMakeStrategy', - 'Strategy mus instanceof IfaceWidgetMakeStrategy!' - ); - - return static::$map[$name] = $strategy; - } - } - - return static::getDefaultStrategy(); - } - - /** - * @static - * @param $entity - * @return mixed - */ - public static function make($entity) - { - Assert::isObject($entity); - - $tree = class_parents($entity); - array_unshift($tree, get_class($entity)); - - $strategy = null; - foreach($tree as $name) { - if(array_key_exists($name, static::$map)) - { - $strategy = static::get($name); - break; - } - } - - if(!$strategy) - $strategy = static::getDefaultStrategy(); - - return $strategy->makeBy($entity); - } - - } - diff --git a/main/UI/Widgets/Tables/TableRow.class.php b/main/UI/Widgets/Tables/TableRow.class.php deleted file mode 100644 index 9b585555a5..0000000000 --- a/main/UI/Widgets/Tables/TableRow.class.php +++ /dev/null @@ -1,81 +0,0 @@ -setColumns($columns); - } - - /** - * @param TableRowData $cell - * @return TableRow - */ - public function addColumn(TableRowData $data) - { - array_push($this->columns, $data); - - return $this; - } - - /** - * @return array - */ - public function getColumns() - { - return $this->columns; - } - - /** - * @param array $columns - * @return TableRow - */ - public function setColumns(array $columns = array()) - { - foreach($columns as $column) - $this->addColumn($column); - - return $this; - } - - /** - * @return string - */ - public function toString() - { - return $this->getType()->toString($this->getValue()); - } - - /** - * @return array - */ - public function toArray() - { - return array( - 'columns' => array_map( - function(TableRowData $data) { - return $data->toArray(); - }, - $this->getColumns() - ) - ); - } - } \ No newline at end of file diff --git a/main/UI/Widgets/Tables/TableRowData.class.php b/main/UI/Widgets/Tables/TableRowData.class.php deleted file mode 100644 index 738fcc83ee..0000000000 --- a/main/UI/Widgets/Tables/TableRowData.class.php +++ /dev/null @@ -1,125 +0,0 @@ -type = $type; - $this->value = $value; - } - - /** - * @return misc|null - */ - public function getValue() - { - return $this->value; - } - - /** - * @param $value - * @return TableRowData - */ - public function setValue($value) - { - $this->value = $value; - - return $this; - } - - - /** - * @param TableRowDataType $type - * @return TableRowData - */ - public function setType(TableRowDataType $type) - { - $this->type = $type; - - return $this; - } - - /** - * @return null|TableRowDataType - */ - public function getType() - { - return $this->type; - } - - /** - * @return string - */ - public function toString() - { - return $this->getType()->toCastedString($this->getValue()); - } - - /** - * @return null - */ - public function getId() - { - return $this->id; - } - - /** - * @param $id - * @return TableRowData - */ - public function setId($id) - { - $this->id = $id; - - return $this; - } - - /** - * @return array - */ - public function toArray() - { - return array( - 'id' => $this->getId(), - 'type' => $this->getType()->getId(), - 'values' => array( - 'raw' => $this->getValue(), - 'string' => $this->toString(), - ), - ); - } - } diff --git a/main/UI/Widgets/Tables/TableRowDataType.class.php b/main/UI/Widgets/Tables/TableRowDataType.class.php deleted file mode 100644 index 21c3407a49..0000000000 --- a/main/UI/Widgets/Tables/TableRowDataType.class.php +++ /dev/null @@ -1,72 +0,0 @@ - 'misc', - self::TYPE_NUMBER => 'number', - self::TYPE_STRING => 'string', - ); - - /** - * @param $value - * @return string - */ - public function toCastedString($value) - { - switch($this->id) - { - case static::TYPE_STRING: - case static::TYPE_MISC: - return GUIUtils::objectToString($value); - break; - - case static::TYPE_NUMBER: - Assert::isTrue( - is_numeric($value) - ); - - return $value; - break; - } - - Assert::isUnreachable(); - } - - /** - * @static - * @return TableRowDataType - */ - public static function typeString() - { - return new static(static::TYPE_STRING); - } - - /** - * @static - * @return TableRowDataType - */ - public static function typeNumber() - { - return new static(static::TYPE_NUMBER); - } - - /** - * @static - * @return TableRowDataType - */ - public static function typeMisc() - { - return new static(static::TYPE_MISC); - } - } \ No newline at end of file diff --git a/main/UI/Widgets/Tables/WTable.class.php b/main/UI/Widgets/Tables/WTable.class.php deleted file mode 100644 index 3134114d78..0000000000 --- a/main/UI/Widgets/Tables/WTable.class.php +++ /dev/null @@ -1,190 +0,0 @@ -model->set('rows', array()); - $this->model->set('columns', array()); - $this->model->set('caption', null); - $this->model->set('nextHref', null); - $this->model->set('isMain', true); - $this->model->set('caption', null); - - if($rows) - $this->setRows($rows); - } - - /** - * @param IfaceFieldsFilter $filter - * @return WTable - */ - public function setFilter(IfaceFieldsFilter $filter) - { - $this->filter = $filter; - - return $this; - } - - public function getCaption() - { - return $this->model->get('caption'); - } - - /** - * @return WTable - **/ - public function setCaption($caption) - { - $this->model->set('caption', $caption); - - return $this; - } - - public function getNextHref() - { - return $this->model->get('nextHref'); - } - - /** - * @return WTable - **/ - public function setNextHref($nextHref) - { - $this->model->set('nextHref', $nextHref); - - return $this; - } - - /** - * @return bool - */ - public function isMain() - { - return ($this->model->get('isMain') === true); - } - - /** - * @return WTable - **/ - public function setMain($main = null) - { - Assert::isTernaryBase($main); - - $this->model->set('isMain', $main); - - return $this; - } - - /** - * @return mixed - */ - public function getRows() - { - return $this->model->get('rows'); - } - - - /** - * @param array $rows - * @return WTable - */ - public function setRows(array $rows = array()) - { - $this->model->set('rows', $rows); - - return $this; - } - - /** - * @return array - */ - public function getColumns() - { - return $this->model->get('columns'); - } - - /** - * @param array $columns - * @return WTable - */ - public function setColumns(array $columns = array()) - { - $this->model->set('columns', array()); - - foreach($columns as $key => $value) - $this->addColumn($key, $value); - - return $this; - } - - /** - * @param array $row - * @return WTable - */ - public function addRow(array $row) - { - $rows = $this->getRows(); - $rows[] = $row; - - return $this->setRows($rows); - } - - /** - * @param TableRowData $data - * @return WTable - */ - public function addColumn($fieldName, $value) - { - $columns = $this->getColumns(); - $columns[$fieldName] = GuiUtils::ObjectToString($value); - - $this->model->set('columns', $columns); - - return $this; - } - - /** - * @return string result - */ - protected function rendering($model = null, $merge=true) - { - if($this->filter) - { - $fields = array_keys($this->getColumns() ); - - $this->setRows( - $this->filter->setFields( - $fields - )->apply($this->getRows()) - ); - - } - - return parent::rendering($model, $merge); - } - } -?> \ No newline at end of file diff --git a/main/UI/Widgets/Utils/GuiUtils.class.php b/main/UI/Widgets/Utils/GuiUtils.class.php deleted file mode 100644 index f952532cf0..0000000000 --- a/main/UI/Widgets/Utils/GuiUtils.class.php +++ /dev/null @@ -1,35 +0,0 @@ -toDate(); - - elseif ($object instanceof Named) - return $object->getName(); - - elseif ($object instanceof Titled) - return $object->getTitle(); - - elseif ($object instanceof Stringable) - return $object->toString(); - - elseif ($object instanceof Identifiable) - return get_class($object).'['.$object->getId().']'; - } else - return (string)$object; - } -} diff --git a/main/UI/Widgets/Utils/WidgetsUtils.class.php b/main/UI/Widgets/Utils/WidgetsUtils.class.php deleted file mode 100644 index b126fa1a27..0000000000 --- a/main/UI/Widgets/Utils/WidgetsUtils.class.php +++ /dev/null @@ -1,13 +0,0 @@ -model-> - set('brandHref', '')-> - set('brandValue', ''); - } - - /** - * @param string|ToString $href - * @param mixed $value - * @return WNavBar - */ - public function setBrand($href, $value) - { - $this->model-> - set('brandHref', $href)-> - set('brandValue', $value); - - return $this; - } -} - diff --git a/main/UI/Widgets/WPaginator.class.php b/main/UI/Widgets/WPaginator.class.php deleted file mode 100644 index 65174b4169..0000000000 --- a/main/UI/Widgets/WPaginator.class.php +++ /dev/null @@ -1,21 +0,0 @@ -model->set('value', $value); - - return $this; - } - - /** - * @param $value - * @return WPropertiesElement - */ - public function addClass($value) - { - if( - !isset($this->attrs['class']) || - !array_search($value, $this->attrs['class']) - ) - $this->attrs['class'][] = $value; - - return $this; - } - - /** - * @param $value - * @return WPropertiesElement - */ - public function removeClass($value) - { - if( - isset($this->attrs['class']) - && ($key = array_search($value, $this->attrs['class'])) - ) - unset($this->attrs['class'][$key]); - - return $this; - } - - /** - * @param $value - * @return WPropertiesElement - */ - public function setClass($value) - { - return $this->addClass($value); - } - - /** - * @param $attr - * @return WPropertiesElement - */ - public function dropAttr($attr) - { - if(isset($this->attrs[$attr])) - unset($this->attrs[$attr]); - - return $this; - } - - /** - * @param $attr - * @param $value - * @return WPropertiesElement - */ - public function setAttr($attr, $value) - { - Assert::isScalar($value); - - $this->attrs[$attr] = $value; - - return $this; - } - - /** - * @param $attr - * @return null - */ - public function getAttr($attr) - { - if(isset($this->attrs[$attr])) - return $this->attrs[$attr]; - - return null; - } - - /** - * Get all attributes - * @return array - */ - public function getAttrs() - { - return $this->attrs; - } - - /** - * Set attrs - * Important: All old attributes will be ovverided - * @param array $attrs - * @return WPropertiesElement - */ - public function setAttrs(array $attrs) - { - foreach($attrs as $key => $value) - $this->setAttr($key, $value); - - return $this; - } - - /** - * @return string result - */ - protected function rendering(/*Model*/$model = null, $merge=true) - { - $attrs = $this->attrs; - - $this->model->set( - 'getAttr', - function($name=null, $value=null, $separator=' ') use (&$attrs) - { - if($name) { - Assert::isScalar($name, 'attr name must be scalar type, gived "'.gettype($name).'"'); - - if($value) { - Assert::isScalar($value, 'attr value must be scalar type, gived "'.gettype($value).'"'); - - if($name=='class') - { - if(!isset($attrs['class'])) - $attrs['class'] = array(); - - $attrs['class'] = array_merge( - $attrs['class'], - array( - $value - ) - ); - } else { - $attrs[$name] = $value; - } - } - - $return = isset($attrs[$name]) - ? $attrs[$name] - : ''; - - unset($attrs[$name]); - - if(is_array($return)) - $return = implode($separator, $return); - - return $return; - } else { - $return = ''; - - foreach($attrs as $key => $value) - { - if(is_array($value)) - $value = implode($separator, $value); - - $return.=' '.$key.'="'.$value.'"'; - } - - return $return; - } - - Assert::isUnreachable(); - } - ); - - return parent::rendering($model, $merge); - } - - -} diff --git a/main/UI/Widgets/Widget.class.php b/main/UI/Widgets/Widget.class.php deleted file mode 100644 index c4f0a060c8..0000000000 --- a/main/UI/Widgets/Widget.class.php +++ /dev/null @@ -1,117 +0,0 @@ -setViewClassName( - 'SimplePhpView' - )->setPostfix( - EXT_TPL - )->addPrefix( - ONPHP_UI_DEFAULT_WTEMPLATES_PATH - ) - ); - } - - return static::$defaultViewResolver; - } - - /** - * @static - * @param ViewResolver $resolver - */ - public static function setDefaultViewResolver(ViewResolver $resolver) - { - static::$defaultViewResolver = $resolver; - } - - /** - * @static - * @param array $map - */ - public static function setViewResolverMap(array $map=array()) - { - static::$viewResolverMap = $map; - } - - /** - * @static - * @return WTable - */ - public static function table() - { - return WTable::create(); - } - - /** - * @static - * @return WButton - */ - public static function button() - { - return WButton::create(); - } - - /** - * @static - * @return WButtonGroup - */ - public static function buttonGroup() - { - return WButtonGroup::create(); - } - - /** - * @static - * @return WDropDownMenu - */ - public static function dropDownMenu() - { - return WDropDownMenu::create(); - } - - } \ No newline at end of file diff --git a/main/UI/Widgets/WidgetPage.class.php b/main/UI/Widgets/WidgetPage.class.php deleted file mode 100644 index 7c8dec1863..0000000000 --- a/main/UI/Widgets/WidgetPage.class.php +++ /dev/null @@ -1,19 +0,0 @@ -/img/bg.png"); -} -.sidebar-nav { - padding: 9px 0; -} -.one-pixel { - height: 1px; - background-color: #696969; - top: 100%; - width: 100%; -} -.shadow-white { - -webkit-box-shadow: 0 5px 10px #fff; - -moz-box-shadow: 0 5px 10px #fff; - box-shadow: 0 5px 10px #fff; -} -.shadow { - -webkit-box-shadow: 0 5px 10px #535351; - -moz-box-shadow: 0 5px 10px #535351; - box-shadow: 0 5px 10px #535351; -} -.box { - background-color: #fff; - border: 1px solid #E1E1E8; - padding: 2px 8px; - -webkit-border-radius: 3px; - -moz-border-radius: 3px; - border-radius: 3px; -} -.form-horizontal .control-group { - margin-bottom: 5px; -} \ No newline at end of file diff --git a/source/template/widget/bootstrap/form/boolean.tpl.html b/source/template/widget/bootstrap/form/boolean.tpl.html deleted file mode 100644 index 125cdae41c..0000000000 --- a/source/template/widget/bootstrap/form/boolean.tpl.html +++ /dev/null @@ -1,23 +0,0 @@ - - -view('form/parts/inputs/head') -?> - -/> - -view('form/parts/inputs/foot') -?> - - - diff --git a/source/template/widget/bootstrap/form/button.tpl.html b/source/template/widget/bootstrap/form/button.tpl.html deleted file mode 100644 index be304e24db..0000000000 --- a/source/template/widget/bootstrap/form/button.tpl.html +++ /dev/null @@ -1,24 +0,0 @@ - - \ No newline at end of file diff --git a/source/template/widget/bootstrap/form/buttonGroup.tpl.html b/source/template/widget/bootstrap/form/buttonGroup.tpl.html deleted file mode 100644 index 9b172b3242..0000000000 --- a/source/template/widget/bootstrap/form/buttonGroup.tpl.html +++ /dev/null @@ -1,24 +0,0 @@ - -
- - toString(); ?> - -
\ No newline at end of file diff --git a/source/template/widget/bootstrap/form/calendar.tpl.html b/source/template/widget/bootstrap/form/calendar.tpl.html deleted file mode 100644 index 0cfd9362a5..0000000000 --- a/source/template/widget/bootstrap/form/calendar.tpl.html +++ /dev/null @@ -1,23 +0,0 @@ - - -view('form/parts/inputs/head') -?> - - - -view('form/parts/inputs/foot') -?> - - - diff --git a/source/template/widget/bootstrap/form/dropDownMenu.tpl.html b/source/template/widget/bootstrap/form/dropDownMenu.tpl.html deleted file mode 100644 index 1367b25762..0000000000 --- a/source/template/widget/bootstrap/form/dropDownMenu.tpl.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - -
> -addClass('btn'); ?> - - -
- - \ No newline at end of file diff --git a/source/template/widget/bootstrap/form/editForm.tpl.html b/source/template/widget/bootstrap/form/editForm.tpl.html deleted file mode 100644 index a77fa35bdd..0000000000 --- a/source/template/widget/bootstrap/form/editForm.tpl.html +++ /dev/null @@ -1,25 +0,0 @@ - - -setAction($action)->setMethod($method)->setEnctype($enctype)->toString() ?> - -
- -toString(); ?> - -
- - -
- - -
-toString() ?> diff --git a/source/template/widget/bootstrap/form/formBegin.tpl.html b/source/template/widget/bootstrap/form/formBegin.tpl.html deleted file mode 100644 index 9f01bd4f3d..0000000000 --- a/source/template/widget/bootstrap/form/formBegin.tpl.html +++ /dev/null @@ -1,16 +0,0 @@ - - -
- -

- \ No newline at end of file diff --git a/source/template/widget/bootstrap/form/formEnd.tpl.html b/source/template/widget/bootstrap/form/formEnd.tpl.html deleted file mode 100644 index d4066f8973..0000000000 --- a/source/template/widget/bootstrap/form/formEnd.tpl.html +++ /dev/null @@ -1,13 +0,0 @@ - - -
\ No newline at end of file diff --git a/source/template/widget/bootstrap/form/parts/inputs/foot.tpl.html b/source/template/widget/bootstrap/form/parts/inputs/foot.tpl.html deleted file mode 100644 index df27a17e7b..0000000000 --- a/source/template/widget/bootstrap/form/parts/inputs/foot.tpl.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/source/template/widget/bootstrap/form/parts/inputs/head.tpl.html b/source/template/widget/bootstrap/form/parts/inputs/head.tpl.html deleted file mode 100644 index 76133ae954..0000000000 --- a/source/template/widget/bootstrap/form/parts/inputs/head.tpl.html +++ /dev/null @@ -1,16 +0,0 @@ - - -
- - - -
\ No newline at end of file diff --git a/source/template/widget/bootstrap/form/select.tpl.html b/source/template/widget/bootstrap/form/select.tpl.html deleted file mode 100644 index d2415b8659..0000000000 --- a/source/template/widget/bootstrap/form/select.tpl.html +++ /dev/null @@ -1,29 +0,0 @@ - - -view('form/parts/inputs/head') -?> - - - -view('form/parts/inputs/foot') -?> - - - diff --git a/source/template/widget/bootstrap/form/ternary.tpl.html b/source/template/widget/bootstrap/form/ternary.tpl.html deleted file mode 100644 index 0a807ee9b2..0000000000 --- a/source/template/widget/bootstrap/form/ternary.tpl.html +++ /dev/null @@ -1,28 +0,0 @@ - - -view('form/parts/inputs/head') -?> - - - -view('form/parts/inputs/foot') -?> - - - ->_none">none \ No newline at end of file diff --git a/source/template/widget/bootstrap/form/textArea.tpl.html b/source/template/widget/bootstrap/form/textArea.tpl.html deleted file mode 100644 index 1b68b8ba9c..0000000000 --- a/source/template/widget/bootstrap/form/textArea.tpl.html +++ /dev/null @@ -1,23 +0,0 @@ - - -view('form/parts/inputs/head') -?> - - - -view('form/parts/inputs/foot') -?> - - - diff --git a/source/template/widget/bootstrap/form/textField.tpl.html b/source/template/widget/bootstrap/form/textField.tpl.html deleted file mode 100644 index a33c17156c..0000000000 --- a/source/template/widget/bootstrap/form/textField.tpl.html +++ /dev/null @@ -1,23 +0,0 @@ - - -view('form/parts/inputs/head') -?> - - - -view('form/parts/inputs/foot') -?> - - - diff --git a/source/template/widget/bootstrap/hyperlink.tpl.html b/source/template/widget/bootstrap/hyperlink.tpl.html deleted file mode 100644 index 0b656948ec..0000000000 --- a/source/template/widget/bootstrap/hyperlink.tpl.html +++ /dev/null @@ -1,11 +0,0 @@ - -> \ No newline at end of file diff --git a/source/template/widget/bootstrap/multiSelect.tpl.html b/source/template/widget/bootstrap/multiSelect.tpl.html deleted file mode 100644 index 66beb29ad3..0000000000 --- a/source/template/widget/bootstrap/multiSelect.tpl.html +++ /dev/null @@ -1,30 +0,0 @@ -getName() - */ -?> - \ No newline at end of file diff --git a/source/template/widget/bootstrap/navbar.tpl.html b/source/template/widget/bootstrap/navbar.tpl.html deleted file mode 100644 index 2a5825f41b..0000000000 --- a/source/template/widget/bootstrap/navbar.tpl.html +++ /dev/null @@ -1,43 +0,0 @@ - diff --git a/source/template/widget/bootstrap/paginator.tpl.html b/source/template/widget/bootstrap/paginator.tpl.html deleted file mode 100644 index 1a900f26ae..0000000000 --- a/source/template/widget/bootstrap/paginator.tpl.html +++ /dev/null @@ -1,8 +0,0 @@ - -
-/> - - -
\ No newline at end of file diff --git a/source/template/widget/bootstrap/table/sortableTable.tpl.html b/source/template/widget/bootstrap/table/sortableTable.tpl.html deleted file mode 100644 index 3c647492dd..0000000000 --- a/source/template/widget/bootstrap/table/sortableTable.tpl.html +++ /dev/null @@ -1,50 +0,0 @@ -proto()->getPropertyList(); - -if (isset($filter) && $filter instanceof IFieldsFilter) { - $fields = $filter->setFields($fields)-> - getList(); -} - -if (!$name) - $name = strtolower($object->dao()->getObjectName()); - -?> - - - $type) { ?> - - - - - $object) { ?> - - $type) { ?> - - -
- -
- {'get'.ucfirst($key)}())?$object->{'get'.ucfirst($key)}():' ';?> -
diff --git a/source/template/widget/bootstrap/table/table.tpl.html b/source/template/widget/bootstrap/table/table.tpl.html deleted file mode 100644 index 9c0517ed07..0000000000 --- a/source/template/widget/bootstrap/table/table.tpl.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - - - - - - - - - - - diff --git a/source/template/widget/bootstrap/table/tableAndActions.tpl.html b/source/template/widget/bootstrap/table/tableAndActions.tpl.html deleted file mode 100644 index 10065ddb20..0000000000 --- a/source/template/widget/bootstrap/table/tableAndActions.tpl.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - $type) { ?> - - - - - - - - $object) { ?> - > - $type) { ?> - - $url) { ?> - - - -
- - - -
- - {$method}()) - : ' '; - ?> - - -
diff --git a/source/template/widget/bootstrap/table/ticketsTable.tpl.html b/source/template/widget/bootstrap/table/ticketsTable.tpl.html deleted file mode 100644 index 75dd49fa10..0000000000 --- a/source/template/widget/bootstrap/table/ticketsTable.tpl.html +++ /dev/null @@ -1,174 +0,0 @@ -proto()->getPropertyList(); - - -if ($_filter instanceof IFieldsFilter) { - $fields = $_filter->setAllFields($fields)-> - getList(); -} - -if (!$_widgetName) - $_widgetName = strtolower($object->dao()->getObjectName()); - - -?> - - - - - - $type) { ?> - - - - - - - - $object) { ?> - - $type) { - $method = 'get'.ucfirst($fieldName); - $text = method_exists($object, $method) - ? GuiUtils::ObjectToString($object->{$method}()) - : ' '; - - $css = null; - $cssArray = array( - 0 => 'warning', - 'Good' => 'good', - 'Bad' => 'error', - 'Test' => 'info', - ); - -// сука хардкод и кописаст -// билять, это все по другому надо делать, но сейчас так - switch($fieldName) { - case 'design': $css = $text= ($text) ? $cssArray['Good'] : $cssArray[0]; - break; - case 'layout': $css = $text = ($text) ? $cssArray['Good'] : $cssArray[0]; - break; - case 'testWorkOld': - case 'testWork': - case 'testDesign': - case 'testText': - $css = $text = (isset($cssArray[$text])) ? $cssArray[$text] : null; - break; - - case 'r4': - $text = TrackUtils::parseTicketUrl($text, 'http://bigwig.rdw.ru:5555/rabota/ticket'); - break; - case 'r5': - $text = TrackUtils::parseTicketUrl($text, 'http://bigwig.rdw.ru:5555/rabota5/ticket'); - break; - - case 'urldmz': - $text = preg_replace('~(^|\s)(.*?)(\s)~', '

$2

$3', $text); - - default: - if (mb_strlen($text) > $maxSizeTextForCut) { - $uid = $object->getId().'_'.$fieldName; - - $smallText = TextUtils::cutOnSpace($text, $maxSizeTextForCut, '...'); - - $text = <<$smallText -
$text
- -OUT; - } - break; - } -?> -
- $url) { ?> - - - -
- - set('sortMode', 'desc'); - break; - case 'desc': - $sortUrl-> - set('sortMode', 'asc'); - break; - default : - $sortUrl-> - set('sortMode', 'desc'); - } - } - - $sortUrl->set('sortField', $key); -?> - - - - -
- - - -
- - \ No newline at end of file diff --git a/source/template/widget/bootstrap/table/treeTable.tpl.html b/source/template/widget/bootstrap/table/treeTable.tpl.html deleted file mode 100644 index 7d7e411a5d..0000000000 --- a/source/template/widget/bootstrap/table/treeTable.tpl.html +++ /dev/null @@ -1,73 +0,0 @@ -getList())); - -if (empty($_objects)) - throw new Exception("array 'objects' is empty"); - -$object = current($_objects); -$fields = $object->proto()->getPropertyList(); - - -if ($_filter instanceof IFieldsFilter) { - $fields = $_filter->setAllFields($fields)-> - getList(); -} - -if (!$_widgetName) - $_widgetName = strtolower($object->dao()->getObjectName()); - - -?> - - - $type) { ?> - - - - - - - - $object) { ?> - - $type) { ?> - - $url) { ?> - - - -
- - - -
- - {$method}()) - : ' '; - ?> - - -
diff --git a/source/template/widget/form/action.tpl.html b/source/template/widget/form/action.tpl.html new file mode 100644 index 0000000000..22187df23a --- /dev/null +++ b/source/template/widget/form/action.tpl.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/template/widget/form/check-box.tpl.html b/source/template/widget/form/check-box.tpl.html new file mode 100644 index 0000000000..22187df23a --- /dev/null +++ b/source/template/widget/form/check-box.tpl.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/template/widget/form/form.tpl.html b/source/template/widget/form/form.tpl.html new file mode 100644 index 0000000000..ebd2871c1a --- /dev/null +++ b/source/template/widget/form/form.tpl.html @@ -0,0 +1,14 @@ +
getAttributesList(true); ?>> + $widget): ?> + + +
+ $widget): ?> + + +
+
\ No newline at end of file diff --git a/source/template/widget/form/input.tpl.html b/source/template/widget/form/input.tpl.html new file mode 100644 index 0000000000..22187df23a --- /dev/null +++ b/source/template/widget/form/input.tpl.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/template/widget/form/select.tpl.html b/source/template/widget/form/select.tpl.html new file mode 100644 index 0000000000..f0dc1b238d --- /dev/null +++ b/source/template/widget/form/select.tpl.html @@ -0,0 +1,6 @@ + diff --git a/source/template/widget/form/text-area.tpl.html b/source/template/widget/form/text-area.tpl.html new file mode 100644 index 0000000000..22187df23a --- /dev/null +++ b/source/template/widget/form/text-area.tpl.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/template/widget/html/a.tpl.html b/source/template/widget/html/a.tpl.html new file mode 100644 index 0000000000..22187df23a --- /dev/null +++ b/source/template/widget/html/a.tpl.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/template/widget/html/html.tpl.html b/source/template/widget/html/html.tpl.html new file mode 100644 index 0000000000..22187df23a --- /dev/null +++ b/source/template/widget/html/html.tpl.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/template/widget/html/img.tpl.html b/source/template/widget/html/img.tpl.html new file mode 100644 index 0000000000..22187df23a --- /dev/null +++ b/source/template/widget/html/img.tpl.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/template/widget/html/page.tpl.html b/source/template/widget/html/page.tpl.html new file mode 100644 index 0000000000..4a586eb17d --- /dev/null +++ b/source/template/widget/html/page.tpl.html @@ -0,0 +1,20 @@ + + + + + <?= $title ?> + + $rel) : ?> + + + + + + + + + + + + +