Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"Riesenia\\Kendo\\": "src/"
}
}
}
}
10 changes: 10 additions & 0 deletions src/Kendo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
* Factory for Kendo UI widgets.
*
* @author Tomas Saghy <segy@riesenia.com>
*
* @method static Riesenia\Kendo\Widget\Form createForm(string $bindTo = '') Create a form widget.
* @method static Riesenia\Kendo\Widget\Grid createGrid(string $bindTo = '') Create a grid widget.
* @method static Riesenia\Kendo\Widget\Window createWindow(string $bindTo = '') Create a window widget.
* @method static Riesenia\Kendo\Widget\DropDownTree createDropDownTree(string $bindTo = '') Create a drop down tree widget.
*/
class Kendo
{
Expand All @@ -30,6 +35,7 @@ class Kendo
public static function create(string $name, string $bindTo = ''): Base
{
$fullName = __NAMESPACE__ . '\\Widget\\' . $name;
/** @var Widget\Base */
$widget = \class_exists($fullName) ? new $fullName() : new Widget\Base('kendo' . $name);

if ($bindTo) {
Expand Down Expand Up @@ -82,6 +88,10 @@ public static function __callStatic(string $method, array $arguments)
{
// create<Widget> method
if (\preg_match('/create([A-Z][a-zA-Z0-9]*)/', $method, $matches)) {
if (!is_string($arguments[0] ?? '')) {
throw new \InvalidArgumentException('BindTo must be a string');
}

return static::create($matches[1], $arguments[0] ?? '');
}

Expand Down
12 changes: 11 additions & 1 deletion src/Widget/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public function add(string $name, ?string $key, $value): self
$this->_data[$name] = [];
}

if (!is_array($this->_data[$name])) {
throw new \TypeError('Property ' . $name . ' is not an array');
}

if ($key === null) {
$key = \count($this->_data[$name]);
}
Expand Down Expand Up @@ -201,7 +205,13 @@ public function __call(string $method, array $arguments)

// add<Attribute> for adding to array object attributes
if (\preg_match('/add([A-Z][a-zA-Z0-9]*)/', $method, $matches)) {
return $this->add(\lcfirst($matches[1]), $arguments[0], $arguments[1]);
$key = $arguments[0];

if (!is_string($key) && $key !== null) {
throw new \TypeError('Key must be a string or null');
}

return $this->add(\lcfirst($matches[1]), $key, $arguments[1]);
}

// get<Attribute> for getting object attributes
Expand Down
110 changes: 110 additions & 0 deletions src/Widget/DropDownTree.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* This file is part of riesenia/kendo package.
*
* Licensed under the MIT License
* (c) RIESENIA.com
*/

declare(strict_types=1);

namespace Riesenia\Kendo\Widget;

use Riesenia\Kendo\JavascriptFunction;
use Riesenia\Kendo\Widget\Base;

/**
* @method $this setAdaptiveMode(null|"none"|"auto" $value) Specifies the adaptive rendering mode of the widget.
* @method null|"none"|"auto" getAdaptiveMode()
* @method $this setAnimation(null|false|array{close?:array{effects:string, duration:int}, open?:array{effects:string, duration:int}} $value)
* @method null|false|array{close?:array{effects:string, duration:int}, open?:array{effects:string, duration:int}} getAnimation()
* @method $this setAutoBind(?bool $value) Determines whether the widget will bind to the data source on initialization.
* @method ?bool getAutoBind() Get whether the widget will bind to the data source on initialization.
* @method $this setAutoClose(?bool $value) If set to true the widget will auto close after selecting or checking a item.
* @method ?bool getAutoClose() Get whether the widget will auto close after selecting or checking a item.
* @method $this setAutoWidth(?bool $value) If set to true the widget will auto expand the width of the popup element to fit its content.
* @method ?bool getAutoWidth() Get whether the widget will auto expand the width of the popup element to fit its content.
* @method $this setCheckAll(?bool $value) Add a check/uncheck all checkbox to the top of the list.
* @method ?bool getCheckAll() Get whether the widget has a check/uncheck all checkbox.
* @method $this setCheckAllTemplate(?string $value) The template used to render the checkAll checkbox state.
* @method ?string getCheckAllTemplate() Get the template used to render the checkAll checkbox state.
* @method $this setCheckboxes(null|bool|array{checkChildren:bool, name:string, template:string|JavascriptFunction} $value) If set will render checkboxes for each item.
* @method null|bool|array{checkChildren:bool, name:string, template:string|JavascriptFunction} getCheckboxes() Get whether the widget will render checkboxes for each item.
* @method $this setClearButton(?bool $value) Unlsess set to false the widget will display a button when hovering the widget that will clear the value.
* @method ?bool getClearButton() Get whether the widget will display a button when hovering the widget that will clear the value.
* @method $this setDataImageUrlField(?string $value) The field of the data item that provides the image URL of the tree items.
* @method ?string getDataImageUrlField() Get the field of the data item that provides the image URL of the tree items.
* @method $this setDataSpriteCssClassField(?string $value) Sets the field of the data item that provides the sprite CSS class of the tree
* @method ?string getDataSpriteCssClassField() Get the field of the data item that provides the sprite CSS class of the tree
* @method $this setDataTextField(null|string|array $value) The field of the data item that provides the text content of the tree items.
* @method null|string|array getDataTextField() Get the field of the data item that provides the text content of the tree items.
* @method $this setDataUrlField(?string $value) The field of the data item that provides the link URL of the tree items.
* @method ?string getDataUrlField() Get the field of the data item that provides the link URL of the tree items.
* @method $this setDataValueField(null|string|array $value) The field of the data item that provides the value of the widget. If an array each level uses the array element corresponding to its depth.
* @method null|string|array getDataValueField() Get the field of the data item that provides the value of the widget.
* @method $this setDelay(?int $value) Sets the delay in milliseconds after which the widget will start filtering the data source.
* @method ?int getDelay() Get the delay in milliseconds after which the widget will start filtering the data source.
* @method $this setEnable(?bool $value) If set to false the widget will be disabled and will not allow user input.
* @method ?bool getEnable() Get whether the widget is disabled.
* @method $this setEnforceMinLength(?bool $value) When set to true will hide all the items when the search text is cleared.
* @method ?bool getEnforceMinLength() Get whether the widget will hide all the items when the search text is cleared.
* @method $this setFilter(?string $value) The filtering method used to determine the suggestions for the current value. Filtering is turned off by default.
* @method ?string getFilter() Get the filtering method used to determine the suggestions for the current value.
* @method $this setFilterLabel(?string $value) The label of the filter input.
* @method ?string getFilterLabel() Get the label of the filter input.
* @method $this setFillMode(?string $value) Sets how the color should be applied to the widget.
* @method ?string getFillMode() Get how the color should be applied to the widget.
* @method $this setFooterTemplate(null|string|JavascriptFunction $value) The template used to render the footer template.
* @method null|string|JavascriptFunction getFooterTemplate() Get the template used to render the footer template.
* @method $this setLabel(null|JavascriptFunction|array{content:string|JavascriptFunction, floating?:bool} $value) The label of the widget.
* @method null|JavascriptFunction|array{content:string|JavascriptFunction, floating?:bool} getLabel() Get the label that will be displayed before the input.
* @method $this setHeight(null|int|string $value) Tge maximum height of the suggestion popup in pixels. If set to auto it will be set to the height of the treeview.
* @method null|int|string getHeight() Get the maximum height of the suggestion popup.
* @method $this setIgnoreCase(?bool $value) Determines if the search should be case sensitive. Default is false.
* @method ?bool getIgnoreCase() Get whether the search should be case sensitive.
* @method $this setLoadOnDemand(null|bool|array{valueMapper:JavascriptFunction} $value) Sets whether the child datasources should be fetched lazily when parent items get expanded. Default is false.
* @method null|bool|array{valueMapper:JavascriptFunction} getLoadOnDemand() Get whether the child datasources should be fetched lazily when parent items get expanded.
* @method $this setMessages(null|array{clear?:string, deleteTag?:string, noData?:string, singleTag?:string} $value) The messages that are displayed in the widget.
* @method null|array{clear?:string, deleteTag?:string, noData?:string, singleTag?:string} getMessages() Get the messages that are displayed in the widget.
* @method $this setMinLength(?int $value) The minimum number of characters the user must type before a search is performed. Default is 1.
* @method ?int getMinLength() Get the minimum number of characters the user must type before a search is performed.
* @method $this setNoDataTemplate(null|string|JavascriptFunction|bool $value) The template used to render the template which is displayed when the underlying datasource is empty.
* @method null|string|JavascriptFunction|bool getNoDataTemplate() Get the template used to render the template which is displayed when the underlying datasource is empty.
* @method $this setPlaceholder(?string $value) The hint displayed by the widget when it is empty.
* @method ?string getPlaceholder() Get the hint displayed by the widget when it is empty.
* @method $this setPopup(null|array{appendTo?:string, origin?:string, position?:string} $value) The options that will be used for the popup initialization.
* @method null|array{appendTo?:string, origin?:string, position?:string} getPopup() Get the options that will be used for the popup initialization.
* @method $this setHeaderTemplate(null|string|JavascriptFunction $value) The template used to render the header of the popup.
* @method null|string|JavascriptFunction getHeaderTemplate() Get the template used to render the header of the popup.
* @method $this setValueTemplate(null|string|JavascriptFunction $value) The template used to render the value of the widget.
* @method null|string|JavascriptFunction getValueTemplate() Get the template used to render the value of the widget.
* @method $this setTagMode(?string $value) The mode used to render the selected tags. Default is multiple.
* @method ?string getTagMode() Get the mode used to render the selected tags.
* @method $this setTemplate(null|string|JavascriptFunction $value) The template used to render the items.
* @method null|string|JavascriptFunction getTemplate() Get the template used to render the items.
* @method $this setText(?string $value) The text of the widget used when the autoBind is set to false.
* @method ?string getText() Get the text of the widget used when the autoBind is set to false.
* @method $this setValue(null|string|array $value) The value of the widget.
* @method null|string|array getValue() Get the value of the widget.
* @method $this setValuePrimitive(?bool $value) If set to true the widget will use the value and valueField fields of the data item and not the data item itself.
* @method ?bool getValuePrimitive() Get whether the widget will use the value and valueField fields of the data item and not the data item itself.
* @method $this setRounded(?string $value) Sets the border-radius of the widget.
* @method ?string getRounded() Get the border-radius of the widget.
* @method $this setSize(?string $value) The size of the widget.
* @method ?string getSize() Get the size of the widget.
* @method $this setChange(?JavascriptFunction $event) The event handler that will be triggered when the value of the widget is changed.
* @method JavascriptFunction|null getChange() Get the event handler that will be triggered when the value of the widget is changed.
* @method $this setClose(?JavascriptFunction $event) The event handler that will be triggered when the popup is closed.
* @method JavascriptFunction|null getClose() Get the event handler that will be triggered when the popup is closed.
* @method $this setDataBound(?JavascriptFunction $event) The event handler that will be triggered when the widget items are bound to data from the widgets data source.
* @method JavascriptFunction|null getDataBound() Get the event handler that will be triggered when the widget items are bound to data from the widgets data source.
* @method $this setFiltering(?JavascriptFunction $event) The event handler that will be triggered when the widget is about to filter the data source.
* @method JavascriptFunction|null getFiltering() Get the event handler that will be triggered when the widget is about to filter the data source.
* @method $this setOpen(?JavascriptFunction $event) The event handler that will be triggered when the popup is opened.
* @method JavascriptFunction|null getOpen() Get the event handler that will be triggered when the popup is opened.
* @method $this setSelect(?JavascriptFunction $event) The event handler that will be triggered when an item from the popup is selected. When checkboxes are enabled the event will be triggered when the a item is deselected.
* @method JavascriptFunction|null getSelect() Get the event handler that will be triggered when an item from the popup is selected.
*/
class DropDownTree extends Base
{
}
56 changes: 56 additions & 0 deletions src/Widget/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* This file is part of riesenia/kendo package.
*
* Licensed under the MIT License
* (c) RIESENIA.com
*/

declare(strict_types=1);

namespace Riesenia\Kendo\Widget;

use Riesenia\Kendo\JavascriptFunction;
use Riesenia\Kendo\Widget\Base;

/**
* A class for creating a kendo form.
*
* @author Adam Bezak <adam.bezak@riesenia.com>
*
* @method $this setButtonsTemplate(string|JavascriptFunction|null $template) Set the template used for rendering form buttons.
* @method string|JavascriptFunction|null getButtonsTemplate() Get the template used for rendering form buttons.
* @method $this setFocusFirst(bool|null $focusFirst) Set whether to focus the first input on initialization.
* @method bool|null getFocusFirst() Get whether to focus the first input on initialization.
* @method $this setFormatLabel(JavascriptFunction|null $formatLabel) Callback function to change the default format of automatically generated labels.
* @method bool|null getFormatLabel() Get the callback function for changing the default format of automatically generated labels.
* @method $this setFormData(array $formData) Set the form data. Unless the items option is set, the form will generate fields based on the provided data.
* @method array|null getFormData() Get the form data.
* @method $this setItems(array<array{type: string, field: string, editor: string|JavascriptFunction, editorOptions:array, validation:array, label: string|array{text:string, optional:bool, encoded?:bool}, id: string, title: string, hint:string, colSpan: int, attributes: array, layout?: string, grid:array }>|null $items) Set the form items.
* @method array<array{type: string, field: string, editor: string|JavascriptFunction, editorOptions:array, validation:array, label: string|array{text:string, optional:bool, encoded?:bool}, id: string, title: string, hint:string, colSpan: int, attributes: array, layout?: string, grid:array }>|null getItems() Get the form items.
* @method $this setOrientation(string|null $orientation) Set the form orientation.
* @method string|null getOrientation() Get the form orientation.
* @method $this setMessages(array{submit?: string, clear?: string, optional?: string}|null $messages) Set the form messages.
* @method array{submit?: string, clear?: string, optional?: string}|null getMessages() Get the form messages.
* @method $this setValidatable(array|null $validatable) Set the build-in validator options.
* @method array|null getValidatable() Get the built-in validator options.
* @method $this setLayout(string|null $layout) Set the layout of form content.
* @method string getLayout() Get the form content layout.
* @method $this setGrid(array{cols:string|int, gutter:int|string|array{rows:int|string, cols:int|string}}|null $grid) Set the form grid layout.
* @method array{cols:string|int, gutter:int|string|array{rows:int|string, cols:int|string}}|null getGrid() Get the form grid layout.
* @method $this setSize(string|null $size) Set the value controlling the form size.
* @method string getSize() Get the value controlling the form size.
* @method $this setValidate(JavascriptFunction|null $validate) Set the function that will be called when the form is validated.
* @method JavascriptFunction|null getValidate() Get the function that will be called when the form is validated.
* @method $this setValidateField(JavascriptFunction|null $validateField) Set the function that will be called when a field is validated.
* @method JavascriptFunction|null getValidateField() Get the function that will be called when a field is validated.
* @method $this setChange(JavascriptFunction|null $change) Set the function that will be called when the form is changed.
* @method JavascriptFunction|null getChange() Get the function that will be called when the form is changed.
* @method $this setSubmit(JavascriptFunction|null $submit) Set the function that will be called when the form is submitted.
* @method JavascriptFunction|null getSubmit() Get the function that will be called when the form is submitted.
* @method $this setClear(JavascriptFunction|null $clear) Set the function that will be called when the form is cleared.
* @method JavascriptFunction|null getClear() Get the function that will be called when the form is cleared.
*/
class Form extends Base
{
}
Loading