Use ajax for form requests too.

This commit is contained in:
Jan Böhmer 2019-03-24 20:25:27 +01:00
parent b3db1dd139
commit 8711f296a4
6 changed files with 43 additions and 4 deletions

View file

@ -37,6 +37,7 @@ require( 'datatables.net-buttons/js/buttons.print.js' );
require( 'datatables.net-fixedheader-bs4' );
require( 'datatables.net-select-bs4' );
require('bootstrap-select');
require('jquery-form');
//require('bootstrap-treeview/src/js/bootstrap-treeview');

View file

@ -75,6 +75,7 @@ class AjaxUI {
{
console.info("AjaxUI started!");
this.registerLinks();
this.registerForm();
}
/**
@ -95,6 +96,26 @@ class AjaxUI {
console.debug('Links registered!');
}
/**
* Register all forms for loading via ajax.
*/
protected registerForm()
{
let options : JQueryFormOptions = {
success: this.onAjaxComplete,
beforeSubmit: function (arr, $form, options) : boolean {
//When data-with-progbar is specified, then show progressbar.
if($form.data("with-progbar") != undefined) {
ajaxUI.showProgressBar();
}
return true;
}
}
$('form').not('[data-no-ajax]').ajaxForm(options);
console.debug('Forms registered!');
}
public showProgressBar()
{
@ -204,6 +225,7 @@ class AjaxUI {
//Do things on the new dom
ajaxUI.registerLinks();
ajaxUI.registerForm();
}

View file

@ -4,7 +4,7 @@
"target": "es5",
"sourceMap": true,
"typeRoots": ["../node_modules"],
"types": ["jquery", "js-cookie", "bootstrap"]
"types": ["jquery", "js-cookie", "bootstrap", "jquery.form"]
},
"exclude": [
"node_modules"

View file

@ -19,6 +19,7 @@
"@ckeditor/ckeditor5-build-classic": "^12.0.0",
"@types/bootstrap": "^4.3.0",
"@types/jquery": "^3.3.29",
"@types/jquery.form": "^3.26.30",
"@types/js-cookie": "^2.2.1",
"awesome-bootstrap-checkbox": "^1.0.1",
"bootstrap-select": "^1.13.8",
@ -27,6 +28,7 @@
"datatables.net-buttons-bs4": "^1.5.4",
"datatables.net-fixedheader-bs4": "^3.1.5",
"datatables.net-select-bs4": "^1.2.7",
"jquery-form": "^4.2.2",
"js-cookie": "^2.2.0",
"jszip": "^3.2.0",
"pdfmake": "^0.1.53",

View file

@ -64,7 +64,7 @@ class PartType extends AbstractType
'disabled' => !$this->security->isGranted('name.edit', $part), ])
->add('description', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'description.label', 'help' => 'bbcode.hint', 'attr' => ['placeholder' => 'part.description.placeholder'],
'disabled' => !$this->security->isGranted('description.edit', $part), ])
'disabled' => !$this->security->isGranted('description.edit', $part), 'empty_data' => '' ])
->add('instock', IntegerType::class,
['attr' => ['min' => 0, 'placeholder' => 'part.instock.placeholder'], 'label' => 'instock.label',
'disabled' => !$this->security->isGranted('instock.edit', $part), ])
@ -85,7 +85,7 @@ class PartType extends AbstractType
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), ])
->add('comment', CKEditorType::class, ['required' => false,
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted('comment.edit', $part), ])
'disabled' => !$this->security->isGranted('comment.edit', $part), 'empty_data' => ''])
//Buttons
->add('save', SubmitType::class, ['label' => 'part.edit.save'])

View file

@ -658,6 +658,13 @@
"@types/jquery" "*"
popper.js "^1.14.1"
"@types/jquery.form@^3.26.30":
version "3.26.30"
resolved "https://registry.yarnpkg.com/@types/jquery.form/-/jquery.form-3.26.30.tgz#a9640ac12a00cb81b446f54c675252ea9c1218e0"
integrity sha512-LJZcG6DiuWZGroYaYmaZRRXg9q6ph0yWS0wxhWHuC1wsvBljV/L9INtrROZcNwLKZNtxVFgeWb8x49iufW9Z+w==
dependencies:
"@types/jquery" "*"
"@types/jquery@*", "@types/jquery@^3.3.29":
version "3.3.29"
resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.3.29.tgz#680a2219ce3c9250483722fccf5570d1e2d08abd"
@ -3643,7 +3650,14 @@ isobject@^3.0.0, isobject@^3.0.1:
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
jquery@>=1.7, jquery@^3.3.1:
jquery-form@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/jquery-form/-/jquery-form-4.2.2.tgz#9f96fb141ec9cbe0cdaf58b4d3f1dcbb009cdd52"
integrity sha512-HJTef7DRBSg8ge/RNUw8rUTTtB3l8ozO0OhD16AzDl+eIXp4skgCqRTd9fYPsOzL+pN6+1B9wvbTLGjgikz8Tg==
dependencies:
jquery ">=1.7.2"
jquery@>=1.7, jquery@>=1.7.2, jquery@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.3.1.tgz#958ce29e81c9790f31be7792df5d4d95fc57fbca"
integrity sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==