wordjelly-auth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +35 -0
  5. data/app/assets/images/auth/activity.jpg +0 -0
  6. data/app/assets/images/auth/facebook.svg +1 -0
  7. data/app/assets/images/auth/google_oauth2.svg +1 -0
  8. data/app/assets/images/auth/js_pic3.jpg +0 -0
  9. data/app/assets/images/auth/profile.jpg +0 -0
  10. data/app/assets/javascripts/auth/admin_create_users.js +2 -0
  11. data/app/assets/javascripts/auth/application.js +20 -0
  12. data/app/assets/javascripts/auth/auth_dependencies.js +12 -0
  13. data/app/assets/javascripts/auth/auth_modals_and_navbar.js +218 -0
  14. data/app/assets/javascripts/auth/clients.js +2 -0
  15. data/app/assets/javascripts/auth/search.js +2 -0
  16. data/app/assets/javascripts/auth/shopping/discounts.js +2 -0
  17. data/app/assets/javascripts/auth/users/profiles.js +188 -0
  18. data/app/assets/stylesheets/auth/admin_create_users.css +4 -0
  19. data/app/assets/stylesheets/auth/application.scss +14 -0
  20. data/app/assets/stylesheets/auth/auth_default_css.scss +13 -0
  21. data/app/assets/stylesheets/auth/common-styles.scss +579 -0
  22. data/app/assets/stylesheets/auth/overrides.scss +26 -0
  23. data/app/assets/stylesheets/auth/search.css +4 -0
  24. data/app/assets/stylesheets/auth/shopping/discounts.css +4 -0
  25. data/app/assets/stylesheets/auth/users/profiles.scss +40 -0
  26. data/app/assets/stylesheets/scaffold.css +56 -0
  27. data/app/controllers/auth/admin_create_users_controller.rb +89 -0
  28. data/app/controllers/auth/application_controller.rb +97 -0
  29. data/app/controllers/auth/clients_controller.rb +105 -0
  30. data/app/controllers/auth/concerns/activity_controller_concern.rb +32 -0
  31. data/app/controllers/auth/concerns/devise_concern.rb +193 -0
  32. data/app/controllers/auth/concerns/omni_concern.rb +310 -0
  33. data/app/controllers/auth/concerns/otp_concern.rb +251 -0
  34. data/app/controllers/auth/concerns/shopping/cart_controller_concern.rb +105 -0
  35. data/app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb +150 -0
  36. data/app/controllers/auth/concerns/shopping/discount_controller_concern.rb +97 -0
  37. data/app/controllers/auth/concerns/shopping/pay_u_money_controller_concern.rb +38 -0
  38. data/app/controllers/auth/concerns/shopping/payment_controller_concern.rb +101 -0
  39. data/app/controllers/auth/concerns/shopping/product_controller_concern.rb +68 -0
  40. data/app/controllers/auth/concerns/token_concern.rb +187 -0
  41. data/app/controllers/auth/confirmations_controller.rb +3 -0
  42. data/app/controllers/auth/mailgun_controller.rb +8 -0
  43. data/app/controllers/auth/omniauth_callbacks_controller.rb +6 -0
  44. data/app/controllers/auth/passwords_controller.rb +4 -0
  45. data/app/controllers/auth/profiles_controller.rb +156 -0
  46. data/app/controllers/auth/registrations_controller.rb +99 -0
  47. data/app/controllers/auth/search_controller.rb +61 -0
  48. data/app/controllers/auth/sessions_controller.rb +20 -0
  49. data/app/controllers/auth/shopping/cart_items_controller.rb +14 -0
  50. data/app/controllers/auth/shopping/carts_controller.rb +13 -0
  51. data/app/controllers/auth/shopping/discounts_controller.rb +19 -0
  52. data/app/controllers/auth/shopping/payments_controller.rb +13 -0
  53. data/app/controllers/auth/shopping/products_controller.rb +17 -0
  54. data/app/controllers/auth/shopping/shopping_controller.rb +86 -0
  55. data/app/controllers/auth/unlocks_controller.rb +3 -0
  56. data/app/controllers/auth/webhooks_controller.rb +3 -0
  57. data/app/helpers/auth/admin_create_users_helper.rb +2 -0
  58. data/app/helpers/auth/application_helper.rb +136 -0
  59. data/app/helpers/auth/clients_helper.rb +4 -0
  60. data/app/helpers/auth/resource_helper.rb +10 -0
  61. data/app/helpers/auth/search_helper.rb +2 -0
  62. data/app/helpers/auth/shopping/cart_items/cart_items_helper.rb +29 -0
  63. data/app/helpers/auth/shopping/carts/carts_helper.rb +25 -0
  64. data/app/helpers/auth/shopping/discounts/discounts_helper.rb +39 -0
  65. data/app/helpers/auth/shopping/payments/pay_u_money_helper.rb +56 -0
  66. data/app/helpers/auth/shopping/payments/payments_helper.rb +54 -0
  67. data/app/helpers/auth/shopping/products/products_helper.rb +52 -0
  68. data/app/helpers/auth/shopping/shopping_helper.rb +3 -0
  69. data/app/helpers/auth/users/profiles_helper.rb +12 -0
  70. data/app/jobs/otp_job.rb +92 -0
  71. data/app/mailers/application_mailer.rb +4 -0
  72. data/app/mailers/auth/notifier.rb +9 -0
  73. data/app/models/auth/admin_create_user.rb +3 -0
  74. data/app/models/auth/client.rb +52 -0
  75. data/app/models/auth/concerns/activity_concern.rb +112 -0
  76. data/app/models/auth/concerns/chief_model_concern.rb +73 -0
  77. data/app/models/auth/concerns/es_concern.rb +21 -0
  78. data/app/models/auth/concerns/notification_concern.rb +232 -0
  79. data/app/models/auth/concerns/notification_response_concern.rb +71 -0
  80. data/app/models/auth/concerns/owner_concern.rb +81 -0
  81. data/app/models/auth/concerns/shopping/cart_concern.rb +329 -0
  82. data/app/models/auth/concerns/shopping/cart_item_concern.rb +437 -0
  83. data/app/models/auth/concerns/shopping/discount_concern.rb +482 -0
  84. data/app/models/auth/concerns/shopping/discount_flow.txt +11 -0
  85. data/app/models/auth/concerns/shopping/pay_u_money_concern.rb +184 -0
  86. data/app/models/auth/concerns/shopping/payment_concern.rb +613 -0
  87. data/app/models/auth/concerns/shopping/product_concern.rb +102 -0
  88. data/app/models/auth/concerns/sms_otp_concern.rb +68 -0
  89. data/app/models/auth/concerns/user_concern.rb +788 -0
  90. data/app/models/auth/identity.rb +23 -0
  91. data/app/models/auth/shopping/cart.rb +3 -0
  92. data/app/models/auth/shopping/cart_item.rb +6 -0
  93. data/app/models/auth/shopping/cart_item_payment_result.rb +7 -0
  94. data/app/models/auth/shopping/discount.rb +4 -0
  95. data/app/models/auth/shopping/payment.rb +5 -0
  96. data/app/models/auth/shopping/product.rb +5 -0
  97. data/app/models/auth/user.rb +3 -0
  98. data/app/views/auth/admin_create_users/_admin_actions.html.erb +46 -0
  99. data/app/views/auth/admin_create_users/_form.html.erb +19 -0
  100. data/app/views/auth/admin_create_users/edit.html.erb +6 -0
  101. data/app/views/auth/admin_create_users/index.html.erb +25 -0
  102. data/app/views/auth/admin_create_users/new.html.erb +5 -0
  103. data/app/views/auth/admin_create_users/show.html.erb +8 -0
  104. data/app/views/auth/clients/_form.html.erb +41 -0
  105. data/app/views/auth/clients/edit.html.erb +6 -0
  106. data/app/views/auth/clients/index.html.erb +33 -0
  107. data/app/views/auth/clients/new.html.erb +5 -0
  108. data/app/views/auth/clients/show.html.erb +21 -0
  109. data/app/views/auth/confirmations/_enter_otp.html.erb +27 -0
  110. data/app/views/auth/confirmations/_get_otp_status.html.erb +25 -0
  111. data/app/views/auth/confirmations/_new_otp_input.js.erb +11 -0
  112. data/app/views/auth/confirmations/_resend_otp.js.erb +8 -0
  113. data/app/views/auth/confirmations/_resend_sms_otp.html.erb +18 -0
  114. data/app/views/auth/confirmations/_verify_otp.js.erb +64 -0
  115. data/app/views/auth/confirmations/create.js.erb +8 -0
  116. data/app/views/auth/confirmations/enter_otp.html.erb +7 -0
  117. data/app/views/auth/confirmations/get_otp_status.html.erb +3 -0
  118. data/app/views/auth/confirmations/new.html.erb +1 -0
  119. data/app/views/auth/confirmations/new.js.erb +16 -0
  120. data/app/views/auth/confirmations/otp_status_result.html.erb +20 -0
  121. data/app/views/auth/mailer/confirmation_instructions.html.erb +5 -0
  122. data/app/views/auth/mailer/password_change.html.erb +3 -0
  123. data/app/views/auth/mailer/reset_password_instructions.html.erb +8 -0
  124. data/app/views/auth/mailer/unlock_instructions.html.erb +7 -0
  125. data/app/views/auth/modals/_ajax_error_modal.html.erb +3 -0
  126. data/app/views/auth/modals/_ajax_error_modal_content.html.erb +0 -0
  127. data/app/views/auth/modals/_edit_account_content.html.erb +68 -0
  128. data/app/views/auth/modals/_edit_account_success_content.html.erb +5 -0
  129. data/app/views/auth/modals/_error_notification.html.erb +8 -0
  130. data/app/views/auth/modals/_forgot_password_content.html.erb +18 -0
  131. data/app/views/auth/modals/_forgot_password_success_content.html.erb +8 -0
  132. data/app/views/auth/modals/_login_default_content.html.erb +3 -0
  133. data/app/views/auth/modals/_login_forms.html.erb +13 -0
  134. data/app/views/auth/modals/_login_navigation_options.html.erb +12 -0
  135. data/app/views/auth/modals/_new_otp_input.html.erb +28 -0
  136. data/app/views/auth/modals/_oauth_and_submit.html.erb +21 -0
  137. data/app/views/auth/modals/_recaptcha_tags.html.erb +4 -0
  138. data/app/views/auth/modals/_resend_confirmation_content.html.erb +17 -0
  139. data/app/views/auth/modals/_resend_confirmation_success_content.html.erb +8 -0
  140. data/app/views/auth/modals/_resend_otp.html.erb +23 -0
  141. data/app/views/auth/modals/_resource_errors.js.erb +24 -0
  142. data/app/views/auth/modals/_sign_in_inputs.html.erb +10 -0
  143. data/app/views/auth/modals/_sign_in_needed_modal.html.erb +3 -0
  144. data/app/views/auth/modals/_sign_in_success_content.html.erb +5 -0
  145. data/app/views/auth/modals/_sign_up_inputs.html.erb +9 -0
  146. data/app/views/auth/modals/_sign_up_success_content.html.erb +1 -0
  147. data/app/views/auth/modals/_sign_up_success_inactive_content.html.erb +2 -0
  148. data/app/views/auth/modals/_unlock_content.html.erb +17 -0
  149. data/app/views/auth/modals/_verify_otp.html.erb +1 -0
  150. data/app/views/auth/modals/base_modal/_base.html.erb +25 -0
  151. data/app/views/auth/modals/login.js.erb +120 -0
  152. data/app/views/auth/modals/unlock_success_content.html.erb +8 -0
  153. data/app/views/auth/notifier/_email.html.erb +3 -0
  154. data/app/views/auth/notifier/notification.html.erb +2 -0
  155. data/app/views/auth/notifier/notification.text.erb +1 -0
  156. data/app/views/auth/omniauth_callbacks/failure.html.erb +4 -0
  157. data/app/views/auth/passwords/create.js.erb +12 -0
  158. data/app/views/auth/passwords/edit.html.erb +25 -0
  159. data/app/views/auth/passwords/new.html.erb +16 -0
  160. data/app/views/auth/passwords/new.js.erb +19 -0
  161. data/app/views/auth/profiles/_proxy_resource.html.erb +5 -0
  162. data/app/views/auth/profiles/set_proxy_resource.js.erb +1 -0
  163. data/app/views/auth/profiles/show.html.erb +8 -0
  164. data/app/views/auth/registrations/create.js.erb +40 -0
  165. data/app/views/auth/registrations/edit.html.erb +2 -0
  166. data/app/views/auth/registrations/edit.js.erb +5 -0
  167. data/app/views/auth/registrations/new.html.erb +33 -0
  168. data/app/views/auth/registrations/update.js.erb +47 -0
  169. data/app/views/auth/search/_search_bar.html.erb +11 -0
  170. data/app/views/auth/search/_search_result.html.erb +7 -0
  171. data/app/views/auth/search/_search_results.html.erb +4 -0
  172. data/app/views/auth/search/authenticated_user_search.js.erb +45 -0
  173. data/app/views/auth/search/authenticated_user_search.json +7 -0
  174. data/app/views/auth/sessions/create.js.erb +5 -0
  175. data/app/views/auth/sessions/new.html.erb +4 -0
  176. data/app/views/auth/sessions/new.js.erb +20 -0
  177. data/app/views/auth/shared/_devise_error_messages.html.erb +9 -0
  178. data/app/views/auth/shared/_links.html.erb +25 -0
  179. data/app/views/auth/shared/_object_errors.html.erb +12 -0
  180. data/app/views/auth/shared/_proxy_resource.html.erb +18 -0
  181. data/app/views/auth/shopping/cart_items/_form.html.erb +34 -0
  182. data/app/views/auth/shopping/cart_items/_show_cart_items_collection.html.erb +31 -0
  183. data/app/views/auth/shopping/cart_items/create_multiple.html.erb +6 -0
  184. data/app/views/auth/shopping/cart_items/create_multiple.json.erb +9 -0
  185. data/app/views/auth/shopping/cart_items/edit.html.erb +6 -0
  186. data/app/views/auth/shopping/cart_items/index.html.erb +52 -0
  187. data/app/views/auth/shopping/cart_items/new.html.erb +5 -0
  188. data/app/views/auth/shopping/cart_items/show.html.erb +13 -0
  189. data/app/views/auth/shopping/carts/_form.html.erb +35 -0
  190. data/app/views/auth/shopping/carts/_payment_links.html.erb +27 -0
  191. data/app/views/auth/shopping/carts/_remove_cart_item.html.erb +11 -0
  192. data/app/views/auth/shopping/carts/_show_cart_balance_info.html.erb +35 -0
  193. data/app/views/auth/shopping/carts/edit.html.erb +6 -0
  194. data/app/views/auth/shopping/carts/index.html.erb +43 -0
  195. data/app/views/auth/shopping/carts/new.html.erb +5 -0
  196. data/app/views/auth/shopping/carts/show.html.erb +46 -0
  197. data/app/views/auth/shopping/discounts/_form.html.erb +18 -0
  198. data/app/views/auth/shopping/discounts/_form_for_create_multiple_cart_items.html.erb +17 -0
  199. data/app/views/auth/shopping/discounts/_show_pending_discount_request.html.erb +17 -0
  200. data/app/views/auth/shopping/discounts/destroy.html.erb +2 -0
  201. data/app/views/auth/shopping/discounts/edit.html.erb +29 -0
  202. data/app/views/auth/shopping/discounts/index.html.erb +40 -0
  203. data/app/views/auth/shopping/discounts/new.html.erb +1 -0
  204. data/app/views/auth/shopping/discounts/show.html.erb +18 -0
  205. data/app/views/auth/shopping/discounts/update.html.erb +2 -0
  206. data/app/views/auth/shopping/payments/_approve_payment.html.erb +7 -0
  207. data/app/views/auth/shopping/payments/_cash_card_cheque.html.erb +24 -0
  208. data/app/views/auth/shopping/payments/_create_discount_coupon.html.erb +5 -0
  209. data/app/views/auth/shopping/payments/_form.html.erb +19 -0
  210. data/app/views/auth/shopping/payments/_gateway.html.erb +21 -0
  211. data/app/views/auth/shopping/payments/_proceed_to_gateway_or_verify_payment.html.erb +18 -0
  212. data/app/views/auth/shopping/payments/_refresh_payment.html.erb +7 -0
  213. data/app/views/auth/shopping/payments/_refund.html.erb +10 -0
  214. data/app/views/auth/shopping/payments/_show_payment_receipt.html.erb +12 -0
  215. data/app/views/auth/shopping/payments/edit.html.erb +6 -0
  216. data/app/views/auth/shopping/payments/index.html.erb +43 -0
  217. data/app/views/auth/shopping/payments/new.html.erb +13 -0
  218. data/app/views/auth/shopping/payments/show.html.erb +36 -0
  219. data/app/views/auth/shopping/products/_form.html.erb +27 -0
  220. data/app/views/auth/shopping/products/edit.html.erb +6 -0
  221. data/app/views/auth/shopping/products/index.html.erb +48 -0
  222. data/app/views/auth/shopping/products/index.json.erb +7 -0
  223. data/app/views/auth/shopping/products/new.html.erb +5 -0
  224. data/app/views/auth/shopping/products/show.html.erb +12 -0
  225. data/app/views/auth/shopping/products/show.json.erb +1 -0
  226. data/app/views/auth/unlocks/create.js.erb +12 -0
  227. data/app/views/auth/unlocks/new.html.erb +14 -0
  228. data/app/views/auth/unlocks/new.js.erb +17 -0
  229. data/app/views/auth/users/_search_result.html.erb +8 -0
  230. data/app/views/auth/users/profiles/_user_data.html.erb +4 -0
  231. data/app/views/auth/users/profiles/show.html.erb +54 -0
  232. data/app/views/layouts/auth/_modals.html.erb +2 -0
  233. data/app/views/layouts/auth/application.html.erb +17 -0
  234. data/app/views/layouts/auth/navbar/_navbar.html.erb +49 -0
  235. data/app/views/layouts/auth/navbar/_personalization.html.erb +17 -0
  236. data/app/views/layouts/auth/navbar/_progress_spinner.html.erb +11 -0
  237. data/app/views/layouts/mailer.html.erb +5 -0
  238. data/app/views/layouts/mailer.text.erb +1 -0
  239. data/config/initializers/active_model.rb +36 -0
  240. data/config/initializers/devise.rb +623 -0
  241. data/config/initializers/json.rb +10 -0
  242. data/config/initializers/omniauth.rb +447 -0
  243. data/config/initializers/redis.rb +2 -0
  244. data/config/initializers/redis.yml +14 -0
  245. data/config/locales/devise.en.yml +63 -0
  246. data/config/routes.rb +1 -0
  247. data/lib/assets/javascripts/data.js +126 -0
  248. data/lib/assets/javascripts/jquery.calendario.js +394 -0
  249. data/lib/assets/javascripts/jquery.tagcloud.js +92 -0
  250. data/lib/assets/javascripts/leanModal.js +236 -0
  251. data/lib/assets/javascripts/main.js +668 -0
  252. data/lib/assets/javascripts/modernizr.custom.63321.js +4 -0
  253. data/lib/assets/javascripts/payumoney.js +9 -0
  254. data/lib/assets/javascripts/search.js +36 -0
  255. data/lib/assets/javascripts/spinner.js +77 -0
  256. data/lib/assets/javascripts/trianglify.min.js +2 -0
  257. data/lib/assets/javascripts/you_need_to_sign_in.js.erb +478 -0
  258. data/lib/assets/stylesheets/calendar.css +111 -0
  259. data/lib/assets/stylesheets/calendar_modifications.scss +276 -0
  260. data/lib/auth.rb +32 -0
  261. data/lib/auth/custom_failure.rb +3 -0
  262. data/lib/auth/engine.rb +231 -0
  263. data/lib/auth/job_exception_handler.rb +7 -0
  264. data/lib/auth/mailgun.rb +28 -0
  265. data/lib/auth/notify.rb +8 -0
  266. data/lib/auth/omniauth/path.rb +104 -0
  267. data/lib/auth/partials.rb +12 -0
  268. data/lib/auth/rails/routes.rb +169 -0
  269. data/lib/auth/search/main.rb +97 -0
  270. data/lib/auth/sidekiq_up.rb +16 -0
  271. data/lib/auth/two_factor_otp.rb +202 -0
  272. data/lib/auth/url_shortener.rb +29 -0
  273. data/lib/auth/version.rb +3 -0
  274. data/lib/tasks/auth_tasks.rake +4 -0
  275. metadata +863 -0
@@ -0,0 +1,92 @@
1
+ /*!
2
+ * jquery.tagcloud.js
3
+ * A Simple Tag Cloud Plugin for JQuery
4
+ *
5
+ * https://github.com/addywaddy/jquery.tagcloud.js
6
+ * created by Adam Groves
7
+ */
8
+ (function($) {
9
+
10
+ /*global jQuery*/
11
+ "use strict";
12
+
13
+ var compareWeights = function(a, b)
14
+ {
15
+ return a - b;
16
+ };
17
+
18
+ // Converts hex to an RGB array
19
+ var toRGB = function(code) {
20
+ if (code.length === 4) {
21
+ code = code.replace(/(\w)(\w)(\w)/gi, "\$1\$1\$2\$2\$3\$3");
22
+ }
23
+ var hex = /(\w{2})(\w{2})(\w{2})/.exec(code);
24
+ return [parseInt(hex[1], 16), parseInt(hex[2], 16), parseInt(hex[3], 16)];
25
+ };
26
+
27
+ // Converts an RGB array to hex
28
+ var toHex = function(ary) {
29
+ return "#" + jQuery.map(ary, function(i) {
30
+ var hex = i.toString(16);
31
+ hex = (hex.length === 1) ? "0" + hex : hex;
32
+ return hex;
33
+ }).join("");
34
+ };
35
+
36
+ var colorIncrement = function(color, range) {
37
+ return jQuery.map(toRGB(color.end), function(n, i) {
38
+ return (n - toRGB(color.start)[i])/range;
39
+ });
40
+ };
41
+
42
+ var tagColor = function(color, increment, weighting) {
43
+ var rgb = jQuery.map(toRGB(color.start), function(n, i) {
44
+ var ref = Math.round(n + (increment[i] * weighting));
45
+ if (ref > 255) {
46
+ ref = 255;
47
+ } else {
48
+ if (ref < 0) {
49
+ ref = 0;
50
+ }
51
+ }
52
+ return ref;
53
+ });
54
+ return toHex(rgb);
55
+ };
56
+
57
+ $.fn.tagcloud = function(options) {
58
+
59
+ var opts = $.extend({}, $.fn.tagcloud.defaults, options);
60
+ var tagWeights = this.map(function(){
61
+ return $(this).attr("rel");
62
+ });
63
+ tagWeights = jQuery.makeArray(tagWeights).sort(compareWeights);
64
+ var lowest = tagWeights[0];
65
+ var highest = tagWeights.pop();
66
+ var range = highest - lowest;
67
+ if(range === 0) {range = 1;}
68
+ // Sizes
69
+ var fontIncr, colorIncr;
70
+ if (opts.size) {
71
+ fontIncr = (opts.size.end - opts.size.start)/range;
72
+ }
73
+ // Colors
74
+ if (opts.color) {
75
+ colorIncr = colorIncrement (opts.color, range);
76
+ }
77
+ return this.each(function() {
78
+ var weighting = $(this).attr("rel") - lowest;
79
+ if (opts.size) {
80
+ $(this).css({"font-size": opts.size.start + (weighting * fontIncr) + opts.size.unit});
81
+ }
82
+ if (opts.color) {
83
+ $(this).css({"color": tagColor(opts.color, colorIncr, weighting)});
84
+ }
85
+ });
86
+ };
87
+
88
+ $.fn.tagcloud.defaults = {
89
+ size: {start: 14, end: 18, unit: "pt"}
90
+ };
91
+
92
+ })(jQuery);
@@ -0,0 +1,236 @@
1
+ /***
2
+ the materialize css
3
+ 'ready' callback -> after_open
4
+
5
+ the materialize css
6
+ 'complete' callback -> after_close
7
+
8
+ before_open -> fires before the modal even shows.
9
+
10
+ before_close -> fires before the close begins.
11
+ ***/
12
+ (function($){
13
+
14
+ var _stack = 0,
15
+ _lastID = 0,
16
+ _generateID = function() {
17
+ _lastID++;
18
+ return 'materialize-lean-overlay-' + _lastID;
19
+ };
20
+
21
+ $.fn.clear_modal_error_message = function(){
22
+ $(".modal").find(".error_notification").hide();
23
+ $(".modal").find(".error_message").html("");
24
+ }
25
+
26
+ $.fn.openModal = function(options){
27
+
28
+
29
+
30
+ var defaults = {
31
+ opacity: 0.5,
32
+ in_duration: 350,
33
+ out_duration: 250,
34
+ before_open: function(){return true},
35
+ after_open: function(){},
36
+ dismissible: true,
37
+ starting_top: '4%'
38
+ },
39
+ should_open = true;
40
+
41
+ // Override defaults
42
+ options = $.extend(defaults, options);
43
+
44
+ if(options.before_open != null && typeof(options.before_open === "function")){
45
+ should_open = options["before_open"](options);
46
+ }
47
+ /****
48
+ main funciton --------------starts----------------------
49
+ *****/
50
+ if(should_open){
51
+ $('body').css('overflow', 'hidden');
52
+
53
+
54
+ var overlayID = _generateID(),
55
+ $modal = $(this),
56
+
57
+ $overlay = $('<div class="lean-overlay"></div>'),
58
+ lStack = (++_stack);
59
+
60
+
61
+ // Store a reference of the overlay
62
+ $overlay.attr('id', overlayID).css('z-index', 1000 + lStack * 2);
63
+ $modal.data('overlay-id', overlayID).css('z-index', 1000 + lStack * 2 + 1);
64
+
65
+ $("body").append($overlay);
66
+
67
+
68
+
69
+ if (options.dismissible) {
70
+ $overlay.click(function() {
71
+ $modal.closeModal(options);
72
+ });
73
+ // Return on ESC
74
+ $(document).on('keyup.leanModal' + overlayID, function(e) {
75
+ if (e.keyCode === 27) { // ESC key
76
+ $modal.closeModal(options);
77
+ }
78
+ });
79
+ }
80
+
81
+ $modal.find(".modal-close").on('click.close', function(e) {
82
+ $modal.closeModal(options);
83
+ });
84
+
85
+ $overlay.css({ display : "block", opacity : 0 });
86
+
87
+ $modal.css({
88
+ display : "block",
89
+ opacity: 0
90
+ });
91
+
92
+
93
+ $overlay.velocity({opacity: options.opacity}, {duration: options.in_duration, queue: false, ease: "easeOutCubic"});
94
+
95
+
96
+ $modal.data('associated-overlay', $overlay[0]);
97
+
98
+ // Define Bottom Sheet animation
99
+ if ($modal.hasClass('bottom-sheet')) {
100
+ $modal.velocity({bottom: "0", opacity: 1}, {
101
+ duration: options.in_duration,
102
+ queue: false,
103
+ ease: "easeOutCubic",
104
+ // Handle modal ready callback
105
+ complete : function(){
106
+ if(options.after_open != null && typeof(options.after_open === "function")){
107
+ options["after_open"](options);
108
+ }
109
+ }
110
+ });
111
+
112
+ }
113
+ else {
114
+
115
+ $.Velocity.hook($modal, "scaleX", 0.7);
116
+ $modal.css({ top: options.starting_top });
117
+ $modal.velocity({top: "10%", opacity: 1, scaleX: '1'}, {
118
+ duration: options.in_duration,
119
+ queue: false,
120
+ ease: "easeOutCubic",
121
+ // Handle modal ready callback
122
+ complete : function(){
123
+ if(options.after_open != null && typeof(options.after_open === "function")){
124
+ options["after_open"](options);
125
+ }
126
+ }
127
+ });
128
+ }
129
+ }
130
+
131
+ };
132
+
133
+
134
+
135
+ $.fn.closeModal = function(options){
136
+
137
+
138
+ var defaults = {
139
+ out_duration: 250,
140
+ complete: undefined,
141
+ before_close: function(){return true},
142
+ after_close: function(){},
143
+ },
144
+
145
+ $modal = $(this),
146
+ overlayID = $modal.data('overlay-id'),
147
+ $overlay = $('#' + overlayID);
148
+
149
+
150
+
151
+
152
+ options = $.extend(defaults, options);
153
+
154
+ var should_close = true
155
+ if(options.before_close != null && typeof(options.before_close === "function")){
156
+ should_close = options["before_close"](options);
157
+ }
158
+
159
+
160
+ if(should_close){
161
+ // Disable scrolling
162
+ $('body').css('overflow', '');
163
+
164
+ $modal.find('.modal-close').off('click.close');
165
+ $(document).off('keyup.leanModal' + overlayID);
166
+
167
+ $overlay.velocity( { opacity: 0}, {duration: options.out_duration, queue: false, ease: "easeOutQuart"});
168
+
169
+
170
+ // Define Bottom Sheet animation
171
+ if ($modal.hasClass('bottom-sheet')) {
172
+ $modal.velocity({bottom: "-100%", opacity: 0}, {
173
+ duration: options.out_duration,
174
+ queue: false,
175
+ ease: "easeOutCubic",
176
+ // Handle modal ready callback
177
+
178
+ complete: function() {
179
+
180
+ $overlay.css({display:"none"});
181
+ $overlay.remove();
182
+ _stack--;
183
+ }
184
+ });
185
+ }
186
+ else {
187
+ $modal.velocity(
188
+ { top: options.starting_top, opacity: 0, scaleX: 0.7}, {
189
+ duration: options.out_duration,
190
+ complete: function() {
191
+ $(this).css('display', 'none');
192
+ // Call complete callback
193
+ if(options.after_close != null && typeof(options.after_close === "function")){
194
+ options["after_close"](options);
195
+ $modal.clear_modal_error_message();
196
+ }
197
+ $overlay.remove();
198
+ _stack--;
199
+ }
200
+ }
201
+ );
202
+ }
203
+
204
+ }
205
+ }
206
+
207
+
208
+
209
+
210
+ $.fn.leanModal = function(option){
211
+
212
+ return this.each(function() {
213
+
214
+ var defaults = {
215
+ starting_top: '4%'
216
+ },
217
+ // Override defaults
218
+ options = $.extend(defaults, option);
219
+ $(this).click(function(e) {
220
+
221
+ var modal_id = $(this).attr("href") || '#' + $(this).data('target');
222
+
223
+ if(!$(e.target).hasClass("modal-close") && typeof modal_id !== 'undefined' && modal_id != "#undefined"){
224
+ options.starting_top = ($(this).offset().top - $(window).scrollTop()) /1.15;
225
+ options.opener_element = $(this);
226
+ options.opener_id = $(this).attr("id");
227
+ options.event = e;
228
+
229
+ $(modal_id).openModal(options);
230
+ e.preventDefault();
231
+ }
232
+ }); // done set on click
233
+ }); // done return
234
+ }
235
+ }(jQuery));
236
+
@@ -0,0 +1,668 @@
1
+ /****
2
+ ARGUMENTS
3
+ {
4
+ form_id:{
5
+
6
+ field_id:{
7
+
8
+ validation_events: {"jquery_event" : true/false}
9
+
10
+ validate_with: {validator_name: arg,...more validators} / function
11
+
12
+ on_success: framework_name / function
13
+
14
+ on_failure: framework_name / function
15
+
16
+ do_before_validating: [list of ids to check if valid] / function
17
+
18
+ do_after_validating: [list of ids to enable if this one is valid] / function
19
+
20
+ },
21
+ ...more field ids
22
+ },
23
+ ....more form ids
24
+ }
25
+
26
+ ---------------------------------------
27
+
28
+ acceptable validator names for "validate_with"
29
+ ================================================
30
+
31
+ format: email
32
+
33
+ required:
34
+
35
+ min-length: length
36
+
37
+ remote-url: url
38
+
39
+ should_equal: id_of_other_element
40
+
41
+ ----------------------------------------
42
+
43
+ ****/
44
+ function WJ_Validator(args,css_framework,log){
45
+
46
+ this.args = args;
47
+ this.two_binding_fields = {};
48
+ this.log = log !== null ? log : true;
49
+ this.logger = {};
50
+ this.css_framework = css_framework;
51
+ /***
52
+ key -> field_id(without prefixed hash)
53
+ value -> form_id(without prefixed hash)
54
+ ***/
55
+ this.field_locs = {};
56
+
57
+
58
+
59
+ /****
60
+ defaults for field definitions.
61
+ ****/
62
+
63
+ this.validation_events_defaults = {
64
+ "focus" : true
65
+ };
66
+
67
+
68
+
69
+ var resolve_fields = function(def,e,field_object){
70
+ if("field_array" in def){
71
+ var arr = _(def["field_array"]).clone();
72
+ arr.push(e.target.id);
73
+ return arr;
74
+ }
75
+ else{
76
+ return [field_object["field_id"]];
77
+ }
78
+ }
79
+
80
+
81
+
82
+ /***
83
+ ****/
84
+ var hide_invalid_label = function(id){
85
+ var input = $("#" + id);
86
+ var label = input.parent().find("label");
87
+ label.attr("data-error","");
88
+ }
89
+
90
+ /***
91
+ here the event is always directly targeting the input field to be validated.
92
+ ***/
93
+ var hide_invalid_warning_on_bound_fields = function(e){
94
+ var form_id = $("#" + e.target.id).parents('form').get(0).id;
95
+ if(form_id){
96
+ for(f in args[form_id]){
97
+ _.each(args[form_id][f]["validate_with"],function(v){
98
+ if("field_array" in v){
99
+ if(f == e.target.id){
100
+
101
+ _.each(v["field_array"],function(b){
102
+ hide_invalid_label(b);
103
+ });
104
+ }
105
+ else if(_.contains(v["field_array"],e.target.id)){
106
+
107
+ hide_invalid_label(f);
108
+ }
109
+ }
110
+ });
111
+ };
112
+ }
113
+ }
114
+
115
+
116
+ /*****
117
+ the framework on_success and on_failure functions are passed the same
118
+ *****/
119
+ this.frameworks = {
120
+ "materialize":{
121
+ on_success: function(res){
122
+ _.each(resolve_fields(res["def"],res["event"],res["field_object"]),function(name){
123
+ var val = $("#" + name).val();
124
+ var type = $("#" + name).attr("type");
125
+ var label = $('label[for="'+ name +'"]');
126
+ var input = $('#' + name);
127
+ input.removeClass("invalid").addClass("valid");
128
+
129
+ });
130
+
131
+ },
132
+ on_failure: function(res){
133
+ _.each(resolve_fields(res["def"],res["event"],res["field_object"]),function(name){
134
+ var val = $("#" + name).val();
135
+ var type = $("#" + name).attr("type");
136
+ var label = $('label[for="'+ name +'"]');
137
+ var input = $('#' + name);
138
+ input.addClass("invalid");
139
+ input.attr("aria-invalid",true);
140
+ label.attr("data-error",res["failure_message"]);
141
+ })
142
+ },
143
+ on_load: function(){
144
+ $(document).on("focusout",":input",function(e){
145
+ if($(this).hasClass("invalid")){
146
+ var label = $(this).parent().find("label");
147
+ label.attr("data-error","");
148
+ hide_invalid_warning_on_bound_fields(e);
149
+ }
150
+ });
151
+ }
152
+ }
153
+ }
154
+
155
+ this.validate_with_defaults = {
156
+
157
+ };
158
+
159
+ /****
160
+ default on success function.
161
+ this function is called only when all the validators for a given field have passed.
162
+
163
+ ARGUMENTS:
164
+ ---------
165
+ e -> the event which triggered the validation
166
+
167
+ RETURNS:
168
+ --------
169
+ null
170
+
171
+ ****/
172
+ this.on_success_defaults = function(res){
173
+
174
+ if(css_framework !== null && (css_framework in _this.frameworks)){
175
+ _this.frameworks[css_framework]["on_success"](res);
176
+ }
177
+ };
178
+
179
+ /***
180
+ default on failure function.
181
+
182
+ ARGUMENTS:
183
+ ---------
184
+ def[Array] -> contains the validation defintion and failure messages, for each validator for the field.(includes failed and successfull validation results.)
185
+ e -> the event which triggered the validation.
186
+
187
+ RETURNs:
188
+ -----------
189
+ null.
190
+
191
+ ***/
192
+ this.on_failure_defaults = function(res){
193
+ if(css_framework !== null && (css_framework in _this.frameworks)){
194
+ _this.frameworks[css_framework]["on_failure"](res);
195
+ }
196
+ };
197
+
198
+ this.do_before_validating_defaults = {
199
+
200
+ };
201
+
202
+ this.do_after_validating_defaults = {
203
+
204
+ };
205
+
206
+ this.field_defaults = {
207
+ "validation_events" : this.validation_events_defaults,
208
+ "validate_with" : this.validate_with_defaults,
209
+ "on_success": this.on_success_defaults,
210
+ "on_failure": this.on_failure_defaults,
211
+ "do_before_validating" : this.do_before_validating_defaults,
212
+ "do_after_validating" : this.do_after_validating_defaults
213
+ };
214
+ /***
215
+ defaults end
216
+ ***/
217
+
218
+ var default_formats = {
219
+ email: /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
220
+ }
221
+
222
+ /****
223
+ ARGUMENTS FOR ANY VALIDATOR ARE THE SAME
224
+ def -> the validator defintion(should have a key->value(format -> email), and a key-value(failure_message -> message))
225
+ e -> the event which triggered the validation.
226
+
227
+ RETURN:
228
+ return true,or false.
229
+ *****/
230
+
231
+ this.validators = {
232
+ /***
233
+ @param[Object] def:
234
+ format => email/regex/function
235
+ failure_message => "whatever you want."
236
+ skip_empty => true/false, defaults to true.
237
+ args => arguments hash to pass to your custom function in case you are using one for the format.
238
+ @return[Deferred Object]
239
+ ***/
240
+ format: function(def,e,field_id){
241
+ var result = $.Deferred();
242
+ var field_value = get_field_attrs(field_id)["value"];
243
+ //HANDLE EMPTY FIELD.
244
+ if(!def["skip_empty"] && field_value.length == 0){
245
+
246
+ }
247
+ else if(field_value.length == 0){
248
+ result.resolve({"is_valid" : true});
249
+ }
250
+
251
+
252
+ if(def["format"] in default_formats){
253
+ //its a regex
254
+ //run it against the value of the field.
255
+ result.resolve({"is_valid" : default_formats[def["format"]].test(field_value)});
256
+ }
257
+ else if($.isFunction(def["format"])){
258
+ //its a function
259
+ //pass the field value insside.
260
+ result.resolve({"is_valid" : def["format"](def,e,field_id)});
261
+ }
262
+ else{
263
+ //trying to test something thats not in the default formats, and not a function, so returns invalid.
264
+ result.resolve({"is_valid" : false});
265
+ }
266
+ return result;
267
+ },
268
+ /***
269
+ @param[Object]:def
270
+ "required" => true/function
271
+ "failure_message" => whatever you want.
272
+ "args" => custom arguments hash to pass to your required function if you decide to use it.
273
+ @return[Deferred Object]
274
+ ***/
275
+ required: function(def,e,field_id){
276
+
277
+ var result = $.Deferred();
278
+ var field_value = get_field_attrs(field_id)["value"];
279
+
280
+ if($.isFunction(def["required"])){
281
+ result.resolve({"is_valid" : def["required"](def,e)});
282
+ }
283
+ result.resolve({"is_valid" : field_value.length > 0});
284
+ return result;
285
+ },
286
+ /****
287
+ @param[Object] def:
288
+ "remote" => true/function,
289
+ "ajax_settings" => function, the function accepts the def and the event.
290
+ "args" => custom arguments hash to pass to your "remote" function or to your ajax settings function.
291
+ @return[Promise object]
292
+ ****/
293
+ remote: function(def,e,field_id){
294
+
295
+ var result = $.Deferred();
296
+ if($.isFunction(def["remote"])){
297
+ return result.resolve({"is_valid" : def["remote"](def,e,field_id)});
298
+ }
299
+ var ajax_settings = def["ajax_settings"](def,e,field_id);
300
+ return $.ajax(ajax_settings);
301
+ },
302
+ min_length: function(def,e,field_id){
303
+ console.log("came to min length validator");
304
+ },
305
+ max_length: function(def,e,field_id){
306
+ console.log("came to max length validator");
307
+ },
308
+ /***
309
+ def ->
310
+ -should_be_equal => true/function
311
+ -field_array => [Array], array of field ids whose values should all be equal.
312
+ -args => object of arguments to pass to the custom function,
313
+ e ->
314
+ -the event.
315
+ ***/
316
+ should_be_equal: function(def,e,field_id){
317
+
318
+ var result = $.Deferred();
319
+
320
+ if($.isFunction(def["remote"])){
321
+ return result.resolve({"is_valid" : def["remote"](def,e,field_id)});
322
+ }
323
+ else{
324
+ if("field_array" in def){
325
+ var values_arr = _.map(def["field_array"],function(t){
326
+ return $("#" + t).val();
327
+ });
328
+ values_arr.push($("#" + field_id).val());
329
+ return result.resolve({"is_valid" : _.uniq(values_arr).length == 1});
330
+ }
331
+ else{
332
+ return result.resolve({"is_valid" : false});
333
+ }
334
+ }
335
+ }
336
+ }
337
+
338
+
339
+
340
+ /****
341
+ Arguments:
342
+ def -> the field definition from the validator settings.
343
+ @type: the type of the field "text,radio,checkbox,select"
344
+ @value: the value of the field
345
+ ****/
346
+ var get_field_attrs = function(field_id){
347
+ jquery_el = $("#" + field_id);
348
+ return {"type":jquery_el.attr('type'), "value" : jquery_el.val(), "name" : jquery_el.attr('name')};
349
+ }
350
+
351
+ this.is_valid = function(res){
352
+ var valid = false;
353
+ if(_.isArray(res)){
354
+ _.each(res,function(o){
355
+ if(_.isObject(o)){
356
+ if("is_valid" in o){
357
+ valid = o["is_valid"];
358
+ }
359
+ }
360
+ });
361
+
362
+ }
363
+ else{
364
+ valid = res["is_valid"];
365
+ }
366
+
367
+ return valid;
368
+ }
369
+
370
+ /***
371
+ e -> form submit event.
372
+ ***/
373
+ this.show_invalid_errors = function(deferred_arr,ret_val,e){
374
+ deferred_arr = _.flatten(deferred_arr);
375
+ var ret_val = true;
376
+ $.when.apply($,deferred_arr).done(function(){
377
+ var failed_ids = [];
378
+ var failures = _.filter(arguments,function(res,index){
379
+ if(!_this.is_valid(res)){
380
+ if(!(_.contains(failed_ids,deferred_arr[index]["event"].target.id))){
381
+
382
+ deferred_arr[index]["field_object"]["on_failure"]( deferred_arr[index]);
383
+ failed_ids.push(deferred_arr[index]["event"].target.id);
384
+ }
385
+ return true;
386
+ }
387
+ });
388
+ var success = _.each(arguments,function(res,index){
389
+ if(_this.is_valid(res) && (!(_.contains(failed_ids,deferred_arr[index]["event"].target.id)))){
390
+ deferred_arr[index]["field_object"]["on_success"](deferred_arr[index]);
391
+ }
392
+ });
393
+ if(_.size(failures) > 0)
394
+ {
395
+
396
+ }
397
+ else{
398
+ if(e){
399
+ console.log("triggering the resubmit");
400
+ $(e.target).trigger("submit",{});
401
+ }
402
+ }
403
+ });
404
+ }
405
+ this.register_handlers();
406
+ var _this = this;
407
+
408
+ }
409
+
410
+
411
+ /****
412
+ the event cannot be guarenteed to have been triggered on the field being validated
413
+ so it is necessary to pass the "field_id" as a part of the "def"
414
+ this is then used for all internal purposes
415
+ ****/
416
+
417
+ WJ_Validator.prototype = {
418
+ constructor: WJ_Validator,
419
+ default_failure_message: function(){
420
+ return "This field is invalid";
421
+ },
422
+ validation_could_not_be_done_message: function(){
423
+ return "server error";
424
+ },
425
+ register_handlers: function(){
426
+ /***
427
+ jquery_event => array_of_field_ids_to_watch_for_that_event
428
+ ***/
429
+ var event_handlers = {};
430
+ /***
431
+ structure like:
432
+ field_id => [[array_of_two_way_fields],validation_events_hash]
433
+ ***/
434
+ var _this = this;
435
+
436
+ _.each(Object.keys(_this.args),function(fo){
437
+
438
+ /***
439
+ the form hash.
440
+ ***/
441
+ var form_obj = _this.args[fo];
442
+
443
+ _.each(Object.keys(_this.args[fo]),function(f){
444
+
445
+
446
+ var field_id = "#" + f;
447
+ /***
448
+ correlate the field id with the form id
449
+ key -> field id
450
+ value -> form id
451
+ ***/
452
+ _this.field_locs[f] = fo;
453
+
454
+
455
+ /***
456
+ merge the defaults with the incoming field definition.
457
+ use jquery extend.
458
+ ***/
459
+ var field_obj = $.extend(true,{},_this.field_defaults,form_obj[f]);
460
+ //added field id to the field_object
461
+ field_obj["field_id"] = f;
462
+
463
+ //reassign the extended field object.
464
+ _this.args[fo][f] = field_obj;
465
+
466
+
467
+ for(jEvent in field_obj["validation_events"]){
468
+ if(jEvent in event_handlers){
469
+ event_handlers[jEvent].push(field_id);
470
+ }
471
+ else{
472
+ event_handlers[jEvent] = [field_id];
473
+ }
474
+ }
475
+
476
+
477
+ _.each(field_obj["validate_with"],function(r,i){
478
+ if("field_array" in r){
479
+ _this.two_binding_fields[f] = [field_obj["validate_with"][i]["field_array"],field_obj["validation_events"]];
480
+ }
481
+ });
482
+
483
+
484
+ });
485
+ });
486
+
487
+ this.field_locs = _this.field_locs;
488
+ this.args = _this.args;
489
+ this.two_binding_fields = _this.two_binding_fields;
490
+
491
+ /***
492
+ HERE THE FUNCTION RETURN VALUE CONSISTS OF THE EVENT, AND OUR CUSTOM RETURN VALUE.
493
+ THIS RETURN VALUE HAS BEEN SENT IN AT THE TIME OF THE TRIGGER FUNCTION.
494
+ the custom event is added here because we simulate custom event click in two way binding.
495
+ ***/
496
+
497
+ if(event_handlers != ""){
498
+ for(event in event_handlers){
499
+ _.each([event,"custom"],function(ev){
500
+ _.each(event_handlers[event],function(id){
501
+ //now bind if not bound.
502
+ if($(id + ":not(." + ev + "_bound)").length){
503
+ $(id).addClass(ev + "_bound");
504
+ $(id).on(ev,function(e,ret){
505
+
506
+ console.log("the ret is:" + ret);
507
+ if(ret){
508
+ console.log("got the ret");
509
+ //this happens at the time of submitting the form, when we want to collect the responses of all the validations.
510
+ ret[e.target.id] = _this.main(e);
511
+ }
512
+ else{
513
+ //this happens during the routine individual field validation
514
+ _this.show_invalid_errors(_this.main(e),null,null);
515
+ }
516
+ });
517
+ }
518
+ });
519
+ });
520
+ }
521
+ }
522
+
523
+
524
+
525
+ /***
526
+ THIS DEALS WITH THE FIELDS WHICH ARE LINKED TO EACH OTHER WHILE VALIDATION.
527
+ FOR EG: PASSWORD AND CONFIRM_PASSWORD WHICH MUST MATCH
528
+ what event should be used for two-way-binding-fields.
529
+ whatever is the event for the root field.
530
+ pick those key-value pairs from the validation event which are true, and then take only those keys and join by space
531
+ ***/
532
+ for(ff in _this.two_binding_fields){
533
+ $(document).on(Object.keys(_.pick(_this.two_binding_fields[ff][1],function(value,key,object){
534
+ return value == true
535
+ })).join(" "),_.map(_this.two_binding_fields[ff][0],function(n){return "#" + n;}).join(","),function(e){
536
+ $("#"+ff).trigger("custom");
537
+ });
538
+ }
539
+
540
+ /****
541
+ form triggers
542
+ ****/
543
+
544
+ /***
545
+ on submitting the form, trigger the custom event on each field of the form object.
546
+ WORKING:
547
+ on form submit, all the validations should be fired again.
548
+ so for this purpose we bind the "submit" event on each form object to the following behaviour.
549
+ while binding, we also expect a variable called "ret" to be passed in while the submit action is triggered.
550
+ this variable is
551
+ ***/
552
+ _.each(Object.keys(_this.args),function(fo){
553
+
554
+ //if the form has remote true, then bind only ajax:before
555
+ //otherwise bind only submit.
556
+ var event_name = "submit";
557
+ if($("#" + fo).attr("data-remote")){
558
+ event_name = "ajax:before";
559
+ }
560
+
561
+ var id = "#" + fo;
562
+ var bound_class = ":not(.submit_bound)";
563
+
564
+
565
+ if($(id + bound_class).length){
566
+
567
+ $("#" + fo).addClass("submit_bound");
568
+ $("#" + fo).on(event_name,function(e,ret){
569
+ console.log("inside submit and ret is: " + ret);
570
+ if(!ret)
571
+ {
572
+
573
+ results = [];
574
+ _.each(Object.keys(_this.args[fo]),function(f){
575
+ //these are the field ids.
576
+ //this will run the validations on that field.
577
+ results.push(_this.main(e,_this.args[fo][f]));
578
+
579
+ });
580
+ e.preventDefault();
581
+ e.stopPropagation();
582
+ _this.show_invalid_errors(results,true,e);
583
+
584
+ return false;
585
+ }
586
+
587
+ });
588
+ }
589
+ });
590
+
591
+
592
+ //if the frameworks have any specific things to be done on load, then do it here.
593
+ this.frameworks[this.css_framework]["on_load"]();
594
+
595
+ },
596
+ /****
597
+ given the field_id get its definition from the form definition.
598
+ ****/
599
+ get_field_object: function(field_id){
600
+ return this.args[this.field_locs[field_id]][field_id];
601
+ },
602
+ /***
603
+ @param[e] : the event that precipitates the validation
604
+ @param[field_object] : the definition for the field validation provided in the validator settings.
605
+ - if the field object is not provided, then the event must be triggered from the field that is to be validated, because it uses the event to get the field id, and then the field object.
606
+ returns array of deferred objects.
607
+ ***/
608
+ main: function(e,field_object){
609
+
610
+ var fo = null;
611
+ if(_.isUndefined(field_object)){
612
+
613
+ fo = this.get_field_object(e.target.id);
614
+ }
615
+ else{
616
+ fo = field_object;
617
+ }
618
+ try{
619
+ return this.validate_with(fo,e);
620
+ }
621
+ catch(err){
622
+ console.log(err);
623
+ return null;
624
+ }
625
+ },
626
+ /****
627
+ basically calls each validator specified and returns true or false
628
+ finally returns true if all are true, otherwise false.
629
+ ****/
630
+ validate_with: function(field_object,e){
631
+
632
+ var deferred_results = [];
633
+ var _this = this;
634
+ _.each(field_object["validate_with"],function(def){
635
+ var validation_kv = _.pick(def, function(value, key, object) {
636
+ return key in _this.validators;
637
+ });
638
+
639
+ if(_.isEmpty(validation_kv)){
640
+
641
+ validation_kv = _.pick(def, function(value, key, object) {
642
+ return $.isFunction(value);
643
+ });
644
+ }
645
+
646
+ _.each(Object.keys(validation_kv),function(v){
647
+ var is_valid = null;
648
+ if(v in _this.validators){
649
+ is_valid = _this.validators[v](def,e,field_object["field_id"]);
650
+ }
651
+ else if($.isFunction(def[v])){
652
+ is_valid = def[v](def,e,field_object["field_id"]);
653
+ }
654
+ if(is_valid!== null){
655
+ var failure_message = def["failure_message"] ? def["failure_message"] : _this.default_failure_message;
656
+ is_valid.fail(function(d){
657
+ failure_message = _this.validation_could_not_be_done_message;
658
+ });
659
+ var g = $.extend({},is_valid,{"failure_message" : failure_message, "field_object" : field_object, "event": e, "def" : def});
660
+ deferred_results.push(g);
661
+ }
662
+ });
663
+ });
664
+
665
+ return deferred_results;
666
+ }
667
+
668
+ }