Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big addColumn, addField and Seed refactor (PART1) #179

Merged
merged 35 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a8f452a
Added comments.
romaninsh Jun 18, 2017
27e3be4
a lot of refactoring for Aglie UI 1.2
romaninsh Jun 19, 2017
8d5f06c
Apply fixes from StyleCI
romaninsh Jun 19, 2017
54999d7
Merge branch 'feature/add-form-validation' into feature/refactor-colu…
romaninsh Jun 19, 2017
324833d
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh Jun 25, 2017
1bdaa6d
work in progress
romaninsh Jun 25, 2017
8a52b73
form testing file
romaninsh Jun 25, 2017
37f910c
Apply fixes from StyleCI
romaninsh Jun 25, 2017
1c9f469
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh Jun 25, 2017
7449eb2
Merge branch 'feature/misc-improvements' into feature/refactor-column…
romaninsh Jul 9, 2017
1ae13af
still working on this
romaninsh Jul 9, 2017
e7ba7f9
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh Jul 23, 2017
bb68906
work in progress
romaninsh Aug 25, 2017
b286a53
Apply fixes from StyleCI
romaninsh Aug 25, 2017
fcabc87
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh Sep 1, 2017
67010de
tabs.pug wouldn't compile.
romaninsh Sep 1, 2017
d07f94f
Merge branch 'feature/refactor-columns-fields' of github.com:atk4/ui …
romaninsh Sep 3, 2017
92ab722
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh Sep 3, 2017
df986d8
Refactored addField() arguments for #187
romaninsh Sep 3, 2017
1a03993
Apply fixes from StyleCI
romaninsh Sep 3, 2017
337e34b
Furher implement addField() refactor
romaninsh Sep 4, 2017
338919d
Merge branch 'feature/refactor-columns-fields' of github.com:atk4/ui …
romaninsh Sep 4, 2017
2191d04
Apply fixes from StyleCI
romaninsh Sep 4, 2017
6797bf9
Refactor form demo and resolve #187
romaninsh Sep 6, 2017
676c152
rewriting form documentation
romaninsh Sep 6, 2017
ef6a600
Merge branch 'feature/refactor-columns-fields' of github.com:atk4/ui …
romaninsh Sep 6, 2017
3e2a2d7
Apply fixes from StyleCI
romaninsh Sep 6, 2017
c191776
added documentation
romaninsh Sep 7, 2017
16a3356
Merge branch 'feature/refactor-columns-fields' of github.com:atk4/ui …
romaninsh Sep 10, 2017
ad2e8d7
Apply fixes from StyleCI
romaninsh Sep 10, 2017
b8b995e
Merge branch 'epic/atk-core-refactor' into feature/refactor-columns-f…
romaninsh Sep 11, 2017
5e7a633
Addressed Imant's change request
romaninsh Sep 14, 2017
b6f7675
Apply fixes from StyleCI
romaninsh Sep 14, 2017
0324dd4
I think this was used somewhere, forgot to add
romaninsh Sep 14, 2017
068a9f6
Apply fixes from StyleCI
romaninsh Sep 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 159 additions & 60 deletions demos/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,170 @@
*/
require 'init.php';

$layout->add(new \atk4\ui\View([
'Forms below focus on Data integration and automated layouts',
'ui'=> 'ignored warning message',
]));

$layout->add(new \atk4\ui\Header(['DefaultForm', 'size'=>2]));

$a = [];
$m_register = new \atk4\data\Model(new \atk4\data\Persistence_Array($a));
$m_register->addField('name');
$m_register->addField('email');
$m_register->addField('is_accept_terms', ['type'=>'boolean', 'mandatory'=>true]);

$f = $layout->add(new \atk4\ui\Form(['segment'=>true]));
$f->setModel($m_register);

$f->onSubmit(function ($f) {
if ($f->model['name'] != 'John') {
return $f->error('name', 'Your name is not John! It is "'.$f->model['name'].'". It should be John. Pleeease!');
} else {
return [
$f->jsInput('email')->val('[email protected]'),
$f->jsField('is_accept_terms')->checkbox('set checked'),
];
}
});

$layout->add(new \atk4\ui\Header(['Another Form', 'size'=>2]));

$f = $layout->add(new \atk4\ui\Form(['segment']));
$f->setModel(new \atk4\data\Model());
$tabs = $app->add('Tabs');

$f->addHeader('Example fields added one-by-one');
$f->addField('name');
$f->addField('email');
////////////////////////////////////////////
$tab = $tabs->addTab('Basic Use');

$f->addHeader('Example of field grouping');
$gr = $f->addGroup('Address with label');
$gr->addField('address', ['width'=>'twelve']);
$gr->addField('code', ['Post Code', 'width'=>'four']);
$tab->add(['Header', 'Very simple form']);

$gr = $f->addGroup(['width'=>'two']);
$gr->addField('city');
$gr->addField('country');
$form = $tab->add('Form');
$form->addField('email');
$form->onSubmit(function ($form) {
// implement subscribe here

return $form->success('Subscribed '.$form->model['email'].' to newsletter.');
});

$gr = $f->addGroup(['Name', 'inline'=>true]);
$gr->addField('first_name', ['width'=>'eight']);
$gr->addField('middle_name', ['width'=>'three', 'disabled'=>true]);
$gr->addField('last_name', ['width'=>'five']);

$f->onSubmit(function ($f) {
$errors = [];

foreach ($f->model->elements as $name=>$ff) {
if ($name == 'id') {
continue;
}
$form->buttonSave->set('Subscribe');
$form->buttonSave->icon = 'mail';

$tab->add(['Header', 'But very flexible']);

$form = $tab->add('Form');
$g = $form->addGroup(['width'=>'three']);
$g->addField('name');
$g->addField('surname');
$g->addField('gender', ['Dropdown', 'values'=>['Female', 'Male']]);

$tab->add(['Header', 'Comparing Field type vs Decorator class']);
$form = $app->add('Form');
$form->addField('date1', null, ['type'=>'date']);
$form->addField('date2', ['Calendar', 'type'=>'date']);

$form->onSubmit(function ($form) {
echo 'date1 = '.print_r($form->model['date1'], true).' and date2 = '.print_r($form->model['date2'], true);
});

////////////////////////////////////////////////////////////
$tab = $tabs->addTab('Handler Output');

$tab->add(['Header', 'Form can respond with manually generated error']);
$form = $tab->add('Form');
$form->addField('email');
$form->onSubmit(function ($form) {
return $form->error('email', 'some error action '.rand(1, 100));
});

$tab->add(['Header', '..or success message']);
$form = $tab->add('Form');
$form->addField('email');
$form->onSubmit(function ($form) {
return $form->success('form was successful');
});

$tab->add(['Header', 'Any other view can be output']);
$form = $tab->add('Form');
$form->addField('email');
$form->onSubmit(function ($form) {
$view = new \atk4\ui\Message('some header');
$view->init();
$view->text->addParagraph('some text '.rand(1, 100));

return $view;
});

$tab->add(['Header', 'jsAction can be used too']);
$form = $tab->add('Form');
$field = $form->addField('email');
$form->onSubmit(function ($form) use ($field) {
return $field->jsInput()->val('random is '.rand(1, 100));
});

/////////////////////////////////////////////////////////////////////
$tab = $tabs->addTab('Handler Safety');

$tab->add(['Header', 'Form handles errors (PHP 7.0+)', 'size'=>2]);

$form = $tab->add('Form');
$form->addField('email');
$form->onSubmit(function ($form) {
$o = new \StdClass();

return $o['abc'];
});

$tab->add(['Header', 'Form handles random output', 'size'=>2]);

$form = $tab->add('Form');
$form->addField('email');
$form->onSubmit(function ($form) {
echo 'some output here';
});

$tab->add(['Header', 'Form shows Agile exceptions', 'size'=>2]);

$form = $tab->add('Form');
$form->addField('email');
$form->onSubmit(function ($form) {
$form->factory([]);
});

/////////////////////////////////////////////////////////////////////
$tab = $tabs->addTab('Complex Examples');

$tab->add(['Header', 'Conditional response']);

$a = [];
$m_register = new \atk4\data\Model(new \atk4\data\Persistence_Array($a));
$m_register->addField('name');
$m_register->addField('email');
$m_register->addField('is_accept_terms', ['type'=>'boolean', 'mandatory'=>true]);

$f = $tab->add(new \atk4\ui\Form(['segment'=>true]));
$f->setModel($m_register);

$f->onSubmit(function ($f) {
if ($f->model['name'] != 'John') {
return $f->error('name', 'Your name is not John! It is "'.$f->model['name'].'". It should be John. Pleeease!');
} else {
return [
$f->jsInput('email')->val('[email protected]'),
$f->jsField('is_accept_terms')->checkbox('set checked'),
];
}
});

////////////////////////////////////////
$tab = $tabs->addTab('Layout Control');

$tab->add(new \atk4\ui\Header(['Shows example of grouping and multiple errors']));

$f = $tab->add(new \atk4\ui\Form(['segment']));
$f->setModel(new \atk4\data\Model());

$f->addHeader('Example fields added one-by-one');
$f->addField('name');
$f->addField('email');

$f->addHeader('Example of field grouping');
$gr = $f->addGroup('Address with label');
$gr->addField('address', ['width'=>'twelve']);
$gr->addField('code', ['width'=>'four'], ['caption'=>'Post Code']);

$gr = $f->addGroup(['width'=>'two']);
$gr->addField('city');
$gr->addField('country');

$gr = $f->addGroup(['Name', 'inline'=>true]);
$gr->addField('first_name', ['width'=>'eight']);
$gr->addField('middle_name', ['width'=>'three', 'disabled'=>true]);
$gr->addField('last_name', ['width'=>'five']);

$f->onSubmit(function ($f) {
$errors = [];

foreach ($f->model->elements as $name=>$ff) {
if ($name == 'id') {
continue;
}

if ($f->model[$name] != 'a') {
$errors[] = $f->error($name, 'Field '.$name.' should contain exactly "a", but contains '.$f->model[$name]);
}
if ($f->model[$name] != 'a') {
$errors[] = $f->error($name, 'Field '.$name.' should contain exactly "a", but contains '.$f->model[$name]);
}
}

return $errors ?: $f->success('No more errors', 'so we have saved everything into the database');
});
return $errors ?: $f->success('No more errors', 'so we have saved everything into the database');
});

//$layout->renderAll();
//$layout->template->appendHTML('HEAD', $layout->getJS());
$tabs->addTabURL('Form Database', ['form2.php', 'layout'=>'Centered']);
75 changes: 75 additions & 0 deletions demos/form5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No link to this demo page in menu.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be OK for now, i suppose we will be re-making the demo suite anyways.


require 'init.php';

$layout->add(new \atk4\ui\View([
'Forms below focus on Data integration and automated layouts',
'ui'=> 'ignored warning message',
]));

$cc = $layout->add('Columns');
$f = $cc->addColumn()->add(new \atk4\ui\Form());

// adding field without model creates a regular line
$f->addField('one');

// Second argument string is used as a caption
$f->addField('two', 'Caption');

// Array second is a default seed for default line field
$f->addField('three', ['caption'=>'Caption2']);

// Use zeroth argument of the seed to specify standard class
$f->addField('four', ['Checkbox', 'caption'=>'Caption2']);

// Use explicit object for user-defined or 3rd party field
$f->addField('five', new \atk4\ui\FormField\Checkbox());

// Objects still accept seed
$f->addField('six', new \atk4\ui\FormField\Checkbox(['caption'=>'Caption3']));

$a = [];
$m = new \atk4\data\Model(new \atk4\data\Persistence_Array($a));

// model field uses regular line form field by default
$m->addField('one');

// caption is a top-level property of a field
$m->addField('two', ['caption'=>'Caption']);

// ui can also specify caption which is a form-specific
$m->addField('three', ['ui'=>['form'=>['caption'=>'Caption']]]);

// type is converted into Checkbox form field with caption as a seed
$m->addField('four', ['type'=>'boolean', 'ui'=>['form'=>['caption'=>'Caption2']]]);

// Can specify class for a checkbox explicitly
$m->addField('five', ['ui'=>['form'=>['Checkbox', 'caption'=>'Caption3']]]);

// Form-specific caption overrides general caption of a field. Also you can specify object instead of seed
$m->addField('six', ['caption'=>'badcaption', 'ui'=>['form'=>new \atk4\ui\FormField\Checkbox(['caption'=>'Caption4'])]]);

$f = $cc->addColumn()->add(new \atk4\ui\Form());
$f->setModel($m);

// Next form won't initalize default fields, but we'll add them individually
$f = $cc->addColumn()->add(new \atk4\ui\Form());
$f->setModel($m, false);

// adding that same field but with custom form field seed
$f->addField('one', ['caption'=>'Caption0']);

// another way to override caption
$f->addField('two', 'Caption2');

// We can override type, but seed from model will still be respected
$f->addField('three', ['Checkbox']);

// We override type and caption here
$f->addField('four', ['Line', 'caption'=>'CaptionX']);

// We can specify form field object. It's still seeded with caption from model.
$f->addField('five', new \atk4\ui\FormField\Checkbox());

// can add field that does not exist in a model
$f->addField('nine', new \atk4\ui\FormField\Checkbox(['caption'=>'Caption3']));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really good option. Previously in toolkit I have had issues with this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and i think it will change again, now it's new Checkbox('Caption 4')

2 changes: 1 addition & 1 deletion demos/layouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$buttons = [
['page' => ['layouts_nolayout'], 'title' => 'HTML without layout'],
['page' => ['layouts_manual'], 'title' => 'Manual layout'],
['page' => ['header', 'layout'=>'centered'], 'title' => 'Centered layout'],
['page' => ['header', 'layout'=>'Centered'], 'title' => 'Centered layout'],
['page' => ['layouts_admin'], 'title' => 'Admin Layout'],
['page' => ['layouts_error'], 'title' => 'Exception Error'],
];
Expand Down
6 changes: 3 additions & 3 deletions docs/app.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
.. _app:


Purpose of App class
====================

.. php:class:: App

App is a mandatory object that's essential for Agile UI to operate. If you don't create App object explicitly, it
Expand All @@ -14,9 +17,6 @@ In most use-scenarios, however, you would create instance of an App class yourse
$app->initLayout('Centered');
$app->layout->add('LoremIpsum');


Purpose of App class
====================
As you add one component into another, they will automatically inherit reference to App class. App
class is an ideal place to have all your environment configured and all the dependencies defined that
other parts of your applications may require.
Expand Down
3 changes: 0 additions & 3 deletions docs/callbacks.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@


.. _callback:

Introduction
------------

Expand Down
Loading