Navigation Menu

Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into feature/add-agile-data-example
Browse files Browse the repository at this point in the history
  • Loading branch information
romaninsh committed Jun 5, 2016
2 parents 0d54722 + e2a47d4 commit 5012ef7
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
@@ -1,3 +1,3 @@
[submodule "addons"]
path = addons
url = ./addons
url = https://github.com/atk4/atk4-addons.git
16 changes: 16 additions & 0 deletions README.md
@@ -0,0 +1,16 @@
# sink
Kitchen Sink Project for Agile Toolkit 4.3 - Demonstration of various features.

## Recommend a good example

Struggling with implementing something? Ask on forum and if your
problem is common, we will also add the solution here.

https://forum.agiletoolkit.org

## Add example yourself

Fork this repository and create pull request implementing new feature.
Use this as example:

https://github.com/atk4/sink/pull/3
19 changes: 11 additions & 8 deletions admin/lib/Admin.php
Expand Up @@ -26,33 +26,36 @@ function init() {
}
function initLayout(){
parent::initLayout();
$this->page_object->add('View_ForkMe');
if(!$_GET['cut_page'])$this->page_object->add('View_ForkMe');

}

function initBasic(){
$sm = $this->api->menu->addMenu('Core Features');

$sm ->addMenuItem('core/hello', 'Hello World');
$sm ->addMenuItem('core/form', 'Basic Form');
$sm ->addItem('Hello World', 'core/hello');
$sm ->addItem('Basic Form', 'core/form');
$sm ->addItem('Validation', 'core/validation');
$sm ->addItem('Virtual Page', 'core/vp');

$sm = $this->api->menu->addMenu('JavaScript');

$sm ->addMenuItem('js/timepicker', 'TimePicker');
$sm ->addMenuItem('js/boys-n-girls', 'Boys and Girls');
$sm ->addItem('TimePicker', 'js/timepicker');
$sm ->addItem('Boys and Girls', 'js/boys-n-girls');
$sm ->addItem('Dog and Cat', 'js/dog-n-cat');

$sm = $this->api->menu->addMenu('Agile Data');
$sm->addItem('.. vs Slick 3.1.0 (scala)','db/slick');
$sm->addItem('Readme Example','db/example');

$sm = $this->api->menu->addMenu('Real-time components');

$sm ->addMenuItem('realtime/console', 'Real-time console');
$sm ->addItem('Real-time console', 'realtime/console');

$sm = $this->api->menu->addMenu('Miscelanious');

$sm ->addMenuItem('misc/alert-button', 'Alert Button');
$sm ->addMenuItem('misc/virtual-pages', 'Virtual Pages');
$sm ->addItem('Alert Button', 'misc/alert-button');
$sm ->addItem('Virtual Pages', 'misc/virtual-pages');

try {
$this->dbConnect();
Expand Down
153 changes: 153 additions & 0 deletions admin/page/core/validation.php
@@ -0,0 +1,153 @@
<?php
class page_core_validation extends Page {

function page_index(){
$this->add('View_Hint')->set('This example clarifies the usage of the validation hooks in ATK 4.3+');

$t = $this->add('Tabs');

$t->addTabURL('./submit','onSubmit');
$t->addTabURL('./validator','validator');
$t->addTabURL('./validator2','validator2');
$t->addTabURL('./validator3','validator3');
$t->addTabURL('./callback','callback');
$t->addTabURL('./class','class');
}

/**
* This demonstrates backwards-compatible validation on submit.
* http://book.agiletoolkit.org/views/form/validation.html#form-validation-examples
*
* Although documentation is using older method displayFieldError(),
* which should be updated to simply error()
*/
function page_submit() {
$f = $this->add('Form');
$f->addField('large_number');
$f->addField('mandatory');
$f->addField('mandatory2')->validateNotNull();
$f->addSubmit();

$f->onSubmit(function($f){
if($f['large_number']<1000)return $f->error('large_number','is not large enough');
if(!$f['mandatory'])return $f->error('mandatory','write something here');
return 'all good';
});
}

/**
* This takes advantage of a new "validator" class, which is described here
* http://book.agiletoolkit.org/controller/validator.html
*
* We are using field->validate() method, which basically will associate
* validation string with the field
*/
function page_validator() {
$f = $this->add('Form');
$f->addField('large_number')->validate('>1000?is not large enough');
$f->addField('mandatory')->validate('required');
$f->addField('mandatory2')->validateNotNull();
$f->addSubmit();

$f->onSubmit(function($f){
return 'all good';
});
}

/**
* This also uses Controller_Validator, but calls it through $form->validate()
* This method allows you to define multiple rules with a single call and is
* directly passed to is(). Also when calling through validate(), this
* also binds validation to 'validate' hook.
*/
function page_validator2() {
$f = $this->add('Form');
$f->addField('large_number');
$f->addField('mandatory');
$f->addField('mandatory2')->validateNotNull();

$f->validate([
'large_number|>1000?is not large enough',
'mandatory|required'
]);

$f->addSubmit();

$f->onSubmit(function($f){
return 'all good';
});
}

/**
* This approach uses validator manually, and performs validation from onSubmit
* method, but still uses the Controller_Validator. I recommend that you
* use validator/validator2 approach.
*/
function page_validator3() {
$f = $this->add('Form');
$f->addField('large_number');
$f->addField('mandatory');
$f->addField('mandatory2')->validateNotNull();


$f->addSubmit();

$f->onSubmit(function($f){
$f->add('Controller_Validator')->is([
'large_number|>1000?is not large enough',
'mandatory|required'
])->now();

return 'all good';
});
}

/**
* Controller_Validator also supports your own callbacks, like below.
* I am also using post-validate hook for my manual call-back, because
* it's what validate() method uses.
*/
function page_callback() {
$f = $this->add('Form');
$f->addField('large_number')->validate(function($v,$a){ if($a<1000)$v->fail('is not large enough'); });
$f->addField('mandatory');
$f->addHook('post-validate', function($f){
if(!$f['mandatory'])
$f->error('mandatory','write something here');

/*
* also works, but longer
throw $this->exception('write something here','ValidityCheck')
->setField('mandatory');
*/
});
$f->addField('mandatory2')->validateField(function($f){ if(!$f->get())return 'must not be null'; });
$f->addSubmit();

$f->onSubmit(function($f){
return 'all good';
});
}

/**
* This demonstrates how validation works in a custom class, with redefining
* performValidation method().
*/
function page_class() {
$f = $this->add('Form');
$f->addField('LargeNumber','large_number');
$f->addField('mandatory');
$f->addField('mandatory2')->validateNotNull();
$f->addSubmit();

$f->onSubmit(function($f){
return 'all good';
});
}
}

class Form_Field_LargeNumber extends Form_Field_Line {
function performValidation() {
if($this->get()<1000) $this->form->error($this->short_name,'too small');
}
}
33 changes: 33 additions & 0 deletions admin/page/js/dogncat.php
@@ -0,0 +1,33 @@
<?php
/**
* Thanks to https://forum.agiletoolkit.org/t/why-do-i-have-to-use-a-chain-of-return-after-a-js-reload/188
* for this example idea
*/
class page_js_dogncat extends Page
{
public $title='Dog and Cat - javascript element reloading';

/**
* Initialize the page
*
* @return void
*/
function init()
{
parent::init();

$vm=$this->add('View_Box')->set('Nothing');

if($_GET['dog'])$vm->set('It is the dog');
if($_GET['cat'])$vm->set('It is the cat');

$button=$this->add('Button');
$button->set('Dog');
$button->on('click',$vm->js()->reload(['dog'=>true]));

$button=$this->add('Button');
$button->set('Cat');
$button->on('click',$vm->js()->reload(['cat'=>true]));

}
}
100 changes: 99 additions & 1 deletion admin/page/misc/virtualpages.php
Expand Up @@ -5,7 +5,81 @@ class page_misc_virtualpages extends Page {
function init() {
parent::init();

$this->add('View_Info')->set('This is main page');

// Demo 1
$this->add('View_Info')->set('You can get the manual URL of a virtual page and use it as you wish');

$vp = $this->add('VirtualPage');
$vp->set(function($p){
$p->add('View_Info')->set('you are now on a virtual page');
});

$this->add('Button')->link($vp->getURL());

// Demo 2

$this->add('HR');

$this->add('View_Info')->set('VirtualPage does not normally render, but you can add it into various views for
som added effects. For example if you add $vp into a Button, you can use click() method. The second button will only respond if you move your mouse cursor directly over the icon');

$this->add('Button')->set('Button 1')->add('VirtualPage')->bindEvent()->set(function($p){
$p->add('View_Info')->set('Clicked button 1');
});

$this->add('Button')->set(['Button 2','icon'=>'check'])->add('VirtualPage')->bindEvent('Mouseovered the icon?','mouseenter','.icon-check')->set(function($p){
$p->add('View_Info')->set('Hovered icon of Button 2');
});

$this->add('HR');

// Demo 3

$this->add('View_Info')->set('VirtualPage is also integrated into other views in Agile Toolkit. For example on() event uses Virtual Page for doing call-backs.');

// Call-back is funneled into enternal VirtualPage.
$this->add('Button')->set('click me')->on('click',function($b){ return $b->fadeOut('slow'); });

$this->add('Button')->set(['hover my icon', 'icon'=>'check'])->on('mouseleave','.icon-check',function($b){ return $b->fadeOut('slow'); });

// Another example is Real-time Console that also uses Virtual Page.

$this->add('HR');

// Demo 4

$this->add('View_Info')->set('As the previous example(s) use custom events and custom selectors, we can now combine virtual page with grid');

$gr = $this->add('SampleGrid');
$gr->addColumn('button','test1');
if(isset($_GET['test1']))$this->js()->univ()->successMessage('Old-style buttons on a grid require checking of _GET argument and executing. ID='.$_GET['test1'])->execute();


$gr->addColumn('template','test2')->setTemplate('<button data-id="{$id}" class="atk-button-small test2">Test2</button>');
$gr->on('click', '.test2', function($js, $data){ return $js->univ()->successMessage('With on() and virtual page, we know id='.$data['id']); });


$vp = $this->add('VirtualPage');
$gr->addColumn('template','test3')->setTemplate('<button data-id="{$id}" class="atk-button-small test3">Test3</button>');
$gr->on('click', '.test3')->univ()->dialogURL('Dialog here', [ $vp->getURL(), 'id'=>$this->js()->_selectorThis()->data('id')]);
$vp->set(function($p){
$p->add('View_Info')->set('Using virtual page we can now get id='.$_GET['id']);
});


$vp = $gr->add('VirtualPage');
$vp->addColumn('test4','Delete', ['icon'=>'trash']);
$gr->js(true)->_selector('.pb_test4')->addClass('atk-swatch-red');
$vp->set(function($p){
$p->add('View_Info')->set('A more integrated way to get id='.$p->id);
});


$this->add('HR');

// Demo 5

$this->add('View_Info')->set('Virtual pages are used to create page within a page. Here you see a button, that opens a "virtual page" that does not have an URL of its own, but will be triggered by a view and will take over rendering, when the dialog is displayed.');

$vp1 = $this->add('VirtualPage','vp1');
$vp1->set(function ($p1) {
Expand All @@ -20,5 +94,29 @@ function init() {
});

$this->add('Button')->set('Open Virtual Page1')->js('click')->univ()->frameURL('Page 1',$vp1->getURL(),['width'=>500,'height'=>300]);




}



}

class SampleGrid extends Grid {
function init(){
parent::init();

$m = $this->add('Model');
$m->addField('name');
$m->addField('surname');
$m->setSource('Array',[
['name'=>'Vinny', 'surname'=>'Sihra'],
['name'=>'Zoe', 'surname'=>'Shatwell'],
['name'=>'Darcy', 'surname'=>'Wild'],
]);

$this->setModel($m);
}
}
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"type":"project",
"require":{
"atk4\/atk4":"dev-master",
"atk4\/atk4":"*",
"educoder\/pest":"1.0.0"
},
"autoload":{
Expand Down

0 comments on commit 5012ef7

Please sign in to comment.