diff --git a/assets/js/app.js b/assets/js/app.js index fe972a7e..c6e21cec 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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'); diff --git a/assets/ts_src/ajax_ui.ts b/assets/ts_src/ajax_ui.ts index f2707799..77a11e69 100644 --- a/assets/ts_src/ajax_ui.ts +++ b/assets/ts_src/ajax_ui.ts @@ -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(); } diff --git a/assets/tsconfig.json b/assets/tsconfig.json index d03ba99a..36c1e869 100644 --- a/assets/tsconfig.json +++ b/assets/tsconfig.json @@ -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" diff --git a/package.json b/package.json index 18d186ff..c17d0de8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Form/PartType.php b/src/Form/PartType.php index d5b82404..c119eddf 100644 --- a/src/Form/PartType.php +++ b/src/Form/PartType.php @@ -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']) diff --git a/yarn.lock b/yarn.lock index 71b9d675..7dce30ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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==