Skip to content

Commit 32a887e

Browse files
committed
Optimize checkAll
Fix form validation error when optional. Add more APIs for table, etc.
1 parent 648a9db commit 32a887e

File tree

13 files changed

+86
-46
lines changed

13 files changed

+86
-46
lines changed

core/tmpl_json_data.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
* Released under the MIT license
77
*/
88
if(!defined('IN_MODULE')){exit('Invalid Request');}
9+
global $FN_PROCESS_NEED_TRANSACTION;
910
do {
1011
set_content_type(QWP_TP_JSON);
1112
$msg_type = "error";
1213
$ret = false;
1314
$msg = "";
1415
$data = array();
16+
$ctx = false;
17+
if ($FN_PROCESS_NEED_TRANSACTION) $ctx = db_transaction();
1518
try {
1619
global $FN_PROCESS_DATA;
1720
if (isset($FN_PROCESS_DATA)) {
@@ -27,6 +30,7 @@
2730
} catch (Exception $e) {
2831
$msg = L("Exception happens: ") . $e->getMessage();
2932
}
33+
if ($ret !== true && $ctx) $ctx->rollback();
3034
} while (false);
3135
if (!$ret && !$msg) {
3236
$msg = L("Invalid parameters");

core/validator.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,21 @@ function qwp_validate_data(&$f, &$rules, &$filters = null) {
118118
} else {
119119
$msg = &$msg_base;
120120
}
121-
foreach ($rule as $key => $item) {
122-
if (substr($key, 0, 1) == '_') {
123-
if ($key == '_avoidSqlInj') $f[$field_name] = mysql_real_escape_string($field_value);
124-
continue;
121+
if (isset($rule['required'])) {
122+
if ($field_value === null || $field_value === '') {
123+
return $msg;
125124
}
126-
if ($key == 'required') {
127-
if ($field_value === null || $field_value === '') {
128-
return $msg;
129-
}
125+
} else if (isset($rule['optional'])) {
126+
if ($field_value === null || $field_value === '') {
130127
continue;
131-
} else if ($key == 'optional') {
132-
if ($field_value === null || $field_value === '') {
133-
continue;
134-
}
135128
}
136-
// if value is not set, ignore the validation if not required
137-
if (!$field_value === null || $field_value === '') {
129+
}
130+
foreach ($rule as $key => $item) {
131+
if (substr($key, 0, 1) == '_') {
132+
if ($key == '_avoidSqlInj') $f[$field_name] = mysql_real_escape_string($field_value);
138133
continue;
139134
}
135+
if ($key == 'required' || $key == 'optional') continue;
140136
if ($key == 'date') {
141137
if (!date_to_int($field_value)) {
142138
return $msg;

include/common.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,11 @@ function dir_size($dir) {
485485
}
486486
function file_ext($name) {
487487
$pos = strrpos($name, '.');
488-
if ($pos === false) {
489-
return "";
490-
}
491-
return substr($name, $pos + 1);
488+
return $pos === false ? '' : substr($name, $pos + 1);
489+
}
490+
function file_name_without_ext($name) {
491+
$pos = strrpos($name, '.');
492+
return $pos === false ? $name : substr($name, 0, $pos);
492493
}
493494
function echo_line($msg) {
494495
echo($msg);

include/db.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,16 @@ function qwp_db_retrieve_data($table_name, &$data, &$options)
464464
qwp_db_init_search_params($options);
465465
qwp_create_query($query, $table_name, $fields, $options);
466466
$enable_pager = P('enable_pager', true, $options);
467-
if ($enable_pager) $data["total"] = qwp_db_calc_data_count($query);
468-
$data["data"] = array();
469-
if (!$enable_pager || ($enable_pager && $data["total"] > 0)) {
467+
$total = 0;
468+
if ($enable_pager) $total = qwp_db_calc_data_count($query);
469+
if (!is_array($data)) $data = array();
470+
if (isset($data["data"])) {
471+
$data["total"] = $total + count($data["data"]);
472+
} else {
473+
$data["total"] = $total;
474+
$data["data"] = array();
475+
}
476+
if (!$enable_pager || ($enable_pager && $total > 0)) {
470477
if ($enable_pager) {
471478
qwp_db_set_pager($query);
472479
}

js/qwp.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,7 @@ $h = {};
703703
if (p.find('> div[qwp=overlay]').length === 0) p.append('<div id="overlay-'+id+'" qwp="overlay" style="margin:0;padding:0;text-align: center;display:none;z-index: '+zIndex+';position: absolute;background-color: white"><img src="img/loading_small.gif"><br><span mtag="txt"></span></b></div>');
704704
var o = p.find('> div[qwp=overlay]');
705705
if (txt) o.find('> span[mtag=txt]').html(txt);
706-
var off = p.offset();
707-
o.css({left: off.left + 'px', top: off.top + 'px'});
706+
o.css({left: '0', top: '0'});
708707
if (show) {
709708
qwp.ui.sameSize(o, p);
710709
o.show();

modules/users/user.php renamed to modules/users/form_user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<div class="form-group">
4242
<label for="f_avatar" class="col-sm-3 control-label">Avatar</label>
4343
<div class="col-sm-9">
44-
<input type="file" name="f[avatar]" id="f_avatar" class="form-control" placeholder="Phone">
44+
<input type="file" name="f[avatar][]" id="f_avatar" class="form-control" placeholder="Phone" multiple="multiple">
4545
</div>
4646
</div>
4747
</form>

modules/users/home.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
);
77
global $roles;
88
get_user_roles($roles);
9-
require_once(join_paths($MODULE_ROOT, 'user.php'));
109
qwp_ui_init_dialog();
11-
qwp_create_dialog("dialog_user", array(
10+
qwp_create_dialog_with_form("dialog_user", array(
1211
'width' => '460px',
1312
'height' => '280px',
14-
));
13+
), 'user');
1514
?>
1615
<div class="user-div">
1716
<div class="row well qwp-search hide">

router/common.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ function qwp_set_custom_validator($fn) {
1919
global $FN_QWP_FORM_VALIDATOR;
2020
$FN_QWP_FORM_VALIDATOR = $fn;
2121
}
22-
function qwp_set_data_processor($fn) {
23-
global $FN_PROCESS_DATA;
22+
function qwp_set_data_processor($fn, $transaction = false) {
23+
global $FN_PROCESS_DATA, $FN_PROCESS_NEED_TRANSACTION;;
2424
$FN_PROCESS_DATA = $fn;
25+
$FN_PROCESS_NEED_TRANSACTION = $transaction;
2526
}
2627
function qwp_is_passport_module() {
2728
global $is_passport;

router/render.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ function qwp_render_add_ztree() {
234234
qwp_include_js_file('jquery.ztree.all.min.js');
235235
}
236236
function qwp_render_add_list() {
237+
qwp_add_js_code(QWP_UI_ROOT . '/loading.js');
237238
qwp_add_js_code(QWP_UI_ROOT . '/list.js');
238239
}
239240
function qwp_render_add_form_code() {

ui/dialog.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ qwp.dialog = {
5353
if (opt) {
5454
qwp.dialog.customize(id, opt);
5555
}
56+
qwp.removeNotice();
5657
$('#' + id).modal();
5758
qwp.dialog._updateDialogSize(id, opt);
5859
},

0 commit comments

Comments
 (0)