Skip to content

Commit

Permalink
Merge pull request #313 from AntonShevchuk/master
Browse files Browse the repository at this point in the history
Migrate to TB4.0 form validation
  • Loading branch information
Anton authored Nov 24, 2017
2 parents f01bd23 + 21875c9 commit 878b1b5
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 194 deletions.
170 changes: 91 additions & 79 deletions application/layouts/partial/nav-menu.phtml
Original file line number Diff line number Diff line change
@@ -1,82 +1,94 @@
<?php /** @var \Bluz\Layout\Layout $this */ ?>
<nav class="col-sm-3 col-md-2 d-none d-sm-block bg-light sidebar">
<hr/>
<ul class="nav nav-pills flex-column">
<li class="nav-item <?= ($this->module('pages') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-edit fa-fw"></i> ' . __('Pages'),
['pages', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<li class="nav-item <?= ($this->module('users') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-user fa-fw"></i> ' . __('Users'),
['users', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php if ($this->hasModule('wallet')) : ?>
<li class="nav-item <?= ($this->module('wallet') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-credit-card fa-fw"></i> ' . __('Wallets'),
['wallet', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
<?php if ($this->hasModule('media')) : ?>
<li class="nav-item <?= ($this->module('media') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-picture-o fa-fw"></i> ' . __('Media'),
['media', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
<?php if ($this->hasModule('categories')) : ?>
<li class="nav-item <?= ($this->module('categories') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-folder-o fa-fw"></i> ' . __('Categories'),
['categories', 'tree', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
<li class="nav-item <?= ($this->module('acl') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-lock fa-fw"></i> ' . __('Permissions'),
['acl', 'index', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php if ($this->hasModule('options')) : ?>
<li class="nav-item <?= ($this->module('options') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-th-list fa-fw"></i> ' . __('Options'),
['options', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
<?php if ($this->hasModule('contact-us')) : ?>
<li class="nav-item <?= ($this->module('contact-us') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-envelope-o fa-fw"></i> ' . __('Contact Us'),
['contact-us', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
</ul>
<hr/>
<ul class="nav nav-pills flex-column">
<li class="nav-item <?= ($this->module('system') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-wrench fa-fw"></i> ' . __('System'),
['system', 'index', [], true],
['class' => 'nav-link']
) ?>
</li>
</ul>
<hr/>
<ul class="nav nav-pills flex-column">
<li class="nav-item <?= ($this->module('users') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-user fa-fw"></i> ' . __('Users'),
['users', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php if ($this->hasModule('wallet')) : ?>
<li class="nav-item <?= ($this->module('wallet') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-credit-card fa-fw"></i> ' . __('Wallets'),
['wallet', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
<?php if ($this->hasModule('phones')) : ?>
<li class="nav-item <?= ($this->module('phones') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-phone fa-fw"></i> ' . __('Phones'),
['phones', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
</ul>
<hr/>
<ul class="nav nav-pills flex-column">
<li class="nav-item <?= ($this->module('pages') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-edit fa-fw"></i> ' . __('Pages'),
['pages', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php if ($this->hasModule('media')) : ?>
<li class="nav-item <?= ($this->module('media') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-picture-o fa-fw"></i> ' . __('Media'),
['media', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
<?php if ($this->hasModule('categories')) : ?>
<li class="nav-item <?= ($this->module('categories') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-folder-o fa-fw"></i> ' . __('Categories'),
['categories', 'tree', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
<?php if ($this->hasModule('contact-us')) : ?>
<li class="nav-item <?= ($this->module('contact-us') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-envelope-o fa-fw"></i> ' . __('Contact Us'),
['contact-us', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
</ul>
<hr/>
<ul class="nav nav-pills flex-column">
<li class="nav-item <?= ($this->module('acl') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-lock fa-fw"></i> ' . __('Permissions'),
['acl', 'index', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php if ($this->hasModule('options')) : ?>
<li class="nav-item <?= ($this->module('options') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-th-list fa-fw"></i> ' . __('Options'),
['options', 'grid', [], true],
['class' => 'nav-link']
) ?>
</li>
<?php endif; ?>
<li class="nav-item <?= ($this->module('system') ? 'active' : '') ?>">
<?= $this->ahref(
'<i class="fa fa-wrench fa-fw"></i> ' . __('System'),
['system', 'index', [], true],
['class' => 'nav-link']
) ?>
</li>
</ul>
</nav>
3 changes: 2 additions & 1 deletion application/modules/acl/views/roles.phtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php /** @var \Bluz\View\View $this */ ?>
<?php $uid = uniqid('form_', false); ?>
<form id="<?= $uid ?>" action="<?= $this->url('acl', 'roles') ?>" class="form-horizontal" data-ajax method="<?= $method ?>">
<form id="<?= $uid ?>" action="<?= $this->url('acl', 'roles') ?>" class="form-horizontal" method="<?= $method ?>"
data-ajax novalidate>
<input type="hidden" name="id" value="<?= $row->id ?>"/>
<div class="modal-header">
<h4 class="modal-title">
Expand Down
4 changes: 2 additions & 2 deletions application/modules/acl/views/user.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @var \Application\Users\Row $user
*/
?>
<form action="<?= $this->url('acl', 'user', ['id' => $user->id]) ?>" class="form-horizontal" data-ajax method="post"
enctype="application/x-www-form-urlencoded">
<form action="<?= $this->url('acl', 'user', ['id' => $user->id]) ?>" class="form-horizontal" method="post"
data-ajax novalidate>
<div class="modal-header">
<h4 class="modal-title"><?= __('Choose roles for %s', $user->login) ?></h4>
<button type="button" class="close" data-dismiss="modal" aria-label="<?=__('Close')?>">
Expand Down
2 changes: 1 addition & 1 deletion application/modules/pages/views/crud.phtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php /** @var \Bluz\View\View $this */ ?>
<?php $uid = uniqid('form_', false); ?>
<form id="<?= $uid ?>" action="<?= $this->url('pages', 'crud') ?>" class="form-horizontal" data-ajax
method="<?= $method ?>">
method="<?= $method ?>" novalidate>
<input type="hidden" name="id" value="<?= $row->id ?>"/>
<input type="hidden" name="_method" value="<?= $method ?>"/>
<div class="modal-content">
Expand Down
32 changes: 32 additions & 0 deletions application/modules/users/controllers/search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* View User Profile
*
* @author Anton Shevchuk
* @created 01.09.11 13:15
*/

namespace Application;

use Application\Users;
use Bluz\Controller\Controller;
use Bluz\Proxy\Request;

/**
* @ accept JSON
* @method GET
* @privilege Management
*/
return function () {
/**
* @var Controller $this
*/
$params = Request::getParams();

$params = array_intersect_key($params, Users\Table::getMeta());

if (empty($params)) {
return [];
}
return Users\Table::findWhere($params);
};
4 changes: 3 additions & 1 deletion application/modules/users/views/crud.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use Application\Users\Table;

$uid = uniqid('form_', false); ?>

<form id="<?= $uid ?>" action="<?= $this->url('users', 'crud') ?>" class="form-horizontal" data-ajax method="<?= $method ?>">
<form id="<?= $uid ?>" action="<?= $this->url('users', 'crud') ?>" class="form-horizontal"
data-ajax method="<?= $method ?>" novalidate>
<input type="hidden" name="id" value="<?= $row->id ?>"/>
<div class="modal-header">
<h4 class="modal-title"><?= __('Edit user') ?></h4>
Expand All @@ -24,6 +25,7 @@ $uid = uniqid('form_', false); ?>
<div class="col-lg-10">
<input type="email" class="form-control" id="email" name="email" value="<?= ($row->email) ?>" maxlength="255"
required/>
<div class="invalid-feedback"><?=__('email is required, and it should has valid format')?></div>
</div>
</div>
<div class="form-group row">
Expand Down
15 changes: 14 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"robmorgan/phinx": "~0.9",
"public/swagger-ui": "dev-master",
"public/jquery": "dev-master",
"public/jquery-ui": "dev-master",
"public/popper": "dev-master",
"public/require": "dev-master"
},
Expand Down Expand Up @@ -59,7 +60,19 @@
"version": "dev-master",
"license": "MIT",
"dist": {
"url": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js",
"url": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js",
"type": "file"
}
}
},
{
"type": "package",
"package": {
"name": "public/jquery-ui",
"version": "dev-master",
"license": "MIT",
"dist": {
"url": "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js",
"type": "file"
}
}
Expand Down
33 changes: 7 additions & 26 deletions public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,6 @@ code strong {
color: #b22222;
}

/* Buttons */
.btn.icon-twitter,
.btn.icon-facebook {
color: #fff;
display: block;
width: 30px;
height: 30px;
text-align: center;
padding: 8px;
border-radius: 50%;
margin: 0 2px;
}

.btn.icon-twitter {
background: #08c;
}

.btn.icon-facebook {
background: #15c;
}

/* Notify */
#notify {
z-index: 1100;
Expand Down Expand Up @@ -95,19 +74,21 @@ code strong {
width: 360px;
}

/* Bootstrap fix? */
/* Bootstrap fix */
.modal-content > .thumbnail {
margin: 0;
}

.tooltip-inner {
min-width: 160px;
}

.table.grid + .table {
margin-top: -20px;
}

.table.grid .controls {
padding: 2px 8px;
}

/* jQuery UI fix */
.ui-state-active,
.ui-state-focus {
background-color: #f5f5f5;
}
13 changes: 10 additions & 3 deletions public/js/bluz.ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ define(['jquery', 'bluz', 'bluz.modal', 'bluz.notify'], function ($, bluz, modal

let $this = $(this);

let source = $this.data('ajax-source') || $this.attr('href');
let source = $this.data('ajax-load') || $this.attr('href');
if (!source) {
throw new Error('Undefined `data-ajax-source` attribute (and href is missing)');
throw new Error('Undefined `data-ajax-load` attribute (and href is missing)');
}

let target = $this.data('ajax-target');
Expand Down Expand Up @@ -249,6 +249,13 @@ define(['jquery', 'bluz', 'bluz.modal', 'bluz.notify'], function ($, bluz, modal
event.preventDefault();

let $this = $(this);
// $this.removeClass('was-validated');
$this.addClass('was-validated');

if (this.checkValidity() === false) {
event.stopPropagation();
return;
}

$.ajax({
url: $this.attr('action'),
Expand Down Expand Up @@ -300,7 +307,7 @@ define(['jquery', 'bluz', 'bluz.modal', 'bluz.notify'], function ($, bluz, modal
event.preventDefault();

let $this = $(this);
let url = $this.is('a') ? $this.attr('href') : $this.data('preview');
let url = $this.is('a') ? $this.attr('href') : $this.data('ajax-preview');

if (!url) {
return;
Expand Down
Loading

0 comments on commit 878b1b5

Please sign in to comment.