-
Notifications
You must be signed in to change notification settings - Fork 108
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
romaninsh
merged 35 commits into
epic/atk-core-refactor
from
feature/refactor-columns-fields
Sep 14, 2017
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a8f452a
Added comments.
romaninsh 27e3be4
a lot of refactoring for Aglie UI 1.2
romaninsh 8d5f06c
Apply fixes from StyleCI
romaninsh 54999d7
Merge branch 'feature/add-form-validation' into feature/refactor-colu…
romaninsh 324833d
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh 1bdaa6d
work in progress
romaninsh 8a52b73
form testing file
romaninsh 37f910c
Apply fixes from StyleCI
romaninsh 1c9f469
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh 7449eb2
Merge branch 'feature/misc-improvements' into feature/refactor-column…
romaninsh 1ae13af
still working on this
romaninsh e7ba7f9
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh bb68906
work in progress
romaninsh b286a53
Apply fixes from StyleCI
romaninsh fcabc87
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh 67010de
tabs.pug wouldn't compile.
romaninsh d07f94f
Merge branch 'feature/refactor-columns-fields' of github.com:atk4/ui …
romaninsh 92ab722
Merge branch 'develop' into feature/refactor-columns-fields
romaninsh df986d8
Refactored addField() arguments for #187
romaninsh 1a03993
Apply fixes from StyleCI
romaninsh 337e34b
Furher implement addField() refactor
romaninsh 338919d
Merge branch 'feature/refactor-columns-fields' of github.com:atk4/ui …
romaninsh 2191d04
Apply fixes from StyleCI
romaninsh 6797bf9
Refactor form demo and resolve #187
romaninsh 676c152
rewriting form documentation
romaninsh ef6a600
Merge branch 'feature/refactor-columns-fields' of github.com:atk4/ui …
romaninsh 3e2a2d7
Apply fixes from StyleCI
romaninsh c191776
added documentation
romaninsh 16a3356
Merge branch 'feature/refactor-columns-fields' of github.com:atk4/ui …
romaninsh ad2e8d7
Apply fixes from StyleCI
romaninsh b8b995e
Merge branch 'epic/atk-core-refactor' into feature/refactor-columns-f…
romaninsh 5e7a633
Addressed Imant's change request
romaninsh b6f7675
Apply fixes from StyleCI
romaninsh 0324dd4
I think this was used somewhere, forgot to add
romaninsh 068a9f6
Apply fixes from StyleCI
romaninsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
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'])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and i think it will change again, now it's |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
|
||
|
||
.. _callback: | ||
|
||
Introduction | ||
------------ | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.