Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
romaninsh committed Feb 25, 2017
2 parents 3281e93 + d5125bd commit 0adda17
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 190 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ docs/build
/build
.DS_Store
*.codekit3

run_local.sh
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ Agile UI comes with many built-in components;

| Name | Description | Introduced |
| ---------------------------------------- | ---------------------------------------- | ---------- |
| Core | Template, Render Tree and various patterns | 0.1 |
| [Button](http://ui.agiletoolkit.org/demos/button.php) | Button in various variations including icons, labels, styles and tags | 0.1 |
| [Input](http://ui.agiletoolkit.org/demos/field.php) | Decoration of input fields, integration with buttons. | 0.2 |
| [JS](http://ui.agiletoolkit.org/demos/button2.php) | Assign JS events and abstraction of PHP callbacks. | 0.2 |
| [Header](http://ui.agiletoolkit.org/demos/header.php) | Simple view for header. | 0.3 |
| [Menu](http://ui.agiletoolkit.org/demos/layout2.php) | Horizontal and vertical multi-dimensional menus with icons. | 0.4 |
| [Form](http://ui.agiletoolkit.org/demos/form.php) | Validation, Interactivity, Feedback, Layouts, Field types. | 0.4 |
| Layouts 1 | Admin, Centered. | 0.4 |
| [Grid](http://ui.agiletoolkit.org/demos/grid.php) | Formatting, Columns, Status, Link, Template, Delete. | 0.5 |
| Core | Template, Render Tree and various patterns | 0.1 |
| [Button](http://ui.agiletoolkit.org/demos/button.php) [[source](https://github.com/atk4/ui/blob/develop/demos/button.php#L14)] | Button in various variations including icons, labels, styles and tags | 0.1 |
| [Input](http://ui.agiletoolkit.org/demos/field.php) [[source](https://github.com/atk4/ui/blob/develop/demos/field.php#L9)] | Decoration of input fields, integration with buttons. | 0.2 |
| [JS](http://ui.agiletoolkit.org/demos/button2.php) [[source](https://github.com/atk4/ui/blob/develop/demos/button2.php#L15)] | Assign JS events and abstraction of PHP callbacks. | 0.2 |
| [Header](http://ui.agiletoolkit.org/demos/header.php) [[source](https://github.com/atk4/ui/blob/develop/demos/header.php#L8)] | Simple view for header. | 0.3 |
| [Menu](http://ui.agiletoolkit.org/demos/layout2.php) [[source](https://github.com/atk4/ui/blob/develop/demos/layout2.php#L16)] | Horizontal and vertical multi-dimensional menus with icons. | 0.4 |
| [Form](http://ui.agiletoolkit.org/demos/form.php) [[source](https://github.com/atk4/ui/blob/develop/demos/form.php#L44)] | Validation, Interactivity, Feedback, Layouts, Field types. | 0.4 |
| [Layouts](http://ui.agiletoolkit.org/demos/layouts.php) [[source](https://github.com/atk4/ui/blob/develop/demos/layout.php#L9)] | Admin, Centered. | 0.4 |
| [Grid](http://ui.agiletoolkit.org/demos/grid.php) [[source](https://github.com/atk4/ui/blob/develop/demos/grid.php#L9)] | Formatting, Columns, Status, Link, Template, Delete. | 1.0 |
| GridAdvanced | Toolbar, Paginator, Quick-search, Expander, Actions. | 1.1 * |
| Messages | Such as "Info", "Error", "Warning" or "Tip" for easy use. | 1.1 * |
| Dialog | Modal dialog with dynamically loaded content. | 1.1 * |
| Relading | Dynamically re-render part of the UI. | 1.1 * |
| Actions | Extended buttons with various interactions | 1.1 * |
| CRUD | Create, List, Edit and Delete records (based on Advanced Grid) | 1.2 * |
| Messages | Such as "Info", "Error", "Warning" or "Tip" for easy use. | 1.0 |
| Layouts 2 | 4 Responsive: Admin, Centered, Site, Wide. | 1.2 * |
| Breadcrumb | Push links to pages for navigation. Wizard. | 1.3 * |
| Items, Cards | Responsive Items and Card implementaiton. | 1.4 * |
Expand Down
28 changes: 16 additions & 12 deletions demos/button2.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,33 @@

use \atk4\ui\Button;
use \atk4\ui\Buttons;
use \atk4\ui\H2;
use \atk4\ui\Header;

$layout->js(true, new \atk4\ui\jsExpression('$.fn.api.settings.successTest = function(response) {
if(response && response.eval) {
var result = function(){ eval(response.eval); }.call(this.obj);
}
return false;
}'));

$layout->add(new H2('Basic Button'));
$layout->add(new Header('Basic Button'));

// This button hides on page load
$b = $layout->add(new Button(['id'=>'b1']))->set('Hidden Button');
$b = $layout->add(new Button('Hidden Button'));
$b->js(true)->hide();

// This button hides when clicked
$b = $layout->add(new Button(['id'=>'b2']))->set('Hide on click Button');
$b->js('click')->hide();

$layout->add(new H2('Callbacks'));
$layout->add(new Header('Callbacks'));

$b = $layout->add(new Button('Hide button B'));
$b2 = $layout->add(new Button('B'));
$b->js('click', $b2->js()->hide('b2'))->hide('b1');

$layout->add(new Header('js() method'));

// On button click reload it and change it's title
$b = $layout->add(new Button(['id'=>'b3']))->set('Callback Test');
$b = $layout->add(new Button('Callback Test'));
$b->on('click', function ($b) {
return $b->text(rand(1, 20));
});

$b = $layout->add(new Button('success'));
$b->on('click', function ($b) {
return 'success';
});
3 changes: 2 additions & 1 deletion demos/grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

$bb->on('click', $g->js()->reload());

$g->setModel(new SomeData());
$g->setModel(new SomeData(), false);

$g->addColumn('name', new \atk4\ui\Column\Link(['details', 'id'=>'{$id}']));
$g->addColumn('surname', new \atk4\ui\Column\Template('<td class="warning">{$surname}</td>'));
$g->addColumn('title', new \atk4\ui\Column\Status([
Expand Down
42 changes: 20 additions & 22 deletions demos/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,32 @@

$layout = $app->layout;

if (!isset($layout->leftMenu)) {
return;
}

$layout->leftMenu->addItem(['Welcome Page', 'icon'=>'gift'], ['index']);
$layout->leftMenu->addItem(['Layouts', 'icon'=>'object group'], ['layouts']);
if (isset($layout->leftMenu)) {
$layout->leftMenu->addItem(['Welcome Page', 'icon'=>'gift'], ['index']);
$layout->leftMenu->addItem(['Layouts', 'icon'=>'object group'], ['layouts']);

$form = $layout->leftMenu->addGroup(['Form', 'icon'=>'edit']);
$form->addItem('Basics and Layouting', ['form']);
$form->addItem('Input Field Decoration', ['field']);
$form->addItem('Data Integration', ['form2']);
$form = $layout->leftMenu->addGroup(['Form', 'icon'=>'edit']);
$form->addItem('Basics and Layouting', ['form']);
$form->addItem('Input Field Decoration', ['field']);
$form->addItem('Data Integration', ['form2']);

$form = $layout->leftMenu->addGroup(['Grid', 'icon'=>'table']);
$form->addItem('Column Formats and Features', ['grid']);
$form = $layout->leftMenu->addGroup(['Grid', 'icon'=>'table']);
$form->addItem('Column Formats and Features', ['grid']);

$basic = $layout->leftMenu->addGroup(['Basics', 'icon'=>'cubes']);
$basic->addItem('Button', ['button']);
$basic->addItem('Header', ['header']);
$basic = $layout->leftMenu->addGroup(['Basics', 'icon'=>'cubes']);
$basic->addItem('Button', ['button']);
$basic->addItem('Header', ['header']);

$basic = $layout->leftMenu->addGroup(['Interactivity', 'icon'=>'talk']);
$basic->addItem('JavaScript Events', ['button2']);
$basic = $layout->leftMenu->addGroup(['Interactivity', 'icon'=>'talk']);
$basic->addItem('JavaScript Events', ['button2']);

$f = basename($_SERVER['PHP_SELF']);
$f = basename($_SERVER['PHP_SELF']);

// Would be nice if this would be a link.
$layout->menu->addItem()->add(new \atk4\ui\Button(['View Source', 'teal', 'icon'=>'github']))
->setAttr('target', '_blan')->on('click', new \atk4\ui\jsExpression('document.location=[];', ['https://github.com/atk4/ui/blob/develop/demos/'.$f]));
// Would be nice if this would be a link.
$layout->menu->addItem()->add(new \atk4\ui\Button(['View Source', 'teal', 'icon'=>'github']))
->setAttr('target', '_blan')->on('click', new \atk4\ui\jsExpression('document.location=[];', ['https://github.com/atk4/ui/blob/develop/demos/'.$f]));

$img = 'https://github.com/atk4/ui/raw/07208a0af84109f0d6e3553e242720d8aeedb784/public/logo.png';
$img = 'https://github.com/atk4/ui/raw/07208a0af84109f0d6e3553e242720d8aeedb784/public/logo.png';
}

require_once 'somedatadef.php';
26 changes: 21 additions & 5 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ class App
init as _init;
}

// @var string Name of application
public $title = 'Agile UI - Untitled Application';

public $layout = null; // the top-most view object

public $template_dir = null;

// @var string Name of skin
public $skin = 'semantic-ui';

/**
Expand All @@ -26,7 +28,7 @@ class App
*/
public $always_run = true;

private $run_called = false;
public $run_called = false;

public $ui_persistence = null;

Expand Down Expand Up @@ -58,13 +60,13 @@ public function __construct($defaults = [])
});
}

if (!$this->_initialized) {
//$this->init();
}

// Always run app on shutdown
if ($this->always_run) {
register_shutdown_function(function () {
if (!$this->_initialized) {
$this->init();
}

if (!$this->run_called) {
try {
$this->run();
Expand Down Expand Up @@ -301,11 +303,25 @@ public function getTag($tag = null, $attr = null, $value = null)
return "<$tag".($tmp ? (' '.implode(' ', $tmp)) : '').$postfix.'>'.($value ? $value."</$tag>" : '');
}

/**
* Encodes string - removes HTML special chars.
*
* @param string $val
*
* @return string
*/
public function encodeAttribute($val)
{
return htmlspecialchars($val);
}

/**
* Encodes string - removes HTML entities.
*
* @param string $val
*
* @return string
*/
public function encodeHTML($val)
{
return htmlentities($val);
Expand Down
16 changes: 14 additions & 2 deletions src/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Callback
use TrackableTrait;
use AppScopeTrait;

public $POST_trigger = false;

/**
* Executes user-specified action when call-back is triggered.
*
Expand All @@ -20,8 +22,14 @@ class Callback
*/
public function set($callback, $args = [])
{
if (isset($_GET[$this->name])) {
return call_user_func_array($callback, $args);
if ($this->POST_trigger) {
if (isset($_POST[$this->name])) {
return call_user_func_array($callback, $args);
}
} else {
if (isset($_GET[$this->name])) {
return call_user_func_array($callback, $args);
}
}
}

Expand All @@ -32,6 +40,10 @@ public function set($callback, $args = [])
*/
public function getURL()
{
if ($this->POST_trigger) {
return $_SERVER['REQUEST_URI'];
}

return $this->app->url([$this->name=>'callback']);
}
}
5 changes: 4 additions & 1 deletion src/Column/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ class Link extends Generic

public function __construct($page = [])
{
$this->page = $page;
$this->page = $page[0];
}

/**
* kill me now for this code :!!
*/
public function getCellTemplate(\atk4\data\Field $f)
{
if (!is_array($this->page)) {
return $this->app->getTag('td', [], $this->app->getTag('a', ['href'=>$this->page], '{$'.$f->short_name.'}'));
}
foreach ($this->page as &$val) {
$val = str_replace('{$', '___o', $val);
$val = str_replace('}', 'c___', $val);
Expand Down
10 changes: 8 additions & 2 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public function init()
*/
public function loadPOST()
{
$this->model->set($this->app->ui_persistence->typecastLoadRow($this->model, $_POST));
$data = array_intersect_key($_POST, $this->model->elements);
$this->model->set($this->app->ui_persistence->typecastLoadRow($this->model, $data));
}

/**
Expand Down Expand Up @@ -239,7 +240,12 @@ public function jsField($name)

public function ajaxSubmit()
{
$this->_add($cb = new jsCallback(), ['desired_name'=>'submit']);
$this->_add($cb = new jsCallback(), ['desired_name'=>'submit', 'POST_trigger'=>true]);

$this->add(new View(['element'=>'input']))
->setAttr('name', $cb->name)
->setAttr('value', 'submit')
->setAttr('type', 'hidden');

$cb->set(function () {
$response = $this->hook('submit');
Expand Down
22 changes: 15 additions & 7 deletions src/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public function addColumn($name, $columnDef = null, $fieldDef = null)

if ($columnDef === null) {
$columnDef = $this->_columnFactory($field);
} elseif (is_string($columnDef) || is_array($columnDef)) {
if (!$this->app) {
throw new Exception(['You can only specify column type by name if Grid is in a render-tree']);
}

$columnDef = $this->add($columnDef, $name);
} else {
$this->add($columnDef, $name);
}
Expand Down Expand Up @@ -170,14 +176,16 @@ public function init()
{
parent::init();

$this->t_head = $this->template->cloneRegion('Head');
$this->t_row_master = $this->template->cloneRegion('Row');
$this->t_totals = $this->template->cloneRegion('Totals');
$this->t_empty = $this->template->cloneRegion('Empty');
if (!$this->t_head) {
$this->t_head = $this->template->cloneRegion('Head');
$this->t_row_master = $this->template->cloneRegion('Row');
$this->t_totals = $this->template->cloneRegion('Totals');
$this->t_empty = $this->template->cloneRegion('Empty');

$this->template->del('Head');
$this->template->del('Body');
$this->template->del('Foot');
$this->template->del('Head');
$this->template->del('Body');
$this->template->del('Foot');
}
}

/**
Expand Down
45 changes: 45 additions & 0 deletions src/Persistence/UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,51 @@ public function _typecastSaveField(\atk4\data\Field $f, $value)
return $v;
}

/**
* Interpret user-defined input for various types.
*/
public function _typecastLoadField(\atk4\data\Field $f, $value)
{
switch ($f->type) {
case 'boolean':
$value = (bool) $value;
break;
case 'money':
return str_replace(',', '', $value);
case 'date':
case 'datetime':
case 'time':
$dt_class = isset($f->dateTimeClass) ? $f->dateTimeClass : 'DateTime';
$tz_class = isset($f->dateTimeZoneClass) ? $f->dateTimeZoneClass : 'DateTimeZone';

// ! symbol in date format is essential here to remove time part of DateTime - don't remove, this is not a bug
$format = ['date' => $this->date_format, 'datetime' => $this->datetime_format, 'time' => $this->time_format];
$format = $f->persist_format ?: $format[$f->type];

// datetime only - set from persisting timezone
if ($f->type == 'datetime' && isset($f->persist_timezone)) {
$v = $dt_class::createFromFormat($format, $value, new $tz_class($f->persist_timezone));
if ($v === false) {
throw new Exception(['Incorrectly formatted datetime', 'format' => $format, 'value' => $value, 'field' => $f]);
}
$v->setTimeZone(new $tz_class(date_default_timezone_get()));

return $v;
} else {
$v = $dt_class::createFromFormat($format, $value);
if ($v === false) {
throw new Exception(['Incorrectly formatted date/time', 'format' => $format, 'value' => $value, 'field' => $f]);
}

return $v;
}

break;
}

return $value;
}

/**
* This is override of the default Persistence logic to tweak the behaviour:.
*
Expand Down
Loading

0 comments on commit 0adda17

Please sign in to comment.