')]);
-$lister = \Atk4\Ui\Lister::addTo($view, [], ['List']);
-$lister->onHook(\Atk4\Ui\Lister::HOOK_BEFORE_ROW, function (\Atk4\Ui\Lister $lister) {
+$lister = Lister::addTo($view, [], ['List']);
+$lister->onHook(Lister::HOOK_BEFORE_ROW, function (Lister $lister) {
$row = Country::assertInstanceOf($lister->currentRow);
$row->iso = mb_strtolower($row->iso);
});
@@ -54,18 +58,18 @@
$model->addCondition(Country::hinting()->fieldName()->id, -1); // no such records so model will be empty
$lister->setModel($model);
-\Atk4\Ui\View::addTo($app, ['ui' => 'clearing divider']);
-\Atk4\Ui\Header::addTo($app, ['Item per page', 'subHeader' => 'Lister can display a certain amount of items']);
+View::addTo($app, ['ui' => 'clearing divider']);
+Header::addTo($app, ['Item per page', 'subHeader' => 'Lister can display a certain amount of items']);
-$container = \Atk4\Ui\View::addTo($app);
+$container = View::addTo($app);
-$view = \Atk4\Ui\View::addTo($container, ['template' => new HtmlTemplate('
+$view = View::addTo($container, ['template' => new HtmlTemplate('
{List} {$atk_fp_country__name} {/}
{$Content}
')]);
-$lister = \Atk4\Ui\Lister::addTo($view, [], ['List']);
-$lister->onHook(\Atk4\Ui\Lister::HOOK_BEFORE_ROW, function (\Atk4\Ui\Lister $lister) {
+$lister = Lister::addTo($view, [], ['List']);
+$lister->onHook(Lister::HOOK_BEFORE_ROW, function (Lister $lister) {
$row = Country::assertInstanceOf($lister->currentRow);
$row->iso = mb_strtolower($row->iso);
});
@@ -74,7 +78,7 @@
$model->setLimit(12);
$lister->setModel($model);
-$ipp = \Atk4\Ui\ItemsPerPageSelector::addTo($view, ['label' => 'Select how many countries:', 'pageLengthItems' => [12, 24, 36]], ['Content']);
+$ipp = ItemsPerPageSelector::addTo($view, ['label' => 'Select how many countries:', 'pageLengthItems' => [12, 24, 36]], ['Content']);
$ipp->onPageLengthSelect(function ($ipp) use ($model, $container) {
$model->setLimit($ipp);
diff --git a/demos/collection/multitable.php b/demos/collection/multitable.php
index 549aeb9503..4d163087ae 100644
--- a/demos/collection/multitable.php
+++ b/demos/collection/multitable.php
@@ -5,13 +5,21 @@
namespace Atk4\Ui\Demos;
use Atk4\Data\Model;
+use Atk4\Ui\Button;
+use Atk4\Ui\Columns;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsExpression;
+use Atk4\Ui\JsModal;
+use Atk4\Ui\JsReload;
+use Atk4\Ui\Table;
+use Atk4\Ui\VirtualPage;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
// Re-usable component implementing counter
-$finderClass = AnonymousClassNameCache::get_class(fn () => new class() extends \Atk4\Ui\Columns {
+$finderClass = AnonymousClassNameCache::get_class(fn () => new class() extends Columns {
public $route = [];
public function setModel(Model $model, array $route = []): void
@@ -21,7 +29,7 @@ public function setModel(Model $model, array $route = []): void
$this->addClass('internally celled');
// lets add our first table here
- $table = \Atk4\Ui\Table::addTo($this->addColumn(), ['header' => false, 'class.very basic selectable' => true])->addStyle('cursor', 'pointer');
+ $table = Table::addTo($this->addColumn(), ['header' => false, 'class.very basic selectable' => true])->addStyle('cursor', 'pointer');
$table->setModel($model, [$model->titleField]);
$selections = explode(',', $_GET[$this->name] ?? '');
@@ -30,10 +38,10 @@ public function setModel(Model $model, array $route = []): void
$table->js(true)->find('tr[data-id=' . $selections[0] . ']')->addClass('active');
}
- $makeJsReloadFx = function (array $path): \Atk4\Ui\JsReload {
- return new \Atk4\Ui\JsReload($this, [$this->name => new \Atk4\Ui\JsExpression('[] + []', [
+ $makeJsReloadFx = function (array $path): JsReload {
+ return new JsReload($this, [$this->name => new JsExpression('[] + []', [
count($path) > 0 ? implode(',', $path) . ',' : '',
- new \Atk4\Ui\JsExpression('$(this).data("id")'),
+ new JsExpression('$(this).data("id")'),
])]);
};
@@ -59,7 +67,7 @@ public function setModel(Model $model, array $route = []): void
$pushModel = $pushModel->ref($ref);
- $table = \Atk4\Ui\Table::addTo($this->addColumn(), ['header' => false, 'class.very basic selectable' => true])->addStyle('cursor', 'pointer');
+ $table = Table::addTo($this->addColumn(), ['header' => false, 'class.very basic selectable' => true])->addStyle('cursor', 'pointer');
$table->setModel($pushModel->setLimit(10), [$pushModel->titleField]);
if ($selections) {
@@ -76,15 +84,15 @@ public function setModel(Model $model, array $route = []): void
$model->addCondition($model->fieldName()->parent_folder_id, null);
$model->setOrder([$model->fieldName()->is_folder => 'desc', $model->fieldName()->name]);
-\Atk4\Ui\Header::addTo($app, ['File Finder', 'subHeader' => 'Component built around Table, Columns and JsReload']);
+Header::addTo($app, ['File Finder', 'subHeader' => 'Component built around Table, Columns and JsReload']);
-$vp = \Atk4\Ui\VirtualPage::addTo($app)->set(function (\Atk4\Ui\VirtualPage $vp) use ($model) {
+$vp = VirtualPage::addTo($app)->set(function (VirtualPage $vp) use ($model) {
$model->importFromFilesystem('.');
- \Atk4\Ui\Button::addTo($vp, ['Import Complete', 'class.big green fluid' => true])->link('multitable.php');
+ Button::addTo($vp, ['Import Complete', 'class.big green fluid' => true])->link('multitable.php');
$vp->js(true)->closest('.modal')->find('.header')->remove();
});
-\Atk4\Ui\Button::addTo($app, ['Re-Import From Filesystem', 'class.top attached' => true])->on('click', new \Atk4\Ui\JsModal('Now importing ... ', $vp));
+Button::addTo($app, ['Re-Import From Filesystem', 'class.top attached' => true])->on('click', new JsModal('Now importing ... ', $vp));
$finderClass::addTo($app, ['bottom attached'])
->addClass('top attached segment')
diff --git a/demos/collection/table.php b/demos/collection/table.php
index 3d5f609e34..42db2da432 100644
--- a/demos/collection/table.php
+++ b/demos/collection/table.php
@@ -4,20 +4,25 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
+use Atk4\Ui\Button;
+use Atk4\Ui\JsReload;
+use Atk4\Ui\JsToast;
use Atk4\Ui\Table;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
if ($id = $_GET['id'] ?? null) {
- $app->layout->js(true, new \Atk4\Ui\JsToast('Details link is in simulation mode.'));
+ $app->layout->js(true, new JsToast('Details link is in simulation mode.'));
}
-$bb = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
+$bb = View::addTo($app, ['ui' => 'buttons']);
-$table = \Atk4\Ui\Table::addTo($app, ['class.celled' => true]);
-\Atk4\Ui\Button::addTo($bb, ['Refresh Table', 'icon' => 'refresh'])
- ->on('click', new \Atk4\Ui\JsReload($table));
+$table = Table::addTo($app, ['class.celled' => true]);
+Button::addTo($bb, ['Refresh Table', 'icon' => 'refresh'])
+ ->on('click', new JsReload($table));
$bb->on('click', $table->js()->reload());
@@ -34,7 +39,7 @@
$table->addColumn('salary', new Table\Column\Money());
$table->addColumn('logo_url', [Table\Column\Image::class, 'caption' => 'Our Logo']);
-$table->onHook(Table\Column::HOOK_GET_HTML_TAGS, function ($table, \Atk4\Data\Model $row) {
+$table->onHook(Table\Column::HOOK_GET_HTML_TAGS, function ($table, Model $row) {
switch ($row->getId()) {
case 1:
$color = 'yellow';
@@ -67,7 +72,7 @@
['name' => 'Brett', 'surname' => 'Bird', 'birthdate' => '1988-12-20', 'cv' => null],
];
-$table = \Atk4\Ui\Table::addTo($app);
+$table = Table::addTo($app);
$table->setSource($myArray, ['name']);
// $table->addColumn('name');
diff --git a/demos/collection/table2.php b/demos/collection/table2.php
index 7d25b67cfd..29313206ad 100644
--- a/demos/collection/table2.php
+++ b/demos/collection/table2.php
@@ -4,7 +4,10 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
use Atk4\Data\Persistence;
+use Atk4\Ui\Header;
+use Atk4\Ui\Lister;
use Atk4\Ui\Table;
/** @var \Atk4\Ui\App $app */
@@ -16,12 +19,12 @@
['id' => 3, 'action' => 'Tax', 'amount' => -40],
];
-$model = new \Atk4\Data\Model(new Persistence\Static_($data));
+$model = new Model(new Persistence\Static_($data));
$model->getField('amount')->type = 'atk4_money';
-\Atk4\Ui\Header::addTo($app, ['Table with various headers', 'subHeader' => 'Demonstrates how you can add subheaders, footnotes and other insertions into your data table', 'icon' => 'table']);
+Header::addTo($app, ['Table with various headers', 'subHeader' => 'Demonstrates how you can add subheaders, footnotes and other insertions into your data table', 'icon' => 'table']);
-$table = \Atk4\Ui\Table::addTo($app);
+$table = Table::addTo($app);
$table->setModel($model, ['action']);
$table->addColumn('amount', [Table\Column\Money::class]);
@@ -30,7 +33,7 @@
$table->template->dangerouslyAppendHtml('Body', '
This is part of body, goes before other rows ');
// Hook can be used to display data before row. You can also inject and format extra rows.
-$table->onHook(\Atk4\Ui\Lister::HOOK_BEFORE_ROW, function (Table $table) {
+$table->onHook(Lister::HOOK_BEFORE_ROW, function (Table $table) {
if ($table->currentRow->getId() === 2) {
$table->template->dangerouslyAppendHtml('Body', '
This goes above row with ID=2 (' . $table->currentRow->get('action') . ') ');
} elseif ($table->currentRow->get('action') === 'Tax') {
@@ -47,13 +50,13 @@
$table->template->dangerouslyAppendHtml('Foot', '
This will appear above totals ');
$table->addTotals(['action' => 'Totals:', 'amount' => ['sum']]);
-\Atk4\Ui\Header::addTo($app, ['Columns with multiple formats', 'subHeader' => 'Single column can use logic to swap out formatters', 'icon' => 'table']);
+Header::addTo($app, ['Columns with multiple formats', 'subHeader' => 'Single column can use logic to swap out formatters', 'icon' => 'table']);
-$table = \Atk4\Ui\Table::addTo($app);
+$table = Table::addTo($app);
$table->setModel($model, ['action']);
// copy of amount through a PHP callback
-$model->addExpression('amount_copy', ['expr' => function (\Atk4\Data\Model $model) {
+$model->addExpression('amount_copy', ['expr' => function (Model $model) {
return $model->get('amount');
}, 'type' => 'atk4_money']);
@@ -79,8 +82,8 @@
return Table\Column\Money::class;
}, 'attr' => ['all' => ['class' => ['right aligned singel line']]]]);
-\Atk4\Ui\Header::addTo($app, ['Table with resizable columns', 'subHeader' => 'Just drag column header to resize', 'icon' => 'table']);
+Header::addTo($app, ['Table with resizable columns', 'subHeader' => 'Just drag column header to resize', 'icon' => 'table']);
-$table = \Atk4\Ui\Table::addTo($app);
+$table = Table::addTo($app);
$table->setModel($model);
$table->addClass('celled')->resizableColumn();
diff --git a/demos/collection/tablecolumnmenu.php b/demos/collection/tablecolumnmenu.php
index 20e57c2af7..8e673ff0fc 100644
--- a/demos/collection/tablecolumnmenu.php
+++ b/demos/collection/tablecolumnmenu.php
@@ -4,14 +4,20 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Grid;
+use Atk4\Ui\Header;
+use Atk4\Ui\Table;
+use Atk4\Ui\Text;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, ['Table column may contains popup or dropdown menu.']);
+Header::addTo($app, ['Table column may contains popup or dropdown menu.']);
// Better Popup positionning when Popup are inside a container.
-$container = \Atk4\Ui\View::addTo($app, ['ui' => 'vertical segment']);
-$table = \Atk4\Ui\Table::addTo($container, ['class.celled' => true]);
+$container = View::addTo($app, ['ui' => 'vertical segment']);
+$table = Table::addTo($container, ['class.celled' => true]);
$table->setModel(new SomeData(), []);
// will add popup to this column.
@@ -23,15 +29,15 @@
$colTitle = $table->addColumn('title');
$table->addColumn('date');
-$table->addColumn('salary', new \Atk4\Ui\Table\Column\Money());
+$table->addColumn('salary', new Table\Column\Money());
// regular popup setup
-\Atk4\Ui\Text::addTo($colName->addPopup())->set('Name popup');
+Text::addTo($colName->addPopup())->set('Name popup');
// dynamic popup setup
// This popup will add content using the callback function.
$colSurname->addPopup()->set(function ($pop) {
- \Atk4\Ui\Text::addTo($pop)->set('This popup is loaded dynamically');
+ Text::addTo($pop)->set('This popup is loaded dynamically');
});
// Another dropdown menu.
@@ -41,10 +47,10 @@
// -----------------------------------------------------------------------------
-\Atk4\Ui\Header::addTo($app, ['Grid column may contains popup or dropdown menu.']);
+Header::addTo($app, ['Grid column may contains popup or dropdown menu.']);
// Table in Grid are already inside a container.
-$grid = \Atk4\Ui\Grid::addTo($app);
+$grid = Grid::addTo($app);
$grid->setModel(new Country($app->db));
$grid->ipp = 5;
@@ -55,4 +61,4 @@
// Adding a popup view to the column 'iso'
$pop = $grid->addPopup(Country::hinting()->fieldName()->iso);
-\Atk4\Ui\Text::addTo($pop)->set('Grid column popup');
+Text::addTo($pop)->set('Grid column popup');
diff --git a/demos/collection/tablecolumns.php b/demos/collection/tablecolumns.php
index ede4daf3a3..f7f021320b 100644
--- a/demos/collection/tablecolumns.php
+++ b/demos/collection/tablecolumns.php
@@ -4,14 +4,16 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
use Atk4\Data\Persistence;
+use Atk4\Ui\Header;
use Atk4\Ui\Table;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-/** @var \Atk4\Data\Model $modelColorClass */
-$modelColorClass = AnonymousClassNameCache::get_class(fn () => new class() extends \Atk4\Data\Model {
+/** @var Model $modelColorClass */
+$modelColorClass = AnonymousClassNameCache::get_class(fn () => new class() extends Model {
protected function init(): void
{
parent::init();
@@ -110,7 +112,7 @@ protected function init(): void
'four',
];
-\Atk4\Ui\Header::addTo($app, ['Table column', 'subHeader' => 'Table column decorator can be set from your model.']);
+Header::addTo($app, ['Table column', 'subHeader' => 'Table column decorator can be set from your model.']);
$model = new $modelColorClass(new Persistence\Static_([]));
@@ -129,5 +131,5 @@ protected function init(): void
]);
}
-$table = \Atk4\Ui\Table::addTo($app);
+$table = Table::addTo($app);
$table->setModel($model);
diff --git a/demos/collection/tablefilter.php b/demos/collection/tablefilter.php
index f6458648c7..2952afe2ee 100644
--- a/demos/collection/tablefilter.php
+++ b/demos/collection/tablefilter.php
@@ -4,13 +4,16 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Grid;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
// For popup positioning to work correctly, table need to be inside a view segment.
-$view = \Atk4\Ui\View::addTo($app, ['ui' => 'basic segment']);
+$view = View::addTo($app, ['ui' => 'basic segment']);
// Important: menu class added for Behat testing.
-$grid = \Atk4\Ui\Grid::addTo($view, ['menu' => ['class' => ['atk-grid-menu']]]);
+$grid = Grid::addTo($view, ['menu' => ['class' => ['atk-grid-menu']]]);
$model = new Country($app->db);
$model->addExpression('is_uk', [
diff --git a/demos/data-action/actions.php b/demos/data-action/actions.php
index e1c79a66c4..bb26332f63 100644
--- a/demos/data-action/actions.php
+++ b/demos/data-action/actions.php
@@ -8,6 +8,7 @@
use Atk4\Ui\Button;
use Atk4\Ui\Columns;
use Atk4\Ui\Header;
+use Atk4\Ui\JsToast;
use Atk4\Ui\UserAction;
use Atk4\Ui\View;
@@ -17,31 +18,28 @@
$files = new File($app->db);
// Actions can be added easily to the model via the Model::addUserAction($name, $properties) method.
-$action = $files->addUserAction(
- 'import_from_filesystem',
- [
- // Which fields may be edited for the action. Default to all fields.
- // ModalExecutor for example, will only display fields set in this array.
- 'fields' => [$files->fieldName()->name],
- // callback function to call in model when action execute.
- // Can use a closure function or model method.
- 'callback' => 'importFromFilesystem',
- // Some Ui action executor will use this property for displaying text in button.
- // Can be override by some Ui executor description property.
- 'description' => 'Import file in a specify path.',
- // Display information prior to execute the action.
- // ModalExecutor or PreviewExecutor will display preview.
- 'preview' => function (Model $model, $path) {
- return 'Execute Import using path: "' . $path . '"';
- },
- // Argument needed to run the callback action method.
- // Some ui executor will ask for arguments prior to run the action, like the ModalExecutor.
- 'args' => [
- 'path' => ['type' => 'string', 'required' => true],
- ],
- 'appliesTo' => \Atk4\Data\Model\UserAction::APPLIES_TO_NO_RECORDS,
- ]
-);
+$action = $files->addUserAction('import_from_filesystem', [
+ // Which fields may be edited for the action. Default to all fields.
+ // ModalExecutor for example, will only display fields set in this array.
+ 'fields' => [$files->fieldName()->name],
+ // callback function to call in model when action execute.
+ // Can use a closure function or model method.
+ 'callback' => 'importFromFilesystem',
+ // Some Ui action executor will use this property for displaying text in button.
+ // Can be override by some Ui executor description property.
+ 'description' => 'Import file in a specify path.',
+ // Display information prior to execute the action.
+ // ModalExecutor or PreviewExecutor will display preview.
+ 'preview' => function (Model $model, $path) {
+ return 'Execute Import using path: "' . $path . '"';
+ },
+ // Argument needed to run the callback action method.
+ // Some ui executor will ask for arguments prior to run the action, like the ModalExecutor.
+ 'args' => [
+ 'path' => ['type' => 'string', 'required' => true],
+ ],
+ 'appliesTo' => Model\UserAction::APPLIES_TO_NO_RECORDS,
+]);
Header::addTo($app, [
'Extensions to ATK Data Actions',
@@ -64,11 +62,11 @@
$executor->setAction($action->getActionForEntity($files->createEntity()));
// Setting user response after model action get execute.
$executor->onHook(UserAction\BasicExecutor::HOOK_AFTER_EXECUTE, function ($t, $m) {
- return new \Atk4\Ui\JsToast('Files imported');
+ return new JsToast('Files imported');
});
$executor->executeModelAction(['path' => '.']);
-$btn = \Atk4\Ui\Button::addTo($rightColumn, ['Import File']);
+$btn = Button::addTo($rightColumn, ['Import File']);
$btn->on('click', $executor, ['confirm' => 'This will import a lot of file. Are you sure?']);
Header::addTo($rightColumn, ['BasicExecutor']);
@@ -78,7 +76,7 @@
$executor->description = 'Execute Import action using "BasicExecutor" with argument "path" equal to "."';
$executor->setArguments(['path' => '.']);
$executor->onHook(UserAction\BasicExecutor::HOOK_AFTER_EXECUTE, function ($x) {
- return new \Atk4\Ui\JsToast('Done!');
+ return new JsToast('Done!');
});
View::addTo($rightColumn, ['ui' => 'hidden divider']);
@@ -91,7 +89,7 @@
$executor->description = 'Displays preview in console prior to executing';
$executor->setArguments(['path' => '.']);
$executor->onHook(UserAction\BasicExecutor::HOOK_AFTER_EXECUTE, function ($x, $ret) {
- return new \Atk4\Ui\JsToast('Confirm!');
+ return new JsToast('Confirm!');
});
Header::addTo($leftColumn, ['FormExecutor']);
@@ -101,7 +99,7 @@
$executor->description = 'Only fields set in $action[field] array will be added in form.';
$executor->setArguments(['path' => '.']);
$executor->onHook(UserAction\BasicExecutor::HOOK_AFTER_EXECUTE, function ($x, $ret) {
- return new \Atk4\Ui\JsToast('Confirm! ' . $x->action->getEntity()->name);
+ return new JsToast('Confirm! ' . $x->action->getEntity()->name);
});
View::addTo($leftColumn, ['ui' => 'hidden divider']);
@@ -112,5 +110,5 @@
$executor->description = 'ArgumentFormExecutor will ask user about arguments set in actions.';
$executor->ui = 'segment';
$executor->onHook(UserAction\BasicExecutor::HOOK_AFTER_EXECUTE, function ($x, $ret) {
- return new \Atk4\Ui\JsToast('Imported!');
+ return new JsToast('Imported!');
});
diff --git a/demos/data-action/factory.php b/demos/data-action/factory.php
index c6ef6f629a..bd1c26ef3e 100644
--- a/demos/data-action/factory.php
+++ b/demos/data-action/factory.php
@@ -6,6 +6,8 @@
use Atk4\Ui\Button;
use Atk4\Ui\CardDeck;
+use Atk4\Ui\Crud;
+use Atk4\Ui\Message;
use Atk4\Ui\UserAction\ExecutorFactory;
use Atk4\Ui\View;
@@ -16,7 +18,7 @@
->link(['factory-view']);
View::addTo($app, ['ui' => 'ui clearing divider']);
-$msg = \Atk4\Ui\Message::addTo($app, [
+$msg = Message::addTo($app, [
'Customizing action trigger by Overriding Executor Factory',
]);
$msg->text->addParagraph('');
@@ -51,7 +53,7 @@
$country = new Country($app->db);
-$crud = \Atk4\Ui\Crud::addTo($app, ['ipp' => 5]);
+$crud = Crud::addTo($app, ['ipp' => 5]);
$crud->setModel($country);
View::addTo($app, ['class' => ['ui divider']]);
diff --git a/demos/data-action/jsactions.php b/demos/data-action/jsactions.php
index f539a9a311..f0fce0e9cb 100644
--- a/demos/data-action/jsactions.php
+++ b/demos/data-action/jsactions.php
@@ -5,13 +5,16 @@
namespace Atk4\Ui\Demos;
use Atk4\Data\Model\UserAction;
+use Atk4\Ui\Card;
use Atk4\Ui\Form\Control\Line;
-use Atk4\Ui\UserAction\JsCallbackExecutor;
+use Atk4\Ui\Header;
+use Atk4\Ui\Image;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, [
+Header::addTo($app, [
'Extensions to ATK Data Actions',
'subHeader' => 'Model action can be trigger in various ways.',
]);
@@ -28,9 +31,9 @@
// -----------------------------------------------------------------------------
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-\Atk4\Ui\Header::addTo($app, [
+Header::addTo($app, [
'Using Input button',
'size' => 4,
'subHeader' => 'Action can be triggered via a button attached to an input. The data action argument value is set to the input value.',
@@ -55,20 +58,20 @@
// -----------------------------------------------------------------------------
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-\Atk4\Ui\Header::addTo($app, [
+Header::addTo($app, [
'Using buttons in a Card component',
'size' => 4,
'subHeader' => 'Easily trigger a data action using a Card component.',
]);
// Card component.
-$card = \Atk4\Ui\Card::addTo($app);
-$content = new \Atk4\Ui\View(['class' => ['content']]);
-$img = \Atk4\Ui\Image::addTo($content, ['../images/kristy.png']);
+$card = Card::addTo($app);
+$content = new View(['class' => ['content']]);
+$img = Image::addTo($content, ['../images/kristy.png']);
$img->addClass('right floated mini ui image');
-\Atk4\Ui\Header::addTo($content, ['Kristy']);
+Header::addTo($content, ['Kristy']);
$card->addContent($content);
$card->addDescription('Kristy is a friend of Mully.');
diff --git a/demos/data-action/jsactions2.php b/demos/data-action/jsactions2.php
index 3da9cee39d..d875b8d762 100644
--- a/demos/data-action/jsactions2.php
+++ b/demos/data-action/jsactions2.php
@@ -4,9 +4,14 @@
namespace Atk4\Ui\Demos;
-// Demo for Model action
-
+use Atk4\Ui\Button;
+use Atk4\Ui\Card;
+use Atk4\Ui\GridLayout;
+use Atk4\Ui\Header;
use Atk4\Ui\Message;
+use Atk4\Ui\View;
+
+// Demo for Model action
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
@@ -18,24 +23,24 @@
// Model actions for this file are setup in DemoActionUtil.
DemoActionsUtil::setupDemoActions($country);
-\Atk4\Ui\Header::addTo($app, ['Assign Model action to button event', 'subHeader' => 'Execute model action on this country record by clicking on the appropriate button on the right.']);
+Header::addTo($app, ['Assign Model action to button event', 'subHeader' => 'Execute model action on this country record by clicking on the appropriate button on the right.']);
$msg = Message::addTo($app, ['Notes', 'type' => 'info']);
$msg->text->addParagraph('When passing an action to a button event, Ui will determine what executor is required base on the action properties.');
$msg->text->addParagraph('If action require arguments, fields and/or preview, then a ModalExecutor will be use.');
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-$gl = \Atk4\Ui\GridLayout::addTo($app, ['rows' => 1, 'columns' => 2]);
-$c = \Atk4\Ui\Card::addTo($gl, ['useLabel' => true], ['r1c1']);
-$c->addContent(new \Atk4\Ui\Header(['Using country: ']));
+$gl = GridLayout::addTo($app, ['rows' => 1, 'columns' => 2]);
+$c = Card::addTo($gl, ['useLabel' => true], ['r1c1']);
+$c->addContent(new Header(['Using country: ']));
$c->setModel($entity, [$country->fieldName()->iso, $country->fieldName()->iso3, $country->fieldName()->phonecode]);
-$buttons = \Atk4\Ui\View::addTo($gl, ['ui' => 'vertical basic buttons'], ['r1c2']);
+$buttons = View::addTo($gl, ['ui' => 'vertical basic buttons'], ['r1c2']);
// Create a button for every action in Country model.
foreach ($country->getUserActions() as $action) {
- $b = \Atk4\Ui\Button::addTo($buttons, [$action->getCaption()]);
+ $b = Button::addTo($buttons, [$action->getCaption()]);
// Assign action to button using current model id as url arguments.
$b->on('click', $action, ['args' => ['id' => $countryId]]);
}
diff --git a/demos/data-action/jsactionscrud.php b/demos/data-action/jsactionscrud.php
index 50e2910b5c..a6959f5acf 100644
--- a/demos/data-action/jsactionscrud.php
+++ b/demos/data-action/jsactionscrud.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Demos;
use Atk4\Data\Model;
+use Atk4\Ui\Crud;
use Atk4\Ui\Header;
/** @var \Atk4\Ui\App $app */
@@ -17,25 +18,22 @@
$files = new File($app->db);
// This action must appear on top of the Crud
-$files->addUserAction(
- 'import_from_filesystem',
- [
- 'caption' => 'Import',
- 'callback' => 'importFromFilesystem',
- 'description' => 'Import file using path:',
- 'preview' => function (Model $model, $path) {
- return 'Execute Import using path: "' . $path . '"';
- },
- 'args' => [
- 'path' => ['type' => 'string', 'required' => true],
- ],
- 'appliesTo' => \Atk4\Data\Model\UserAction::APPLIES_TO_NO_RECORDS,
- ]
-);
+$files->addUserAction('import_from_filesystem', [
+ 'caption' => 'Import',
+ 'callback' => 'importFromFilesystem',
+ 'description' => 'Import file using path:',
+ 'preview' => function (Model $model, $path) {
+ return 'Execute Import using path: "' . $path . '"';
+ },
+ 'args' => [
+ 'path' => ['type' => 'string', 'required' => true],
+ ],
+ 'appliesTo' => Model\UserAction::APPLIES_TO_NO_RECORDS,
+]);
$files->addUserAction('download', function (Model $model) {
return 'File has been download!';
});
-\Atk4\Ui\Crud::addTo($app, ['ipp' => 10])
+Crud::addTo($app, ['ipp' => 10])
->setModel($files);
diff --git a/demos/data-action/jsactionsgrid.php b/demos/data-action/jsactionsgrid.php
index 53ac9bce43..69ea62eed4 100644
--- a/demos/data-action/jsactionsgrid.php
+++ b/demos/data-action/jsactionsgrid.php
@@ -6,15 +6,17 @@
use Atk4\Core\Factory;
use Atk4\Data\Model\UserAction;
+use Atk4\Ui\Grid;
+use Atk4\Ui\Header;
use Atk4\Ui\Icon;
use Atk4\Ui\UserAction\ExecutorFactory;
use Atk4\Ui\View;
+// Demo for Model action in Grid
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-// Demo for Model action in Grid
-
$country = new Country($app->db);
// Model actions for this file are setup in DemoActionUtil.
DemoActionsUtil::setupDemoActions($country);
@@ -26,9 +28,9 @@
// register this menu item in factory.
$app->getExecutorFactory()->registerTrigger(ExecutorFactory::TABLE_MENU_ITEM, $specialItem, $multiAction);
-\Atk4\Ui\Header::addTo($app, ['Execute model action from Grid menu items', 'subHeader' => 'Setting grid menu items in order to execute model actions or javascript.']);
+Header::addTo($app, ['Execute model action from Grid menu items', 'subHeader' => 'Setting grid menu items in order to execute model actions or javascript.']);
-$grid = \Atk4\Ui\Grid::addTo($app, ['menu' => false]);
+$grid = Grid::addTo($app, ['menu' => false]);
$grid->setModel($country);
$divider = Factory::factory([View::class], ['name' => false, 'class' => ['divider'], 'content' => '']);
diff --git a/demos/form-control/checkbox.php b/demos/form-control/checkbox.php
index 7166185b19..7a0aa8dbcf 100644
--- a/demos/form-control/checkbox.php
+++ b/demos/form-control/checkbox.php
@@ -5,14 +5,14 @@
namespace Atk4\Ui\Demos;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsToast;
use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-// Testing fields.
-
-\Atk4\Ui\Header::addTo($app, ['CheckBoxes', 'size' => 2]);
+Header::addTo($app, ['CheckBoxes', 'size' => 2]);
Form\Control\Checkbox::addTo($app, ['Make my profile visible']);
Form\Control\Checkbox::addTo($app, ['Make my profile visible ticked'])->set(true);
@@ -28,14 +28,14 @@
View::addTo($app, ['ui' => 'divider']);
Form\Control\Checkbox::addTo($app, ['Custom setting?'])->js(true)->checkbox('set indeterminate');
-\Atk4\Ui\Header::addTo($app, ['CheckBoxes in a form', 'size' => 2]);
+Header::addTo($app, ['CheckBoxes in a form', 'size' => 2]);
$form = Form::addTo($app);
$form->addControl('test', [Form\Control\Checkbox::class]);
$form->addControl('test_checked', [Form\Control\Checkbox::class])->set(1);
$form->addControl('also_checked', ['caption' => 'Hello World'], ['type' => 'boolean'])->set(true);
$form->onSubmit(function (Form $form) use ($app) {
- return new \Atk4\Ui\JsToast($app->encodeJson($form->model->get()));
+ return new JsToast($app->encodeJson($form->model->get()));
});
View::addTo($app, ['ui' => 'divider']);
diff --git a/demos/form-control/dropdown-plus.php b/demos/form-control/dropdown-plus.php
index de46fb97ef..9e9eb08121 100644
--- a/demos/form-control/dropdown-plus.php
+++ b/demos/form-control/dropdown-plus.php
@@ -6,16 +6,19 @@
use Atk4\Data\Model;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\Message;
+use Atk4\Ui\Text;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
$demo = Demo::addTo($app);
-\Atk4\Ui\Header::addTo($demo->left, ['Dropdown sample:']);
-\Atk4\Ui\Header::addTo($demo->right, ['Cascading Dropdown']);
+Header::addTo($demo->left, ['Dropdown sample:']);
+Header::addTo($demo->right, ['Cascading Dropdown']);
-$txt = \Atk4\Ui\Text::addTo($demo->right);
+$txt = Text::addTo($demo->right);
$txt->addParagraph('Dropdown may also be used in a cascade manner.');
$form = Form::addTo($demo->right);
@@ -26,7 +29,7 @@
$form->onSubmit(function (Form $form) use ($app) {
$message = $app->encodeJson($form->model->get());
- $view = new \Atk4\Ui\Message('Values: ');
+ $view = new Message('Values: ');
$view->invokeInit();
$view->text->addParagraph($message);
@@ -36,92 +39,71 @@
$form = Form::addTo($demo->left);
// standard with model: use idField as Value, titleField as Title for each Dropdown option
-$form->addControl(
- 'withModel',
- [
- Form\Control\Dropdown::class,
- 'caption' => 'Dropdown with data from Model',
- 'model' => (new Country($app->db))->setLimit(25),
- ]
-);
+$form->addControl('withModel', [
+ Form\Control\Dropdown::class,
+ 'caption' => 'Dropdown with data from Model',
+ 'model' => (new Country($app->db))->setLimit(25),
+]);
// custom callback: alter title
-$form->addControl(
- 'withModel2',
- [
- Form\Control\Dropdown::class,
- 'caption' => 'Dropdown with data from Model',
- 'model' => (new Country($app->db))->setLimit(25),
- 'renderRowFunction' => function (Country $row) {
- return [
- 'value' => $row->getId(),
- 'title' => $row->getTitle() . ' (' . $row->iso3 . ')',
- ];
- },
- ]
-);
+$form->addControl('withModel2', [
+ Form\Control\Dropdown::class,
+ 'caption' => 'Dropdown with data from Model',
+ 'model' => (new Country($app->db))->setLimit(25),
+ 'renderRowFunction' => function (Country $row) {
+ return [
+ 'value' => $row->getId(),
+ 'title' => $row->getTitle() . ' (' . $row->iso3 . ')',
+ ];
+ },
+]);
// custom callback: add icon
-$form->addControl(
- 'withModel3',
- [
- Form\Control\Dropdown::class,
- 'caption' => 'Dropdown with data from Model',
- 'model' => (new File($app->db))->setLimit(25),
- 'renderRowFunction' => function (File $row) {
- return [
- 'value' => $row->getId(),
- 'title' => $row->getTitle(),
- 'icon' => $row->is_folder ? 'folder' : 'file',
- ];
- },
- ]
-);
-
-$form->addControl(
- 'enum',
- [
- Form\Control\Dropdown::class,
- 'caption' => 'Using Single Values',
- 'values' => ['default', 'option1', 'option2', 'option3'],
- ]
-);
-
-$form->addControl(
- 'values',
- [
- Form\Control\Dropdown::class,
- 'caption' => 'Using values with default text',
- 'empty' => 'Choose an option',
- 'values' => ['default' => 'Default', 'option1' => 'Option 1', 'option2' => 'Option 2', 'option3' => 'Option 3'],
- ]
-);
-
-$form->addControl(
- 'icon',
- [
- Form\Control\Dropdown::class,
- 'caption' => 'Using icon',
- 'empty' => 'Choose an icon',
- 'values' => ['tag' => ['Tag', 'icon' => 'tag icon'], 'globe' => ['Globe', 'icon' => 'globe icon'], 'registered' => ['Registered', 'icon' => 'registered icon'], 'file' => ['File', 'icon' => 'file icon']],
- ]
-);
-
-$form->addControl(
- 'multi',
- [
- Form\Control\Dropdown::class,
- 'caption' => 'Multiple selection',
- 'empty' => 'Choose has many options needed',
- 'isMultiple' => true,
- 'values' => ['default' => 'Default', 'option1' => 'Option 1', 'option2' => 'Option 2'],
- ]
-);
+$form->addControl('withModel3', [
+ Form\Control\Dropdown::class,
+ 'caption' => 'Dropdown with data from Model',
+ 'model' => (new File($app->db))->setLimit(25),
+ 'renderRowFunction' => function (File $row) {
+ return [
+ 'value' => $row->getId(),
+ 'title' => $row->getTitle(),
+ 'icon' => $row->is_folder ? 'folder' : 'file',
+ ];
+ },
+]);
+
+$form->addControl('enum', [
+ Form\Control\Dropdown::class,
+ 'caption' => 'Using Single Values',
+ 'values' => ['default', 'option1', 'option2', 'option3'],
+]);
+
+$form->addControl('values', [
+ Form\Control\Dropdown::class,
+ 'caption' => 'Using values with default text',
+ 'empty' => 'Choose an option',
+ 'values' => ['default' => 'Default', 'option1' => 'Option 1', 'option2' => 'Option 2', 'option3' => 'Option 3'],
+]);
+
+$form->addControl('icon', [
+ Form\Control\Dropdown::class,
+ 'caption' => 'Using icon',
+ 'empty' => 'Choose an icon',
+ 'values' => ['tag' => ['Tag', 'icon' => 'tag icon'], 'globe' => ['Globe', 'icon' => 'globe icon'], 'registered' => ['Registered', 'icon' => 'registered icon'], 'file' => ['File', 'icon' => 'file icon']],
+]);
+
+$form->addControl('multi', [
+ Form\Control\Dropdown::class,
+ 'caption' => 'Multiple selection',
+ 'empty' => 'Choose has many options needed',
+ 'isMultiple' => true,
+ 'values' => ['default' => 'Default', 'option1' => 'Option 1', 'option2' => 'Option 2'],
+]);
$form->onSubmit(function (Form $form) use ($app) {
$message = $app->encodeJson($form->model->get());
- $view = new \Atk4\Ui\Message('Values: ');
+ $view = new Message('Values: ');
$view->invokeInit();
$view->text->addParagraph($message);
diff --git a/demos/form-control/form6.php b/demos/form-control/form6.php
index cd4f47cc25..31e04b2490 100644
--- a/demos/form-control/form6.php
+++ b/demos/form-control/form6.php
@@ -4,18 +4,20 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Columns;
use Atk4\Ui\Form;
use Atk4\Ui\JsToast;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\View::addTo($app, [
+View::addTo($app, [
'Forms below demonstrate how to work with multi-value selectors',
'ui' => 'ignored warning message',
]);
-$cc = \Atk4\Ui\Columns::addTo($app);
+$cc = Columns::addTo($app);
$form = Form::addTo($cc->addColumn());
$form->addControl('one', [], ['enum' => ['female', 'male']])->set('male');
diff --git a/demos/form-control/input.php b/demos/form-control/input.php
index 399d248d19..f9d2726af2 100644
--- a/demos/form-control/input.php
+++ b/demos/form-control/input.php
@@ -4,12 +4,17 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Dropdown as UiDropdown;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\Icon;
+use Atk4\Ui\Label;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, ['Types', 'size' => 2]);
+Header::addTo($app, ['Types', 'size' => 2]);
Form\Control\Line::addTo($app)->setDefaults(['placeholder' => 'Search']);
Form\Control\Line::addTo($app, ['placeholder' => 'Search', 'loading' => true]);
@@ -17,84 +22,84 @@
Form\Control\Line::addTo($app, ['placeholder' => 'Search', 'icon' => 'search', 'class.disabled' => true]);
Form\Control\Line::addTo($app, ['placeholder' => 'Search', 'class.error' => true]);
-\Atk4\Ui\Header::addTo($app, ['Icon Variations', 'size' => 2]);
+Header::addTo($app, ['Icon Variations', 'size' => 2]);
Form\Control\Line::addTo($app, ['placeholder' => 'Search users', 'class.left' => true, 'icon' => 'users']);
Form\Control\Line::addTo($app, ['placeholder' => 'Search users', 'icon' => 'circular search link']);
Form\Control\Line::addTo($app, ['placeholder' => 'Search users', 'icon' => 'inverted circular search link']);
-\Atk4\Ui\Header::addTo($app, ['Labels', 'size' => 2]);
+Header::addTo($app, ['Labels', 'size' => 2]);
Form\Control\Line::addTo($app, ['placeholder' => 'Search users', 'label' => 'http://']);
// dropdown example
-$dd = new \Atk4\Ui\Dropdown('.com');
+$dd = new UiDropdown('.com');
$dd->setSource(['.com', '.net', '.org']);
Form\Control\Line::addTo($app, [
'placeholder' => 'Find Domain',
'labelRight' => $dd,
]);
-Form\Control\Line::addTo($app, ['placeholder' => 'Weight', 'labelRight' => new \Atk4\Ui\Label(['kg', 'class.basic' => true])]);
-Form\Control\Line::addTo($app, ['label' => '$', 'labelRight' => new \Atk4\Ui\Label(['.00', 'class.basic' => true])]);
+Form\Control\Line::addTo($app, ['placeholder' => 'Weight', 'labelRight' => new Label(['kg', 'class.basic' => true])]);
+Form\Control\Line::addTo($app, ['label' => '$', 'labelRight' => new Label(['.00', 'class.basic' => true])]);
Form\Control\Line::addTo($app, [
'iconLeft' => 'tags',
- 'labelRight' => new \Atk4\Ui\Label(['Add Tag', 'class.tag' => true]),
+ 'labelRight' => new Label(['Add Tag', 'class.tag' => true]),
]);
// left/right corner is not supported, but here is work-around:
-$label = new \Atk4\Ui\Label();
+$label = new Label();
$label->addClass('left corner');
-\Atk4\Ui\Icon::addTo($label, ['asterisk']);
+Icon::addTo($label, ['asterisk']);
Form\Control\Line::addTo($app, [
'label' => $label,
])->addClass('left corner');
-$label = new \Atk4\Ui\Label();
+$label = new Label();
$label->addClass('corner');
-\Atk4\Ui\Icon::addTo($label, ['asterisk']);
+Icon::addTo($label, ['asterisk']);
Form\Control\Line::addTo($app, [
'label' => $label,
])->addClass('corner');
-\Atk4\Ui\Header::addTo($app, ['Actions', 'size' => 2]);
+Header::addTo($app, ['Actions', 'size' => 2]);
Form\Control\Line::addTo($app, ['action' => 'Search']);
-Form\Control\Line::addTo($app, ['actionLeft' => new \Atk4\Ui\Button([
+Form\Control\Line::addTo($app, ['actionLeft' => new Button([
'Checkout', 'class.teal' => true, 'icon' => 'cart',
])]);
Form\Control\Line::addTo($app, ['iconLeft' => 'search', 'action' => 'Search']);
-$dd = new \Atk4\Ui\DropdownButton(['This Page', 'class.basic' => true]);
+$dd = new UiDropdown(['This Page', 'class.basic' => true]);
$dd->setSource(['This Organisation', 'Entire Site']);
Form\Control\Line::addTo($app, ['iconLeft' => 'search', 'action' => $dd]);
// double actions are not supported but you can add them yourself
-$dd = new \Atk4\Ui\Dropdown(['Articles', 'class.compact selection' => true]);
+$dd = new UiDropdown(['Articles', 'class.compact selection' => true]);
$dd->setSource(['All', 'Services', 'Products']);
-\Atk4\Ui\Button::addTo(Form\Control\Line::addTo($app, ['iconLeft' => 'search', 'action' => $dd]), ['Search'], ['AfterAfterInput']);
+Button::addTo(Form\Control\Line::addTo($app, ['iconLeft' => 'search', 'action' => $dd]), ['Search'], ['AfterAfterInput']);
-Form\Control\Line::addTo($app, ['action' => new \Atk4\Ui\Button([
+Form\Control\Line::addTo($app, ['action' => new Button([
'Copy', 'class.teal' => true, 'iconRight' => 'copy',
])]);
-Form\Control\Line::addTo($app, ['action' => new \Atk4\Ui\Button([
+Form\Control\Line::addTo($app, ['action' => new Button([
'icon' => 'search',
])]);
-\Atk4\Ui\Header::addTo($app, ['Modifiers', 'size' => 2]);
+Header::addTo($app, ['Modifiers', 'size' => 2]);
Form\Control\Line::addTo($app, ['icon' => 'search', 'class.transparent' => true, 'placeholder' => 'transparent']);
Form\Control\Line::addTo($app, ['icon' => 'search', 'class.fluid' => true, 'placeholder' => 'fluid']);
Form\Control\Line::addTo($app, ['icon' => 'search', 'class.mini' => true, 'placeholder' => 'mini']);
-\Atk4\Ui\Header::addTo($app, ['Custom HTML attributes for
tag', 'size' => 2]);
+Header::addTo($app, ['Custom HTML attributes for
tag', 'size' => 2]);
$l = Form\Control\Line::addTo($app, ['placeholder' => 'maxlength attribute set to 10']);
$l->setInputAttr('maxlength', '10');
$l = Form\Control\Line::addTo($app, ['class.fluid' => true, 'placeholder' => 'overwrite existing attribute (type="number")']);
diff --git a/demos/form-control/input2.php b/demos/form-control/input2.php
index 1427b1247e..96f2d561a9 100644
--- a/demos/form-control/input2.php
+++ b/demos/form-control/input2.php
@@ -5,12 +5,16 @@
namespace Atk4\Ui\Demos;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
use Atk4\Ui\HtmlTemplate;
+use Atk4\Ui\JsExpression;
+use Atk4\Ui\Tabs;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, ['Disabled and read only form controls (normal / read only / disabled)']);
+Header::addTo($app, ['Disabled and read only form controls (normal / read only / disabled)']);
$form = Form::addTo($app);
@@ -99,16 +103,16 @@
$form->onSubmit(function (Form $form) {
});
-\Atk4\Ui\Header::addTo($app, ['Stand Alone Line']);
+Header::addTo($app, ['Stand Alone Line']);
// you can pass values to button
$control = Form\Control\Line::addTo($app);
$control->set('hello world');
$button = $control->addAction('check value');
-$button->on('click', new \Atk4\Ui\JsExpression('alert("field value is: "+[])', [$control->jsInput()->val()]));
+$button->on('click', new JsExpression('alert("field value is: "+[])', [$control->jsInput()->val()]));
-\Atk4\Ui\Header::addTo($app, ['Line in a Form']);
+Header::addTo($app, ['Line in a Form']);
$form = Form::addTo($app);
$control = $form->addControl('Title', [], ['values' => ['Mr', 'Mrs', 'Miss'], 'ui' => ['hint' => 'select one']]);
@@ -117,7 +121,7 @@
$control->set('value in a form');
$control = $form->addControl('surname', new Form\Control\Line([
- 'hint' => [\Atk4\Ui\View::class, 'template' => new HtmlTemplate(
+ 'hint' => [View::class, 'template' => new HtmlTemplate(
'Click
here '
)],
]));
@@ -126,11 +130,11 @@
return $form->model->get('name');
});
-\Atk4\Ui\Header::addTo($app, ['Multiple Form Layouts']);
+Header::addTo($app, ['Multiple Form Layouts']);
$form = Form::addTo($app);
-$tabs = \Atk4\Ui\Tabs::addTo($form, [], ['AboveControls']);
-\Atk4\Ui\View::addTo($form, ['ui' => 'divider'], ['AboveControls']);
+$tabs = Tabs::addTo($form, [], ['AboveControls']);
+View::addTo($form, ['ui' => 'divider'], ['AboveControls']);
$formPage = Form\Layout::addTo($tabs->addTab('Basic Info'), ['form' => $form]);
$formPage->addControl('name', new Form\Control\Line());
@@ -142,7 +146,7 @@
return $form->model->get('name') . ' has age ' . $form->model->get('age');
});
-\Atk4\Ui\Header::addTo($app, ['onChange event', 'subHeader' => 'see in browser console']);
+Header::addTo($app, ['onChange event', 'subHeader' => 'see in browser console']);
$form = Form::addTo($app);
@@ -152,10 +156,10 @@
$c3 = $group->addControl('c3', new Form\Control\Calendar(['type' => 'date']));
$c1->onChange('console.log("c1 changed: "+date+","+text+","+mode)');
-$c2->onChange(new \Atk4\Ui\JsExpression('console.log("c2 changed: "+date+","+text+","+mode)'));
+$c2->onChange(new JsExpression('console.log("c2 changed: "+date+","+text+","+mode)'));
$c3->onChange([
- new \Atk4\Ui\JsExpression('console.log("c3 changed: "+date+","+text+","+mode)'),
- new \Atk4\Ui\JsExpression('console.log("c3 really changed: "+date+","+text+","+mode)'),
+ new JsExpression('console.log("c3 changed: "+date+","+text+","+mode)'),
+ new JsExpression('console.log("c3 really changed: "+date+","+text+","+mode)'),
]);
$group = $form->addGroup('Line');
@@ -165,13 +169,13 @@
$f4 = $group->addControl('f4');
$f1->onChange('console.log("f1 changed")');
-$f2->onChange(new \Atk4\Ui\JsExpression('console.log("f2 changed")'));
+$f2->onChange(new JsExpression('console.log("f2 changed")'));
$f3->onChange([
- new \Atk4\Ui\JsExpression('console.log("f3 changed")'),
- new \Atk4\Ui\JsExpression('console.log("f3 really changed")'),
+ new JsExpression('console.log("f3 changed")'),
+ new JsExpression('console.log("f3 really changed")'),
]);
$f4->onChange(function () {
- return new \Atk4\Ui\JsExpression('console.log("f4 changed")');
+ return new JsExpression('console.log("f4 changed")');
});
$group = $form->addGroup('CheckBox');
@@ -200,7 +204,7 @@
]));
$r1->onChange('console.log("radio changed")');
-\Atk4\Ui\Header::addTo($app, ['Line ends of Textarea']);
+Header::addTo($app, ['Line ends of Textarea']);
$form = Form::addTo($app);
$group = $form->addGroup('Without model');
diff --git a/demos/form-control/lookup-dep.php b/demos/form-control/lookup-dep.php
index c19b8fb1df..7e02349cbb 100644
--- a/demos/form-control/lookup-dep.php
+++ b/demos/form-control/lookup-dep.php
@@ -5,14 +5,16 @@
namespace Atk4\Ui\Demos;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\Label;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, ['Lookup dependency']);
+Header::addTo($app, ['Lookup dependency']);
$form = Form::addTo($app, ['class.segment' => true]);
-\Atk4\Ui\Label::addTo($form, ['Input information here', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($form, ['Input information here', 'class.top attached' => true], ['AboveControls']);
$form->addControl('starts_with', [
Form\Control\Dropdown::class,
@@ -50,10 +52,10 @@
return 'Submitted: ' . print_r($form->model->get(), true);
});
-\Atk4\Ui\Header::addTo($app, ['Lookup multiple values']);
+Header::addTo($app, ['Lookup multiple values']);
$form = Form::addTo($app, ['class.segment' => true]);
-\Atk4\Ui\Label::addTo($form, ['Input information here', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($form, ['Input information here', 'class.top attached' => true], ['AboveControls']);
$form->addControl('ends_with', [
Form\Control\Dropdown::class,
diff --git a/demos/form-control/lookup.php b/demos/form-control/lookup.php
index a3719cc78c..95d0a17ca4 100644
--- a/demos/form-control/lookup.php
+++ b/demos/form-control/lookup.php
@@ -4,22 +4,29 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
+use Atk4\Ui\Button;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\Icon;
+use Atk4\Ui\Label;
+use Atk4\Ui\Message;
+use Atk4\Ui\Modal;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
// create header
-\Atk4\Ui\Header::addTo($app, ['Lookup Input']);
+Header::addTo($app, ['Lookup Input']);
Form\Control\Lookup::addTo($app, ['placeholder' => 'Search country', 'label' => 'Country: '])
->setModel(new Country($app->db));
// create form
$form = Form::addTo($app, ['class.segment' => true]);
-\Atk4\Ui\Label::addTo($form, ['Lookup countries', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($form, ['Lookup countries', 'class.top attached' => true], ['AboveControls']);
-$model = new \Atk4\Data\Model($app->db, ['table' => 'test']);
+$model = new Model($app->db, ['table' => 'test']);
// Without Lookup
$model->hasOne('country1', ['model' => [Country::class]]);
@@ -47,41 +54,41 @@
. (new Country($form->getApp()->db))->load($form->model->get('country3'))
->get(Country::hinting()->fieldName()->name);
- $view = new \Atk4\Ui\Message('Select:'); // need in behat test.
+ $view = new Message('Select:'); // need in behat test.
$view->invokeInit();
$view->text->addParagraph($str);
return $view;
});
-\Atk4\Ui\Header::addTo($app, ['Lookup input using label']);
+Header::addTo($app, ['Lookup input using label']);
// from seed
Form\Control\Lookup::addTo($app, ['placeholder' => 'Search country', 'label' => 'Country: '])
->setModel(new Country($app->db));
// through constructor
-Form\Control\Lookup::addTo($app, ['placeholder' => 'Weight', 'labelRight' => new \Atk4\Ui\Label(['kg', 'class.basic' => true])]);
-Form\Control\Lookup::addTo($app, ['label' => '$', 'labelRight' => new \Atk4\Ui\Label(['.00', 'class.basic' => true])]);
+Form\Control\Lookup::addTo($app, ['placeholder' => 'Weight', 'labelRight' => new Label(['kg', 'class.basic' => true])]);
+Form\Control\Lookup::addTo($app, ['label' => '$', 'labelRight' => new Label(['.00', 'class.basic' => true])]);
Form\Control\Lookup::addTo($app, [
'iconLeft' => 'tags',
- 'labelRight' => new \Atk4\Ui\Label(['Add Tag', 'class.tag' => true]),
+ 'labelRight' => new Label(['Add Tag', 'class.tag' => true]),
]);
// left/right corner is not supported, but here is work-around:
-$label = new \Atk4\Ui\Label();
+$label = new Label();
$label->addClass('left corner');
-\Atk4\Ui\Icon::addTo($label, ['asterisk']);
+Icon::addTo($label, ['asterisk']);
Form\Control\Lookup::addTo($app, [
'label' => $label,
])->addClass('left corner');
-\Atk4\Ui\Header::addTo($app, ['Lookup input inside modal']);
+Header::addTo($app, ['Lookup input inside modal']);
-$modal = \Atk4\Ui\Modal::addTo($app)->set(function ($p) {
+$modal = Modal::addTo($app)->set(function ($p) {
$a = Form\Control\Lookup::addTo($p, ['placeholder' => 'Search country', 'label' => 'Country: ']);
$a->setModel(new Country($p->getApp()->db));
});
-\Atk4\Ui\Button::addTo($app, ['Open Lookup on a Modal window'])->on('click', $modal->show());
+Button::addTo($app, ['Open Lookup on a Modal window'])->on('click', $modal->show());
diff --git a/demos/form-control/multiline-containsmany.php b/demos/form-control/multiline-containsmany.php
index 49f65d1d59..eea06581bd 100644
--- a/demos/form-control/multiline-containsmany.php
+++ b/demos/form-control/multiline-containsmany.php
@@ -4,6 +4,7 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Crud;
use Atk4\Ui\Form\Control\Multiline;
/** @var \Atk4\Ui\App $app */
@@ -52,4 +53,4 @@ protected function init(): void
}
}
-\Atk4\Ui\Crud::addTo($app)->setModel(new Client($app->db));
+Crud::addTo($app)->setModel(new Client($app->db));
diff --git a/demos/form-control/multiline.php b/demos/form-control/multiline.php
index 7b87e9a973..f33d127576 100644
--- a/demos/form-control/multiline.php
+++ b/demos/form-control/multiline.php
@@ -11,6 +11,7 @@
use Atk4\Ui\Header;
use Atk4\Ui\JsExpression;
use Atk4\Ui\JsFunction;
+use Atk4\Ui\JsToast;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
@@ -121,5 +122,5 @@ protected function init(): void
$form->onSubmit(function (Form $form) use ($multiline) {
$rows = $multiline->saveRows()->getModel()->export();
- return new \Atk4\Ui\JsToast($form->getApp()->encodeJson(array_values($rows)));
+ return new JsToast($form->getApp()->encodeJson(array_values($rows)));
});
diff --git a/demos/form-control/scope-builder.php b/demos/form-control/scope-builder.php
index a439435403..b49f9958d4 100644
--- a/demos/form-control/scope-builder.php
+++ b/demos/form-control/scope-builder.php
@@ -13,9 +13,9 @@
$model->addCondition($model->fieldName()->finish_time, '=', '22:12:00');
$model->addCondition($model->fieldName()->start_date, '=', '2020-10-22');
-$form = \Atk4\Ui\Form::addTo($app);
+$form = Form::addTo($app);
-$form->addControl('qb', [\Atk4\Ui\Form\Control\ScopeBuilder::class, 'model' => $model, 'options' => ['debug' => true]]);
+$form->addControl('qb', [Form\Control\ScopeBuilder::class, 'model' => $model, 'options' => ['debug' => true]]);
$form->onSubmit(function (Form $form) use ($model) {
return "Scope selected:\n\n" . $form->model->get('qb')->toWords($model);
diff --git a/demos/form-control/tree-item-selector.php b/demos/form-control/tree-item-selector.php
index 9e7b680d7d..2f226cafd9 100644
--- a/demos/form-control/tree-item-selector.php
+++ b/demos/form-control/tree-item-selector.php
@@ -5,7 +5,9 @@
namespace Atk4\Ui\Demos;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
use Atk4\Ui\JsToast;
+use Atk4\Ui\Message;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
@@ -35,14 +37,14 @@
['name' => 'Appliances', 'id' => 301, 'nodes' => []],
];
-\Atk4\Ui\Header::addTo($app, ['Tree item selector']);
+Header::addTo($app, ['Tree item selector']);
$form = Form::addTo($app);
$control = $form->addControl('tree', [Form\Control\TreeItemSelector::class, 'treeItems' => $items, 'caption' => 'Multiple selection:'], ['type' => 'json']);
$control->set([201, 301, 503]);
// $control->onItem(function ($value) use ($app) {
-// return new \Atk4\Ui\JsToast($app->encodeJson($value));
+// return new JsToast($app->encodeJson($value));
// });
$control = $form->addControl('tree1', [Form\Control\TreeItemSelector::class, 'treeItems' => $items, 'allowMultiple' => false, 'caption' => 'Single selection:']);
@@ -58,7 +60,7 @@
'single' => $form->model->get('tree1'),
];
- $view = new \Atk4\Ui\Message('Items: ');
+ $view = new Message('Items: ');
$view->invokeInit();
$view->text->addParagraph($app->encodeJson($response));
diff --git a/demos/form-control/upload.php b/demos/form-control/upload.php
index 143f3b3253..4bef427f1d 100644
--- a/demos/form-control/upload.php
+++ b/demos/form-control/upload.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Demos;
use Atk4\Ui\Form;
+use Atk4\Ui\JsToast;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
@@ -22,7 +23,7 @@
$img->onDelete(function ($fileId) use ($img) {
$img->clearThumbnail('./images/default.png');
- return new \Atk4\Ui\JsToast([
+ return new JsToast([
'title' => 'Delete successfully',
'message' => $fileId . ' has been removed',
'class' => 'success',
@@ -47,7 +48,7 @@
// return $form->error('file', 'Unable to upload file.');
// can also return a notifier.
- return new \Atk4\Ui\JsToast([
+ return new JsToast([
'title' => 'Upload success',
'message' => 'Image is uploaded!',
'class' => 'success',
@@ -55,7 +56,7 @@
});
$control->onDelete(function ($fileId) {
- return new \Atk4\Ui\JsToast([
+ return new JsToast([
'title' => 'Delete successfully',
'message' => $fileId . ' has been removed',
'class' => 'success',
@@ -77,7 +78,7 @@
@unlink($tmpFilePath);
}
- return new \Atk4\Ui\JsToast([
+ return new JsToast([
'title' => 'Upload success',
'message' => 'File is uploaded! (name: ' . $postFile['name'] . ', md5: ' . md5($data) . ')',
'class' => 'success',
diff --git a/demos/form/form-section-accordion.php b/demos/form/form-section-accordion.php
index 02cea88b03..55b9b7dc9a 100644
--- a/demos/form/form-section-accordion.php
+++ b/demos/form/form-section-accordion.php
@@ -4,20 +4,23 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Form Sections', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
+Button::addTo($app, ['Form Sections', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
->link(['form-section']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
$form = Form::addTo($app);
-$sublayout = $form->layout->addSubLayout([\Atk4\Ui\Form\Layout\Section::class]);
+$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class]);
-\Atk4\Ui\Header::addTo($sublayout, ['Please fill all form sections!', 'size' => 4]);
+Header::addTo($sublayout, ['Please fill all form sections!', 'size' => 4]);
$sublayout->addControl('company_name');
diff --git a/demos/form/form-section.php b/demos/form/form-section.php
index 0dee563621..49a53f5033 100644
--- a/demos/form/form-section.php
+++ b/demos/form/form-section.php
@@ -4,14 +4,18 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsToast;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Accordion in Form', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Accordion in Form', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['form-section-accordion']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
$model = new Country($app->db);
$model = $model->loadAny();
@@ -19,7 +23,7 @@
$saveAndDumpValues = function (Form $form) {
$form->model->save();
- return new \Atk4\Ui\JsToast([
+ return new JsToast([
'title' => 'POSTed field values',
'message' => '
' . $form->getApp()->encodeJson($form->model->get()) . ' ',
'class' => 'success',
@@ -34,7 +38,7 @@
$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class]);
-\Atk4\Ui\Header::addTo($sublayout, ['Column Section in Form']);
+Header::addTo($sublayout, ['Column Section in Form']);
$sublayout->setModel($model, [$model->fieldName()->name]);
$colsLayout = $form->layout->addSubLayout([Form\Layout\Section\Columns::class]);
@@ -49,7 +53,7 @@
$form->onSubmit($saveAndDumpValues);
-\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
+View::addTo($app, ['ui' => 'divider']);
// -----------------------------------------------------------------------------
@@ -58,7 +62,7 @@
$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class]);
-\Atk4\Ui\Header::addTo($sublayout, ['Accordion Section in Form']);
+Header::addTo($sublayout, ['Accordion Section in Form']);
$sublayout->setModel($model, [$model->fieldName()->name]);
$accordionLayout = $form->layout->addSubLayout([Form\Layout\Section\Accordion::class]);
@@ -71,7 +75,7 @@
$form->onSubmit($saveAndDumpValues);
-\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
+View::addTo($app, ['ui' => 'divider']);
// -----------------------------------------------------------------------------
@@ -80,7 +84,7 @@
$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class]);
-\Atk4\Ui\Header::addTo($sublayout, ['Tabs in Form']);
+Header::addTo($sublayout, ['Tabs in Form']);
$sublayout->setModel($model, [$model->fieldName()->name]);
$tabsLayout = $form->layout->addSubLayout([Form\Layout\Section\Tabs::class]);
@@ -93,18 +97,18 @@
$form->onSubmit($saveAndDumpValues);
-\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
+View::addTo($app, ['ui' => 'divider']);
// -----------------------------------------------------------------------------
-\Atk4\Ui\Header::addTo($app, ['Color in form']);
+Header::addTo($app, ['Color in form']);
$form = Form::addTo($app);
$form->setModel($model, []);
$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class, 'ui' => 'segment red inverted'], false);
-\Atk4\Ui\Header::addTo($sublayout, ['This section in Red', 'ui' => 'dividing header', 'element' => 'h2']);
+Header::addTo($sublayout, ['This section in Red', 'ui' => 'dividing header', 'element' => 'h2']);
$sublayout->setModel($model, [$model->fieldName()->name]);
$sublayout = $form->layout->addSubLayout([Form\Layout\Section::class, 'ui' => 'segment teal inverted']);
@@ -118,4 +122,4 @@
$form->onSubmit($saveAndDumpValues);
-\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
+View::addTo($app, ['ui' => 'divider']);
diff --git a/demos/form/form.php b/demos/form/form.php
index 87acb27c75..4ca5625a52 100644
--- a/demos/form/form.php
+++ b/demos/form/form.php
@@ -4,8 +4,16 @@
namespace Atk4\Ui\Demos;
+use Atk4\Core\Exception as CoreException;
+use Atk4\Data\Model;
use Atk4\Data\Persistence;
+use Atk4\Ui\Button;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsToast;
+use Atk4\Ui\Message;
+use Atk4\Ui\Modal;
+use Atk4\Ui\Tabs;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
@@ -21,13 +29,13 @@
* This approach will also prevent your application from registering shutdown handler or catching error,
* so we will need to do a bit of work about that too.
*/
-$tabs = \Atk4\Ui\Tabs::addTo($app);
+$tabs = Tabs::addTo($app);
// -----------------------------------------------------------------------------
$tab = $tabs->addTab('Basic Use');
-\Atk4\Ui\Header::addTo($tab, ['Very simple form']);
+Header::addTo($tab, ['Very simple form']);
$form = Form::addTo($tab);
$form->addControl('email');
@@ -40,7 +48,7 @@
$form->buttonSave->set('Subscribe');
$form->buttonSave->icon = 'mail';
-\Atk4\Ui\Header::addTo($tab, ['But very flexible']);
+Header::addTo($tab, ['But very flexible']);
$form = Form::addTo($tab);
$group = $form->addGroup(['width' => 'three']);
@@ -59,10 +67,10 @@
$form->addControl('status_integer_required', [Form\Control\Dropdown::class], ['type' => 'integer', 'values' => $values, 'required' => true]);
$form->onSubmit(function (Form $form) use ($app) {
- return new \Atk4\Ui\JsToast($app->encodeJson($form->model->get()));
+ return new JsToast($app->encodeJson($form->model->get()));
});
-\Atk4\Ui\Header::addTo($tab, ['Comparing Field type vs Form control class']);
+Header::addTo($tab, ['Comparing Field type vs Form control class']);
$form = Form::addTo($tab);
$form->addControl('field', [], ['type' => 'date', 'caption' => 'Date using model field:']);
$form->addControl('control', [Form\Control\Calendar::class, 'type' => 'date', 'caption' => 'Date using form control: ']);
@@ -70,7 +78,7 @@
$form->onSubmit(function (Form $form) {
$message = 'field = ' . print_r($form->model->get('field'), true) . ';
control = ' . print_r($form->model->get('control'), true);
- $view = new \Atk4\Ui\Message('Date field vs control:');
+ $view = new Message('Date field vs control:');
$view->invokeInit();
$view->text->addHtml($message);
@@ -81,7 +89,7 @@
$tab = $tabs->addTab('Handler Output');
-\Atk4\Ui\Header::addTo($tab, ['Form can respond with manually generated error']);
+Header::addTo($tab, ['Form can respond with manually generated error']);
$form = Form::addTo($tab);
$form->addControl('email1');
$form->buttonSave->set('Save1');
@@ -89,7 +97,7 @@
return $form->error('email1', 'some error action ' . random_int(1, 100));
});
-\Atk4\Ui\Header::addTo($tab, ['..or success message']);
+Header::addTo($tab, ['..or success message']);
$form = Form::addTo($tab);
$form->addControl('email2');
$form->buttonSave->set('Save2');
@@ -97,34 +105,34 @@
return $form->success('form was successful');
});
-\Atk4\Ui\Header::addTo($tab, ['Any other view can be output']);
+Header::addTo($tab, ['Any other view can be output']);
$form = Form::addTo($tab);
$form->addControl('email3');
$form->buttonSave->set('Save3');
$form->onSubmit(function (Form $form) {
- $view = new \Atk4\Ui\Message('some header');
+ $view = new Message('some header');
$view->invokeInit();
$view->text->addParagraph('some text ' . random_int(1, 100));
return $view;
});
-\Atk4\Ui\Header::addTo($tab, ['Modal can be output directly']);
+Header::addTo($tab, ['Modal can be output directly']);
$form = Form::addTo($tab);
$form->addControl('email4');
$form->buttonSave->set('Save4');
$form->onSubmit(function (Form $form) {
- $view = new \Atk4\Ui\Message('some header');
+ $view = new Message('some header');
$view->invokeInit();
$view->text->addParagraph('some text ' . random_int(1, 100));
- $modal = new \Atk4\Ui\Modal(['title' => 'Something happen', 'ui' => 'ui modal tiny']);
+ $modal = new Modal(['title' => 'Something happen', 'ui' => 'ui modal tiny']);
$modal->add($view);
return $modal;
});
-\Atk4\Ui\Header::addTo($tab, ['jsAction can be used too']);
+Header::addTo($tab, ['jsAction can be used too']);
$form = Form::addTo($tab);
$control = $form->addControl('email5');
$form->buttonSave->set('Save5');
@@ -136,7 +144,7 @@
$tab = $tabs->addTab('Handler Safety');
-\Atk4\Ui\Header::addTo($tab, ['Form handles errors', 'size' => 2]);
+Header::addTo($tab, ['Form handles errors', 'size' => 2]);
$form = Form::addTo($tab);
$form->addControl('email');
@@ -146,23 +154,23 @@
return $o['abc'];
});
-\Atk4\Ui\Header::addTo($tab, ['Form shows Agile exceptions', 'size' => 2]);
+Header::addTo($tab, ['Form shows Agile exceptions', 'size' => 2]);
$form = Form::addTo($tab);
$form->addControl('email');
$form->onSubmit(function (Form $form) {
- throw (new \Atk4\Core\Exception('testing'))
+ throw (new CoreException('testing'))
->addMoreInfo('arg1', 'val1');
// return 'somehow it did not crash';
});
-\Atk4\Ui\Button::addTo($form, ['Modal Test', 'class.secondary' => true])->on('click', \Atk4\Ui\Modal::addTo($form)
+Button::addTo($form, ['Modal Test', 'class.secondary' => true])->on('click', Modal::addTo($form)
->set(function ($p) {
$form = Form::addTo($p);
$form->addControl('email');
$form->onSubmit(function (Form $form) {
- throw (new \Atk4\Core\Exception('testing'))
+ throw (new CoreException('testing'))
->addMoreInfo('arg1', 'val1');
// return 'somehow it did not crash';
@@ -173,9 +181,9 @@
$tab = $tabs->addTab('Complex Examples');
-\Atk4\Ui\Header::addTo($tab, ['Conditional response']);
+Header::addTo($tab, ['Conditional response']);
-$modelRegister = new \Atk4\Data\Model(new Persistence\Array_());
+$modelRegister = new Model(new Persistence\Array_());
$modelRegister->addField('name');
$modelRegister->addField('email');
$modelRegister->addField('is_accept_terms', ['type' => 'boolean', 'nullable' => false]);
@@ -199,10 +207,10 @@
$tab = $tabs->addTab('Layout Control');
-\Atk4\Ui\Header::addTo($tab, ['Shows example of grouping and multiple errors']);
+Header::addTo($tab, ['Shows example of grouping and multiple errors']);
$form = Form::addTo($tab, ['class.segment' => true]);
-$form->setModel((new \Atk4\Data\Model())->createEntity());
+$form->setModel((new Model())->createEntity());
$form->addHeader('Example fields added one-by-one');
$form->addControl('name');
diff --git a/demos/form/form2.php b/demos/form/form2.php
index 07cb1a27fa..5ebcbd1684 100644
--- a/demos/form/form2.php
+++ b/demos/form/form2.php
@@ -4,23 +4,25 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
+use Atk4\Ui\Button;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
use Atk4\Ui\JsToast;
+use Atk4\Ui\Label;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-// Testing form.
-
// create header
-\Atk4\Ui\Header::addTo($app, ['Database-driven form with an enjoyable layout']);
+Header::addTo($app, ['Database-driven form with an enjoyable layout']);
// create form
$form = Form::addTo($app, ['class.segment' => true]);
// $form = Form::addTo($app, ['class.segment' => true, 'buttonSave' => false]);
-// $form = Form::addTo($app, ['class.segment' => true, 'buttonSave' => new \Atk4\Ui\Button(['Import', 'class.secondary' => true, 'iconRight' => 'list'])]);
+// $form = Form::addTo($app, ['class.segment' => true, 'buttonSave' => new Button(['Import', 'class.secondary' => true, 'iconRight' => 'list'])]);
// $form = Form::addTo($app, ['class.segment' => true, 'buttonSave' => [null, 'Import', 'class.secondary' => true, 'iconRight' => 'list']]);
-\Atk4\Ui\Label::addTo($form, ['Input new country information here', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($form, ['Input new country information here', 'class.top attached' => true], ['AboveControls']);
$form->setModel((new Country($app->db))->createEntity(), []);
@@ -79,10 +81,8 @@
return new JsToast($countryEntity->getUserAction('add')->execute());
});
-// ======
-
-/** @var \Atk4\Data\Model $personClass */
-$personClass = AnonymousClassNameCache::get_class(fn () => new class() extends \Atk4\Data\Model {
+/** @var Model $personClass */
+$personClass = AnonymousClassNameCache::get_class(fn () => new class() extends Model {
public $table = 'person';
protected function init(): void
@@ -96,9 +96,9 @@ protected function init(): void
$this->hasOne('country_dropdown_id', ['model' => [Country::class], 'ui' => ['form' => new Form\Control\Dropdown()]]); // this works slow
}
- public function validate($intent = null): array
+ public function validate(string $intent = null): array
{
- $errors = parent::validate();
+ $errors = parent::validate($intent);
if ($this->get('name') === $this->get('surname')) {
$errors['surname'] = 'Your surname cannot be same as the name';
diff --git a/demos/form/form3.php b/demos/form/form3.php
index f912847786..3bbc8c2dc9 100644
--- a/demos/form/form3.php
+++ b/demos/form/form3.php
@@ -5,25 +5,26 @@
namespace Atk4\Ui\Demos;
use Atk4\Data\Model;
+use Atk4\Ui\Button;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
use Atk4\Ui\JsReload;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-// Testing form.
+Header::addTo($app, ['Form automatically decided how many columns to use']);
-\Atk4\Ui\Header::addTo($app, ['Form automatically decided how many columns to use']);
+$buttons = View::addTo($app, ['ui' => 'green basic buttons']);
-$buttons = \Atk4\Ui\View::addTo($app, ['ui' => 'green basic buttons']);
+$seg = View::addTo($app, ['ui' => 'raised segment']);
-$seg = \Atk4\Ui\View::addTo($app, ['ui' => 'raised segment']);
-
-\Atk4\Ui\Button::addTo($buttons, ['Use Country Model', 'icon' => 'arrow down'])
+Button::addTo($buttons, ['Use Country Model', 'icon' => 'arrow down'])
->on('click', new JsReload($seg, ['m' => 'country']));
-\Atk4\Ui\Button::addTo($buttons, ['Use File Model', 'icon' => 'arrow down'])
+Button::addTo($buttons, ['Use File Model', 'icon' => 'arrow down'])
->on('click', new JsReload($seg, ['m' => 'file']));
-\Atk4\Ui\Button::addTo($buttons, ['Use Stat Model', 'icon' => 'arrow down'])
+Button::addTo($buttons, ['Use Stat Model', 'icon' => 'arrow down'])
->on('click', new JsReload($seg, ['m' => 'stat']));
$form = Form::addTo($seg, ['layout' => [Form\Layout\Columns::class]]);
diff --git a/demos/form/form5.php b/demos/form/form5.php
index e027456748..336c5ac44e 100644
--- a/demos/form/form5.php
+++ b/demos/form/form5.php
@@ -4,14 +4,17 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
use Atk4\Data\Persistence;
+use Atk4\Ui\Columns;
use Atk4\Ui\Form;
use Atk4\Ui\JsToast;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\View::addTo($app, [
+View::addTo($app, [
'Forms below focus on Data integration and automated layouts',
'ui' => 'ignored warning message',
]);
@@ -20,7 +23,7 @@
return new JsToast($app->encodeJson($f->model->get()));
};
-$cc = \Atk4\Ui\Columns::addTo($app);
+$cc = Columns::addTo($app);
$form = Form::addTo($cc->addColumn());
// adding field without model creates a regular line
@@ -40,7 +43,7 @@
$form->onSubmit($formSubmit);
-$model = new \Atk4\Data\Model(new Persistence\Array_());
+$model = new Model(new Persistence\Array_());
// model field uses regular line form control by default
$model->addField('one');
diff --git a/demos/form/html-layout.php b/demos/form/html-layout.php
index 92394c0eed..e78dfc4eba 100644
--- a/demos/form/html-layout.php
+++ b/demos/form/html-layout.php
@@ -8,6 +8,8 @@
use Atk4\Ui\Form;
use Atk4\Ui\GridLayout;
use Atk4\Ui\Header;
+use Atk4\Ui\JsToast;
+use Atk4\Ui\Label;
use Atk4\Ui\Tabs;
use Atk4\Ui\View;
@@ -45,7 +47,7 @@
Form\Layout::class,
[
'defaultInputTemplate' => __DIR__ . '/templates/input.html',
- 'defaultHint' => [\Atk4\Ui\Label::class, 'class' => ['pointing', 'below']],
+ 'defaultHint' => [Label::class, 'class' => ['pointing', 'below']],
],
],
]);
@@ -60,5 +62,5 @@
$form->setModel((new Country($app->db))->loadAny());
$form->onSubmit(function (Form $form) {
- return new \Atk4\Ui\JsToast('Saving is disabled');
+ return new JsToast('Saving is disabled');
});
diff --git a/demos/form/jscondform.php b/demos/form/jscondform.php
index 11c79346bf..1d577c3b20 100644
--- a/demos/form/jscondform.php
+++ b/demos/form/jscondform.php
@@ -5,16 +5,18 @@
namespace Atk4\Ui\Demos;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\Label;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
// -----------------------------------------------------------------------------
-\Atk4\Ui\Header::addTo($app, ['Phone', 'size' => 2]);
+Header::addTo($app, ['Phone', 'size' => 2]);
$formPhone = Form::addTo($app, ['class.segment' => true]);
-\Atk4\Ui\Label::addTo($formPhone, ['Add other phone field input. Note: phone1 required a number of at least 5 char.', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($formPhone, ['Add other phone field input. Note: phone1 required a number of at least 5 char.', 'class.top attached' => true], ['AboveControls']);
$formPhone->addControl('phone1');
$formPhone->addControl('phone2');
@@ -30,10 +32,10 @@
// -----------------------------------------------------------------------------
-\Atk4\Ui\Header::addTo($app, ['Optional subscription', 'size' => 2]);
+Header::addTo($app, ['Optional subscription', 'size' => 2]);
$formSubscribe = Form::addTo($app, ['class.segment' => true]);
-\Atk4\Ui\Label::addTo($formSubscribe, ['Click on subscribe and add email to receive your gift.', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($formSubscribe, ['Click on subscribe and add email to receive your gift.', 'class.top attached' => true], ['AboveControls']);
$formSubscribe->addControl('name');
$formSubscribe->addControl('subscribe', [Form\Control\Checkbox::class, 'Subscribe to weekly newsletter', 'class.toggle' => true]);
@@ -54,10 +56,10 @@
// -----------------------------------------------------------------------------
-\Atk4\Ui\Header::addTo($app, ['Dog registration', 'size' => 2]);
+Header::addTo($app, ['Dog registration', 'size' => 2]);
$formDog = Form::addTo($app, ['class.segment' => true]);
-\Atk4\Ui\Label::addTo($formDog, ['You can select type of hair cut only with race that contains "poodle" AND age no more than 5 year OR your dog race equals "bichon".', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($formDog, ['You can select type of hair cut only with race that contains "poodle" AND age no more than 5 year OR your dog race equals "bichon".', 'class.top attached' => true], ['AboveControls']);
$formDog->addControl('race', [Form\Control\Line::class]);
$formDog->addControl('age');
$formDog->addControl('hair_cut', [Form\Control\Dropdown::class, 'values' => ['Short', 'Long']]);
@@ -71,10 +73,10 @@
// -----------------------------------------------------------------------------
-\Atk4\Ui\Header::addTo($app, ['Hide or show group', 'size' => 2]);
+Header::addTo($app, ['Hide or show group', 'size' => 2]);
$formGroup = Form::addTo($app, ['class.segment' => true]);
-\Atk4\Ui\Label::addTo($formGroup, ['Work on form group too.', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($formGroup, ['Work on form group too.', 'class.top attached' => true], ['AboveControls']);
$groupBasic = $formGroup->addGroup(['Basic Information']);
$groupBasic->addControl('first_name', ['width' => 'eight']);
@@ -101,10 +103,10 @@
// -----------------------------------------------------------------------------
/*
-\Atk4\Ui\Header::addTo($app, ['Hide or show accordion section', 'size' => 2]);
+Header::addTo($app, ['Hide or show accordion section', 'size' => 2]);
$f_acc = Form::addTo($app, ['class.segment' => true]);
-\Atk4\Ui\Label::addTo($f_acc, ['Work on section layouts too.', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($f_acc, ['Work on section layouts too.', 'class.top attached' => true], ['AboveControls']);
// Accordion
$accordion_layout = $f_acc->layout->addSubLayout([Form\Layout\Section\Accordion::class, 'type' => ['styled', 'fluid'], 'settings' => ['exclusive' => false]]);
diff --git a/demos/index.php b/demos/index.php
index 0f6976c4a2..78ef12bb38 100644
--- a/demos/index.php
+++ b/demos/index.php
@@ -4,21 +4,26 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
+use Atk4\Ui\Text;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/init-app.php';
-\Atk4\Ui\Header::addTo($app)->set('Welcome to Agile Toolkit Demo!!');
+Header::addTo($app)->set('Welcome to Agile Toolkit Demo!!');
-$t = \Atk4\Ui\Text::addTo(\Atk4\Ui\View::addTo($app, [false, 'class.green' => true, 'ui' => 'segment']));
+$t = Text::addTo(View::addTo($app, [false, 'class.green' => true, 'ui' => 'segment']));
$t->addParagraph('Take a quick stroll through some of the amazing features of Agile Toolkit.');
-\Atk4\Ui\Button::addTo($app, ['Begin the demo..', 'class.huge primary fluid' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Begin the demo..', 'class.huge primary fluid' => true, 'iconRight' => 'right arrow'])
->link('tutorial/intro.php');
-\Atk4\Ui\Header::addTo($app)->set('What is new in Agile Toolkit 2.0');
+Header::addTo($app)->set('What is new in Agile Toolkit 2.0');
-$t = \Atk4\Ui\Text::addTo(\Atk4\Ui\View::addTo($app, [false, 'class.green' => true, 'ui' => 'segment']));
+$t = Text::addTo(View::addTo($app, [false, 'class.green' => true, 'ui' => 'segment']));
$t->addParagraph('In this version of Agile Toolkit we introduce "User Actions"!');
-\Atk4\Ui\Button::addTo($app, ['Learn about User Actions', 'class.huge basic primary fluid' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Learn about User Actions', 'class.huge basic primary fluid' => true, 'iconRight' => 'right arrow'])
->link('tutorial/actions.php');
diff --git a/demos/init-app.php b/demos/init-app.php
index 02ef3b0640..32c07b9f0f 100644
--- a/demos/init-app.php
+++ b/demos/init-app.php
@@ -5,6 +5,9 @@
namespace Atk4\Ui\Demos;
use Atk4\Data\Persistence;
+use Atk4\Ui\Button;
+use Atk4\Ui\Exception;
+use Atk4\Ui\Layout;
date_default_timezone_set('UTC');
@@ -66,17 +69,17 @@ public static function get_class(\Closure $createAnonymousClassFx): string
$app->db = $db;
unset($db);
} catch (\Throwable $e) {
- throw new \Atk4\Ui\Exception('Database error: ' . $e->getMessage());
+ throw new Exception('Database error: ' . $e->getMessage());
}
[$rootUrl, $relUrl] = preg_split('~(?<=/)(?=demos(/|\?|$))|\?~s', $_SERVER['REQUEST_URI'], 3);
$demosUrl = $rootUrl . 'demos/';
// allow custom layout override
-$app->initLayout([!isset($_GET['layout']) ? \Atk4\Ui\Layout\Maestro::class : $app->stickyGet('layout')]);
+$app->initLayout([!isset($_GET['layout']) ? Layout\Maestro::class : $app->stickyGet('layout')]);
$layout = $app->layout;
-if ($layout instanceof \Atk4\Ui\Layout\NavigableInterface) {
+if ($layout instanceof Layout\NavigableInterface) {
$layout->addMenuItem(['Welcome to Agile Toolkit', 'icon' => 'gift'], [$demosUrl . 'index']);
$path = $demosUrl . 'layout/';
@@ -177,7 +180,7 @@ public static function get_class(\Closure $createAnonymousClassFx): string
$layout->addMenuItem('Recursive Views', [$path . 'recursive'], $menu);
// view demo source page on Github
- \Atk4\Ui\Button::addTo($layout->menu->addItem()->addClass('aligned right'), ['View Source', 'class.teal' => true, 'icon' => 'github'])
+ Button::addTo($layout->menu->addItem()->addClass('aligned right'), ['View Source', 'class.teal' => true, 'icon' => 'github'])
->on('click', $app->jsRedirect('https://github.com/atk4/ui/blob/develop/' . $relUrl, true));
}
unset($layout, $rootUrl, $relUrl, $demosUrl, $path, $menu);
diff --git a/demos/init-db.php b/demos/init-db.php
index aae278364f..7c94ce20b5 100644
--- a/demos/init-db.php
+++ b/demos/init-db.php
@@ -4,7 +4,10 @@
namespace Atk4\Ui\Demos;
+use Atk4\Core\Factory;
+use Atk4\Data\Field;
use Atk4\Data\Model;
+use Atk4\Ui\Exception;
use Atk4\Ui\Form;
use Mvorisek\Atk4\Hintable\Data\HintablePropertyDef;
@@ -14,7 +17,7 @@
: __DIR__ . '/db.default.php';
} catch (\PDOException $e) {
// do not show $e unless you can secure DSN!
- throw (new \Atk4\Ui\Exception('This demo requires access to the database. See "demos/init-db.php"'))
+ throw (new Exception('This demo requires access to the database. See "demos/init-db.php"'))
->addMoreInfo('PDO error', $e->getMessage());
}
@@ -133,9 +136,9 @@ protected function init(): void
$this->initPreventModification();
}
- public function addField($name, $seed = []): \Atk4\Data\Field
+ public function addField(string $name, $seed = []): Field
{
- $seed = \Atk4\Core\Factory::mergeSeeds($seed, [
+ $seed = Factory::mergeSeeds($seed, [
'actual' => $this->prefixFieldName($name, true),
'caption' => $this->readableCaption($this->unprefixFieldName($name)),
]);
@@ -176,7 +179,7 @@ protected function init(): void
});
}
- public function validate($intent = null): array
+ public function validate(string $intent = null): array
{
$errors = parent::validate($intent);
@@ -287,7 +290,7 @@ protected function init(): void
}
}
-class Percent extends \Atk4\Data\Field
+class Percent extends Field
{
public ?string $type = 'float';
}
diff --git a/demos/interactive/accordion-nested.php b/demos/interactive/accordion-nested.php
index f5f454ab77..50e44ee539 100644
--- a/demos/interactive/accordion-nested.php
+++ b/demos/interactive/accordion-nested.php
@@ -4,32 +4,40 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Accordion;
+use Atk4\Ui\Button;
+use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\LoremIpsum;
+use Atk4\Ui\Message;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
/*
-\Atk4\Ui\Button::addTo($app, ['View Form input split in Accordion section', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['View Form input split in Accordion section', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['accordion-in-form']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'clearing divider']);
+View::addTo($app, ['ui' => 'clearing divider']);
*/
-\Atk4\Ui\Header::addTo($app, ['Nested accordions']);
+Header::addTo($app, ['Nested accordions']);
$addAccordionFunc = function ($view, $maxDepth = 2, $level = 0) use (&$addAccordionFunc) {
- $accordion = \Atk4\Ui\Accordion::addTo($view, ['type' => ['styled', 'fluid']]);
+ $accordion = Accordion::addTo($view, ['type' => ['styled', 'fluid']]);
// static section
$i1 = $accordion->addSection('Static Text');
- \Atk4\Ui\Message::addTo($i1, ['This content is added on page loaded', 'ui' => 'tiny message']);
- \Atk4\Ui\LoremIpsum::addTo($i1, ['size' => 1]);
+ Message::addTo($i1, ['This content is added on page loaded', 'ui' => 'tiny message']);
+ LoremIpsum::addTo($i1, ['size' => 1]);
if ($level < $maxDepth) {
$addAccordionFunc($i1, $maxDepth, $level + 1);
}
// dynamic section - simple view
$i2 = $accordion->addSection('Dynamic Text', function ($v) use ($addAccordionFunc, $maxDepth, $level) {
- \Atk4\Ui\Message::addTo($v, ['Every time you open this accordion item, you will see a different text', 'ui' => 'tiny message']);
- \Atk4\Ui\LoremIpsum::addTo($v, ['size' => 2]);
+ Message::addTo($v, ['Every time you open this accordion item, you will see a different text', 'ui' => 'tiny message']);
+ LoremIpsum::addTo($v, ['size' => 2]);
if ($level < $maxDepth) {
$addAccordionFunc($v, $maxDepth, $level + 1);
}
@@ -37,10 +45,10 @@
// dynamic section - form view
$i3 = $accordion->addSection('Dynamic Form', function ($v) use ($addAccordionFunc, $maxDepth, $level) {
- \Atk4\Ui\Message::addTo($v, ['Loading a form dynamically.', 'ui' => 'tiny message']);
- $form = \Atk4\Ui\Form::addTo($v);
+ Message::addTo($v, ['Loading a form dynamically.', 'ui' => 'tiny message']);
+ $form = Form::addTo($v);
$form->addControl('Email');
- $form->onSubmit(function (\Atk4\Ui\Form $form) {
+ $form->onSubmit(function (Form $form) {
return $form->success('Subscribed ' . $form->model->get('Email') . ' to newsletter.');
});
diff --git a/demos/interactive/accordion.php b/demos/interactive/accordion.php
index 846d795f6c..152cf255f9 100644
--- a/demos/interactive/accordion.php
+++ b/demos/interactive/accordion.php
@@ -4,41 +4,47 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Accordion;
+use Atk4\Ui\Button;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\LoremIpsum;
+use Atk4\Ui\Message;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Nested accordions', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Nested accordions', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['accordion-nested']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'clearing divider']);
+View::addTo($app, ['ui' => 'clearing divider']);
-\Atk4\Ui\Header::addTo($app, ['Accordion\'s section can be control programmatically.']);
+Header::addTo($app, ['Accordion\'s section can be control programmatically.']);
// toggle menu
-$bar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
-$b1 = \Atk4\Ui\Button::addTo($bar, ['Toggle Section #1']);
-$b2 = \Atk4\Ui\Button::addTo($bar, ['Toggle Section #2']);
-$b3 = \Atk4\Ui\Button::addTo($bar, ['Toggle Section #3']);
+$bar = View::addTo($app, ['ui' => 'buttons']);
+$b1 = Button::addTo($bar, ['Toggle Section #1']);
+$b2 = Button::addTo($bar, ['Toggle Section #2']);
+$b3 = Button::addTo($bar, ['Toggle Section #3']);
-\Atk4\Ui\Header::addTo($app, ['Accordion Sections']);
+Header::addTo($app, ['Accordion Sections']);
-$accordion = \Atk4\Ui\Accordion::addTo($app, ['type' => ['styled', 'fluid']/* , 'settings' => ['exclusive' => false] */]);
+$accordion = Accordion::addTo($app, ['type' => ['styled', 'fluid']/* , 'settings' => ['exclusive' => false] */]);
// static section
$i1 = $accordion->addSection('Static Text');
-\Atk4\Ui\Message::addTo($i1, ['This content is added on page loaded', 'ui' => 'tiny message']);
-\Atk4\Ui\LoremIpsum::addTo($i1, ['size' => 1]);
+Message::addTo($i1, ['This content is added on page loaded', 'ui' => 'tiny message']);
+LoremIpsum::addTo($i1, ['size' => 1]);
// dynamic section - simple view
$i2 = $accordion->addSection('Dynamic Text', function ($v) {
- \Atk4\Ui\Message::addTo($v, ['Every time you open this accordion item, you will see a different text', 'ui' => 'tiny message']);
- \Atk4\Ui\LoremIpsum::addTo($v, ['size' => 2]);
+ Message::addTo($v, ['Every time you open this accordion item, you will see a different text', 'ui' => 'tiny message']);
+ LoremIpsum::addTo($v, ['size' => 2]);
});
// dynamic section - form view
$i3 = $accordion->addSection('Dynamic Form', function ($v) {
- \Atk4\Ui\Message::addTo($v, ['Loading a form dynamically.', 'ui' => 'tiny message']);
+ Message::addTo($v, ['Loading a form dynamically.', 'ui' => 'tiny message']);
$form = Form::addTo($v);
$form->addControl('Email');
$form->onSubmit(function (Form $form) {
diff --git a/demos/interactive/card-action.php b/demos/interactive/card-action.php
index 754e02a666..8dcd6e29c4 100644
--- a/demos/interactive/card-action.php
+++ b/demos/interactive/card-action.php
@@ -6,20 +6,23 @@
use Atk4\Data\Model;
use Atk4\Ui\Button;
+use Atk4\Ui\Card;
+use Atk4\Ui\Header;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Card', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
+Button::addTo($app, ['Card', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
->link(['card']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-\Atk4\Ui\Header::addTo($app, ['Models', 'size' => 1, 'subHeader' => 'Card may display information from many models.']);
+Header::addTo($app, ['Models', 'size' => 1, 'subHeader' => 'Card may display information from many models.']);
$stat = new Stat($app->db);
$stat = $stat->loadAny();
-$c = \Atk4\Ui\Card::addTo($app);
+$c = Card::addTo($app);
$c->setModel($stat, [$stat->fieldName()->client_name, $stat->fieldName()->description]);
$c->addSection('Project: ', $stat, [$stat->fieldName()->start_date, $stat->fieldName()->finish_date], true);
diff --git a/demos/interactive/card.php b/demos/interactive/card.php
index ce7098184d..2242316a2c 100644
--- a/demos/interactive/card.php
+++ b/demos/interactive/card.php
@@ -4,68 +4,74 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Card;
+use Atk4\Ui\Header;
+use Atk4\Ui\Image;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Card Model', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Card Model', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['card-action']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-\Atk4\Ui\Header::addTo($app, ['Card.', 'size' => 1, 'subHeader' => 'Component based on Fomantic-Ui Card view.']);
+Header::addTo($app, ['Card.', 'size' => 1, 'subHeader' => 'Component based on Fomantic-Ui Card view.']);
// Simple Card
-\Atk4\Ui\Header::addTo($app, ['Card can be defined manually.', 'size' => 3]);
+Header::addTo($app, ['Card can be defined manually.', 'size' => 3]);
-$card = \Atk4\Ui\Card::addTo($app);
+$card = Card::addTo($app);
-$card->addContent(new \Atk4\Ui\Header(['Meet Kristy', 'subHeader' => 'Friends']));
+$card->addContent(new Header(['Meet Kristy', 'subHeader' => 'Friends']));
$card->addDescription('Kristy is a friend of Mully.');
$card->addImage('../images/kristy.png');
-$card->addButton(new \Atk4\Ui\Button(['Join']));
-$card->addButton(new \Atk4\Ui\Button(['Email']));
+$card->addButton(new Button(['Join']));
+$card->addButton(new Button(['Email']));
-$card->addExtraContent(new \Atk4\Ui\View(['Copyright notice: Image from Semantic-UI (Fomantic-UI)', 'element' => 'span']));
+$card->addExtraContent(new View(['Copyright notice: Image from Semantic-UI (Fomantic-UI)', 'element' => 'span']));
// Simple Card
-$card = \Atk4\Ui\Card::addTo($app);
-$content = new \Atk4\Ui\View(['class' => ['content']]);
-$img = \Atk4\Ui\Image::addTo($content, ['../images/kristy.png']);
+$card = Card::addTo($app);
+$content = new View(['class' => ['content']]);
+$img = Image::addTo($content, ['../images/kristy.png']);
$img->addClass('right floated mini ui image');
-$header = \Atk4\Ui\Header::addTo($content, ['Kristy']);
+$header = Header::addTo($content, ['Kristy']);
$card->addContent($content);
$card->addDescription('Friend of Bob');
// Card with Table and Label
-\Atk4\Ui\Header::addTo($app, ['Card can display model label in a table or in line.', 'size' => 3]);
+Header::addTo($app, ['Card can display model label in a table or in line.', 'size' => 3]);
-$deck = \Atk4\Ui\View::addTo($app, ['ui' => 'cards']);
+$deck = View::addTo($app, ['ui' => 'cards']);
-$cardStat = \Atk4\Ui\Card::addTo($deck, ['useTable' => true]);
-$cardStat->addContent(new \Atk4\Ui\Header(['Project Info']));
+$cardStat = Card::addTo($deck, ['useTable' => true]);
+$cardStat->addContent(new Header(['Project Info']));
$stat = (new Stat($app->db))->loadAny();
$cardStat->setModel($stat, [$stat->fieldName()->project_name, $stat->fieldName()->project_code, $stat->fieldName()->client_name, $stat->fieldName()->start_date]);
-$btn = $cardStat->addButton(new \Atk4\Ui\Button(['Email Client']));
+$btn = $cardStat->addButton(new Button(['Email Client']));
-$cardStat = \Atk4\Ui\Card::addTo($deck, ['useLabel' => true]);
-$cardStat->addContent(new \Atk4\Ui\Header(['Project Info']));
+$cardStat = Card::addTo($deck, ['useLabel' => true]);
+$cardStat->addContent(new Header(['Project Info']));
$stat = (new Stat($app->db))->loadAny();
$cardStat->setModel($stat, [$stat->fieldName()->project_name, $stat->fieldName()->project_code, $stat->fieldName()->client_name, $stat->fieldName()->start_date]);
-$cardStat->addButton(new \Atk4\Ui\Button(['Email Client']));
+$cardStat->addButton(new Button(['Email Client']));
// Card display horizontally
-\Atk4\Ui\Header::addTo($app, ['Card can be display horizontally and/or centered.', 'size' => 3]);
+Header::addTo($app, ['Card can be display horizontally and/or centered.', 'size' => 3]);
-$card = \Atk4\Ui\Card::addTo($app)->addClass('horizontal centered');
+$card = Card::addTo($app)->addClass('horizontal centered');
-$card->addContent(new \Atk4\Ui\Header(['Meet Kristy', 'subHeader' => 'Friends']));
+$card->addContent(new Header(['Meet Kristy', 'subHeader' => 'Friends']));
$card->addDescription('Kristy is a friend of Mully.');
$card->addImage('../images/kristy.png');
diff --git a/demos/interactive/cardtable.php b/demos/interactive/cardtable.php
index 452e00970c..e3c61519ae 100644
--- a/demos/interactive/cardtable.php
+++ b/demos/interactive/cardtable.php
@@ -4,9 +4,12 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\CardTable;
+use Atk4\Ui\Header;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, ['Card displays read-only data of a single record']);
+Header::addTo($app, ['Card displays read-only data of a single record']);
-\Atk4\Ui\CardTable::addTo($app)->setModel((new Stat($app->db))->loadAny());
+CardTable::addTo($app)->setModel((new Stat($app->db))->loadAny());
diff --git a/demos/interactive/console.php b/demos/interactive/console.php
index 371fd5da50..3ed418daf8 100644
--- a/demos/interactive/console.php
+++ b/demos/interactive/console.php
@@ -4,12 +4,22 @@
namespace Atk4\Ui\Demos;
+use Atk4\Core\DebugTrait;
+use Atk4\Core\Exception as CoreException;
+use Atk4\Ui\Button;
+use Atk4\Ui\Console;
+use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\Message;
+use Atk4\Ui\Tabs;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-/** @var \Atk4\Ui\View $testRunClass */
-$testRunClass = AnonymousClassNameCache::get_class(fn () => new class() extends \Atk4\Ui\View {
- use \Atk4\Core\DebugTrait;
+/** @var View $testRunClass */
+$testRunClass = AnonymousClassNameCache::get_class(fn () => new class() extends View {
+ use DebugTrait;
public function generateReport()
{
@@ -27,53 +37,53 @@ public function generateReport()
}
});
-$tabs = \Atk4\Ui\Tabs::addTo($app);
+$tabs = Tabs::addTo($app);
$tab = $tabs->addTab('set()');
-\Atk4\Ui\Header::addTo($tab, [
+Header::addTo($tab, [
'icon' => 'terminal',
'Console output streaming',
'subHeader' => 'any output your PHP script produces through console is displayed to user in real-time',
]);
-\Atk4\Ui\Console::addTo($tab)->set(function ($console) {
+Console::addTo($tab)->set(function ($console) {
$console->output('Executing test process...');
sleep(1);
$console->output('Now trying something dangerous..');
sleep(1);
echo 'direct output is captured';
- throw new \Atk4\Core\Exception('BOOM - exceptions are caught');
+ throw new CoreException('BOOM - exceptions are caught');
});
$tab = $tabs->addTab('runMethod()', function ($tab) use ($testRunClass) {
- \Atk4\Ui\Header::addTo($tab, [
+ Header::addTo($tab, [
'icon' => 'terminal',
'Non-interractive method invocation',
'subHeader' => 'console can invoke a method, which normaly would be non-interractive and can still capture debug output',
]);
- \Atk4\Ui\Console::addTo($tab)->runMethod($testRunClass::addTo($tab), 'generateReport');
+ Console::addTo($tab)->runMethod($testRunClass::addTo($tab), 'generateReport');
});
$tab = $tabs->addTab('exec() single', function ($tab) {
- \Atk4\Ui\Header::addTo($tab, [
+ Header::addTo($tab, [
'icon' => 'terminal',
'Command execution',
'subHeader' => 'it is easy to run server-side commands and stream output through console',
]);
- $message = \Atk4\Ui\Message::addTo($tab, ['This demo may not work', 'type' => 'warning']);
+ $message = Message::addTo($tab, ['This demo may not work', 'type' => 'warning']);
$message->text->addParagraph('This demo requires Linux OS and will display error otherwise.');
- \Atk4\Ui\Console::addTo($tab)->exec('/bin/pwd');
+ Console::addTo($tab)->exec('/bin/pwd');
});
$tab = $tabs->addTab('exec() chain', function ($tab) {
- \Atk4\Ui\Header::addTo($tab, [
+ Header::addTo($tab, [
'icon' => 'terminal',
'Command execution',
'subHeader' => 'it is easy to run server-side commands and stream output through console',
]);
- $message = \Atk4\Ui\Message::addTo($tab, ['This demo may not work', 'type' => 'warning']);
+ $message = Message::addTo($tab, ['This demo may not work', 'type' => 'warning']);
$message->text->addParagraph('This demo requires Linux OS and will display error otherwise.');
- \Atk4\Ui\Console::addTo($tab)->set(function ($console) {
+ Console::addTo($tab)->set(function ($console) {
$console->exec('/sbin/ping', ['-c', '5', '-i', '1', '192.168.0.1']);
$console->exec('/sbin/ping', ['-c', '5', '-i', '2', '8.8.8.8']);
$console->exec('/bin/no-such-command');
@@ -81,25 +91,25 @@ public function generateReport()
});
$tab = $tabs->addTab('composer update', function ($tab) {
- \Atk4\Ui\Header::addTo($tab, [
+ Header::addTo($tab, [
'icon' => 'terminal',
'Command execution',
'subHeader' => 'it is easy to run server-side commands and stream output through console',
]);
- $message = \Atk4\Ui\Message::addTo($tab, ['This demo may not work', 'type' => 'warning']);
+ $message = Message::addTo($tab, ['This demo may not work', 'type' => 'warning']);
$message->text->addParagraph('This demo requires you to have "bash" and "composer" installed and may display error if the process running PHP does not have write access to the "vendor" folder and "composer.*".');
- $button = \Atk4\Ui\Button::addTo($message, ['I understand, proceed anyway', 'class.primary big' => true]);
+ $button = Button::addTo($message, ['I understand, proceed anyway', 'class.primary big' => true]);
- $console = \Atk4\Ui\Console::addTo($tab, ['event' => false]);
+ $console = Console::addTo($tab, ['event' => false]);
$console->exec('bash', ['-c', 'cd ../..; echo "Running \'composer update\' in `pwd`"; composer --no-ansi update; echo "Self-updated. OK to refresh now!"']);
$button->on('click', $console->jsExecute());
});
$tab = $tabs->addTab('Use after form submit', function ($tab) {
- \Atk4\Ui\Header::addTo($tab, [
+ Header::addTo($tab, [
'icon' => 'terminal',
'How to log form submit process',
'subHeader' => 'Sometimes you can have long running process after form submit and want to show progress for user...',
@@ -107,10 +117,10 @@ public function generateReport()
session_start();
- $form = \Atk4\Ui\Form::addTo($tab);
+ $form = Form::addTo($tab);
$form->addControls([['foo'], ['bar']]);
- $console = \Atk4\Ui\Console::addTo($tab, ['event' => false]);
+ $console = Console::addTo($tab, ['event' => false]);
$console->set(function ($console) {
$model = $_SESSION['atk4_ui_console_demo'];
$console->output('Executing process...');
@@ -122,7 +132,7 @@ public function generateReport()
});
$console->js(true)->hide();
- $form->onSubmit(function (\Atk4\Ui\Form $form) use ($console) {
+ $form->onSubmit(function (Form $form) use ($console) {
$_SESSION['atk4_ui_console_demo'] = $form->model; // only option is to store model in session here in demo
return [
diff --git a/demos/interactive/jssortable.php b/demos/interactive/jssortable.php
index 8de9a06c92..7be0a9b2a3 100644
--- a/demos/interactive/jssortable.php
+++ b/demos/interactive/jssortable.php
@@ -4,12 +4,19 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Grid;
+use Atk4\Ui\Header;
use Atk4\Ui\HtmlTemplate;
+use Atk4\Ui\JsSortable;
+use Atk4\Ui\JsToast;
+use Atk4\Ui\Lister;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-$view = \Atk4\Ui\View::addTo($app, ['template' => new HtmlTemplate(
+$view = View::addTo($app, ['template' => new HtmlTemplate(
'
'
)]);
-$lister = \Atk4\Ui\Lister::addTo($view, [], ['List']);
-$lister->onHook(\Atk4\Ui\Lister::HOOK_BEFORE_ROW, function (\Atk4\Ui\Lister $lister) {
+$lister = Lister::addTo($view, [], ['List']);
+$lister->onHook(Lister::HOOK_BEFORE_ROW, function (Lister $lister) {
$row = Country::assertInstanceOf($lister->currentRow);
$row->iso = mb_strtolower($row->iso);
});
@@ -27,28 +34,28 @@
$model->setLimit(20);
$lister->setModel($model);
-$sortable = \Atk4\Ui\JsSortable::addTo($view, ['container' => 'ul', 'draggable' => 'li', 'dataLabel' => 'name']);
+$sortable = JsSortable::addTo($view, ['container' => 'ul', 'draggable' => 'li', 'dataLabel' => 'name']);
$sortable->onReorder(function ($order, $src, $pos, $oldPos) {
if ($_GET['btn'] ?? null) {
- return new \Atk4\Ui\JsToast(implode(' - ', $order));
+ return new JsToast(implode(' - ', $order));
}
- return new \Atk4\Ui\JsToast($src . ' moved from position ' . $oldPos . ' to ' . $pos);
+ return new JsToast($src . ' moved from position ' . $oldPos . ' to ' . $pos);
});
-$button = \Atk4\Ui\Button::addTo($app)->set('Get countries order');
+$button = Button::addTo($app)->set('Get countries order');
$button->js('click', $sortable->jsGetOrders(['btn' => '1']));
// -----------------------------------------------------------------------------
-\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
-\Atk4\Ui\Header::addTo($app, ['Add Drag n drop to Grid']);
+View::addTo($app, ['ui' => 'divider']);
+Header::addTo($app, ['Add Drag n drop to Grid']);
-$grid = \Atk4\Ui\Grid::addTo($app, ['paginator' => false]);
+$grid = Grid::addTo($app, ['paginator' => false]);
$grid->setModel((new Country($app->db))->setLimit(6));
$dragHandler = $grid->addDragHandler();
$dragHandler->onReorder(function ($order) {
- return new \Atk4\Ui\JsToast('New order: ' . implode(' - ', $order));
+ return new JsToast('New order: ' . implode(' - ', $order));
});
diff --git a/demos/interactive/loader.php b/demos/interactive/loader.php
index 882c2fd84e..0386f34bba 100644
--- a/demos/interactive/loader.php
+++ b/demos/interactive/loader.php
@@ -4,37 +4,44 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
+use Atk4\Ui\Loader;
+use Atk4\Ui\LoremIpsum;
+use Atk4\Ui\Message;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Loader Examples - Page 2', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Loader Examples - Page 2', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['loader2']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'clearing divider']);
+View::addTo($app, ['ui' => 'clearing divider']);
// ViewTester will perform callback to self.
ViewTester::addTo($app);
// Example 1 - Basic usage of a Loader.
-\Atk4\Ui\Loader::addTo($app)->set(function (\Atk4\Ui\Loader $p) {
+Loader::addTo($app)->set(function (Loader $p) {
// set your time expensive function here.
sleep(1);
- \Atk4\Ui\Header::addTo($p, ['Loader #1']);
- \Atk4\Ui\LoremIpsum::addTo($p, ['size' => 1]);
+ Header::addTo($p, ['Loader #1']);
+ LoremIpsum::addTo($p, ['size' => 1]);
// Any dynamic views can perform call-backs just fine
ViewTester::addTo($p);
// Loader may be inside another loader, works fine.
- $loader = \Atk4\Ui\Loader::addTo($p);
+ $loader = Loader::addTo($p);
// use loadEvent to prevent manual loading or even specify custom trigger event
$loader->loadEvent = false;
$loader->set(function ($p) {
// You may pass arguments to the loader, in this case it's "color"
sleep(1);
- \Atk4\Ui\Header::addTo($p, ['Loader #1b - ' . $_GET['color']]);
- \Atk4\Ui\LoremIpsum::addTo(\Atk4\Ui\View::addTo($p, ['ui' => $_GET['color'] . ' segment']), ['size' => 1]);
+ Header::addTo($p, ['Loader #1b - ' . $_GET['color']]);
+ LoremIpsum::addTo(View::addTo($p, ['ui' => $_GET['color'] . ' segment']), ['size' => 1]);
// don't forget to make your own argument sticky so that Components can communicate with themselves:
$p->stickyGet('color');
@@ -44,19 +51,19 @@
});
// button may contain load event.
- \Atk4\Ui\Button::addTo($p, ['Load Segment Manually (2s)', 'class.red' => true])->js('click', $loader->jsLoad(['color' => 'red']));
- \Atk4\Ui\Button::addTo($p, ['Load Segment Manually (2s)', 'class.blue' => true])->js('click', $loader->jsLoad(['color' => 'blue']));
+ Button::addTo($p, ['Load Segment Manually (2s)', 'class.red' => true])->js('click', $loader->jsLoad(['color' => 'red']));
+ Button::addTo($p, ['Load Segment Manually (2s)', 'class.blue' => true])->js('click', $loader->jsLoad(['color' => 'blue']));
});
// Example 2 - Loader with custom body.
-\Atk4\Ui\Loader::addTo($app, [
+Loader::addTo($app, [
'ui' => '', // this will prevent "loading spinner" from showing
'shim' => [ // shim is displayed while content is leaded
- \Atk4\Ui\Message::class,
+ Message::class,
'Generating LoremIpsum, please wait...',
'class.red' => true,
],
])->set(function ($p) {
usleep(500_000);
- \Atk4\Ui\LoremIpsum::addTo($p, ['size' => 2]);
+ LoremIpsum::addTo($p, ['size' => 2]);
});
diff --git a/demos/interactive/loader2.php b/demos/interactive/loader2.php
index 80565ccf04..1b3e2e757e 100644
--- a/demos/interactive/loader2.php
+++ b/demos/interactive/loader2.php
@@ -4,22 +4,30 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Columns;
+use Atk4\Ui\Form;
+use Atk4\Ui\Grid;
+use Atk4\Ui\Loader;
+use Atk4\Ui\Text;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Loader Example - page 1', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
+Button::addTo($app, ['Loader Example - page 1', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
->link(['loader']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-$c = \Atk4\Ui\Columns::addTo($app);
+$c = Columns::addTo($app);
-$grid = \Atk4\Ui\Grid::addTo($c->addColumn(), ['ipp' => 10, 'menu' => false]);
+$grid = Grid::addTo($c->addColumn(), ['ipp' => 10, 'menu' => false]);
$grid->setModel(new Country($app->db), [Country::hinting()->fieldName()->name]);
-$countryLoader = \Atk4\Ui\Loader::addTo($c->addColumn(), ['loadEvent' => false, 'shim' => [\Atk4\Ui\Text::class, 'Select country on your left']]);
+$countryLoader = Loader::addTo($c->addColumn(), ['loadEvent' => false, 'shim' => [Text::class, 'Select country on your left']]);
$grid->table->onRowClick($countryLoader->jsLoad(['id' => $grid->table->jsRow()->data('id')]));
$countryLoader->set(function ($p) {
- \Atk4\Ui\Form::addTo($p)->setModel((new Country($p->getApp()->db))->load($_GET['id']));
+ Form::addTo($p)->setModel((new Country($p->getApp()->db))->load($_GET['id']));
});
diff --git a/demos/interactive/modal.php b/demos/interactive/modal.php
index bec8ec583a..c59771a3dd 100644
--- a/demos/interactive/modal.php
+++ b/demos/interactive/modal.php
@@ -4,75 +4,86 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
use Atk4\Data\Persistence;
+use Atk4\Ui\Button;
+use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsExpression;
+use Atk4\Ui\LoremIpsum;
+use Atk4\Ui\Menu;
+use Atk4\Ui\Message;
+use Atk4\Ui\Modal;
+use Atk4\Ui\Text;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, ['Modal View']);
+Header::addTo($app, ['Modal View']);
$session = new Session($app);
// Re-usable component implementing counter
-\Atk4\Ui\Header::addTo($app, ['Static Modal Dialog']);
+Header::addTo($app, ['Static Modal Dialog']);
-$bar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
+$bar = View::addTo($app, ['ui' => 'buttons']);
-$modal = \Atk4\Ui\Modal::addTo($app, ['title' => 'Add a name']);
-\Atk4\Ui\LoremIpsum::addTo($modal);
-\Atk4\Ui\Button::addTo($modal, ['Hide'])->on('click', $modal->hide());
+$modal = Modal::addTo($app, ['title' => 'Add a name']);
+LoremIpsum::addTo($modal);
+Button::addTo($modal, ['Hide'])->on('click', $modal->hide());
-$noTitle = \Atk4\Ui\Modal::addTo($app, ['title' => false]);
-\Atk4\Ui\LoremIpsum::addTo($noTitle);
-\Atk4\Ui\Button::addTo($noTitle, ['Hide'])->on('click', $noTitle->hide());
+$noTitle = Modal::addTo($app, ['title' => false]);
+LoremIpsum::addTo($noTitle);
+Button::addTo($noTitle, ['Hide'])->on('click', $noTitle->hide());
-$scrolling = \Atk4\Ui\Modal::addTo($app, ['title' => 'Long Content that Scrolls inside Modal']);
+$scrolling = Modal::addTo($app, ['title' => 'Long Content that Scrolls inside Modal']);
$scrolling->addScrolling();
-\Atk4\Ui\LoremIpsum::addTo($scrolling);
-\Atk4\Ui\LoremIpsum::addTo($scrolling);
-\Atk4\Ui\LoremIpsum::addTo($scrolling);
-\Atk4\Ui\Button::addTo($scrolling, ['Hide'])->on('click', $scrolling->hide());
+LoremIpsum::addTo($scrolling);
+LoremIpsum::addTo($scrolling);
+LoremIpsum::addTo($scrolling);
+Button::addTo($scrolling, ['Hide'])->on('click', $scrolling->hide());
-\Atk4\Ui\Button::addTo($bar, ['Show'])->on('click', $modal->show());
-\Atk4\Ui\Button::addTo($bar, ['No Title'])->on('click', $noTitle->show());
-\Atk4\Ui\Button::addTo($bar, ['Scrolling Content'])->on('click', $scrolling->show());
+Button::addTo($bar, ['Show'])->on('click', $modal->show());
+Button::addTo($bar, ['No Title'])->on('click', $noTitle->show());
+Button::addTo($bar, ['Scrolling Content'])->on('click', $scrolling->show());
// Modal demos.
// REGULAR
-$simpleModal = \Atk4\Ui\Modal::addTo($app, ['title' => 'Simple modal']);
-\Atk4\Ui\Message::addTo($simpleModal)->set('Modal message here.');
+$simpleModal = Modal::addTo($app, ['title' => 'Simple modal']);
+Message::addTo($simpleModal)->set('Modal message here.');
ViewTester::addTo($simpleModal);
-$menuBar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
-$button = \Atk4\Ui\Button::addTo($menuBar)->set('Show Modal');
+$menuBar = View::addTo($app, ['ui' => 'buttons']);
+$button = Button::addTo($menuBar)->set('Show Modal');
$button->on('click', $simpleModal->show());
// DYNAMIC
-\Atk4\Ui\Header::addTo($app, ['Three levels of Modal loading dynamic content via callback']);
+Header::addTo($app, ['Three levels of Modal loading dynamic content via callback']);
// vp1Modal will be render into page but hide until $vp1Modal->show() is activate.
-$vp1Modal = \Atk4\Ui\Modal::addTo($app, ['title' => 'Lorem Ipsum load dynamically']);
+$vp1Modal = Modal::addTo($app, ['title' => 'Lorem Ipsum load dynamically']);
// vp2Modal will be render into page but hide until $vp1Modal->show() is activate.
-$vp2Modal = \Atk4\Ui\Modal::addTo($app, ['title' => 'Text message load dynamically'])->addClass('small');
+$vp2Modal = Modal::addTo($app, ['title' => 'Text message load dynamically'])->addClass('small');
-$vp3Modal = \Atk4\Ui\Modal::addTo($app, ['title' => 'Third level modal'])->addClass('small');
+$vp3Modal = Modal::addTo($app, ['title' => 'Third level modal'])->addClass('small');
$vp3Modal->set(function ($modal) {
- \Atk4\Ui\Text::addTo($modal)->set('This is yet another modal');
- \Atk4\Ui\LoremIpsum::addTo($modal, ['size' => 2]);
+ Text::addTo($modal)->set('This is yet another modal');
+ LoremIpsum::addTo($modal, ['size' => 2]);
});
// When $vp1Modal->show() is activate, it will dynamically add this content to it.
$vp1Modal->set(function ($modal) use ($vp2Modal) {
ViewTester::addTo($modal);
- \Atk4\Ui\View::addTo($modal, ['Showing lorem ipsum']); // need in behat test.
- \Atk4\Ui\LoremIpsum::addTo($modal, ['size' => 2]);
- $form = \Atk4\Ui\Form::addTo($modal);
+ View::addTo($modal, ['Showing lorem ipsum']); // need in behat test.
+ LoremIpsum::addTo($modal, ['size' => 2]);
+ $form = Form::addTo($modal);
$form->addControl('color', [], ['enum' => ['red', 'green', 'blue'], 'default' => 'green']);
- $form->onSubmit(function (\Atk4\Ui\Form $form) use ($vp2Modal) {
+ $form->onSubmit(function (Form $form) use ($vp2Modal) {
return $vp2Modal->show(['color' => $form->model->get('color')]);
});
});
@@ -80,12 +91,12 @@
// When $vp2Modal->show() is activate, it will dynamically add this content to it.
$vp2Modal->set(function ($modal) use ($vp3Modal) {
ViewTester::addTo($modal);
- \Atk4\Ui\Message::addTo($modal, ['Message', $_GET['color'] ?? 'No color'])->text->addParagraph('This text is loaded using a second modal.');
- \Atk4\Ui\Button::addTo($modal)->set('Third modal')->on('click', $vp3Modal->show());
+ Message::addTo($modal, ['Message', $_GET['color'] ?? 'No color'])->text->addParagraph('This text is loaded using a second modal.');
+ Button::addTo($modal)->set('Third modal')->on('click', $vp3Modal->show());
});
-$bar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
-$button = \Atk4\Ui\Button::addTo($bar)->set('Open Lorem Ipsum');
+$bar = View::addTo($app, ['ui' => 'buttons']);
+$button = Button::addTo($bar)->set('Open Lorem Ipsum');
$button->on('click', $vp1Modal->show());
// ANIMATION
@@ -102,14 +113,14 @@
'static' => ['jiggle', 'flash', 'shake', 'pulse', 'tada', 'bounce'],
];
-\Atk4\Ui\Header::addTo($app, ['Modal Animation']);
+Header::addTo($app, ['Modal Animation']);
-$transitionModal = \Atk4\Ui\Modal::addTo($app, ['title' => 'Animated modal']);
-\Atk4\Ui\Message::addTo($transitionModal)->set('A lot of animated transition available');
+$transitionModal = Modal::addTo($app, ['title' => 'Animated modal']);
+Message::addTo($transitionModal)->set('A lot of animated transition available');
$transitionModal->duration(1000);
-$menuBar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
-$main = \Atk4\Ui\Menu::addTo($menuBar);
+$menuBar = View::addTo($app, ['ui' => 'buttons']);
+$main = Menu::addTo($menuBar);
$transitionMenu = $main->addMenu('Select Transition');
foreach ($menuItems as $key => $items) {
@@ -127,30 +138,30 @@
// DENY APPROVE
-\Atk4\Ui\Header::addTo($app, ['Modal Options']);
+Header::addTo($app, ['Modal Options']);
-$denyApproveModal = \Atk4\Ui\Modal::addTo($app, ['title' => 'Deny / Approve actions']);
-\Atk4\Ui\Message::addTo($denyApproveModal)->set('This modal is only closable via the green button');
-$denyApproveModal->addDenyAction('No', new \Atk4\Ui\JsExpression('function() { window.alert("Can\'t do that."); return false; }'));
-$denyApproveModal->addApproveAction('Yes', new \Atk4\Ui\JsExpression('function() { window.alert("You\'re good to go!"); }'));
+$denyApproveModal = Modal::addTo($app, ['title' => 'Deny / Approve actions']);
+Message::addTo($denyApproveModal)->set('This modal is only closable via the green button');
+$denyApproveModal->addDenyAction('No', new JsExpression('function() { window.alert("Can\'t do that."); return false; }'));
+$denyApproveModal->addApproveAction('Yes', new JsExpression('function() { window.alert("You\'re good to go!"); }'));
$denyApproveModal->notClosable();
-$menuBar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
-$button = \Atk4\Ui\Button::addTo($menuBar)->set('Show Deny/Approve');
+$menuBar = View::addTo($app, ['ui' => 'buttons']);
+$button = Button::addTo($menuBar)->set('Show Deny/Approve');
$button->on('click', $denyApproveModal->show());
// MULTI STEP
-\Atk4\Ui\Header::addTo($app, ['Multiple page modal']);
+Header::addTo($app, ['Multiple page modal']);
// Add modal to layout.
-$stepModal = \Atk4\Ui\Modal::addTo($app, ['title' => 'Multi step actions']);
+$stepModal = Modal::addTo($app, ['title' => 'Multi step actions']);
$stepModal->setOption('observeChanges', true);
// Add buttons to modal for next and previous actions.
-$action = new \Atk4\Ui\View(['ui' => 'buttons']);
-$prevAction = new \Atk4\Ui\Button(['Prev', 'class.labeled' => true, 'icon' => 'left arrow']);
-$nextAction = new \Atk4\Ui\Button(['Next', 'iconRight' => 'right arrow']);
+$action = new View(['ui' => 'buttons']);
+$prevAction = new Button(['Prev', 'class.labeled' => true, 'icon' => 'left arrow']);
+$nextAction = new Button(['Next', 'iconRight' => 'right arrow']);
$action->add($prevAction);
$action->add($nextAction);
@@ -175,20 +186,20 @@
}
$session->memorize('page', $page);
if ($page === 1) {
- \Atk4\Ui\Message::addTo($modal)->set('Thanks for choosing us. We will be asking some questions along the way.');
+ Message::addTo($modal)->set('Thanks for choosing us. We will be asking some questions along the way.');
$session->memorize('success', true);
$modal->js(true, $prevAction->js(true)->show());
$modal->js(true, $nextAction->js(true)->show());
$modal->js(true, $prevAction->js()->addClass('disabled'));
$modal->js(true, $nextAction->js(true)->removeClass('disabled'));
} elseif ($page === 2) {
- $modelRegister = new \Atk4\Data\Model(new Persistence\Array_());
+ $modelRegister = new Model(new Persistence\Array_());
$modelRegister->addField('name', ['caption' => 'Please enter your name (John)']);
- $form = \Atk4\Ui\Form::addTo($modal, ['class.segment' => true]);
+ $form = Form::addTo($modal, ['class.segment' => true]);
$form->setModel($modelRegister->createEntity());
- $form->onSubmit(function (\Atk4\Ui\Form $form) use ($nextAction, $session) {
+ $form->onSubmit(function (Form $form) use ($nextAction, $session) {
if ($form->model->get('name') !== 'John') {
return $form->error('name', 'Your name is not John! It is "' . $form->model->get('name') . '". It should be John. Pleeease!');
}
@@ -204,7 +215,7 @@
$modal->js(true, $nextAction->js(true)->addClass('disabled'));
} elseif ($page === 3) {
$name = $session->recall('name');
- \Atk4\Ui\Message::addTo($modal)->set("Thank you {$name} for visiting us! We will be in touch");
+ Message::addTo($modal)->set("Thank you {$name} for visiting us! We will be in touch");
$session->memorize('success', true);
$modal->js(true, $prevAction->js(true)->hide());
$modal->js(true, $nextAction->js(true)->hide());
@@ -223,6 +234,6 @@
));
// Bind display modal to page display button.
-$menuBar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
-$button = \Atk4\Ui\Button::addTo($menuBar)->set('Multi Step Modal');
+$menuBar = View::addTo($app, ['ui' => 'buttons']);
+$button = Button::addTo($menuBar)->set('Multi Step Modal');
$button->on('click', $stepModal->show());
diff --git a/demos/interactive/paginator.php b/demos/interactive/paginator.php
index c31b16a3f8..42d5cfc7fb 100644
--- a/demos/interactive/paginator.php
+++ b/demos/interactive/paginator.php
@@ -4,34 +4,39 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Header;
+use Atk4\Ui\Label;
+use Atk4\Ui\Paginator;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
// Paginator which tracks its own position
-\Atk4\Ui\Header::addTo($app, ['Paginator tracks its own position']);
-\Atk4\Ui\Paginator::addTo($app, ['total' => 40, 'urlTrigger' => 'page']);
+Header::addTo($app, ['Paginator tracks its own position']);
+Paginator::addTo($app, ['total' => 40, 'urlTrigger' => 'page']);
// Dynamically reloading paginator
-\Atk4\Ui\Header::addTo($app, ['Dynamic reloading']);
-$seg = \Atk4\Ui\View::addTo($app, ['ui' => 'blue segment']);
-$label = \Atk4\Ui\Label::addTo($seg);
-$bb = \Atk4\Ui\Paginator::addTo($seg, ['total' => 50, 'range' => 2, 'reload' => $seg]);
+Header::addTo($app, ['Dynamic reloading']);
+$seg = View::addTo($app, ['ui' => 'blue segment']);
+$label = Label::addTo($seg);
+$bb = Paginator::addTo($seg, ['total' => 50, 'range' => 2, 'reload' => $seg]);
$label->addClass('blue ribbon');
$label->set('Current page: ' . $bb->page);
// Multiple dependent Paginators
-\Atk4\Ui\Header::addTo($app, ['Local Sticky Usage']);
-$seg = \Atk4\Ui\View::addTo($app, ['ui' => 'blue segment']);
+Header::addTo($app, ['Local Sticky Usage']);
+$seg = View::addTo($app, ['ui' => 'blue segment']);
$month = $seg->stickyGet('month') ?: 1;
$day = $seg->stickyGet('day') ?: 1;
// we intentionally left 31 days here and do not calculate number of days in particular month to keep example simple
-$monthPaginator = \Atk4\Ui\Paginator::addTo($seg, ['total' => 12, 'range' => 3, 'urlTrigger' => 'month']);
-\Atk4\Ui\View::addTo($seg, ['ui' => 'hidden divider']);
-$dayPaginator = \Atk4\Ui\Paginator::addTo($seg, ['total' => 31, 'range' => 3, 'urlTrigger' => 'day']);
-\Atk4\Ui\View::addTo($seg, ['ui' => 'hidden divider']);
+$monthPaginator = Paginator::addTo($seg, ['total' => 12, 'range' => 3, 'urlTrigger' => 'month']);
+View::addTo($seg, ['ui' => 'hidden divider']);
+$dayPaginator = Paginator::addTo($seg, ['total' => 31, 'range' => 3, 'urlTrigger' => 'day']);
+View::addTo($seg, ['ui' => 'hidden divider']);
-$label = \Atk4\Ui\Label::addTo($seg);
+$label = Label::addTo($seg);
$label->addClass('orange');
$label->set('Month: ' . $month . ' and Day: ' . $day);
diff --git a/demos/interactive/popup.php b/demos/interactive/popup.php
index b6943948f9..c4b6ddb1c8 100644
--- a/demos/interactive/popup.php
+++ b/demos/interactive/popup.php
@@ -4,8 +4,20 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Columns;
+use Atk4\Ui\Dropdown as UiDropdown;
use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\Item as UiItem;
+use Atk4\Ui\Jquery;
+use Atk4\Ui\JsExpression;
+use Atk4\Ui\Label;
+use Atk4\Ui\Lister;
+use Atk4\Ui\Menu;
+use Atk4\Ui\Message;
use Atk4\Ui\Popup;
+use Atk4\Ui\SessionTrait;
use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
@@ -18,9 +30,9 @@
* render the items.
*/
-/** @var \Atk4\Ui\Lister $cartClass */
-$cartClass = AnonymousClassNameCache::get_class(fn () => new class() extends \Atk4\Ui\Lister {
- use \Atk4\Ui\SessionTrait;
+/** @var Lister $cartClass */
+$cartClass = AnonymousClassNameCache::get_class(fn () => new class() extends Lister {
+ use SessionTrait;
public $items = [];
@@ -95,30 +107,30 @@ protected function init(): void
parent::init();
$v = View::addTo($this, ['ui' => 'fluid']);
- $cols = \Atk4\Ui\Columns::addTo($v, ['ui' => 'relaxed divided grid']);
+ $cols = Columns::addTo($v, ['ui' => 'relaxed divided grid']);
$c1 = $cols->addColumn();
- \Atk4\Ui\Header::addTo($c1, ['size' => 'small'])->set('Snacks');
+ Header::addTo($c1, ['size' => 'small'])->set('Snacks');
$l1 = View::addTo($c1, ['ui' => 'list']);
- \Atk4\Ui\Item::addTo($l1, ['content' => 'Crisps', 'ui' => 'item'])->setElement('a');
- \Atk4\Ui\Item::addTo($l1, ['content' => 'Pork Scratchings', 'ui' => 'item'])->setElement('a');
- \Atk4\Ui\Item::addTo($l1, ['content' => 'Candies', 'ui' => 'item'])->setElement('a');
- \Atk4\Ui\Item::addTo($l1, ['content' => 'Sweets', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l1, ['content' => 'Crisps', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l1, ['content' => 'Pork Scratchings', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l1, ['content' => 'Candies', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l1, ['content' => 'Sweets', 'ui' => 'item'])->setElement('a');
$c2 = $cols->addColumn();
- \Atk4\Ui\Header::addTo($c2, ['size' => 'small'])->set('Drinks');
+ Header::addTo($c2, ['size' => 'small'])->set('Drinks');
$l2 = View::addTo($c2, ['ui' => 'list']);
- \Atk4\Ui\Item::addTo($l2, ['content' => 'Fizzy Drink', 'ui' => 'item'])->setElement('a');
- \Atk4\Ui\Item::addTo($l2, ['content' => 'Hot Latte', 'ui' => 'item'])->setElement('a');
- \Atk4\Ui\Item::addTo($l2, ['content' => 'Water', 'ui' => 'item'])->setElement('a');
- \Atk4\Ui\Item::addTo($l2, ['content' => 'Apple Juice', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l2, ['content' => 'Fizzy Drink', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l2, ['content' => 'Hot Latte', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l2, ['content' => 'Water', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l2, ['content' => 'Apple Juice', 'ui' => 'item'])->setElement('a');
$c3 = $cols->addColumn();
- \Atk4\Ui\Header::addTo($c3, ['size' => 'small'])->set('Mains');
+ Header::addTo($c3, ['size' => 'small'])->set('Mains');
$l3 = View::addTo($c3, ['ui' => 'list']);
- \Atk4\Ui\Item::addTo($l3, ['content' => 'Chicken Tikka', 'ui' => 'item'])->setElement('a');
- \Atk4\Ui\Item::addTo($l3, ['content' => 'Green Curry', 'ui' => 'item'])->setElement('a');
- \Atk4\Ui\Item::addTo($l3, ['content' => 'Pastries', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l3, ['content' => 'Chicken Tikka', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l3, ['content' => 'Green Curry', 'ui' => 'item'])->setElement('a');
+ UiItem::addTo($l3, ['content' => 'Pastries', 'ui' => 'item'])->setElement('a');
}
/**
@@ -133,17 +145,17 @@ public function linkCart($cart, $jsAction = null)
$cart->addItem($b);
return $jsAction;
- }, [(new \Atk4\Ui\Jquery())->text()]);
+ }, [(new Jquery())->text()]);
}
});
-\Atk4\Ui\Header::addTo($app)->set('Menu popup');
-$menu = \Atk4\Ui\Menu::addTo($app);
+Header::addTo($app)->set('Menu popup');
+$menu = Menu::addTo($app);
// You may add popup on top of menu items or dropdowns. Dropdowns have a slightly different
// look, with that triangle on the right. You don't have to add pop-up right away, it can be
// added later.
-$browse = \Atk4\Ui\Dropdown::addTo($menu, ['Browse']);
+$browse = UiDropdown::addTo($menu, ['Browse']);
// Add cart item into the menu, with a popup inside
$cartItem = $menu->addItem([$cartClass, 'icon' => 'cart'])->set('Cart');
@@ -182,21 +194,21 @@ public function linkCart($cart, $jsAction = null)
// Label now can be added referencing Cart's items. Init() was colled when I added it into app, so the
// item property is populated.
-$cartOutterLabel = \Atk4\Ui\Label::addTo($cartItem, [count($cart->items), 'class.floating red' => true]);
+$cartOutterLabel = Label::addTo($cartItem, [count($cart->items), 'class.floating red' => true]);
if (!$cart->items) {
$cartOutterLabel->addStyle('display', 'none');
}
$cartPopup->set(function ($popup) use ($cart) {
- $cartInnerLabel = \Atk4\Ui\Label::addTo($popup, ['Number of items:']);
+ $cartInnerLabel = Label::addTo($popup, ['Number of items:']);
// cart is already initialized, so init() is not called again. However, cart will be rendered
// as a child of a pop-up now.
$cart = $popup->add($cart);
$cartInnerLabel->detail = count($cart->items);
- \Atk4\Ui\Item::addTo($popup)->setElement('hr');
- \Atk4\Ui\Button::addTo($popup, ['Checkout', 'class.primary small' => true]);
+ UiItem::addTo($popup)->setElement('hr');
+ Button::addTo($popup, ['Checkout', 'class.primary small' => true]);
});
// Add item shelf below menu and link it with the cart
@@ -205,7 +217,7 @@ public function linkCart($cart, $jsAction = null)
$cartOutterLabel->jsReload(),
// also will hide current item from the shelf
- (new \Atk4\Ui\Jquery())->hide(),
+ (new Jquery())->hide(),
]);
// label placed on top of menu item, not in the popup
@@ -218,7 +230,7 @@ public function linkCart($cart, $jsAction = null)
// -----------------------------------------------------------------------------
-$userMenu = \Atk4\Ui\Menu::addTo($menu, ['ui' => false], ['RightMenu'])
+$userMenu = Menu::addTo($menu, ['ui' => false], ['RightMenu'])
->addClass('right menu')->removeClass('item');
$rightMenu = $userMenu->addMenu(['', 'icon' => 'user']);
@@ -231,8 +243,8 @@ public function linkCart($cart, $jsAction = null)
$signup->set(function ($pop) {
// contetn of the popup will be different depending on this condition.
if (isset($_GET['logged'])) {
- \Atk4\Ui\Message::addTo($pop, ['You are already logged in as ' . $_GET['logged']]);
- \Atk4\Ui\Button::addTo($pop, ['Logout', 'class.primary' => true, 'icon' => 'sign out'])
+ Message::addTo($pop, ['You are already logged in as ' . $_GET['logged']]);
+ Button::addTo($pop, ['Logout', 'class.primary' => true, 'icon' => 'sign out'])
->link($pop->getApp()->url());
} else {
$form = Form::addTo($pop);
@@ -249,20 +261,20 @@ public function linkCart($cart, $jsAction = null)
// refreshes entire page
return $form->getApp()->jsRedirect(['logged' => $form->model->get('email')]);
- // return new \Atk4\Ui\JsExpression('alert([])', ['Thank you ' . $form->model->get('email')]);
+ // return new JsExpression('alert([])', ['Thank you ' . $form->model->get('email')]);
});
}
});
// -----------------------------------------------------------------------------
-\Atk4\Ui\Header::addTo($app)->set('Specifying trigger');
+Header::addTo($app)->set('Specifying trigger');
-$button = \Atk4\Ui\Button::addTo($app, ['Click Me', 'class.primary' => true]);
+$button = Button::addTo($app, ['Click Me', 'class.primary' => true]);
$buttonPopup = Popup::addTo($app, [$button]);
-\Atk4\Ui\Header::addTo($buttonPopup)->set('Using click events');
+Header::addTo($buttonPopup)->set('Using click events');
View::addTo($buttonPopup)->set('Adding popup into button activates on click by default. Clicked popups will close if you click away.');
$input = Form\Control\Line::addTo($app, ['placeholder' => 'Search users', 'icon' => 'circular search link']);
@@ -270,7 +282,7 @@ public function linkCart($cart, $jsAction = null)
$inputPopup = Popup::addTo($app, [$input, 'triggerOn' => 'focus']);
View::addTo($inputPopup)->set('You can use this field to search data.');
-$button = \Atk4\Ui\Button::addTo($app, [null, 'icon' => 'volume down']);
+$button = Button::addTo($app, [null, 'icon' => 'volume down']);
$buttonPopup = Popup::addTo($app, [$button, 'triggerOn' => 'hover'])->setHoverable();
Form\Control\Checkbox::addTo($buttonPopup, ['Just On/Off', 'class.slider' => true])->on('change', $button->js()->find('.icon')->toggleClass('up down'));
diff --git a/demos/interactive/progress.php b/demos/interactive/progress.php
index c0b63c6d81..414326a876 100644
--- a/demos/interactive/progress.php
+++ b/demos/interactive/progress.php
@@ -4,11 +4,14 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\ProgressBar;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-$p = \Atk4\Ui\ProgressBar::addTo($app, [20]);
+$p = ProgressBar::addTo($app, [20]);
-$p = \Atk4\Ui\ProgressBar::addTo($app, [60, 'indicating progress', 'class.indicating' => true]);
-\Atk4\Ui\Button::addTo($app, ['increment'])->on('click', $p->jsIncrement());
-\Atk4\Ui\Button::addTo($app, ['set'])->on('click', $p->jsValue(20));
+$p = ProgressBar::addTo($app, [60, 'indicating progress', 'class.indicating' => true]);
+Button::addTo($app, ['increment'])->on('click', $p->jsIncrement());
+Button::addTo($app, ['set'])->on('click', $p->jsValue(20));
diff --git a/demos/interactive/scroll-container.php b/demos/interactive/scroll-container.php
index d4fed4a73c..26a2a7b9af 100644
--- a/demos/interactive/scroll-container.php
+++ b/demos/interactive/scroll-container.php
@@ -4,29 +4,33 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
use Atk4\Ui\HtmlTemplate;
+use Atk4\Ui\Lister;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Dynamic scroll in Table', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
+Button::addTo($app, ['Dynamic scroll in Table', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
->link(['scroll-table']);
-\Atk4\Ui\Button::addTo($app, ['Dynamic scroll in Grid', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Dynamic scroll in Grid', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['scroll-grid']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-\Atk4\Ui\Header::addTo($app, ['Dynamic scroll in Container']);
+Header::addTo($app, ['Dynamic scroll in Container']);
-$view = \Atk4\Ui\View::addTo($app)->addClass('ui basic segment atk-scroller');
+$view = View::addTo($app)->addClass('ui basic segment atk-scroller');
-$scrollContainer = \Atk4\Ui\View::addTo($view)->addClass('ui segment')->addStyle(['max-height' => '400px', 'overflow-y' => 'scroll']);
+$scrollContainer = View::addTo($view)->addClass('ui segment')->addStyle(['max-height' => '400px', 'overflow-y' => 'scroll']);
$listerTemplate = '
{List}
{name}andorra{/}
{/}{$Content}
';
-$listerContainer = \Atk4\Ui\View::addTo($scrollContainer, ['template' => new HtmlTemplate($listerTemplate)]);
+$listerContainer = View::addTo($scrollContainer, ['template' => new HtmlTemplate($listerTemplate)]);
-$lister = \Atk4\Ui\Lister::addTo($listerContainer, [], ['List']);
-$lister->onHook(\Atk4\Ui\Lister::HOOK_BEFORE_ROW, function (\Atk4\Ui\Lister $lister) {
+$lister = Lister::addTo($listerContainer, [], ['List']);
+$lister->onHook(Lister::HOOK_BEFORE_ROW, function (Lister $lister) {
$row = Country::assertInstanceOf($lister->currentRow);
$row->iso = mb_strtolower($row->iso);
});
diff --git a/demos/interactive/scroll-grid-container.php b/demos/interactive/scroll-grid-container.php
index 72941ad1ab..bb7bc41a78 100644
--- a/demos/interactive/scroll-grid-container.php
+++ b/demos/interactive/scroll-grid-container.php
@@ -4,26 +4,34 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Card;
+use Atk4\Ui\Columns;
+use Atk4\Ui\Crud;
+use Atk4\Ui\Grid;
+use Atk4\Ui\Header;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Dynamic scroll in Crud and Grid', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
+Button::addTo($app, ['Dynamic scroll in Crud and Grid', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
->link(['scroll-grid']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-\Atk4\Ui\Header::addTo($app, ['Dynamic scroll in Grid with fixed column headers']);
+Header::addTo($app, ['Dynamic scroll in Grid with fixed column headers']);
-$c = \Atk4\Ui\Columns::addTo($app);
+$c = Columns::addTo($app);
$c1 = $c->addColumn();
-$g1 = \Atk4\Ui\Crud::addTo($c1);
+$g1 = Crud::addTo($c1);
$m1 = new Country($app->db);
$g1->setModel($m1);
$g1->addQuickSearch([Country::hinting()->fieldName()->name, Country::hinting()->fieldName()->iso]);
// demo for additional action buttons in Crud + JsPaginator
$g1->addModalAction(['icon' => 'cogs'], 'Details', function ($p, $id) use ($g1) {
- \Atk4\Ui\Card::addTo($p)->setModel($g1->model->load($id));
+ Card::addTo($p)->setModel($g1->model->load($id));
});
$g1->addActionButton('red', function ($js) {
return $js->closest('tr')->css('color', 'red');
@@ -32,12 +40,12 @@
$g1->addJsPaginatorInContainer(30, 350);
$c2 = $c->addColumn();
-$g2 = \Atk4\Ui\Grid::addTo($c2, ['menu' => false]);
+$g2 = Grid::addTo($c2, ['menu' => false]);
$m2 = new Country($app->db);
$g2->setModel($m2);
$g2->addJsPaginatorInContainer(20, 200);
-$g3 = \Atk4\Ui\Grid::addTo($c2, ['menu' => false]);
+$g3 = Grid::addTo($c2, ['menu' => false]);
$m3 = new Country($app->db);
$g3->setModel($m3);
$g3->addJsPaginatorInContainer(10, 150);
diff --git a/demos/interactive/scroll-grid.php b/demos/interactive/scroll-grid.php
index 9c08a5719a..76d732f44c 100644
--- a/demos/interactive/scroll-grid.php
+++ b/demos/interactive/scroll-grid.php
@@ -4,18 +4,23 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Grid;
+use Atk4\Ui\Header;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Dynamic scroll in Container', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
+Button::addTo($app, ['Dynamic scroll in Container', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
->link(['scroll-container']);
-\Atk4\Ui\Button::addTo($app, ['Dynamic scroll in Grid using Container', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Dynamic scroll in Grid using Container', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['scroll-grid-container']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-\Atk4\Ui\Header::addTo($app, ['Dynamic scroll in Grid']);
+Header::addTo($app, ['Dynamic scroll in Grid']);
-$grid = \Atk4\Ui\Grid::addTo($app, ['menu' => false]);
+$grid = Grid::addTo($app, ['menu' => false]);
$model = new Country($app->db);
$grid->setModel($model);
diff --git a/demos/interactive/scroll-lister.php b/demos/interactive/scroll-lister.php
index a094b0df09..d4230c92ab 100644
--- a/demos/interactive/scroll-lister.php
+++ b/demos/interactive/scroll-lister.php
@@ -4,25 +4,29 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
use Atk4\Ui\HtmlTemplate;
+use Atk4\Ui\Lister;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Dynamic scroll in Table', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Dynamic scroll in Table', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['scroll-table']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-\Atk4\Ui\Header::addTo($app, ['Dynamic scroll in Lister']);
+Header::addTo($app, ['Dynamic scroll in Lister']);
-$container = \Atk4\Ui\View::addTo($app);
+$container = View::addTo($app);
-$view = \Atk4\Ui\View::addTo($container, ['template' => new HtmlTemplate('
+$view = View::addTo($container, ['template' => new HtmlTemplate('
{List}
{$atk_fp_country__name}
{/}
{$Content}')]);
-$lister = \Atk4\Ui\Lister::addTo($view, [], ['List']);
-$lister->onHook(\Atk4\Ui\Lister::HOOK_BEFORE_ROW, function (\Atk4\Ui\Lister $lister) {
+$lister = Lister::addTo($view, [], ['List']);
+$lister->onHook(Lister::HOOK_BEFORE_ROW, function (Lister $lister) {
$row = Country::assertInstanceOf($lister->currentRow);
$row->iso = mb_strtolower($row->iso);
});
diff --git a/demos/interactive/scroll-table.php b/demos/interactive/scroll-table.php
index 238791006d..bf594f072d 100644
--- a/demos/interactive/scroll-table.php
+++ b/demos/interactive/scroll-table.php
@@ -4,18 +4,23 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
+use Atk4\Ui\Table;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Dynamic scroll in Lister', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
+Button::addTo($app, ['Dynamic scroll in Lister', 'class.small left floated basic blue' => true, 'icon' => 'left arrow'])
->link(['scroll-lister']);
-\Atk4\Ui\Button::addTo($app, ['Dynamic scroll in Container', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Dynamic scroll in Container', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['scroll-container']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'ui clearing divider']);
+View::addTo($app, ['ui' => 'ui clearing divider']);
-\Atk4\Ui\Header::addTo($app, ['Dynamic scroll in Table']);
+Header::addTo($app, ['Dynamic scroll in Table']);
-$table = \Atk4\Ui\Table::addTo($app);
+$table = Table::addTo($app);
$model = new Country($app->db);
$table->setModel($model);
diff --git a/demos/interactive/sse.php b/demos/interactive/sse.php
index 22b3598c9b..cc0a48d450 100644
--- a/demos/interactive/sse.php
+++ b/demos/interactive/sse.php
@@ -4,19 +4,25 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsSse;
+use Atk4\Ui\ProgressBar;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, ['SSE with ProgressBar']);
+Header::addTo($app, ['SSE with ProgressBar']);
-$bar = \Atk4\Ui\ProgressBar::addTo($app);
+$bar = ProgressBar::addTo($app);
-$button = \Atk4\Ui\Button::addTo($app, ['Turn On']);
-$buttonStop = \Atk4\Ui\Button::addTo($app, ['Turn Off']);
+$button = Button::addTo($app, ['Turn On']);
+$buttonStop = Button::addTo($app, ['Turn Off']);
// non-SSE way
// $button->on('click', $bar->js()->progress(['percent' => 40]));
-$sse = \Atk4\Ui\JsSse::addTo($app, ['showLoader' => true]);
+$sse = JsSse::addTo($app, ['showLoader' => true]);
$button->on('click', $sse->set(function () use ($button, $sse, $bar) {
$sse->send($button->js()->addClass('disabled'));
@@ -39,11 +45,11 @@
$buttonStop->on('click', [$button->js()->atkServerEvent('stop'), $button->js()->removeClass('disabled')]);
-\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
-\Atk4\Ui\Header::addTo($app, ['SSE operation with user confirmation']);
+View::addTo($app, ['ui' => 'divider']);
+Header::addTo($app, ['SSE operation with user confirmation']);
-$sse = \Atk4\Ui\JsSse::addTo($app);
-$button = \Atk4\Ui\Button::addTo($app, ['Click me to change my text']);
+$sse = JsSse::addTo($app);
+$button = Button::addTo($app, ['Click me to change my text']);
$button->on('click', $sse->set(function ($jsChain) use ($sse, $button) {
$sse->send($button->js()->text('Please wait for 2 seconds...'));
diff --git a/demos/interactive/tabs.php b/demos/interactive/tabs.php
index 7b9f74ca36..4f686fd955 100644
--- a/demos/interactive/tabs.php
+++ b/demos/interactive/tabs.php
@@ -4,47 +4,55 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
use Atk4\Data\Persistence;
+use Atk4\Ui\Button;
+use Atk4\Ui\Form;
+use Atk4\Ui\HelloWorld;
+use Atk4\Ui\LoremIpsum;
+use Atk4\Ui\Message;
+use Atk4\Ui\Modal;
+use Atk4\Ui\Tabs;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-$tabs = \Atk4\Ui\Tabs::addTo($app);
+$tabs = Tabs::addTo($app);
// static tab
-\Atk4\Ui\HelloWorld::addTo($tabs->addTab('Hello'));
+HelloWorld::addTo($tabs->addTab('Hello'));
$tab = $tabs->addTab('Static Tab');
-\Atk4\Ui\Message::addTo($tab, ['Content of this tab will refresh only if you reload entire page']);
-\Atk4\Ui\LoremIpsum::addTo($tab);
+Message::addTo($tab, ['Content of this tab will refresh only if you reload entire page']);
+LoremIpsum::addTo($tab);
// set the default active tab
$tabs->addTab('Default Active Tab', function ($tab) {
- \Atk4\Ui\Message::addTo($tab, ['This is the active tab by default']);
+ Message::addTo($tab, ['This is the active tab by default']);
})->setActive();
// dynamic tab
$tabs->addTab('Dynamic Lorem Ipsum', function ($tab) {
- \Atk4\Ui\Message::addTo($tab, ['Every time you come to this tab, you will see a different text']);
- \Atk4\Ui\LoremIpsum::addTo($tab, ['size' => (int) ($_GET['size'] ?? 1)]);
+ Message::addTo($tab, ['Every time you come to this tab, you will see a different text']);
+ LoremIpsum::addTo($tab, ['size' => (int) ($_GET['size'] ?? 1)]);
}, ['apiSettings' => ['data' => ['size' => random_int(1, 4)]]]);
// modal tab
$tabs->addTab('Modal popup', function ($tab) {
- \Atk4\Ui\Button::addTo($tab, ['Load Lorem'])->on('click', \Atk4\Ui\Modal::addTo($tab)->set(function ($p) {
- \Atk4\Ui\LoremIpsum::addTo($p, ['size' => 2]);
+ Button::addTo($tab, ['Load Lorem'])->on('click', Modal::addTo($tab)->set(function ($p) {
+ LoremIpsum::addTo($p, ['size' => 2]);
})->show());
});
// dynamic tab
$tabs->addTab('Dynamic Form', function ($tab) {
- \Atk4\Ui\Message::addTo($tab, ['It takes 2 seconds for this tab to load', 'type' => 'warning']);
+ Message::addTo($tab, ['It takes 2 seconds for this tab to load', 'type' => 'warning']);
sleep(2);
- $modelRegister = new \Atk4\Data\Model(new Persistence\Array_());
+ $modelRegister = new Model(new Persistence\Array_());
$modelRegister->addField('name', ['caption' => 'Please enter your name (John)']);
- $form = \Atk4\Ui\Form::addTo($tab, ['class.segment' => true]);
+ $form = Form::addTo($tab, ['class.segment' => true]);
$form->setModel($modelRegister->createEntity());
- $form->onSubmit(function (\Atk4\Ui\Form $form) {
+ $form->onSubmit(function (Form $form) {
if ($form->model->get('name') !== 'John') {
return $form->error('name', 'Your name is not John! It is "' . $form->model->get('name') . '". It should be John. Pleeease!');
}
diff --git a/demos/interactive/toast.php b/demos/interactive/toast.php
index 3940943423..7728a95775 100644
--- a/demos/interactive/toast.php
+++ b/demos/interactive/toast.php
@@ -4,87 +4,91 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsToast;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, ['Toast']);
+Header::addTo($app, ['Toast']);
-$btn = \Atk4\Ui\Button::addTo($app)->set('Minimal');
+$btn = Button::addTo($app)->set('Minimal');
-$btn->on('click', new \Atk4\Ui\JsToast('Hi there!'));
+$btn->on('click', new JsToast('Hi there!'));
-$btn = \Atk4\Ui\Button::addTo($app)->set('Using a title');
+$btn = Button::addTo($app)->set('Using a title');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn->on('click', new JsToast([
'title' => 'Title',
'message' => 'See I have a title',
]));
-\Atk4\Ui\Header::addTo($app, ['Using class name']);
+Header::addTo($app, ['Using class name']);
-$btn = \Atk4\Ui\Button::addTo($app)->set('Success');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn = Button::addTo($app)->set('Success');
+$btn->on('click', new JsToast([
'title' => 'Success',
'message' => 'Well done',
'class' => 'success',
]));
-$btn = \Atk4\Ui\Button::addTo($app)->set('Error');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn = Button::addTo($app)->set('Error');
+$btn->on('click', new JsToast([
'title' => 'Error',
'message' => 'An error occured',
'class' => 'error',
]));
-$btn = \Atk4\Ui\Button::addTo($app)->set('Warning');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn = Button::addTo($app)->set('Warning');
+$btn->on('click', new JsToast([
'title' => 'Warning',
'message' => 'Behind you!',
'class' => 'warning',
]));
-\Atk4\Ui\Header::addTo($app, ['Using different position']);
+Header::addTo($app, ['Using different position']);
-$btn = \Atk4\Ui\Button::addTo($app)->set('Bottom Right');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn = Button::addTo($app)->set('Bottom Right');
+$btn->on('click', new JsToast([
'title' => 'Bottom Right',
'message' => 'Should appear at the bottom on your right',
'position' => 'bottom right',
]));
-$btn = \Atk4\Ui\Button::addTo($app)->set('Top Center');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn = Button::addTo($app)->set('Top Center');
+$btn->on('click', new JsToast([
'title' => 'Top Center',
'message' => 'Should appear at the top center',
'position' => 'top center',
]));
-\Atk4\Ui\Header::addTo($app, ['Other Options']);
+Header::addTo($app, ['Other Options']);
-$btn = \Atk4\Ui\Button::addTo($app)->set('5 seconds');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn = Button::addTo($app)->set('5 seconds');
+$btn->on('click', new JsToast([
'title' => 'Timeout',
'message' => 'I will stay here for 5 sec.',
'displayTime' => 5000,
]));
-$btn = \Atk4\Ui\Button::addTo($app)->set('For ever');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn = Button::addTo($app)->set('For ever');
+$btn->on('click', new JsToast([
'title' => 'No Timeout',
'message' => 'I will stay until you click me',
'displayTime' => 0,
]));
-$btn = \Atk4\Ui\Button::addTo($app)->set('Using Message style');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn = Button::addTo($app)->set('Using Message style');
+$btn->on('click', new JsToast([
'title' => 'Awesome',
'message' => 'I got my style from the message class',
'class' => 'purple',
'className' => ['toast' => 'ui message', 'title' => 'ui header'],
]));
-$btn = \Atk4\Ui\Button::addTo($app)->set('With progress bar');
-$btn->on('click', new \Atk4\Ui\JsToast([
+$btn = Button::addTo($app)->set('With progress bar');
+$btn->on('click', new JsToast([
'title' => 'Awesome',
'message' => 'See how long I will last',
'showProgress' => 'bottom',
diff --git a/demos/interactive/virtual.php b/demos/interactive/virtual.php
index e6f0a2e581..a17d71ee5f 100644
--- a/demos/interactive/virtual.php
+++ b/demos/interactive/virtual.php
@@ -6,9 +6,11 @@
use Atk4\Ui\Button;
use Atk4\Ui\Header;
+use Atk4\Ui\JsModal;
use Atk4\Ui\LoremIpsum;
use Atk4\Ui\Message;
use Atk4\Ui\Modal;
+use Atk4\Ui\Table;
use Atk4\Ui\Text;
use Atk4\Ui\View;
use Atk4\Ui\VirtualPage;
@@ -68,19 +70,19 @@
Header::addTo($app, ['Inside Modal', 'subHeader' => 'Virtual page content can be display using JsModal Class.']);
$bar = View::addTo($app, ['ui' => 'buttons']);
-Button::addTo($bar)->set('Load in Modal')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut')));
+Button::addTo($bar)->set('Load in Modal')->on('click', new JsModal('My Popup Title', $virtualPage->getJsUrl('cut')));
-Button::addTo($bar)->set('Simulate slow load')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut') . '&slow=true'));
+Button::addTo($bar)->set('Simulate slow load')->on('click', new JsModal('My Popup Title', $virtualPage->getJsUrl('cut') . '&slow=true'));
if (isset($_GET['slow'])) {
sleep(1);
}
-Button::addTo($bar)->set('No title')->on('click', new \Atk4\Ui\JsModal(null, $virtualPage->getJsUrl('cut')));
+Button::addTo($bar)->set('No title')->on('click', new JsModal(null, $virtualPage->getJsUrl('cut')));
View::addTo($app, ['ui' => 'hidden divider']);
$text = Text::addTo($app);
$text->addParagraph('Can also be trigger from a js event, like clicking on a table row.');
-$table = \Atk4\Ui\Table::addTo($app, ['class.celled' => true]);
+$table = Table::addTo($app, ['class.celled' => true]);
$table->setModel(new SomeData());
$frame = VirtualPage::addTo($app);
@@ -88,4 +90,4 @@
Header::addTo($frame, ['Clicked row with ID = ' . ($_GET['id'] ?? '')]);
});
-$table->onRowClick(new \Atk4\Ui\JsModal('Row Clicked', $frame, ['id' => $table->jsRow()->data('id')]));
+$table->onRowClick(new JsModal('Row Clicked', $frame, ['id' => $table->jsRow()->data('id')]));
diff --git a/demos/interactive/wizard.php b/demos/interactive/wizard.php
index 063c363d3b..ec7efd3d4f 100644
--- a/demos/interactive/wizard.php
+++ b/demos/interactive/wizard.php
@@ -4,6 +4,13 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Columns;
+use Atk4\Ui\Console;
+use Atk4\Ui\Form;
+use Atk4\Ui\Grid;
+use Atk4\Ui\Header;
+use Atk4\Ui\Message;
+use Atk4\Ui\Table;
use Atk4\Ui\Wizard;
/** @var \Atk4\Ui\App $app */
@@ -13,7 +20,7 @@
// First step will automatcally be active when you open page first. It
// will contain the 'Next' button with a link.
$wizard->addStep('Welcome', function (Wizard $wizard) {
- \Atk4\Ui\Message::addTo($wizard, ['Welcome to wizard demonstration'])->text
+ Message::addTo($wizard, ['Welcome to wizard demonstration'])->text
->addParagraph('Use button "Next" to advance')
->addParagraph('You can specify your existing database connection string which will be used
to create a table for model of your choice');
@@ -24,12 +31,12 @@
// to return any action from form's onSubmit callback. You may also use memorize()
// to store wizard-specific variables
$wizard->addStep(['Set DSN', 'icon' => 'configure', 'description' => 'Database Connection String'], function (Wizard $wizard) {
- $form = \Atk4\Ui\Form::addTo($wizard);
+ $form = Form::addTo($wizard);
// IMPORTANT - needed for php_unit Wizard test.
$form->cb->setUrlTrigger('w_form_submit');
$form->addControl('dsn', ['caption' => 'Connect DSN'], ['required' => true])->placeholder = 'mysql://user:pass@db-host.example.com/mydb';
- $form->onSubmit(function (\Atk4\Ui\Form $form) use ($wizard) {
+ $form->onSubmit(function (Form $form) use ($wizard) {
$wizard->memorize('dsn', $form->model->get('dsn'));
return $wizard->jsNext();
@@ -45,18 +52,18 @@
$wizard->getApp()->redirect($wizard->urlNext());
}
- $columns = \Atk4\Ui\Columns::addTo($wizard);
+ $columns = Columns::addTo($wizard);
- $grid = \Atk4\Ui\Grid::addTo($columns->addColumn(), ['paginator' => false, 'menu' => false]);
- \Atk4\Ui\Message::addTo($columns->addColumn(), ['Information', 'type' => 'info'])->text
+ $grid = Grid::addTo($columns->addColumn(), ['paginator' => false, 'menu' => false]);
+ Message::addTo($columns->addColumn(), ['Information', 'type' => 'info'])->text
->addParagraph('Selecting which model you would like to import into your DSN. If corresponding table already exist, we might add extra fields into it. No tables, columns or rows will be deleted.');
$grid->setSource(['Country', 'Stat']);
// should work after url() fix
- $grid->addDecorator('name', [\Atk4\Ui\Table\Column\Link::class, [], ['name']]);
+ $grid->addDecorator('name', [Table\Column\Link::class, [], ['name']]);
- // $t->addDecorator('name', [\Atk4\Ui\Table\Column\Link::class, [$wizard->stepCallback->name => $wizard->currentStep], ['name']]);
+ // $t->addDecorator('name', [Table\Column\Link::class, [$wizard->stepCallback->name => $wizard->currentStep], ['name']]);
$wizard->buttonNext->addClass('disabled');
});
@@ -65,7 +72,7 @@
// and enable them as you see fit. Use handy js method to trigger advancement to
// the next step.
$wizard->addStep(['Migration', 'description' => 'Create or update table', 'icon' => 'database'], function (Wizard $wizard) {
- $console = \Atk4\Ui\Console::addTo($wizard);
+ $console = Console::addTo($wizard);
$wizard->buttonFinish->addClass('disabled');
$console->set(function ($console) use ($wizard) {
@@ -89,5 +96,5 @@
// because you shouldn't be able to navigate wizard back without restarting it.
// Only one finish can be added.
$wizard->addFinish(function (Wizard $wizard) {
- \Atk4\Ui\Header::addTo($wizard, ['You are DONE', 'class.huge centered' => true]);
+ Header::addTo($wizard, ['You are DONE', 'class.huge centered' => true]);
});
diff --git a/demos/javascript/js.php b/demos/javascript/js.php
index 5da20d2f66..b750598fa0 100644
--- a/demos/javascript/js.php
+++ b/demos/javascript/js.php
@@ -7,6 +7,8 @@
use Atk4\Ui\Button;
use Atk4\Ui\Exception;
use Atk4\Ui\Header;
+use Atk4\Ui\JsExpression;
+use Atk4\Ui\Label;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
@@ -60,8 +62,8 @@
Header::addTo($app, ['Callbacks on HTML element', 'subHeader' => 'Click on label below.']);
-$label = \Atk4\Ui\Label::addTo($app->layout, ['Test']);
+$label = Label::addTo($app->layout, ['Test']);
$label->on('click', null, function ($j, $arg1) {
return 'width is ' . $arg1;
-}, [new \Atk4\Ui\JsExpression('$(window).width()')]);
+}, [new JsExpression('$(window).width()')]);
diff --git a/demos/javascript/reloading.php b/demos/javascript/reloading.php
index d63e23ebfb..c23b99b39e 100644
--- a/demos/javascript/reloading.php
+++ b/demos/javascript/reloading.php
@@ -4,30 +4,37 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsExpression;
+use Atk4\Ui\JsReload;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
// Test 1 - Basic reloading
-\Atk4\Ui\Header::addTo($app, ['Button reloading segment']);
-$v = \Atk4\Ui\View::addTo($app, ['ui' => 'segment'])->set((string) random_int(1, 100));
-\Atk4\Ui\Button::addTo($app, ['Reload random number'])->js('click', new \Atk4\Ui\JsReload($v, [], new \Atk4\Ui\JsExpression('console.log("Output with afterSuccess");')));
+Header::addTo($app, ['Button reloading segment']);
+$v = View::addTo($app, ['ui' => 'segment'])->set((string) random_int(1, 100));
+Button::addTo($app, ['Reload random number'])->js('click', new JsReload($v, [], new JsExpression('console.log("Output with afterSuccess");')));
// Test 2 - Reloading self
-\Atk4\Ui\Header::addTo($app, ['JS-actions will be re-applied']);
-$b2 = \Atk4\Ui\Button::addTo($app, ['Reload Myself']);
-$b2->js('click', new \Atk4\Ui\JsReload($b2));
+Header::addTo($app, ['JS-actions will be re-applied']);
+$b2 = Button::addTo($app, ['Reload Myself']);
+$b2->js('click', new JsReload($b2));
// Test 3 - avoid duplicate
-\Atk4\Ui\Header::addTo($app, ['No duplicate JS bindings']);
-$b3 = \Atk4\Ui\Button::addTo($app, ['Reload other button']);
-$b4 = \Atk4\Ui\Button::addTo($app, ['Add one dot']);
+Header::addTo($app, ['No duplicate JS bindings']);
+$b3 = Button::addTo($app, ['Reload other button']);
+$b4 = Button::addTo($app, ['Add one dot']);
-$b4->js('click', $b4->js()->text(new \Atk4\Ui\JsExpression('[]+"."', [$b4->js()->text()])));
-$b3->js('click', new \Atk4\Ui\JsReload($b4));
+$b4->js('click', $b4->js()->text(new JsExpression('[]+"."', [$b4->js()->text()])));
+$b3->js('click', new JsReload($b4));
// Test 3 - avoid duplicate
-\Atk4\Ui\Header::addTo($app, ['Make sure nested JS bindings are applied too']);
-$seg = \Atk4\Ui\View::addTo($app, ['ui' => 'segment']);
+Header::addTo($app, ['Make sure nested JS bindings are applied too']);
+$seg = View::addTo($app, ['ui' => 'segment']);
// add 3 counters
Counter::addTo($seg);
@@ -35,16 +42,16 @@
Counter::addTo($seg, ['-20']);
// Add button to reload all counters
-$bar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']);
-$b = \Atk4\Ui\Button::addTo($bar, ['Reload counter'])->js('click', new \Atk4\Ui\JsReload($seg));
+$bar = View::addTo($app, ['ui' => 'buttons']);
+$b = Button::addTo($bar, ['Reload counter'])->js('click', new JsReload($seg));
// Relading with argument
-\Atk4\Ui\Header::addTo($app, ['We can pass argument to reloader']);
+Header::addTo($app, ['We can pass argument to reloader']);
-$v = \Atk4\Ui\View::addTo($app, ['ui' => 'segment'])->set($_GET['val'] ?? 'No value');
+$v = View::addTo($app, ['ui' => 'segment'])->set($_GET['val'] ?? 'No value');
-\Atk4\Ui\Button::addTo($app, ['Set value to "hello"'])->js('click', new \Atk4\Ui\JsReload($v, ['val' => 'hello']));
-\Atk4\Ui\Button::addTo($app, ['Set value to "world"'])->js('click', new \Atk4\Ui\JsReload($v, ['val' => 'world']));
+Button::addTo($app, ['Set value to "hello"'])->js('click', new JsReload($v, ['val' => 'hello']));
+Button::addTo($app, ['Set value to "world"'])->js('click', new JsReload($v, ['val' => 'world']));
-$val = \Atk4\Ui\Form\Control\Line::addTo($app, ['']);
-$val->addAction('Set Custom Value')->js('click', new \Atk4\Ui\JsReload($v, ['val' => $val->jsInput()->val()], $val->jsInput()->focus()));
+$val = Form\Control\Line::addTo($app, ['']);
+$val->addAction('Set Custom Value')->js('click', new JsReload($v, ['val' => $val->jsInput()->val()], $val->jsInput()->focus()));
diff --git a/demos/javascript/vue-component.php b/demos/javascript/vue-component.php
index e7fbbe6db7..ea93e0cf02 100644
--- a/demos/javascript/vue-component.php
+++ b/demos/javascript/vue-component.php
@@ -4,13 +4,20 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
use Atk4\Ui\HtmlTemplate;
+use Atk4\Ui\Lister;
+use Atk4\Ui\Message;
+use Atk4\Ui\View;
+use Atk4\Ui\VueComponent\InlineEdit;
+use Atk4\Ui\VueComponent\ItemSearch;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Header::addTo($app, ['Component', 'size' => 2, 'icon' => 'vuejs', 'subHeader' => 'UI view handle by Vue.js']);
-\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
+Header::addTo($app, ['Component', 'size' => 2, 'icon' => 'vuejs', 'subHeader' => 'UI view handle by Vue.js']);
+View::addTo($app, ['ui' => 'divider']);
// Inline Edit
@@ -18,37 +25,37 @@
$model = $model->loadAny();
$subHeader = 'Try me. I will restore value on "Escape" or save it on "Enter" or when field get blur after it has been changed.';
-\Atk4\Ui\Header::addTo($app, ['Inline editing.', 'size' => 3, 'subHeader' => $subHeader]);
+Header::addTo($app, ['Inline editing.', 'size' => 3, 'subHeader' => $subHeader]);
-$inline_edit = \Atk4\Ui\Component\InlineEdit::addTo($app);
+$inline_edit = InlineEdit::addTo($app);
$inline_edit->fieldName = $model->fieldName()->name;
$inline_edit->setModel($model);
$inline_edit->onChange(function ($value) {
- $view = new \Atk4\Ui\Message();
+ $view = new Message();
$view->invokeInit();
$view->text->addParagraph('new value: ' . $value);
return $view;
});
-\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
+View::addTo($app, ['ui' => 'divider']);
// ITEM SEARCH
$subHeader = 'Searching will reload the list of countries below with matching result.';
-\Atk4\Ui\Header::addTo($app, ['Search using a Vue component', 'subHeader' => $subHeader]);
+Header::addTo($app, ['Search using a Vue component', 'subHeader' => $subHeader]);
$model = new Country($app->db);
$lister_template = new HtmlTemplate('
{List}
{$atk_fp_country__name}
{$end}{/}
');
-$view = \Atk4\Ui\View::addTo($app);
+$view = View::addTo($app);
-$search = \Atk4\Ui\Component\ItemSearch::addTo($view, ['ui' => 'ui compact segment']);
-$lister_container = \Atk4\Ui\View::addTo($view, ['template' => $lister_template]);
-$lister = \Atk4\Ui\Lister::addTo($lister_container, [], ['List']);
-$lister->onHook(\Atk4\Ui\Lister::HOOK_BEFORE_ROW, function (\Atk4\Ui\Lister $lister) {
+$search = ItemSearch::addTo($view, ['ui' => 'ui compact segment']);
+$lister_container = View::addTo($view, ['template' => $lister_template]);
+$lister = Lister::addTo($lister_container, [], ['List']);
+$lister->onHook(Lister::HOOK_BEFORE_ROW, function (Lister $lister) {
$row = Country::assertInstanceOf($lister->currentRow);
$row->iso = mb_strtolower($row->iso);
@@ -63,11 +70,11 @@
$model->setLimit(50);
$lister->setModel($model);
-\Atk4\Ui\View::addTo($app, ['ui' => 'divider']);
+View::addTo($app, ['ui' => 'divider']);
// CREATING CUSTOM VUE USING EXTERNAL COMPONENT
-\Atk4\Ui\Header::addTo($app, ['External Component', 'subHeader' => 'Creating component using an external component definition.']);
+Header::addTo($app, ['External Component', 'subHeader' => 'Creating component using an external component definition.']);
// same as $app->requireJs('https://unpkg.com/vue-clock2@1.1.5/dist/vue-clock.min.js');
// for Behat testing without internet access
@@ -129,7 +136,7 @@
EOF;
// Creating the clock view and injecting js.
-$clock = \Atk4\Ui\View::addTo($app, ['template' => $clock_template]);
+$clock = View::addTo($app, ['template' => $clock_template]);
$clock->template->tryDangerouslySetHtml('script', $clock_script);
// passing some style to my-clock component.
@@ -142,6 +149,6 @@
// creating vue using an external definition.
$clock->vue('my-clock', ['clock' => $clock_style], 'myClock');
-$btn = \Atk4\Ui\Button::addTo($app, ['Change Style']);
+$btn = Button::addTo($app, ['Change Style']);
$btn->on('click', $clock->jsEmitEvent($clock->name . '-clock-change-style'));
-\Atk4\Ui\View::addTo($app, ['element' => 'p', 'I am not part of the component but I can still change style using the eventBus.']);
+View::addTo($app, ['element' => 'p', 'I am not part of the component but I can still change style using the eventBus.']);
diff --git a/demos/layout/layout-panel.php b/demos/layout/layout-panel.php
index c5fc64cfa6..fcad9c36f0 100644
--- a/demos/layout/layout-panel.php
+++ b/demos/layout/layout-panel.php
@@ -4,9 +4,16 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Card;
+use Atk4\Ui\Form;
use Atk4\Ui\Header;
+use Atk4\Ui\Icon;
+use Atk4\Ui\JsReload;
+use Atk4\Ui\JsToast;
use Atk4\Ui\Message;
use Atk4\Ui\Panel\Right;
+use Atk4\Ui\Text;
use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
@@ -22,7 +29,7 @@
Header::addTo($app, ['Static', 'size' => 4, 'subHeader' => 'Panel may have static content only.']);
$panel = Right::addTo($app, ['dynamic' => []]);
Message::addTo($panel, ['This panel contains only static content.']);
-$btn = \Atk4\Ui\Button::addTo($app, ['Open Static']);
+$btn = Button::addTo($app, ['Open Static']);
$btn->on('click', $panel->jsOpen());
View::addTo($app, ['ui' => 'divider']);
@@ -32,16 +39,16 @@
$panel1 = Right::addTo($app);
Message::addTo($panel1, ['This panel will load content dynamically below according to button select on the right.']);
-$btn = \Atk4\Ui\Button::addTo($app, ['Button 1']);
+$btn = Button::addTo($app, ['Button 1']);
$btn->js(true)->data('btn', '1');
$btn->on('click', $panel1->jsOpen([], ['btn'], 'orange'));
-$btn = \Atk4\Ui\Button::addTo($app, ['Button 2']);
+$btn = Button::addTo($app, ['Button 2']);
$btn->js(true)->data('btn', '2');
$btn->on('click', $panel1->jsOpen([], ['btn'], 'orange'));
$view = View::addTo($app, ['ui' => 'segment']);
-$text = \Atk4\Ui\Text::addTo($view);
+$text = Text::addTo($view);
$text->set($_GET['txt'] ?? 'Not Complete');
$panel1->onOpen(function ($p) use ($view) {
@@ -51,14 +58,14 @@
$panelText = 'You loaded panel content using button #' . $buttonNumber;
Message::addTo($panel, ['Panel 1', 'text' => $panelText]);
- $reloadPanelButton = \Atk4\Ui\Button::addTo($panel, ['Reload Myself']);
- $reloadPanelButton->on('click', new \Atk4\Ui\JsReload($panel));
+ $reloadPanelButton = Button::addTo($panel, ['Reload Myself']);
+ $reloadPanelButton->on('click', new JsReload($panel));
View::addTo($panel, ['ui' => 'divider']);
- $panelButton = \Atk4\Ui\Button::addTo($panel, ['Complete']);
+ $panelButton = Button::addTo($panel, ['Complete']);
$panelButton->on('click', [
$p->getOwner()->jsClose(),
- new \Atk4\Ui\JsReload($view, ['txt' => 'Complete using button #' . $buttonNumber]),
+ new JsReload($view, ['txt' => 'Complete using button #' . $buttonNumber]),
]);
});
@@ -69,26 +76,26 @@
Header::addTo($app, ['Closing option', 'size' => 4, 'subHeader' => 'Panel can prevent from closing.']);
$panel2 = Right::addTo($app, ['hasClickAway' => false]);
-$icon = \Atk4\Ui\Icon::addTo($app, ['big cog'])->addStyle('cursor', 'pointer');
+$icon = Icon::addTo($app, ['big cog'])->addStyle('cursor', 'pointer');
$icon->on('click', $panel2->jsOpen());
$panel2->addConfirmation('Changes will be lost. Are you sure?');
$msg = Message::addTo($panel2, ['Prevent close.']);
-$txt = \Atk4\Ui\Text::addTo($msg);
+$txt = Text::addTo($msg);
$txt->addParagraph('This panel can only be closed via it\'s close icon at top right.');
$txt->addParagraph('Try to change dropdown value and close without saving!');
$panel2->onOpen(function ($p) {
- $form = \Atk4\Ui\Form::addTo($p);
+ $form = Form::addTo($p);
$form->addHeader('Settings');
- $form->addControl('name', [\Atk4\Ui\Form\Control\Dropdown::class, 'values' => ['1' => 'Option 1', '2' => 'Option 2']])
+ $form->addControl('name', [Form\Control\Dropdown::class, 'values' => ['1' => 'Option 1', '2' => 'Option 2']])
->set('1')
->onChange($p->getOwner()->jsDisplayWarning(true));
- $form->onSubmit(function (\Atk4\Ui\Form $form) use ($p) {
+ $form->onSubmit(function (Form $form) use ($p) {
return [
- new \Atk4\Ui\JsToast('Saved, closing panel.'),
+ new JsToast('Saved, closing panel.'),
$p->getOwner()->jsDisplayWarning(false),
$p->getOwner()->jsClose(),
];
@@ -108,7 +115,7 @@
$country->setLimit(3);
foreach ($country as $ct) {
- $c = \Atk4\Ui\Card::addTo($deck, ['useLabel' => true])->addStyle('cursor', 'pointer');
+ $c = Card::addTo($deck, ['useLabel' => true])->addStyle('cursor', 'pointer');
$c->setModel($ct);
$c->on('click', $panel3->jsOpen([], ['id'], 'orange'));
}
@@ -118,7 +125,7 @@
Header::addTo($seg, [$country->load($countryId)->getTitle()]);
$buttons = View::addTo($seg, ['ui' => 'vertical basic buttons']);
foreach ($country->getUserActions() as $action) {
- $button = \Atk4\Ui\Button::addTo($buttons, [$action->getCaption()]);
+ $button = Button::addTo($buttons, [$action->getCaption()]);
$button->on('click', $action, ['args' => ['id' => $countryId]]);
}
});
diff --git a/demos/layout/layouts.php b/demos/layout/layouts.php
index fbdbf4111c..7956f3b3e0 100644
--- a/demos/layout/layouts.php
+++ b/demos/layout/layouts.php
@@ -4,6 +4,11 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Layout;
+use Atk4\Ui\Text;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
@@ -11,24 +16,24 @@
$buttons = [
['page' => ['layouts_nolayout'], 'title' => 'HTML without layout'],
['page' => ['layouts_manual'], 'title' => 'Manual layout'],
- ['page' => ['../basic/header', 'layout' => \Atk4\Ui\Layout\Centered::class], 'title' => 'Centered layout'],
+ ['page' => ['../basic/header', 'layout' => Layout\Centered::class], 'title' => 'Centered layout'],
['page' => ['layouts_admin'], 'title' => 'Admin Layout'],
['page' => ['layouts_error'], 'title' => 'Exception Error'],
];
// layout
-\Atk4\Ui\Text::addTo(\Atk4\Ui\View::addTo($app, ['class.red' => true, 'ui' => 'segment']))
+Text::addTo(View::addTo($app, ['class.red' => true, 'ui' => 'segment']))
->addParagraph('Layouts can be used to wrap your UI elements into HTML / Boilerplate');
// toolbar
-$tb = \Atk4\Ui\View::addTo($app);
+$tb = View::addTo($app);
// iframe
-$i = \Atk4\Ui\View::addTo($app, ['class.green' => true, 'ui' => 'segment'])->setElement('iframe')->setStyle(['width' => '100%', 'height' => '500px']);
+$i = View::addTo($app, ['class.green' => true, 'ui' => 'segment'])->setElement('iframe')->setStyle(['width' => '100%', 'height' => '500px']);
// add buttons in toolbar
foreach ($buttons as $k => $args) {
- \Atk4\Ui\Button::addTo($tb)
+ Button::addTo($tb)
->set([$args['title'], 'iconRight' => 'down arrow'])
->js('click', $i->js()->attr('src', $app->url($args['page'])));
}
diff --git a/demos/layout/layouts_admin.php b/demos/layout/layouts_admin.php
index cf4c7b31c4..152dea1780 100644
--- a/demos/layout/layouts_admin.php
+++ b/demos/layout/layouts_admin.php
@@ -4,14 +4,19 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
+use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\Layout;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-$layout = \Atk4\Ui\Layout\Admin::addTo($app);
+$layout = Layout\Admin::addTo($app);
$menu = $layout->menu->addMenu(['Layouts', 'icon' => 'puzzle']);
-$menu->addItem(\Atk4\Ui\Layout\Centered::class);
-$menu->addItem(\Atk4\Ui\Layout\Admin::class);
+$menu->addItem(Layout\Centered::class);
+$menu->addItem(Layout\Admin::class);
$menuRight = $layout->menuRight;
$menuRight->addItem(['Warning', 'class.red' => true, 'icon' => 'red warning']);
@@ -34,10 +39,10 @@
$layout->template->set('Footer', 'ATK is awesome');
-\Atk4\Ui\Header::addTo($layout, ['Basic Form Example']);
+Header::addTo($layout, ['Basic Form Example']);
-$form = \Atk4\Ui\Form::addTo($layout, ['class.segment' => true]);
-$form->setModel((new \Atk4\Data\Model())->createEntity());
+$form = Form::addTo($layout, ['class.segment' => true]);
+$form->setModel((new Model())->createEntity());
$formGroup = $form->addGroup('Name');
$formGroup->addControl('first_name', ['width' => 'eight']);
@@ -48,7 +53,7 @@
$formGroup->addControl('address', ['width' => 'twelve']);
$formGroup->addControl('zip', ['width' => 'four']);
-$form->onSubmit(function (\Atk4\Ui\Form $form) {
+$form->onSubmit(function (Form $form) {
$errors = [];
foreach (['first_name', 'last_name', 'address'] as $field) {
diff --git a/demos/layout/layouts_error.php b/demos/layout/layouts_error.php
index 78dc0719f2..103d04f3bb 100644
--- a/demos/layout/layouts_error.php
+++ b/demos/layout/layouts_error.php
@@ -4,8 +4,10 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
// Next line produces exception, which Agile UI will catch and display nicely.
-\Atk4\Ui\View::addTo($app, ['foo' => 'bar']);
+View::addTo($app, ['foo' => 'bar']);
diff --git a/demos/layout/layouts_manual.php b/demos/layout/layouts_manual.php
index bfa268a043..6483312077 100644
--- a/demos/layout/layouts_manual.php
+++ b/demos/layout/layouts_manual.php
@@ -4,15 +4,19 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Layout;
+use Atk4\Ui\Lister;
+use Atk4\Ui\Text;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-$layout = new \Atk4\Ui\Layout(['defaultTemplate' => __DIR__ . '/templates/layout1.html']);
+$layout = new Layout(['defaultTemplate' => __DIR__ . '/templates/layout1.html']);
-\Atk4\Ui\Lister::addTo($layout, [], ['Report'])
+Lister::addTo($layout, [], ['Report'])
->setModel(new SomeData());
$app->html = null;
-$app->initLayout([\Atk4\Ui\Layout::class]);
+$app->initLayout([Layout::class]);
-\Atk4\Ui\Text::addTo($app->layout)->addHtml($layout->render());
+Text::addTo($app->layout)->addHtml($layout->render());
diff --git a/demos/layout/layouts_nolayout.php b/demos/layout/layouts_nolayout.php
index 9f06911344..2c65a759fe 100644
--- a/demos/layout/layouts_nolayout.php
+++ b/demos/layout/layouts_nolayout.php
@@ -4,14 +4,18 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Layout;
+use Atk4\Ui\LoremIpsum;
+use Atk4\Ui\Text;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
// nothing to do with Agile UI - will not use any Layout
-$a = new \Atk4\Ui\LoremIpsum();
+$a = new LoremIpsum();
$text = $a->generateLorem(150);
$app->html = null;
-$app->initLayout([\Atk4\Ui\Layout::class]);
+$app->initLayout([Layout::class]);
-\Atk4\Ui\Text::addTo($app->layout)->addParagraph($text);
+Text::addTo($app->layout)->addParagraph($text);
diff --git a/demos/obsolete/crud.php b/demos/obsolete/crud.php
index 59dd4f13e0..587b036433 100644
--- a/demos/obsolete/crud.php
+++ b/demos/obsolete/crud.php
@@ -4,6 +4,9 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Crud;
+use Atk4\Ui\Table;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
@@ -12,6 +15,6 @@
$model->getUserAction('edit')->system = true;
$model->getUserAction('delete')->system = true;
-$grid = \Atk4\Ui\Crud::addTo($app, ['paginator' => false]);
+$grid = Crud::addTo($app, ['paginator' => false]);
$grid->setModel($model);
-$grid->addDecorator($model->fieldName()->project_code, [\Atk4\Ui\Table\Column\Link::class]);
+$grid->addDecorator($model->fieldName()->project_code, [Table\Column\Link::class]);
diff --git a/demos/obsolete/notify.php b/demos/obsolete/notify.php
index 8d2bc819a4..d16ac30778 100644
--- a/demos/obsolete/notify.php
+++ b/demos/obsolete/notify.php
@@ -4,30 +4,35 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Form;
+use Atk4\Ui\JsNotify;
+use Atk4\Ui\Modal;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\Button::addTo($app, ['Notify Examples - Page 2', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
+Button::addTo($app, ['Notify Examples - Page 2', 'class.small right floated basic blue' => true, 'iconRight' => 'right arrow'])
->link(['notify2']);
-\Atk4\Ui\Button::addTo($app, ['Test'])->on('click', (new \Atk4\Ui\JsNotify('Not yet implemented'))->setColor('red'));
+Button::addTo($app, ['Test'])->on('click', (new JsNotify('Not yet implemented'))->setColor('red'));
-$modal = \Atk4\Ui\Modal::addTo($app, ['Modal Title']);
+$modal = Modal::addTo($app, ['Modal Title']);
$modal->set(function ($p) use ($modal) {
- $form = \Atk4\Ui\Form::addTo($p);
+ $form = Form::addTo($p);
$form->addControl('name', [], ['caption' => 'Add your name']);
- $form->onSubmit(function (\Atk4\Ui\Form $form) use ($modal) {
+ $form->onSubmit(function (Form $form) use ($modal) {
if (empty($form->model->get('name'))) {
return $form->error('name', 'Please add a name!');
}
return [
$modal->hide(),
- new \Atk4\Ui\JsNotify('Thank you ' . $form->model->get('name')),
+ new JsNotify('Thank you ' . $form->model->get('name')),
];
});
});
-\Atk4\Ui\Button::addTo($app, ['Open Modal'])->on('click', $modal->show());
+Button::addTo($app, ['Open Modal'])->on('click', $modal->show());
diff --git a/demos/obsolete/notify2.php b/demos/obsolete/notify2.php
index d9d5a64b99..e55cd2151a 100644
--- a/demos/obsolete/notify2.php
+++ b/demos/obsolete/notify2.php
@@ -4,11 +4,17 @@
namespace Atk4\Ui\Demos;
+use Atk4\Data\Model;
+use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsNotify;
+use Atk4\Ui\Label;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-/** @var \Atk4\Data\Model $notifierClass */
-$notifierClass = AnonymousClassNameCache::get_class(fn () => new class() extends \Atk4\Data\Model {
+/** @var Model $notifierClass */
+$notifierClass = AnonymousClassNameCache::get_class(fn () => new class() extends Model {
public $table = 'notifier';
protected function init(): void
@@ -26,13 +32,13 @@ protected function init(): void
});
// Notification type form
-$head = \Atk4\Ui\Header::addTo($app, ['Notification Types']);
+$head = Header::addTo($app, ['Notification Types']);
-$form = \Atk4\Ui\Form::addTo($app, ['class.segment' => true]);
+$form = Form::addTo($app, ['class.segment' => true]);
// Unit test only.
$form->cb->setUrlTrigger('test_notify');
-\Atk4\Ui\Label::addTo($form, ['Some of notification options that can be set.', 'class.top attached' => true], ['AboveControls']);
+Label::addTo($form, ['Some of notification options that can be set.', 'class.top attached' => true], ['AboveControls']);
$form->buttonSave->set('Show');
$form->setModel((new $notifierClass($app->db))->createEntity(), []);
@@ -49,8 +55,8 @@ protected function init(): void
$formGroup2->addControl('position', ['width' => 'four']);
$formGroup2->addControl('attach', ['width' => 'four']);
-$form->onSubmit(function (\Atk4\Ui\Form $form) {
- $notifier = new \Atk4\Ui\JsNotify();
+$form->onSubmit(function (Form $form) {
+ $notifier = new JsNotify();
$notifier->setColor($form->model->get('color'))
->setPosition($form->model->get('position'))
->setWidth(rtrim($form->model->get('width'), '%'))
diff --git a/demos/others/recursive.php b/demos/others/recursive.php
index 3effcc96ed..4079e32be4 100644
--- a/demos/others/recursive.php
+++ b/demos/others/recursive.php
@@ -4,41 +4,47 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
+use Atk4\Ui\Jquery;
+use Atk4\Ui\JsReload;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-/** @var \Atk4\Ui\View $mySwitcherClass */
-$mySwitcherClass = AnonymousClassNameCache::get_class(fn () => new class() extends \Atk4\Ui\View {
+/** @var View $mySwitcherClass */
+$mySwitcherClass = AnonymousClassNameCache::get_class(fn () => new class() extends View {
protected function init(): void
{
parent::init();
- \Atk4\Ui\Header::addTo($this, ['My name is ' . $this->name, 'class.red' => true]);
+ Header::addTo($this, ['My name is ' . $this->name, 'class.red' => true]);
- $buttons = \Atk4\Ui\View::addTo($this, ['ui' => 'basic buttons']);
- \Atk4\Ui\Button::addTo($buttons, ['Yellow'])->setAttr('data-id', 'yellow');
- \Atk4\Ui\Button::addTo($buttons, ['Blue'])->setAttr('data-id', 'blue');
- \Atk4\Ui\Button::addTo($buttons, ['Button'])->setAttr('data-id', 'button');
+ $buttons = View::addTo($this, ['ui' => 'basic buttons']);
+ Button::addTo($buttons, ['Yellow'])->setAttr('data-id', 'yellow');
+ Button::addTo($buttons, ['Blue'])->setAttr('data-id', 'blue');
+ Button::addTo($buttons, ['Button'])->setAttr('data-id', 'button');
- $buttons->on('click', '.button', new \Atk4\Ui\JsReload($this, [$this->name => (new \Atk4\Ui\Jquery())->data('id')]));
+ $buttons->on('click', '.button', new JsReload($this, [$this->name => (new Jquery())->data('id')]));
switch ($this->stickyGet($this->name)) {
case 'yellow':
- self::addTo(\Atk4\Ui\View::addTo($this, ['ui' => 'yellow segment']));
+ self::addTo(View::addTo($this, ['ui' => 'yellow segment']));
break;
case 'blue':
- self::addTo(\Atk4\Ui\View::addTo($this, ['ui' => 'blue segment']));
+ self::addTo(View::addTo($this, ['ui' => 'blue segment']));
break;
case 'button':
- \Atk4\Ui\Button::addTo(\Atk4\Ui\View::addTo($this, ['ui' => 'green segment']), ['Refresh page'])->link([]);
+ Button::addTo(View::addTo($this, ['ui' => 'green segment']), ['Refresh page'])->link([]);
break;
}
}
});
-$view = \Atk4\Ui\View::addTo($app, ['ui' => 'segment']);
+$view = View::addTo($app, ['ui' => 'segment']);
$mySwitcherClass::addTo($view);
diff --git a/demos/others/sticky.php b/demos/others/sticky.php
index 7c67e6ab81..1a9d00ae76 100644
--- a/demos/others/sticky.php
+++ b/demos/others/sticky.php
@@ -5,17 +5,19 @@
namespace Atk4\Ui\Demos;
use Atk4\Ui\Button;
+use Atk4\Ui\Header;
+use Atk4\Ui\View;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-\Atk4\Ui\View::addTo($app, [
+View::addTo($app, [
'Sticky GET allows us to preserve some GET arguments',
'ui' => 'ignored info message',
]);
-/** @var \Atk4\Ui\Button $myButtonClass */
-$myButtonClass = AnonymousClassNameCache::get_class(fn () => new class() extends \Atk4\Ui\Button {
+/** @var Button $myButtonClass */
+$myButtonClass = AnonymousClassNameCache::get_class(fn () => new class() extends Button {
protected function renderView(): void
{
$this->link($this->content);
@@ -32,7 +34,7 @@ protected function renderView(): void
$myButtonClass::addTo($app, [$app->url(['xx' => 'YEY', 'c' => 'OHO'])]);
// URLs presented by a blank app
-\Atk4\Ui\Header::addTo($app, ['URLs presented by a blank app']);
+Header::addTo($app, ['URLs presented by a blank app']);
Button::addTo($app, [$app->url()]);
Button::addTo($app, [$app->url(['b' => 2])]);
Button::addTo($app, [$app->url(['b' => 2, 'c' => false])]);
@@ -40,7 +42,7 @@ protected function renderView(): void
Button::addTo($app, [$app->url(['b' => 2, 'c' => 'abc'])]);
// Sticky for xx=
-\Atk4\Ui\Header::addTo($app, ['Now add sticky for xx=' . $app->stickyGet('xx')]);
+Header::addTo($app, ['Now add sticky for xx=' . $app->stickyGet('xx')]);
Button::addTo($app, [$app->url()]);
Button::addTo($app, [$app->url(['b' => 2])]);
Button::addTo($app, [$app->url(['b' => 2, 'c' => false])]);
@@ -48,7 +50,7 @@ protected function renderView(): void
Button::addTo($app, [$app->url(['b' => 2, 'c' => 'abc'])]);
// Sticky for c=
-\Atk4\Ui\Header::addTo($app, ['Now also add sticky for c=' . $app->stickyGet('c')]);
+Header::addTo($app, ['Now also add sticky for c=' . $app->stickyGet('c')]);
Button::addTo($app, [$app->url()]);
Button::addTo($app, [$app->url(['b' => 2])]);
Button::addTo($app, [$app->url(['b' => 2, 'c' => false])]);
@@ -56,7 +58,7 @@ protected function renderView(): void
Button::addTo($app, [$app->url(['b' => 2, 'c' => 'abc'])]);
// Various ways to build links
-\Atk4\Ui\Header::addTo($app, ['Various ways to build links']);
+Header::addTo($app, ['Various ways to build links']);
Button::addTo($app, [$app->url()]);
Button::addTo($app, [$app->url('other.php')]);
Button::addTo($app, [$app->url('other')]);
diff --git a/demos/others/sticky2.php b/demos/others/sticky2.php
index cb5ecdfebb..578b315bd8 100644
--- a/demos/others/sticky2.php
+++ b/demos/others/sticky2.php
@@ -4,6 +4,16 @@
namespace Atk4\Ui\Demos;
+use Atk4\Ui\Button;
+use Atk4\Ui\Console;
+use Atk4\Ui\Header;
+use Atk4\Ui\JsNotify;
+use Atk4\Ui\JsReload;
+use Atk4\Ui\Label;
+use Atk4\Ui\Loader;
+use Atk4\Ui\Table;
+use Atk4\Ui\View;
+
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
@@ -12,49 +22,49 @@
if (isset($_GET['name'])) {
// IMPORTANT: because this is an optional frame, I have to specify it's unique shortName explicitly, othrewise
// the name for a second frame will be affected by presence of GET['name'] parameter
- $frame = \Atk4\Ui\View::addTo($app, ['ui' => 'red segment', 'shortName' => 'fr1']);
+ $frame = View::addTo($app, ['ui' => 'red segment', 'shortName' => 'fr1']);
$frame->stickyGet('name');
// frame will generate URL with sticky parameter
- \Atk4\Ui\Label::addTo($frame, ['Name:', 'detail' => $_GET['name'], 'class.black' => true])->link($frame->url());
+ Label::addTo($frame, ['Name:', 'detail' => $_GET['name'], 'class.black' => true])->link($frame->url());
// app still generates URL without localized sticky
- \Atk4\Ui\Label::addTo($frame, ['Reset', 'iconRight' => 'close', 'class.black' => true])->link($app->url());
- \Atk4\Ui\View::addTo($frame, ['ui' => 'hidden divider']);
+ Label::addTo($frame, ['Reset', 'iconRight' => 'close', 'class.black' => true])->link($app->url());
+ View::addTo($frame, ['ui' => 'hidden divider']);
// nested interractive elemetns will respect lockal sticky get
- \Atk4\Ui\Button::addTo($frame, ['Triggering callback here will inherit color'])->on('click', function () {
- return new \Atk4\Ui\JsNotify('Color was = ' . $_GET['name']);
+ Button::addTo($frame, ['Triggering callback here will inherit color'])->on('click', function () {
+ return new JsNotify('Color was = ' . $_GET['name']);
});
// Next we have loader, which will dynamically load console which will dynamically output "success" message.
- \Atk4\Ui\Loader::addTo($frame)->set(function ($page) {
- \Atk4\Ui\Console::addTo($page)->set(function ($console) {
+ Loader::addTo($frame)->set(function ($page) {
+ Console::addTo($page)->set(function ($console) {
$console->output('success!, color is still ' . $_GET['name']);
});
});
}
-$t = \Atk4\Ui\Table::addTo($app);
+$t = Table::addTo($app);
$t->setSource(['Red', 'Green', 'Blue']);
-$t->addDecorator('name', [\Atk4\Ui\Table\Column\Link::class, [], ['name']]);
+$t->addDecorator('name', [Table\Column\Link::class, [], ['name']]);
-$frame = \Atk4\Ui\View::addTo($app, ['ui' => 'green segment']);
-\Atk4\Ui\Button::addTo($frame, ['does not inherit sticky get'])->on('click', function () use ($app) {
- return new \Atk4\Ui\JsNotify('$_GET = ' . $app->encodeJson($_GET));
+$frame = View::addTo($app, ['ui' => 'green segment']);
+Button::addTo($frame, ['does not inherit sticky get'])->on('click', function () use ($app) {
+ return new JsNotify('$_GET = ' . $app->encodeJson($_GET));
});
-\Atk4\Ui\Header::addTo($app, ['Use of View::url()']);
+Header::addTo($app, ['Use of View::url()']);
-$b1 = \Atk4\Ui\Button::addTo($app);
+$b1 = Button::addTo($app);
$b1->set($b1->url());
-\Atk4\Ui\Loader::addTo($app)->set(function ($page) use ($b1) {
- $b2 = \Atk4\Ui\Button::addTo($page);
+Loader::addTo($app)->set(function ($page) use ($b1) {
+ $b2 = Button::addTo($page);
$b2->set($b2->url());
- $b2->on('click', new \Atk4\Ui\JsReload($b1));
+ $b2->on('click', new JsReload($b1));
});
-$b3 = \Atk4\Ui\Button::addTo($app);
+$b3 = Button::addTo($app);
$b3->set($b3->url());
diff --git a/demos/tutorial/actions.php b/demos/tutorial/actions.php
index 0d347696fb..7ecdddaeeb 100644
--- a/demos/tutorial/actions.php
+++ b/demos/tutorial/actions.php
@@ -6,18 +6,25 @@
use Atk4\Data\Model;
use Atk4\Ui\Button;
+use Atk4\Ui\Card;
+use Atk4\Ui\Crud;
+use Atk4\Ui\Form;
+use Atk4\Ui\Header;
+use Atk4\Ui\Menu;
+use Atk4\Ui\Text;
use Atk4\Ui\UserAction\ExecutorFactory;
use Atk4\Ui\View;
+use Atk4\Ui\Wizard;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-$wizard = \Atk4\Ui\Wizard::addTo($app);
+$wizard = Wizard::addTo($app);
$wizard->addStep('Define User Action', function ($page) {
- \Atk4\Ui\Header::addTo($page, ['What are User Actions?']);
+ Header::addTo($page, ['What are User Actions?']);
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
Since the early version ATK UI was about building generic UI capable of automatically read information about
@@ -42,7 +49,7 @@
$country->addUserAction('send_message');
});
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
Once defied - actions will be visualised in the Form, Grid, Crud and CardDeck. Additionally add-ons will recognise
@@ -67,14 +74,14 @@
});
$country = $country->loadAny();
- $card = \Atk4\Ui\Card::addTo($owner);
+ $card = Card::addTo($owner);
$card->setModel($country, [$country->fieldName()->iso]);
$card->addClickAction($country->getModel()->getUserAction('send_message'));
});
});
$wizard->addStep('UI Integration', function ($page) {
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
Agile UI introduces a new set of views called "User Action Executors". Their job is to recognise all that meta-information
@@ -87,11 +94,11 @@
$country = new Country($owner->getApp()->db);
$country = $country->loadAny();
- \Atk4\Ui\Button::addTo($owner, ['Edit some country'])
+ Button::addTo($owner, ['Edit some country'])
->on('click', $country->getUserAction('edit'));
});
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
It is not only the button, but any view can have "User Action" passed as a second step of the on() call. Here the user action
@@ -103,14 +110,14 @@
$country = new Country($owner->getApp()->db);
$country = $country->loadAny();
- $menu = \Atk4\Ui\Menu::addTo($owner);
+ $menu = Menu::addTo($owner);
$menu->addItem('Hello');
$menu->addItem('World', $country->getUserAction('edit'));
});
});
$wizard->addStep('Arguments', function ($page) {
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
Next demo defines an user action that requires arguments. You can specify arguments when the user action is invoked, but if not
@@ -120,10 +127,10 @@
);
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
- $model = new \Atk4\Data\Model($owner->getApp()->db, ['table' => 'test']);
+ $model = new Model($owner->getApp()->db, ['table' => 'test']);
$model->addUserAction('greet', [
- 'appliesTo' => \Atk4\Data\Model\UserAction::APPLIES_TO_NO_RECORDS,
+ 'appliesTo' => Model\UserAction::APPLIES_TO_NO_RECORDS,
'args' => [
'name' => [
'type' => 'string',
@@ -135,7 +142,7 @@
]);
$model->addUserAction('ask_age', [
- 'appliesTo' => \Atk4\Data\Model\UserAction::APPLIES_TO_NO_RECORDS,
+ 'appliesTo' => Model\UserAction::APPLIES_TO_NO_RECORDS,
'args' => [
'age' => [
'type' => 'integer',
@@ -147,13 +154,13 @@
},
]);
- \Atk4\Ui\Form\Control\Line::addTo($owner, [
+ Form\Control\Line::addTo($owner, [
'action' => $model->getUserAction('greet'),
]);
- \Atk4\Ui\View::addTo($owner, ['ui' => 'divider']);
+ View::addTo($owner, ['ui' => 'divider']);
- \Atk4\Ui\Button::addTo($owner, ['Ask Age'])
+ Button::addTo($owner, ['Ask Age'])
->on('click', $model->getUserAction('ask_age'));
});
});
@@ -164,7 +171,7 @@
$model = new Stat($owner->getApp()->db);
$model->addUserAction('mail', [
'fields' => ['currency_field'],
- 'appliesTo' => \Atk4\Data\Model\UserAction::APPLIES_TO_SINGLE_RECORD,
+ 'appliesTo' => Model\UserAction::APPLIES_TO_SINGLE_RECORD,
'callback' => function () {
* return 'testing';
* },
@@ -180,7 +187,7 @@
*/
$wizard->addStep('Crud integration', function ($page) {
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
Compared to 1.x versions Crud implementation has became much more lightweight, however you retain all the same
@@ -196,7 +203,7 @@ functionality and more. Next example shows how you can disable user action (add)
return $m->id % 2 === 0;
};
$country->addUserAction('mail', [
- 'appliesTo' => \Atk4\Data\Model\UserAction::APPLIES_TO_SINGLE_RECORD,
+ 'appliesTo' => Model\UserAction::APPLIES_TO_SINGLE_RECORD,
'preview' => function (Model $model) {
return 'here is email preview for ' . $model->get('name');
},
@@ -212,13 +219,13 @@ functionality and more. Next example shows how you can disable user action (add)
[Button::class, null, 'icon' => 'blue mail'],
$country->getUserAction('mail')
);
- \Atk4\Ui\Crud::addTo($owner, ['ipp' => 5])
+ Crud::addTo($owner, ['ipp' => 5])
->setModel($country, [$country->fieldName()->name, $country->fieldName()->iso]);
});
});
$wizard->addFinish(function ($page) use ($wizard) {
PromotionText::addTo($page);
- \Atk4\Ui\Button::addTo($wizard, ['Exit demo', 'class.primary' => true, 'icon' => 'left arrow'], ['Left'])
+ Button::addTo($wizard, ['Exit demo', 'class.primary' => true, 'icon' => 'left arrow'], ['Left'])
->link('/demos/index.php');
});
diff --git a/demos/tutorial/intro.php b/demos/tutorial/intro.php
index a57815b264..b68820b38b 100644
--- a/demos/tutorial/intro.php
+++ b/demos/tutorial/intro.php
@@ -6,19 +6,24 @@
use Atk4\Data\Model;
use Atk4\Data\Persistence;
+use Atk4\Ui\Button;
+use Atk4\Ui\Card;
use Atk4\Ui\Form;
use Atk4\Ui\Header;
use Atk4\Ui\JsToast;
use Atk4\Ui\Message;
+use Atk4\Ui\Paginator;
+use Atk4\Ui\Text;
use Atk4\Ui\View;
+use Atk4\Ui\Wizard;
/** @var \Atk4\Ui\App $app */
require_once __DIR__ . '/../init-app.php';
-$wizard = \Atk4\Ui\Wizard::addTo($app);
+$wizard = Wizard::addTo($app);
$wizard->addStep('User Interface', function ($page) {
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
Agile Toolkit is a "Low Code Framework" written in PHP. It is designed to simplify all aspects of web application creation:
@@ -60,12 +65,12 @@
$t->addParagraph('It all has started with a "Button" though:');
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
- \Atk4\Ui\Button::addTo($owner, ['Hello from the button!']);
+ Button::addTo($owner, ['Hello from the button!']);
});
});
$wizard->addStep('Interactivity', function ($page) {
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
PHP is a server-side language. That prompted us to implement server-side UI actions. They are very easy to define -
@@ -74,13 +79,13 @@
);
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
- $button = \Atk4\Ui\Button::addTo($owner, ['Click for the greeting!']);
+ $button = Button::addTo($owner, ['Click for the greeting!']);
$button->on('click', function () {
return 'Hello World!';
});
});
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
A component of Agile Toolkit (callback) enables seamless communication between the frontend components (which are often
@@ -89,24 +94,24 @@
);
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
- $seg = \Atk4\Ui\View::addTo($owner, ['ui' => 'segment']);
+ $seg = View::addTo($owner, ['ui' => 'segment']);
- \Atk4\Ui\Text::addTo($seg)->set('Number of buttons: ');
+ Text::addTo($seg)->set('Number of buttons: ');
- $paginator = \Atk4\Ui\Paginator::addTo($seg, [
+ $paginator = Paginator::addTo($seg, [
'total' => 5,
'reload' => $seg,
'urlTrigger' => 'count',
]);
- \Atk4\Ui\View::addTo($seg, ['ui' => 'divider']);
+ View::addTo($seg, ['ui' => 'divider']);
for ($i = 1; $i <= ($_GET['count'] ?? 1); ++$i) {
- \Atk4\Ui\Button::addTo($seg, [$i]);
+ Button::addTo($seg, [$i]);
}
});
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
This demo also shows you how to create composite views. The '$seg' above contains text, paginator, divider and some
@@ -116,7 +121,7 @@
});
$wizard->addStep('Business Model', function ($page) {
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
One major benefit of Server Side Rendered applications is ability to directly interact with data. In other applications
@@ -126,7 +131,7 @@
Demo::addTo($page)->setCodeAndCall(function (View $owner) {
/* Showing Class definition.
- class DemoInvoice extends \Atk4\Data\Model
+ class DemoInvoice extends Model
{
public ?string $titleField = 'reference';
@@ -142,12 +147,12 @@ protected function init(): void
session_start();
$model = new DemoInvoice(new Persistence\Array_($_SESSION['atk4_ui_intro_demo'] ?? []), ['dateFormat' => $owner->getApp()->uiPersistence->dateFormat]);
- $model->onHook(\Atk4\Data\Model::HOOK_AFTER_SAVE, function (Model $model) {
+ $model->onHook(Model::HOOK_AFTER_SAVE, function (Model $model) {
$_SESSION['atk4_ui_intro_demo'][$model->getId()] = (clone $model->getModel())->addCondition($model->idField, $model->getId())->export(null, null, false)[$model->getId()];
});
Header::addTo($owner, ['Set invoice data:']);
- $form = \Atk4\Ui\Form::addTo($owner);
+ $form = Form::addTo($owner);
$entity = $model->tryLoad(1);
if ($entity === null) {
@@ -168,10 +173,10 @@ protected function init(): void
return new JsToast('Saved!');
});
- \Atk4\Ui\View::addTo($owner, ['ui' => 'divider']);
+ View::addTo($owner, ['ui' => 'divider']);
});
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
This code shows you a combination of 3 objects:
@@ -194,7 +199,7 @@ protected function init(): void
});
$wizard->addStep('Persistence', function ($page) {
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
Once your model is defined, it can be re-used later with any generic view:
@@ -205,21 +210,21 @@ protected function init(): void
session_start();
$model = new DemoInvoice(new Persistence\Array_($_SESSION['atk4_ui_intro_demo'] ?? []), ['dateFormat' => $owner->getApp()->uiPersistence->dateFormat]);
- $model->onHook(\Atk4\Data\Model::HOOK_AFTER_SAVE, function (Model $model) {
+ $model->onHook(Model::HOOK_AFTER_SAVE, function (Model $model) {
$_SESSION['atk4_ui_intro_demo'][$model->getId()] = (clone $model->getModel())->addCondition($model->idField, $model->getId())->export(null, null, false)[$model->getId()];
});
Header::addTo($owner, ['Record display in Card View using model data.']);
$model = $model->tryLoad(1);
if ($model !== null) {
- \Atk4\Ui\Card::addTo($owner, ['useLabel' => true])
+ Card::addTo($owner, ['useLabel' => true])
->setModel($model);
} else {
Message::addTo($owner, ['Empty record.']);
}
});
- $t = \Atk4\Ui\Text::addTo($page);
+ $t = Text::addTo($page);
$t->addParagraph(
<<< 'EOF'
Re-use of your Business Model code, generic and interactive views and principles of composition and a simple PHP
@@ -230,6 +235,6 @@ protected function init(): void
$wizard->addFinish(function ($page) use ($wizard) {
PromotionText::addTo($page);
- \Atk4\Ui\Button::addTo($wizard, ['Exit demo', 'class.primary' => true, 'icon' => 'left arrow'], ['Left'])
+ Button::addTo($wizard, ['Exit demo', 'class.primary' => true, 'icon' => 'left arrow'], ['Left'])
->link('../');
});
diff --git a/docs/dataexecutor.rst b/docs/dataexecutor.rst
index 1a33f2c9be..9b5e5a13cf 100644
--- a/docs/dataexecutor.rst
+++ b/docs/dataexecutor.rst
@@ -102,18 +102,15 @@ return specific record information to be display to user prior to execute the ac
Here is an example of an user action returning specific record information in the confirmation message::
- $country->addUserAction(
- 'delete_country',
- [
- 'caption' => 'Delete',
- 'description' => 'Delete Country',
- 'ui' => ['executor' => [\Atk4\Ui\UserAction\ConfirmationExecutor::class]],
- 'confirmation' => function ($action) {
- return 'Are you sure you want to delete this country: $action->getModel()->getTitle();
- },
- 'callback' => 'delete',
- ]
- );
+ $country->addUserAction('delete_country', [
+ 'caption' => 'Delete',
+ 'description' => 'Delete Country',
+ 'ui' => ['executor' => [\Atk4\Ui\UserAction\ConfirmationExecutor::class]],
+ 'confirmation' => function ($action) {
+ return 'Are you sure you want to delete this country: $action->getModel()->getTitle();
+ },
+ 'callback' => 'delete',
+ ]);
The modal title default is set from the UserAction::getDescription() method but can be override using the
Modal::$title property.
diff --git a/docs/form.rst b/docs/form.rst
index 4cffc00413..51f4b9ff87 100644
--- a/docs/form.rst
+++ b/docs/form.rst
@@ -516,10 +516,7 @@ We can now populate form controls based around the data fields defined in the mo
This should display a following form::
- $form->addControl(
- 'terms',
- ['type' => 'boolean', 'ui' => ['caption' => 'Accept Terms and Conditions']]
- );
+ $form->addControl('terms', ['type' => 'boolean', 'ui' => ['caption' => 'Accept Terms and Conditions']]);
Form Submit Handling
--------------------
diff --git a/docs/view.rst b/docs/view.rst
index 12adc6120c..f41a9b3beb 100644
--- a/docs/view.rst
+++ b/docs/view.rst
@@ -151,7 +151,7 @@ Models::
$db = new \Atk4\Data\Persistence\Sql($dsn);
- $client = new Client($db); // extends \Atk4\Data\Model();
+ $client = new Client($db); // extends \Atk4\Data\Model
Once you have a model, you can associate it with a View such as Form or Grid
so that those Views would be able to interact with your persistence directly::
diff --git a/js/.eslintrc.js b/js/.eslintrc.js
index cb2b77f36a..4ada3c406d 100644
--- a/js/.eslintrc.js
+++ b/js/.eslintrc.js
@@ -21,7 +21,7 @@ module.exports = {
flatpickr: true,
},
rules: {
- indent: ['error', 4],
+ indent: ['error', 4, { SwitchCase: 1 }],
'object-shorthand': ['error', 'never'],
'func-names': ['error', 'never'],
'no-param-reassign': 'off',
@@ -30,6 +30,7 @@ module.exports = {
'no-plusplus': 'off',
'consistent-return': 'off',
'no-nested-ternary': 'off',
+ 'default-case': 'off',
'import/prefer-default-export': 'off',
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-underscore-dangle': ['error', { allow: ['__atkml', '__atkml_action', '__atk_reload'] }],
diff --git a/js/src/components/multiline/multiline-header.component.js b/js/src/components/multiline/multiline-header.component.js
index 3fb1246b52..dc0d733042 100644
--- a/js/src/components/multiline/multiline-header.component.js
+++ b/js/src/components/multiline/multiline-header.component.js
@@ -32,13 +32,12 @@ export default {
let align = 'left';
if (!column.isEditable) {
switch (column.type) {
- case 'money':
- case 'integer':
- case 'number':
- align = 'right';
+ case 'money':
+ case 'integer':
+ case 'number':
+ align = 'right';
- break;
- default:
+ break;
}
}
diff --git a/js/src/components/multiline/multiline.component.js b/js/src/components/multiline/multiline.component.js
index eecfe0fd56..ca87fa5150 100644
--- a/js/src/components/multiline/multiline.component.js
+++ b/js/src/components/multiline/multiline.component.js
@@ -159,14 +159,14 @@ export default {
}
},
/**
- * Update Multi-line Form input with all rowData values
- * as json string.
- */
+ * Update Multi-line Form input with all rowData values
+ * as json string.
+ */
updateInputValue: function () {
this.value = JSON.stringify(this.rowData);
},
/**
- * Build rowData from json string.
+ * Build rowData from json string.
*/
buildRowData: function (jsonValue) {
const rows = atk.utils.json().tryParse(jsonValue, []);
diff --git a/js/src/components/query-builder/fomantic-ui-rule.component.vue b/js/src/components/query-builder/fomantic-ui-rule.component.vue
index a0026454fd..226e758880 100644
--- a/js/src/components/query-builder/fomantic-ui-rule.component.vue
+++ b/js/src/components/query-builder/fomantic-ui-rule.component.vue
@@ -128,11 +128,11 @@ export default {
}
switch (type) {
- case 'input': return this.isInput;
- case 'checkbox': return this.isCheckbox;
- case 'select': return this.isSelect;
- case 'custom-component': return this.isComponent;
- default: return false;
+ case 'input': return this.isInput;
+ case 'checkbox': return this.isCheckbox;
+ case 'select': return this.isSelect;
+ case 'custom-component': return this.isComponent;
+ default: return false;
}
},
onChange: function (value) {
diff --git a/js/src/components/share/atk-lookup.js b/js/src/components/share/atk-lookup.js
index 6e29935ac6..6e70631a54 100644
--- a/js/src/components/share/atk-lookup.js
+++ b/js/src/components/share/atk-lookup.js
@@ -54,8 +54,8 @@ export default {
this.$emit('onChange', value);
},
/**
- * Receive user input text for search.
- */
+ * Receive user input text for search.
+ */
onFiltered: function (inputValue) {
if (inputValue) {
this.isLoading = true;
@@ -71,8 +71,8 @@ export default {
}, 300).call(this);
},
/**
- * Fetch new data from server.
- */
+ * Fetch new data from server.
+ */
fetchItems: async function (q) {
try {
const data = { atk_vlookup_q: q, atk_vlookup_field: this.field };
diff --git a/js/src/components/tree-item-selector/tree-item-selector.component.js b/js/src/components/tree-item-selector/tree-item-selector.component.js
index d2c0bd688b..30cfc31e14 100644
--- a/js/src/components/tree-item-selector/tree-item-selector.component.js
+++ b/js/src/components/tree-item-selector/tree-item-selector.component.js
@@ -76,8 +76,8 @@ export default {
return this.values.filter((val) => val === id).length > 0;
},
/**
- * Get input initial data.
- */
+ * Get input initial data.
+ */
getInitData: function () {
// check if input containing data is set and initialized.
if (!this.getRootData().item.isInitialized) {
@@ -97,11 +97,11 @@ export default {
return values;
},
/**
- * Check if all children nodes are on.
- *
- * @param nodes
- * @returns {boolean}
- */
+ * Check if all children nodes are on.
+ *
+ * @param nodes
+ * @returns {boolean}
+ */
hasAllFill: function (nodes) {
let state = true;
for (let i = 0; i < nodes.length; i++) {
@@ -122,11 +122,11 @@ export default {
return state;
},
/**
- * Check if some children nodes are on.
- *
- * @param nodes
- * @returns {boolean}
- */
+ * Check if some children nodes are on.
+ *
+ * @param nodes
+ * @returns {boolean}
+ */
hasSomeFill: function (nodes) {
let state = false;
for (let i = 0; i < nodes.length; i++) {
@@ -148,37 +148,36 @@ export default {
return state;
},
/**
- * Fire when arrow are click in order to show or hide children.
- */
+ * Fire when arrow are click in order to show or hide children.
+ */
onToggleShow: function () {
if (this.isParent) {
this.open = !this.open;
}
},
/**
- * Fire when checkbox is click.
- *
- */
+ * Fire when checkbox is click.
+ *
+ */
onToggleSelect: function () {
const { options } = this.getRootData();
switch (options.mode) {
- case 'single':
- this.handleSingleSelect();
+ case 'single':
+ this.handleSingleSelect();
- break;
- case 'multiple':
- this.handleMultipleSelect();
+ break;
+ case 'multiple':
+ this.handleMultipleSelect();
- break;
- default:
+ break;
}
},
/**
- * Merge array and remove duplicate.
- *
- * @param arrays
- * @returns {*[]}
- */
+ * Merge array and remove duplicate.
+ *
+ * @param arrays
+ * @returns {*[]}
+ */
mergeArrays: function (...arrays) {
let jointArray = [];
@@ -189,12 +188,12 @@ export default {
return [...new Set([...jointArray])];
},
/**
- * Get all id from all chidren node.
- *
- * @param nodes
- * @param ids
- * @returns {Array}
- */
+ * Get all id from all chidren node.
+ *
+ * @param nodes
+ * @param ids
+ * @returns {Array}
+ */
collectAllChildren: function (nodes, ids = []) {
nodes.forEach((node) => {
if (node.nodes && node.nodes.length > 0) {
@@ -210,8 +209,8 @@ export default {
return values.filter((val) => val !== value);
},
/**
- * Handle a selection when in single mode.
- */
+ * Handle a selection when in single mode.
+ */
handleSingleSelect: function () {
if (this.state === 'off' && !this.isParent) {
this.getRootData().values = [this.item.id];
@@ -225,8 +224,8 @@ export default {
}
},
/**
- * Handle a selection when in multiple mode.
- */
+ * Handle a selection when in multiple mode.
+ */
handleMultipleSelect: function () {
let values;
if (this.isParent) {
@@ -256,25 +255,25 @@ export default {
}
},
/**
- * Set input field with current mapped model value.
- *
- * @param data
- */
+ * Set input field with current mapped model value.
+ *
+ * @param data
+ */
setInput: function (value) {
// console.log('set input');
this.getInputElement().value = value;
},
/**
- * Get input element set for this Item Selector.
- *
- * @returns {HTMLElement}
- */
+ * Get input element set for this Item Selector.
+ *
+ * @returns {HTMLElement}
+ */
getInputElement: function () {
return document.getElementsByName(this.getRootData().field)[0];
},
/**
- * Send data using callback url.
- */
+ * Send data using callback url.
+ */
postValue: function () {
jQuery(this.$el).parents('.' + this.getRootData().options.loader).api({
on: 'now',
diff --git a/js/src/helpers/url.helper.js b/js/src/helpers/url.helper.js
index f9be5e4d7b..54458bd801 100644
--- a/js/src/helpers/url.helper.js
+++ b/js/src/helpers/url.helper.js
@@ -1,5 +1,5 @@
/**
- * Url helper jQuery functions.
+ * Url helper jQuery functions.
*
* - AddParams - Pass an url with an object and object key=value pair will be
* added to the url as get parameter.
diff --git a/js/src/plugins/file-upload.plugin.js b/js/src/plugins/file-upload.plugin.js
index 2efcdf41dd..5ab3df5945 100644
--- a/js/src/plugins/file-upload.plugin.js
+++ b/js/src/plugins/file-upload.plugin.js
@@ -96,23 +96,22 @@ export default class fileUpload extends atkPlugin {
*/
setState(mode) {
switch (mode) {
- case 'delete':
- this.action.html(this.getEraseContent);
- setTimeout(() => {
- this.bar.progress('reset');
- this.bar.hide('fade');
- }, 1000);
-
- break;
- case 'upload':
- this.action.html(this.actionContent);
- this.textInput.val('');
- this.fileInput.val('');
- this.hiddenInput.val('');
- this.$el.data().fileId = null;
-
- break;
- default:
+ case 'delete':
+ this.action.html(this.getEraseContent);
+ setTimeout(() => {
+ this.bar.progress('reset');
+ this.bar.hide('fade');
+ }, 1000);
+
+ break;
+ case 'upload':
+ this.action.html(this.actionContent);
+ this.textInput.val('');
+ this.fileInput.val('');
+ this.hiddenInput.val('');
+ this.$el.data().fileId = null;
+
+ break;
}
}
diff --git a/js/src/plugins/js-sortable.plugin.js b/js/src/plugins/js-sortable.plugin.js
index 9c92787132..9d7af3b891 100644
--- a/js/src/plugins/js-sortable.plugin.js
+++ b/js/src/plugins/js-sortable.plugin.js
@@ -16,7 +16,7 @@ import 'draggable';
*
* Defaut container is set to table boddy (tbody), using table row(tr) as reoderable element.
* To use other container, simply set container and draggable accordingly.
- * $sortable = \Atk4\Ui\JsSortable::addTo($lister, ['container' => 'ul', 'draggable' => 'li', 'dataLabel' => 'name']);
+ * $sortable = JsSortable::addTo($lister, ['container' => 'ul', 'draggable' => 'li', 'dataLabel' => 'name']);
*
* Element containing specific css class can be used as the handle for dragging element, if null
* is pass, than the entire element is used.
diff --git a/js/src/services/upload.service.js b/js/src/services/upload.service.js
index cb02273c7a..d63ed7a9ca 100644
--- a/js/src/services/upload.service.js
+++ b/js/src/services/upload.service.js
@@ -18,10 +18,10 @@ class UploadService {
}
/**
- * Will upload a FileList object to server.
- * Each file in FileList will be include in formData as
- * 'file-(number)' param, except for the first one which will
- * be set to 'file' only.
+ * Will upload a FileList object to server.
+ * Each file in FileList will be include in formData as
+ * 'file-(number)' param, except for the first one which will
+ * be set to 'file' only.
*
* @param files A FileList object.
* @param el the jQuery element to attach to semantic api.
diff --git a/js/src/services/vue.service.js b/js/src/services/vue.service.js
index 2b55ec9a2f..a2c8e4197d 100644
--- a/js/src/services/vue.service.js
+++ b/js/src/services/vue.service.js
@@ -119,8 +119,8 @@ class VueService {
}
/*
- * Add component to vues container.
- * Group ids that are using the same component.
+ * Add component to vues container.
+ * Group ids that are using the same component.
*/
registerComponent(component) {
// check if that component is already registered
@@ -153,8 +153,8 @@ class VueService {
}
/*
- * Mark a component as loaded.
- */
+ * Mark a component as loaded.
+ */
markComponentLoaded(name) {
this.vues.forEach((component) => {
if (component.name === name) {
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
index 8358f8a48e..b99762ed4b 100644
--- a/phpstan.neon.dist
+++ b/phpstan.neon.dist
@@ -281,12 +281,6 @@ parameters:
# TODO these rules are generated, this ignores should be fixed in the code
# for level = 3
- -
- path: 'demos/form/form2.php'
- message: '~^Parameter #1 \$intent \(string\) of method class@anonymous/demos/form/form2\.php:\d+::validate\(\) should be contravariant with parameter \$intent \(string\|null\) of method Atk4\\Data\\Model::validate\(\)$~'
- -
- path: 'demos/init-db.php'
- message: '~^Parameter #1 \$intent \(string\) of method Atk4\\Ui\\Demos\\Country::validate\(\) should be contravariant with parameter \$intent \(string\|null\) of method Atk4\\Data\\Model::validate\(\)$~'
-
path: 'demos/interactive/popup.php'
message: '~^Property Atk4\\Ui\\Label::\$detail \(string\|false\|null\) does not accept int<0, max>\.$~'
@@ -331,7 +325,7 @@ parameters:
message: '~^Property Atk4\\Ui\\CardDeck::\$menu \(array\|false\|null\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/CardDeck.php'
- message: '~^Property Atk4\\Ui\\CardDeck::\$search \(array\|Atk4\\Ui\\Component\\ItemSearch\|false\) does not accept Atk4\\Ui\\AbstractView\.$~'
+ message: '~^Property Atk4\\Ui\\CardDeck::\$search \(array\|Atk4\\Ui\\VueComponent\\ItemSearch\|false\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/CardDeck.php'
message: '~^Property Atk4\\Ui\\CardDeck::\$paginator \(Atk4\\Ui\\Paginator\|false\|null\) does not accept Atk4\\Ui\\AbstractView\.$~'
@@ -602,9 +596,6 @@ parameters:
-
path: 'demos/form-control/multiline.php'
message: '~^Property class@anonymous/demos/form\-control/multiline\.php:\d+::\$countryPersistence has no type specified\.$~'
- -
- path: 'demos/init-db.php'
- message: '~^Method Atk4\\Ui\\Demos\\ModelWithPrefixedFields::addField\(\) has parameter \$name with no type specified\.$~'
-
path: 'demos/init-db.php'
message: '~^Property Atk4\\Ui\\Demos\\Stat::\$title has no type specified\.$~'
@@ -1427,9 +1418,6 @@ parameters:
-
path: 'src/UserAction/BasicExecutor.php'
message: '~^Method Atk4\\Ui\\UserAction\\BasicExecutor::setArguments\(\) has no return type specified\.$~'
- -
- path: 'src/UserAction/BasicExecutor.php'
- message: '~^Method Atk4\\Ui\\UserAction\\BasicExecutor::hasAllArguments\(\) has no return type specified\.$~'
-
path: 'src/UserAction/BasicExecutor.php'
message: '~^Method Atk4\\Ui\\UserAction\\BasicExecutor::initPreview\(\) has no return type specified\.$~'
@@ -1523,12 +1511,6 @@ parameters:
-
path: 'src/Wizard.php'
message: '~^Method Atk4\\Ui\\Wizard::addFinish\(\) has no return type specified\.$~'
- -
- path: 'tests/PaginatorTest.php'
- message: '~^Property Atk4\\Ui\\Tests\\PaginatorTest::\$p has no type specified\.$~'
- -
- path: 'tests/PaginatorTest.php'
- message: '~^Method Atk4\\Ui\\Tests\\PaginatorTest::addDataProvider\(\) has no return type specified\.$~'
-
path: 'tests/PaginatorTest.php'
message: '~^Method Atk4\\Ui\\Tests\\PaginatorTest::testPaginator\(\) has parameter \$expected with no type specified\.$~'
diff --git a/src/App.php b/src/App.php
index 979d011671..2d2f935b6d 100644
--- a/src/App.php
+++ b/src/App.php
@@ -7,6 +7,7 @@
use Atk4\Core\AppScopeTrait;
use Atk4\Core\DiContainerTrait;
use Atk4\Core\DynamicMethodTrait;
+use Atk4\Core\ExceptionRenderer;
use Atk4\Core\Factory;
use Atk4\Core\HookTrait;
use Atk4\Core\InitializerTrait;
@@ -642,8 +643,8 @@ protected function createRequestPathFromLocalPath(string $localPath): string
if (\PHP_SAPI === 'cli') { // for phpunit
$requestUrlPath = '/';
$requestLocalPath = \Closure::bind(function () {
- return dirname((new \Atk4\Core\ExceptionRenderer\Html(new \Exception()))->getVendorDirectory());
- }, null, \Atk4\Core\ExceptionRenderer\Html::class)();
+ return dirname((new ExceptionRenderer\Html(new \Exception()))->getVendorDirectory());
+ }, null, ExceptionRenderer\Html::class)();
} else {
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$requestUrlPath = $request->getBasePath();
@@ -999,15 +1000,15 @@ public function encodeJson($data, bool $forceObject = false): string
* Return exception message using HTML block and Semantic UI formatting. It's your job
* to put it inside boilerplate HTML and output, e.g:.
*
- * $app = new \Atk4\Ui\App();
- * $app->initLayout([\Atk4\Ui\Layout\Centered::class]);
+ * $app = new App();
+ * $app->initLayout([Layout\Centered::class]);
* $app->layout->template->dangerouslySetHtml('Content', $e->getHtml());
* $app->run();
* $app->callBeforeExit();
*/
public function renderExceptionHtml(\Throwable $exception): string
{
- return (string) new \Atk4\Core\ExceptionRenderer\Html($exception);
+ return (string) new ExceptionRenderer\Html($exception);
}
protected function setupAlwaysRun(): void
diff --git a/src/CardDeck.php b/src/CardDeck.php
index c79dc746f1..03f18896a4 100644
--- a/src/CardDeck.php
+++ b/src/CardDeck.php
@@ -9,9 +9,9 @@
use Atk4\Core\Factory;
use Atk4\Data\Model;
-use Atk4\Ui\Component\ItemSearch;
use Atk4\Ui\UserAction\ExecutorFactory;
use Atk4\Ui\UserAction\ExecutorInterface;
+use Atk4\Ui\VueComponent\ItemSearch;
class CardDeck extends View
{
diff --git a/src/Columns.php b/src/Columns.php
index a5564b4510..305a2c0905 100644
--- a/src/Columns.php
+++ b/src/Columns.php
@@ -25,8 +25,10 @@ class Columns extends View
protected $calculatedWidth = 0;
/** @var array Allows Grid to calculate widths automatically. */
- public $sizes = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',
- 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', ];
+ public $sizes = [
+ '', 'one', 'two', 'three', 'four', 'five', 'six', 'seven',
+ 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen',
+ ];
/**
* Add new vertical column.
@@ -42,7 +44,7 @@ public function addColumn($defaults = null)
$size = $defaults[0] ?? null;
unset($defaults[0]);
- $column = Factory::factory([\Atk4\Ui\View::class], $defaults);
+ $column = Factory::factory([View::class], $defaults);
$this->add($column);
if ($size && isset($this->sizes[$size])) {
diff --git a/src/Exception.php b/src/Exception.php
index d9c73a911e..abc26e903d 100644
--- a/src/Exception.php
+++ b/src/Exception.php
@@ -4,6 +4,8 @@
namespace Atk4\Ui;
-class Exception extends \Atk4\Core\Exception
+use Atk4\Core\Exception as CoreException;
+
+class Exception extends CoreException
{
}
diff --git a/src/Form.php b/src/Form.php
index a642d16c29..ecb10a6def 100644
--- a/src/Form.php
+++ b/src/Form.php
@@ -9,6 +9,7 @@
use Atk4\Data\Model;
use Atk4\Data\Model\EntityFieldPair;
use Atk4\Data\Reference\ContainsMany;
+use Atk4\Data\ValidationException;
use Atk4\Ui\Form\Control;
/**
@@ -61,7 +62,7 @@ class Form extends View
*/
public $formElement;
- /** @var \Atk4\Ui\Form\Layout A current layout of a form, needed if you call Form->addControl(). */
+ /** @var Form\Layout A current layout of a form, needed if you call Form->addControl(). */
public $layout;
/** @var array
List of form controls currently registered with this form. */
@@ -260,7 +261,7 @@ public function onSubmit(\Closure $callback)
}
return $response;
- } catch (\Atk4\Data\ValidationException $e) {
+ } catch (ValidationException $e) {
$response = [];
foreach ($e->errors as $field => $error) {
$response[] = $this->error($field, $error);
@@ -518,7 +519,7 @@ protected function loadPost()
}
if (count($errors) > 0) {
- throw new \Atk4\Data\ValidationException($errors);
+ throw new ValidationException($errors);
}
}
diff --git a/src/Form/AbstractLayout.php b/src/Form/AbstractLayout.php
index beffc50aa5..6d5cbcee83 100644
--- a/src/Form/AbstractLayout.php
+++ b/src/Form/AbstractLayout.php
@@ -7,16 +7,19 @@
use Atk4\Core\WarnDynamicPropertyTrait;
use Atk4\Data\Field;
use Atk4\Data\Model;
+use Atk4\Ui\Button;
use Atk4\Ui\Exception;
+use Atk4\Ui\Form;
+use Atk4\Ui\View;
/**
* Custom Layout for a form (user-defined HTML).
*/
-abstract class AbstractLayout extends \Atk4\Ui\View
+abstract class AbstractLayout extends View
{
use WarnDynamicPropertyTrait;
- /** @var \Atk4\Ui\Form Links layout to the form. */
+ /** @var Form Links layout to the form. */
public $form;
/**
@@ -132,9 +135,9 @@ public function getControl(string $name): Control
/**
* Adds Button into form layout.
*
- * @param \Atk4\Ui\Button|array|string $seed
+ * @param Button|array|string $seed
*
- * @return \Atk4\Ui\Button
+ * @return Button
*/
abstract public function addButton($seed);
}
diff --git a/src/Form/Control.php b/src/Form/Control.php
index cebd40ea9c..4f761d5ad2 100644
--- a/src/Form/Control.php
+++ b/src/Form/Control.php
@@ -9,6 +9,8 @@
use Atk4\Data\Model\EntityFieldPair;
use Atk4\Ui\Exception;
use Atk4\Ui\Form;
+use Atk4\Ui\Jquery;
+use Atk4\Ui\JsExpression;
use Atk4\Ui\JsExpressionable;
use Atk4\Ui\View;
@@ -53,7 +55,7 @@ class Control extends View
* Placed as a pointing label below the field. This only works when Form\Control appears in a form. You can also
* set this to object, such as \Atk4\Ui\Text otherwise HTML characters are escaped.
*
- * @var string|\Atk4\Ui\View|array
+ * @var string|View|array
*/
public $hint;
@@ -140,16 +142,16 @@ protected function renderTemplateToHtml(string $region = null): string
*
* Examples:
* $control->onChange('console.log("changed")');
- * $control->onChange(new \Atk4\Ui\JsExpression('console.log("changed")'));
+ * $control->onChange(new JsExpression('console.log("changed")'));
* $control->onChange('$(this).parents(".form").form("submit")');
*
- * @param string|\Atk4\Ui\JsExpression|array|\Closure $expr
- * @param array|bool $default
+ * @param string|JsExpression|array|\Closure $expr
+ * @param array|bool $default
*/
public function onChange($expr, $default = []): void
{
if (is_string($expr)) {
- $expr = new \Atk4\Ui\JsExpression($expr);
+ $expr = new JsExpression($expr);
}
if (is_bool($default)) {
@@ -168,7 +170,7 @@ public function onChange($expr, $default = []): void
*
* @param JsExpressionable $action
*
- * @return \Atk4\Ui\Jquery
+ * @return Jquery
*/
public function jsInput($when = null, $action = null)
{
diff --git a/src/Form/Control/Calendar.php b/src/Form/Control/Calendar.php
index b574368deb..9f26be8931 100644
--- a/src/Form/Control/Calendar.php
+++ b/src/Form/Control/Calendar.php
@@ -6,6 +6,7 @@
use Atk4\Ui\Jquery;
use Atk4\Ui\JsExpression;
+use Atk4\Ui\JsFunction;
/**
* Date/Time picker attached to a form control.
@@ -72,7 +73,7 @@ protected function renderView(): void
*
* Examples:
* $control->onChange('console.log(date, text, mode)');
- * $control->onChange(new \Atk4\Ui\JsExpression('console.log(date, text, mode)'));
+ * $control->onChange(new JsExpression('console.log(date, text, mode)'));
* $control->onChange('$(this).parents(".form").form("submit")');
*
* Note: Unlike Control::onChange() method, flatpickr onChange options does not use $default settings.
@@ -83,14 +84,14 @@ protected function renderView(): void
public function onChange($expr, $default = []): void
{
if (is_string($expr)) {
- $expr = new \Atk4\Ui\JsExpression($expr);
+ $expr = new JsExpression($expr);
}
if (!is_array($expr)) {
$expr = [$expr];
}
// flatpickr on change event
- $this->options['onChange'] = new \Atk4\Ui\JsFunction(['date', 'text', 'mode'], $expr);
+ $this->options['onChange'] = new JsFunction(['date', 'text', 'mode'], $expr);
}
/**
diff --git a/src/Form/Control/DropdownCascade.php b/src/Form/Control/DropdownCascade.php
index 4ac5934442..47156d84e4 100644
--- a/src/Form/Control/DropdownCascade.php
+++ b/src/Form/Control/DropdownCascade.php
@@ -94,8 +94,8 @@ public function getNewValues($id): array
}
/**
- * Will mark current value as selected from a list
- * of possible values.
+ * Will mark current value as selected from a list
+ * of possible values.
*
* @param string|int $value the current field value
*/
diff --git a/src/Form/Control/Lookup.php b/src/Form/Control/Lookup.php
index a6bc3b3119..4201847c98 100644
--- a/src/Form/Control/Lookup.php
+++ b/src/Form/Control/Lookup.php
@@ -8,22 +8,26 @@
use Atk4\Core\HookTrait;
use Atk4\Data\Model;
use Atk4\Ui\App;
+use Atk4\Ui\Button;
+use Atk4\Ui\Callback;
use Atk4\Ui\Exception;
+use Atk4\Ui\Form;
use Atk4\Ui\Jquery;
use Atk4\Ui\JsExpression;
use Atk4\Ui\JsFunction;
+use Atk4\Ui\JsModal;
+use Atk4\Ui\VirtualPage;
class Lookup extends Input
{
use HookTrait;
public $defaultTemplate = 'form/control/lookup.html';
- public $ui = 'input';
/** @var array Declare this property so Lookup is consistent as decorator to replace Form\Control\Dropdown. */
public $values = [];
- /** @var \Atk4\Ui\Callback Object used to capture requests from the browser. */
+ /** @var Callback Object used to capture requests from the browser. */
public $callback;
/** @var string Set this to true, to permit "empty" selection. If you set it to string, it will be used as a placeholder for empty value. */
@@ -87,7 +91,7 @@ class Lookup extends Input
*
* For example, using this setting will automatically submit
* form when field value is changes.
- * $form->addControl('field', [\Atk4\Ui\Form\Control\Lookup::class, 'settings' => ['allowReselection' => true,
+ * $form->addControl('field', [Form\Control\Lookup::class, 'settings' => ['allowReselection' => true,
* 'selectOnKeydown' => false,
* 'onChange' => new Atk4\Ui\JsExpression('function(value, t, c) {
* if ($(this).data("value") !== value) {
@@ -131,7 +135,7 @@ protected function init(): void
$this->settings['forceSelection'] = false;
- $this->callback = \Atk4\Ui\Callback::addTo($this);
+ $this->callback = Callback::addTo($this);
$this->getApp()->onHook(App::HOOK_BEFORE_RENDER, function () {
$this->callback->set(\Closure::fromCallable([$this, 'outputApiResponse']));
@@ -239,24 +243,20 @@ protected function initQuickNewRecord()
$buttonSeed = ['content' => $buttonSeed];
}
- $defaultSeed = [\Atk4\Ui\Button::class, 'class.disabled' => ($this->disabled || $this->readOnly)];
+ $defaultSeed = [Button::class, 'class.disabled' => ($this->disabled || $this->readOnly)];
$this->action = Factory::factory(array_merge($defaultSeed, $buttonSeed));
- if ($this->form) {
- $vp = \Atk4\Ui\VirtualPage::addTo($this->form);
- } else {
- $vp = \Atk4\Ui\VirtualPage::addTo($this->getOwner());
- }
+ $vp = VirtualPage::addTo($this->form ?? $this->getOwner());
$vp->set(function ($page) {
- $form = \Atk4\Ui\Form::addTo($page);
+ $form = Form::addTo($page);
$entity = (clone $this->model)->setOnlyFields($this->plus['fields'] ?? null)->createEntity();
$form->setModel($entity);
- $form->onSubmit(function (\Atk4\Ui\Form $form) {
+ $form->onSubmit(function (Form $form) {
$form->model->save();
$ret = [
@@ -276,7 +276,7 @@ protected function initQuickNewRecord()
$caption = $this->plus['caption'] ?? 'Add New ' . $this->model->getModelCaption();
- $this->action->js('click', new \Atk4\Ui\JsModal($caption, $vp));
+ $this->action->js('click', new JsModal($caption, $vp));
}
/**
diff --git a/src/Form/Control/Multiline.php b/src/Form/Control/Multiline.php
index 32b95019ea..9ed403de34 100644
--- a/src/Form/Control/Multiline.php
+++ b/src/Form/Control/Multiline.php
@@ -4,6 +4,7 @@
namespace Atk4\Ui\Form\Control;
+use Atk4\Core\Exception as CoreException;
use Atk4\Data\Field;
use Atk4\Data\Field\CallbackField;
use Atk4\Data\Field\SqlExpressionField;
@@ -33,7 +34,7 @@
* // Save Form model and then Multiline model
* $form->model->save(); // Saving Invoice record.
* $ml->saveRows(); // Saving invoice items record related to invoice.
- * return new \Atk4\Ui\JsToast('Saved!');
+ * return new JsToast('Saved!');
* });
*
* If Multiline's model contains expressions, these will be evaluated on the fly
@@ -323,7 +324,7 @@ public function validate(array $rows): array
if (!$field->readOnly) {
$entity->set($fieldName, $value);
}
- } catch (\Atk4\Core\Exception $e) {
+ } catch (CoreException $e) {
$rowErrors[$rowId][] = ['name' => $fieldName, 'msg' => $e->getMessage()];
}
}
@@ -669,26 +670,23 @@ protected function renderView(): void
$inputValue = $this->getValue();
$this->valuePropsBinding($inputValue);
- $this->multiLine->vue(
- 'atk-multiline',
- [
- 'data' => [
- 'formName' => $this->form->formElement->name,
- 'inputValue' => $inputValue,
- 'inputName' => $this->shortName,
- 'fields' => $this->fieldDefs,
- 'url' => $this->renderCallback->getJsUrl(),
- 'eventFields' => $this->eventFields,
- 'hasChangeCb' => $this->onChangeFunction ? true : false,
- 'tableProps' => $this->tableProps,
- 'rowLimit' => $this->rowLimit,
- 'caption' => $this->caption,
- 'afterAdd' => $this->jsAfterAdd,
- 'afterDelete' => $this->jsAfterDelete,
- 'addOnTab' => $this->addOnTab,
- ],
- ]
- );
+ $this->multiLine->vue('atk-multiline', [
+ 'data' => [
+ 'formName' => $this->form->formElement->name,
+ 'inputValue' => $inputValue,
+ 'inputName' => $this->shortName,
+ 'fields' => $this->fieldDefs,
+ 'url' => $this->renderCallback->getJsUrl(),
+ 'eventFields' => $this->eventFields,
+ 'hasChangeCb' => $this->onChangeFunction ? true : false,
+ 'tableProps' => $this->tableProps,
+ 'rowLimit' => $this->rowLimit,
+ 'caption' => $this->caption,
+ 'afterAdd' => $this->jsAfterAdd,
+ 'afterDelete' => $this->jsAfterDelete,
+ 'addOnTab' => $this->addOnTab,
+ ],
+ ]);
}
/**
@@ -864,7 +862,7 @@ private function getValueForExpression(Field $exprField, string $fieldName, Mode
case 'integer':
case 'float':
case 'atk4_money':
- // Value is 0 or the field value.
+ // value is 0 or the field value.
$value = (string) $model->get($fieldName) ?: 0;
break;
diff --git a/src/Form/Control/Radio.php b/src/Form/Control/Radio.php
index 99d46df5d5..b0ccccb467 100644
--- a/src/Form/Control/Radio.php
+++ b/src/Form/Control/Radio.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Form\Control;
use Atk4\Ui\Form;
+use Atk4\Ui\JsExpression;
use Atk4\Ui\Lister;
/**
@@ -66,16 +67,16 @@ protected function renderView(): void
*
* Examples:
* $control->onChange('console.log("changed")');
- * $control->onChange(new \Atk4\Ui\JsExpression('console.log("changed")'));
+ * $control->onChange(new JsExpression('console.log("changed")'));
* $control->onChange('$(this).parents(".form").form("submit")');
*
- * @param string|\Atk4\Ui\JsExpression|array|\Closure $expr
- * @param array|bool $default
+ * @param string|JsExpression|array|\Closure $expr
+ * @param array|bool $default
*/
public function onChange($expr, $default = []): void
{
if (is_string($expr)) {
- $expr = new \Atk4\Ui\JsExpression($expr);
+ $expr = new JsExpression($expr);
}
if (is_bool($default)) {
diff --git a/src/Form/Control/ScopeBuilder.php b/src/Form/Control/ScopeBuilder.php
index c07453e004..c6d4d27b32 100644
--- a/src/Form/Control/ScopeBuilder.php
+++ b/src/Form/Control/ScopeBuilder.php
@@ -12,6 +12,7 @@
use Atk4\Ui\Form;
use Atk4\Ui\Form\Control;
use Atk4\Ui\HtmlTemplate;
+use Atk4\Ui\View;
class ScopeBuilder extends Control
{
@@ -67,7 +68,7 @@ class ScopeBuilder extends Control
'ui' => 'small basic button',
];
- /** @var \Atk4\Ui\View The scopebuilder View. Assigned in init(). */
+ /** @var View The scopebuilder View. Assigned in init(). */
protected $scopeBuilderView;
/** @var array Definition of VueQueryBuilder rules. */
@@ -289,10 +290,10 @@ protected function init(): void
$this->scopeBuilderTemplate = new HtmlTemplate('');
}
- $this->scopeBuilderView = \Atk4\Ui\View::addTo($this, ['template' => $this->scopeBuilderTemplate]);
+ $this->scopeBuilderView = View::addTo($this, ['template' => $this->scopeBuilderTemplate]);
if ($this->form) {
- $this->form->onHook(\Atk4\Ui\Form::HOOK_LOAD_POST, function (Form $form, &$postRawData) {
+ $this->form->onHook(Form::HOOK_LOAD_POST, function (Form $form, &$postRawData) {
$key = $this->entityField->getFieldName();
$postRawData[$key] = $this->queryToScope($this->getApp()->decodeJson($postRawData[$key] ?? '{}'));
});
@@ -517,20 +518,17 @@ protected function renderView(): void
{
parent::renderView();
- $this->scopeBuilderView->vue(
- 'atk-query-builder',
- [
- 'data' => [
- 'rules' => $this->rules,
- 'maxDepth' => $this->maxDepth,
- 'query' => $this->query,
- 'name' => $this->shortName,
- 'labels' => $this->labels ?: null,
- 'form' => $this->form->formElement->name,
- 'debug' => $this->options['debug'] ?? false,
- ],
- ]
- );
+ $this->scopeBuilderView->vue('atk-query-builder', [
+ 'data' => [
+ 'rules' => $this->rules,
+ 'maxDepth' => $this->maxDepth,
+ 'query' => $this->query,
+ 'name' => $this->shortName,
+ 'labels' => $this->labels ?: null,
+ 'form' => $this->form->formElement->name,
+ 'debug' => $this->options['debug'] ?? false,
+ ],
+ ]);
}
/**
@@ -553,8 +551,6 @@ public static function queryToScope(array $query): Scope\AbstractScope
break;
default:
$scope = Scope::createAnd();
-
- break;
}
return $scope;
@@ -594,8 +590,6 @@ public static function queryToCondition(array $query): Scope\Condition
case self::OPERATOR_NOT_IN:
$value = explode(self::detectDelimiter($value), (string) $value);
- break;
- default:
break;
}
diff --git a/src/Form/Control/TreeItemSelector.php b/src/Form/Control/TreeItemSelector.php
index 781d80dad0..333a7e6bb6 100644
--- a/src/Form/Control/TreeItemSelector.php
+++ b/src/Form/Control/TreeItemSelector.php
@@ -19,13 +19,14 @@
use Atk4\Ui\Form;
use Atk4\Ui\HtmlTemplate;
use Atk4\Ui\JsCallback;
+use Atk4\Ui\View;
class TreeItemSelector extends Form\Control
{
/** @var HtmlTemplate|null Template for the item selector view. */
public $itemSelectorTemplate;
- /** @var \Atk4\Ui\View|null The tree item selector View. */
+ /** @var View|null The tree item selector View. */
public $itemSelector;
/**
@@ -77,7 +78,7 @@ protected function init(): void
$this->itemSelectorTemplate = new HtmlTemplate('');
}
- $this->itemSelector = \Atk4\Ui\View::addTo($this, ['template' => $this->itemSelectorTemplate]);
+ $this->itemSelector = View::addTo($this, ['template' => $this->itemSelectorTemplate]);
}
/**
@@ -135,18 +136,15 @@ protected function renderView(): void
$this->itemSelector->template->tryDangerouslySetHtml('Input', $this->getInput());
- $this->itemSelector->vue(
- 'atk-tree-item-selector',
- [
- 'item' => ['id' => 'atk-root', 'nodes' => $this->treeItems],
- 'values' => [], // need empty for Vue reactivity.
- 'field' => $this->shortName,
- 'options' => [
- 'mode' => $this->allowMultiple ? 'multiple' : 'single',
- 'url' => $this->cb ? $this->cb->getJsUrl() : null,
- 'loader' => $this->loaderCssName,
- ],
- ]
- );
+ $this->itemSelector->vue('atk-tree-item-selector', [
+ 'item' => ['id' => 'atk-root', 'nodes' => $this->treeItems],
+ 'values' => [], // need empty for Vue reactivity.
+ 'field' => $this->shortName,
+ 'options' => [
+ 'mode' => $this->allowMultiple ? 'multiple' : 'single',
+ 'url' => $this->cb ? $this->cb->getJsUrl() : null,
+ 'loader' => $this->loaderCssName,
+ ],
+ ]);
}
}
diff --git a/src/Form/Control/Upload.php b/src/Form/Control/Upload.php
index e7377fa1e2..819156d207 100644
--- a/src/Form/Control/Upload.php
+++ b/src/Form/Control/Upload.php
@@ -4,7 +4,9 @@
namespace Atk4\Ui\Form\Control;
+use Atk4\Ui\Button;
use Atk4\Ui\Exception;
+use Atk4\Ui\JsCallback;
use Atk4\Ui\JsExpressionable;
use Atk4\Ui\View;
@@ -31,7 +33,7 @@ class Upload extends Input
/** @var string The input default template. */
public $defaultTemplate = 'form/control/upload.html';
- /** @var \Atk4\Ui\JsCallback Callback is use for onUpload or onDelete. */
+ /** @var JsCallback Callback is use for onUpload or onDelete. */
public $cb;
/**
@@ -64,12 +66,10 @@ protected function init(): void
{
parent::init();
- // $this->inputType = 'hidden';
-
- $this->cb = \Atk4\Ui\JsCallback::addTo($this);
+ $this->cb = JsCallback::addTo($this);
if (!$this->action) {
- $this->action = new \Atk4\Ui\Button(['icon' => 'upload', 'class.disabled' => ($this->disabled || $this->readOnly)]);
+ $this->action = new Button(['icon' => 'upload', 'class.disabled' => ($this->disabled || $this->readOnly)]);
}
}
diff --git a/src/Form/Layout.php b/src/Form/Layout.php
index 5780474263..775e50afb8 100644
--- a/src/Form/Layout.php
+++ b/src/Form/Layout.php
@@ -6,8 +6,11 @@
use Atk4\Core\Factory;
use Atk4\Data\Field;
+use Atk4\Ui\Button;
+use Atk4\Ui\Header;
use Atk4\Ui\HtmlTemplate;
use Atk4\Ui\Label;
+use Atk4\Ui\View;
/**
* Provides generic layout for a form.
@@ -56,13 +59,13 @@ protected function init(): void
/**
* Adds Button.
*
- * @param \Atk4\Ui\Button|array|string $seed
+ * @param Button|array|string $seed
*
- * @return \Atk4\Ui\Button
+ * @return Button
*/
public function addButton($seed)
{
- return $this->add(Factory::mergeSeeds([\Atk4\Ui\Button::class], $seed), 'Buttons');
+ return $this->add(Factory::mergeSeeds([Button::class], $seed), 'Buttons');
}
/**
@@ -74,7 +77,7 @@ public function addButton($seed)
*/
public function addHeader($label)
{
- \Atk4\Ui\Header::addTo($this, [$label, 'class.dividing' => true, 'element' => 'h4']);
+ Header::addTo($this, [$label, 'class.dividing' => true, 'element' => 'h4']);
return $this;
}
@@ -113,12 +116,12 @@ public function addGroup($label = null)
public function addSubLayout($seed = [self::class], $addDivider = true)
{
$v = $this->add(Factory::factory($seed, ['form' => $this->form]));
- if ($v instanceof \Atk4\Ui\Form\Layout\Section) {
+ if ($v instanceof Layout\Section) {
$v = $v->addSection();
}
if ($addDivider) {
- \Atk4\Ui\View::addTo($this, ['ui' => 'hidden divider']);
+ View::addTo($this, ['ui' => 'hidden divider']);
}
return $v;
@@ -138,7 +141,7 @@ protected function recursiveRender(): void
foreach ($this->elements as $element) {
// Buttons go under Button section
- if ($element instanceof \Atk4\Ui\Button) {
+ if ($element instanceof Button) {
$this->template->dangerouslyAppendHtml('Buttons', $element->getHtml());
continue;
diff --git a/src/Form/Layout/Columns.php b/src/Form/Layout/Columns.php
index 44ad722b23..f879985af3 100644
--- a/src/Form/Layout/Columns.php
+++ b/src/Form/Layout/Columns.php
@@ -5,7 +5,9 @@
namespace Atk4\Ui\Form\Layout;
use Atk4\Data\Model;
+use Atk4\Ui\Columns as UiColumns;
use Atk4\Ui\Form;
+use Atk4\Ui\View;
/**
* Layout that automatically arranges itself into multiple columns.
@@ -59,7 +61,7 @@ public function setModel(Model $model, array $fields = null): void
$this->form->addClass($size);
}
- $c = \Atk4\Ui\Columns::addTo($this);
+ $c = UiColumns::addTo($this);
$chunks = array_chunk($fields, (int) ceil($cnt / $col));
foreach ($chunks as $chunk) {
@@ -68,6 +70,6 @@ public function setModel(Model $model, array $fields = null): void
->setModel($model, $chunk);
}
- \Atk4\Ui\View::addTo($this, ['ui' => 'clearing hidden divider']);
+ View::addTo($this, ['ui' => 'clearing hidden divider']);
}
}
diff --git a/src/Form/Layout/Custom.php b/src/Form/Layout/Custom.php
index 21eb8a29ed..f1e900a800 100644
--- a/src/Form/Layout/Custom.php
+++ b/src/Form/Layout/Custom.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Form\Layout;
use Atk4\Core\Factory;
+use Atk4\Ui\Button;
use Atk4\Ui\Exception;
use Atk4\Ui\Form\AbstractLayout;
@@ -28,12 +29,12 @@ protected function init(): void
/**
* Adds Button into {$Buttons}.
*
- * @param \Atk4\Ui\Button|array|string $seed
+ * @param Button|array|string $seed
*
- * @return \Atk4\Ui\Button
+ * @return Button
*/
public function addButton($seed)
{
- return $this->add(Factory::mergeSeeds([\Atk4\Ui\Button::class], $seed), 'Buttons');
+ return $this->add(Factory::mergeSeeds([Button::class], $seed), 'Buttons');
}
}
diff --git a/src/Form/Layout/Section.php b/src/Form/Layout/Section.php
index c834f56cad..4c41c92c01 100644
--- a/src/Form/Layout/Section.php
+++ b/src/Form/Layout/Section.php
@@ -4,18 +4,21 @@
namespace Atk4\Ui\Form\Layout;
+use Atk4\Ui\Form;
+use Atk4\Ui\View;
+
/**
* Form generic layout section.
*/
-class Section extends \Atk4\Ui\View
+class Section extends View
{
- public $formLayout = \Atk4\Ui\Form\Layout::class;
+ public $formLayout = Form\Layout::class;
public $form;
/**
* Adds sub-layout in existing layout.
*
- * @return \Atk4\Ui\Form\Layout
+ * @return Form\Layout
*/
public function addSection()
{
diff --git a/src/Form/Layout/Section/Accordion.php b/src/Form/Layout/Section/Accordion.php
index 1867a61f3a..e77a2ea5ba 100644
--- a/src/Form/Layout/Section/Accordion.php
+++ b/src/Form/Layout/Section/Accordion.php
@@ -4,15 +4,16 @@
namespace Atk4\Ui\Form\Layout\Section;
+use Atk4\Ui\Accordion as UiAccordion;
use Atk4\Ui\AccordionSection;
use Atk4\Ui\Form;
/**
* Represents form controls in accordion.
*/
-class Accordion extends \Atk4\Ui\Accordion
+class Accordion extends UiAccordion
{
- public $formLayout = \Atk4\Ui\Form\Layout::class;
+ public $formLayout = Form\Layout::class;
public $form;
/**
@@ -22,7 +23,7 @@ protected function init(): void
{
parent::init();
- $this->form->onHook(\Atk4\Ui\Form::HOOK_DISPLAY_ERROR, function (Form $form, $fieldName, $str) {
+ $this->form->onHook(Form::HOOK_DISPLAY_ERROR, function (Form $form, $fieldName, $str) {
// default behavior
$jsError = [$form->js()->form('add prompt', $fieldName, $str)];
@@ -42,7 +43,7 @@ protected function init(): void
* @param string $title
* @param string $icon
*
- * @return \Atk4\Ui\Form\Layout
+ * @return Form\Layout
*/
public function addSection($title, \Closure $callback = null, $icon = 'dropdown')
{
@@ -60,7 +61,7 @@ public function addSection($title, \Closure $callback = null, $icon = 'dropdown'
*/
public function getSectionIdx($section)
{
- if ($section instanceof \Atk4\Ui\AccordionSection) {
+ if ($section instanceof AccordionSection) {
return parent::getSectionIdx($section);
}
diff --git a/src/Form/Layout/Section/Columns.php b/src/Form/Layout/Section/Columns.php
index afba661526..1837679441 100644
--- a/src/Form/Layout/Section/Columns.php
+++ b/src/Form/Layout/Section/Columns.php
@@ -4,12 +4,15 @@
namespace Atk4\Ui\Form\Layout\Section;
+use Atk4\Ui\Columns as UiColumns;
+use Atk4\Ui\Form;
+
/**
* Represents form controls in columns.
*/
-class Columns extends \Atk4\Ui\Columns
+class Columns extends UiColumns
{
- public $formLayout = \Atk4\Ui\Form\Layout::class;
+ public $formLayout = Form\Layout::class;
public $form;
/**
@@ -17,7 +20,7 @@ class Columns extends \Atk4\Ui\Columns
*
* @param int|array $defaults specify width (1..16) or relative to $width
*
- * @return \Atk4\Ui\Form\Layout
+ * @return Form\Layout
*/
public function addColumn($defaults = null)
{
diff --git a/src/Form/Layout/Section/Tabs.php b/src/Form/Layout/Section/Tabs.php
index e15aedeead..24f21318c1 100644
--- a/src/Form/Layout/Section/Tabs.php
+++ b/src/Form/Layout/Section/Tabs.php
@@ -4,22 +4,26 @@
namespace Atk4\Ui\Form\Layout\Section;
+use Atk4\Ui\Form;
+use Atk4\Ui\Tab;
+use Atk4\Ui\Tabs as UiTabs;
+
/**
* Represents form controls in tabs.
*/
-class Tabs extends \Atk4\Ui\Tabs
+class Tabs extends UiTabs
{
- public $formLayout = \Atk4\Ui\Form\Layout::class;
+ public $formLayout = Form\Layout::class;
public $form;
/**
* Adds tab in tabs widget.
*
- * @param string|\Atk4\Ui\Tab $name Name of tab or Tab object
- * @param \Closure $callback Callback action or URL (or array with url + parameters)
- * @param array $settings tab settings
+ * @param string|Tab $name Name of tab or Tab object
+ * @param \Closure $callback Callback action or URL (or array with url + parameters)
+ * @param array $settings tab settings
*
- * @return \Atk4\Ui\Form\Layout
+ * @return Form\Layout
*/
public function addTab($name, \Closure $callback = null, $settings = [])
{
diff --git a/src/Grid.php b/src/Grid.php
index 9ec75d6e61..ec9d34119d 100644
--- a/src/Grid.php
+++ b/src/Grid.php
@@ -349,7 +349,7 @@ public function addQuickSearch($fields = [], $hasAutoQuery = false)
* @param JsExpression|null $afterSuccess
* @param array $apiConfig
*
- * @return \Atk4\Ui\JsReload
+ * @return JsReload
*/
public function jsReload($args = [], $afterSuccess = null, $apiConfig = [])
{
@@ -463,7 +463,7 @@ public function addFilterColumn($names = null)
if (!$this->menu) {
throw new Exception('Unable to add Filter Column without Menu');
}
- $this->menu->addItem(['Clear Filters'], new \Atk4\Ui\JsReload($this->table->reload, ['atk_clear_filter' => 1]));
+ $this->menu->addItem(['Clear Filters'], new JsReload($this->table->reload, ['atk_clear_filter' => 1]));
$this->table->setFilterColumn($names);
return $this;
diff --git a/src/Layout/Centered.php b/src/Layout/Centered.php
index 5e8fa31efe..8367bc3a25 100644
--- a/src/Layout/Centered.php
+++ b/src/Layout/Centered.php
@@ -19,7 +19,7 @@ class Centered extends Layout
public $defaultTemplate = 'layout/centered.html';
- /** @var string|null @see \Atk4\Ui\App::$cdn */
+ /** @var string|null @see App::$cdn */
public $image;
/** @var string */
public $imageAlt = 'Logo';
diff --git a/src/Lister.php b/src/Lister.php
index cdf2e23285..bee91cee7c 100644
--- a/src/Lister.php
+++ b/src/Lister.php
@@ -4,11 +4,12 @@
namespace Atk4\Ui;
+use Atk4\Core\HookTrait;
use Atk4\Data\Model;
class Lister extends View
{
- use \Atk4\Core\HookTrait;
+ use HookTrait;
/** @const string */
public const HOOK_BEFORE_ROW = self::class . '@beforeRow';
diff --git a/src/Misc/ProxyModel.php b/src/Misc/ProxyModel.php
index 711a02e429..ccbad67535 100644
--- a/src/Misc/ProxyModel.php
+++ b/src/Misc/ProxyModel.php
@@ -4,6 +4,8 @@
namespace Atk4\Ui\Misc;
-class ProxyModel extends \Atk4\Data\Model
+use Atk4\Data\Model;
+
+class ProxyModel extends Model
{
}
diff --git a/src/Modal.php b/src/Modal.php
index eba71069dd..dfdc52f362 100644
--- a/src/Modal.php
+++ b/src/Modal.php
@@ -20,8 +20,8 @@
*
* Modal can use semantic-ui predefine method onApprove or onDeny by passing
* a jsAction to Modal::addDenyAction or Modal::addApproveAction method. It will not close until the jsAction return true.
- * $modal->addDenyAction('No', new \Atk4\Ui\JsExpression('function() { window.alert("Can\'t do that."); return false; }'));
- * $modal->addApproveAction('Yes', new \Atk4\Ui\JsExpression('function() { window.alert("You\'re good to go!"); }'));
+ * $modal->addDenyAction('No', new JsExpression('function() { window.alert("Can\'t do that."); return false; }'));
+ * $modal->addApproveAction('Yes', new JsExpression('function() { window.alert("You\'re good to go!"); }'));
*
* You may also prevent modal from closing via the esc or dimmed area click using $modal->notClosable().
*
diff --git a/src/Panel/Content.php b/src/Panel/Content.php
index 1801a7494e..4b7dc38bac 100644
--- a/src/Panel/Content.php
+++ b/src/Panel/Content.php
@@ -1,15 +1,15 @@
totalsPlan as $key => $val) {
// if value is array, then we treat it as built-in or closure aggregate method
if (is_array($val)) {
- $f = $val[0]; // shortcut
+ $f = $val[0];
// initial value is always 0
if (!isset($this->totals[$key])) {
@@ -581,9 +581,9 @@ public function updateTotals()
}
// closure support
- // arguments - current value, key, \Atk4\Ui\Table object
+ // arguments - current value, key, Table object
if ($f instanceof \Closure) {
- $this->totals[$key] += ($f($this->model->get($key), $key, $this) ?: 0);
+ $this->totals[$key] += ($f($this->model->get($key), $key, $this) ?? 0);
} elseif (is_string($f)) { // built-in methods
switch ($f) {
case 'sum':
diff --git a/src/Table/Column.php b/src/Table/Column.php
index 9d3fdc4764..e51a98125d 100644
--- a/src/Table/Column.php
+++ b/src/Table/Column.php
@@ -7,13 +7,15 @@
use Atk4\Data\Field;
use Atk4\Data\Model;
use Atk4\Ui\Jquery;
+use Atk4\Ui\JsCallback;
use Atk4\Ui\JsExpression;
use Atk4\Ui\Popup;
+use Atk4\Ui\Table;
/**
* Implements Column helper for table.
*
- * @method \Atk4\Ui\Table getOwner()
+ * @method Table getOwner()
*/
class Column
{
@@ -28,7 +30,7 @@ class Column
/** @const string */
public const HOOK_GET_HEADER_CELL_HTML = self::class . '@getHeaderCellHtml';
- /** @var \Atk4\Ui\Table Link back to the table, where column is used. */
+ /** @var Table Link back to the table, where column is used. */
public $table;
/** @var array Contains any custom attributes that may be applied on head, body or foot. */
@@ -144,20 +146,18 @@ public function addDropdown(array $items, \Closure $fx, $icon = 'caret square do
* This method return a callback where you can detect
* menu item change via $cb->onMenuItem($item) function.
*
- * @return \Atk4\Ui\JsCallback
+ * @return JsCallback
*/
public function setHeaderDropdown($items, string $icon = 'caret square down', string $menuId = null)
{
$this->hasHeaderAction = true;
$id = $this->name . '_ac';
- $this->headerActionTag = ['div', ['class' => 'atk-table-dropdown'],
+ $this->headerActionTag = ['div', ['class' => 'atk-table-dropdown'], [
[
- [
- 'div', ['id' => $id, 'class' => 'ui top left pointing dropdown', 'data-menu-id' => $menuId],
- [['i', ['class' => $icon . ' icon'], '']],
- ],
+ 'div', ['id' => $id, 'class' => 'ui top left pointing dropdown', 'data-menu-id' => $menuId],
+ [['i', ['class' => $icon . ' icon'], '']],
],
- ];
+ ]];
$cb = Column\JsHeader::addTo($this->table);
@@ -260,7 +260,6 @@ public function getTag(string $position, $value, $attr = []): string
* Provided with a field definition (from a model) will return a header
* cell, fully formatted to be included in a Table. ().
*
- * @param Field $field
* @param mixed $value
*
* @return string
@@ -336,8 +335,6 @@ public function getTotalsCellHtml(Field $field, $value)
*
* This method will be executed only once per table rendering, if you need to format data manually,
* you should use $this->table->onHook('beforeRow' or 'afterRow', ...);
- *
- * @param Field $field
*/
public function getDataCellHtml(Field $field = null, array $attr = []): string
{
@@ -355,8 +352,6 @@ public function getDataCellHtml(Field $field = null, array $attr = []): string
* applied to the same column. The first one to be applied is executed first, then
* a subsequent ones are executed.
*
- * @param Field $field
- *
* @return string
*/
public function getDataCellTemplate(Field $field = null)
diff --git a/src/Table/Column/ActionButtons.php b/src/Table/Column/ActionButtons.php
index 72f8d4d1b8..2dbe897c38 100644
--- a/src/Table/Column/ActionButtons.php
+++ b/src/Table/Column/ActionButtons.php
@@ -5,9 +5,11 @@
namespace Atk4\Ui\Table\Column;
use Atk4\Core\Factory;
+use Atk4\Data\Field;
use Atk4\Data\Model;
use Atk4\Ui\Button;
use Atk4\Ui\JsChain;
+use Atk4\Ui\Modal;
use Atk4\Ui\Table;
use Atk4\Ui\UserAction\ExecutorInterface;
use Atk4\Ui\View;
@@ -88,7 +90,7 @@ public function addModal($button, $defaults, \Closure $callback, $owner = null,
$defaults = ['title' => $defaults];
}
- $modal = \Atk4\Ui\Modal::addTo($owner, $defaults);
+ $modal = Modal::addTo($owner, $defaults);
$modal->observeChanges(); // adds scrollbar if needed
@@ -108,9 +110,9 @@ public function getTag(string $position, $value, $attr = []): string
return parent::getTag($position, $value, $attr);
}
- public function getDataCellTemplate(\Atk4\Data\Field $field = null)
+ public function getDataCellTemplate(Field $field = null)
{
- if (!$this->buttons) {
+ if (count($this->buttons) === 0) {
return '';
}
diff --git a/src/Table/Column/ActionMenu.php b/src/Table/Column/ActionMenu.php
index fcab126ace..950dc71e61 100644
--- a/src/Table/Column/ActionMenu.php
+++ b/src/Table/Column/ActionMenu.php
@@ -1,14 +1,11 @@
name . '_action_' . (count($this->items) + 1);
if (!is_object($item)) {
- $item = Factory::factory([\Atk4\Ui\View::class], ['name' => false, 'ui' => 'item', 'content' => $item]);
+ $item = Factory::factory([View::class], ['name' => false, 'ui' => 'item', 'content' => $item]);
}
$this->items[] = $item;
@@ -86,7 +87,7 @@ public function addActionMenuItem($item, $action = null, string $confirmMsg = ''
return $item;
}
- public function getHeaderCellHtml(\Atk4\Data\Field $field = null, $value = null)
+ public function getHeaderCellHtml(Field $field = null, $value = null)
{
$this->table->js(true)->find('.atk-action-menu')->dropdown(
array_merge(
@@ -103,7 +104,7 @@ public function getHeaderCellHtml(\Atk4\Data\Field $field = null, $value = null)
return parent::getHeaderCellHtml($field, $value);
}
- public function getDataCellTemplate(\Atk4\Data\Field $field = null)
+ public function getDataCellTemplate(Field $field = null)
{
if (!$this->items) {
return '';
diff --git a/src/Table/Column/ColorRating.php b/src/Table/Column/ColorRating.php
index 9b04b07873..bf609d00a6 100644
--- a/src/Table/Column/ColorRating.php
+++ b/src/Table/Column/ColorRating.php
@@ -10,21 +10,17 @@
use Atk4\Ui\Table;
/**
- * Class ColorRating
- * Can be defined like this :
- * [
- * ColorRating::class,
- * [
- * 'min' => 1,
- * 'max' => 3,
- * 'steps' => 3,
- * 'colors' => [
- * '#FF0000',
- * '#FFFF00',
- * '#00FF00'
- * ]
- * ]
- * ].
+ * Class ColorRating can be defined like this:
+ * [ColorRating::class, [
+ * 'min' => 1,
+ * 'max' => 3,
+ * 'steps' => 3,
+ * 'colors' => [
+ * '#FF0000',
+ * '#FFFF00',
+ * '#00FF00'
+ * ]
+ * ]].
*/
class ColorRating extends Table\Column
{
diff --git a/src/Table/Column/Delete.php b/src/Table/Column/Delete.php
index 14500b7ffd..a7f370dfc6 100644
--- a/src/Table/Column/Delete.php
+++ b/src/Table/Column/Delete.php
@@ -4,7 +4,9 @@
namespace Atk4\Ui\Table\Column;
+use Atk4\Data\Field;
use Atk4\Ui\CallbackLater;
+use Atk4\Ui\Jquery;
use Atk4\Ui\Table;
/**
@@ -29,9 +31,9 @@ protected function init(): void
});
}
- public function getDataCellTemplate(\Atk4\Data\Field $field = null)
+ public function getDataCellTemplate(Field $field = null)
{
- $this->table->on('click', 'a.' . $this->shortName, null, ['confirm' => (new \Atk4\Ui\Jquery())->attr('title')])->atkAjaxec([
+ $this->table->on('click', 'a.' . $this->shortName, null, ['confirm' => (new Jquery())->attr('title')])->atkAjaxec([
'uri' => $this->vp->getJsUrl(),
'uri_options' => [$this->name => $this->table->jsRow()->data('id')],
]);
diff --git a/src/Table/Column/DragHandler.php b/src/Table/Column/DragHandler.php
index 899f7c99d8..b2363897ca 100644
--- a/src/Table/Column/DragHandler.php
+++ b/src/Table/Column/DragHandler.php
@@ -4,6 +4,9 @@
namespace Atk4\Ui\Table\Column;
+use Atk4\Data\Field;
+use Atk4\Ui\JsCallback;
+use Atk4\Ui\JsSortable;
use Atk4\Ui\Table;
/**
@@ -14,7 +17,7 @@ class DragHandler extends Table\Column
public $class;
/** @var string */
public $tag = 'i';
- /** @var \Atk4\Ui\JsCallback */
+ /** @var JsCallback */
public $cb;
protected function init(): void
@@ -24,7 +27,7 @@ protected function init(): void
if (!$this->class) {
$this->class = 'content icon';
}
- $this->cb = \Atk4\Ui\JsSortable::addTo($this->table, ['handleClass' => 'atk-handle']);
+ $this->cb = JsSortable::addTo($this->table, ['handleClass' => 'atk-handle']);
}
/**
@@ -35,7 +38,7 @@ public function onReorder(\Closure $fx): void
$this->cb->onReorder($fx);
}
- public function getDataCellTemplate(\Atk4\Data\Field $field = null)
+ public function getDataCellTemplate(Field $field = null)
{
return $this->getApp()->getTag($this->tag, ['class' => $this->class . ' atk-handle', 'style' => 'cursor:pointer; color: #bcbdbd']);
}
diff --git a/src/Table/Column/FilterModel/TypeDate.php b/src/Table/Column/FilterModel/TypeDate.php
index 0b9847f53e..b9f57f8b95 100644
--- a/src/Table/Column/FilterModel/TypeDate.php
+++ b/src/Table/Column/FilterModel/TypeDate.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Table\Column\FilterModel;
use Atk4\Data\Model;
+use Atk4\Ui\Form;
use Atk4\Ui\Table\Column;
use DateTime;
@@ -60,7 +61,7 @@ protected function init(): void
$this->addField('exact_date', ['type' => 'date', 'ui' => ['caption' => '']]);
// The integer field to generate a date when x day selector is used.
- $this->addField('number_days', ['ui' => ['caption' => '', 'form' => [\Atk4\Ui\Form\Control\Line::class, 'inputType' => 'number']]]);
+ $this->addField('number_days', ['ui' => ['caption' => '', 'form' => [Form\Control\Line::class, 'inputType' => 'number']]]);
}
public function setConditionForModel(Model $model)
@@ -124,8 +125,6 @@ public function getDate($dateModifier)
break;
default:
$date = $dateModifier ? new DateTime($dateModifier) : null;
-
- break;
}
return $date;
diff --git a/src/Table/Column/FilterModel/TypeDatetime.php b/src/Table/Column/FilterModel/TypeDatetime.php
index 08bf1ecddf..3415546663 100644
--- a/src/Table/Column/FilterModel/TypeDatetime.php
+++ b/src/Table/Column/FilterModel/TypeDatetime.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Table\Column\FilterModel;
use Atk4\Data\Model;
+use Atk4\Ui\Form;
use Atk4\Ui\Table\Column;
use DateTime;
@@ -60,7 +61,7 @@ protected function init(): void
$this->addField('exact_date', ['type' => 'date', 'ui' => ['caption' => '']]);
// The integer field to generate a date when x day selector is used.
- $this->addField('number_days', ['ui' => ['caption' => '', 'form' => [\Atk4\Ui\Form\Control\Line::class, 'inputType' => 'number']]]);
+ $this->addField('number_days', ['ui' => ['caption' => '', 'form' => [Form\Control\Line::class, 'inputType' => 'number']]]);
}
public function setConditionForModel(Model $model)
@@ -149,8 +150,6 @@ public function getDatetime($dateModifier)
break;
default:
$date = $dateModifier ? new DateTime($dateModifier) : null;
-
- break;
}
return $date;
diff --git a/src/Table/Column/FilterModel/TypeNumber.php b/src/Table/Column/FilterModel/TypeNumber.php
index c914887f25..4e9b4c98b9 100644
--- a/src/Table/Column/FilterModel/TypeNumber.php
+++ b/src/Table/Column/FilterModel/TypeNumber.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Table\Column\FilterModel;
use Atk4\Data\Model;
+use Atk4\Ui\Form;
use Atk4\Ui\Table\Column;
class TypeNumber extends Column\FilterModel
@@ -24,8 +25,8 @@ protected function init(): void
];
$this->op->default = '=';
- $this->value->ui['form'] = [\Atk4\Ui\Form\Control\Line::class, 'inputType' => 'number'];
- $this->addField('range', ['ui' => ['caption' => '', 'form' => [\Atk4\Ui\Form\Control\Line::class, 'inputType' => 'number']]]);
+ $this->value->ui['form'] = [Form\Control\Line::class, 'inputType' => 'number'];
+ $this->addField('range', ['ui' => ['caption' => '', 'form' => [Form\Control\Line::class, 'inputType' => 'number']]]);
}
public function setConditionForModel(Model $model)
diff --git a/src/Table/Column/FilterPopup.php b/src/Table/Column/FilterPopup.php
index 341f57e78e..65b0f4c986 100644
--- a/src/Table/Column/FilterPopup.php
+++ b/src/Table/Column/FilterPopup.php
@@ -5,10 +5,12 @@
namespace Atk4\Ui\Table\Column;
use Atk4\Data\Field;
+use Atk4\Ui\Button;
use Atk4\Ui\Form;
use Atk4\Ui\Jquery;
use Atk4\Ui\JsReload;
use Atk4\Ui\Popup;
+use Atk4\Ui\View;
/**
* Implement a filterPopup in a table column.
@@ -23,7 +25,7 @@ class FilterPopup extends Popup
/** @var Field The table field that need filtering. */
public $field;
- /** @var \Atk4\Ui\View|null The view associate with this filter popup that need to be reload. */
+ /** @var View|null The view associate with this filter popup that need to be reload. */
public $reload;
/**
@@ -65,15 +67,16 @@ protected function init(): void
return new jsReload($this->reload);
});
- \Atk4\Ui\Button::addTo($this->form, ['Clear', 'class.clear' => true])->on('click', function ($f) use ($model) {
- $model->clearData();
+ Button::addTo($this->form, ['Clear', 'class.clear' => true])
+ ->on('click', function ($f) use ($model) {
+ $model->clearData();
- return [
- $this->form->js(null, null, $this->form->formElement)->form('reset'),
- new JsReload($this->reload),
- (new Jquery($this->colTrigger))->trigger('click'),
- ];
- });
+ return [
+ $this->form->js(null, null, $this->form->formElement)->form('reset'),
+ new JsReload($this->reload),
+ (new Jquery($this->colTrigger))->trigger('click'),
+ ];
+ });
}
/**
diff --git a/src/Table/Column/Html.php b/src/Table/Column/Html.php
index 03a40ce55e..9d6aa4c3a6 100644
--- a/src/Table/Column/Html.php
+++ b/src/Table/Column/Html.php
@@ -9,30 +9,15 @@
use Atk4\Ui\Table;
/**
- * Class HTML.
- *
* Use this decorator if you have HTML code that you just want to put into the table cell.
*/
class Html extends Table\Column
{
- /**
- * Replace parent method.
- *
- * @param Field $field
- */
public function getDataCellHtml(Field $field = null, array $attr = []): string
{
return '{$_' . $field->shortName . '}';
}
- /**
- * Replace parent method.
- *
- * @param Model $row link to row data
- * @param Field|null $field field being rendered
- *
- * @return array associative array with tags and their HTML values
- */
public function getHtmlTags(Model $row, $field)
{
return ['_' . $field->shortName => ' ' . $row->get($field->shortName) . ' '];
diff --git a/src/Table/Column/Image.php b/src/Table/Column/Image.php
index f900561a6e..7756d0d8b4 100644
--- a/src/Table/Column/Image.php
+++ b/src/Table/Column/Image.php
@@ -4,6 +4,7 @@
namespace Atk4\Ui\Table\Column;
+use Atk4\Data\Field;
use Atk4\Ui\Table;
/**
@@ -14,12 +15,7 @@ class Image extends Table\Column
/** @var array Overrides custom attributes that will be applied on head, body or foot. */
public $attr = ['all' => ['class' => ['center aligned single line']]];
- /**
- * Extend parent method.
- *
- * @return string
- */
- public function getDataCellTemplate(\Atk4\Data\Field $field = null)
+ public function getDataCellTemplate(Field $field = null)
{
$caption = $field ? $field->getCaption() : $this->shortName;
diff --git a/src/Table/Column/KeyValue.php b/src/Table/Column/KeyValue.php
index e73ba407aa..3c27c2af51 100644
--- a/src/Table/Column/KeyValue.php
+++ b/src/Table/Column/KeyValue.php
@@ -10,36 +10,32 @@
use Atk4\Ui\Table;
/**
- * Class KeyValue.
- *
- * if field have values without a relation
- * like a status or a coded state of a process
- * Ex :
- * Machine state :
+ * If field have values without a relation like a status or a coded state of a process, example:
+ * Machine state:
* 0 => off
* 1 => powerup
* 2 => on
* 3 => resetting
- * 4 => error
+ * 4 => error.
*
* we don't need a table to define this, cause are defined in project
*
* using KeyValue Column you can show this values without using DB Relations
- * need to be defined in field like this :
+ * need to be defined in field like this:
*
* $this->addField('course_payment_status', [
- * 'caption' => __('Payment Status'),
- * 'default' => 0,
- * 'values' => [
- * 0 => __('not invoiceable'),
- * 1 => __('ready to invoice'),
- * 2 => __('invoiced'),
- * 3 => __('paid'),
- * ],
- * 'ui' => [
- * 'form' => [\Atk4\Ui\Form\Control\Dropdown::class],
- * 'table' => ['KeyValue'],
- * ],
+ * 'caption' => __('Payment Status'),
+ * 'default' => 0,
+ * 'values' => [
+ * 0 => __('not invoiceable'),
+ * 1 => __('ready to invoice'),
+ * 2 => __('invoiced'),
+ * 3 => __('paid'),
+ * ],
+ * 'ui' => [
+ * 'form' => [Form\Control\Dropdown::class],
+ * 'table' => ['KeyValue'],
+ * ],
* ]);
*/
class KeyValue extends Table\Column
diff --git a/src/Table/Column/Labels.php b/src/Table/Column/Labels.php
index d8585a7e9d..a2d56b4c27 100644
--- a/src/Table/Column/Labels.php
+++ b/src/Table/Column/Labels.php
@@ -9,8 +9,6 @@
use Atk4\Ui\Table;
/**
- * Class Labels.
- *
* Take the field value as string in CSV format or array of IDs and transforms into SemanticUI labels.
* If model field values property is set, then will use titles instead of IDs as label text.
*
diff --git a/src/Table/Column/Link.php b/src/Table/Column/Link.php
index 4d80dc3c84..694dc44269 100644
--- a/src/Table/Column/Link.php
+++ b/src/Table/Column/Link.php
@@ -4,6 +4,7 @@
namespace Atk4\Ui\Table\Column;
+use Atk4\Data\Field;
use Atk4\Data\Model;
use Atk4\Ui\HtmlTemplate;
use Atk4\Ui\Table;
@@ -110,7 +111,7 @@ protected function init(): void
}
}
- public function getDataCellTemplate(\Atk4\Data\Field $field = null)
+ public function getDataCellTemplate(Field $field = null)
{
$download = $this->forceDownload ? ' download="true" ' : '';
$external = $this->target ? ' target="' . $this->target . '" ' : '';
diff --git a/src/Table/Column/Money.php b/src/Table/Column/Money.php
index 8e7448ad30..85dad4da1f 100644
--- a/src/Table/Column/Money.php
+++ b/src/Table/Column/Money.php
@@ -6,6 +6,7 @@
use Atk4\Data\Field;
use Atk4\Data\Model;
+use Atk4\Ui\Exception;
use Atk4\Ui\Table;
/**
@@ -27,8 +28,8 @@ public function getTagAttributes(string $position, array $attr = []): array
public function getDataCellHtml(Field $field = null, array $attr = []): string
{
- if (!isset($field)) {
- throw new \Atk4\Ui\Exception('Money column requires a field');
+ if ($field === null) {
+ throw new Exception('Money column requires a field');
}
return $this->getTag(
diff --git a/src/Table/Column/NoValue.php b/src/Table/Column/NoValue.php
index d4427b7d39..8500f3c0f4 100644
--- a/src/Table/Column/NoValue.php
+++ b/src/Table/Column/NoValue.php
@@ -8,21 +8,17 @@
use Atk4\Ui\Table;
/**
- * Class NoValue.
- *
- * sometime we need null values in db
- *
- * when we display values we have holes
- * with NoValue decorator we can show a display value for column null value
+ * Sometime we need null values in DB. When we display values we have holes
+ * with NoValue decorator we can show a display value for column null value.
*
* $this->addField('field', [
- * [...]
- * 'ui' => [
- * [...]
- * 'table' => [
- * 'NoValue', ' if empty display this value '
- * ]
- * ]
+ * [...]
+ * 'ui' => [
+ * [...],
+ * 'table' => [
+ * 'NoValue', ' if empty display this value '
+ * ],
+ * ],
* ]);
*/
class NoValue extends Table\Column
diff --git a/src/Table/Column/Password.php b/src/Table/Column/Password.php
index 32ef4bd6c9..4c8d9a0de4 100644
--- a/src/Table/Column/Password.php
+++ b/src/Table/Column/Password.php
@@ -4,6 +4,7 @@
namespace Atk4\Ui\Table\Column;
+use Atk4\Data\Field;
use Atk4\Ui\Table;
/**
@@ -13,7 +14,7 @@ class Password extends Table\Column
{
public $sortable = false;
- public function getDataCellTemplate(\Atk4\Data\Field $field = null)
+ public function getDataCellTemplate(Field $field = null)
{
return '***';
}
diff --git a/src/Table/Column/Status.php b/src/Table/Column/Status.php
index a93a3024b4..133ae4201a 100644
--- a/src/Table/Column/Status.php
+++ b/src/Table/Column/Status.php
@@ -6,6 +6,7 @@
use Atk4\Data\Field;
use Atk4\Data\Model;
+use Atk4\Ui\Exception;
use Atk4\Ui\Table;
/**
@@ -31,7 +32,7 @@ public function __construct($states)
public function getDataCellHtml(Field $field = null, array $attr = []): string
{
if ($field === null) {
- throw new \Atk4\Ui\Exception('Status can be used only with model field');
+ throw new Exception('Status can be used only with model field');
}
$bodyAttr = $this->getTagAttributes('body');
diff --git a/src/Table/Column/Template.php b/src/Table/Column/Template.php
index cfa82aea66..4b7fa8f188 100644
--- a/src/Table/Column/Template.php
+++ b/src/Table/Column/Template.php
@@ -4,6 +4,7 @@
namespace Atk4\Ui\Table\Column;
+use Atk4\Data\Field;
use Atk4\Ui\Table;
/**
@@ -31,7 +32,7 @@ public function __construct($template)
*/
}
- public function getDataCellTemplate(\Atk4\Data\Field $field = null)
+ public function getDataCellTemplate(Field $field = null)
{
return $this->template;
}
diff --git a/src/Table/Column/Tooltip.php b/src/Table/Column/Tooltip.php
index 2e1e2a6002..0eec46e257 100644
--- a/src/Table/Column/Tooltip.php
+++ b/src/Table/Column/Tooltip.php
@@ -10,13 +10,11 @@
use Atk4\Ui\Table;
/**
- * Class Tooltip.
- *
* column to add a little icon to show on hover a text
- * text is taken by the Row Model in $tooltipField
+ * text is taken by the Row Model in $tooltipField.
*
- * $crud->addDecorator('paid_date', new \Atk4\Ui\Table\Column\Tooltip('note'));
- * $crud->addDecorator('paid_date', new \Atk4\Ui\Table\Column\Tooltip('note','error red'));
+ * $crud->addDecorator('paid_date', new Table\Column\Tooltip('note'));
+ * $crud->addDecorator('paid_date', new Table\Column\Tooltip('note','error red'));
*/
class Tooltip extends Table\Column
{
diff --git a/src/UserAction/BasicExecutor.php b/src/UserAction/BasicExecutor.php
index 69f255b8ef..99e1bc34ae 100644
--- a/src/UserAction/BasicExecutor.php
+++ b/src/UserAction/BasicExecutor.php
@@ -8,11 +8,13 @@
use Atk4\Data\Model;
use Atk4\Ui\Button;
use Atk4\Ui\Exception;
+use Atk4\Ui\Header;
use Atk4\Ui\JsExpressionable;
use Atk4\Ui\JsToast;
use Atk4\Ui\Message;
+use Atk4\Ui\View;
-class BasicExecutor extends \Atk4\Ui\View implements ExecutorInterface
+class BasicExecutor extends View implements ExecutorInterface
{
use HookTrait;
@@ -93,7 +95,7 @@ protected function recursiveRender(): void
/**
* Check if all argument values have been provided.
*/
- public function hasAllArguments()
+ public function hasAllArguments(): bool
{
foreach ($this->action->args as $key => $val) {
if (!isset($this->arguments[$key])) {
@@ -115,7 +117,7 @@ protected function initPreview()
$this->addHeader();
- \Atk4\Ui\Button::addToWithCl($this, $this->executorButton)->on('click', function () {
+ Button::addToWithCl($this, $this->executorButton)->on('click', function () {
return $this->executeModelAction();
});
}
@@ -148,7 +150,7 @@ public function executeModelAction()
public function addHeader()
{
if ($this->hasHeader) {
- \Atk4\Ui\Header::addTo($this, [$this->action->getCaption(), 'subHeader' => $this->description ?: $this->action->getDescription()]);
+ Header::addTo($this, [$this->action->getCaption(), 'subHeader' => $this->description ?: $this->action->getDescription()]);
}
}
}
diff --git a/src/UserAction/ConfirmationExecutor.php b/src/UserAction/ConfirmationExecutor.php
index 4ab3190070..970de10e6a 100644
--- a/src/UserAction/ConfirmationExecutor.php
+++ b/src/UserAction/ConfirmationExecutor.php
@@ -154,32 +154,22 @@ public function doConfirmation(View $modal)
$modal->js(
true,
- $this->ok->js()->on(
- 'click',
- new JsFunction(
+ $this->ok->js()->on('click', new JsFunction([
+ $this->loader->jsLoad(
[
- $this->loader->jsLoad(
- [
- 'step' => 'exec',
- $this->name => $this->action->getEntity()->getId(),
- ],
- ['method' => 'post']
- ),
- ]
- )
- )
+ 'step' => 'exec',
+ $this->name => $this->action->getEntity()->getId(),
+ ],
+ ['method' => 'post']
+ ),
+ ]))
);
$modal->js(
true,
- $this->cancel->js()->on(
- 'click',
- new JsFunction(
- [
- $this->hide(),
- ]
- )
- )
+ $this->cancel->js()->on('click', new JsFunction([
+ $this->hide(),
+ ]))
);
}
diff --git a/src/UserAction/ModalExecutor.php b/src/UserAction/ModalExecutor.php
index ff626837db..08299a81b1 100644
--- a/src/UserAction/ModalExecutor.php
+++ b/src/UserAction/ModalExecutor.php
@@ -8,6 +8,7 @@
use Atk4\Data\Model;
use Atk4\Ui\Exception;
use Atk4\Ui\JsToast;
+use Atk4\Ui\Loader;
use Atk4\Ui\Modal;
use Atk4\Ui\View;
@@ -61,7 +62,7 @@ public function getAction(): Model\UserAction
*/
public function afterActionInit(Model\UserAction $action): void
{
- $this->loader = \Atk4\Ui\Loader::addTo($this, ['ui' => $this->loaderUi, 'shim' => $this->loaderShim]);
+ $this->loader = Loader::addTo($this, ['ui' => $this->loaderUi, 'shim' => $this->loaderShim]);
$this->loader->loadEvent = false;
$this->loader->addClass('atk-hide-loading-content');
$this->actionData = $this->loader->jsGetStoreData()['session'];
diff --git a/src/UserAction/PreviewExecutor.php b/src/UserAction/PreviewExecutor.php
index 5757c5dc3a..4e080c3e43 100644
--- a/src/UserAction/PreviewExecutor.php
+++ b/src/UserAction/PreviewExecutor.php
@@ -4,6 +4,8 @@
namespace Atk4\Ui\UserAction;
+use Atk4\Ui\Button;
+use Atk4\Ui\Message;
use Atk4\Ui\View;
class PreviewExecutor extends BasicExecutor
@@ -17,7 +19,7 @@ class PreviewExecutor extends BasicExecutor
public function initPreview()
{
if (!$this->hasAllArguments()) {
- \Atk4\Ui\Message::addTo($this, ['type' => 'error', $this->missingArgsMsg]);
+ Message::addTo($this, ['type' => 'error', $this->missingArgsMsg]);
return;
}
@@ -42,7 +44,7 @@ public function initPreview()
break;
}
- \Atk4\Ui\Button::addToWithCl($this, $this->executorButton)->on('click', function () {
+ Button::addToWithCl($this, $this->executorButton)->on('click', function () {
return $this->executeModelAction();
});
}
diff --git a/src/UserAction/StepExecutorTrait.php b/src/UserAction/StepExecutorTrait.php
index 946d1b6ff1..07461b0f0a 100644
--- a/src/UserAction/StepExecutorTrait.php
+++ b/src/UserAction/StepExecutorTrait.php
@@ -13,6 +13,7 @@
use Atk4\Ui\Form;
use Atk4\Ui\JsExpressionable;
use Atk4\Ui\JsFunction;
+use Atk4\Ui\Loader;
use Atk4\Ui\Message;
use Atk4\Ui\View;
@@ -27,7 +28,7 @@ trait StepExecutorTrait
/** @var string current step. */
protected $step;
- /** @var \Atk4\Ui\Loader The Loader that will execute all action step. */
+ /** @var Loader The Loader that will execute all action step. */
protected $loader;
/** @var string */
@@ -217,21 +218,16 @@ protected function doPreview(View $page): void
// setup executor button to perform action
$page->js(
true,
- $this->execActionBtn->js()->on(
- 'click',
- new JsFunction(
+ $this->execActionBtn->js()->on('click', new JsFunction([
+ $this->loader->jsLoad(
[
- $this->loader->jsLoad(
- [
- 'step' => 'final',
- $this->name => $this->action->getEntity()->getId(),
- ],
- ['method' => 'post'],
- $this->loader->name
- ),
- ]
- )
- )
+ 'step' => 'final',
+ $this->name => $this->action->getEntity()->getId(),
+ ],
+ ['method' => 'post'],
+ $this->loader->name
+ ),
+ ]))
);
$text = $this->getActionPreview();
diff --git a/src/View.php b/src/View.php
index be9ccfe610..b5e4905b73 100644
--- a/src/View.php
+++ b/src/View.php
@@ -967,16 +967,16 @@ public function jsReload($args = [], $afterSuccess = null, $apiConfig = [])
*
* @see http://agile-ui.readthedocs.io/en/latest/js.html
*
- * @param string $event JavaScript event
- * @param string|View|JsExpressionable|array|Model\UserAction|null $selector Optional jQuery-style selector
+ * @param string $event JavaScript event
+ * @param ($action is null|array ? string|JsExpressionable|\Closure|array|UserAction\ExecutorInterface|Model\UserAction : string|array) $selector Optional jQuery-style selector
* @param string|JsExpressionable|\Closure|array|UserAction\ExecutorInterface|Model\UserAction|null $action code to execute
* @param array $defaults Options
*
* @return Jquery
*/
- public function on($event, $selector = null, $action = null, $defaults = null)
+ public function on(string $event, $selector = null, $action = null, array $defaults = null)
{
- $event_stmts = [];
+ $eventStatements = [];
$cb = null;
$actions = [];
@@ -1005,8 +1005,8 @@ public function on($event, $selector = null, $action = null, $defaults = null)
}
// set event stmts to use preventDefault and/or stopPropagation
- $event_stmts['preventDefault'] = $defaults['preventDefault'] ?? true;
- $event_stmts['stopPropagation'] = $defaults['stopPropagation'] ?? true;
+ $eventStatements['preventDefault'] = $defaults['preventDefault'] ?? true;
+ $eventStatements['stopPropagation'] = $defaults['stopPropagation'] ?? true;
// Dealing with callback action.
if ($action instanceof \Closure || (is_array($action) && ($action[0] ?? null) instanceof \Closure)) {
@@ -1067,17 +1067,17 @@ public function on($event, $selector = null, $action = null, $defaults = null)
// Do we need confirm action.
if ($defaults['confirm'] ?? null) {
- array_unshift($event_stmts, new JsExpression('$.atkConfirm({message:[confirm], onApprove: [action], options: {button:{ok:[ok], cancel:[cancel]}}, context:this})', [
+ array_unshift($eventStatements, new JsExpression('$.atkConfirm({ message: [confirm], onApprove: [action], options: { button: {ok: [ok], cancel: [cancel] } }, context: this })', [
'confirm' => $defaults['confirm'],
'action' => new JsFunction($actions),
'ok' => $defaults['ok'] ?? 'Ok',
'cancel' => $defaults['cancel'] ?? 'Cancel',
]));
} else {
- $event_stmts = array_merge($event_stmts, $actions);
+ $eventStatements = array_merge($eventStatements, $actions);
}
- $event_function = new JsFunction($event_stmts);
+ $event_function = new JsFunction($eventStatements);
if ($selector) {
$this->js(true)->on($event, $selector, $event_function);
diff --git a/src/Component/InlineEdit.php b/src/VueComponent/InlineEdit.php
similarity index 96%
rename from src/Component/InlineEdit.php
rename to src/VueComponent/InlineEdit.php
index 8b562ed2c9..3a20b40c08 100644
--- a/src/Component/InlineEdit.php
+++ b/src/VueComponent/InlineEdit.php
@@ -1,23 +1,24 @@
cb = \Atk4\Ui\JsCallback::addTo($this);
+ $this->cb = JsCallback::addTo($this);
// Set default validation error handler.
if (!$this->formatErrorMsg) {
@@ -131,7 +132,7 @@ public function onChange(\Closure $fx): void
/**
* On success notifier.
*
- * @return \Atk4\Ui\JsToast
+ * @return JsToast
*/
public function jsSuccess(string $message)
{
@@ -147,7 +148,7 @@ public function jsSuccess(string $message)
*
* @param string $message
*
- * @return \Atk4\Ui\JsToast
+ * @return JsToast
*/
public function jsError($message)
{
diff --git a/src/Component/ItemSearch.php b/src/VueComponent/ItemSearch.php
similarity index 98%
rename from src/Component/ItemSearch.php
rename to src/VueComponent/ItemSearch.php
index 927f382232..79884a6e5b 100644
--- a/src/Component/ItemSearch.php
+++ b/src/VueComponent/ItemSearch.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Atk4\Ui\Component;
+namespace Atk4\Ui\VueComponent;
use Atk4\Data\Model;
use Atk4\Ui\JsVueService;
diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php
index e5cd3095dd..d87175bdd3 100644
--- a/tests/CallbackTest.php
+++ b/tests/CallbackTest.php
@@ -6,11 +6,15 @@
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\AbstractView;
+use Atk4\Ui\App;
use Atk4\Ui\Callback;
+use Atk4\Ui\CallbackLater;
+use Atk4\Ui\Layout;
+use Atk4\Ui\View;
use Atk4\Ui\VirtualPage;
use Mvorisek\Atk4\Hintable\Phpstan\PhpstanUtil;
-class AppMock extends \Atk4\Ui\App
+class AppMock extends App
{
/** @var bool */
public $terminated = false;
@@ -36,13 +40,13 @@ class CallbackTest extends TestCase
/** @var string */
private $htmlDoctypeRegex = '~^app = new AppMock(['alwaysRun' => false, 'catchExceptions' => false]);
- $this->app->initLayout([\Atk4\Ui\Layout\Centered::class]);
+ $this->app->initLayout([Layout\Centered::class]);
}
protected function tearDown(): void
@@ -61,7 +65,7 @@ protected function simulateCallbackTriggering(AbstractView $cb): void
public function testCallback(): void
{
- $cb = \Atk4\Ui\Callback::addTo($this->app);
+ $cb = Callback::addTo($this->app);
$this->simulateCallbackTriggering($cb);
@@ -76,7 +80,7 @@ public function testCallback(): void
public function testCallbackTrigger(): void
{
- $cb = \Atk4\Ui\Callback::addTo($this->app);
+ $cb = Callback::addTo($this->app);
$this->assertSame($this->app->layout->name . '_' . $cb->shortName, $cb->getUrlTrigger());
$cb = Callback::addTo($this->app, ['urlTrigger' => 'test']);
@@ -85,9 +89,9 @@ public function testCallbackTrigger(): void
public function testViewUrlCallback(): void
{
- $cbApp = \Atk4\Ui\Callback::addTo($this->app, ['urlTrigger' => 'aa']);
- $v1 = \Atk4\Ui\View::addTo($this->app);
- $cb = \Atk4\Ui\Callback::addTo($v1, ['urlTrigger' => 'bb']);
+ $cbApp = Callback::addTo($this->app, ['urlTrigger' => 'aa']);
+ $v1 = View::addTo($this->app);
+ $cb = Callback::addTo($v1, ['urlTrigger' => 'bb']);
$this->simulateCallbackTriggering($cbApp);
$this->simulateCallbackTriggering($cb);
@@ -105,12 +109,12 @@ public function testViewUrlCallback(): void
$var = null;
$cb->set(function ($x) use (&$var, $v1) {
- $v3 = \Atk4\Ui\View::addTo($v1);
+ $v3 = View::addTo($v1);
$this->assertSame('test.php', $v3->url(['test']));
$var = $x;
}, [34]);
- $v2 = \Atk4\Ui\View::addTo($v1);
+ $v2 = View::addTo($v1);
$v2->stickyGet('g1', '1');
$this->assertSame(34, $var);
@@ -119,7 +123,7 @@ public function testViewUrlCallback(): void
public function testCallbackNotFiring(): void
{
- $cb = \Atk4\Ui\Callback::addTo($this->app);
+ $cb = Callback::addTo($this->app);
// do NOT simulate triggering in this test
@@ -133,7 +137,7 @@ public function testCallbackNotFiring(): void
public function testCallbackLater(): void
{
- $cb = \Atk4\Ui\CallbackLater::addTo($this->app);
+ $cb = CallbackLater::addTo($this->app);
$this->simulateCallbackTriggering($cb);
@@ -152,13 +156,13 @@ public function testCallbackLater(): void
public function testCallbackLaterNested(): void
{
- $cb = \Atk4\Ui\CallbackLater::addTo($this->app);
+ $cb = CallbackLater::addTo($this->app);
$this->simulateCallbackTriggering($cb);
$var = null;
$cb->set(function ($x) use (&$var) {
- $cb2 = \Atk4\Ui\CallbackLater::addTo($this->app);
+ $cb2 = CallbackLater::addTo($this->app);
$this->simulateCallbackTriggering($cb2);
@@ -177,7 +181,7 @@ public function testCallbackLaterNested(): void
public function testCallbackLaterNotFiring(): void
{
- $cb = \Atk4\Ui\CallbackLater::addTo($this->app);
+ $cb = CallbackLater::addTo($this->app);
// don't simulate triggering
$var = null;
diff --git a/tests/Concerns/HandlesTable.php b/tests/Concerns/HandlesTable.php
index dd9f001c18..8a6d903f7b 100644
--- a/tests/Concerns/HandlesTable.php
+++ b/tests/Concerns/HandlesTable.php
@@ -9,16 +9,10 @@
trait HandlesTable
{
/**
- * Extract only out from an \Atk4\Ui\Table given the data-id attribute value.
- *
- * @param string $rowDataId
- *
- * @return string
+ * Extract only out from a Table given the data-id attribute value.
*/
- protected function extractTableRow(Table $table, $rowDataId = '1')
+ protected function extractTableRow(Table $table, string $rowDataId = '1'): string
{
- $matches = [];
-
preg_match('/<.*data-id="' . $rowDataId . '".*/m', $table->render(), $matches);
return preg_replace('~\r?\n|\r~', '', $matches[0]);
diff --git a/tests/DemosTest.php b/tests/DemosTest.php
index 3529138ddd..2b1eeede0d 100644
--- a/tests/DemosTest.php
+++ b/tests/DemosTest.php
@@ -4,11 +4,14 @@
namespace Atk4\Ui\Tests;
+use Atk4\Core\Exception as CoreException;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Data\Persistence;
use Atk4\Ui\App;
use Atk4\Ui\Callback;
+use Atk4\Ui\Exception;
use Atk4\Ui\Exception\UnhandledCallbackExceptionError;
+use Atk4\Ui\Layout;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
@@ -60,7 +63,7 @@ protected function setUp(): void
$initVars = array_diff_key(get_defined_vars(), $initVars + ['initVars' => true]);
if (array_keys($initVars) !== ['app']) {
- throw new \Atk4\Ui\Exception('Demos init must setup only $app variable');
+ throw new Exception('Demos init must setup only $app variable');
}
self::$_db = $app->db;
@@ -135,7 +138,7 @@ public function callExit(): void
throw new DemosTestExitError();
}
};
- $app->initLayout([\Atk4\Ui\Layout\Maestro::class]);
+ $app->initLayout([Layout\Maestro::class]);
// clone DB (mainly because all Models remains attached now, TODO can be removed once they are GCed)
$app->db = clone self::$_db;
@@ -150,7 +153,7 @@ protected function assertNoGlobalSticky(App $app): void
['__atk_json' => false, '__atk_tab' => false, 'APP_CALL_EXIT' => true, 'APP_CATCH_EXCEPTIONS' => true]
);
if ($appSticky !== []) {
- throw (new \Atk4\Ui\Exception('Global GET sticky must never be set by any component'))
+ throw (new Exception('Global GET sticky must never be set by any component'))
->addMoreInfo('appSticky', $appSticky);
}
}
@@ -337,7 +340,7 @@ public function testDemosStatusAndHtmlResponse(string $path): void
public function testDemoResponseError(): void
{
if (static::class === self::class) {
- $this->expectException(\Atk4\Core\Exception::class);
+ $this->expectException(CoreException::class);
$this->expectExceptionMessage('Property for specified object is not defined');
}
diff --git a/tests/ExecutorFactoryTest.php b/tests/ExecutorFactoryTest.php
index 61fbba6e4b..fd51c01a2d 100644
--- a/tests/ExecutorFactoryTest.php
+++ b/tests/ExecutorFactoryTest.php
@@ -10,6 +10,7 @@
use Atk4\Ui\App;
use Atk4\Ui\Button;
use Atk4\Ui\Item;
+use Atk4\Ui\Layout;
use Atk4\Ui\UserAction\BasicExecutor;
use Atk4\Ui\UserAction\ConfirmationExecutor;
use Atk4\Ui\UserAction\JsCallbackExecutor;
@@ -48,7 +49,7 @@ protected function setUp(): void
$p = new Persistence\Array_();
$this->model = new TestModel($p);
$this->app = $this->createApp();
- $this->app->initLayout([\Atk4\Ui\Layout\Admin::class]);
+ $this->app->initLayout([Layout\Admin::class]);
}
protected function createApp(): App
diff --git a/tests/ForFieldUiTest.php b/tests/ForFieldUiTest.php
index 1cc95ebb85..fd5ae295b6 100644
--- a/tests/ForFieldUiTest.php
+++ b/tests/ForFieldUiTest.php
@@ -7,6 +7,7 @@
use Atk4\Core\Phpunit\TestCase;
use Atk4\Data\Model;
use Atk4\Data\Persistence;
+use Atk4\Ui\Form;
class MyTestModel extends Model
{
@@ -42,7 +43,7 @@ public function testModelLevel(): void
public function testRegularField(): void
{
- $f = new \Atk4\Ui\Form();
+ $f = new Form();
$f->invokeInit();
$f->setModel($this->m->createEntity());
$this->assertFalse($f->getControl('regular_field')->readOnly);
@@ -50,7 +51,7 @@ public function testRegularField(): void
public function testJustDataField(): void
{
- $f = new \Atk4\Ui\Form();
+ $f = new Form();
$f->invokeInit();
$f->setModel($this->m->createEntity(), ['just_for_data']);
$this->assertTrue($f->getControl('just_for_data')->readOnly);
@@ -58,7 +59,7 @@ public function testJustDataField(): void
public function testShowInUi(): void
{
- $f = new \Atk4\Ui\Form();
+ $f = new Form();
$f->invokeInit();
$f->setModel($this->m->createEntity());
$this->assertFalse($f->getControl('no_persist_but_show_in_ui')->readOnly);
diff --git a/tests/FormTest.php b/tests/FormTest.php
index 61c3892899..efc9def761 100644
--- a/tests/FormTest.php
+++ b/tests/FormTest.php
@@ -23,7 +23,7 @@ protected function setUp(): void
{
parent::setUp();
- $this->form = new \Atk4\Ui\Form();
+ $this->form = new Form();
$this->form->setApp(new AppFormTestMock([
'catchExceptions' => false,
'alwaysRun' => false,
diff --git a/tests/GridTest.php b/tests/GridTest.php
index 1923c02800..540d67817b 100644
--- a/tests/GridTest.php
+++ b/tests/GridTest.php
@@ -4,10 +4,12 @@
namespace Atk4\Ui\Tests;
+use Atk4\Core\Phpunit\TestCase;
+use Atk4\Data\Model;
use Atk4\Data\Persistence;
use Atk4\Ui\Table;
-class GridTest extends \Atk4\Core\Phpunit\TestCase
+class GridTest extends TestCase
{
use Concerns\HandlesTable;
@@ -70,7 +72,7 @@ public function test3(): void
}
}
-class MyModel extends \Atk4\Data\Model
+class MyModel extends Model
{
public ?string $titleField = 'email';
diff --git a/tests/JsTest.php b/tests/JsTest.php
index 8e8558b0de..b98d712b4f 100644
--- a/tests/JsTest.php
+++ b/tests/JsTest.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Tests;
use Atk4\Core\Phpunit\TestCase;
+use Atk4\Ui\App;
use Atk4\Ui\Jquery;
use Atk4\Ui\JsChain;
use Atk4\Ui\JsExpression;
@@ -44,8 +45,8 @@ public function testNumbers(): void
$this->assertSame($expected, (new JsExpression('[]', [$in]))->jsRender());
// test JSON renderer in App too
- // test extensively because of (possibly fragile) custom regex impl
- $app = (new \ReflectionClass(\Atk4\Ui\App::class))->newInstanceWithoutConstructor();
+ // test extensively because of complex custom regex impl
+ $app = (new \ReflectionClass(App::class))->newInstanceWithoutConstructor();
$expectedRaw = json_decode($expected);
foreach ([
[$expectedRaw, $in], // direct value
@@ -66,18 +67,10 @@ public function testNestedExpressions(): void
{
$this->assertSame(
'10-(2 + 3)',
- (
- new JsExpression(
- '[]-[]',
- [
- 10,
- new JsExpression(
- '[a] + [b]',
- ['a' => 2, 'b' => 3]
- ),
- ]
- )
- )->jsRender()
+ (new JsExpression(
+ '[]-[]',
+ [10, new JsExpression('[a] + [b]', ['a' => 2, 'b' => 3])]
+ ))->jsRender()
);
}
diff --git a/tests/ListerTest.php b/tests/ListerTest.php
index 48e757d827..522907ec7e 100644
--- a/tests/ListerTest.php
+++ b/tests/ListerTest.php
@@ -7,6 +7,8 @@
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Exception;
use Atk4\Ui\HtmlTemplate;
+use Atk4\Ui\Lister;
+use Atk4\Ui\View;
class ListerTest extends TestCase
{
@@ -15,9 +17,9 @@ class ListerTest extends TestCase
*/
public function testListerRender(): void
{
- $v = new \Atk4\Ui\View();
+ $v = new View();
$v->invokeInit();
- $l = \Atk4\Ui\Lister::addTo($v, ['defaultTemplate' => 'lister.html']);
+ $l = Lister::addTo($v, ['defaultTemplate' => 'lister.html']);
$l->setSource(['foo', 'bar']);
}
@@ -26,9 +28,9 @@ public function testListerRender(): void
*/
public function testListerRender2(): void
{
- $v = new \Atk4\Ui\View(['template' => new HtmlTemplate('hello{list}, world{/list}')]);
+ $v = new View(['template' => new HtmlTemplate('hello{list}, world{/list}')]);
$v->invokeInit();
- $l = \Atk4\Ui\Lister::addTo($v, [], ['list']);
+ $l = Lister::addTo($v, [], ['list']);
$l->setSource(['foo', 'bar']);
$this->assertSame('hello, world, world', $v->render());
}
@@ -36,9 +38,9 @@ public function testListerRender2(): void
public function testAddAfterRender(): void
{
$this->expectException(Exception::class);
- $v = new \Atk4\Ui\View();
+ $v = new View();
$v->invokeInit();
- $l = \Atk4\Ui\Lister::addTo($v);
+ $l = Lister::addTo($v);
$l->setSource(['foo', 'bar']);
}
}
diff --git a/tests/PaginatorTest.php b/tests/PaginatorTest.php
index bb4b041171..4c3b8346f0 100644
--- a/tests/PaginatorTest.php
+++ b/tests/PaginatorTest.php
@@ -5,15 +5,13 @@
namespace Atk4\Ui\Tests;
use Atk4\Core\Phpunit\TestCase;
+use Atk4\Ui\Paginator;
class PaginatorTest extends TestCase
{
- public $p;
-
- public function addDataProvider()
+ public function addDataProvider(): array
{
return [
- // cur, range, total, expected output
[1, 1, 1, [1]],
[1, 4, 1, [1]],
[1, 1, 2, [1, 2]],
@@ -40,7 +38,7 @@ public function addDataProvider()
*/
public function testPaginator($page, $range, $total, $expected): void
{
- $p = new \Atk4\Ui\Paginator(['page' => $page, 'range' => $range, 'total' => $total]);
+ $p = new Paginator(['page' => $page, 'range' => $range, 'total' => $total]);
$this->assertSame($expected, $p->getPaginatorItems());
}
}
diff --git a/tests/TableColumnColorRatingTest.php b/tests/TableColumnColorRatingTest.php
index df2f9f87e5..3347243cdf 100644
--- a/tests/TableColumnColorRatingTest.php
+++ b/tests/TableColumnColorRatingTest.php
@@ -5,7 +5,9 @@
namespace Atk4\Ui\Tests;
use Atk4\Core\Phpunit\TestCase;
+use Atk4\Data\Model;
use Atk4\Data\Persistence;
+use Atk4\Ui\Exception;
use Atk4\Ui\Table;
class TableColumnColorRatingTest extends TestCase
@@ -21,36 +23,31 @@ protected function setUp(): void
{
$arr = [
'table' => [
- 1 => [
- 'id' => 1, 'name' => 'bar', 'ref' => 'ref123', 'rating' => 3,
- ],
+ 1 => ['id' => 1, 'name' => 'bar', 'ref' => 'ref123', 'rating' => 3],
],
];
$db = new Persistence\Array_($arr);
- $m = new \Atk4\Data\Model($db, ['table' => 'table']);
+ $m = new Model($db, ['table' => 'table']);
$m->addField('name');
$m->addField('ref');
$m->addField('rating');
- $this->table = new \Atk4\Ui\Table();
+ $this->table = new Table();
$this->table->invokeInit();
$this->table->setModel($m, ['name', 'ref', 'rating']);
}
public function testValueGreaterThanMax(): void
{
- $rating = $this->table->addDecorator('rating', [
- Table\Column\ColorRating::class,
- [
- 'min' => 0,
- 'max' => 2,
- 'steps' => 3,
- 'colors' => [
- '#FF0000',
- '#FFFF00',
- '#00FF00',
- ],
+ $rating = $this->table->addDecorator('rating', [Table\Column\ColorRating::class, [
+ 'min' => 0,
+ 'max' => 2,
+ 'steps' => 3,
+ 'colors' => [
+ '#FF0000',
+ '#FFFF00',
+ '#00FF00',
],
- ]);
+ ]]);
$this->assertSame(
'{$name} {$ref} {$rating} ',
@@ -65,20 +62,17 @@ public function testValueGreaterThanMax(): void
public function testValueGreaterThanMaxNoColor(): void
{
- $this->table->addDecorator('rating', [
- Table\Column\ColorRating::class,
- [
- 'min' => 0,
- 'max' => 2,
- 'steps' => 3,
- 'colors' => [
- '#FF0000',
- '#FFFF00',
- '#00FF00',
- ],
- 'moreThanMaxNoColor' => true,
+ $this->table->addDecorator('rating', [Table\Column\ColorRating::class, [
+ 'min' => 0,
+ 'max' => 2,
+ 'steps' => 3,
+ 'colors' => [
+ '#FF0000',
+ '#FFFF00',
+ '#00FF00',
],
- ]);
+ 'moreThanMaxNoColor' => true,
+ ]]);
$this->assertSame(
' bar ref123 3 ',
@@ -88,19 +82,16 @@ public function testValueGreaterThanMaxNoColor(): void
public function testValueLowerThanMin(): void
{
- $rating = $this->table->addDecorator('rating', [
- Table\Column\ColorRating::class,
- [
- 'min' => 4,
- 'max' => 10,
- 'steps' => 3,
- 'colors' => [
- '#FF0000',
- '#FFFF00',
- '#00FF00',
- ],
+ $rating = $this->table->addDecorator('rating', [Table\Column\ColorRating::class, [
+ 'min' => 4,
+ 'max' => 10,
+ 'steps' => 3,
+ 'colors' => [
+ '#FF0000',
+ '#FFFF00',
+ '#00FF00',
],
- ]);
+ ]]);
$this->assertSame(
'{$name} {$ref} {$rating} ',
@@ -115,20 +106,17 @@ public function testValueLowerThanMin(): void
public function testValueLowerThanMinNoColor(): void
{
- $this->table->addDecorator('rating', [
- Table\Column\ColorRating::class,
- [
- 'min' => 4,
- 'max' => 10,
- 'steps' => 3,
- 'colors' => [
- '#FF0000',
- '#FFFF00',
- '#00FF00',
- ],
- 'lessThanMinNoColor' => true,
+ $this->table->addDecorator('rating', [Table\Column\ColorRating::class, [
+ 'min' => 4,
+ 'max' => 10,
+ 'steps' => 3,
+ 'colors' => [
+ '#FF0000',
+ '#FFFF00',
+ '#00FF00',
],
- ]);
+ 'lessThanMinNoColor' => true,
+ ]]);
$this->assertSame(
'bar ref123 3 ',
@@ -138,75 +126,59 @@ public function testValueLowerThanMinNoColor(): void
public function testExceptionMinGreaterThanMax(): void
{
- $this->expectException(\Atk4\Ui\Exception::class);
-
- $this->table->addDecorator('rating', [
- Table\Column\ColorRating::class,
- [
- 'min' => 3,
- 'max' => 1,
- 'steps' => 3,
- 'colors' => [
- '#FF0000',
- '#FFFF00',
- '#00FF00',
- ],
+ $this->expectException(Exception::class);
+ $this->table->addDecorator('rating', [Table\Column\ColorRating::class, [
+ 'min' => 3,
+ 'max' => 1,
+ 'steps' => 3,
+ 'colors' => [
+ '#FF0000',
+ '#FFFF00',
+ '#00FF00',
],
- ]);
+ ]]);
}
public function testExceptionMinEqualsMax(): void
{
- $this->expectException(\Atk4\Ui\Exception::class);
-
- $this->table->addDecorator('rating', [
- Table\Column\ColorRating::class,
- [
- 'min' => 3,
- 'max' => 3,
- 'steps' => 3,
- 'colors' => [
- '#FF0000',
- '#FFFF00',
- '#00FF00',
- ],
+ $this->expectException(Exception::class);
+ $this->table->addDecorator('rating', [Table\Column\ColorRating::class, [
+ 'min' => 3,
+ 'max' => 3,
+ 'steps' => 3,
+ 'colors' => [
+ '#FF0000',
+ '#FFFF00',
+ '#00FF00',
],
- ]);
+ ]]);
}
public function testExceptionZeroSteps(): void
{
- $this->expectException(\Atk4\Ui\Exception::class);
-
- $this->table->addDecorator('rating', [
- Table\Column\ColorRating::class,
- [
- 'min' => 1,
- 'max' => 3,
- 'steps' => 0,
- 'colors' => [
- '#FF0000',
- '#FFFF00',
- '#00FF00',
- ],
+ $this->expectException(Exception::class);
+ $this->table->addDecorator('rating', [Table\Column\ColorRating::class, [
+ 'min' => 1,
+ 'max' => 3,
+ 'steps' => 0,
+ 'colors' => [
+ '#FF0000',
+ '#FFFF00',
+ '#00FF00',
],
- ]);
+ ]]);
}
public function testExceptionLessThan2ColorsDefined(): void
{
- $this->expectException(\Atk4\Ui\Exception::class);
-
- $this->table->addDecorator('rating', [
- Table\Column\ColorRating::class,
- [
- 'min' => 1,
- 'max' => 3,
- 'steps' => 3,
- 'colors' => [
- '#FF0000',
- ],
+ $this->expectException(Exception::class);
+ $this->table->addDecorator('rating', [Table\Column\ColorRating::class, [
+ 'min' => 1,
+ 'max' => 3,
+ 'steps' => 3,
+ 'colors' => [
+ '#FF0000',
],
- ]);
+ ]]);
}
}
diff --git a/tests/TableColumnLinkTest.php b/tests/TableColumnLinkTest.php
index c727d318a5..8d6afe6ebe 100644
--- a/tests/TableColumnLinkTest.php
+++ b/tests/TableColumnLinkTest.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Tests;
use Atk4\Core\Phpunit\TestCase;
+use Atk4\Data\Model;
use Atk4\Data\Persistence;
use Atk4\Ui\Table;
@@ -24,11 +25,11 @@ protected function setUp(): void
],
];
$db = new Persistence\Array_($arr);
- $m = new \Atk4\Data\Model($db, ['table' => 'table']);
+ $m = new Model($db, ['table' => 'table']);
$m->addField('name');
$m->addField('ref');
$m->addField('salary');
- $this->table = new \Atk4\Ui\Table();
+ $this->table = new Table();
$this->table->invokeInit();
$this->table->setModel($m, ['name', 'ref']);
}
@@ -269,11 +270,11 @@ public function testLink10(): void
],
];
$db = new Persistence\Array_($arr);
- $m = new \Atk4\Data\Model($db, ['table' => 'table']);
+ $m = new Model($db, ['table' => 'table']);
$m->addField('name');
$m->addField('ref');
$m->addField('salary');
- $this->table = new \Atk4\Ui\Table();
+ $this->table = new Table();
$this->table->invokeInit();
$this->table->setModel($m, ['name', 'ref']);
diff --git a/tests/TableTest.php b/tests/TableTest.php
index 9b6d3ff215..357832c156 100644
--- a/tests/TableTest.php
+++ b/tests/TableTest.php
@@ -5,6 +5,7 @@
namespace Atk4\Ui\Tests;
use Atk4\Core\Phpunit\TestCase;
+use Atk4\Ui\Table;
class TableTest extends TestCase
{
@@ -13,7 +14,7 @@ class TableTest extends TestCase
*/
public function testAddColumnWithoutModel(): void
{
- $t = new \Atk4\Ui\Table();
+ $t = new Table();
$t->invokeInit();
$t->setSource([
['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4],
@@ -21,12 +22,12 @@ public function testAddColumnWithoutModel(): void
]);
// 4 ways to add column
- $t->addColumn(null, new \Atk4\Ui\Table\Column\Link('test.php?id=1'));
+ $t->addColumn(null, new Table\Column\Link('test.php?id=1'));
// multiple ways to add column which doesn't exist in model
- $t->addColumn('five', new \Atk4\Ui\Table\Column\Link('test.php?id=1'));
- $t->addColumn('seven', [\Atk4\Ui\Table\Column\Link::class, ['id' => 3]]);
- $t->addColumn('eight', \Atk4\Ui\Table\Column\Link::class);
+ $t->addColumn('five', new Table\Column\Link('test.php?id=1'));
+ $t->addColumn('seven', [Table\Column\Link::class, ['id' => 3]]);
+ $t->addColumn('eight', Table\Column\Link::class);
$t->addColumn('nine');
$t->render();
diff --git a/tests/TagTest.php b/tests/TagTest.php
index 5f93ef740c..af10568e43 100644
--- a/tests/TagTest.php
+++ b/tests/TagTest.php
@@ -5,12 +5,13 @@
namespace Atk4\Ui\Tests;
use Atk4\Core\Phpunit\TestCase;
+use Atk4\Ui\App;
class TagTest extends TestCase
{
- public function getApp(): \Atk4\Ui\App
+ public function getApp(): App
{
- return new \Atk4\Ui\App(['catchExceptions' => false, 'alwaysRun' => false]);
+ return new App(['catchExceptions' => false, 'alwaysRun' => false]);
}
public function assertTagRender(string $html, array $args): void
diff --git a/tests/ViewTest.php b/tests/ViewTest.php
index 9ed0e2b70f..b42e96423b 100644
--- a/tests/ViewTest.php
+++ b/tests/ViewTest.php
@@ -6,15 +6,13 @@
use Atk4\Core\Phpunit\TestCase;
use Atk4\Ui\Exception;
+use Atk4\Ui\View;
class ViewTest extends TestCase
{
- /**
- * Test redering multiple times.
- */
- public function testMultipleRender(): void
+ public function testMultipleTimesRender(): void
{
- $v = new \Atk4\Ui\View();
+ $v = new View();
$v->set('foo');
$a = $v->render();
@@ -24,14 +22,12 @@ public function testMultipleRender(): void
public function testAddAfterRender(): void
{
- $this->expectException(Exception::class);
-
- $v = new \Atk4\Ui\View();
+ $v = new View();
$v->set('foo');
- $a = $v->render();
- \Atk4\Ui\View::addTo($v); // this should fail. No adding after rendering.
- $b = $v->render();
- $this->assertSame($a, $b);
+ $v->render();
+
+ $this->expectException(Exception::class);
+ View::addTo($v); // no adding after rendering
}
}