From cf14306c2b3f82a81f8d56669a71633b4d4b5fce Mon Sep 17 00:00:00 2001
From: marvin-borner@live.com
Date: Mon, 16 Apr 2018 21:09:05 +0200
Subject: Main merge to user management system - files are now at /main/public/
---
main/app/sprinkles/FormGenerator/.gitignore | 3 +
main/app/sprinkles/FormGenerator/CHANGELOG.md | 78 ++++
main/app/sprinkles/FormGenerator/LICENSE | 21 ++
main/app/sprinkles/FormGenerator/README.md | 352 ++++++++++++++++++
.../app/sprinkles/FormGenerator/asset-bundles.json | 17 +
.../assets/js/widget-formGenerator.js | 348 ++++++++++++++++++
main/app/sprinkles/FormGenerator/bower.json | 30 ++
main/app/sprinkles/FormGenerator/composer.json | 25 ++
.../FormGenerator/locale/en_US/FormGenerator.php | 14 +
.../FormGenerator/locale/fr_FR/FormGenerator.php | 14 +
.../FormGenerator/routes/FormGenerator.php | 12 +
.../src/Controller/FormGeneratorController.php | 26 ++
.../sprinkles/FormGenerator/src/Element/Alert.php | 33 ++
.../FormGenerator/src/Element/BaseInput.php | 111 ++++++
.../FormGenerator/src/Element/Checkbox.php | 38 ++
.../sprinkles/FormGenerator/src/Element/Hidden.php | 32 ++
.../FormGenerator/src/Element/InputInterface.php | 19 +
.../sprinkles/FormGenerator/src/Element/Select.php | 41 +++
.../sprinkles/FormGenerator/src/Element/Text.php | 37 ++
.../FormGenerator/src/Element/Textarea.php | 38 ++
main/app/sprinkles/FormGenerator/src/Form.php | 188 ++++++++++
.../FormGenerator/FormGenerator.html.twig | 33 ++
.../templates/FormGenerator/confirm.html.twig | 28 ++
.../templates/FormGenerator/macros/alert.html.twig | 5 +
.../FormGenerator/macros/checkbox.html.twig | 5 +
.../FormGenerator/macros/hidden.html.twig | 3 +
.../FormGenerator/macros/select.html.twig | 5 +
.../templates/FormGenerator/macros/text.html.twig | 10 +
.../FormGenerator/macros/textarea.html.twig | 5 +
.../templates/FormGenerator/modal-large.html.twig | 3 +
.../templates/FormGenerator/modal.html.twig | 62 ++++
.../templates/FormGenerator/typehead.html.twig | 15 +
.../FormGenerator/tests/Unit/FormGeneratorTest.php | 408 +++++++++++++++++++++
.../FormGenerator/tests/Unit/data/bad.json | 12 +
.../FormGenerator/tests/Unit/data/good.json | 67 ++++
35 files changed, 2138 insertions(+)
create mode 100755 main/app/sprinkles/FormGenerator/.gitignore
create mode 100755 main/app/sprinkles/FormGenerator/CHANGELOG.md
create mode 100755 main/app/sprinkles/FormGenerator/LICENSE
create mode 100755 main/app/sprinkles/FormGenerator/README.md
create mode 100755 main/app/sprinkles/FormGenerator/asset-bundles.json
create mode 100755 main/app/sprinkles/FormGenerator/assets/js/widget-formGenerator.js
create mode 100755 main/app/sprinkles/FormGenerator/bower.json
create mode 100755 main/app/sprinkles/FormGenerator/composer.json
create mode 100755 main/app/sprinkles/FormGenerator/locale/en_US/FormGenerator.php
create mode 100755 main/app/sprinkles/FormGenerator/locale/fr_FR/FormGenerator.php
create mode 100755 main/app/sprinkles/FormGenerator/routes/FormGenerator.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Controller/FormGeneratorController.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Element/Alert.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Element/BaseInput.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Element/Checkbox.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Element/Hidden.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Element/InputInterface.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Element/Select.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Element/Text.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Element/Textarea.php
create mode 100755 main/app/sprinkles/FormGenerator/src/Form.php
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/FormGenerator.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/confirm.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/macros/alert.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/macros/checkbox.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/macros/hidden.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/macros/select.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/macros/text.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/macros/textarea.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/modal-large.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/modal.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/templates/FormGenerator/typehead.html.twig
create mode 100755 main/app/sprinkles/FormGenerator/tests/Unit/FormGeneratorTest.php
create mode 100755 main/app/sprinkles/FormGenerator/tests/Unit/data/bad.json
create mode 100755 main/app/sprinkles/FormGenerator/tests/Unit/data/good.json
(limited to 'main/app/sprinkles/FormGenerator')
diff --git a/main/app/sprinkles/FormGenerator/.gitignore b/main/app/sprinkles/FormGenerator/.gitignore
new file mode 100755
index 0000000..3afbe61
--- /dev/null
+++ b/main/app/sprinkles/FormGenerator/.gitignore
@@ -0,0 +1,3 @@
+
+.DS_Store
+assets/vendor/
\ No newline at end of file
diff --git a/main/app/sprinkles/FormGenerator/CHANGELOG.md b/main/app/sprinkles/FormGenerator/CHANGELOG.md
new file mode 100755
index 0000000..0975d22
--- /dev/null
+++ b/main/app/sprinkles/FormGenerator/CHANGELOG.md
@@ -0,0 +1,78 @@
+# Change Log
+
+## 2.2.10
+- Added support for Repository
+
+## 2.2.9
+- Fix issue when setting data that is a collection
+- `formSuccess` and `confirmSuccess` events now include the request data as a second argument
+
+## 2.2.8
+- Fix icon in textarea macro
+
+## 2.2.7
+- Added `modal-large` template file.
+
+## 2.2.6
+- Fix issue with `binary` checkbox tests.
+- Fix Text input style when no icon is added
+
+## 2.2.5
+- Added `binary` option for checkbox to disable UF binary checkbox system (bool; default true).
+
+## 2.2.4
+- Add necessary HTML to disable submit and cancel button in modal form.
+
+## 2.2.3
+- New `$form->setOptions` function to set options of a select element. Shortcut for using `setInputArgument` and `setValue`.
+
+## 2.2.2
+- Fix issue with error alert no displaying on confirmation dialog
+
+## 2.2.1
+- Initialize ufAlert if not already done
+- Autofocus first form field when modal is displayed
+
+## 2.2.0
+- Refactored the javascript plugin
+- Added new events
+- Added new `redirectAfterSuccess` boolean option
+
+## 2.1.2
+- Fix warning with select macro
+
+## 2.1.1
+- Fix issue with the select macro
+- Renamed macro templates with the `*.html.twig` extension
+
+## 2.1.0
+- Completely refactored how form fields are parsed, including how default value are defined. Each input type now defines it's own class for defining default values and transforming some input.
+- Twig templates updated to reflect the new parser.
+- Twig macros changed from `*.generate(name, value)` to `*.generate(input)`.
+- **`Bool` type changed to `checkbox`**.
+- Removed the `number` Twig template (Will use the text input one).
+- Added unit tests.
+- Support for any attributes in the schema. For example, if you need to add a data attribute to a field, your schema would be:
+```
+"myField" : {
+ "form" : {
+ "type" : "text",
+ "label" : "My Field",
+ "icon" : "fa-pencil",
+ "data-something" : "blah"
+ }
+}
+```
+
+## 2.0.0
+- Updated for UserFrosting v4.1.x
+
+The custom `RequestSchema` have been removed. Instead of building the form directly on the schema using `$schema->initForm()`, you now create a new Form using `$form = new Form($schema)` and go on from there. Handling complex schema can now be done using the new loader system from UF 4.1.
+
+`$schema->generateForm();` has also been changed to `$form->generate();`.
+
+## 1.0.1
+- Bug fixes
+
+## 1.0.0
+- Initial release
diff --git a/main/app/sprinkles/FormGenerator/LICENSE b/main/app/sprinkles/FormGenerator/LICENSE
new file mode 100755
index 0000000..09386f7
--- /dev/null
+++ b/main/app/sprinkles/FormGenerator/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2016 Louis Charette
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/main/app/sprinkles/FormGenerator/README.md b/main/app/sprinkles/FormGenerator/README.md
new file mode 100755
index 0000000..2924ede
--- /dev/null
+++ b/main/app/sprinkles/FormGenerator/README.md
@@ -0,0 +1,352 @@
+# Form Generator Sprinkle for [UserFrosting 4](https://www.userfrosting.com)
+This Sprinkle provides helper classes, Twig template and JavaScript plugins to generate HTML forms, modals and confirm modal bases on UserFrosting/[validation schemas](https://learn.userfrosting.com/routes-and-controllers/client-input/validation).
+
+> This version only works with UserFrosting 4.1.x !
+
+# Help and Contributing
+
+If you need help using this sprinkle or found any bug, feels free to open an issue or submit a pull request. You can also find me on the [UserFrosting Chat](https://chat.userfrosting.com/) most of the time for direct support.
+
+
+
+# Installation
+Edit UserFrosting `app/sprinkles.json` file and add the following to the `require` list : `"lcharette/uf_formgenerator": "^2.0.0"`. Also add `FormGenerator` to the `base` list. For example:
+
+```
+{
+ "require": {
+ "lcharette/uf_formgenerator": "^2.0.0"
+ },
+ "base": [
+ "core",
+ "account",
+ "admin",
+ "FormGenerator"
+ ]
+}
+```
+
+Run `composer update` then `php bakery bake` to install the sprinkle.
+
+# Features and usage
+Before starting with _FormGenerator_, you should read the main UserFrosting guide to familiarize yourself with _validation schemas_: (https://learn.userfrosting.com/routes-and-controllers/client-input/validation).
+
+## Form generation
+### Defining the fields in the schema
+This sprinkle uses the `schemas` used by UserFrosting to validate form data to build form. To achieve this, a new `form` key is simply added to the fields found in a `schema` file.
+
+For example, here's a simple `schema` used to validate a form used to create a `project`. The form will contain a `name`, `description` and `status` fields.
+
+```
+{
+ "name" : {
+ "validators" : {
+ "length" : {
+ "min" : 1,
+ "max" : 100
+ },
+ "required" : {
+ "message" : "PROJECT.VALIDATE.REQUIRED_NAME"
+ }
+ }
+ },
+ "description" : {
+ "validators" : {}
+ },
+ "status" : {
+ "validators" : {
+ "member_of" : {
+ "values" : [
+ "0", "1"
+ ]
+ },
+ "required" : {
+ "message" : "PROJECT.VALIDATE.STATUS"
+ }
+ }
+ }
+}
+```
+> Note: FormGenerator works with json and YAML schemas.
+
+At this point, with typical UserFrosting setup, you would be going into your controller and Twig files to manually create your HTML form. This can be easy if you have a two or three fields, but can be a pain with a dozen fields and more. This is where FormGenerator steps in with the use of a new `form` attribute. Let's add it to our `project` form :
+
+```
+{
+ "name" : {
+ "validators" : {
+ "length" : {
+ "min" : 1,
+ "max" : 100
+ },
+ "required" : {
+ "message" : "VALIDATE.REQUIRED_NAME"
+ }
+ },
+ "form" : {
+ "type" : "text",
+ "label" : "NAME",
+ "icon" : "fa-flag",
+ "placeholder" : "NAME"
+ }
+ },
+ "description" : {
+ "validators" : {},
+ "form" : {
+ "type" : "textarea",
+ "label" : "DESCRIPTION",
+ "icon" : "fa-pencil",
+ "placeholder" : "DESCRIPTION",
+ "rows" : 5
+ }
+ },
+ "status" : {
+ "validators" : {
+ "member_of" : {
+ "values" : [
+ "0", "1"
+ ]
+ },
+ "required" : {
+ "message" : "VALIDATE.STATUS"
+ }
+ },
+ "form" : {
+ "type" : "select",
+ "label" : "STATUS",
+ "options" : {
+ "0" : "Active",
+ "1" : "Disabled"
+ }
+ }
+ }
+}
+```
+
+Let's look closer at the `name` field :
+
+```
+"form" : {
+ "type" : "text",
+ "label" : "PROJECT.NAME",
+ "icon" : "fa-flag",
+ "placeholder" : "PROJECT.NAME"
+}
+```
+
+Here you can see that we define the `type`, `label`, `icon` and `placeholder` value for this `name` field. You can define any standard [form attributes](http://www.w3schools.com/html/html_form_attributes.asp), plus the `icon`, `label` and `default` attributes. `data-*` attributes can also be defined in your schema if you need them. For the `select` element, a special `options` attribute containing an array of `key : value` can be used to define the dropdown options. The select options (as any other attributes) can also be set in PHP (see further below).
+
+And of course, the values of the `label` and `placeholder` attributes can be defined using _translation keys_.
+
+Currently, FormGenerator supports the following form elements :
+- text (and any input supported by the HTML5 standard : number, tel, password, etc.)
+- textarea
+- select
+- checkbox
+- hidden
+- alert (Display a static alert box in the form)
+
+### The controller part
+Once your fields defined in the `schema` json or yaml file, you need to load that schema in your controller.
+
+First thing to do is add FormGenerator's `Form` class to your "use" list :
+`use UserFrosting\Sprinkle\FormGenerator\Form;`
+
+Next, where you load the schema and setup the `validator`, you simply add the new Form creation:
+```
+// Load validator rules
+$schema = new RequestSchema("schema://project.json");
+$validator = new JqueryValidationAdapter($schema, $this->ci->translator);
+
+// Create the form
+$form = new Form($schema, $project);
+```
+
+In this example, `$project` can contain the default (or current value) of the fields. A data collection fetched from the database with eloquent can also be passed directly. That second argument can also be omited to create an empty form.
+
+Last thing to do is send the fields to Twig. In the list of retuned variables to the template, add the `fields` variable:
+```
+$this->ci->view->render($response, "pages/myPage.html.twig", [
+ "fields" => $form->generate(),
+ "validators" => $validator->rules('json', true)
+]);
+
+```
+
+### The Twig template part
+
+Now it's time to display the form in `myPage.html.twig` !
+
+```
+