Skip to content

Commit 878b1b5

Browse files
author
Anton
authored
Merge pull request #313 from AntonShevchuk/master
Migrate to TB4.0 form validation
2 parents f01bd23 + 21875c9 commit 878b1b5

15 files changed

Lines changed: 284 additions & 194 deletions

File tree

Lines changed: 91 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,94 @@
11
<?php /** @var \Bluz\Layout\Layout $this */ ?>
22
<nav class="col-sm-3 col-md-2 d-none d-sm-block bg-light sidebar">
3-
<hr/>
4-
<ul class="nav nav-pills flex-column">
5-
<li class="nav-item <?= ($this->module('pages') ? 'active' : '') ?>">
6-
<?= $this->ahref(
7-
'<i class="fa fa-edit fa-fw"></i> ' . __('Pages'),
8-
['pages', 'grid', [], true],
9-
['class' => 'nav-link']
10-
) ?>
11-
</li>
12-
<li class="nav-item <?= ($this->module('users') ? 'active' : '') ?>">
13-
<?= $this->ahref(
14-
'<i class="fa fa-user fa-fw"></i> ' . __('Users'),
15-
['users', 'grid', [], true],
16-
['class' => 'nav-link']
17-
) ?>
18-
</li>
19-
<?php if ($this->hasModule('wallet')) : ?>
20-
<li class="nav-item <?= ($this->module('wallet') ? 'active' : '') ?>">
21-
<?= $this->ahref(
22-
'<i class="fa fa-credit-card fa-fw"></i> ' . __('Wallets'),
23-
['wallet', 'grid', [], true],
24-
['class' => 'nav-link']
25-
) ?>
26-
</li>
27-
<?php endif; ?>
28-
<?php if ($this->hasModule('media')) : ?>
29-
<li class="nav-item <?= ($this->module('media') ? 'active' : '') ?>">
30-
<?= $this->ahref(
31-
'<i class="fa fa-picture-o fa-fw"></i> ' . __('Media'),
32-
['media', 'grid', [], true],
33-
['class' => 'nav-link']
34-
) ?>
35-
</li>
36-
<?php endif; ?>
37-
<?php if ($this->hasModule('categories')) : ?>
38-
<li class="nav-item <?= ($this->module('categories') ? 'active' : '') ?>">
39-
<?= $this->ahref(
40-
'<i class="fa fa-folder-o fa-fw"></i> ' . __('Categories'),
41-
['categories', 'tree', [], true],
42-
['class' => 'nav-link']
43-
) ?>
44-
</li>
45-
<?php endif; ?>
46-
<li class="nav-item <?= ($this->module('acl') ? 'active' : '') ?>">
47-
<?= $this->ahref(
48-
'<i class="fa fa-lock fa-fw"></i> ' . __('Permissions'),
49-
['acl', 'index', [], true],
50-
['class' => 'nav-link']
51-
) ?>
52-
</li>
53-
<?php if ($this->hasModule('options')) : ?>
54-
<li class="nav-item <?= ($this->module('options') ? 'active' : '') ?>">
55-
<?= $this->ahref(
56-
'<i class="fa fa-th-list fa-fw"></i> ' . __('Options'),
57-
['options', 'grid', [], true],
58-
['class' => 'nav-link']
59-
) ?>
60-
</li>
61-
<?php endif; ?>
62-
<?php if ($this->hasModule('contact-us')) : ?>
63-
<li class="nav-item <?= ($this->module('contact-us') ? 'active' : '') ?>">
64-
<?= $this->ahref(
65-
'<i class="fa fa-envelope-o fa-fw"></i> ' . __('Contact Us'),
66-
['contact-us', 'grid', [], true],
67-
['class' => 'nav-link']
68-
) ?>
69-
</li>
70-
<?php endif; ?>
71-
</ul>
72-
<hr/>
73-
<ul class="nav nav-pills flex-column">
74-
<li class="nav-item <?= ($this->module('system') ? 'active' : '') ?>">
75-
<?= $this->ahref(
76-
'<i class="fa fa-wrench fa-fw"></i> ' . __('System'),
77-
['system', 'index', [], true],
78-
['class' => 'nav-link']
79-
) ?>
80-
</li>
81-
</ul>
3+
<hr/>
4+
<ul class="nav nav-pills flex-column">
5+
<li class="nav-item <?= ($this->module('users') ? 'active' : '') ?>">
6+
<?= $this->ahref(
7+
'<i class="fa fa-user fa-fw"></i> ' . __('Users'),
8+
['users', 'grid', [], true],
9+
['class' => 'nav-link']
10+
) ?>
11+
</li>
12+
<?php if ($this->hasModule('wallet')) : ?>
13+
<li class="nav-item <?= ($this->module('wallet') ? 'active' : '') ?>">
14+
<?= $this->ahref(
15+
'<i class="fa fa-credit-card fa-fw"></i> ' . __('Wallets'),
16+
['wallet', 'grid', [], true],
17+
['class' => 'nav-link']
18+
) ?>
19+
</li>
20+
<?php endif; ?>
21+
<?php if ($this->hasModule('phones')) : ?>
22+
<li class="nav-item <?= ($this->module('phones') ? 'active' : '') ?>">
23+
<?= $this->ahref(
24+
'<i class="fa fa-phone fa-fw"></i> ' . __('Phones'),
25+
['phones', 'grid', [], true],
26+
['class' => 'nav-link']
27+
) ?>
28+
</li>
29+
<?php endif; ?>
30+
</ul>
31+
<hr/>
32+
<ul class="nav nav-pills flex-column">
33+
<li class="nav-item <?= ($this->module('pages') ? 'active' : '') ?>">
34+
<?= $this->ahref(
35+
'<i class="fa fa-edit fa-fw"></i> ' . __('Pages'),
36+
['pages', 'grid', [], true],
37+
['class' => 'nav-link']
38+
) ?>
39+
</li>
40+
<?php if ($this->hasModule('media')) : ?>
41+
<li class="nav-item <?= ($this->module('media') ? 'active' : '') ?>">
42+
<?= $this->ahref(
43+
'<i class="fa fa-picture-o fa-fw"></i> ' . __('Media'),
44+
['media', 'grid', [], true],
45+
['class' => 'nav-link']
46+
) ?>
47+
</li>
48+
<?php endif; ?>
49+
<?php if ($this->hasModule('categories')) : ?>
50+
<li class="nav-item <?= ($this->module('categories') ? 'active' : '') ?>">
51+
<?= $this->ahref(
52+
'<i class="fa fa-folder-o fa-fw"></i> ' . __('Categories'),
53+
['categories', 'tree', [], true],
54+
['class' => 'nav-link']
55+
) ?>
56+
</li>
57+
<?php endif; ?>
58+
<?php if ($this->hasModule('contact-us')) : ?>
59+
<li class="nav-item <?= ($this->module('contact-us') ? 'active' : '') ?>">
60+
<?= $this->ahref(
61+
'<i class="fa fa-envelope-o fa-fw"></i> ' . __('Contact Us'),
62+
['contact-us', 'grid', [], true],
63+
['class' => 'nav-link']
64+
) ?>
65+
</li>
66+
<?php endif; ?>
67+
</ul>
68+
<hr/>
69+
<ul class="nav nav-pills flex-column">
70+
<li class="nav-item <?= ($this->module('acl') ? 'active' : '') ?>">
71+
<?= $this->ahref(
72+
'<i class="fa fa-lock fa-fw"></i> ' . __('Permissions'),
73+
['acl', 'index', [], true],
74+
['class' => 'nav-link']
75+
) ?>
76+
</li>
77+
<?php if ($this->hasModule('options')) : ?>
78+
<li class="nav-item <?= ($this->module('options') ? 'active' : '') ?>">
79+
<?= $this->ahref(
80+
'<i class="fa fa-th-list fa-fw"></i> ' . __('Options'),
81+
['options', 'grid', [], true],
82+
['class' => 'nav-link']
83+
) ?>
84+
</li>
85+
<?php endif; ?>
86+
<li class="nav-item <?= ($this->module('system') ? 'active' : '') ?>">
87+
<?= $this->ahref(
88+
'<i class="fa fa-wrench fa-fw"></i> ' . __('System'),
89+
['system', 'index', [], true],
90+
['class' => 'nav-link']
91+
) ?>
92+
</li>
93+
</ul>
8294
</nav>

application/modules/acl/views/roles.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php /** @var \Bluz\View\View $this */ ?>
22
<?php $uid = uniqid('form_', false); ?>
3-
<form id="<?= $uid ?>" action="<?= $this->url('acl', 'roles') ?>" class="form-horizontal" data-ajax method="<?= $method ?>">
3+
<form id="<?= $uid ?>" action="<?= $this->url('acl', 'roles') ?>" class="form-horizontal" method="<?= $method ?>"
4+
data-ajax novalidate>
45
<input type="hidden" name="id" value="<?= $row->id ?>"/>
56
<div class="modal-header">
67
<h4 class="modal-title">

application/modules/acl/views/user.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* @var \Application\Users\Row $user
55
*/
66
?>
7-
<form action="<?= $this->url('acl', 'user', ['id' => $user->id]) ?>" class="form-horizontal" data-ajax method="post"
8-
enctype="application/x-www-form-urlencoded">
7+
<form action="<?= $this->url('acl', 'user', ['id' => $user->id]) ?>" class="form-horizontal" method="post"
8+
data-ajax novalidate>
99
<div class="modal-header">
1010
<h4 class="modal-title"><?= __('Choose roles for %s', $user->login) ?></h4>
1111
<button type="button" class="close" data-dismiss="modal" aria-label="<?=__('Close')?>">

application/modules/pages/views/crud.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php /** @var \Bluz\View\View $this */ ?>
22
<?php $uid = uniqid('form_', false); ?>
33
<form id="<?= $uid ?>" action="<?= $this->url('pages', 'crud') ?>" class="form-horizontal" data-ajax
4-
method="<?= $method ?>">
4+
method="<?= $method ?>" novalidate>
55
<input type="hidden" name="id" value="<?= $row->id ?>"/>
66
<input type="hidden" name="_method" value="<?= $method ?>"/>
77
<div class="modal-content">
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* View User Profile
4+
*
5+
* @author Anton Shevchuk
6+
* @created 01.09.11 13:15
7+
*/
8+
9+
namespace Application;
10+
11+
use Application\Users;
12+
use Bluz\Controller\Controller;
13+
use Bluz\Proxy\Request;
14+
15+
/**
16+
* @ accept JSON
17+
* @method GET
18+
* @privilege Management
19+
*/
20+
return function () {
21+
/**
22+
* @var Controller $this
23+
*/
24+
$params = Request::getParams();
25+
26+
$params = array_intersect_key($params, Users\Table::getMeta());
27+
28+
if (empty($params)) {
29+
return [];
30+
}
31+
return Users\Table::findWhere($params);
32+
};

application/modules/users/views/crud.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use Application\Users\Table;
44

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

7-
<form id="<?= $uid ?>" action="<?= $this->url('users', 'crud') ?>" class="form-horizontal" data-ajax method="<?= $method ?>">
7+
<form id="<?= $uid ?>" action="<?= $this->url('users', 'crud') ?>" class="form-horizontal"
8+
data-ajax method="<?= $method ?>" novalidate>
89
<input type="hidden" name="id" value="<?= $row->id ?>"/>
910
<div class="modal-header">
1011
<h4 class="modal-title"><?= __('Edit user') ?></h4>
@@ -24,6 +25,7 @@ $uid = uniqid('form_', false); ?>
2425
<div class="col-lg-10">
2526
<input type="email" class="form-control" id="email" name="email" value="<?= ($row->email) ?>" maxlength="255"
2627
required/>
28+
<div class="invalid-feedback"><?=__('email is required, and it should has valid format')?></div>
2729
</div>
2830
</div>
2931
<div class="form-group row">

composer.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"robmorgan/phinx": "~0.9",
1616
"public/swagger-ui": "dev-master",
1717
"public/jquery": "dev-master",
18+
"public/jquery-ui": "dev-master",
1819
"public/popper": "dev-master",
1920
"public/require": "dev-master"
2021
},
@@ -59,7 +60,19 @@
5960
"version": "dev-master",
6061
"license": "MIT",
6162
"dist": {
62-
"url": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js",
63+
"url": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js",
64+
"type": "file"
65+
}
66+
}
67+
},
68+
{
69+
"type": "package",
70+
"package": {
71+
"name": "public/jquery-ui",
72+
"version": "dev-master",
73+
"license": "MIT",
74+
"dist": {
75+
"url": "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js",
6376
"type": "file"
6477
}
6578
}

public/css/styles.css

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,6 @@ code strong {
3232
color: #b22222;
3333
}
3434

35-
/* Buttons */
36-
.btn.icon-twitter,
37-
.btn.icon-facebook {
38-
color: #fff;
39-
display: block;
40-
width: 30px;
41-
height: 30px;
42-
text-align: center;
43-
padding: 8px;
44-
border-radius: 50%;
45-
margin: 0 2px;
46-
}
47-
48-
.btn.icon-twitter {
49-
background: #08c;
50-
}
51-
52-
.btn.icon-facebook {
53-
background: #15c;
54-
}
55-
5635
/* Notify */
5736
#notify {
5837
z-index: 1100;
@@ -95,19 +74,21 @@ code strong {
9574
width: 360px;
9675
}
9776

98-
/* Bootstrap fix? */
77+
/* Bootstrap fix */
9978
.modal-content > .thumbnail {
10079
margin: 0;
10180
}
10281

103-
.tooltip-inner {
104-
min-width: 160px;
105-
}
106-
10782
.table.grid + .table {
10883
margin-top: -20px;
10984
}
11085

11186
.table.grid .controls {
11287
padding: 2px 8px;
11388
}
89+
90+
/* jQuery UI fix */
91+
.ui-state-active,
92+
.ui-state-focus {
93+
background-color: #f5f5f5;
94+
}

public/js/bluz.ajax.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ define(['jquery', 'bluz', 'bluz.modal', 'bluz.notify'], function ($, bluz, modal
217217

218218
let $this = $(this);
219219

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

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

251251
let $this = $(this);
252+
// $this.removeClass('was-validated');
253+
$this.addClass('was-validated');
254+
255+
if (this.checkValidity() === false) {
256+
event.stopPropagation();
257+
return;
258+
}
252259

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

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

305312
if (!url) {
306313
return;

0 commit comments

Comments
 (0)