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.
Files changed (466) hide show
  1. package/INSTALL.md +46 -0
  2. package/{core/asset/html/static.html → Icon/r} +0 -0
  3. package/LICENSE +1 -1
  4. package/README-4Contributors.md +96 -0
  5. package/README.md +296 -104
  6. package/bin/cli +287 -0
  7. package/bin/cli-debug +60 -0
  8. package/bin/cmd +184 -0
  9. package/bin/gina +180 -0
  10. package/config/logger.json +17 -0
  11. package/doc/framework/cli/doc.json +9 -0
  12. package/doc/framework/index.md +60 -0
  13. package/framework/v0.1.1-alpha.2/AUTHORS +7 -0
  14. package/{core/utils/lib/inherits → framework/v0.1.1-alpha.2}/LICENSE +1 -1
  15. package/framework/v0.1.1-alpha.2/VERSION +1 -0
  16. package/{core/locales/dist/language/en.json → framework/v0.1.1-alpha.2/core/asset/html/nolayout.html} +0 -0
  17. package/{core/locales/dist/language/fr.json → framework/v0.1.1-alpha.2/core/asset/html/static.html} +0 -0
  18. package/{core → framework/v0.1.1-alpha.2/core}/asset/img/android-chrome-192x192.png +0 -0
  19. package/{core → framework/v0.1.1-alpha.2/core}/asset/img/android-chrome-512x512.png +0 -0
  20. package/{core → framework/v0.1.1-alpha.2/core}/asset/img/apple-touch-icon.png +0 -0
  21. package/{core → framework/v0.1.1-alpha.2/core}/asset/img/favicon-16x16.png +0 -0
  22. package/{core → framework/v0.1.1-alpha.2/core}/asset/img/favicon-32x32.png +0 -0
  23. package/{core → framework/v0.1.1-alpha.2/core}/asset/img/favicon.ico +0 -0
  24. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.js +20904 -0
  25. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.js.map +56 -0
  26. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.css +1 -0
  27. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.css.map +1 -0
  28. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.js +736 -0
  29. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.min.js.map +56 -0
  30. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.onload.min.js +5 -0
  31. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/dist/gina.onload.min.js.map +8 -0
  32. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/readme.md +192 -0
  33. package/framework/v0.1.1-alpha.2/core/asset/js/plugin/uuid.json +23 -0
  34. package/framework/v0.1.1-alpha.2/core/config.js +2308 -0
  35. package/framework/v0.1.1-alpha.2/core/connectors/couchbase/index.js +757 -0
  36. package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/connector.js +20 -0
  37. package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/connector.v2.js +429 -0
  38. package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/connector.v3.js +432 -0
  39. package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/n1ql.js +14 -0
  40. package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/session-store.js +21 -0
  41. package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/session-store.v2.js +258 -0
  42. package/framework/v0.1.1-alpha.2/core/connectors/couchbase/lib/session-store.v3.js +341 -0
  43. package/{core → framework/v0.1.1-alpha.2/core}/controller/controller.framework.js +3 -2
  44. package/framework/v0.1.1-alpha.2/core/controller/controller.js +3990 -0
  45. package/{core → framework/v0.1.1-alpha.2/core}/controller/index.js +5 -5
  46. package/framework/v0.1.1-alpha.2/core/deps/busboy/.travis.yml +17 -0
  47. package/framework/v0.1.1-alpha.2/core/deps/busboy/LICENSE +19 -0
  48. package/framework/v0.1.1-alpha.2/core/deps/busboy/README.md +225 -0
  49. package/framework/v0.1.1-alpha.2/core/deps/busboy/deps/encoding/encoding-indexes.js +73 -0
  50. package/framework/v0.1.1-alpha.2/core/deps/busboy/deps/encoding/encoding.js +2391 -0
  51. package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/main.js +89 -0
  52. package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/types/multipart.js +328 -0
  53. package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/types/urlencoded.js +214 -0
  54. package/framework/v0.1.1-alpha.2/core/deps/busboy/lib/utils.js +191 -0
  55. package/framework/v0.1.1-alpha.2/core/deps/busboy/package.json +69 -0
  56. package/framework/v0.1.1-alpha.2/core/deps/swig-client/swig-2.0.0.min.js +5 -0
  57. package/{core → framework/v0.1.1-alpha.2/core}/dev/index.js +5 -5
  58. package/{core → framework/v0.1.1-alpha.2/core}/dev/lib/class.js +1 -1
  59. package/{core → framework/v0.1.1-alpha.2/core}/dev/lib/factory.js +1 -1
  60. package/{core → framework/v0.1.1-alpha.2/core}/dev/lib/tools.js +0 -0
  61. package/framework/v0.1.1-alpha.2/core/gna.js +1070 -0
  62. package/{core → framework/v0.1.1-alpha.2/core}/locales/README.md +41 -2
  63. package/{core → framework/v0.1.1-alpha.2/core}/locales/currency.json +0 -0
  64. package/{core/plugins/README.md → framework/v0.1.1-alpha.2/core/locales/dist/language/en.json} +0 -0
  65. package/{core/plugins/lib/intl/README.md → framework/v0.1.1-alpha.2/core/locales/dist/language/fr.json} +0 -0
  66. package/{core → framework/v0.1.1-alpha.2/core}/locales/dist/region/en.json +0 -0
  67. package/framework/v0.1.1-alpha.2/core/locales/dist/region/fr.json +9492 -0
  68. package/{core → framework/v0.1.1-alpha.2/core}/locales/index.js +5 -4
  69. package/{core → framework/v0.1.1-alpha.2/core}/locales/src/make.js +15 -12
  70. package/{core → framework/v0.1.1-alpha.2/core}/locales/src/resources/currency.csv +0 -0
  71. package/{core → framework/v0.1.1-alpha.2/core}/locales/src/resources/region.csv +0 -0
  72. package/{core → framework/v0.1.1-alpha.2/core}/locales/src/resources/region.mapping.json +0 -0
  73. package/{core → framework/v0.1.1-alpha.2/core}/mime.types +0 -0
  74. package/{core → framework/v0.1.1-alpha.2/core}/model/entity.js +156 -196
  75. package/{core → framework/v0.1.1-alpha.2/core}/model/index.js +67 -48
  76. package/{core → framework/v0.1.1-alpha.2/core}/model/template/entityFactory.js +2 -2
  77. package/{core → framework/v0.1.1-alpha.2/core}/model/template/index.js +8 -10
  78. package/{core/plugins/lib/storage → framework/v0.1.1-alpha.2/core/plugins}/README.md +0 -0
  79. package/{core → framework/v0.1.1-alpha.2/core}/plugins/index.js +3 -3
  80. package/{core/plugins/lib/validator → framework/v0.1.1-alpha.2/core/plugins/lib/file}/README.md +0 -0
  81. package/{core/plugins/lib/intl → framework/v0.1.1-alpha.2/core/plugins/lib/file}/build.json +0 -0
  82. package/framework/v0.1.1-alpha.2/core/plugins/lib/file/package.json +25 -0
  83. package/{core/utils/lib/collection → framework/v0.1.1-alpha.2/core/plugins/lib/intl}/README.md +0 -0
  84. package/{core/plugins/lib/storage → framework/v0.1.1-alpha.2/core/plugins/lib/intl}/build.json +0 -0
  85. package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/intl/package.json +3 -3
  86. package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/intl/src/main.js +17 -1
  87. package/{core/utils/lib/routing → framework/v0.1.1-alpha.2/core/plugins/lib/storage}/README.md +0 -0
  88. package/{core/plugins/lib/validator → framework/v0.1.1-alpha.2/core/plugins/lib/storage}/build.json +0 -0
  89. package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/storage/package.json +2 -2
  90. package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/storage/src/main.js +91 -85
  91. package/{core/utils/lib/url → framework/v0.1.1-alpha.2/core/plugins/lib/validator}/README.md +0 -0
  92. package/{core/utils/lib/collection → framework/v0.1.1-alpha.2/core/plugins/lib/validator}/build.json +0 -0
  93. package/{core → framework/v0.1.1-alpha.2/core}/plugins/lib/validator/package.json +3 -3
  94. package/framework/v0.1.1-alpha.2/core/plugins/lib/validator/src/form-validator.js +1762 -0
  95. package/framework/v0.1.1-alpha.2/core/plugins/lib/validator/src/main.js +6917 -0
  96. package/framework/v0.1.1-alpha.2/core/router.js +664 -0
  97. package/framework/v0.1.1-alpha.2/core/server.express.js +213 -0
  98. package/framework/v0.1.1-alpha.2/core/server.isaac.js +386 -0
  99. package/framework/v0.1.1-alpha.2/core/server.js +3010 -0
  100. package/{core → framework/v0.1.1-alpha.2/core}/status.codes +8 -0
  101. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/app.json +6 -0
  102. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/routing.json +11 -0
  103. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/settings.json +9 -0
  104. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/settings.server.json +30 -0
  105. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/config/templates.json +42 -0
  106. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/controllers/controller.content.js +39 -0
  107. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/controllers/controller.js +30 -0
  108. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle/controllers/setup.js +111 -0
  109. package/{core/template/samples → framework/v0.1.1-alpha.2/core/template/boilerplate}/bundle/index.js +0 -0
  110. package/{core/template/samples/bundle → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_namespace}/controllers/controller.js +9 -7
  111. package/{core/template/views → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public}/css/default.css +0 -0
  112. package/{core/template/views → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public}/css/vendor/readme.md +0 -0
  113. package/{core/template/views → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public}/favicon.ico +0 -0
  114. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public/js/vendor/readme.md +1 -0
  115. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_public/readme.md +1 -0
  116. package/framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_templates/handlers/main.js +24 -0
  117. package/{core/template/views/html/default.html → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_templates/html/homepage.html} +0 -0
  118. package/{core/template/views/html/layout.html → framework/v0.1.1-alpha.2/core/template/boilerplate/bundle_templates/html/layout/main.html} +2 -2
  119. package/{core → framework/v0.1.1-alpha.2/core}/template/command/gina.bat.tpl +0 -0
  120. package/{core → framework/v0.1.1-alpha.2/core}/template/command/gina.tpl +1 -1
  121. package/framework/v0.1.1-alpha.2/core/template/conf/env.json +76 -0
  122. package/{core/template/conf/project.json → framework/v0.1.1-alpha.2/core/template/conf/manifest.json} +1 -0
  123. package/{core → framework/v0.1.1-alpha.2/core}/template/conf/package.json +2 -2
  124. package/framework/v0.1.1-alpha.2/core/template/conf/settings.json +92 -0
  125. package/framework/v0.1.1-alpha.2/core/template/conf/statics.json +10 -0
  126. package/framework/v0.1.1-alpha.2/core/template/conf/templates.json +37 -0
  127. package/{core → framework/v0.1.1-alpha.2/core}/template/error/client/json/401.json +0 -0
  128. package/{core → framework/v0.1.1-alpha.2/core}/template/error/client/json/403.json +0 -0
  129. package/{core → framework/v0.1.1-alpha.2/core}/template/error/client/json/404.json +0 -0
  130. package/{core → framework/v0.1.1-alpha.2/core}/template/error/server/html/50x.html +0 -0
  131. package/{core → framework/v0.1.1-alpha.2/core}/template/error/server/json/500.json +0 -0
  132. package/{core → framework/v0.1.1-alpha.2/core}/template/error/server/json/503.json +0 -0
  133. package/{core/utils/lib/routing/build.json → framework/v0.1.1-alpha.2/core/template/extensions/logger/config.json} +0 -0
  134. package/{core/utils → framework/v0.1.1-alpha.2}/helpers/console.js +3 -3
  135. package/{core/utils → framework/v0.1.1-alpha.2}/helpers/context.js +240 -49
  136. package/framework/v0.1.1-alpha.2/helpers/dateFormat.js +528 -0
  137. package/framework/v0.1.1-alpha.2/helpers/index.js +79 -0
  138. package/framework/v0.1.1-alpha.2/helpers/json/README.md +0 -0
  139. package/framework/v0.1.1-alpha.2/helpers/json/package.json +20 -0
  140. package/framework/v0.1.1-alpha.2/helpers/json/src/main.js +97 -0
  141. package/{core/utils → framework/v0.1.1-alpha.2}/helpers/path.js +342 -140
  142. package/framework/v0.1.1-alpha.2/helpers/plugins/README.md +4 -0
  143. package/framework/v0.1.1-alpha.2/helpers/plugins/package.json +20 -0
  144. package/framework/v0.1.1-alpha.2/helpers/plugins/src/api-error.js +160 -0
  145. package/framework/v0.1.1-alpha.2/helpers/plugins/src/main.js +32 -0
  146. package/framework/v0.1.1-alpha.2/helpers/prototypes.js +218 -0
  147. package/{core/utils → framework/v0.1.1-alpha.2}/helpers/task.js +49 -29
  148. package/{core/utils → framework/v0.1.1-alpha.2}/helpers/text.js +7 -7
  149. package/framework/v0.1.1-alpha.2/lib/archiver/README.md +0 -0
  150. package/framework/v0.1.1-alpha.2/lib/archiver/build.json +0 -0
  151. package/framework/v0.1.1-alpha.2/lib/archiver/package.json +20 -0
  152. package/framework/v0.1.1-alpha.2/lib/archiver/src/dep/jszip.min.js +15 -0
  153. package/framework/v0.1.1-alpha.2/lib/archiver/src/main.js +499 -0
  154. package/framework/v0.1.1-alpha.2/lib/cmd/aliases.json +13 -0
  155. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/add.js +507 -0
  156. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/arguments.json +4 -0
  157. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/copy.js +15 -0
  158. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/cp.js +2 -0
  159. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/help.js +28 -0
  160. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/help.txt +67 -0
  161. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/list.js +129 -0
  162. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/remove.js +229 -0
  163. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/rename.js +4 -0
  164. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/restart.js +235 -0
  165. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/rm.js +2 -0
  166. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/start.js +394 -0
  167. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/status.js +3 -0
  168. package/framework/v0.1.1-alpha.2/lib/cmd/bundle/stop.js +232 -0
  169. package/framework/v0.1.1-alpha.2/lib/cmd/env/add.js +436 -0
  170. package/framework/v0.1.1-alpha.2/lib/cmd/env/get.js +62 -0
  171. package/framework/v0.1.1-alpha.2/lib/cmd/env/help.js +28 -0
  172. package/framework/v0.1.1-alpha.2/lib/cmd/env/help.txt +33 -0
  173. package/framework/v0.1.1-alpha.2/lib/cmd/env/link-dev.js +80 -0
  174. package/framework/v0.1.1-alpha.2/lib/cmd/env/list.js +111 -0
  175. package/framework/v0.1.1-alpha.2/lib/cmd/env/remove.js +150 -0
  176. package/framework/v0.1.1-alpha.2/lib/cmd/env/rm.js +2 -0
  177. package/framework/v0.1.1-alpha.2/lib/cmd/env/set.js +57 -0
  178. package/framework/v0.1.1-alpha.2/lib/cmd/env/unset.js +44 -0
  179. package/framework/v0.1.1-alpha.2/lib/cmd/env/use.js +79 -0
  180. package/framework/v0.1.1-alpha.2/lib/cmd/framework/dot.js +70 -0
  181. package/framework/v0.1.1-alpha.2/lib/cmd/framework/get.js +0 -0
  182. package/framework/v0.1.1-alpha.2/lib/cmd/framework/help.js +39 -0
  183. package/framework/v0.1.1-alpha.2/lib/cmd/framework/help.txt +31 -0
  184. package/framework/v0.1.1-alpha.2/lib/cmd/framework/init.js +514 -0
  185. package/{core/utils/lib/cmd → framework/v0.1.1-alpha.2/lib/cmd/framework}/msg.json +3 -3
  186. package/framework/v0.1.1-alpha.2/lib/cmd/framework/open.js +50 -0
  187. package/framework/v0.1.1-alpha.2/lib/cmd/framework/restart.js +124 -0
  188. package/framework/v0.1.1-alpha.2/lib/cmd/framework/set.js +161 -0
  189. package/framework/v0.1.1-alpha.2/lib/cmd/framework/start.js +96 -0
  190. package/framework/v0.1.1-alpha.2/lib/cmd/framework/status.js +72 -0
  191. package/framework/v0.1.1-alpha.2/lib/cmd/framework/stop.js +159 -0
  192. package/framework/v0.1.1-alpha.2/lib/cmd/framework/tail.js +183 -0
  193. package/framework/v0.1.1-alpha.2/lib/cmd/framework/update.js +0 -0
  194. package/framework/v0.1.1-alpha.2/lib/cmd/framework/version.js +44 -0
  195. package/framework/v0.1.1-alpha.2/lib/cmd/gina-dev.1.md +66 -0
  196. package/framework/v0.1.1-alpha.2/lib/cmd/gina-framework.1.md +100 -0
  197. package/framework/v0.1.1-alpha.2/lib/cmd/gina.1.md +79 -0
  198. package/framework/v0.1.1-alpha.2/lib/cmd/helper.js +1147 -0
  199. package/framework/v0.1.1-alpha.2/lib/cmd/index.js +170 -0
  200. package/framework/v0.1.1-alpha.2/lib/cmd/msg.json +20 -0
  201. package/framework/v0.1.1-alpha.2/lib/cmd/port/help.js +28 -0
  202. package/framework/v0.1.1-alpha.2/lib/cmd/port/help.txt +31 -0
  203. package/framework/v0.1.1-alpha.2/lib/cmd/port/inc/scan.js +108 -0
  204. package/framework/v0.1.1-alpha.2/lib/cmd/port/list.js +176 -0
  205. package/framework/v0.1.1-alpha.2/lib/cmd/port/set.js +0 -0
  206. package/framework/v0.1.1-alpha.2/lib/cmd/project/add.js +528 -0
  207. package/framework/v0.1.1-alpha.2/lib/cmd/project/arguments.json +9 -0
  208. package/framework/v0.1.1-alpha.2/lib/cmd/project/build.js +115 -0
  209. package/framework/v0.1.1-alpha.2/lib/cmd/project/help.js +28 -0
  210. package/framework/v0.1.1-alpha.2/lib/cmd/project/help.txt +76 -0
  211. package/framework/v0.1.1-alpha.2/lib/cmd/project/import.js +2 -0
  212. package/framework/v0.1.1-alpha.2/lib/cmd/project/list.js +55 -0
  213. package/framework/v0.1.1-alpha.2/lib/cmd/project/move.js +0 -0
  214. package/framework/v0.1.1-alpha.2/lib/cmd/project/remove.js +144 -0
  215. package/framework/v0.1.1-alpha.2/lib/cmd/project/rename.js +162 -0
  216. package/framework/v0.1.1-alpha.2/lib/cmd/project/restart.js +0 -0
  217. package/framework/v0.1.1-alpha.2/lib/cmd/project/rm.js +2 -0
  218. package/framework/v0.1.1-alpha.2/lib/cmd/project/start.js +0 -0
  219. package/framework/v0.1.1-alpha.2/lib/cmd/project/status.js +3 -0
  220. package/framework/v0.1.1-alpha.2/lib/cmd/project/stop.js +0 -0
  221. package/framework/v0.1.1-alpha.2/lib/cmd/protocol/help.js +27 -0
  222. package/framework/v0.1.1-alpha.2/lib/cmd/protocol/help.txt +57 -0
  223. package/framework/v0.1.1-alpha.2/lib/cmd/protocol/list.js +239 -0
  224. package/framework/v0.1.1-alpha.2/lib/cmd/protocol/set.js +631 -0
  225. package/framework/v0.1.1-alpha.2/lib/cmd/scope/help.js +28 -0
  226. package/framework/v0.1.1-alpha.2/lib/cmd/scope/help.txt +33 -0
  227. package/framework/v0.1.1-alpha.2/lib/cmd/scope/link-local.js +80 -0
  228. package/framework/v0.1.1-alpha.2/lib/cmd/scope/list.js +116 -0
  229. package/framework/v0.1.1-alpha.2/lib/cmd/scope/remove.js +150 -0
  230. package/framework/v0.1.1-alpha.2/lib/cmd/scope/rm.js +2 -0
  231. package/framework/v0.1.1-alpha.2/lib/cmd/scope/set.js +57 -0
  232. package/framework/v0.1.1-alpha.2/lib/cmd/scope/unset.js +44 -0
  233. package/framework/v0.1.1-alpha.2/lib/cmd/scope/use.js +79 -0
  234. package/framework/v0.1.1-alpha.2/lib/cmd/view/add.js +311 -0
  235. package/framework/v0.1.1-alpha.2/lib/collection/README.md +5 -0
  236. package/framework/v0.1.1-alpha.2/lib/collection/build.json +0 -0
  237. package/{core/utils → framework/v0.1.1-alpha.2}/lib/collection/package.json +2 -2
  238. package/framework/v0.1.1-alpha.2/lib/collection/src/main.js +1459 -0
  239. package/{core/utils → framework/v0.1.1-alpha.2}/lib/config.js +49 -34
  240. package/framework/v0.1.1-alpha.2/lib/cron/README.md +7 -0
  241. package/framework/v0.1.1-alpha.2/lib/cron/package.json +20 -0
  242. package/framework/v0.1.1-alpha.2/lib/cron/src/main.js +176 -0
  243. package/{core/utils → framework/v0.1.1-alpha.2}/lib/generator/index.js +8 -4
  244. package/framework/v0.1.1-alpha.2/lib/index.js +116 -0
  245. package/framework/v0.1.1-alpha.2/lib/inherits/LICENSE +19 -0
  246. package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/README.md +0 -0
  247. package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/inheriting_eventemitter.js +0 -0
  248. package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/protected_inheritance.js +0 -0
  249. package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/simple_inheritance.js +0 -0
  250. package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/example/super_attribute_overridden_by_child_on_init.js +0 -0
  251. package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/package.json +2 -2
  252. package/{core/utils → framework/v0.1.1-alpha.2}/lib/inherits/src/main.js +18 -19
  253. package/framework/v0.1.1-alpha.2/lib/logger/README.md +7 -0
  254. package/framework/v0.1.1-alpha.2/lib/logger/package.json +20 -0
  255. package/framework/v0.1.1-alpha.2/lib/logger/src/containers/default/index.js +55 -0
  256. package/framework/v0.1.1-alpha.2/lib/logger/src/containers/file/index.js +251 -0
  257. package/framework/v0.1.1-alpha.2/lib/logger/src/containers/file/lib/logrotator/README.md +100 -0
  258. package/framework/v0.1.1-alpha.2/lib/logger/src/containers/file/lib/logrotator/index.js +274 -0
  259. package/framework/v0.1.1-alpha.2/lib/logger/src/containers/mq/index.js +52 -0
  260. package/framework/v0.1.1-alpha.2/lib/logger/src/containers/mq/listener.js +302 -0
  261. package/framework/v0.1.1-alpha.2/lib/logger/src/containers/mq/speaker.js +118 -0
  262. package/framework/v0.1.1-alpha.2/lib/logger/src/helper.js +131 -0
  263. package/framework/v0.1.1-alpha.2/lib/logger/src/main.js +734 -0
  264. package/{core/utils → framework/v0.1.1-alpha.2}/lib/math/index.js +58 -35
  265. package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/README.md +5 -0
  266. package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/example/merge.js +1 -1
  267. package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/example/merge_2_literal objects.js +0 -0
  268. package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/example/merge_and_preserve_first.js +2 -0
  269. package/{core/utils → framework/v0.1.1-alpha.2}/lib/merge/package.json +2 -2
  270. package/framework/v0.1.1-alpha.2/lib/merge/src/main.js +531 -0
  271. package/{core/utils → framework/v0.1.1-alpha.2}/lib/model.js +42 -19
  272. package/framework/v0.1.1-alpha.2/lib/proc.js +518 -0
  273. package/framework/v0.1.1-alpha.2/lib/routing/README.md +0 -0
  274. package/framework/v0.1.1-alpha.2/lib/routing/build.json +0 -0
  275. package/{core/utils → framework/v0.1.1-alpha.2}/lib/routing/package.json +2 -2
  276. package/framework/v0.1.1-alpha.2/lib/routing/src/main.js +1492 -0
  277. package/framework/v0.1.1-alpha.2/lib/session-store.js +33 -0
  278. package/{core/utils → framework/v0.1.1-alpha.2}/lib/shell.js +43 -30
  279. package/framework/v0.1.1-alpha.2/lib/swig-filters/README.md +0 -0
  280. package/framework/v0.1.1-alpha.2/lib/swig-filters/package.json +20 -0
  281. package/framework/v0.1.1-alpha.2/lib/swig-filters/src/main.js +322 -0
  282. package/framework/v0.1.1-alpha.2/lib/url/README.md +0 -0
  283. package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/index.js +2 -1
  284. package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/mocks.json +0 -0
  285. package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/routing.json +9 -9
  286. package/{core/utils → framework/v0.1.1-alpha.2}/lib/url/test.js +0 -0
  287. package/{core/utils → framework/v0.1.1-alpha.2}/lib/validator.js +7 -7
  288. package/framework/v0.1.1-alpha.2/package.json +14 -0
  289. package/package.json +35 -33
  290. package/resources/etc/init.d/debian/gina +117 -0
  291. package/resources/home/framework/env.json +34 -0
  292. package/resources/home/framework/locals.json +14 -0
  293. package/resources/home/framework/project.json +48 -0
  294. package/resources/home/framework/projects.json +6 -0
  295. package/resources/home/main.json +47 -0
  296. package/resources/home/settings.json +22 -0
  297. package/resources/home/user/extensions/logger/default/config.json +77 -0
  298. package/resources/home/user/extensions/logger/file/config.json +11 -0
  299. package/resources/img/android-chrome-192x192.png +0 -0
  300. package/resources/img/android-chrome-512x512.png +0 -0
  301. package/resources/img/apple-touch-icon.png +0 -0
  302. package/resources/img/favicon-16x16.png +0 -0
  303. package/resources/img/favicon-32x32.png +0 -0
  304. package/resources/img/favicon.ico +0 -0
  305. package/resources/package.json.template +50 -0
  306. package/script/lib.js +24 -0
  307. package/script/post_install.js +449 -157
  308. package/script/pre_install.js +277 -36
  309. package/script/prepare_version.js +425 -0
  310. package/utils/helper.js +438 -0
  311. package/utils/prototypes.js +239 -0
  312. package/utils/prototypes.json_clone.js +175 -0
  313. package/.npmignore +0 -6
  314. package/MIDDLEWARE +0 -1
  315. package/SUCCESS +0 -1
  316. package/VERSION +0 -1
  317. package/core/asset/html/nolayout.html +0 -1
  318. package/core/asset/js/plugin/build.dev.json +0 -28
  319. package/core/asset/js/plugin/build.json +0 -31
  320. package/core/asset/js/plugin/dist/gina.min.css +0 -1
  321. package/core/asset/js/plugin/dist/gina.min.css.map +0 -1
  322. package/core/asset/js/plugin/dist/gina.min.js +0 -13731
  323. package/core/asset/js/plugin/dist/gina.min.js.map +0 -42
  324. package/core/asset/js/plugin/dist/gina.onload.min.js +0 -3
  325. package/core/asset/js/plugin/dist/gina.onload.min.js.map +0 -8
  326. package/core/asset/js/plugin/readme.md +0 -152
  327. package/core/asset/js/plugin/src/gina/main.js +0 -132
  328. package/core/asset/js/plugin/src/gina/popin/css/design.css +0 -23
  329. package/core/asset/js/plugin/src/gina/popin/css/main.css +0 -1112
  330. package/core/asset/js/plugin/src/gina/popin/css/popin.css +0 -3
  331. package/core/asset/js/plugin/src/gina/popin/css/popin.css.map +0 -1
  332. package/core/asset/js/plugin/src/gina/popin/doc/TOC.md +0 -29
  333. package/core/asset/js/plugin/src/gina/popin/doc/css.md +0 -162
  334. package/core/asset/js/plugin/src/gina/popin/doc/extend.md +0 -663
  335. package/core/asset/js/plugin/src/gina/popin/doc/faq.md +0 -46
  336. package/core/asset/js/plugin/src/gina/popin/doc/html.md +0 -227
  337. package/core/asset/js/plugin/src/gina/popin/doc/js.md +0 -37
  338. package/core/asset/js/plugin/src/gina/popin/doc/misc.md +0 -178
  339. package/core/asset/js/plugin/src/gina/popin/doc/usage.md +0 -130
  340. package/core/asset/js/plugin/src/gina/popin/main.js +0 -783
  341. package/core/asset/js/plugin/src/gina/popin/sass/config.sass +0 -37
  342. package/core/asset/js/plugin/src/gina/popin/sass/gina-design.sass +0 -622
  343. package/core/asset/js/plugin/src/gina/popin/sass/gina-popin.sass +0 -54
  344. package/core/asset/js/plugin/src/gina/popin/sass/helper.scss +0 -73
  345. package/core/asset/js/plugin/src/gina/toolbar/.npmignore +0 -19
  346. package/core/asset/js/plugin/src/gina/toolbar/css/toolbar.css +0 -433
  347. package/core/asset/js/plugin/src/gina/toolbar/css/toolbar.css.map +0 -1
  348. package/core/asset/js/plugin/src/gina/toolbar/index.html +0 -285
  349. package/core/asset/js/plugin/src/gina/toolbar/index.kit +0 -120
  350. package/core/asset/js/plugin/src/gina/toolbar/jquery-3.1.0.min.js +0 -4
  351. package/core/asset/js/plugin/src/gina/toolbar/main.js +0 -693
  352. package/core/asset/js/plugin/src/gina/toolbar/mock.gina.json +0 -1
  353. package/core/asset/js/plugin/src/gina/toolbar/mock.user.json +0 -1
  354. package/core/asset/js/plugin/src/gina/toolbar/readme.md +0 -7
  355. package/core/asset/js/plugin/src/gina/toolbar/sass/toolbar.sass +0 -563
  356. package/core/asset/js/plugin/src/gina/toolbar/svg-src/Info-color.svg +0 -1
  357. package/core/asset/js/plugin/src/gina/toolbar/svg-src/Info-grey.svg +0 -1
  358. package/core/asset/js/plugin/src/gina/toolbar/svg-src/error-color.svg +0 -1
  359. package/core/asset/js/plugin/src/gina/toolbar/svg-src/error-grey.svg +0 -1
  360. package/core/asset/js/plugin/src/gina/toolbar/svg-src/info-optim.svg +0 -13
  361. package/core/asset/js/plugin/src/gina/toolbar/svg-src/logo-gina.svg +0 -1
  362. package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings-big.svg +0 -1
  363. package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings.afdesign +0 -0
  364. package/core/asset/js/plugin/src/gina/toolbar/svg-src/settings.svg +0 -1
  365. package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-calendar-optim.svg +0 -1
  366. package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-calendar.svg +0 -1
  367. package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-card-optim.svg +0 -1
  368. package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-card.svg +0 -1
  369. package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-lock-optim.svg +0 -1
  370. package/core/asset/js/plugin/src/gina/toolbar/svg-src/stripe-lock.svg +0 -1
  371. package/core/asset/js/plugin/src/gina/toolbar/svg-src/warning-color.svg +0 -1
  372. package/core/asset/js/plugin/src/gina/toolbar/svg-src/warning-grey.svg +0 -1
  373. package/core/asset/js/plugin/src/gina/toolbar/test.jpg +0 -0
  374. package/core/asset/js/plugin/src/gina/toolbar/toolbar.html +0 -104
  375. package/core/asset/js/plugin/src/gina/utils/dom.js +0 -24
  376. package/core/asset/js/plugin/src/gina/utils/events.js +0 -201
  377. package/core/asset/js/plugin/src/gina/utils/loader.js +0 -57
  378. package/core/asset/js/plugin/src/main.js +0 -235
  379. package/core/asset/js/plugin/src/vendor/jquery/1.11.1-css-event_alias.min.js +0 -5
  380. package/core/asset/js/plugin/src/vendor/jquery/1.12.4.min.js +0 -5
  381. package/core/asset/js/plugin/src/vendor/jquery/2.1.1-css-event_alias-sizzle.min.js +0 -4
  382. package/core/asset/js/plugin/src/vendor/jquery/README.md +0 -14
  383. package/core/asset/js/plugin/src/vendor/jquery/slim-3.1.1.min.js +0 -4
  384. package/core/config.js +0 -1225
  385. package/core/controller/controller.js +0 -1860
  386. package/core/gna.js +0 -908
  387. package/core/plugins/lib/validator/src/form-validator.js +0 -788
  388. package/core/plugins/lib/validator/src/main.js +0 -2056
  389. package/core/router.js +0 -717
  390. package/core/server.js +0 -1363
  391. package/core/template/conf/env.json +0 -70
  392. package/core/template/conf/settings.json +0 -48
  393. package/core/template/conf/statics.json +0 -6
  394. package/core/template/conf/views.json +0 -16
  395. package/core/template/samples/bundle/config/app.json +0 -4
  396. package/core/template/samples/bundle/config/routing.json +0 -9
  397. package/core/template/samples/bundle/controllers/setup.js +0 -33
  398. package/core/template/views/js/vendor/readme.md +0 -1
  399. package/core/template/views/readme.md +0 -1
  400. package/core/utils/helpers/dateFormat.js +0 -264
  401. package/core/utils/helpers/index.js +0 -202
  402. package/core/utils/index.js +0 -75
  403. package/core/utils/lib/cmd/app.js +0 -686
  404. package/core/utils/lib/cmd/basic.help.txt +0 -40
  405. package/core/utils/lib/cmd/basic.js +0 -141
  406. package/core/utils/lib/cmd/gina-add-bundle.js +0 -328
  407. package/core/utils/lib/cmd/gina-add-views.js +0 -99
  408. package/core/utils/lib/cmd/gina-build.js +0 -218
  409. package/core/utils/lib/cmd/gina-clean.js +0 -26
  410. package/core/utils/lib/cmd/gina-connect.js +0 -176
  411. package/core/utils/lib/cmd/gina-delete-bundle.js +0 -176
  412. package/core/utils/lib/cmd/gina-deploy.js +0 -452
  413. package/core/utils/lib/cmd/gina-init-project.js +0 -83
  414. package/core/utils/lib/cmd/gina-start-bundle.js +0 -3
  415. package/core/utils/lib/cmd/gina-start.js +0 -3
  416. package/core/utils/lib/cmd/index.js +0 -157
  417. package/core/utils/lib/cmd/project.js +0 -14
  418. package/core/utils/lib/collection/src/main.js +0 -650
  419. package/core/utils/lib/logger/containers/file.js +0 -11
  420. package/core/utils/lib/logger/index.js +0 -260
  421. package/core/utils/lib/merge/src/main.js +0 -344
  422. package/core/utils/lib/proc.js +0 -416
  423. package/core/utils/lib/routing/src/main.js +0 -165
  424. package/documentation/css/default.css +0 -3
  425. package/documentation/html/home.html +0 -6
  426. package/documentation/html/inc/_footer.html +0 -5
  427. package/documentation/html/layout.html +0 -21
  428. package/documentation/img/debug-conf1.png +0 -0
  429. package/documentation/img/debug-conf2.png +0 -0
  430. package/documentation/img/debug-conf3.png +0 -0
  431. package/documentation/img/debug-conf4.png +0 -0
  432. package/documentation/img/debug-conf5.png +0 -0
  433. package/documentation/img/debug-conf6.png +0 -0
  434. package/documentation/img/debug-conf7.png +0 -0
  435. package/documentation/img/debug-new1.png +0 -0
  436. package/documentation/img/debug-new2.png +0 -0
  437. package/documentation/img/debug-start.png +0 -0
  438. package/documentation/md/api/controller/main.md +0 -74
  439. package/migration_note.md +0 -7
  440. package/package-lock.json +0 -611
  441. package/script/pre_publish.js +0 -207
  442. package/tutorial/Commands/README.md +0 -56
  443. package/tutorial/Commands/add-bundle-result.png +0 -0
  444. package/tutorial/Commands/add-bundle.png +0 -0
  445. package/tutorial/Commands/delete-bundle.png +0 -0
  446. package/tutorial/Commands/help.png +0 -0
  447. package/tutorial/Commands/init-project.png +0 -0
  448. package/tutorial/Commands/start-bundle-result.png +0 -0
  449. package/tutorial/Commands/start-bundle-stop.png +0 -0
  450. package/tutorial/Commands/start-bundle.png +0 -0
  451. package/tutorial/Commands/version.png +0 -0
  452. package/tutorial/ETC/README.md +0 -74
  453. package/tutorial/ETC/add-bundle-result.png +0 -0
  454. package/tutorial/ETC/add-bundle.png +0 -0
  455. package/tutorial/ETC/init-project.png +0 -0
  456. package/tutorial/Install/README.md +0 -54
  457. package/tutorial/Install/git-get.png +0 -0
  458. package/tutorial/Install/git-install-end.png +0 -0
  459. package/tutorial/Install/git-install-result.png +0 -0
  460. package/tutorial/Install/git-install-start.png +0 -0
  461. package/tutorial/Install/install-end.png +0 -0
  462. package/tutorial/Install/install-result.png +0 -0
  463. package/tutorial/Install/install-start.png +0 -0
  464. package/tutorial/WebStorm/README.md +0 -30
  465. package/tutorial/WebStorm/closure-compiler.png +0 -0
  466. package/tutorial/WebStorm/sass.png +0 -0
@@ -0,0 +1,1762 @@
1
+ /**
2
+ * FormValidatorUtil
3
+ *
4
+ * Dependencies:
5
+ * - utils/helpers
6
+ * - utils/helpers/dateFormat
7
+ * - utils/merge
8
+ * - utils/routing (for API calls)
9
+ *
10
+ * @param {object} data
11
+ * @param {object} [ $fields ] - isGFFCtx only
12
+ * @param {object} [ xhrOptions ] - isGFFCtx only
13
+ * @param {object} [ fieldsSet ] - isGFFCtx only; required for when ginaFormLiveCheckEnabled
14
+ * */
15
+ function FormValidatorUtil(data, $fields, xhrOptions, fieldsSet) {
16
+
17
+ var isGFFCtx = ( ( typeof(module) !== 'undefined' ) && module.exports ) ? false : true;
18
+
19
+ // if (isGFFCtx && !$fields )
20
+ // throw new Error('No `Validator` instance found.\nTry:\nvar FormValidator = require("gina/validator"):\nvar formValidator = new FormValidator(...);')
21
+
22
+ var merge = (isGFFCtx) ? require('utils/merge') : require('../../../../../lib/merge');
23
+ var helpers = (isGFFCtx) ? {} : require('../../../../../helpers');
24
+ var dateFormat = (isGFFCtx) ? require('helpers/dateFormat') : helpers.dateFormat;
25
+ var routing = (isGFFCtx) ? require('utils/routing') : require('../../../../../lib/routing');
26
+
27
+ var hasUserValidators = function() {
28
+
29
+ var _hasUserValidators = false, formsContext = null;
30
+ // backend validation check
31
+ if (!isGFFCtx) {
32
+ // TODO - retrieve bakcend forms context
33
+ formsContext = getContext('gina').forms || null;
34
+ } else if (isGFFCtx && typeof(gina.forms) != 'undefined') {
35
+ formsContext = gina.forms
36
+ }
37
+ if ( formsContext && typeof(formsContext.validators) != 'undefined' ) {
38
+ _hasUserValidators = true
39
+ }
40
+ return _hasUserValidators;
41
+ }
42
+ /**@js_externs local*/
43
+ var local = {
44
+ 'errors': {},
45
+ 'keys': {
46
+ '%l': 'label', // %l => label: needs `data-gina-form-field-label` attribute (frontend only)
47
+ '%n': 'name', // %n => field name
48
+ '%s': 'size' // %s => length
49
+ },
50
+ 'errorLabels': {},
51
+ 'data': {}, // output to send
52
+ 'excluded': []
53
+ };
54
+
55
+ local.errorLabels = {
56
+ 'is': 'Condition not satisfied',
57
+ 'isEmail': 'A valid email is required',
58
+ 'isRequired': 'Cannot be left empty',
59
+ 'isBoolean': 'Must be a valid boolean',
60
+ 'isNumber': 'Must be a number: allowed values are integers or floats',
61
+ 'isNumberLength': 'Must contain %s characters',
62
+ 'isNumberMinLength': 'Should be at least %s characters',
63
+ 'isNumberMaxLength': 'Should not be more than %s characters',
64
+ 'isInteger': 'Must be an integer',
65
+ 'isIntegerLength': 'Must have %s characters',
66
+ 'isIntegerMinLength': 'Should be at least %s characters',
67
+ 'isIntegerMaxLength': 'Should not be more than %s characters',
68
+ 'toInteger': 'Could not be converted to integer',
69
+ 'isFloat': 'Must be a proper float',
70
+ 'isFloatException': 'Float exception found: %n',
71
+ 'toFloat': 'Could not be converted to float',
72
+ 'toFloatNAN': 'Value must be a valid number',
73
+ 'isDate': 'Must be a valid Date',
74
+ 'isString': 'Must be a string',
75
+ 'isStringLength': 'Must have %s characters',
76
+ 'isStringMinLength': 'Should be at least %s characters',
77
+ 'isStringMaxLength': 'Should not be more than %s characters',
78
+ 'isJsonWebToken': 'Must be a valid JSON Web Token',
79
+ 'query': 'Must be a valid response',
80
+ 'isApiError': 'Condition not satisfied'
81
+ };
82
+ var self = null;
83
+ if (!data) {
84
+ throw new Error('missing data param')
85
+ } else {
86
+ // cloning
87
+ self = merge( JSON.clone(data), self );
88
+ local.data = merge( JSON.clone(data), local.data);
89
+ }
90
+
91
+ var getElementByName = function($form, name) { // frontend only
92
+ var $foundElement = null;
93
+ for (let f in fieldsSet) {
94
+ if (fieldsSet[f].name !== name) continue;
95
+
96
+ $foundElement = new DOMParser()
97
+ .parseFromString($form.innerHTML , 'text/html')
98
+ .getElementById( fieldsSet[f].id );
99
+ break;
100
+ }
101
+ if ($foundElement)
102
+ return $foundElement;
103
+
104
+ throw new Error('Field `'+ name +'` not found in fieldsSet');
105
+ }
106
+
107
+ /**
108
+ * bufferToString - Convert Buffer to String
109
+ * Will apply `Utf8Array` to `String`
110
+ * @param {array} arrayBuffer
111
+ */
112
+ var bufferToString = function(arrayBuffer) {
113
+ var out = null
114
+ , i = null
115
+ , len = null
116
+ , c = null
117
+ ;
118
+ var char2 = null, char3 = null;
119
+
120
+ out = '';
121
+ len = arrayBuffer.length;
122
+ i = 0;
123
+ while(i < len) {
124
+ c = arrayBuffer[i++];
125
+ switch (c >> 4) {
126
+ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
127
+ // 0xxxxxxx
128
+ out += String.fromCharCode(c);
129
+ break;
130
+ case 12: case 13:
131
+ // 110x xxxx 10xx xxxx
132
+ char2 = arrayBuffer[i++];
133
+ out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
134
+ break;
135
+ case 14:
136
+ // 1110 xxxx 10xx xxxx 10xx xxxx
137
+ char2 = arrayBuffer[i++];
138
+ char3 = arrayBuffer[i++];
139
+ out += String.fromCharCode(((c & 0x0F) << 12) |
140
+ ((char2 & 0x3F) << 6) |
141
+ ((char3 & 0x3F) << 0));
142
+ break;
143
+ }
144
+ }
145
+
146
+ return out;
147
+ };
148
+
149
+ // TODO - One method for the front, and one for the server
150
+ var queryFromFrontend = function(options, errorMessage) {
151
+ var errors = self[this['name']]['errors'] || {};
152
+ var id = this.target.id || this.target.getAttribute('id');
153
+
154
+
155
+ // stop if
156
+ // - previous error detected
157
+ if ( !self.isValid() ) {
158
+ console.debug('stopping on errors ...');
159
+ triggerEvent(gina, this.target, 'asyncCompleted.' + id, self[this['name']]);
160
+ //return self[this.name];
161
+ return;
162
+ }
163
+
164
+ var testedValue = this.target.dataset.ginaFormValidatorTestedValue;
165
+ console.debug('[ '+ this['name'] +' ]', 'TESTED VALUE -> ' + this.value +' vs '+ testedValue);
166
+ var _evt = 'asyncCompleted.' + id;
167
+ var currentFormId = this.target.form.getAttribute('id');
168
+ var cachedErrors = (
169
+ typeof(gina.validator) != 'undefined'
170
+ && typeof(gina.validator.$forms[currentFormId]) != 'undefined'
171
+ && typeof(gina.validator.$forms[currentFormId].cachedErrors) != 'undefined'
172
+ )
173
+ ? gina.validator.$forms[currentFormId].cachedErrors
174
+ : null;
175
+ if ( !testedValue || typeof(testedValue) == 'undefined' || testedValue !== this.value ) {
176
+ this.target.dataset.ginaFormValidatorTestedValue = this.value;
177
+ // remove cachedErrors
178
+ if (
179
+ cachedErrors
180
+ && typeof(cachedErrors[this.name]) != 'undefined'
181
+ && typeof(cachedErrors[this.name].query) != 'undefined'
182
+ ) {
183
+ delete cachedErrors[this.name].query;
184
+ if (
185
+ typeof(gina.validator.$forms[currentFormId]) != 'undefined'
186
+ &&
187
+ typeof(gina.validator.$forms[currentFormId].errors) != 'undefined'
188
+ ) {
189
+ delete gina.validator.$forms[currentFormId].errors.query;
190
+ }
191
+
192
+ }
193
+ } else if (testedValue === this.value) {
194
+ // not resending to backend, but in case of cached errors, re display same error message
195
+ var hasCachedErrors = false;
196
+ if (
197
+ cachedErrors
198
+ && typeof(cachedErrors[this.name]) != 'undefined'
199
+ && typeof(cachedErrors[this.name].query) != 'undefined'
200
+ && typeof(cachedErrors[this.name].query[this.value]) != 'undefined'
201
+ ) {
202
+ this.error = errorMessage = cachedErrors[this.name].query[this.value].slice(0);
203
+ hasCachedErrors = true;
204
+ }
205
+ errors['query'] = replace( this.error || errorMessage || local.errorLabels['query'], this);
206
+
207
+ if (hasCachedErrors) {
208
+ this['errors'] = errors;
209
+ this.valid = false;
210
+ }
211
+ // Do not remove this test
212
+ if ( typeof( gina.events[_evt]) != 'undefined' ) {
213
+ triggerEvent(gina, this.target, _evt, self[this['name']]);
214
+ }
215
+
216
+ return self[this.name];
217
+ }
218
+ //console.debug('Did not return !!!');
219
+
220
+ var xhr = null, _this = this;
221
+ // setting up AJAX
222
+ if (window.XMLHttpRequest) { // Mozilla, Safari, ...
223
+ xhr = new XMLHttpRequest();
224
+ } else if (window.ActiveXObject) { // IE
225
+ try {
226
+ xhr = new ActiveXObject("Msxml2.XMLHTTP");
227
+ } catch (e) {
228
+ try {
229
+ xhr = new ActiveXObject("Microsoft.XMLHTTP");
230
+ }
231
+ catch (e) {}
232
+ }
233
+ }
234
+
235
+ // forcing to sync mode
236
+ var queryOptions = { isSynchrone: false, headers: {} };
237
+ var queryData = options.data || null, strData = null;
238
+ var isInlineValidation = (/^true$/i.test(this.target.form.dataset.ginaFormLiveCheckEnabled)) ? true : false; // TRUE if liveCheckEnabled
239
+
240
+ // replace placeholders by field values
241
+ strData = JSON.stringify(queryData);
242
+ if ( /\$/.test(strData) ) {
243
+ var variables = strData.match(/\$[-_\[\]a-z 0-9]+/g) || [];
244
+ var value = null, key = null;
245
+ for (let i = 0, len = variables.length; i < len; i++) {
246
+ key = variables[i].replace(/\$/g, '');
247
+ re = new RegExp("\\"+ variables[i].replace(/\[|\]/g, '\\$&'), "g");
248
+ value = local.data[key] || null;
249
+ if (!value && isInlineValidation) {
250
+ // Retrieving live value instead of using fieldsSet.value
251
+ value = getElementByName(this.target.form, key).value;
252
+ }
253
+
254
+ strData = strData.replace( re, value );
255
+ }
256
+ }
257
+ // cleanup before sending
258
+ queryData = strData.replace(/\\"/g, '');
259
+ // TODO - support regexp for validIf
260
+ var validIf = ( typeof(options.validIf) == 'undefined' ) ? true : options.validIf;
261
+
262
+ queryOptions = merge(queryOptions, options, xhrOptions);
263
+ delete queryOptions.data;
264
+ delete queryOptions.validIf;
265
+
266
+ var enctype = queryOptions.headers['Content-Type'];
267
+ var result = null
268
+ , $target = this.target
269
+ //, id = $target.getAttribute('id')
270
+ ;
271
+ id = $target.getAttribute('id')
272
+
273
+ // checking url
274
+ if (!/^http/.test(queryOptions.url) && /\@/.test(queryOptions.url) ) {
275
+ try {
276
+ var route = routing.getRoute(queryOptions.url);
277
+ queryOptions.url = route.toUrl();
278
+ } catch (routingError) {
279
+ throw routingError;
280
+ }
281
+ }
282
+
283
+ if ( queryOptions.withCredentials ) {
284
+ if ('withCredentials' in xhr) {
285
+ // XHR for Chrome/Firefox/Opera/Safari.
286
+ if (queryOptions.isSynchrone) {
287
+ xhr.open(queryOptions.method, queryOptions.url, queryOptions.isSynchrone)
288
+ } else {
289
+ xhr.open(queryOptions.method, queryOptions.url)
290
+ }
291
+ } else if ( typeof XDomainRequest != 'undefined' ) {
292
+ // XDomainRequest for IE.
293
+ xhr = new XDomainRequest();
294
+ // if (queryOptions.isSynchrone) {
295
+ // xhr.open(queryOptions.method, queryOptions.url, queryOptions.isSynchrone);
296
+ // } else {
297
+ xhr.open(queryOptions.method, queryOptions.url);
298
+ // }
299
+ } else {
300
+ // CORS not supported.
301
+ xhr = null;
302
+ result = 'CORS not supported: the server is missing the header `"Access-Control-Allow-Credentials": true` ';
303
+ //triggerEvent(gina, $target, 'error.' + id, result);
304
+ throw new Error(result);
305
+ }
306
+
307
+ if ( typeof(queryOptions.responseType) != 'undefined' ) {
308
+ /**
309
+ * Note: We expect to remove support for synchronous use of XMLHTTPRequest() during page unloads in Chrome in version 88,
310
+ * scheduled to ship in January 2021.
311
+ * The XMLHttpRequest2 spec was recently changed to prohibit sending a synchronous request when XMLHttpRequest.responseType
312
+ */
313
+ xhr.responseType = queryOptions.responseType;
314
+ } else {
315
+ xhr.responseType = '';
316
+ }
317
+
318
+ xhr.withCredentials = true;
319
+ } else {
320
+ if (queryOptions.isSynchrone) {
321
+ xhr.open(queryOptions.method, queryOptions.url, queryOptions.isSynchrone)
322
+ } else {
323
+ xhr.open(queryOptions.method, queryOptions.url)
324
+ }
325
+ }
326
+
327
+ // setting up headers - all but Content-Type ; it will be set right before .send() is called
328
+ for (var hearder in queryOptions.headers) {
329
+ if (hearder == 'Content-Type' && typeof (enctype) != 'undefined' && enctype != null && enctype != '')
330
+ continue;
331
+
332
+ xhr.setRequestHeader(hearder, queryOptions.headers[hearder]);
333
+ }
334
+ if (typeof (enctype) != 'undefined' && enctype != null && enctype != '') {
335
+ xhr.setRequestHeader('Content-Type', enctype);
336
+ }
337
+
338
+ if (xhr) {
339
+
340
+ xhr.onload = function () {
341
+
342
+ var onResult = function(result) {
343
+
344
+ _this.value = local['data'][_this.name] = (_this.value) ? _this.value.toLowerCase() : _this.value;
345
+
346
+ var isValid = result.isValid || false;
347
+ if (validIf != isValid) {
348
+ isValid = false;
349
+ } else {
350
+ isValid = true;
351
+ }
352
+ self[_this['name']].valid = isValid;
353
+ var errors = self[_this['name']]['errors'] || {};
354
+
355
+ var errorFields = ( typeof(result.error) != 'undefined' && typeof(result.fields) != 'undefined' ) ? result.fields : {};
356
+
357
+ if (errorFields.count() > 0 && !isValid || !isValid) {
358
+
359
+ if (!isValid) {
360
+ var systemError = null;
361
+ if ( typeof(errorFields[_this.name]) != 'undefined') {
362
+ local.errorLabels['query'] = errorFields[_this.name];
363
+ } else if ( typeof(result.error) != 'undefined' && /^5/.test(result.status) ) {
364
+ // system error
365
+ //console.debug('found system error: ', result);
366
+ systemError = result.error;
367
+ }
368
+ errors['query'] = replace(systemError || _this['error'] || options['error'] || local.errorLabels['query'], _this);
369
+ console.debug('query error detected !! ', result);
370
+ }
371
+
372
+ if ( !errors['query'] && _this.value == '' ) {
373
+ isValid = true;
374
+ }
375
+ }
376
+
377
+ // if error tagged by a previous validation, remove it when isValid == true
378
+ if ( isValid && typeof(errors['query']) != 'undefined' ) {
379
+ delete errors['query'];
380
+ }
381
+
382
+ // To handle multiple errors from backend
383
+ // for (var f in errorFields.length) {
384
+ // if ( !errors['query'] && _this.value == '' ) {
385
+ // isValid = true;
386
+ // }
387
+
388
+ // if (!isValid) {
389
+ // errors['query'] = replace(_this['error'] || local.errorLabels['query'], _this)
390
+ // }
391
+ // // if error tagged by a previous validation, remove it when isValid == true
392
+ // else if ( isValid && typeof(errors['query']) != 'undefined' ) {
393
+ // delete errors['query'];
394
+ // }
395
+ // }
396
+
397
+ _this.valid = isValid;
398
+ var cachedErrors = gina.validator.$forms[_this.target.form.getAttribute('id')].cachedErrors || {};
399
+ if ( errors.count() > 0 ) {
400
+
401
+ _this['errors'] = errors;
402
+ if ( typeof(self[_this['name']].errors) == 'undefined' ) {
403
+ self[_this['name']].errors = {};
404
+ }
405
+
406
+ self[_this['name']].errors = merge(self[_this['name']].errors, errors);
407
+
408
+ if ( typeof(errors.query) != 'undefined' && errors.query ) {
409
+
410
+ if ( typeof(cachedErrors[_this.name]) == 'undefined' ) {
411
+ cachedErrors[_this.name] = {}
412
+ }
413
+ if ( typeof(cachedErrors[_this.name].query) == 'undefined' ) {
414
+ cachedErrors[_this.name].query = {}
415
+ }
416
+
417
+ cachedErrors[_this.name].query[_this.value] = errors.query.slice(0);
418
+ }
419
+
420
+ var errClass = _this.target.getAttribute('data-gina-form-errors');
421
+ if ( !/query/.test(errClass) ) {
422
+ if ( !errClass || errClass =='' ) {
423
+ errClass = 'query'
424
+ } else {
425
+ errClass +=' query'
426
+ }
427
+ _this.target.setAttribute('data-gina-form-errors', errClass);
428
+ }
429
+ } else if (
430
+ typeof(cachedErrors[_this.name]) != 'undefined'
431
+ && typeof(cachedErrors[_this.name].query) != 'undefined'
432
+ && typeof(cachedErrors[_this.name].query[_this.value]) != 'undefined'
433
+ ) {
434
+ delete cachedErrors[_this.name].query[_this.value];
435
+ }
436
+
437
+ var id = _this.target.id || _this.target.getAttribute('id');
438
+ console.debug('prematurely completed event `'+ 'asyncCompleted.' + id +'`');
439
+ return triggerEvent(gina, _this.target, 'asyncCompleted.' + id, self[_this['name']]);
440
+ }
441
+
442
+ try {
443
+ result = this.responseText;
444
+ var contentType = this.getResponseHeader("Content-Type");
445
+ if ( /\/json/.test( contentType ) ) {
446
+ result = JSON.parse(this.responseText);
447
+
448
+ if ( typeof(result.status) == 'undefined' )
449
+ result.status = this.status;
450
+
451
+ //triggerEvent(gina, $target, 'success.' + id, result);
452
+ return onResult(result)
453
+ } else {
454
+ result = { 'status': xhr.status, 'message': '' };
455
+ if ( /^(\{|\[)/.test( xhr.responseText ) ) {
456
+ try {
457
+ result = merge( result, JSON.parse(xhr.responseText) );
458
+ } catch (err) {
459
+ result = merge(result, err);
460
+ }
461
+ }
462
+ return onResult(result);
463
+ }
464
+ } catch (err) {
465
+ throw err;
466
+ }
467
+ }
468
+
469
+ if (data) {
470
+ xhr.send( queryData ); // stringyfied
471
+ } else {
472
+ xhr.send();
473
+ }
474
+ }
475
+ }
476
+
477
+ /**
478
+ * queryFromBackend
479
+ *
480
+ *
481
+ * @param {object} options
482
+ * @param {object} request
483
+ * @param {object} response
484
+ * @param {callback} next
485
+ *
486
+ *
487
+ */
488
+ var queryFromBackend = async function(options, request, response, next) {
489
+ var Config = require(_(GINA_FRAMEWORK_DIR +'/core/config.js', true));
490
+ var config = new Config().getInstance();
491
+
492
+ var opt = null
493
+ //appConf.proxy.<bundle>;
494
+ , rule = null
495
+ , bundle = null
496
+ , currentBundle = getContext('bundle')
497
+ ;
498
+ // trying to retrieve proxy conf
499
+ if ( /\@/.test(options.url) ) {
500
+ var attr = options.url.split(/@/);
501
+ rule = attr[0];
502
+ bundle = attr[1];
503
+ var proxyConf = getConfig( currentBundle, 'app' ).proxy;
504
+ try {
505
+ if (config.bundle !== bundle) { // ignore if same bundle
506
+ // getting proxy conf when available
507
+ opt = getConfig( currentBundle, 'app' ).proxy[bundle];
508
+ }
509
+ } catch (proxyError) {
510
+ throw new Error('Could not retrieve `proxy` configuration for bundle `'+ bundle +'`. Please check your `/config/app.json`.\n'+proxyError.stack);
511
+ }
512
+
513
+ attr = null;
514
+ } else {
515
+ // TODO - handle else; when it is an external domain/url
516
+ throw new Error('external url/domain not handled at this moment, please contact us if you need support for it.')
517
+ }
518
+ var route = JSON.clone(routing.getRoute(options.url, options.data));
519
+ var env = config.env;
520
+ var conf = config[bundle][env];
521
+ if (!opt) { // setup opt by default if no proxy conf found
522
+ if (config.bundle == bundle) {
523
+ var credentials = getConfig( currentBundle, 'settings' ).server.credentials;
524
+ options.ca = credentials.ca || null;
525
+ options.hostname = conf.server.scheme +'://'+ conf.host;
526
+ options.port = conf.port[conf.server.protocol][conf.server.scheme];
527
+ options.protocol = conf.server.protocol;
528
+ options.rejectUnauthorized = false;
529
+ }
530
+ opt = {
531
+ "ca" : options.ca,
532
+ "hostname" : options.hostname,
533
+ "port" : options.port,
534
+ "path" : options.path
535
+ };
536
+
537
+ if ( typeof(options.protocol) != 'undefined' ) {
538
+ opt.protocol = options.protocol
539
+ }
540
+ if ( typeof(options.rejectUnauthorized) != 'undefined' ) {
541
+ opt.rejectUnauthorized = options.rejectUnauthorized
542
+ }
543
+ }
544
+
545
+ /**
546
+ * BO routing configuration
547
+ * Attention: this portion of code is from `router.js`
548
+ * Any modification on this part must be reflected on `router.js`
549
+ */
550
+ // default param setting
551
+ var params = {
552
+ method : route.method,
553
+ requirements : route.requirements,
554
+ namespace : route.namespace || undefined,
555
+ url : unescape(route.url), /// avoid %20
556
+ rule : rule + '@' + bundle,
557
+ param : JSON.clone(route.param),
558
+ middleware : JSON.clone(route.middleware),
559
+ bundle : route.bundle,
560
+ isXMLRequest : request.isXMLRequest,
561
+ isWithCredentials : request.isWithCredentials
562
+ };
563
+
564
+ var templateName = params.rule.replace('\@'+ bundle, '') || '_common';
565
+ var routeHasViews = ( typeof(conf.content.templates) != 'undefined' ) ? true : false;
566
+ var controllerOptions = {
567
+ // view namespace first
568
+ template: (routeHasViews) ? conf.content.templates[templateName] || conf.content.templates._common : undefined,
569
+ // namespace : params.param.namespace || namespace,
570
+ //control : route.param.control,
571
+ // controller : controllerFile,
572
+ //controller: '<span class="gina-bundle-name">' + bundle +'</span>/controllers/controller.js',
573
+ //file: route.param.file, // matches rule name by default
574
+ //bundle : bundle,//module
575
+ // bundlePath : conf.bundlesPath + '/' + bundle,
576
+ // rootPath : self.executionPath,
577
+ // We don't want to keep original conf untouched
578
+ conf : JSON.clone(conf),
579
+ //instance: self.serverInstance,
580
+ //template: (routeHasViews) ? conf.content.templates[templateName] : undefined,
581
+ //isUsingTemplate: local.isUsingTemplate,
582
+ cacheless: conf.cacheless //,
583
+ //path: params.param.path || null, // user custom path : namespace should be ignored | left blank
584
+ //assets: {}
585
+ };
586
+
587
+ controllerOptions = merge(controllerOptions, params);
588
+
589
+ // BO - Template outside of namespace fix added on 2021-08-19
590
+ // We want to keep original conf untouched
591
+ controllerOptions.conf = JSON.clone(conf);
592
+ controllerOptions.conf.content.routing[controllerOptions.rule].param = params.param;
593
+ // inheriting from _common
594
+ if (
595
+ controllerOptions.template
596
+ && typeof(controllerOptions.template.ginaLoader) == 'undefined'
597
+ ) {
598
+ controllerOptions.template.ginaLoader = controllerOptions.conf.content.templates._common.ginaLoader;
599
+ }
600
+ controllerOptions.conf.content.routing[controllerOptions.rule].param = params.param;
601
+ delete controllerOptions.middleware;
602
+ delete controllerOptions.param;
603
+ delete controllerOptions.requirements;
604
+ // EO - Template outside of namespace
605
+ /**
606
+ * EO routing configuration
607
+ */
608
+
609
+ var Controller = require(_(GINA_FRAMEWORK_DIR +'/core/controller/controller.js'), true);
610
+ var controller = new Controller(controllerOptions);
611
+ controller.name = route.param.control;
612
+ //controller.serverInstance = serverInstance;
613
+ controller.setOptions(request, response, next, controllerOptions);
614
+
615
+
616
+ var data = ( typeof(options.data) == 'object' && options.data.count() > 0 )
617
+ ? options.data
618
+ : {};
619
+ // inherited data from current query asking for validation
620
+ var urlParams = '';
621
+ if ( /^get|delete|put$/i.test(options.method) ) {
622
+ urlParams += '?';
623
+ var i = 0;
624
+ for (let p in data) {
625
+ if (i > 0) {
626
+ urlParams += '&';
627
+ }
628
+ let val = (typeof(data[p]) == 'object') ? encodeURIComponent(JSON.stringify(data[p])) : data[p];
629
+ urlParams += p +'='+ val;
630
+ i++;
631
+ }
632
+ }
633
+ opt.method = options.method;
634
+ //opt.path = route.url + urlParams;
635
+ opt.path = route.url;
636
+
637
+ var util = require('util');
638
+ var promisify = util.promisify;
639
+ var result = { isValid: false }, err = false;
640
+
641
+ await promisify(controller.query)(opt, data)
642
+ .then(function onResult(_result) {
643
+ result = _result;
644
+ })
645
+ .catch(function onResultError(_err) {
646
+ err = _err;
647
+ });
648
+ if (err) {
649
+ //throw err;
650
+ console.error(err);
651
+ result.error = err;
652
+ }
653
+ return result;
654
+ };
655
+
656
+ /**
657
+ * query
658
+ */
659
+ var query = null;
660
+ if (isGFFCtx) {
661
+ query = queryFromFrontend;
662
+ } else {
663
+ query = queryFromBackend;
664
+ }
665
+
666
+
667
+ /**
668
+ * addField
669
+ * Add field to the validation context
670
+ * @param {string} el
671
+ * @param {string|boolean|number|object} [value]
672
+ */
673
+ var addField = function(el, value) {
674
+ var val = null, label = null;
675
+
676
+ if ( typeof(self[el]) == 'undefined' && typeof(value) != 'undefined' ) {
677
+ self[el] = val = value;
678
+ }
679
+
680
+ if ( typeof(self[el]) == 'object' ) {
681
+ try {
682
+ val = JSON.parse( JSON.stringify( self[el] ))
683
+ } catch (err) {
684
+ val = self[el]
685
+ }
686
+ } else {
687
+ val = self[el]
688
+ }
689
+
690
+ label = '';
691
+ if ( isGFFCtx && typeof($fields) != 'undefined' ) { // frontend only
692
+ label = $fields[el].getAttribute('data-gina-form-field-label') || '';
693
+ }
694
+
695
+ // keys are stringyfied because of the compiler !!!
696
+ self[el] = {
697
+ 'target': (isGFFCtx && typeof($fields) != 'undefined') ? $fields[el] : null,
698
+ 'name': el,
699
+ 'value': val,
700
+ 'valid': false,
701
+ // is name by default, but you should use setLabe(name) to change it if you need to
702
+ 'label': label,
703
+ // check as field to exclude while sending datas to the model
704
+ 'exclude': false
705
+ };
706
+
707
+ /**
708
+ *
709
+ * is(condition) -> validate if value matches `condition`
710
+ *
711
+ * When entered in a JSON rule, you must double the backslashes
712
+ *
713
+ * e.g.:
714
+ * "/\\D+/" -> like [^0-9]
715
+ * "!/^\\\\s+/" -> not starting by white space allow
716
+ * "/^[0-9]+$/" -> only numbers
717
+ * "$field === $fieldOther" -> will be evaluated
718
+ *
719
+ * @param {object|string} condition - RegExp object, or condition to eval, or eval result
720
+ * @param {string} [errorMessage] - error message
721
+ * @param {string} [errorStack] - error stack
722
+ *
723
+ * */
724
+ self[el]['is'] = function(condition, errorMessage, errorStack) {
725
+ var isValid = false;
726
+ var alias = ( typeof(window) != 'undefined' && typeof(window._currentValidatorAlias) != 'undefined' ) ? window._currentValidatorAlias : 'is';
727
+ if ( typeof(window) != 'undefined' && window._currentValidatorAlias)
728
+ delete window._currentValidatorAlias;
729
+
730
+ var errors = self[this['name']]['errors'] || {};
731
+ local.data[this.name] = self[this.name].value;
732
+
733
+ if (
734
+ typeof(errors['isRequired']) == 'undefined'
735
+ && this.value == ''
736
+ && !/^false$/i.test(this.value)
737
+ && this.value != 0
738
+ ||
739
+ !errors['isRequired']
740
+ && this.value == ''
741
+ && !/^false$/i.test(this.value)
742
+ && this.value != 0
743
+ ) {
744
+ isValid = true;
745
+ } else if (!errors['isRequired'] && typeof(this.value) == 'string' && this.value == '') {
746
+ isValid = true;
747
+ }
748
+
749
+ if ( !isValid && /^(true|false)$/i.test(condition) ) { // because it can be evaluated on backend validation
750
+ isValid = condition;
751
+ } else if (!isValid) {
752
+ var re = null, flags = null;
753
+ // Fixed on 2021-03-13: $variable now replaced with real value beafore validation
754
+ if ( /[\!\=>\>\<a-z 0-9]+/i.test(condition) ) {
755
+ var variables = condition.match(/\${0}[-_,.\[\]a-z0-9]+/ig); // without space(s)
756
+ if (variables && variables.length > 0) {
757
+ var compiledCondition = condition;
758
+ for (var i = 0, len = variables.length; i < len; ++i) {
759
+ // $varibale comparison
760
+ if ( typeof(self[ variables[i] ]) != 'undefined' && variables[i]) {
761
+ re = new RegExp("\\$"+ variables[i] +"(?!\\S+)", "g");
762
+ if ( self[ variables[i] ].value == "" ) {
763
+ compiledCondition = compiledCondition.replace(re, '""');
764
+ } else if ( typeof(self[ variables[i] ].value) == 'string' ) {
765
+ compiledCondition = compiledCondition.replace(re, '"'+ self[ variables[i] ].value +'"');
766
+ } else {
767
+ compiledCondition = compiledCondition.replace(re, self[ variables[i] ].value);
768
+ }
769
+ }
770
+ }
771
+
772
+ try {
773
+ // security checks
774
+ compiledCondition = compiledCondition.replace(/(\(|\)|return)/g, '');
775
+ if ( /^\//.test(compiledCondition) ) {
776
+ isValid = eval(compiledCondition + '.test("' + this.value + '")')
777
+ } else {
778
+ isValid = eval(compiledCondition)
779
+ }
780
+
781
+ } catch (err) {
782
+ throw new Error(err.stack||err.message)
783
+ }
784
+ }
785
+ } else if ( condition instanceof RegExp ) {
786
+
787
+ isValid = condition.test(this.value) ? true : false;
788
+
789
+ } else if( typeof(condition) == 'boolean') {
790
+
791
+ isValid = (condition) ? true : false;
792
+
793
+ } else {
794
+ try {
795
+ // TODO - motif /gi to pass to the second argument
796
+ if ( /\/(.*)\//.test(condition) ) {
797
+ re = condition.match(/\/(.*)\//).pop();
798
+ flags = condition.replace('/' + re + '/', '');
799
+
800
+ isValid = new RegExp(re, flags).test(this.value)
801
+ } else {
802
+ isValid = eval(condition);
803
+ }
804
+
805
+ //valid = new RegExp(condition.replace(/\//g, '')).test(this.value)
806
+ } catch (err) {
807
+ throw new Error(err.stack||err.message)
808
+ }
809
+ }
810
+ }
811
+
812
+ if (!isValid) {
813
+ errors[alias] = replace(this.error || errorMessage || local.errorLabels[alias], this);
814
+ if ( typeof(errorStack) != 'undefined' )
815
+ errors['stack'] = errorStack;
816
+ }
817
+ // if error tagged by a previous vlaidation, remove it when isValid == true
818
+ else if ( isValid && typeof(errors[alias]) != 'undefined' ) {
819
+ delete errors[alias];
820
+ //delete errors['stack'];
821
+ }
822
+
823
+ this.valid = isValid;
824
+ if ( errors.count() > 0 )
825
+ this['errors'] = errors;
826
+
827
+
828
+ return self[this.name]
829
+ }
830
+
831
+ self[el]['set'] = function(value) {
832
+ this.value = local['data'][this.name] = value;
833
+ // html
834
+ this.target.setAttribute('value', value);
835
+ // Todo : select and radio case to apply change
836
+
837
+ return self[this.name]
838
+ }
839
+
840
+ self[el]['isEmail'] = function() {
841
+
842
+
843
+ this.value = local['data'][this.name] = (this.value) ? this.value.toLowerCase() : this.value;
844
+ // Apply on current field upper -> lower
845
+ if (
846
+ isGFFCtx
847
+ && this.target
848
+ && this.target.value != ''
849
+ && /[A-Z]+/.test(this.target.value)
850
+ ) {
851
+ this.target.value = this.value;
852
+ }
853
+
854
+
855
+ var rgx = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
856
+ var isValid = rgx.test(this['value']) ? true : false;
857
+ var errors = self[this['name']]['errors'] || {};
858
+
859
+ if ( !errors['isRequired'] && this.value == '' ) {
860
+ isValid = true;
861
+ }
862
+
863
+ if (!isValid) {
864
+ errors['isEmail'] = replace(this['error'] || local.errorLabels['isEmail'], this)
865
+ }
866
+ // if error tagged by a previous vlaidation, remove it when isValid == true
867
+ else if ( isValid && typeof(errors['isEmail']) != 'undefined' ) {
868
+ delete errors['isEmail'];
869
+ //delete errors['stack'];
870
+ }
871
+
872
+ this.valid = isValid;
873
+
874
+ if ( errors.count() > 0 )
875
+ this['errors'] = errors;
876
+
877
+ return self[this['name']]
878
+ }
879
+
880
+ self[el]['isJsonWebToken'] = function() {
881
+
882
+
883
+ this.value = local['data'][this.name] = (this.value) ? this.value.toLowerCase() : this.value;
884
+ // Apply on current field upper -> lower
885
+ if (
886
+ isGFFCtx
887
+ && this.target
888
+ && this.target.value != ''
889
+ && /[A-Z]+/.test(this.target.value)
890
+ ) {
891
+ this.target.value = this.value;
892
+ }
893
+
894
+ var rgx = /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/;
895
+ var isValid = rgx.test(this['value']) ? true : false;
896
+ var errors = self[this['name']]['errors'] || {};
897
+
898
+ if ( !errors['isRequired'] && this.value == '' ) {
899
+ isValid = true;
900
+ }
901
+
902
+ if (!isValid) {
903
+ errors['isJsonWebToken'] = replace(this['error'] || local.errorLabels['isJsonWebToken'], this)
904
+ }
905
+ // if error tagged by a previous vlaidation, remove it when isValid == true
906
+ else if ( isValid && typeof(errors['isJsonWebToken']) != 'undefined' ) {
907
+ delete errors['isJsonWebToken'];
908
+ //delete errors['stack'];
909
+ }
910
+
911
+ this.valid = isValid;
912
+
913
+ if ( errors.count() > 0 )
914
+ this['errors'] = errors;
915
+
916
+ return self[this['name']]
917
+ }
918
+
919
+ /**
920
+ * Check if boolean and convert to `true/false` booloean if value is a string or a number
921
+ * Will include `false` value if isRequired
922
+ * */
923
+ self[el]['isBoolean'] = function() {
924
+ var val = null
925
+ , errors = self[this['name']]['errors'] || {}
926
+ ;
927
+
928
+ if ( errors['isRequired'] && this.value == false) {
929
+ isValid = true;
930
+ delete errors['isRequired'];
931
+ this['errors'] = errors;
932
+ }
933
+
934
+ switch(this.value) {
935
+ case 'true':
936
+ case true:
937
+ case 1:
938
+ val = this.value = local.data[this.name] = true;
939
+ break;
940
+ case 'false':
941
+ case false:
942
+ case 0:
943
+ val = this.value = local.data[this.name] = false;
944
+ break;
945
+ }
946
+
947
+ var isValid = (val !== null) ? true : false;
948
+
949
+ if (!isValid) {
950
+ errors['isBoolean'] = replace(this.error || local.errorLabels['isBoolean'], this)
951
+ }
952
+ // if error tagged by a previous vlaidation, remove it when isValid == true
953
+ else if ( isValid && typeof(errors['isBoolean']) != 'undefined' ) {
954
+ delete errors['isBoolean'];
955
+ //delete errors['stack'];
956
+ }
957
+
958
+ this.valid = isValid;
959
+ if ( errors.count() > 0 )
960
+ this['errors'] = errors;
961
+
962
+ return self[this.name]
963
+ }
964
+
965
+ /**
966
+ * Check if value is an a Number.
967
+ * - valid if a number is found
968
+ * - cast into a number if a string is found
969
+ * - if string is blank, no transformation will be done: valid if not required
970
+ *
971
+ * @param {number} minLength
972
+ * @param {number} maxLength
973
+ *
974
+ * @returns {object} result
975
+ * */
976
+ self[el]['isNumber'] = function(minLength, maxLength) {
977
+ var val = this.value
978
+ , len = 0
979
+ , isValid = false
980
+ , isMinLength = true
981
+ , isMaxLength = true
982
+ , errors = self[this['name']]['errors'] || {}
983
+ ;
984
+
985
+ // test if val is a number
986
+ try {
987
+ // if val is a string replaces comas by points
988
+ if ( typeof(val) == 'string' && /\,|\./g.test(val) ) {
989
+ val = local.data[this.name] = this.value = parseFloat( val.replace(/,/g, '.').replace(/\s+/g, '') );
990
+ } else if ( typeof(val) == 'string' && val != '') {
991
+ val = local.data[this.name] = this.value = parseInt( val.replace(/\s+/g, '') );
992
+ }
993
+
994
+ } catch (err) {
995
+ errors['isNumber'] = replace(this.error || local.errorLabels['isNumber'], this);
996
+ this.valid = false;
997
+ if ( errors.count() > 0 )
998
+ this['errors'] = errors;
999
+ }
1000
+
1001
+ if ( +val === +val ) {
1002
+ isValid = true;
1003
+ if ( !errors['isRequired'] && val != '' ) {
1004
+ len = val.toString().length;
1005
+ // if so also test max and min length if defined
1006
+ if (minLength && typeof(minLength) == 'number' && len < minLength) {
1007
+ isMinLength = false;
1008
+ this['size'] = minLength;
1009
+ }
1010
+ if (maxLength && typeof(maxLength) == 'number' && len > maxLength) {
1011
+ isMaxLength = false;
1012
+ this['size'] = maxLength;
1013
+ }
1014
+ }
1015
+ }
1016
+
1017
+ // if val is invalid return error message
1018
+ if ( !isValid || !isMinLength || !isMaxLength ) {
1019
+
1020
+ if ( !isValid )
1021
+ errors['isNumber'] = replace(this.error || local.errorLabels['isNumber'], this);
1022
+ if ( !isMinLength || !isMaxLength ) {
1023
+ if ( !isMinLength )
1024
+ errors['isNumberLength'] = replace(this.error || local.errorLabels['isNumberMinLength'], this);
1025
+ if ( !isMaxLength )
1026
+ errors['isNumberLength'] = replace(this.error || local.errorLabels['isNumberMaxLength'], this);
1027
+ if ( minLength === maxLength )
1028
+ errors['isNumberLength'] = replace(this.error || local.errorLabels['isNumberLength'], this);
1029
+ }
1030
+
1031
+ isValid = false;
1032
+ }
1033
+ // if error tagged by a previous vlaidation, remove it when isValid == true
1034
+ if ( isValid && typeof(errors['isNumberLength']) != 'undefined') {
1035
+ delete errors['isNumberLength'];
1036
+ }
1037
+
1038
+ this.valid = isValid;
1039
+ val = this.value = local.data[this.name] = ( val != '' ) ? Number(val) : val;
1040
+ if ( errors.count() > 0 )
1041
+ this['errors'] = errors;
1042
+
1043
+ return self[this.name]
1044
+ }
1045
+
1046
+ self[el]['toInteger'] = function() {
1047
+ var val = this.value
1048
+ , errors = self[this['name']]['errors'] || {}
1049
+ ;
1050
+
1051
+ if (!val) {
1052
+ return self[this.name]
1053
+ } else {
1054
+ try {
1055
+ //val = this.value = local.data[this.name] = ~~(val.match(/[0-9]+/g).join(''));
1056
+ val = this.value = local.data[this.name] = Math.round(val);
1057
+ } catch (err) {
1058
+
1059
+ errors['toInteger'] = replace(this.error || local.errorLabels['toInteger'], this);
1060
+ this.valid = false;
1061
+ if ( errors.count() > 0 )
1062
+ this['errors'] = errors;
1063
+ }
1064
+
1065
+ }
1066
+
1067
+ return self[this.name]
1068
+ }
1069
+
1070
+ self[el]['isInteger'] = function(minLength, maxLength) {
1071
+ var val = this.value
1072
+ , isValid = false
1073
+ , isMinLength = true
1074
+ , isMaxLength = true
1075
+ , errors = self[this['name']]['errors'] || {}
1076
+ ;
1077
+
1078
+ // test if val is a number
1079
+ if ( +val === +val && val % 1 === 0 ) {
1080
+ isValid = true;
1081
+ if ( !errors['isRequired'] && val != '' ) {
1082
+ // if so also test max and min length if defined
1083
+ if (minLength && typeof(minLength) == 'number' && val.length < minLength) {
1084
+ isMinLength = false;
1085
+ this['size'] = minLength;
1086
+ }
1087
+ if (maxLength && typeof(maxLength) == 'number' && val.length > maxLength) {
1088
+ isMaxLength = false;
1089
+ this['size'] = maxLength;
1090
+ }
1091
+ }
1092
+ }
1093
+ // if val is invalid return error message
1094
+ if ( !isValid || !isMinLength || !isMaxLength ) {
1095
+
1096
+ if ( !isValid )
1097
+ errors['isInteger'] = replace(this.error || local.errorLabels['isInteger'], this);
1098
+
1099
+ if ( !isMinLength || !isMaxLength ) {
1100
+
1101
+ if ( !isMinLength ) {
1102
+ errors['isIntegerLength'] = replace(this.error || local.errorLabels['isIntegerMinLength'], this);
1103
+ isValid = false;
1104
+ }
1105
+
1106
+ if ( !isMaxLength ) {
1107
+ errors['isIntegerLength'] = replace(this.error || local.errorLabels['isIntegerMaxLength'], this);
1108
+ isValid = false;
1109
+ }
1110
+
1111
+ if ( minLength === maxLength ) {
1112
+ errors['isIntegerLength'] = replace(this.error || local.errorLabels['isIntegerLength'], this);
1113
+ isValid = false;
1114
+ }
1115
+ }
1116
+ }
1117
+
1118
+ this.valid = isValid;
1119
+ val = this.value = local.data[this.name] = Number(val);
1120
+
1121
+ if ( errors.count() > 0 )
1122
+ this['errors'] = errors;
1123
+
1124
+ return self[this.name]
1125
+ }
1126
+
1127
+
1128
+ self[el]['toFloat'] = function(decimals) {
1129
+ if ( typeof(this.value) == 'string' ) {
1130
+ this.value = this.value.replace(/\s+/g, '');
1131
+ if ( /\,/.test(this.value) && !/\./.test(this.value) ) {
1132
+ this.value = this.value.replace(/\,/g,'.');
1133
+ //local.data[this.name] = this.value;
1134
+ // if (isGFFCtx) {
1135
+ // //this.target.setAttribute('value', this.value);
1136
+ // document.getElementById(this.target.id).value = this.value;
1137
+ // //triggerEvent(gina, this.target, 'change', self[this['name']]);
1138
+ // }
1139
+
1140
+ } else {
1141
+ this.value = this.value.replace(/\,/g,'');
1142
+ }
1143
+ }
1144
+
1145
+ var val = local.data[this.name] = this.value
1146
+ , errors = self[this['name']]['errors'] || {}
1147
+ , isValid = true
1148
+ ;
1149
+
1150
+ if (decimals) {
1151
+ this['decimals'] = parseInt(decimals)
1152
+ } else if ( typeof(this['decimals']) == 'undefined' ) {
1153
+ this['decimals'] = 2
1154
+ }
1155
+
1156
+ if (!val) {
1157
+ return self[this.name]
1158
+ } else {
1159
+ if ( this['isNumber']().valid ) {
1160
+ try {
1161
+
1162
+ if ( !Number.isFinite(val) ) {
1163
+ val = this.value = local.data[this.name] = new Number(parseFloat(val.match(/[0-9.,]+/g).join('').replace(/,/, '.')));// Number <> number
1164
+ }
1165
+ if (isGFFCtx)
1166
+ this.target.setAttribute('value', val);
1167
+ } catch(err) {
1168
+ isValid = false;
1169
+ errors['toFloat'] = replace(this.error || local.errorLabels['toFloat'], this);
1170
+ this.valid = false;
1171
+ if ( errors.count() > 0 )
1172
+ this['errors'] = errors;
1173
+ }
1174
+ } else {
1175
+ isValid = false;
1176
+ errors['toFloat'] = replace(this.error || local.errorLabels['toFloatNAN'], this)
1177
+ }
1178
+ }
1179
+
1180
+ if (this['decimals'] && val && !errors['toFloat']) {
1181
+ this.value = local.data[this.name] = parseFloat(this.value.toFixed(this['decimals']));
1182
+ }
1183
+
1184
+ this.valid = isValid;
1185
+ if ( errors.count() > 0 )
1186
+ this['errors'] = errors;
1187
+
1188
+ return self[this.name]
1189
+ }
1190
+
1191
+ /**
1192
+ * Check if value is float. No transformation is done here.
1193
+ * Can be used in combo preceded by *.toFloat(2) to transform data if needed:
1194
+ * 1 => 1.0
1195
+ * or
1196
+ * 3 500,5 => 3500.50
1197
+ *
1198
+ *
1199
+ * @param {number} [ decimals ]
1200
+ *
1201
+ * TODO - decimals transformation
1202
+ * */
1203
+ self[el]['isFloat'] = function(decimals) {
1204
+
1205
+ if ( typeof(this.value) == 'string' ) {
1206
+ this.value = this.value.replace(/\s+/g, '');
1207
+ }
1208
+
1209
+ var val = local.data[this.name] = this.value
1210
+ , isValid = false
1211
+ , errors = self[this['name']]['errors'] || {}
1212
+ ;
1213
+
1214
+
1215
+ if ( typeof(val) == 'string' && /\./.test(val) && Number.isFinite( Number(val) ) ) {
1216
+ isValid = true
1217
+ }
1218
+
1219
+ // if string replaces comas by points
1220
+ if (typeof(val) == 'string' && /,/g.test(val)) {
1221
+ val = this.value = local.data[this.name] = Number(val.replace(/,/g, '.'))
1222
+ }
1223
+
1224
+ // test if val is strictly a float
1225
+ if ( Number(val) === val && val % 1 !== 0 ) {
1226
+ this.value = local.data[this.name] = Number(val);
1227
+ isValid = true
1228
+ } else {
1229
+ isValid = false
1230
+ }
1231
+
1232
+ if ( !errors['isRequired'] && this.value == '' ) {
1233
+ isValid = true
1234
+ }
1235
+
1236
+ if (!isValid) {
1237
+ errors['isFloat'] = replace(this.error || local.errorLabels['isFloat'], this)
1238
+ }
1239
+
1240
+ this.valid = isValid;
1241
+ if ( errors.count() > 0 )
1242
+ this['errors'] = errors;
1243
+
1244
+ return self[this.name]
1245
+ }
1246
+
1247
+ self[el]['isRequired'] = function(isApplicable) {
1248
+
1249
+ if ( typeof(isApplicable) == 'boolean' && !isApplicable ) {
1250
+
1251
+ this.valid = true;
1252
+
1253
+ // is in excluded ?
1254
+ var excludedIndex = local.excluded.indexOf(this.name);
1255
+ if ( excludedIndex > -1 ) {
1256
+ local.excluded.splice(excludedIndex, 1);
1257
+ }
1258
+
1259
+ return self[this.name]
1260
+ }
1261
+
1262
+ // radio group case
1263
+ if (
1264
+ isGFFCtx
1265
+ && this.target
1266
+ && this.target.tagName == 'INPUT'
1267
+ && typeof(this.target.type) != 'undefined'
1268
+ && this.target.type == 'radio'
1269
+ ) {
1270
+ var radios = document.getElementsByName(this.name);
1271
+ for (var i = 0, len = radios.length; i < len; ++i) {
1272
+ if (radios[i].checked) {
1273
+ if ( /true|false/.test(radios[i].value) ) {
1274
+ this.value = local.data[this.name] = ( /true/.test(radios[i].value) ) ? true : false
1275
+ } else {
1276
+ this.value = local.data[this.name] = radios[i].value;
1277
+ }
1278
+
1279
+ this.valid = true;
1280
+ break;
1281
+ }
1282
+ }
1283
+ }
1284
+
1285
+
1286
+ var isValid = ( typeof(this.value) != 'undefined' && this.value != null && this.value != '' && !/^\s+/.test(this.value) ) ? true : false;
1287
+ var errors = self[this['name']]['errors'] || {};
1288
+
1289
+
1290
+ if (!isValid) {
1291
+ errors['isRequired'] = replace(this.error || local.errorLabels['isRequired'], this)
1292
+ }
1293
+ // if error tagged by a previous vlaidation, remove it when isValid == true
1294
+ else if ( isValid ) {
1295
+ if (typeof(errors['isRequired']) != 'undefined' )
1296
+ delete errors['isRequired'];
1297
+ //delete errors['stack'];
1298
+ // if ( typeof(self[this.name]['errors']) != 'undefined' && typeof(self[this.name]['errors']['isRequired']) != 'undefined' )
1299
+ // delete self[this.name]['errors']['isRequired'];
1300
+ }
1301
+
1302
+ this.valid = isValid;
1303
+ if (errors.count() > 0)
1304
+ this['errors'] = errors;
1305
+
1306
+ return self[this.name]
1307
+ }
1308
+ /**
1309
+ *
1310
+ * isString() -> validate if value is string
1311
+ * isString(10) -> validate if value is at least 10 chars length
1312
+ * isString(0, 45) -> no minimum length, but validate if value is maximum 45 chars length
1313
+ * NB.:
1314
+ * In your JSON rule ;
1315
+ * {
1316
+ * "password": {
1317
+ * "isRequired": true,
1318
+ *
1319
+ * "isString": true // Means that we just want a string and we don't care of its length
1320
+ * // OR
1321
+ * "isString": 7 // Means at least 7 chars length
1322
+ * // OR
1323
+ * "isString": [7, 40] // Means at least 7 chars length and maximum 40 chars length
1324
+ * // OR
1325
+ * "isString": [7] // Means is strickly equal to 7 chars length, same as [7,7]
1326
+ * }
1327
+ * }
1328
+ * @param {number|undefined} [ minLength ]
1329
+ * @param {number} [ maxLength ]
1330
+ * */
1331
+ self[el]['isString'] = function(minLength, maxLength) {
1332
+
1333
+ var val = local.data[this.name] = this.value
1334
+ , isValid = false
1335
+ , isMinLength = true
1336
+ , isMaxLength = true
1337
+ , errors = self[this['name']]['errors'] || {}
1338
+ ;
1339
+
1340
+
1341
+ // test if val is a string
1342
+ if ( typeof(val) == 'string' ) {
1343
+ //isValid = true;
1344
+
1345
+ if ( !errors['isRequired'] && val != '' ) {
1346
+ isValid = true;
1347
+ // if so also test max and min length if defined
1348
+ if (minLength && typeof(minLength) == 'number' && val.length < minLength) {
1349
+ isMinLength = false;
1350
+ this['size'] = minLength;
1351
+ }
1352
+ if (maxLength && typeof(maxLength) == 'number' && val.length > maxLength) {
1353
+ isMaxLength = false;
1354
+ this['size'] = maxLength;
1355
+ }
1356
+ }
1357
+
1358
+ }
1359
+
1360
+ // if val is invalid return error message
1361
+ if (!isValid || !isMinLength || !isMaxLength ) {
1362
+
1363
+ if (!isValid && errors['isRequired'] && val == '') {
1364
+ isValid = false;
1365
+ errors['isString'] = replace(this['error'] || local.errorLabels['isString'], this);
1366
+ } else if (!isValid && !errors['isRequired']) {
1367
+ isValid = true;
1368
+ }
1369
+
1370
+ if ( !isMinLength || !isMaxLength) {
1371
+ isValid = false;
1372
+
1373
+ if ( !isMinLength )
1374
+ errors['isStringLength'] = replace(this['error'] || local.errorLabels['isStringMinLength'], this);
1375
+ if ( !isMaxLength )
1376
+ errors['isStringLength'] = replace(this['error'] || local.errorLabels['isStringMaxLength'], this);
1377
+ if (minLength === maxLength)
1378
+ errors['isStringLength'] = replace(this['error'] || local.errorLabels['isStringLength'], this);
1379
+ }
1380
+
1381
+ }
1382
+
1383
+ this.valid = isValid;
1384
+ if ( errors.count() > 0 ) {
1385
+ this['errors'] = errors;
1386
+ }
1387
+
1388
+ return self[this.name]
1389
+ }
1390
+
1391
+ /**
1392
+ * Check if date
1393
+ *
1394
+ * @param {string|boolean} [mask] - by default "yyyy-mm-dd"
1395
+ *
1396
+ * @returns {date} date - extended by gina::utils::dateFormat; an adaptation of Steven Levithan's code
1397
+ * */
1398
+ self[el]['isDate'] = function(mask) {
1399
+ var val = this.value
1400
+ , isValid = false
1401
+ , errors = self[this['name']]['errors'] || {}
1402
+ , m = null
1403
+ , date = null
1404
+ ;
1405
+ // Default validation on livecheck & invalid init value
1406
+ if (!val || val == '' || /NaN|Invalid Date/i.test(val) ) {
1407
+ if ( /NaN|Invalid Date/i.test(val) ) {
1408
+ console.warn('[FormValidator::isDate] Provided value for field `'+ this.name +'` is not allowed: `'+ val +'`');
1409
+ errors['isDate'] = replace(this.error || local.errorLabels['isDate'], this);
1410
+
1411
+ }
1412
+ this.valid = isValid;
1413
+ if ( errors.count() > 0 )
1414
+ this['errors'] = errors;
1415
+
1416
+ return self[this.name];
1417
+ }
1418
+
1419
+ if (
1420
+ typeof(mask) == 'undefined'
1421
+ ||
1422
+ typeof(mask) != 'undefined' && /true/i.test(mask)
1423
+ ) {
1424
+ mask = "yyyy-mm-dd"; // by default
1425
+ }
1426
+
1427
+ if (val instanceof Date) {
1428
+ date = val.format(mask);
1429
+ } else {
1430
+
1431
+ try {
1432
+ m = mask.match(/[^\/\- ]+/g);
1433
+ } catch (err) {
1434
+ throw new Error('[FormValidator::isDate] Provided mask not allowed: `'+ mask +'`');
1435
+ }
1436
+
1437
+ try {
1438
+ val = val.match(/[^\/\- ]+/g);
1439
+ var dic = {}, d, len;
1440
+ for (d=0, len=m.length; d<len; ++d) {
1441
+ dic[m[d]] = val[d]
1442
+ }
1443
+ var formatedDate = mask;
1444
+ for (var v in dic) {
1445
+ formatedDate = formatedDate.replace(new RegExp(v, "g"), dic[v])
1446
+ }
1447
+ } catch (err) {
1448
+ throw new Error('[FormValidator::isDate] Provided value not allowed: `'+ val +'`' + err);
1449
+ }
1450
+
1451
+
1452
+ date = this.value = local.data[this.name] = new Date(formatedDate);
1453
+
1454
+ if ( /Invalid Date/i.test(date) || date instanceof Date === false ) {
1455
+ if ( !errors['isRequired'] && this.value == '' ) {
1456
+ isValid = true
1457
+ } else {
1458
+ errors['isDate'] = replace(this.error || local.errorLabels['isDate'], this);
1459
+ }
1460
+
1461
+ this.valid = isValid;
1462
+ if ( errors.count() > 0 )
1463
+ this['errors'] = errors;
1464
+
1465
+ return self[this.name]
1466
+ }
1467
+ isValid = true;
1468
+ }
1469
+
1470
+ this.valid = isValid;
1471
+
1472
+ return date
1473
+ }
1474
+
1475
+ /**
1476
+ * Formating date using DateFormatHelper
1477
+ * Check out documentation in the helper source: `utils/helpers/dateFormat.js`
1478
+ * e.g.:
1479
+ * d.start
1480
+ * .isDate('dd/mm/yyyy')
1481
+ * .format('isoDateTime');
1482
+ *
1483
+ *
1484
+ * */
1485
+ self[el]['format'] = function(mask, utc) {
1486
+ var val = this.value;
1487
+ if (!val) return self[this.name];
1488
+
1489
+ return val.format(mask, utc)
1490
+ };
1491
+
1492
+ /**
1493
+ * Set flash
1494
+ *
1495
+ * @param {str} flash
1496
+ * */
1497
+ self[el]['setFlash'] = function(regex, flash) {
1498
+ if ( typeof(flash) != 'undefined' && flash != '') {
1499
+ this.error = flash
1500
+ }
1501
+ return self[this.name]
1502
+ }
1503
+
1504
+ /**
1505
+ * Set label
1506
+ *
1507
+ * @param {str} label
1508
+ * */
1509
+ self[el]['setLabel'] = function(label) {
1510
+ if ( typeof(label) != 'undefined' && label != '') {
1511
+ this.label = label
1512
+ }
1513
+ return self[this.name]
1514
+ }
1515
+
1516
+ /**
1517
+ * Trim when string starts or ends with white space(s)
1518
+ *
1519
+ * @param {str} trimmed off string
1520
+ * */
1521
+ self[el]['trim'] = function(isApplicable) {
1522
+ if ( typeof(isApplicable) == 'boolean' && isApplicable ) {
1523
+ //if ( typeof(this.value) == 'string' ) {
1524
+ this.value = this.value.replace(/^\s+|\s+$/, '');
1525
+ local.data[this.name] = local.data[this.name] = this.value;
1526
+ //}
1527
+ return self[this.name]
1528
+ }
1529
+ }
1530
+
1531
+ /**
1532
+ * Exclude when converting back to datas
1533
+ *
1534
+ * @returns {object} data
1535
+ * */
1536
+ self[el]['exclude'] = function(isApplicable) {
1537
+
1538
+ if ( typeof(isApplicable) == 'boolean' && !isApplicable ) {
1539
+
1540
+ if ( /^true|false$/i.test(this.value)) {
1541
+ this.value = (/^true$/i.test(this.value)) ? true : false;
1542
+ local.data[this.name] = this.value;
1543
+ }
1544
+
1545
+ return self[this.name]
1546
+ }
1547
+ this.isExcluded = false;
1548
+ // list field to be purged
1549
+ if ( local.excluded.indexOf(this.name) < 0) {
1550
+ local.excluded.push(this.name);
1551
+ this.isExcluded = true;
1552
+ }
1553
+
1554
+
1555
+ // remove existing errors
1556
+ return self[this.name];
1557
+ }
1558
+ /**
1559
+ * Validation through API call
1560
+ * Try to put this rule at the end to prevent sending
1561
+ * a request to the remote host if previous rules failed
1562
+ */
1563
+ self[el]['query'] = query;
1564
+
1565
+
1566
+ self[el]['getValidationContext'] = function() {
1567
+ return {
1568
+ 'isGFFCtx' : isGFFCtx,
1569
+ 'self' : self,
1570
+ 'local' : local,
1571
+ 'replace' : replace
1572
+ }
1573
+ }
1574
+ // Merging user validators
1575
+ // To debug, open inspector and look into `Extra Scripts`
1576
+ if ( hasUserValidators() ) {
1577
+ var userValidator = null, filename = null;
1578
+ try {
1579
+ for (let v in gina.forms.validators) {
1580
+ filename = '/validators/'+ v + '/main.js';
1581
+ // setting default local error
1582
+ local.errorLabels[v] = 'Condition not satisfied';
1583
+ // converting Buffer to string
1584
+ if ( isGFFCtx ) {
1585
+ //userValidatorError = String.fromCharCode.apply(null, new Uint16Array(gina.forms.validators[v].data));
1586
+ userValidator = bufferToString(gina.forms.validators[v].data); // ok
1587
+ var passedContext = 'var validationContext = this.getValidationContext(),isGFFCtx = validationContext.isGFFCtx,self = validationContext.self,local = validationContext.local,replace = validationContext.replace;';
1588
+ userValidator = userValidator.replace(/(\)\s+\{|\)\{){1}/, '$&\n\t'+ passedContext);
1589
+
1590
+ //userValidator += '\n//#sourceURL='+ v +'.js';
1591
+ } else {
1592
+ userValidator = gina.forms.validators[v].toString();
1593
+ }
1594
+
1595
+ self[el][v] = eval('(' + userValidator + ')\n//# sourceURL='+ v +'.js');
1596
+ //self[el][v] = Function('errorMessage', 'errorStack', userValidator);
1597
+ }
1598
+ } catch (userValidatorError) {
1599
+ throw new Error('[UserFormValidator] Could not evaluate: `'+ filename +'`\n'+userValidatorError.stack);
1600
+ }
1601
+ }
1602
+ } // EO addField(el, value)
1603
+
1604
+
1605
+ for (let el in self) {
1606
+ // Adding fields & validators to context
1607
+ addField(el, self[el]);
1608
+ }
1609
+
1610
+ self['addField'] = function(el, value) {
1611
+ if ( typeof(self[el]) != 'undefined' ) {
1612
+ return
1613
+ }
1614
+ addField(el, value);
1615
+ };
1616
+
1617
+
1618
+ // self['getExcludedFields'] = function() {
1619
+ // return local.excluded;
1620
+ // };
1621
+
1622
+ /**
1623
+ * Check if errors found during validation
1624
+ *
1625
+ * @returns {boolean}
1626
+ * */
1627
+ self['isValid'] = function() {
1628
+ return (self['getErrors']().count() > 0) ? false : true;
1629
+ }
1630
+ self['setErrors'] = function(errors) {
1631
+ if (!errors) {
1632
+ return {}
1633
+ }
1634
+ for (var field in self) {
1635
+ if ( typeof(self[field]) != 'object' ) {
1636
+ continue
1637
+ }
1638
+ // if ( typeof(self[field]['errors']) == 'undefined' || self[field]['errors'].count() == 0 ) {
1639
+ // delete errors[field];
1640
+ // continue;
1641
+ // }
1642
+ // if ( typeof(errors[field]) == 'undefined' ) {
1643
+ // continue;
1644
+ // }
1645
+ for (var r in self[field]) {
1646
+ // no error for the current field rule
1647
+ if (
1648
+ typeof(errors[field]) != 'object'
1649
+ ||
1650
+ typeof(errors[field][r]) == 'undefined'
1651
+ ) {
1652
+ continue;
1653
+ }
1654
+
1655
+
1656
+ if (
1657
+ typeof(self[field].valid) != 'undefined'
1658
+ && /^true$/i.test(self[field].valid)
1659
+ ) {
1660
+ delete errors[field][r];
1661
+ continue;
1662
+ }
1663
+
1664
+
1665
+ if ( typeof( self[field]['errors']) == 'undefined' ) {
1666
+ self[field]['errors'] = {}
1667
+ }
1668
+
1669
+ self[field]['errors'][r] = errors[field][r];
1670
+ }
1671
+
1672
+ // if field does not have errors, remove errors[field]
1673
+ if (
1674
+ typeof(self[field]['errors']) == 'undefined'
1675
+ && typeof(errors[field]) != 'undefined'
1676
+ ||
1677
+ typeof(self[field]['errors']) != 'undefined'
1678
+ && self[field]['errors'].count() == 0
1679
+ && typeof(errors[field]) != 'undefined'
1680
+ ) {
1681
+ delete errors[field];
1682
+ continue;
1683
+ }
1684
+ }
1685
+ return errors;
1686
+ }
1687
+ /**
1688
+ * getErrors
1689
+ * NB.: This portion is shared between the front & the back
1690
+ *
1691
+ * @param {string} [fieldName]
1692
+ *
1693
+ * @returns errors
1694
+ */
1695
+ self['getErrors'] = function(fieldName) {
1696
+ var errors = {};
1697
+
1698
+ if ( typeof(fieldName) != 'undefined' ) {
1699
+ if ( typeof(self[fieldName]) != 'undefined' && self[fieldName] && typeof(self[fieldName]['errors']) != 'undefined' && self[fieldName]['errors'].count() > 0 ) {
1700
+ errors[fieldName] = self[fieldName]['errors'];
1701
+ }
1702
+ return errors
1703
+ }
1704
+
1705
+ for (var field in self) {
1706
+ if (
1707
+ typeof(self[field]) != 'object'
1708
+ ) {
1709
+ continue;
1710
+ }
1711
+
1712
+ if ( typeof(self[field]['errors']) != 'undefined' ) {
1713
+ if ( self[field]['errors'].count() > 0)
1714
+ errors[field] = self[field]['errors'];
1715
+ }
1716
+ }
1717
+
1718
+ return errors
1719
+ }
1720
+
1721
+ self['toData'] = function() {
1722
+
1723
+ // cleaning data
1724
+ if (local.excluded.length > 0) {
1725
+ for (var i = 0, len = local.excluded.length; i < len; ++i) {
1726
+ if ( typeof(local.data[ local.excluded[i] ]) != 'undefined' ) {
1727
+ delete local.data[ local.excluded[i] ]
1728
+ }
1729
+ }
1730
+ }
1731
+ // local.data = JSON.parse(JSON.stringify(local.data).replace(/\"(true|false)\"/gi, '$1'))
1732
+ return local.data
1733
+ }
1734
+
1735
+ /**@js_externs replace*/
1736
+ var replace = function(target, fieldObj) {
1737
+ var keys = target.match(/%[a-z]+/gi);
1738
+ if (keys) {
1739
+ for (var k = 0, len = keys.length; k < len; ++k) {
1740
+ target = target.replace(new RegExp(keys[k], 'g'), fieldObj[local.keys[keys[k]]])
1741
+ }
1742
+ }
1743
+
1744
+ return target
1745
+ }
1746
+
1747
+ self['setErrorLabels'] = function (errorLabels) {
1748
+ if ( typeof(errorLabels) != 'undefined') {
1749
+ local.errorLabels = merge(errorLabels, local.errorLabels)
1750
+ }
1751
+ }
1752
+
1753
+ return self
1754
+ };
1755
+
1756
+ if ( ( typeof(module) !== 'undefined' ) && module.exports ) {
1757
+ // Publish as node.js module
1758
+ module.exports = FormValidatorUtil
1759
+ } else if ( typeof(define) === 'function' && define.amd) {
1760
+ // Publish as AMD module
1761
+ define(function() { return FormValidatorUtil })
1762
+ }