Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added pages for form layout demonstration

  • Loading branch information...
commit f1a06a82e74595831525275be1a1ab615d3371c2 1 parent dcdf734
@romaninsh romaninsh authored
View
10 example/learn2/lib/Model/Borrower.php
@@ -10,12 +10,12 @@ function init(){
$this->b=$this->join('library_borrowing.library_member_id');
- $this->b->hasOne('Staff','verified_by');
- $this->b->addField('borrowed');
- $this->b->addField('is_returned');
- $this->b->addField('returned');
+ $this->b->hasOne('Staff','verified_by')->sortable(true);
+ $this->b->addField('borrowed')->sortable(true);
+ $this->b->addField('is_returned')->sortable(true);
+ $this->b->addField('returned')->sortable(true);
- $this->b->join('library_book')->addField('book_name','name');
+ $this->b->join('library_book')->addField('book_name','name')->sortable(true);
// Showing only if borrowed
//$this->addCondition('is_returned',false);
View
2  example/learn2/lib/Model/Borrowing.php
@@ -6,7 +6,7 @@ function init(){
$this->hasOne('Book');
$this->hasOne('Member');
- $this->hasOne('Staff','verified_by');
+ $this->hasOne('Staff','verified_by')->sortable(true);
$this->addField('borrowed')->type('date')->defaultValue(date('Y-m-d'));
View
4 example/learn2/lib/Model/Member.php
@@ -4,8 +4,8 @@ class Model_Member extends Model_Table {
function init(){
parent::init();
- $this->addField('name');
- $this->addField('card_number');
+ $this->addField('name')->sortable(true);
+ $this->addField('card_number')->sortable(true);
// We can define theese only if we plan to reference them. While it makes sense to see curent
// member's borrowed book, there is no need to see all the preious borrowings, so i commented
View
2  lib/Model/Employee.php
@@ -8,7 +8,7 @@ function init(){
->datatype('int');
$this->addField('salary')
- ->mandatory(true)
+ ->mandatory('Salary is required')
->datatype('money');
}
View
12 lib/Model/Menu.php
@@ -1,11 +1,11 @@
<?php
class Model_Menu extends hierarchy\Model_Array {
/** Convert array into proper format */
- function convertArray($array){
+ function convertArray($array,$prefix=''){
$res=array();
foreach($array as $key=>$row){
$r=array(
- 'page'=>$key,
+ 'page'=>$this->api->url($prefix.$key),
'name'=>$row
);
@@ -13,7 +13,7 @@ function convertArray($array){
$r['children']=$r['name'];
$r['name']=array_shift($r['children']);
}
- if($r['children'])$r['children']=$this->convertArray($r['children']);
+ if($r['children'])$r['children']=$this->convertArray($r['children'],$prefix.$key.'/');
$res[]=$r;
}
@@ -23,12 +23,12 @@ function init(){
parent::init();
$this->setSource($this->convertArray(array(
- 'about'=>'About This Site',
+ 'index'=>'About This Site',
'gui'=>array(
'User Interface',
- 'form'=>'Form',
- 'grid'=>'Grid',
+ 'form'=>'Forms',
+ 'grid'=>'Grids',
'buttons'=>'Buttons',
'upload'=>'File Uploads',
),
View
43 page/index.php
@@ -1,43 +0,0 @@
-<?php
-class page_index extends Page {
- public $descr='This page shows the index of all the pages available under this installation of Agile Toolkit. Since all
- the pages are classes we can somewhat "peek" into them and grab the descriptions out, as we produce array with all
- examples and their descriptions';
- function init(){
- parent::init();
- $p=$this;
-
- $this->add('View_Error')->setHTML('This site is currendly being upgraded. Archives are always available at
- <a href="https://github.com/atk4/atk4-codepad" target="_blank">https://github.com/atk4/atk4-codepad</a>');
-
- /*
-
- $data=array();
- $files=$this->api->pathfinder->searchDir('page','');
- foreach($files as $key=>$val){
- $row=array();
- $name=preg_replace('/[^a-zA-Z0-9].* /','',$val);
-
- $row['name']=$name;
-
- $path=$this->api->locate('page',$name.'.php');
- $class='page_'.$name;
-
- include_once($path);
- $c=new $class;
- if(isset($c->skip))continue;
- $row['descr']=preg_replace('/([\.\?]).* /s','$1',@$c->descr);
- $data[]=$row;
- }
-
-
- $l=$this->add('Lister',null,null,array('view/example'));
- $l->setStaticSource($data);
- $l->safe_html_output=false;
- */
- }
-
- function defaultTemplate(){
- return array('page/index');
- }
-}
View
3  templates/default/form/mylayout.html
@@ -0,0 +1,3 @@
+<div>
+Hi. My Name is <?$name?> and my email is <?$email?>. I am writing to you because I'm willing to change my password to <?$password?>, i repeat <?$password2?>.
+</div>
View
4 templates/default/page/about.html
@@ -1,4 +0,0 @@
-<p>
-This is your first static page. Custom template is used for a page if it
-is found in this directory.
-</p>
View
83 templates/default/page/gui/form.html
@@ -2,7 +2,7 @@
<p>Form is a fundamental component of any web application. Agile Toolkit greatly simplifies form creation.</p>
-<?Example?>
+<?Example?>example 1
$form=$page->add('Form');
$form->addField('line','name');
$form->addField('line','surname');
@@ -14,12 +14,48 @@
}
<?/?>
+<?Example?>example 2
+$f=$page->add('Form');
+
+// email field
+$f->addField('line','email')
+ ->validateNotNull()
+ ->validateField('filter_var($this->get(), FILTER_VALIDATE_EMAIL)')
+ ;
+
+// Submit handling
+$f->addSubmit('Check email');
+if($f->isSubmitted()){
+ $f->js()->univ()->alert('Email '.$f->get('email').' is valid')->execute();
+}
+
+// Application is safe from arbitary code injection, but validate input at will
+<?/?>
+
+<?Example?>example 3
+$f=$page->add('Form');
+
+// using multiple validations on a same field
+$f->addField('line','username')->validateNotNull()
+ ->validateField('preg_match("/^[a-z]+$/",$this->get())')
+ ->validateField('strlen($this->get())>=6','Too short')
+ ->validateField('20>=strlen($this->get())','Too long');
+
+$f->addField('password','pasword')->validateNotNull();
+$f->addSubmit('Login');
+
+if($f->isSubmitted()){
+ $f->js()->univ()->alert('[Demo] Login Successful')->execute();
+}
+<?/?>
+
+
<h3>Form Elements</h3>
<p>There are many field types you can use with form. In addition you can add your own field types or use add-on which may provide additional types.</p>
-<?Example?>
+<?Example?>field types
$form=$page->add('Form');
$form->addComment('This form shows all sorts of fields you can use by default');
$form->addField('line','line');
@@ -45,7 +81,46 @@
<p>The most convenient way to use form is to have it's fields populated from a Model.</p>
-<?Example?>
-$form=$page->add('Form');
+<?Example?>model 1
+$form = $page->add('Form');
$form->setModel('Employee');
+$form->addSubmit();
+<?/?>
+
+<?Example?>model 2
+$f = $page->add('Form');
+
+// defining arary of fields to show and sequence order
+$f->setModel('Employee',array('name'));
<?/?>
+
+<?Example?>model 3
+$model = $page->add('Model_Employee');
+$model->addCondition('salary','<=',3000);
+
+$f=$page->add('Form');
+
+$f->setModel($model,array('name','salary'));
+$f->getElement('salary')->setFieldHint('Must not exceed 3000');
+$f->addSubmit();
+
+$f->onSubmit(function($f){
+ try {
+ $f->update()->js()->univ()->successMessage('Saved with id='.$f->model->id)->execute();
+ }catch(Exception $e){
+ $f->js()->univ()->alert('Failed to add record')->execute();
+ }
+});
+
+<?/?>
+
+
+
+
+
+
+
+
+
+
+
View
160 templates/default/page/gui/formstyle.html
@@ -0,0 +1,160 @@
+<h2>Form Styling Examples</h2>
+
+<p>First let's declare a form</p>
+<?Example?>StylingForm
+class StylingForm extends Form {
+ function init(){
+ parent::init();
+ $f=$this;
+
+ $f->addField('line','name')->validateNotNull()
+ ->setFieldHint('Click "Register" to see error');
+ $f->addField('line','email')
+ ->validateNotNull()
+ ->validateField('filter_var($this->get(), FILTER_VALIDATE_EMAIL)')
+ ;
+
+ $f->addField('password','password')->validateNotNull()
+ ->setProperty('max-length',30)->setFieldHint('30 characters maximum');
+
+ $p2=$f->addField('password','password2')
+ ->validateField('$this->get()==$this->owner->getElement("password")->get()',
+ 'Passwords do not match');
+
+
+
+
+ $f->addField('DatePicker','date_birth','Birthdate');
+
+ $f->addField('dropdown','age')
+ ->setValueList(array('','11 - 20', '21 - 30', '31 - 40'));
+
+ $f->addField('text','about')
+ ->setProperty('cols',45)->setProperty('rows','5')
+ ->validateField('5000>=strlen($this->get())','Too long');
+
+ $f->addField('radio','sex')
+ ->setValueList(array('m'=>'Male','f'=>'Female'))
+ ; // automatically validated to be one of value list
+
+
+
+ $f->addField('checkbox','agreeRules','I Agree to Rules and Terms'
+ )->validateNotNull('You must agree to the rules');
+
+
+ $js=array();
+ $this->js()->atk4_form('fieldError','password2','Passwords do not match');
+ $this->js()->atk4_form('fieldError','age','Age is not entered - sample longer error which may span');
+ $this->js()->atk4_form('fieldError','about','Sample error on textarea field');
+
+
+ $f->addSubmit('Submit');
+ }
+}
+<?/?>
+
+
+<?Example?>example 1
+$form=$page->add('Form');
+$form->setModel('Employee');
+
+$sep=$form->addSeparator();
+
+// Ordering controller can re-position child elements now or later
+$form->add('Order')->move($sep,'after','name')->now();
+<?/?>
+
+<h3>Styling - default</h3>
+
+<?ExecuteTrigger?>example 1
+$form=$page->add('StylingForm');
+<?/?>
+
+<h3>Styling - stacked</h3>
+<?ExecuteTrigger?>example 2
+// Stacked class puts labels on top of fields
+$form=$page->add('StylingForm');
+$form->addClass('stacked');
+<?/?>
+
+<h3>Styling - vertical 2 columns</h3>
+<?ExecuteTrigger?>example 3
+// Stacked class puts labels on top of fields
+$form=$page->add('StylingForm');
+$form->addClass('stacked atk-row');
+
+$form->template->trySet('fieldset','span6');
+$sep=$form->addSeparator('span6');
+$form->add('Order')->move($sep,'before','age')->now();
+<?/?>
+
+<h3>Styling - vertical 3 or more columns</h3>
+<?ExecuteTrigger?>example 4
+$form=$page->add('StylingForm');
+$form->addClass('stacked atk-row');
+
+// strategical placement of atk-row and spanX
+$form->template->trySet('fieldset','span3');
+$form->add('Order')
+ ->move('sex','before','age')
+ ->move($form->addSeparator('span3'),'before','password2')
+ ->move($form->addSeparator('span6'),'before','age')
+ ->now();
+
+<?/?>
+
+<h3>Styling - hybrid layouts</h3>
+<?ExecuteTrigger?>example 5
+// Stacked class puts labels on top of fields
+$form=$page->add('StylingForm');
+$form->addClass('stacked atk-row');
+
+// strategical placement of atk-row and spanX
+$form->template->trySet('fieldset','atk-row');
+
+$form->getElement('name')->template->trySet('row_class','span6');
+$form->getElement('email')->template->trySet('row_class','span6');
+
+$form->add('Order')
+ ->move($form->addSeparator('span3'),'after','email')
+ ->move($form->addSeparator('span3'),'after','password2')
+ ->move($form->addSeparator('span5'),'before','about')
+ ->now();
+
+<?/?>
+
+<h3>Styling - horizontal</h3>
+<?ExecuteTrigger?>example 6
+// Stacked class puts labels on top of fields
+$form=$page->add('StylingForm',null,null,array('form_horizontal'));
+
+$form->getElement('name')->template->trySet('row_class','span6');
+$form->getElement('email')->template->trySet('row_class','span6');
+
+//$form->getElement('email')->js(true)->parent()->next('div')->addClass('span4');
+
+$form->add('Order')
+ ->move($form->addSeparator('atk-row'),'after','email')
+ ->move($form->addSeparator('atk-row'),'before','about')
+ ->now();
+
+<?/?>
+
+<h3>Styling - empty template with custom layout</h3>
+<p>Although this might look like a mess, empty field helps you eliminate any form formatting. This way you can do simply output fields without worries.</p>
+<?ExecuteTrigger?>example 7
+$form=$page->add('StylingForm',null,null,array('form_empty'));
+<?/?>
+
+<p>Empty template in collaboration with custom layout can give you the most flexible field configuration on a form.</p>
+
+<?ExecuteTrigger?>example 8
+$form=$page->add('StylingForm',null,null,array('form_empty'));
+$form->setLayout('form/mylayout');
+<?/?>
+
+Template:
+<div style="border: 1px solid black">
+ Hi. My Name is &lt;?$name?&gt; and my email is &lt;?$email?&gt;. I am writing to you because I'm willing to change my password to &lt;?$password?&gt;, i repeat &lt;?$password2?&gt;.
+</div>
View
50 templates/default/page/gui/validation.html
@@ -0,0 +1,50 @@
+<h2>Form Validation Examples</h2>
+
+<?Example?>example 1
+$f=$page->add('Form');
+
+$f->addField('line','email')
+ ->validateNotNull()
+ ->validateField(
+ 'filter_var($this->get(), FILTER_VALIDATE_EMAIL)');
+
+$f->addSubmit();
+<?/?>
+
+<?Example?>example 2
+$f=$page->add('Form');
+
+$f_email=$f->addField('line','email')
+ ->validateNotNull();
+
+$f->addSubmit();
+if($f->isSubmitted()){
+ // manually displaying error message
+ if($f->get('email')=='test@example.com'){
+ return $f_email->displayFieldError('Choose other email');
+ }
+}
+<?/?>
+
+<?Example?>example 3
+$f=$page->add('Form');
+
+$f_email=$f->addField('line','email')
+ ->validateNotNull();
+
+// Adding validation hook through closure
+$f_email->addHook('validate',function() use ($f_email){
+ if($f_email->get()=='test@example.com')
+ $f_email->displayFieldError('Choose other email');
+});
+
+$f->addSubmit();
+<?/?>
+
+<?Example?>example 4
+$f=$page->add('Form');
+
+// JavaScript-based validation
+$f->addField('line','age')->js(true)
+ ->univ()->numericField();
+<?/?>
View
18 templates/default/page/index.html
@@ -1,5 +1,17 @@
-<h1>Examples of Web Interfaces created with Agile Toolkit</h1>
-<p>Agile Toolkit is a powerful object-oriented platform for Web User Interface development in PHP. It focuses on seamless integration while being simple to learn. Filling the gaps between ORM and User Interface, Agile Toolkit reinvents web development. <a href="http://agiletoolkit.org/" target="_blank">Learn more.</a></p>
-<?$Content?>
+<h2>Agile Toolkit Demonstration</h2>
+
+<p>This demo website is designed to help you learn Agile Toolkit by focusing on a practical examples. Examples are surrounded by a extensive commentary</p>
+
+<h3>How to use this website</h3>
+<p>Left-side navigation contains links to some of the most popular examples stored here. There are many hidden examples, so do not forget to search the site.</p>
+
+<p>Below is an interactive demonstration. It contains the PHP source code and result produced by that code. You can <a href="/learn/install/how">run this example in your local installation of Agile Toolkit</a>.
+<?Example?>
+$page->add('HelloWorld');
+<?/?>
+
+<p>You can also download Codepad alltogether with all it's examples and run it on your local computer. <a href="https://github.com/atk4/atk4-codepad">Full sources of codepad are available as open-source</a>.</p>
+
+<?$Content?>
View
20 templates/default/shared.html
@@ -64,6 +64,26 @@
<div class="content-w-sidebar">
<div class="inner">
<?$Content?>
+
+<?Disqus?>
+<div class="hr"></div>
+
+<div id="disqus_thread"></div>
+<script type="text/javascript">
+/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
+var disqus_shortname = 'atkdemos'; // required: replace example with your forum shortname
+
+/* * * DON'T EDIT BELOW THIS LINE * * */
+(function() {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+})();
+</script>
+<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
+<a href="http://disqus.com" class="dsq-brlink"><span class="logo-disqus">Disqus</span></a>
+<?/?>
+
</div>
</div>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.