gina 0.0.9-p91b → 0.1.1-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTALL.md +46 -0
- package/{core/asset/html/static.html → Icon/r} +0 -0
- package/LICENSE +1 -1
- package/README-4Contributors.md +96 -0
- package/README.md +296 -104
- package/bin/cli +287 -0
- package/bin/cli-debug +60 -0
- package/bin/cmd +184 -0
- package/bin/gina +180 -0
- package/config/logger.json +17 -0
- package/doc/framework/cli/doc.json +9 -0
- package/doc/framework/index.md +60 -0
- package/framework/v0.1.1-alpha.2/AUTHORS +7 -0
- package/{core/utils/lib/inherits → framework/v0.1.1-alpha.2}/LICENSE +1 -1
- package/framework/v0.1.1-alpha.2/VERSION +1 -0
- package/{core/locales/dist/language/en.json → framework/v0.1.1-alpha.2/core/asset/html/nolayout.html} +0 -0
- package/{core/locales/dist/language/fr.json → framework/v0.1.1-alpha.2/core/asset/html/static.html} +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/android-chrome-192x192.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/android-chrome-512x512.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/apple-touch-icon.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/favicon-16x16.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/favicon-32x32.png +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/asset/img/favicon.ico +0 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.js +20904 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.js.map +56 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.css +1 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.css.map +1 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.js +736 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.js.map +56 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.onload.min.js +5 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.onload.min.js.map +8 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/readme.md +192 -0
- package/framework/v0.1.1-alpha.2/core/asset/js/plugin/uuid.json +23 -0
- package/framework/v0.1.1-alpha.2/core/config.js +2308 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/index.js +757 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/connector.js +20 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/connector.v2.js +429 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/connector.v3.js +432 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/n1ql.js +14 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/session-store.js +21 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/session-store.v2.js +258 -0
- package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/session-store.v3.js +341 -0
- package/{core → framework/v0.1.1-alpha.2/core}/controller/controller.framework.js +3 -2
- package/framework/v0.1.1-alpha.2/core/controller/controller.js +3990 -0
- package/{core → framework/v0.1.1-alpha.2/core}/controller/index.js +5 -5
- package/framework/v0.1.1-alpha.2/core/deps/busboy/.travis.yml +17 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/LICENSE +19 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/README.md +225 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/deps/encoding/encoding-indexes.js +73 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/deps/encoding/encoding.js +2391 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/main.js +89 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/types/multipart.js +328 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/types/urlencoded.js +214 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/utils.js +191 -0
- package/framework/v0.1.1-alpha.2/core/deps/busboy/package.json +69 -0
- package/framework/v0.1.1-alpha.2/core/deps/swig-client/swig-2.0.0.min.js +5 -0
- package/{core → framework/v0.1.1-alpha.2/core}/dev/index.js +5 -5
- package/{core → framework/v0.1.1-alpha.2/core}/dev/lib/class.js +1 -1
- package/{core → framework/v0.1.1-alpha.2/core}/dev/lib/factory.js +1 -1
- package/{core → framework/v0.1.1-alpha.2/core}/dev/lib/tools.js +0 -0
- package/framework/v0.1.1-alpha.2/core/gna.js +1070 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/README.md +41 -2
- package/{core → framework/v0.1.1-alpha.2/core}/locales/currency.json +0 -0
- package/{core/plugins/README.md → framework/v0.1.1-alpha.2/core/locales/dist/language/en.json} +0 -0
- package/{core/plugins/lib/intl/README.md → framework/v0.1.1-alpha.2/core/locales/dist/language/fr.json} +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/dist/region/en.json +0 -0
- package/framework/v0.1.1-alpha.2/core/locales/dist/region/fr.json +9492 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/index.js +5 -4
- package/{core → framework/v0.1.1-alpha.2/core}/locales/src/make.js +15 -12
- package/{core → framework/v0.1.1-alpha.2/core}/locales/src/resources/currency.csv +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/src/resources/region.csv +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/locales/src/resources/region.mapping.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/mime.types +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/model/entity.js +156 -196
- package/{core → framework/v0.1.1-alpha.2/core}/model/index.js +67 -48
- package/{core → framework/v0.1.1-alpha.2/core}/model/template/entityFactory.js +2 -2
- package/{core → framework/v0.1.1-alpha.2/core}/model/template/index.js +8 -10
- package/{core/plugins/lib/storage → framework/v0.1.1-alpha.2/core/plugins}/README.md +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/index.js +3 -3
- package/{core/plugins/lib/validator → framework/v0.1.1-alpha.2/core/plugins/lib/file}/README.md +0 -0
- package/{core/plugins/lib/intl → framework/v0.1.1-alpha.2/core/plugins/lib/file}/build.json +0 -0
- package/framework/v0.1.1-alpha.2/core/plugins/lib/file/package.json +25 -0
- package/{core/utils/lib/collection → framework/v0.1.1-alpha.2/core/plugins/lib/intl}/README.md +0 -0
- package/{core/plugins/lib/storage → framework/v0.1.1-alpha.2/core/plugins/lib/intl}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/intl/package.json +3 -3
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/intl/src/main.js +17 -1
- package/{core/utils/lib/routing → framework/v0.1.1-alpha.2/core/plugins/lib/storage}/README.md +0 -0
- package/{core/plugins/lib/validator → framework/v0.1.1-alpha.2/core/plugins/lib/storage}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/storage/package.json +2 -2
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/storage/src/main.js +91 -85
- package/{core/utils/lib/url → framework/v0.1.1-alpha.2/core/plugins/lib/validator}/README.md +0 -0
- package/{core/utils/lib/collection → framework/v0.1.1-alpha.2/core/plugins/lib/validator}/build.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/validator/package.json +3 -3
- package/framework/v0.1.1-alpha.2/core/plugins/lib/validator/src/form-validator.js +1762 -0
- package/framework/v0.1.1-alpha.2/core/plugins/lib/validator/src/main.js +6917 -0
- package/framework/v0.1.1-alpha.2/core/router.js +664 -0
- package/framework/v0.1.1-alpha.2/core/server.express.js +213 -0
- package/framework/v0.1.1-alpha.2/core/server.isaac.js +386 -0
- package/framework/v0.1.1-alpha.2/core/server.js +3010 -0
- package/{core → framework/v0.1.1-alpha.2/core}/status.codes +8 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/app.json +6 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/routing.json +11 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/settings.json +9 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/settings.server.json +30 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/templates.json +42 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/controllers/controller.content.js +39 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/controllers/controller.js +30 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/controllers/setup.js +111 -0
- package/{core/template/samples → framework/v0.1.1-alpha.2/core/template/boilerplate}/bundle/index.js +0 -0
- package/{core/template/samples/bundle → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_namespace}/controllers/controller.js +9 -7
- package/{core/template/views → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public}/css/default.css +0 -0
- package/{core/template/views → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public}/css/vendor/readme.md +0 -0
- package/{core/template/views → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public}/favicon.ico +0 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public/js/vendor/readme.md +1 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public/readme.md +1 -0
- package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_templates/handlers/main.js +24 -0
- package/{core/template/views/html/default.html → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_templates/html/homepage.html} +0 -0
- package/{core/template/views/html/layout.html → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_templates/html/layout/main.html} +2 -2
- package/{core → framework/v0.1.1-alpha.2/core}/template/command/gina.bat.tpl +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/command/gina.tpl +1 -1
- package/framework/v0.1.1-alpha.2/core/template/conf/env.json +76 -0
- package/{core/template/conf/project.json → framework/v0.1.1-alpha.2/core/template/conf/manifest.json} +1 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/conf/package.json +2 -2
- package/framework/v0.1.1-alpha.2/core/template/conf/settings.json +92 -0
- package/framework/v0.1.1-alpha.2/core/template/conf/statics.json +10 -0
- package/framework/v0.1.1-alpha.2/core/template/conf/templates.json +37 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/client/json/401.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/client/json/403.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/client/json/404.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/server/html/50x.html +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/server/json/500.json +0 -0
- package/{core → framework/v0.1.1-alpha.2/core}/template/error/server/json/503.json +0 -0
- package/{core/utils/lib/routing/build.json → framework/v0.1.1-alpha.2/core/template/extensions/logger/config.json} +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/console.js +3 -3
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/context.js +240 -49
- package/framework/v0.1.1-alpha.2/helpers/dateFormat.js +528 -0
- package/framework/v0.1.1-alpha.2/helpers/index.js +79 -0
- package/framework/v0.1.1-alpha.2/helpers/json/README.md +0 -0
- package/framework/v0.1.1-alpha.2/helpers/json/package.json +20 -0
- package/framework/v0.1.1-alpha.2/helpers/json/src/main.js +97 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/path.js +342 -140
- package/framework/v0.1.1-alpha.2/helpers/plugins/README.md +4 -0
- package/framework/v0.1.1-alpha.2/helpers/plugins/package.json +20 -0
- package/framework/v0.1.1-alpha.2/helpers/plugins/src/api-error.js +160 -0
- package/framework/v0.1.1-alpha.2/helpers/plugins/src/main.js +32 -0
- package/framework/v0.1.1-alpha.2/helpers/prototypes.js +218 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/task.js +49 -29
- package/{core/utils → framework/v0.1.1-alpha.2}/helpers/text.js +7 -7
- package/framework/v0.1.1-alpha.2/lib/archiver/README.md +0 -0
- package/framework/v0.1.1-alpha.2/lib/archiver/build.json +0 -0
- package/framework/v0.1.1-alpha.2/lib/archiver/package.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/archiver/src/dep/jszip.min.js +15 -0
- package/framework/v0.1.1-alpha.2/lib/archiver/src/main.js +499 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/aliases.json +13 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/add.js +507 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/arguments.json +4 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/copy.js +15 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/cp.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/help.txt +67 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/list.js +129 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/remove.js +229 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/rename.js +4 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/restart.js +235 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/rm.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/start.js +394 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/status.js +3 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/bundle/stop.js +232 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/add.js +436 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/get.js +62 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/help.txt +33 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/link-dev.js +80 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/list.js +111 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/remove.js +150 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/rm.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/set.js +57 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/unset.js +44 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/env/use.js +79 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/dot.js +70 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/get.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/help.js +39 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/help.txt +31 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/init.js +514 -0
- package/{core/utils/lib/cmd → framework/v0.1.1-alpha.2/lib/cmd/framework}/msg.json +3 -3
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/open.js +50 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/restart.js +124 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/set.js +161 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/start.js +96 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/status.js +72 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/stop.js +159 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/tail.js +183 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/update.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/framework/version.js +44 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/gina-dev.1.md +66 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/gina-framework.1.md +100 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/gina.1.md +79 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/helper.js +1147 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/index.js +170 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/msg.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/help.txt +31 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/inc/scan.js +108 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/list.js +176 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/port/set.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/add.js +528 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/arguments.json +9 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/build.js +115 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/help.txt +76 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/import.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/list.js +55 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/move.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/remove.js +144 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/rename.js +162 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/restart.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/rm.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/start.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/status.js +3 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/project/stop.js +0 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/protocol/help.js +27 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/protocol/help.txt +57 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/protocol/list.js +239 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/protocol/set.js +631 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/help.js +28 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/help.txt +33 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/link-local.js +80 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/list.js +116 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/remove.js +150 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/rm.js +2 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/set.js +57 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/unset.js +44 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/scope/use.js +79 -0
- package/framework/v0.1.1-alpha.2/lib/cmd/view/add.js +311 -0
- package/framework/v0.1.1-alpha.2/lib/collection/README.md +5 -0
- package/framework/v0.1.1-alpha.2/lib/collection/build.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/collection/package.json +2 -2
- package/framework/v0.1.1-alpha.2/lib/collection/src/main.js +1459 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/config.js +49 -34
- package/framework/v0.1.1-alpha.2/lib/cron/README.md +7 -0
- package/framework/v0.1.1-alpha.2/lib/cron/package.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/cron/src/main.js +176 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/generator/index.js +8 -4
- package/framework/v0.1.1-alpha.2/lib/index.js +116 -0
- package/framework/v0.1.1-alpha.2/lib/inherits/LICENSE +19 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/README.md +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/inheriting_eventemitter.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/protected_inheritance.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/simple_inheritance.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/super_attribute_overridden_by_child_on_init.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/package.json +2 -2
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/src/main.js +18 -19
- package/framework/v0.1.1-alpha.2/lib/logger/README.md +7 -0
- package/framework/v0.1.1-alpha.2/lib/logger/package.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/default/index.js +55 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/file/index.js +251 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/file/lib/logrotator/README.md +100 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/file/lib/logrotator/index.js +274 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/mq/index.js +52 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/mq/listener.js +302 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/containers/mq/speaker.js +118 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/helper.js +131 -0
- package/framework/v0.1.1-alpha.2/lib/logger/src/main.js +734 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/math/index.js +58 -35
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/README.md +5 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/example/merge.js +1 -1
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/example/merge_2_literal objects.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/example/merge_and_preserve_first.js +2 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/package.json +2 -2
- package/framework/v0.1.1-alpha.2/lib/merge/src/main.js +531 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/model.js +42 -19
- package/framework/v0.1.1-alpha.2/lib/proc.js +518 -0
- package/framework/v0.1.1-alpha.2/lib/routing/README.md +0 -0
- package/framework/v0.1.1-alpha.2/lib/routing/build.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/routing/package.json +2 -2
- package/framework/v0.1.1-alpha.2/lib/routing/src/main.js +1492 -0
- package/framework/v0.1.1-alpha.2/lib/session-store.js +33 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/shell.js +43 -30
- package/framework/v0.1.1-alpha.2/lib/swig-filters/README.md +0 -0
- package/framework/v0.1.1-alpha.2/lib/swig-filters/package.json +20 -0
- package/framework/v0.1.1-alpha.2/lib/swig-filters/src/main.js +322 -0
- package/framework/v0.1.1-alpha.2/lib/url/README.md +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/index.js +2 -1
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/mocks.json +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/routing.json +9 -9
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/test.js +0 -0
- package/{core/utils → framework/v0.1.1-alpha.2}/lib/validator.js +7 -7
- package/framework/v0.1.1-alpha.2/package.json +14 -0
- package/package.json +35 -33
- package/resources/etc/init.d/debian/gina +117 -0
- package/resources/home/framework/env.json +34 -0
- package/resources/home/framework/locals.json +14 -0
- package/resources/home/framework/project.json +48 -0
- package/resources/home/framework/projects.json +6 -0
- package/resources/home/main.json +47 -0
- package/resources/home/settings.json +22 -0
- package/resources/home/user/extensions/logger/default/config.json +77 -0
- package/resources/home/user/extensions/logger/file/config.json +11 -0
- package/resources/img/android-chrome-192x192.png +0 -0
- package/resources/img/android-chrome-512x512.png +0 -0
- package/resources/img/apple-touch-icon.png +0 -0
- package/resources/img/favicon-16x16.png +0 -0
- package/resources/img/favicon-32x32.png +0 -0
- package/resources/img/favicon.ico +0 -0
- package/resources/package.json.template +50 -0
- package/script/lib.js +24 -0
- package/script/post_install.js +449 -157
- package/script/pre_install.js +277 -36
- package/script/prepare_version.js +425 -0
- package/utils/helper.js +438 -0
- package/utils/prototypes.js +239 -0
- package/utils/prototypes.json_clone.js +175 -0
- package/.npmignore +0 -6
- package/MIDDLEWARE +0 -1
- package/SUCCESS +0 -1
- package/VERSION +0 -1
- package/core/asset/html/nolayout.html +0 -1
- package/core/asset/js/plugin/build.dev.json +0 -28
- package/core/asset/js/plugin/build.json +0 -31
- package/core/asset/js/plugin/dist/gina.min.css +0 -1
- package/core/asset/js/plugin/dist/gina.min.css.map +0 -1
- package/core/asset/js/plugin/dist/gina.min.js +0 -13731
- package/core/asset/js/plugin/dist/gina.min.js.map +0 -42
- package/core/asset/js/plugin/dist/gina.onload.min.js +0 -3
- package/core/asset/js/plugin/dist/gina.onload.min.js.map +0 -8
- package/core/asset/js/plugin/readme.md +0 -152
- package/core/asset/js/plugin/src/gina/main.js +0 -132
- package/core/asset/js/plugin/src/gina/popin/css/design.css +0 -23
- package/core/asset/js/plugin/src/gina/popin/css/main.css +0 -1112
- package/core/asset/js/plugin/src/gina/popin/css/popin.css +0 -3
- package/core/asset/js/plugin/src/gina/popin/css/popin.css.map +0 -1
- package/core/asset/js/plugin/src/gina/popin/doc/TOC.md +0 -29
- package/core/asset/js/plugin/src/gina/popin/doc/css.md +0 -162
- package/core/asset/js/plugin/src/gina/popin/doc/extend.md +0 -663
- package/core/asset/js/plugin/src/gina/popin/doc/faq.md +0 -46
- package/core/asset/js/plugin/src/gina/popin/doc/html.md +0 -227
- package/core/asset/js/plugin/src/gina/popin/doc/js.md +0 -37
- package/core/asset/js/plugin/src/gina/popin/doc/misc.md +0 -178
- package/core/asset/js/plugin/src/gina/popin/doc/usage.md +0 -130
- package/core/asset/js/plugin/src/gina/popin/main.js +0 -783
- package/core/asset/js/plugin/src/gina/popin/sass/config.sass +0 -37
- package/core/asset/js/plugin/src/gina/popin/sass/gina-design.sass +0 -622
- package/core/asset/js/plugin/src/gina/popin/sass/gina-popin.sass +0 -54
- package/core/asset/js/plugin/src/gina/popin/sass/helper.scss +0 -73
- package/core/asset/js/plugin/src/gina/toolbar/.npmignore +0 -19
- package/core/asset/js/plugin/src/gina/toolbar/css/toolbar.css +0 -433
- package/core/asset/js/plugin/src/gina/toolbar/css/toolbar.css.map +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/index.html +0 -285
- package/core/asset/js/plugin/src/gina/toolbar/index.kit +0 -120
- package/core/asset/js/plugin/src/gina/toolbar/jquery-3.1.0.min.js +0 -4
- package/core/asset/js/plugin/src/gina/toolbar/main.js +0 -693
- package/core/asset/js/plugin/src/gina/toolbar/mock.gina.json +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/mock.user.json +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/readme.md +0 -7
- package/core/asset/js/plugin/src/gina/toolbar/sass/toolbar.sass +0 -563
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/Info-color.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/Info-grey.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/error-color.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/error-grey.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/info-optim.svg +0 -13
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/logo-gina.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings-big.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings.afdesign +0 -0
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-calendar-optim.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-calendar.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-card-optim.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-card.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-lock-optim.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-lock.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/warning-color.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/svg-src/warning-grey.svg +0 -1
- package/core/asset/js/plugin/src/gina/toolbar/test.jpg +0 -0
- package/core/asset/js/plugin/src/gina/toolbar/toolbar.html +0 -104
- package/core/asset/js/plugin/src/gina/utils/dom.js +0 -24
- package/core/asset/js/plugin/src/gina/utils/events.js +0 -201
- package/core/asset/js/plugin/src/gina/utils/loader.js +0 -57
- package/core/asset/js/plugin/src/main.js +0 -235
- package/core/asset/js/plugin/src/vendor/jquery/1.11.1-css-event_alias.min.js +0 -5
- package/core/asset/js/plugin/src/vendor/jquery/1.12.4.min.js +0 -5
- package/core/asset/js/plugin/src/vendor/jquery/2.1.1-css-event_alias-sizzle.min.js +0 -4
- package/core/asset/js/plugin/src/vendor/jquery/README.md +0 -14
- package/core/asset/js/plugin/src/vendor/jquery/slim-3.1.1.min.js +0 -4
- package/core/config.js +0 -1225
- package/core/controller/controller.js +0 -1860
- package/core/gna.js +0 -908
- package/core/plugins/lib/validator/src/form-validator.js +0 -788
- package/core/plugins/lib/validator/src/main.js +0 -2056
- package/core/router.js +0 -717
- package/core/server.js +0 -1363
- package/core/template/conf/env.json +0 -70
- package/core/template/conf/settings.json +0 -48
- package/core/template/conf/statics.json +0 -6
- package/core/template/conf/views.json +0 -16
- package/core/template/samples/bundle/config/app.json +0 -4
- package/core/template/samples/bundle/config/routing.json +0 -9
- package/core/template/samples/bundle/controllers/setup.js +0 -33
- package/core/template/views/js/vendor/readme.md +0 -1
- package/core/template/views/readme.md +0 -1
- package/core/utils/helpers/dateFormat.js +0 -264
- package/core/utils/helpers/index.js +0 -202
- package/core/utils/index.js +0 -75
- package/core/utils/lib/cmd/app.js +0 -686
- package/core/utils/lib/cmd/basic.help.txt +0 -40
- package/core/utils/lib/cmd/basic.js +0 -141
- package/core/utils/lib/cmd/gina-add-bundle.js +0 -328
- package/core/utils/lib/cmd/gina-add-views.js +0 -99
- package/core/utils/lib/cmd/gina-build.js +0 -218
- package/core/utils/lib/cmd/gina-clean.js +0 -26
- package/core/utils/lib/cmd/gina-connect.js +0 -176
- package/core/utils/lib/cmd/gina-delete-bundle.js +0 -176
- package/core/utils/lib/cmd/gina-deploy.js +0 -452
- package/core/utils/lib/cmd/gina-init-project.js +0 -83
- package/core/utils/lib/cmd/gina-start-bundle.js +0 -3
- package/core/utils/lib/cmd/gina-start.js +0 -3
- package/core/utils/lib/cmd/index.js +0 -157
- package/core/utils/lib/cmd/project.js +0 -14
- package/core/utils/lib/collection/src/main.js +0 -650
- package/core/utils/lib/logger/containers/file.js +0 -11
- package/core/utils/lib/logger/index.js +0 -260
- package/core/utils/lib/merge/src/main.js +0 -344
- package/core/utils/lib/proc.js +0 -416
- package/core/utils/lib/routing/src/main.js +0 -165
- package/documentation/css/default.css +0 -3
- package/documentation/html/home.html +0 -6
- package/documentation/html/inc/_footer.html +0 -5
- package/documentation/html/layout.html +0 -21
- package/documentation/img/debug-conf1.png +0 -0
- package/documentation/img/debug-conf2.png +0 -0
- package/documentation/img/debug-conf3.png +0 -0
- package/documentation/img/debug-conf4.png +0 -0
- package/documentation/img/debug-conf5.png +0 -0
- package/documentation/img/debug-conf6.png +0 -0
- package/documentation/img/debug-conf7.png +0 -0
- package/documentation/img/debug-new1.png +0 -0
- package/documentation/img/debug-new2.png +0 -0
- package/documentation/img/debug-start.png +0 -0
- package/documentation/md/api/controller/main.md +0 -74
- package/migration_note.md +0 -7
- package/package-lock.json +0 -611
- package/script/pre_publish.js +0 -207
- package/tutorial/Commands/README.md +0 -56
- package/tutorial/Commands/add-bundle-result.png +0 -0
- package/tutorial/Commands/add-bundle.png +0 -0
- package/tutorial/Commands/delete-bundle.png +0 -0
- package/tutorial/Commands/help.png +0 -0
- package/tutorial/Commands/init-project.png +0 -0
- package/tutorial/Commands/start-bundle-result.png +0 -0
- package/tutorial/Commands/start-bundle-stop.png +0 -0
- package/tutorial/Commands/start-bundle.png +0 -0
- package/tutorial/Commands/version.png +0 -0
- package/tutorial/ETC/README.md +0 -74
- package/tutorial/ETC/add-bundle-result.png +0 -0
- package/tutorial/ETC/add-bundle.png +0 -0
- package/tutorial/ETC/init-project.png +0 -0
- package/tutorial/Install/README.md +0 -54
- package/tutorial/Install/git-get.png +0 -0
- package/tutorial/Install/git-install-end.png +0 -0
- package/tutorial/Install/git-install-result.png +0 -0
- package/tutorial/Install/git-install-start.png +0 -0
- package/tutorial/Install/install-end.png +0 -0
- package/tutorial/Install/install-result.png +0 -0
- package/tutorial/Install/install-start.png +0 -0
- package/tutorial/WebStorm/README.md +0 -30
- package/tutorial/WebStorm/closure-compiler.png +0 -0
- package/tutorial/WebStorm/sass.png +0 -0
|
@@ -1,2056 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ValidatorPlugin
|
|
3
|
-
*
|
|
4
|
-
* Dependencies:
|
|
5
|
-
* - utils/form-validator
|
|
6
|
-
* - utils/merge
|
|
7
|
-
* - utils/events
|
|
8
|
-
* - vendor/uuid
|
|
9
|
-
*
|
|
10
|
-
* @param {object} rule
|
|
11
|
-
* @param {object} [ data ] // from request
|
|
12
|
-
* @param {string} [ formId ]
|
|
13
|
-
* */
|
|
14
|
-
function ValidatorPlugin(rules, data, formId) {
|
|
15
|
-
|
|
16
|
-
this.plugin = 'validator';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* validator event handler - isGFFCtx only
|
|
20
|
-
* */
|
|
21
|
-
var events = ['ready', 'error', 'progress', 'submit', 'success', 'change', "destroy"];
|
|
22
|
-
|
|
23
|
-
/** imports */
|
|
24
|
-
var isGFFCtx = ( ( typeof(module) !== 'undefined' ) && module.exports ) ? false : true;
|
|
25
|
-
if (isGFFCtx) {
|
|
26
|
-
require('utils/events');
|
|
27
|
-
registerEvents(this.plugin, events);
|
|
28
|
-
|
|
29
|
-
require('utils/dom');
|
|
30
|
-
|
|
31
|
-
} else {
|
|
32
|
-
var cacheless = (process.env.IS_CACHELESS == 'false') ? false : true;
|
|
33
|
-
if (cacheless) {
|
|
34
|
-
delete require.cache[require.resolve('./form-validator')]
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var uuid = (isGFFCtx) ? require('vendor/uuid') : require('uuid');
|
|
39
|
-
var merge = (isGFFCtx) ? require('utils/merge') : require('../../../../utils/lib/merge');
|
|
40
|
-
var FormValidator = (isGFFCtx) ? require('utils/form-validator') : require('./form-validator');
|
|
41
|
-
|
|
42
|
-
/** definitions */
|
|
43
|
-
var instance = { // isGFFCtx only
|
|
44
|
-
'id' : 'validator-' + uuid.v1(),
|
|
45
|
-
|
|
46
|
-
'plugin' : this.plugin,
|
|
47
|
-
'on' : (isGFFCtx) ? on : null,
|
|
48
|
-
'eventData' : {},
|
|
49
|
-
'target' : (isGFFCtx) ? document : null, // by default
|
|
50
|
-
|
|
51
|
-
'initialized' : false,
|
|
52
|
-
'isReady' : false,
|
|
53
|
-
'rules' : {},
|
|
54
|
-
'$forms' : {},
|
|
55
|
-
'getFormById' : null,
|
|
56
|
-
'validateFormById' : null,
|
|
57
|
-
'setOptions' : null,
|
|
58
|
-
'resetErrorsDisplay': null,
|
|
59
|
-
'resetFields' : null
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// validator proto
|
|
63
|
-
var $validator = { // isGFFCtx only
|
|
64
|
-
'id' : null, // form id
|
|
65
|
-
|
|
66
|
-
'plugin' : this.plugin,
|
|
67
|
-
'on' : (isGFFCtx) ? on : null,
|
|
68
|
-
'eventData' : {},
|
|
69
|
-
'target' : (isGFFCtx) ? document : null, // by default
|
|
70
|
-
|
|
71
|
-
'binded' : false,
|
|
72
|
-
'withUserBindings' : false,
|
|
73
|
-
'rules' : {},
|
|
74
|
-
'setOptions' : null,
|
|
75
|
-
'send' : null,
|
|
76
|
-
'submit' : null,
|
|
77
|
-
'destroy' : null,
|
|
78
|
-
'resetErrorsDisplay' : null,
|
|
79
|
-
'resetFields' : null
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* XML Request - isGFFCtx only
|
|
85
|
-
* */
|
|
86
|
-
var xhr = null;
|
|
87
|
-
var xhrOptions = {
|
|
88
|
-
'url' : '',
|
|
89
|
-
'method' : 'GET',
|
|
90
|
-
'isSynchrone' : false,
|
|
91
|
-
'withCredentials': false,
|
|
92
|
-
'headers' : {
|
|
93
|
-
// to upload, use `multipart/form-data` for `enctype`
|
|
94
|
-
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
95
|
-
// cross domain is enabled by default, but you need to setup `Access-Control-Allow-Origin`
|
|
96
|
-
'X-Requested-With': 'XMLHttpRequest' // in case of cross domain origin
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* backend definitions
|
|
103
|
-
* */
|
|
104
|
-
var setCustomRules = function (customRules) {
|
|
105
|
-
// parsing rules
|
|
106
|
-
if ( typeof(customRule) != 'undefined' ) {
|
|
107
|
-
parseRules(customRule, '');
|
|
108
|
-
checkForRulesImports(customRule);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
var backendProto = {
|
|
113
|
-
'setCustomRules': setCustomRules
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Backend init
|
|
119
|
-
*
|
|
120
|
-
* @param {object} rules
|
|
121
|
-
* @param {object} [customRule]
|
|
122
|
-
* */
|
|
123
|
-
var backendInit = function (rules, data, formId) {
|
|
124
|
-
|
|
125
|
-
var $form = ( typeof(formId) != 'undefined' ) ? { 'id': formId } : null;
|
|
126
|
-
var fields = {};
|
|
127
|
-
|
|
128
|
-
for (var field in data) {
|
|
129
|
-
fields[field] = data[field]
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// parsing rules
|
|
134
|
-
if ( typeof(rules) != 'undefined' && rules.count() > 0 ) {
|
|
135
|
-
parseRules(rules, '');
|
|
136
|
-
checkForRulesImports(rules);
|
|
137
|
-
|
|
138
|
-
backendProto.rules = instance.rules;
|
|
139
|
-
|
|
140
|
-
return validate($form, fields, null, instance.rules)
|
|
141
|
-
|
|
142
|
-
} else {
|
|
143
|
-
// without rules - by hand
|
|
144
|
-
return new FormValidator(fields)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* GFF definitions
|
|
151
|
-
* */
|
|
152
|
-
|
|
153
|
-
var setOptions = function (options) {
|
|
154
|
-
var options = merge(options, xhrOptions);
|
|
155
|
-
xhrOptions = options;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
var getFormById = function(formId) {
|
|
160
|
-
var $form = null, _id = formId;
|
|
161
|
-
|
|
162
|
-
if ( !instance['$forms'] )
|
|
163
|
-
throw new Error('`$forms` collection not found');
|
|
164
|
-
|
|
165
|
-
if ( typeof(_id) == 'undefined') {
|
|
166
|
-
throw new Error('[ FormValidator::getFormById(formId) ] `formId` is missing')
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
_id = _id.replace(/\#/, '');
|
|
170
|
-
|
|
171
|
-
if ( typeof(instance['$forms'][_id]) != 'undefined' ) {
|
|
172
|
-
instance['$forms'][_id].withUserBindings = true;
|
|
173
|
-
|
|
174
|
-
$form = this.$forms[_id] = instance['$forms'][_id];
|
|
175
|
-
|
|
176
|
-
return $form
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return null
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* validateFormById
|
|
185
|
-
*
|
|
186
|
-
* @param {string} formId
|
|
187
|
-
* @param {object} [customRule]
|
|
188
|
-
*
|
|
189
|
-
* @return {object} $form
|
|
190
|
-
* */
|
|
191
|
-
var validateFormById = function(formId, customRule) {
|
|
192
|
-
var $form = null, _id = formId;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if ( !instance['$forms'] ) {
|
|
196
|
-
throw new Error('`$forms` collection not found')
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if ( typeof(_id) == 'undefined') {
|
|
201
|
-
if ( typeof(this.id) != 'undefined' && this.id != '' && this.id != null ) {
|
|
202
|
-
_id = this.id
|
|
203
|
-
} else {
|
|
204
|
-
throw new Error('[ FormValidator::validateFormById(formId, customRule) ] `formId` is missing')
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if ( typeof(_id) == 'string') {
|
|
209
|
-
_id = _id.replace(/\#/, '')
|
|
210
|
-
} else if ( typeof(_id) == 'object' && !Array.isArray(_id) ) { // weird exception
|
|
211
|
-
|
|
212
|
-
var $target = _id.form;
|
|
213
|
-
_id = $target.getAttribute('id') || 'form.'+uuid.v1();
|
|
214
|
-
|
|
215
|
-
$target.setAttribute('id', _id);// just in case
|
|
216
|
-
|
|
217
|
-
} else {
|
|
218
|
-
throw new Error('[ FormValidator::validateFormById(formId[, customRule]) ] `formId` should be a `string`');
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if ( typeof(instance['$forms'][_id]) != 'undefined' ) {
|
|
222
|
-
$form = this.$forms[_id] = instance['$forms'][_id];
|
|
223
|
-
} else { // binding a form out of context (outside of the main instance)
|
|
224
|
-
var $target = document.getElementById(_id);
|
|
225
|
-
$validator.id = _id;
|
|
226
|
-
$validator.target = $target;
|
|
227
|
-
|
|
228
|
-
$form = this.$forms[_id] = instance.$forms[_id] = merge({}, $validator);
|
|
229
|
-
|
|
230
|
-
var rule = null;
|
|
231
|
-
if ( typeof(customRule) == 'undefined') {
|
|
232
|
-
rule = _id.replace(/\-/g, '.');
|
|
233
|
-
|
|
234
|
-
if ( typeof(instance.rules[rule]) != 'undefined' ) {
|
|
235
|
-
$form['rule'] = customRule = instance.rules[rule];
|
|
236
|
-
} else if ( $form.target.getAttribute('data-gina-form-rule') ) {
|
|
237
|
-
rule = $form.target.getAttribute('data-gina-form-rule').replace(/\-/g, '.');
|
|
238
|
-
|
|
239
|
-
if ( typeof(instance.rules[rule]) != 'undefined' ) {
|
|
240
|
-
$form['rule'] = instance.rules[rule]
|
|
241
|
-
} else {
|
|
242
|
-
throw new Error('[ FormValidator::validateFormById(formId) ] using `data-gina-form-rule` on form `'+$form.target+'`: no matching rule found')
|
|
243
|
-
}
|
|
244
|
-
} // no else to allow form without any rule
|
|
245
|
-
} else {
|
|
246
|
-
rule = customRule.replace(/\-/g, '.');
|
|
247
|
-
|
|
248
|
-
if ( typeof(instance.rules[rule]) != 'undefined' ) {
|
|
249
|
-
$form['rule'] = instance.rules[rule]
|
|
250
|
-
} else {
|
|
251
|
-
throw new Error('[ FormValidator::validateFormById(formId, customRule) ] `'+customRule+'` is not a valid rule')
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if ($target && !$form.binded)
|
|
256
|
-
bindForm($target, rule);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (!$form) throw new Error('[ FormValidator::validateFormById(formId, customRule) ] `'+_id+'` not found');
|
|
260
|
-
|
|
261
|
-
return $form || null;
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
var handleErrorsDisplay = function($form, errors, data) {
|
|
266
|
-
|
|
267
|
-
if ( gina.options.env == 'dev' )
|
|
268
|
-
var formsErrors = null;
|
|
269
|
-
|
|
270
|
-
var name = null, errAttr = null;
|
|
271
|
-
var $err = null, $msg = null;
|
|
272
|
-
var $el = null, $parent = null, $target = null;
|
|
273
|
-
var id = $form.getAttribute('id');
|
|
274
|
-
|
|
275
|
-
for (var i = 0, len = $form.length; i<len; ++i) {
|
|
276
|
-
$el = $form[i];
|
|
277
|
-
if ( /form\-item\-wrapper$/.test($el.parentNode.className) ) {
|
|
278
|
-
$parent = $el.parentNode.parentNode;
|
|
279
|
-
$target = $el.parentNode;
|
|
280
|
-
} else {
|
|
281
|
-
$parent = $el.parentNode;
|
|
282
|
-
$target = $el;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
name = $el.getAttribute('name');
|
|
286
|
-
errAttr = $el.getAttribute('data-gina-form-errors');
|
|
287
|
-
|
|
288
|
-
if (!name) continue;
|
|
289
|
-
|
|
290
|
-
if ( typeof(errors[name]) != 'undefined' && !/form\-item\-error/.test($parent.className) ) {
|
|
291
|
-
|
|
292
|
-
$parent.className += ($parent.className == '' ) ? 'form-item-error' : ' form-item-error';
|
|
293
|
-
|
|
294
|
-
$err = document.createElement('div');
|
|
295
|
-
$err.setAttribute('class', 'form-item-error-message');
|
|
296
|
-
|
|
297
|
-
// injecting error messages
|
|
298
|
-
for (var e in errors[name]) {
|
|
299
|
-
|
|
300
|
-
if (e != 'stack') { // ignore stack for display
|
|
301
|
-
$msg = document.createElement('p');
|
|
302
|
-
$msg.appendChild( document.createTextNode(errors[name][e]) );
|
|
303
|
-
$err.appendChild($msg);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if ( gina.options.env == 'dev' ) {
|
|
307
|
-
if (!formsErrors) formsErrors = {};
|
|
308
|
-
if ( !formsErrors[ name ] )
|
|
309
|
-
formsErrors[ name ] = {};
|
|
310
|
-
|
|
311
|
-
formsErrors[ name ][e] = errors[name][e]
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if ($target.type != 'hidden')
|
|
316
|
-
insertAfter($target, $err);
|
|
317
|
-
|
|
318
|
-
} else if ( typeof(errors[name]) == 'undefined' && /form\-item\-error/.test($parent.className) ) {
|
|
319
|
-
// reset when not in error
|
|
320
|
-
// remove child elements
|
|
321
|
-
var $children = $parent.getElementsByTagName('div');
|
|
322
|
-
for (var c = 0, cLen = $children.length; c<cLen; ++c) {
|
|
323
|
-
if ( /form\-item\-error\-message/.test($children[c].className) ) {
|
|
324
|
-
//$parent.removeChild($children[c]);
|
|
325
|
-
$children[c].parentElement.removeChild($children[c]);
|
|
326
|
-
break
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
$parent.className = $parent.className.replace(/(\s+form\-item\-error|form\-item\-error)/, '');
|
|
331
|
-
|
|
332
|
-
} else if ( typeof(errors[name]) != 'undefined' && errAttr) {
|
|
333
|
-
// refreshing already displayed error on msg update
|
|
334
|
-
var $divs = $parent.getElementsByTagName('div');
|
|
335
|
-
for (var d = 0, dLen = $divs.length; d<dLen; ++d) {
|
|
336
|
-
if ($divs[d].className == 'form-item-error-message') {
|
|
337
|
-
|
|
338
|
-
$divs[d].parentElement.removeChild($divs[d]);
|
|
339
|
-
$err = document.createElement('div');
|
|
340
|
-
$err.setAttribute('class', 'form-item-error-message');
|
|
341
|
-
|
|
342
|
-
// injecting error messages
|
|
343
|
-
for (var e in errors[name]) {
|
|
344
|
-
$msg = document.createElement('p');
|
|
345
|
-
$msg.appendChild( document.createTextNode(errors[name][e]) );
|
|
346
|
-
$err.appendChild($msg);
|
|
347
|
-
|
|
348
|
-
if ( gina.options.env == 'dev' ) {
|
|
349
|
-
if (!formsErrors) formsErrors = {};
|
|
350
|
-
if ( !formsErrors[ name ] )
|
|
351
|
-
formsErrors[ name ] = {};
|
|
352
|
-
|
|
353
|
-
formsErrors[ name ][e] = errors[name][e]
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
break;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if ($target.type != 'hidden')
|
|
362
|
-
insertAfter($target, $err);
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if ( formsErrors ) {
|
|
369
|
-
|
|
370
|
-
triggerEvent(gina, $form, 'error.' + id, errors)
|
|
371
|
-
|
|
372
|
-
if ( typeof(window.ginaToolbar) == 'object' ) {
|
|
373
|
-
// update toolbar
|
|
374
|
-
if (!gina.forms.errors)
|
|
375
|
-
gina.forms.errors = {};
|
|
376
|
-
|
|
377
|
-
gina.forms.errors = formsErrors;
|
|
378
|
-
|
|
379
|
-
window.ginaToolbar.update('forms', gina.forms);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Reset errors display
|
|
388
|
-
*
|
|
389
|
-
* @param {object|string} [$form|formId]
|
|
390
|
-
*
|
|
391
|
-
* */
|
|
392
|
-
var resetErrorsDisplay = function($form) {
|
|
393
|
-
var $form = $form, _id = null;
|
|
394
|
-
if ( typeof($form) == 'undefined' ) {
|
|
395
|
-
if ( typeof(this.target) != 'undefined' ) {
|
|
396
|
-
_id = this.target.getAttribute('id');
|
|
397
|
-
} else {
|
|
398
|
-
_id = this.getAttribute('id');
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
$form = instance.$forms[_id]
|
|
402
|
-
} else if ( typeof($form) == 'string' ) {
|
|
403
|
-
_id = $form;
|
|
404
|
-
_id = _id.replace(/\#/, '');
|
|
405
|
-
|
|
406
|
-
if ( typeof(instance.$forms[_id]) == 'undefined') {
|
|
407
|
-
throw new Error('[ FormValidator::resetErrorsDisplay([formId]) ] `'+$form+'` not found')
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
$form = instance.$forms[_id]
|
|
411
|
-
}
|
|
412
|
-
//reseting error display
|
|
413
|
-
handleErrorsDisplay($form['target'], []);
|
|
414
|
-
|
|
415
|
-
return $form
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Reset fields
|
|
420
|
-
*
|
|
421
|
-
* @param {object|string} [$form|formId]
|
|
422
|
-
*
|
|
423
|
-
* */
|
|
424
|
-
var resetFields = function($form) {
|
|
425
|
-
var $form = $form, _id = null;
|
|
426
|
-
if ( typeof($form) == 'undefined' ) {
|
|
427
|
-
if ( typeof(this.target) != 'undefined' ) {
|
|
428
|
-
_id = this.target.getAttribute('id');
|
|
429
|
-
} else {
|
|
430
|
-
_id = this.getAttribute('id');
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
$form = instance.$forms[_id]
|
|
434
|
-
} else if ( typeof($form) == 'string' ) {
|
|
435
|
-
_id = $form;
|
|
436
|
-
_id = _id.replace(/\#/, '');
|
|
437
|
-
|
|
438
|
-
if ( typeof(instance.$forms[_id]) == 'undefined') {
|
|
439
|
-
throw new Error('[ FormValidator::resetErrorsDisplay([formId]) ] `'+$form+'` not found')
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
$form = instance.$forms[_id]
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
if ($form.defaultFields) {
|
|
446
|
-
|
|
447
|
-
var elId = null
|
|
448
|
-
, $element = null
|
|
449
|
-
, type = null;
|
|
450
|
-
|
|
451
|
-
for (var f in $form.defaultFields) {
|
|
452
|
-
|
|
453
|
-
$element = document.getElementById(f)
|
|
454
|
-
type = $element.tagName.toLowerCase();
|
|
455
|
-
|
|
456
|
-
if (type == 'input') {
|
|
457
|
-
$element.value = $form.defaultFields[f];
|
|
458
|
-
} else if ( type == 'select' ) {
|
|
459
|
-
$element.options[ $form.defaultFields[f] ].selected = true;
|
|
460
|
-
$element.setAttribute('data-value', $element.options[ $form.defaultFields[f] ].value);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return $form
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// TODO - efreshErrorsDisplay
|
|
469
|
-
// var refreshErrorsDisplay = function ($form) {
|
|
470
|
-
//
|
|
471
|
-
// }
|
|
472
|
-
|
|
473
|
-
var submit = function () {
|
|
474
|
-
|
|
475
|
-
var $form = null, _id = null, $target = null;
|
|
476
|
-
|
|
477
|
-
if ( this.getAttribute ) {
|
|
478
|
-
_id = this.getAttribute('id');
|
|
479
|
-
$target = this;
|
|
480
|
-
} else if ( typeof(this.target) && this.target.getAttribute ) {
|
|
481
|
-
_id = this.target.getAttribute('id');
|
|
482
|
-
$target = this.target
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
if ( typeof(instance.$forms[_id]) == 'undefined') {
|
|
486
|
-
throw new Error('[ FormValidator::submit() ] not `$form` binded. Use `FormValidator::getFormById(id)` or `FormValidator::validateFormById(id)` first ')
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
triggerEvent(gina, $target, 'submit');
|
|
490
|
-
|
|
491
|
-
return this;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* send
|
|
497
|
-
* N.B.: no validation here; if you want to validate against rules, use `.submit()` before
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
* @param {object} data
|
|
501
|
-
* @param {object} [ options ]
|
|
502
|
-
* */
|
|
503
|
-
var send = function(data, options) {
|
|
504
|
-
|
|
505
|
-
var $target = this.target , id = $target.getAttribute('id');
|
|
506
|
-
var $form = instance.$forms[id] || this;
|
|
507
|
-
|
|
508
|
-
// forward callback to HTML attribute
|
|
509
|
-
listenToXhrEvents($form);
|
|
510
|
-
|
|
511
|
-
if (options) {
|
|
512
|
-
var options = merge(options, xhrOptions);
|
|
513
|
-
} else {
|
|
514
|
-
var options = xhrOptions;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
var url = $target.getAttribute('action') || options.url;
|
|
518
|
-
var method = $target.getAttribute('method') || options.method;
|
|
519
|
-
method = method.toUpperCase();
|
|
520
|
-
options.method = method;
|
|
521
|
-
options.url = url;
|
|
522
|
-
|
|
523
|
-
// to upload, use `multipart/form-data` for `enctype`
|
|
524
|
-
var enctype = $target.getAttribute('enctype');
|
|
525
|
-
|
|
526
|
-
if ( options.withCredentials ) {
|
|
527
|
-
|
|
528
|
-
if ('withCredentials' in xhr) {
|
|
529
|
-
// XHR for Chrome/Firefox/Opera/Safari.
|
|
530
|
-
if (options.isSynchrone) {
|
|
531
|
-
xhr.open(options.method, options.url, options.isSynchrone)
|
|
532
|
-
} else {
|
|
533
|
-
xhr.open(options.method, options.url)
|
|
534
|
-
}
|
|
535
|
-
} else if ( typeof XDomainRequest != 'undefined' ) {
|
|
536
|
-
// XDomainRequest for IE.
|
|
537
|
-
xhr = new XDomainRequest();
|
|
538
|
-
xhr.open(options.method, options.url);
|
|
539
|
-
} else {
|
|
540
|
-
// CORS not supported.
|
|
541
|
-
xhr = null;
|
|
542
|
-
var result = 'CORS not supported: the server is missing the header `"Access-Control-Allow-Credentials": true` ';
|
|
543
|
-
triggerEvent(gina, $target, 'error.' + id, result);
|
|
544
|
-
|
|
545
|
-
return
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
xhr.withCredentials = true;
|
|
549
|
-
} else {
|
|
550
|
-
if (options.isSynchrone) {
|
|
551
|
-
xhr.open(options.method, options.url, options.isSynchrone)
|
|
552
|
-
} else {
|
|
553
|
-
xhr.open(options.method, options.url)
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// setting up headers
|
|
558
|
-
for (var hearder in options.headers) {
|
|
559
|
-
if ( hearder == 'Content-Type' && typeof (enctype) != 'undefined' && enctype != null && enctype != '') {
|
|
560
|
-
options.headers[hearder] = enctype
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
xhr.setRequestHeader(hearder, options.headers[hearder]);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
if (xhr) {
|
|
567
|
-
// catching ready state cb
|
|
568
|
-
xhr.onreadystatechange = function (event) {
|
|
569
|
-
|
|
570
|
-
if (xhr.readyState == 4) {
|
|
571
|
-
// 200, 201, 201' etc ...
|
|
572
|
-
if( /^2/.test(xhr.status) ) {
|
|
573
|
-
|
|
574
|
-
try {
|
|
575
|
-
var result = xhr.responseText;
|
|
576
|
-
if ( /json$/.test( xhr.getResponseHeader("Content-Type") ) ) {
|
|
577
|
-
result = JSON.parse(xhr.responseText)
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
$form.eventData.success = result;
|
|
581
|
-
|
|
582
|
-
var XHRData = result;
|
|
583
|
-
if ( gina && typeof(window.ginaToolbar) == "object" && XHRData ) {
|
|
584
|
-
try {
|
|
585
|
-
|
|
586
|
-
if ( typeof(XHRData) != 'undefined' ) {
|
|
587
|
-
window.ginaToolbar.update("data-xhr", XHRData);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
} catch (err) {
|
|
591
|
-
throw err
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
triggerEvent(gina, $target, 'success.' + id, result)
|
|
596
|
-
|
|
597
|
-
} catch (err) {
|
|
598
|
-
var result = {
|
|
599
|
-
status: 422,
|
|
600
|
-
error : err.message,
|
|
601
|
-
stack : err.stack
|
|
602
|
-
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
$form.eventData.error = result;
|
|
606
|
-
|
|
607
|
-
// // update toolbar
|
|
608
|
-
// var XHRData = result;
|
|
609
|
-
// if ( gina && typeof(window.ginaToolbar) == "object" && XHRData ) {
|
|
610
|
-
// try {
|
|
611
|
-
//
|
|
612
|
-
// // forward backend appplication errors to forms.errors when available
|
|
613
|
-
// if ( XHRData.error && typeof(XHRData.error) == 'object' && $form.fields ) {
|
|
614
|
-
// var formsErrors = {}, errCount = 0;
|
|
615
|
-
// for (var e in XHRData.error) {
|
|
616
|
-
// if ( typeof($form.fields[e]) != 'undefined' ) {
|
|
617
|
-
// ++errCount;
|
|
618
|
-
// formsErrors[e] = XHRData.error[e];
|
|
619
|
-
//
|
|
620
|
-
// if ( typeof(XHRData.stack) != 'undefined' )
|
|
621
|
-
// formsErrors[e].stack = XHRData.stack;
|
|
622
|
-
// }
|
|
623
|
-
// }
|
|
624
|
-
//
|
|
625
|
-
// if (errCount > 0) {
|
|
626
|
-
// handleErrorsDisplay($form.target, formsErrors);
|
|
627
|
-
// }
|
|
628
|
-
// }
|
|
629
|
-
// // update toolbar
|
|
630
|
-
// ginaToolbar.update("data-xhr", XHRData );
|
|
631
|
-
//
|
|
632
|
-
// } catch (err) {
|
|
633
|
-
// throw err
|
|
634
|
-
// }
|
|
635
|
-
// }
|
|
636
|
-
|
|
637
|
-
var XHRData = result;
|
|
638
|
-
if ( gina && typeof(window.ginaToolbar) == "object" && XHRData ) {
|
|
639
|
-
try {
|
|
640
|
-
|
|
641
|
-
if ( typeof(XHRData) != 'undefined' ) {
|
|
642
|
-
window.ginaToolbar.update("data-xhr", XHRData);
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
} catch (err) {
|
|
646
|
-
throw err
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
triggerEvent(gina, $target, 'error.' + id, result)
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
} else if ( xhr.status != 0) {
|
|
654
|
-
|
|
655
|
-
var result = { 'status': xhr.status };
|
|
656
|
-
|
|
657
|
-
if ( /^(\{|\[).test( xhr.responseText ) /) {
|
|
658
|
-
|
|
659
|
-
try {
|
|
660
|
-
result = JSON.parse(xhr.responseText);
|
|
661
|
-
} catch (err) {
|
|
662
|
-
result = merge(result, err)
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
} else if ( typeof(xhr.responseText) == 'object' ) {
|
|
666
|
-
result = xhr.responseText
|
|
667
|
-
} else {
|
|
668
|
-
result.message = xhr.responseText
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
$form.eventData.error = result;
|
|
672
|
-
|
|
673
|
-
// update toolbar
|
|
674
|
-
var XHRData = result;
|
|
675
|
-
if ( gina && typeof(window.ginaToolbar) == "object" && XHRData ) {
|
|
676
|
-
try {
|
|
677
|
-
|
|
678
|
-
// forward backend appplication errors to forms.errors when available
|
|
679
|
-
if ( XHRData.error && typeof(XHRData.error) == 'object' && $form.fields ) {
|
|
680
|
-
var formsErrors = {}, errCount = 0;
|
|
681
|
-
for (var e in XHRData.error) {
|
|
682
|
-
if ( typeof($form.fields[e]) != 'undefined' ) {
|
|
683
|
-
++errCount;
|
|
684
|
-
formsErrors[e] = XHRData.error[e];
|
|
685
|
-
|
|
686
|
-
if ( typeof(XHRData.stack) != 'undefined' )
|
|
687
|
-
formsErrors[e].stack = XHRData.stack;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
if (errCount > 0) {
|
|
692
|
-
handleErrorsDisplay($form.target, formsErrors);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
// update toolbar
|
|
696
|
-
ginaToolbar.update('data-xhr', XHRData );
|
|
697
|
-
|
|
698
|
-
} catch (err) {
|
|
699
|
-
throw err
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
triggerEvent(gina, $target, 'error.' + id, result)
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
|
|
708
|
-
// catching request progress
|
|
709
|
-
xhr.onprogress = function(event) {
|
|
710
|
-
// console.log(
|
|
711
|
-
// 'progress position '+ event.position,
|
|
712
|
-
// '\nprogress total size '+ event.totalSize
|
|
713
|
-
// );
|
|
714
|
-
|
|
715
|
-
var percentComplete = (event.position / event.totalSize)*100;
|
|
716
|
-
var result = {
|
|
717
|
-
'status': 100,
|
|
718
|
-
'progress': percentComplete
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
$form.eventData.onprogress = result;
|
|
722
|
-
|
|
723
|
-
triggerEvent(gina, $target, 'progress.' + id, result)
|
|
724
|
-
};
|
|
725
|
-
|
|
726
|
-
// catching timeout
|
|
727
|
-
xhr.ontimeout = function (event) {
|
|
728
|
-
var result = {
|
|
729
|
-
'status': 408,
|
|
730
|
-
'error': 'Request Timeout'
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
$form.eventData.ontimeout = result;
|
|
734
|
-
|
|
735
|
-
triggerEvent(gina, $target, 'error.' + id, result)
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
// sending
|
|
740
|
-
if (!data)
|
|
741
|
-
data = event.detail.data;
|
|
742
|
-
|
|
743
|
-
if (data) {
|
|
744
|
-
if ( typeof(data) == 'object' ) {
|
|
745
|
-
try {
|
|
746
|
-
data = JSON.stringify(data)
|
|
747
|
-
} catch (err) {
|
|
748
|
-
triggerEvent(gina, $target, 'error.' + id, err)
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
//console.log('sending -> ', data);
|
|
752
|
-
//try {
|
|
753
|
-
xhr.send(data)
|
|
754
|
-
// } catch (err) {
|
|
755
|
-
// var XHRData = result;
|
|
756
|
-
// if ( gina && typeof(window.ginaToolbar) == "object" && XHRData ) {
|
|
757
|
-
// try {
|
|
758
|
-
//
|
|
759
|
-
// if ( typeof(XHRData) != 'undefined' ) {
|
|
760
|
-
// window.ginaToolbar.update("data-xhr", XHRData);
|
|
761
|
-
// }
|
|
762
|
-
//
|
|
763
|
-
// } catch (err) {
|
|
764
|
-
// throw err
|
|
765
|
-
// }
|
|
766
|
-
// }
|
|
767
|
-
// }
|
|
768
|
-
|
|
769
|
-
} else {
|
|
770
|
-
xhr.send()
|
|
771
|
-
}
|
|
772
|
-
$form.sent = true;
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
var listenToXhrEvents = function($form) {
|
|
779
|
-
|
|
780
|
-
//$form['plugin'] = $validator.plugin;
|
|
781
|
-
//$form['on'] = $validator.on;
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
//data-gina-form-event-on-submit-success
|
|
785
|
-
var htmlSuccesEventCallback = $form.target.getAttribute('data-gina-form-event-on-submit-success') || null;
|
|
786
|
-
if (htmlSuccesEventCallback != null) {
|
|
787
|
-
|
|
788
|
-
if ( /\((.*)\)/.test(htmlSuccesEventCallback) ) {
|
|
789
|
-
eval(htmlSuccesEventCallback)
|
|
790
|
-
} else {
|
|
791
|
-
$form.on('success', window[htmlSuccesEventCallback])
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
//data-gina-form-event-on-submit-error
|
|
796
|
-
var htmlErrorEventCallback = $form.target.getAttribute('data-gina-form-event-on-submit-error') || null;
|
|
797
|
-
if (htmlErrorEventCallback != null) {
|
|
798
|
-
if ( /\((.*)\)/.test(htmlErrorEventCallback) ) {
|
|
799
|
-
eval(htmlErrorEventCallback)
|
|
800
|
-
} else {
|
|
801
|
-
$form.on('error', window[htmlErrorEventCallback])
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
var destroy = function(formId) {
|
|
807
|
-
var $form = null, _id = formId;
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
if ( !instance['$forms'] )
|
|
811
|
-
throw new Error('`$forms` collection not found');
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
if ( typeof(_id) == 'undefined') {
|
|
815
|
-
if ( typeof(this.id) != 'undefined' && this.id != '' && this.id != null ) {
|
|
816
|
-
_id = this.id
|
|
817
|
-
} else {
|
|
818
|
-
throw new Error('[ FormValidator::destroy(formId) ] `formId` is missing')
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
if ( typeof(_id) == 'string') {
|
|
823
|
-
_id = _id.replace(/\#/, '')
|
|
824
|
-
} else if ( typeof(_id) == 'object' && !Array.isArray(_id) ) { // weird exception
|
|
825
|
-
var $target = _id.form;
|
|
826
|
-
_id = $target.getAttribute('id') || 'form.'+uuid.v1();
|
|
827
|
-
|
|
828
|
-
$target.setAttribute('id', _id);// just in case
|
|
829
|
-
|
|
830
|
-
} else {
|
|
831
|
-
throw new Error('[ FormValidator::destroy(formId) ] `formId` should be a `string`');
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
if ( typeof(instance['$forms'][_id]) != 'undefined' ) {
|
|
835
|
-
$form = instance['$forms'][_id]
|
|
836
|
-
} else if ( typeof(this.binded) != 'undefined' ) {
|
|
837
|
-
$form = this;
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
if ($form) {
|
|
841
|
-
// remove existing listeners
|
|
842
|
-
|
|
843
|
-
// form events
|
|
844
|
-
removeListener(gina, $form, 'success.' + _id);
|
|
845
|
-
removeListener(gina, $form, 'validate.' + _id);
|
|
846
|
-
removeListener(gina, $form, 'submit.' + _id);
|
|
847
|
-
removeListener(gina, $form, 'error.' + _id);
|
|
848
|
-
|
|
849
|
-
// binded elements
|
|
850
|
-
var $el = null
|
|
851
|
-
, evt = null
|
|
852
|
-
, $els = []
|
|
853
|
-
, $elTMP = [];
|
|
854
|
-
|
|
855
|
-
// submit buttons
|
|
856
|
-
$elTMP = $form.target.getElementsByTagName('button');
|
|
857
|
-
if ( $elTMP.length > 0 ) {
|
|
858
|
-
for(var i = 0, len = $elTMP.length; i < len; ++i) {
|
|
859
|
-
if ($elTMP[i].type == 'submit')
|
|
860
|
-
$els.push($elTMP[i])
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
// submit links
|
|
865
|
-
$elTMP = $form.target.getElementsByTagName('a');
|
|
866
|
-
if ( $elTMP.length > 0 ) {
|
|
867
|
-
for(var i = 0, len = $elTMP.length; i < len; ++i) {
|
|
868
|
-
if ( $elTMP[i].attributes.getNamedItem('data-gina-form-submit') || /^click\./.test( $elTMP[i].attributes.getNamedItem('id') ) )
|
|
869
|
-
$els.push($elTMP[i])
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
// checkbox & radio
|
|
874
|
-
$elTMP = $form.target.getElementsByTagName('input');
|
|
875
|
-
if ( $elTMP.length > 0 ) {
|
|
876
|
-
for(var i = 0, len = $elTMP.length; i < len; ++i) {
|
|
877
|
-
if ($elTMP[i].type == 'checkbox' || $elTMP[i].type == 'radio' )
|
|
878
|
-
$els.push( $elTMP[i] )
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
for (var i = 0, len = $els.length; i < len; ++i) {
|
|
883
|
-
|
|
884
|
-
$el = $els[i];
|
|
885
|
-
if ($el.type == 'submit') {
|
|
886
|
-
|
|
887
|
-
evt = $el.getAttribute('id');
|
|
888
|
-
if ( typeof(gina.events[ evt ]) != 'undefined' )
|
|
889
|
-
removeListener(gina, $el, gina.events[ evt ]);
|
|
890
|
-
|
|
891
|
-
} else {
|
|
892
|
-
|
|
893
|
-
evt ='click.' + $el.getAttribute('id');
|
|
894
|
-
if ( typeof(gina.events[ evt ]) != 'undefined' )
|
|
895
|
-
removeListener(gina, $el, evt);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
$form.binded = false;
|
|
900
|
-
|
|
901
|
-
//addListener(gina, instance['$forms'][_id].target, 'destroy.' + _id, function(event) {
|
|
902
|
-
addListener(gina, $form.target, 'destroy.' + _id, function(event) {
|
|
903
|
-
|
|
904
|
-
cancelEvent(event);
|
|
905
|
-
|
|
906
|
-
delete instance['$forms'][_id];
|
|
907
|
-
removeListener(gina, event.currentTarget, event.type);
|
|
908
|
-
removeListener(gina, event.currentTarget,'destroy');
|
|
909
|
-
});
|
|
910
|
-
|
|
911
|
-
//triggerEvent(gina, instance['$forms'][_id].target, 'destroy.' + _id);
|
|
912
|
-
triggerEvent(gina, $form.target, 'destroy.' + _id);
|
|
913
|
-
|
|
914
|
-
} else {
|
|
915
|
-
throw new Error('[ FormValidator::destroy(formId) ] `'+_id+'` not found');
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
var checkForRulesImports = function (rules) {
|
|
921
|
-
// check if rules has imports & replace
|
|
922
|
-
var rulesStr = JSON.stringify(rules, null, 4);
|
|
923
|
-
var importedRules = rulesStr.match(/(\"@import\s+[a-z A-Z 0-9/.]+\")/g);
|
|
924
|
-
if (importedRules && importedRules.length > 0) {
|
|
925
|
-
var ruleArr = [], rule = {}, tmpRule = null;
|
|
926
|
-
for (var r = 0, len = importedRules.length; r<len; ++r) {
|
|
927
|
-
ruleArr = importedRules[r].replace(/(@import\s+|\"|\')/g, '').split(/\s/g);
|
|
928
|
-
// [""@import client/form", ""@import project26/edit demo/edit"]
|
|
929
|
-
//console.log('ruleArr -> ', ruleArr, importedRules[r]);
|
|
930
|
-
for (var i = 0, iLen = ruleArr.length; i<iLen; ++i) {
|
|
931
|
-
tmpRule = ruleArr[i].replace(/\//g, '.');
|
|
932
|
-
if ( typeof(instance.rules[ tmpRule ]) != 'undefined' ) {
|
|
933
|
-
rule = merge(rule, instance.rules[ tmpRule ])
|
|
934
|
-
} else {
|
|
935
|
-
console.warn('[formValidator:rules] <@import error> on `'+importedRules[r]+'`: rule `'+ruleArr[i]+'` not found. Ignoring.')
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
//console.log('replacing ', importedRules[r]);
|
|
939
|
-
rulesStr = rulesStr.replace(importedRules[r], JSON.stringify(rule));
|
|
940
|
-
instance.rules = JSON.parse( JSON.stringify(instance.rules).replace( new RegExp(importedRules[r], 'g'), JSON.stringify(rule)) );
|
|
941
|
-
//console.log('str ', rulesStr);
|
|
942
|
-
rule = {}
|
|
943
|
-
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
if (!instance.rules) {
|
|
947
|
-
instance.rules = {}
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
rules = JSON.parse(rulesStr);
|
|
951
|
-
parseRules(rules, '');
|
|
952
|
-
|
|
953
|
-
// if (!isGFFCtx) {
|
|
954
|
-
// backendProto.rules = instance.rules
|
|
955
|
-
// }
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
var init = function (rules) {
|
|
960
|
-
|
|
961
|
-
if (gina.hasValidator) {
|
|
962
|
-
instance = merge(instance, gina.validator);
|
|
963
|
-
instance.on('init', function(event) {
|
|
964
|
-
instance.isReady = true;
|
|
965
|
-
triggerEvent(gina, instance.target, 'ready.' + instance.id, instance)
|
|
966
|
-
})
|
|
967
|
-
} else {
|
|
968
|
-
setupInstanceProto();
|
|
969
|
-
instance.on('init', function(event) {
|
|
970
|
-
// parsing rules
|
|
971
|
-
if ( typeof(rules) != 'undefined' && rules.count() ) {
|
|
972
|
-
gina.forms.rules = JSON.parse(JSON.stringify(rules));// making copy
|
|
973
|
-
parseRules(rules, '');
|
|
974
|
-
checkForRulesImports(rules);
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
$validator.setOptions = setOptions;
|
|
978
|
-
$validator.getFormById = getFormById;
|
|
979
|
-
$validator.validateFormById = validateFormById;
|
|
980
|
-
$validator.resetErrorsDisplay = resetErrorsDisplay;
|
|
981
|
-
$validator.resetFields = resetFields;
|
|
982
|
-
$validator.handleErrorsDisplay = handleErrorsDisplay;
|
|
983
|
-
$validator.submit = submit;
|
|
984
|
-
$validator.send = send;
|
|
985
|
-
$validator.destroy = destroy;
|
|
986
|
-
|
|
987
|
-
var id = null
|
|
988
|
-
, $target = null
|
|
989
|
-
, i = 0
|
|
990
|
-
, $forms = []
|
|
991
|
-
, $allForms = document.getElementsByTagName('form');
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
// has rule ?
|
|
995
|
-
for (var f=0, len = $allForms.length; f<len; ++f) {
|
|
996
|
-
// preparing prototype (need at least an ID for this)
|
|
997
|
-
|
|
998
|
-
if ($allForms[f].getAttribute) {
|
|
999
|
-
id = $allForms[f].getAttribute('id') || 'form.' + uuid.v1();
|
|
1000
|
-
if ( id !== $allForms[f].getAttribute('id') ) {
|
|
1001
|
-
$allForms[f].setAttribute('id', id)
|
|
1002
|
-
}
|
|
1003
|
-
} else {
|
|
1004
|
-
id = 'form.' + uuid.v1();
|
|
1005
|
-
$allForms[f].setAttribute('id', id)
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
$allForms[f]['id'] = $validator.id = id;
|
|
1009
|
-
|
|
1010
|
-
if ( typeof($allForms[f].id) != 'undefined' && $allForms[f].id != 'null' && $allForms[f].id != '') {
|
|
1011
|
-
|
|
1012
|
-
$validator.target = $allForms[f];
|
|
1013
|
-
instance.$forms[$allForms[f].id] = merge({}, $validator);
|
|
1014
|
-
|
|
1015
|
-
var customRule = $allForms[f].getAttribute('data-gina-form-rule');
|
|
1016
|
-
|
|
1017
|
-
if (customRule) {
|
|
1018
|
-
customRule = customRule.replace(/\-/g, '.');
|
|
1019
|
-
if ( typeof(instance.rules[customRule]) == 'undefined' ) {
|
|
1020
|
-
throw new Error('['+$allForms[f].id+'] no rule found with key: `'+customRule+'`');
|
|
1021
|
-
customRule = null
|
|
1022
|
-
} else {
|
|
1023
|
-
customRule = instance.rules[customRule]
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
// finding forms handled by rules
|
|
1028
|
-
if ( typeof($allForms[f].id) == 'string' && typeof(instance.rules[$allForms[f].id.replace(/\-/g, '.')]) != 'undefined' ) {
|
|
1029
|
-
$target = instance.$forms[$allForms[f].id].target;
|
|
1030
|
-
if (customRule) {
|
|
1031
|
-
bindForm($target, customRule)
|
|
1032
|
-
} else {
|
|
1033
|
-
bindForm($target)
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
++i
|
|
1037
|
-
} else {
|
|
1038
|
-
// weird exception when having in the form an element with name="id"
|
|
1039
|
-
if ( typeof($allForms[f].id) == 'object' ) {
|
|
1040
|
-
delete instance.$forms[$allForms[f].id];
|
|
1041
|
-
|
|
1042
|
-
var _id = $allForms[f].attributes.getNamedItem('id').nodeValue || 'form.'+uuid.v1();
|
|
1043
|
-
|
|
1044
|
-
$allForms[f].setAttribute('id', _id);
|
|
1045
|
-
$allForms[f]['id'] = _id;
|
|
1046
|
-
|
|
1047
|
-
$validator.target = $allForms[f];
|
|
1048
|
-
instance.$forms[_id] = merge({}, $validator);
|
|
1049
|
-
|
|
1050
|
-
$target = instance.$forms[_id].target;
|
|
1051
|
-
if (customRule) {
|
|
1052
|
-
bindForm($target, customRule)
|
|
1053
|
-
} else {
|
|
1054
|
-
bindForm($target)
|
|
1055
|
-
}
|
|
1056
|
-
} else {
|
|
1057
|
-
|
|
1058
|
-
$target = instance.$forms[$allForms[f].id].target;
|
|
1059
|
-
if (customRule) {
|
|
1060
|
-
bindForm($target, customRule)
|
|
1061
|
-
} else {
|
|
1062
|
-
bindForm($target)
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
// setting up AJAX
|
|
1072
|
-
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
|
|
1073
|
-
xhr = new XMLHttpRequest();
|
|
1074
|
-
} else if (window.ActiveXObject) { // IE
|
|
1075
|
-
try {
|
|
1076
|
-
xhr = new ActiveXObject("Msxml2.XMLHTTP");
|
|
1077
|
-
} catch (e) {
|
|
1078
|
-
try {
|
|
1079
|
-
xhr = new ActiveXObject("Microsoft.XMLHTTP");
|
|
1080
|
-
}
|
|
1081
|
-
catch (e) {}
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
instance.isReady = true;
|
|
1086
|
-
gina.hasValidator = true;
|
|
1087
|
-
gina.validator = instance;
|
|
1088
|
-
triggerEvent(gina, instance.target, 'ready.' + instance.id, instance);
|
|
1089
|
-
});
|
|
1090
|
-
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
instance.initialized = true;
|
|
1094
|
-
return instance
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
/**
|
|
1098
|
-
* parseRules - Preparing rules paths
|
|
1099
|
-
*
|
|
1100
|
-
* @param {object} rules
|
|
1101
|
-
* @param {string} tmp - path
|
|
1102
|
-
* */
|
|
1103
|
-
var parseRules = function(rules, tmp) {
|
|
1104
|
-
var _r = null;
|
|
1105
|
-
for (var r in rules) {
|
|
1106
|
-
|
|
1107
|
-
if ( typeof(rules[r]) == 'object' && typeof(instance.rules[tmp + r]) == 'undefined' ) {
|
|
1108
|
-
|
|
1109
|
-
_r = r;
|
|
1110
|
-
if (/\[|\]/.test(r) ) { // must be a real path
|
|
1111
|
-
_r = r.replace(/\[/g, '.').replace(/\]/g, '');
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
instance.rules[tmp + _r] = rules[r];
|
|
1115
|
-
//delete instance.rules[r];
|
|
1116
|
-
parseRules(rules[r], tmp + _r +'.');
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
/**
|
|
1122
|
-
* makeObject - Preparing form data
|
|
1123
|
-
*
|
|
1124
|
-
* @param {object} obj - data
|
|
1125
|
-
* @param {string\number\boolean} value
|
|
1126
|
-
* @param {array} string
|
|
1127
|
-
* @param {number} len
|
|
1128
|
-
* @param {number} i
|
|
1129
|
-
*
|
|
1130
|
-
* */
|
|
1131
|
-
var makeObject = function (obj, value, args, len, i) {
|
|
1132
|
-
|
|
1133
|
-
if (i >= len) {
|
|
1134
|
-
return false
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
var key = args[i].replace(/^\[|\]$/g, '');
|
|
1138
|
-
var nextKey = ( i < len-1 && typeof(args[i+1]) != 'undefined' ) ? args[i+1].replace(/^\[|\]$/g, '') : null;
|
|
1139
|
-
|
|
1140
|
-
if ( typeof(obj[key]) == 'undefined' ) {
|
|
1141
|
-
if (nextKey && /^\d+$/.test(nextKey)) {
|
|
1142
|
-
nextKey = parseInt(nextKey);
|
|
1143
|
-
obj[key] = []
|
|
1144
|
-
} else {
|
|
1145
|
-
obj[key] = {}
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
for (var o in obj) {
|
|
1150
|
-
|
|
1151
|
-
if ( typeof(obj[o]) == 'object' ) {
|
|
1152
|
-
|
|
1153
|
-
if ( Array.isArray(obj[o]) ) {
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
if (o === key) {
|
|
1157
|
-
|
|
1158
|
-
var _args = JSON.parse(JSON.stringify(args));
|
|
1159
|
-
_args.splice(0, 1);
|
|
1160
|
-
|
|
1161
|
-
for (var a = i, aLen = _args.length; a < aLen; ++a) {
|
|
1162
|
-
key = parseInt(_args[a].replace(/^\[|\]$/g, ''))
|
|
1163
|
-
obj[o][key] = {};
|
|
1164
|
-
|
|
1165
|
-
if (a == aLen-1) {
|
|
1166
|
-
obj[o][key] = value;
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
} else if ( o === key ) {
|
|
1172
|
-
|
|
1173
|
-
if (i == len-1) {
|
|
1174
|
-
obj[o] = value;
|
|
1175
|
-
} else {
|
|
1176
|
-
makeObject(obj[o], value, args, len, i+1)
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
var formatData = function (data) {
|
|
1185
|
-
|
|
1186
|
-
var args = null
|
|
1187
|
-
, obj = {}
|
|
1188
|
-
, key = null
|
|
1189
|
-
, fields = {};
|
|
1190
|
-
|
|
1191
|
-
for (name in data) {
|
|
1192
|
-
|
|
1193
|
-
if ( /\[(.*)\]/.test(name) ) {
|
|
1194
|
-
// backup name key
|
|
1195
|
-
key = name;
|
|
1196
|
-
|
|
1197
|
-
// properties
|
|
1198
|
-
args = name.match(/(\[[-_\[a-z 0-9]*\]\]|\[[-_\[a-z 0-9]*\])/ig);
|
|
1199
|
-
|
|
1200
|
-
// root
|
|
1201
|
-
name = name.match(/^[-_a-z 0-9]+\[{0}/ig);
|
|
1202
|
-
|
|
1203
|
-
// building object tree
|
|
1204
|
-
makeObject(obj, data[key], args, args.length, 0);
|
|
1205
|
-
|
|
1206
|
-
fields[name] = merge( fields[name], obj );
|
|
1207
|
-
obj = {}
|
|
1208
|
-
|
|
1209
|
-
} else {
|
|
1210
|
-
fields[name] = data[name];
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
return fields
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
var validate = function($form, fields, $fields, rules, cb) {
|
|
1219
|
-
|
|
1220
|
-
delete fields['_length']; //cleaning
|
|
1221
|
-
|
|
1222
|
-
var id = null, data = null;
|
|
1223
|
-
if (isGFFCtx) {
|
|
1224
|
-
id = $form.getAttribute('id') || $form.id;
|
|
1225
|
-
instance.$forms[id].fields = fields;
|
|
1226
|
-
}
|
|
1227
|
-
//console.log(fields, $fields);
|
|
1228
|
-
|
|
1229
|
-
var d = new FormValidator(fields, $fields), args = null;
|
|
1230
|
-
var fieldErrorsAttributes = {};
|
|
1231
|
-
var re = null, flags = null;
|
|
1232
|
-
|
|
1233
|
-
var forEachField = function($form, fields, $fields, rules, cb, i) {
|
|
1234
|
-
var hasCase = false, conditions = null;
|
|
1235
|
-
var caseValue = null, caseType = null;
|
|
1236
|
-
var localRules = null;
|
|
1237
|
-
|
|
1238
|
-
//console.log('parsing ', fields, $fields, rules);
|
|
1239
|
-
|
|
1240
|
-
for (var field in fields) {
|
|
1241
|
-
|
|
1242
|
-
hasCase = ( typeof(rules['_case_' + field]) != 'undefined' ) ? true : false;
|
|
1243
|
-
if (hasCase) {
|
|
1244
|
-
|
|
1245
|
-
conditions = rules['_case_' + field]['conditions'];
|
|
1246
|
-
|
|
1247
|
-
if ( !conditions ) {
|
|
1248
|
-
throw new Error('[ ginaFormValidator ] case `_case_'+field+'` found without `condition(s)` !');
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
for (var c = 0, cLen = conditions.length; c<cLen; ++c) {
|
|
1252
|
-
|
|
1253
|
-
caseValue = fields[field];
|
|
1254
|
-
|
|
1255
|
-
if (isGFFCtx) {
|
|
1256
|
-
if (fields[field] == "true")
|
|
1257
|
-
caseValue = true;
|
|
1258
|
-
else if (fields[field] == "false")
|
|
1259
|
-
caseValue = false;
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
//console.log(caseValue +' VS '+ conditions[c]['case'], "->", (caseValue == conditions[c]['case'] || Array.isArray(conditions[c]['case']) && conditions[c]['case'].indexOf(caseValue) > -1) );
|
|
1263
|
-
if ( conditions[c]['case'] === caseValue || Array.isArray(conditions[c]['case']) && conditions[c]['case'].indexOf(caseValue) > -1 || /^\//.test(conditions[c]['case']) ) {
|
|
1264
|
-
|
|
1265
|
-
//console.log('[fields ] ' + JSON.stringify(fields, null, 4));
|
|
1266
|
-
localRules = {};
|
|
1267
|
-
|
|
1268
|
-
for (var f in conditions[c]['rules']) {
|
|
1269
|
-
//console.log('F: ', f, '\nrule: '+ JSON.stringify(conditions[c]['rules'][f], null, 2));
|
|
1270
|
-
if ( /^\//.test(f) ) { // RegExp found
|
|
1271
|
-
|
|
1272
|
-
re = f.match(/\/(.*)\//).pop();
|
|
1273
|
-
flags = f.replace('/'+ re +'/', '');
|
|
1274
|
-
re = new RegExp(re, flags);
|
|
1275
|
-
|
|
1276
|
-
for (var localField in $fields) {
|
|
1277
|
-
if ( re.test(localField) ) {
|
|
1278
|
-
if ( /^\//.test(conditions[c]['case']) ) {
|
|
1279
|
-
re = conditions[c]['case'].match(/\/(.*)\//).pop();
|
|
1280
|
-
flags = conditions[c]['case'].replace('/'+ re +'/', '');
|
|
1281
|
-
re = new RegExp(re, flags);
|
|
1282
|
-
|
|
1283
|
-
if ( re.test(caseValue) ) {
|
|
1284
|
-
localRules[localField] = conditions[c]['rules'][f]
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
} else {
|
|
1288
|
-
localRules[localField] = conditions[c]['rules'][f]
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
} else {
|
|
1294
|
-
if ( /^\//.test(conditions[c]['case']) ) {
|
|
1295
|
-
re = conditions[c]['case'].match(/\/(.*)\//).pop();
|
|
1296
|
-
flags = conditions[c]['case'].replace('/'+ re +'/', '');
|
|
1297
|
-
re = new RegExp(re, flags);
|
|
1298
|
-
|
|
1299
|
-
if ( re.test(caseValue) ) {
|
|
1300
|
-
localRules[f] = conditions[c]['rules'][f]
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
} else {
|
|
1304
|
-
localRules[f] = conditions[c]['rules'][f]
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
//console.log('parsing ', localRules, fields);
|
|
1309
|
-
if (isGFFCtx)
|
|
1310
|
-
forEachField($form, fields, $fields, localRules, cb, i+1);
|
|
1311
|
-
else
|
|
1312
|
-
return forEachField($form, fields, $fields, localRules, cb, i+1);
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
if ( typeof(rules[field]) == 'undefined' ) continue;
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
// check against rule
|
|
1323
|
-
for (var rule in rules[field]) {
|
|
1324
|
-
// check for rule params
|
|
1325
|
-
try {
|
|
1326
|
-
|
|
1327
|
-
if ( Array.isArray(rules[field][rule]) ) { // has args
|
|
1328
|
-
//convert array to arguments
|
|
1329
|
-
args = rules[field][rule];
|
|
1330
|
-
d[field][rule].apply(d[field], args);
|
|
1331
|
-
} else {
|
|
1332
|
-
d[field][rule](rules[field][rule]);
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
} catch (err) {
|
|
1336
|
-
if (rule == 'conditions') {
|
|
1337
|
-
throw new Error('[ ginaFormValidator ] could not evaluate `'+field+'->'+rule+'()` where `conditions` must be a `collection` (Array)\nStack:\n'+ (err.stack|err.message))
|
|
1338
|
-
} else {
|
|
1339
|
-
throw new Error('[ ginaFormValidator ] could not evaluate `'+field+'->'+rule+'()`\nStack:\n'+ (err.stack|err.message))
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
--i;
|
|
1348
|
-
|
|
1349
|
-
if (i < 0) {
|
|
1350
|
-
|
|
1351
|
-
var errors = d['getErrors']();
|
|
1352
|
-
|
|
1353
|
-
// adding data attribute to handle display refresh
|
|
1354
|
-
for (var field in errors) {
|
|
1355
|
-
for (rule in errors[field]) {
|
|
1356
|
-
if (!fieldErrorsAttributes[field]) {
|
|
1357
|
-
fieldErrorsAttributes[field] = ''
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
if (fieldErrorsAttributes[field].indexOf(rule) < 0)
|
|
1361
|
-
fieldErrorsAttributes[field] += rule +' ';
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
if (isGFFCtx)
|
|
1365
|
-
$fields[field].setAttribute('data-gina-form-errors', fieldErrorsAttributes[field].substr(0, fieldErrorsAttributes[field].length-1))
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
//calling back
|
|
1369
|
-
try {
|
|
1370
|
-
data = formatData( d['toData']() );
|
|
1371
|
-
|
|
1372
|
-
if ( typeof(window.ginaToolbar) == 'object' ) {
|
|
1373
|
-
// update toolbar
|
|
1374
|
-
if (!gina.forms.sent)
|
|
1375
|
-
gina.forms.sent = {};
|
|
1376
|
-
|
|
1377
|
-
gina.forms.sent = data;
|
|
1378
|
-
|
|
1379
|
-
window.ginaToolbar.update('forms', gina.forms);
|
|
1380
|
-
}
|
|
1381
|
-
} catch (err) {
|
|
1382
|
-
throw err
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
if ( typeof(cb) != 'undefined' && typeof(cb) === 'function' ) {
|
|
1386
|
-
|
|
1387
|
-
cb({
|
|
1388
|
-
'isValid' : d['isValid'],
|
|
1389
|
-
'errors' : errors,
|
|
1390
|
-
'data' : data
|
|
1391
|
-
})
|
|
1392
|
-
|
|
1393
|
-
} else {
|
|
1394
|
-
|
|
1395
|
-
return {
|
|
1396
|
-
'isValid' : d['isValid'],
|
|
1397
|
-
'errors' : errors,
|
|
1398
|
-
'data' : data
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
if (isGFFCtx)
|
|
1405
|
-
forEachField($form, fields, $fields, rules, cb, 0);
|
|
1406
|
-
else
|
|
1407
|
-
return forEachField($form, fields, $fields, rules, cb, 0);
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
/**
|
|
1411
|
-
* bindForm
|
|
1412
|
-
*
|
|
1413
|
-
* @param {object} target - DOM element
|
|
1414
|
-
* @param {object} [customRule]
|
|
1415
|
-
* */
|
|
1416
|
-
var bindForm = function($target, customRule) {
|
|
1417
|
-
|
|
1418
|
-
var $form = null, _id = null;
|
|
1419
|
-
|
|
1420
|
-
try {
|
|
1421
|
-
if ( $target.getAttribute && $target.getAttribute('id') ) {
|
|
1422
|
-
_id = $target.getAttribute('id');
|
|
1423
|
-
if ( typeof(instance.$forms[_id]) != 'undefined')
|
|
1424
|
-
$form = instance.$forms[_id];
|
|
1425
|
-
else
|
|
1426
|
-
throw new Error('form instance `'+ _id +'` not found');
|
|
1427
|
-
|
|
1428
|
-
} else {
|
|
1429
|
-
throw new Error('Validator::bindForm($target, customRule): `$target` must be a DOM element\n'+err.stack )
|
|
1430
|
-
}
|
|
1431
|
-
} catch(err) {
|
|
1432
|
-
throw new Error('Validator::bindForm($target, customRule) could not bind form `'+ $target +'`\n'+err.stack )
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
if ( typeof($form) != 'undefined' && $form.binded) {
|
|
1436
|
-
return false
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
var withRules = false, rule = null, evt = '', procced = null;
|
|
1440
|
-
|
|
1441
|
-
if ( typeof(customRule) != 'undefined' || typeof(_id) == 'string' && typeof(instance.rules[_id.replace(/\-/g, '.')]) != 'undefined' ) {
|
|
1442
|
-
withRules = true;
|
|
1443
|
-
|
|
1444
|
-
if ( customRule && typeof(customRule) == 'object' ) {
|
|
1445
|
-
rule = customRule
|
|
1446
|
-
} else if ( customRule && typeof(customRule) == 'string' && typeof(instance.rules[customRule.replace(/\-/g, '.')]) != 'undefined') {
|
|
1447
|
-
rule = instance.rules[customRule.replace(/\-/g, '.')]
|
|
1448
|
-
} else {
|
|
1449
|
-
rule = instance.rules[_id.replace(/\-/g, '.')]
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
$form.rules = rule
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
// form fields
|
|
1456
|
-
if (!$form.defaultFields)
|
|
1457
|
-
$form.defaultFields = {};
|
|
1458
|
-
|
|
1459
|
-
// binding form elements
|
|
1460
|
-
var type = null
|
|
1461
|
-
, id = null
|
|
1462
|
-
// input: checkbox, radio
|
|
1463
|
-
, $inputs = $target.getElementsByTagName('input')
|
|
1464
|
-
// select
|
|
1465
|
-
, $select = $target.getElementsByTagName('select')
|
|
1466
|
-
;
|
|
1467
|
-
|
|
1468
|
-
var elId = null;
|
|
1469
|
-
for (var i = 0, len = $inputs.length; i < len; ++i) {
|
|
1470
|
-
elId = $inputs[i].getAttribute('id');
|
|
1471
|
-
if (!elId) {
|
|
1472
|
-
elId = 'input.' + uuid.v1();
|
|
1473
|
-
$inputs[i].setAttribute('id', elId)
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
if (!$form.defaultFields[ elId ])
|
|
1477
|
-
$form.defaultFields[ elId ] = $inputs[i].value;
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
var selectedIndex = null, selectedValue = null;
|
|
1481
|
-
for (var s = 0, sLen = $select.length; s < sLen; ++s) {
|
|
1482
|
-
elId = $select[s].getAttribute('id');
|
|
1483
|
-
if (!elId) {
|
|
1484
|
-
elId = 'select.' + uuid.v1();
|
|
1485
|
-
$select[s].setAttribute('id', elId)
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
if ($select[s].options && !$form.defaultFields[ elId ]) {
|
|
1489
|
-
selectedIndex = 0;
|
|
1490
|
-
selectedValue = $select[s].getAttribute('data-value');
|
|
1491
|
-
|
|
1492
|
-
if ( $select[s].options[ $select[s].selectedIndex ].index ) {
|
|
1493
|
-
selectedIndex = $select[s].options[ $select[s].selectedIndex ].index
|
|
1494
|
-
} else if ( typeof(selectedValue) != 'undefined' ) {
|
|
1495
|
-
for (var o = 0, oLen = $select[s].options.length; o < oLen; ++o ) {
|
|
1496
|
-
if ( $select[s].options[o].value == selectedValue) {
|
|
1497
|
-
selectedIndex = o;
|
|
1498
|
-
break
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
$form.defaultFields[ elId ] = selectedIndex;
|
|
1504
|
-
// update select
|
|
1505
|
-
$select[s].options[ selectedIndex ].selected = true;
|
|
1506
|
-
$select[s].setAttribute('data-value', $select[s].options[ selectedIndex ].value);
|
|
1507
|
-
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
var updateCheckBox = function($el) {
|
|
1512
|
-
|
|
1513
|
-
var checked = $el.checked;
|
|
1514
|
-
|
|
1515
|
-
if ( !checked || checked == 'null' || checked == 'false' || checked == '' ) {
|
|
1516
|
-
|
|
1517
|
-
// prevents ticking behavior
|
|
1518
|
-
setTimeout(function () {
|
|
1519
|
-
$el.checked = false;
|
|
1520
|
-
}, 0);
|
|
1521
|
-
|
|
1522
|
-
$el.removeAttribute('checked');
|
|
1523
|
-
$el.value = false;
|
|
1524
|
-
$el.setAttribute('value', 'false');
|
|
1525
|
-
|
|
1526
|
-
} else {
|
|
1527
|
-
|
|
1528
|
-
// prevents ticking behavior
|
|
1529
|
-
setTimeout(function () {
|
|
1530
|
-
$el.checked = true;
|
|
1531
|
-
}, 0);
|
|
1532
|
-
|
|
1533
|
-
$el.setAttribute('checked', 'checked');
|
|
1534
|
-
//boolean exception handling
|
|
1535
|
-
$el.value = true;
|
|
1536
|
-
$el.setAttribute('value', 'true');
|
|
1537
|
-
|
|
1538
|
-
}
|
|
1539
|
-
};
|
|
1540
|
-
|
|
1541
|
-
var updateRadio = function($el, isInit) {
|
|
1542
|
-
var checked = $el.checked;
|
|
1543
|
-
var isBoolean = /^(true|false)$/i.test($el.value);
|
|
1544
|
-
|
|
1545
|
-
// loop if radio group
|
|
1546
|
-
if (!isInit) {
|
|
1547
|
-
var radioGroup = document.getElementsByName($el.name);
|
|
1548
|
-
//console.log('found ', radioGroup.length, radioGroup)
|
|
1549
|
-
for (var r = 0, rLen = radioGroup.length; r < rLen; ++r) {
|
|
1550
|
-
if (radioGroup[r].id !== $el.id) {
|
|
1551
|
-
radioGroup[r].checked = false;
|
|
1552
|
-
radioGroup[r].removeAttribute('checked');
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
if ( !checked || checked == 'null' || checked == 'false' || checked == '' ) {
|
|
1558
|
-
|
|
1559
|
-
// prevents ticking behavior
|
|
1560
|
-
setTimeout(function () {
|
|
1561
|
-
$el.checked = false;
|
|
1562
|
-
}, 0)
|
|
1563
|
-
|
|
1564
|
-
$el.removeAttribute('checked');
|
|
1565
|
-
|
|
1566
|
-
if (isBoolean) {
|
|
1567
|
-
$el.value = false;
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
} else {
|
|
1571
|
-
|
|
1572
|
-
// prevents ticking behavior
|
|
1573
|
-
setTimeout(function () {
|
|
1574
|
-
$el.checked = true;
|
|
1575
|
-
}, 0)
|
|
1576
|
-
|
|
1577
|
-
$el.setAttribute('checked', 'checked');
|
|
1578
|
-
|
|
1579
|
-
if (isBoolean) { // no multiple choice supported
|
|
1580
|
-
$el.value = true;
|
|
1581
|
-
}
|
|
1582
|
-
var radioGroup = document.getElementsByName($el.name);
|
|
1583
|
-
//console.log('found ', radioGroup.length, radioGroup)
|
|
1584
|
-
for (var r = 0, rLen = radioGroup.length; r < rLen; ++r) {
|
|
1585
|
-
if (radioGroup[r].id !== $el.id) {
|
|
1586
|
-
radioGroup[r].checked = false;
|
|
1587
|
-
radioGroup[r].removeAttribute('checked');
|
|
1588
|
-
if (isBoolean) {
|
|
1589
|
-
radioGroup[r].value = false;
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
evt = 'click';
|
|
1599
|
-
|
|
1600
|
-
procced = function () {
|
|
1601
|
-
// click proxy
|
|
1602
|
-
addListener(gina, $target, 'click', function(event) {
|
|
1603
|
-
|
|
1604
|
-
if ( /(label)/i.test(event.target.tagName) )
|
|
1605
|
-
return false;
|
|
1606
|
-
|
|
1607
|
-
if ( typeof(event.target.id) == 'undefined' || !event.target.getAttribute('id') ) {
|
|
1608
|
-
event.target.setAttribute('id', 'click.' + uuid.v1() );
|
|
1609
|
-
event.target.id = event.target.getAttribute('id')
|
|
1610
|
-
} else {
|
|
1611
|
-
event.target.id = event.target.getAttribute('id')
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
if (/^click\./.test(event.target.id) || withRules) {
|
|
1616
|
-
|
|
1617
|
-
var _evt = event.target.id;
|
|
1618
|
-
|
|
1619
|
-
if (!_evt) return false;
|
|
1620
|
-
|
|
1621
|
-
if ( ! /^click\./.test(_evt) ) {
|
|
1622
|
-
_evt = event.target.id
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
// prevent event to be triggered twice
|
|
1626
|
-
if ( typeof(event.defaultPrevented) != 'undefined' && event.defaultPrevented )
|
|
1627
|
-
return false;
|
|
1628
|
-
|
|
1629
|
-
if (gina.events[_evt]) {
|
|
1630
|
-
cancelEvent(event);
|
|
1631
|
-
|
|
1632
|
-
triggerEvent(gina, event.target, _evt, event.detail);
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
})
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
procced()
|
|
1642
|
-
|
|
1643
|
-
for (var i=0, len = $inputs.length; i<len; ++i) {
|
|
1644
|
-
type = $inputs[i].getAttribute('type');
|
|
1645
|
-
|
|
1646
|
-
if ( typeof($inputs[i].id) == 'undefined' || $inputs[i].id == '' ) {
|
|
1647
|
-
$inputs[i]['id'] = type +'-'+ uuid.v1();
|
|
1648
|
-
$inputs[i].setAttribute('id', $inputs[i]['id'])
|
|
1649
|
-
}
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
// recover default state only on value === true || false || on
|
|
1653
|
-
if ( typeof(type) != 'undefined' && type == 'checkbox' && /^(true|false|on)$/i.test($inputs[i].value) || typeof(type) != 'undefined' && type == 'checkbox' && !$inputs[i].getAttribute('value') ) {
|
|
1654
|
-
|
|
1655
|
-
if ( !/^(true|false|on)$/i.test($inputs[i].value) ) {
|
|
1656
|
-
|
|
1657
|
-
if ( !$inputs[i].checked || $inputs[i].checked == 'null' || $inputs[i].checked == 'false' || $inputs[i].checked == '' ) {
|
|
1658
|
-
$inputs[i].value = false;
|
|
1659
|
-
$inputs[i].setAttribute('value', false)
|
|
1660
|
-
} else {
|
|
1661
|
-
$inputs[i].value = true;
|
|
1662
|
-
$inputs[i].setAttribute('value', true)
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
evt = $inputs[i].id;
|
|
1668
|
-
|
|
1669
|
-
procced = function ($el, evt) {
|
|
1670
|
-
|
|
1671
|
-
// recover default state only on value === true || false
|
|
1672
|
-
addListener(gina, $el, evt, function(event) {
|
|
1673
|
-
|
|
1674
|
-
if ( /^(true|false|on)$/i.test(event.target.value) ) {
|
|
1675
|
-
cancelEvent(event);
|
|
1676
|
-
updateCheckBox(event.target);
|
|
1677
|
-
}
|
|
1678
|
-
});
|
|
1679
|
-
|
|
1680
|
-
// default state recovery
|
|
1681
|
-
var value = $el.value || $el.getAttribute('value') || $el.getAttribute('data-value');
|
|
1682
|
-
if ( /^(true|false|on)$/i.test(value) ) {
|
|
1683
|
-
|
|
1684
|
-
if ( typeof(value) != 'undefined' && /^(true|on|false)$/.test(value) ) {
|
|
1685
|
-
$el.checked = /true|on/.test(value) ? true : false;
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
updateCheckBox($el);
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
}
|
|
1693
|
-
|
|
1694
|
-
if ( typeof(gina.events[evt]) != 'undefined' && gina.events[evt] == $inputs[i].id ) {
|
|
1695
|
-
removeListener(gina, $inputs[i], evt);
|
|
1696
|
-
procced($inputs[i], evt)
|
|
1697
|
-
|
|
1698
|
-
} else {
|
|
1699
|
-
procced($inputs[i], evt)
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
|
-
} else if ( typeof(type) != 'undefined' && type == 'radio' ) {
|
|
1703
|
-
|
|
1704
|
-
evt = $inputs[i].id;
|
|
1705
|
-
|
|
1706
|
-
procced = function ($el, evt) {
|
|
1707
|
-
addListener(gina, $el, evt, function(event) {
|
|
1708
|
-
|
|
1709
|
-
cancelEvent(event);
|
|
1710
|
-
updateRadio(event.target);
|
|
1711
|
-
});
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
updateRadio($el, true);
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
if ( typeof(gina.events[evt]) != 'undefined' && gina.events[evt] == $inputs[i].id ) {
|
|
1718
|
-
removeListener(gina, $inputs[i], evt);
|
|
1719
|
-
procced(event.target, evt)
|
|
1720
|
-
|
|
1721
|
-
} else {
|
|
1722
|
-
procced($inputs[i], evt)
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
if (withRules) {
|
|
1729
|
-
|
|
1730
|
-
evt = 'validate.' + _id;
|
|
1731
|
-
procced = function () {
|
|
1732
|
-
|
|
1733
|
-
// attach form event
|
|
1734
|
-
addListener(gina, $target, evt, function(event) {
|
|
1735
|
-
cancelEvent(event);
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
var result = event['detail'] || $form.eventData.validation;
|
|
1739
|
-
//console.log('$form[ '+_id+' ] validation done !!!\n isValid ? ', result['isValid'](), '\nErrors -> ', result['errors'], '\nData -> ', result['data']);
|
|
1740
|
-
|
|
1741
|
-
handleErrorsDisplay(event['target'], result['errors'], result['data']);
|
|
1742
|
-
|
|
1743
|
-
var _id = event.target.getAttribute('id');
|
|
1744
|
-
|
|
1745
|
-
if ( result['isValid']() ) { // send if valid
|
|
1746
|
-
// now sending to server
|
|
1747
|
-
// TODO - remove comments, or replace 'submit' by 'submit.' + _id
|
|
1748
|
-
//if ( $form.withUserBindings && /validate\./.test(event.type) && typeof(gina.events[event.type]) != 'undefined' ) {
|
|
1749
|
-
// triggerEvent(gina, event.target, 'submit', result)
|
|
1750
|
-
//} else {
|
|
1751
|
-
|
|
1752
|
-
if (instance.$forms[_id]) {
|
|
1753
|
-
instance.$forms[_id].send(result['data']);
|
|
1754
|
-
} else if ($form) { // just in case the form is being destroyed
|
|
1755
|
-
$form.send(result['data']);
|
|
1756
|
-
}
|
|
1757
|
-
//}
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
return false
|
|
1761
|
-
|
|
1762
|
-
})
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
if ( typeof(gina.events[evt]) != 'undefined' && gina.events[evt] == 'validate.' + _id ) {
|
|
1766
|
-
removeListener(gina, $form, evt, procced)
|
|
1767
|
-
} else {
|
|
1768
|
-
procced()
|
|
1769
|
-
}
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
var proccedToSubmit = function (evt, $submit) {
|
|
1774
|
-
// console.log('placing submit ', evt, $submit);
|
|
1775
|
-
// attach submit events
|
|
1776
|
-
addListener(gina, $submit, evt, function(event) {
|
|
1777
|
-
// start validation
|
|
1778
|
-
cancelEvent(event);
|
|
1779
|
-
|
|
1780
|
-
// getting fields & values
|
|
1781
|
-
var $fields = {}
|
|
1782
|
-
, fields = { '_length': 0 }
|
|
1783
|
-
, id = $target.getAttribute('id')
|
|
1784
|
-
, rules = ( typeof(gina.validator.$forms[id]) != 'undefined' ) ? gina.validator.$forms[id].rules : null
|
|
1785
|
-
, name = null
|
|
1786
|
-
, value = 0
|
|
1787
|
-
, type = null
|
|
1788
|
-
, index = { checkbox: 0, radio: 0 };
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
for (var i = 0, len = $target.length; i<len; ++i) {
|
|
1792
|
-
|
|
1793
|
-
name = $target[i].getAttribute('name');
|
|
1794
|
-
|
|
1795
|
-
if (!name) continue;
|
|
1796
|
-
|
|
1797
|
-
// TODO - add switch cases against tagName (checkbox/radio)
|
|
1798
|
-
if ( typeof($target[i].type) != 'undefined' && $target[i].type == 'radio' || typeof($target[i].type) != 'undefined' && $target[i].type == 'checkbox' ) {
|
|
1799
|
-
|
|
1800
|
-
if ( $target[i].checked ) {
|
|
1801
|
-
fields[name] = $target[i].value
|
|
1802
|
-
} else if ( // force validator to pass `false` if boolean is required explicitly
|
|
1803
|
-
rules
|
|
1804
|
-
&& typeof(rules[name]) != 'undefined'
|
|
1805
|
-
&& typeof(rules[name].isBoolean)
|
|
1806
|
-
&& typeof(rules[name].isRequired)
|
|
1807
|
-
) {
|
|
1808
|
-
fields[name] = false;
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
} else {
|
|
1812
|
-
fields[name] = $target[i].value;
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
$fields[name] = $target[i];
|
|
1817
|
-
// reset filed error data attributes
|
|
1818
|
-
$fields[name].setAttribute('data-gina-form-errors', '');
|
|
1819
|
-
|
|
1820
|
-
++fields['_length']
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
//console.log('$fields =>\n' + $fields);
|
|
1824
|
-
|
|
1825
|
-
//instance.$forms[ $target.getAttribute('id') ].sent = false;
|
|
1826
|
-
|
|
1827
|
-
if ( fields['_length'] == 0 ) { // nothing to validate
|
|
1828
|
-
delete fields['_length'];
|
|
1829
|
-
var result = {
|
|
1830
|
-
'errors' : [],
|
|
1831
|
-
'isValid' : function() { return true },
|
|
1832
|
-
'data' : formatData(fields)
|
|
1833
|
-
};
|
|
1834
|
-
|
|
1835
|
-
triggerEvent(gina, $target, 'validate.' + _id, result)
|
|
1836
|
-
|
|
1837
|
-
} else {
|
|
1838
|
-
// update rule in case the current event is triggered outside the main sequence
|
|
1839
|
-
// e.g.: form `id` attribute rewritten on the fly
|
|
1840
|
-
_id = $target.getAttribute('id');
|
|
1841
|
-
var customRule = $target.getAttribute('data-gina-form-rule');
|
|
1842
|
-
|
|
1843
|
-
if ( customRule ) { // 'data-gina-form-rule'
|
|
1844
|
-
rule = gina.validator.rules[ customRule.replace(/\-/g, '.') ];
|
|
1845
|
-
} else {
|
|
1846
|
-
rule = gina.validator.$forms[ _id ].rules;
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
//console.log('testing rule [ '+_id.replace(/\-/g, '.') +' ]\n'+ JSON.stringify(rule, null, 4));
|
|
1850
|
-
//console.log('validating ', $form, fields, rule);
|
|
1851
|
-
validate($target, fields, $fields, rule, function onValidation(result){
|
|
1852
|
-
//console.log('validation result ', 'validate.' + _id, JSON.stringify(result.data, null, 2));
|
|
1853
|
-
//console.log('events ', 'validate.' + _id, self.events )
|
|
1854
|
-
triggerEvent(gina, $target, 'validate.' + _id, result)
|
|
1855
|
-
})
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
|
-
});
|
|
1859
|
-
}
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
// binding submit button
|
|
1863
|
-
var $submit = null, $buttons = [], $buttonsTMP = [], buttonId = null;
|
|
1864
|
-
$buttonsTMP = $target.getElementsByTagName('button');
|
|
1865
|
-
if ( $buttonsTMP.length > 0 ) {
|
|
1866
|
-
for(var b = 0, len = $buttonsTMP.length; b < len; ++b) {
|
|
1867
|
-
if ($buttonsTMP[b].type == 'submit')
|
|
1868
|
-
$buttons.push($buttonsTMP[b])
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1872
|
-
$buttonsTMP = $target.getElementsByTagName('a');
|
|
1873
|
-
if ( $buttonsTMP.length > 0 ) {
|
|
1874
|
-
for(var b = 0, len = $buttonsTMP.length; b < len; ++b) {
|
|
1875
|
-
if ( $buttonsTMP[b].attributes.getNamedItem('data-gina-form-submit'))
|
|
1876
|
-
$buttons.push($buttonsTMP[b])
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
var onclickAttribute = null, isSubmitType = false;
|
|
1882
|
-
for (var b=0, len=$buttons.length; b<len; ++b) {
|
|
1883
|
-
|
|
1884
|
-
$submit = $buttons[b];
|
|
1885
|
-
|
|
1886
|
-
if ($submit.tagName == 'A') { // without this test, XHR callback is ignored
|
|
1887
|
-
//console.log('a#$buttons ', $buttonsTMP[b]);
|
|
1888
|
-
onclickAttribute = $submit.getAttribute('onclick');
|
|
1889
|
-
isSubmitType = $submit.getAttribute('data-gina-form-submit');
|
|
1890
|
-
|
|
1891
|
-
if ( !onclickAttribute && !isSubmitType) {
|
|
1892
|
-
$submit.setAttribute('onclick', 'return false;')
|
|
1893
|
-
} else if ( !/return false/ && !isSubmitType) {
|
|
1894
|
-
if ( /\;$/.test(onclickAttribute) ) {
|
|
1895
|
-
onclickAttribute += 'return false;'
|
|
1896
|
-
} else {
|
|
1897
|
-
onclickAttribute += '; return false;'
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
|
|
1902
|
-
if (!$submit['id']) {
|
|
1903
|
-
|
|
1904
|
-
evt = 'click.'+ uuid.v1();
|
|
1905
|
-
$submit['id'] = evt;
|
|
1906
|
-
$submit.setAttribute( 'id', evt);
|
|
1907
|
-
|
|
1908
|
-
} else {
|
|
1909
|
-
evt = $submit['id'];
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
if ( typeof(gina.events[evt]) == 'undefined' || gina.events[evt] != $submit.id ) {
|
|
1914
|
-
proccedToSubmit(evt, $submit)
|
|
1915
|
-
}
|
|
1916
|
-
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
evt = 'submit';
|
|
1923
|
-
|
|
1924
|
-
// submit proxy
|
|
1925
|
-
addListener(gina, $target, evt, function(e) {
|
|
1926
|
-
|
|
1927
|
-
var $target = e.target
|
|
1928
|
-
, id = $target.getAttribute('id')
|
|
1929
|
-
, isBinded = instance.$forms[id].binded
|
|
1930
|
-
;
|
|
1931
|
-
|
|
1932
|
-
// prevent event to be triggered twice
|
|
1933
|
-
if ( typeof(e.defaultPrevented) != 'undefined' && e.defaultPrevented )
|
|
1934
|
-
return false;
|
|
1935
|
-
|
|
1936
|
-
if (withRules || isBinded) {
|
|
1937
|
-
cancelEvent(e);
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
// just collect data for over forms
|
|
1942
|
-
// getting fields & values
|
|
1943
|
-
var $fields = {}
|
|
1944
|
-
, fields = { '_length': 0 }
|
|
1945
|
-
, id = $target.getAttribute('id')
|
|
1946
|
-
, rules = ( typeof(gina.validator.$forms[id]) != 'undefined' ) ? gina.validator.$forms[id].rules : null
|
|
1947
|
-
, name = null
|
|
1948
|
-
, value = 0
|
|
1949
|
-
, type = null
|
|
1950
|
-
, index = { checkbox: 0, radio: 0 };
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
for (var i = 0, len = $target.length; i<len; ++i) {
|
|
1954
|
-
name = $target[i].getAttribute('name');
|
|
1955
|
-
|
|
1956
|
-
if (!name) continue;
|
|
1957
|
-
|
|
1958
|
-
// checkbox/radio
|
|
1959
|
-
if ( typeof($target[i].type) != 'undefined' && $target[i].type == 'radio' || typeof($target[i].type) != 'undefined' && $target[i].type == 'checkbox' ) {
|
|
1960
|
-
|
|
1961
|
-
if ( $target[i].checked ) {
|
|
1962
|
-
fields[name] = $target[i].value
|
|
1963
|
-
} else if ( // force validator to pass `false` if boolean is required explicitly
|
|
1964
|
-
rules
|
|
1965
|
-
&& typeof(rules[name]) != 'undefined'
|
|
1966
|
-
&& typeof(rules[name].isBoolean)
|
|
1967
|
-
&& typeof(rules[name].isRequired)
|
|
1968
|
-
) {
|
|
1969
|
-
fields[name] = false;
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
|
-
} else {
|
|
1973
|
-
fields[name] = $target[i].value;
|
|
1974
|
-
}
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
$fields[name] = $target[i];
|
|
1979
|
-
// reset filed error data attributes
|
|
1980
|
-
$fields[name].setAttribute('data-gina-form-errors', '');
|
|
1981
|
-
|
|
1982
|
-
++fields['_length']
|
|
1983
|
-
}
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
if ( fields['_length'] == 0 ) { // nothing to validate
|
|
1987
|
-
|
|
1988
|
-
delete fields['_length'];
|
|
1989
|
-
var result = {
|
|
1990
|
-
'errors' : [],
|
|
1991
|
-
'isValid' : function() { return true },
|
|
1992
|
-
'data' : formatData(fields)
|
|
1993
|
-
};
|
|
1994
|
-
|
|
1995
|
-
if ( typeof(gina.events['submit.' + id]) != 'undefined' ) { // if `on('submit', cb)` is binded
|
|
1996
|
-
triggerEvent(gina, $target, 'submit.' + id, result);
|
|
1997
|
-
} else {
|
|
1998
|
-
triggerEvent(gina, $target, 'validate.' + id, result);
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
|
-
} else {
|
|
2002
|
-
// update rule in case the current event is triggered outside the main sequence
|
|
2003
|
-
// e.g.: form `id` attribute rewritten on the fly
|
|
2004
|
-
//ruleId = id.replace(/-/g, '.');
|
|
2005
|
-
//if ( typeof(instance.$forms[id].rules) != 'undefined' )
|
|
2006
|
-
// rule = instance.$forms[id].rules;
|
|
2007
|
-
|
|
2008
|
-
var customRule = $target.getAttribute('data-gina-form-rule');
|
|
2009
|
-
|
|
2010
|
-
if ( customRule ) { // 'data-gina-form-rule'
|
|
2011
|
-
rule = gina.validator.rules[ customRule.replace(/\-/g, '.') ];
|
|
2012
|
-
} else {
|
|
2013
|
-
rule = gina.validator.$forms[ id ].rules;
|
|
2014
|
-
}
|
|
2015
|
-
|
|
2016
|
-
validate($target, fields, $fields, rule, function onValidation(result){
|
|
2017
|
-
if ( typeof(gina.events['submit.' + id]) != 'undefined' ) { // if `on('submit', cb)` is binded
|
|
2018
|
-
triggerEvent(gina, $target, 'submit.' + id, result);
|
|
2019
|
-
} else {
|
|
2020
|
-
triggerEvent(gina, $target, 'validate.' + id, result);
|
|
2021
|
-
}
|
|
2022
|
-
})
|
|
2023
|
-
}
|
|
2024
|
-
});
|
|
2025
|
-
|
|
2026
|
-
instance.$forms[_id]['binded'] = true;
|
|
2027
|
-
}
|
|
2028
|
-
|
|
2029
|
-
var setupInstanceProto = function() {
|
|
2030
|
-
|
|
2031
|
-
instance.setOptions = setOptions;
|
|
2032
|
-
instance.getFormById = getFormById;
|
|
2033
|
-
instance.validateFormById = validateFormById;
|
|
2034
|
-
instance.target = document;
|
|
2035
|
-
instance.validateFormById = validateFormById;
|
|
2036
|
-
instance.resetErrorsDisplay = resetErrorsDisplay;
|
|
2037
|
-
instance.resetFields = resetFields;
|
|
2038
|
-
instance.handleErrorsDisplay = handleErrorsDisplay;
|
|
2039
|
-
instance.send = send;
|
|
2040
|
-
}
|
|
2041
|
-
|
|
2042
|
-
if (isGFFCtx) {
|
|
2043
|
-
return init(rules)
|
|
2044
|
-
} else {
|
|
2045
|
-
return backendInit(rules, data, formId)
|
|
2046
|
-
}
|
|
2047
|
-
|
|
2048
|
-
};
|
|
2049
|
-
|
|
2050
|
-
if ( ( typeof(module) !== 'undefined' ) && module.exports ) {
|
|
2051
|
-
// Publish as node.js module
|
|
2052
|
-
module.exports = ValidatorPlugin
|
|
2053
|
-
} else if ( typeof(define) === 'function' && define.amd) {
|
|
2054
|
-
// Publish as AMD module
|
|
2055
|
-
define('gina/validator', function(){ return ValidatorPlugin })
|
|
2056
|
-
}
|