maily_herald-webui 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +5 -0
  4. data/Gemfile +15 -0
  5. data/Gemfile.lock +250 -0
  6. data/Guardfile +23 -0
  7. data/LICENSE +11 -0
  8. data/README.md +62 -0
  9. data/Rakefile +30 -0
  10. data/app/assets/images/maily_herald/.gitkeep +0 -0
  11. data/app/assets/images/maily_herald/webui/arrow-bottom.png +0 -0
  12. data/app/assets/images/maily_herald/webui/arrow-left.png +0 -0
  13. data/app/assets/images/maily_herald/webui/arrow-right.png +0 -0
  14. data/app/assets/images/maily_herald/webui/arrow-top.png +0 -0
  15. data/app/assets/images/maily_herald/webui/logo.svg +38 -0
  16. data/app/assets/images/maily_herald/webui/sprite-dropdown.png +0 -0
  17. data/app/assets/images/maily_herald/webui/sprite-form.png +0 -0
  18. data/app/assets/images/maily_herald/webui/sprite.png +0 -0
  19. data/app/assets/images/maily_herald/webui/user.png +0 -0
  20. data/app/assets/javascripts/maily_herald/webui/application.js +20 -0
  21. data/app/assets/javascripts/maily_herald/webui/dispatches.coffee +58 -0
  22. data/app/assets/javascripts/maily_herald/webui/webui.coffee +209 -0
  23. data/app/assets/stylesheets/maily_herald/webui/application.css +18 -0
  24. data/app/assets/stylesheets/maily_herald/webui/webui-bootstrap.scss +0 -0
  25. data/app/assets/stylesheets/maily_herald/webui/webui.sass +846 -0
  26. data/app/controllers/maily_herald/webui/application_controller.rb +19 -0
  27. data/app/controllers/maily_herald/webui/dashboard_controller.rb +65 -0
  28. data/app/controllers/maily_herald/webui/dispatches_controller.rb +42 -0
  29. data/app/controllers/maily_herald/webui/lists_controller.rb +69 -0
  30. data/app/controllers/maily_herald/webui/logs_controller.rb +20 -0
  31. data/app/controllers/maily_herald/webui/mailings_controller.rb +68 -0
  32. data/app/controllers/maily_herald/webui/one_time_mailings_controller.rb +32 -0
  33. data/app/controllers/maily_herald/webui/periodical_mailings_controller.rb +25 -0
  34. data/app/controllers/maily_herald/webui/resources_controller.rb +144 -0
  35. data/app/controllers/maily_herald/webui/sequence_mailings_controller.rb +43 -0
  36. data/app/controllers/maily_herald/webui/sequences_controller.rb +56 -0
  37. data/app/controllers/maily_herald/webui/sessions_controller.rb +11 -0
  38. data/app/controllers/maily_herald/webui/subscriptions_controller.rb +33 -0
  39. data/app/helpers/maily_herald/webui/application_helper.rb +157 -0
  40. data/app/helpers/maily_herald/webui/dispatches_helper.rb +18 -0
  41. data/app/helpers/maily_herald/webui/logs_helper.rb +37 -0
  42. data/app/helpers/maily_herald/webui/mailings_helper.rb +64 -0
  43. data/app/helpers/maily_herald/webui/sequence_mailings_helper.rb +13 -0
  44. data/app/helpers/maily_herald/webui/sequences_helper.rb +6 -0
  45. data/app/helpers/maily_herald/webui/subscribers_helper.rb +25 -0
  46. data/app/helpers/maily_herald/webui/subscriptions_helper.rb +11 -0
  47. data/app/helpers/maily_herald_helper.rb +151 -0
  48. data/app/views/layouts/maily_herald/webui/application.html.haml +58 -0
  49. data/app/views/layouts/maily_herald/webui/modal.html.haml +6 -0
  50. data/app/views/maily_herald/webui/dashboard/_log.html.haml +20 -0
  51. data/app/views/maily_herald/webui/dashboard/_log_list.html.haml +19 -0
  52. data/app/views/maily_herald/webui/dashboard/_logs.html.haml +15 -0
  53. data/app/views/maily_herald/webui/dashboard/index.html.haml +43 -0
  54. data/app/views/maily_herald/webui/dashboard/index.js.erb +15 -0
  55. data/app/views/maily_herald/webui/dispatches/_entities.html.haml +7 -0
  56. data/app/views/maily_herald/webui/dispatches/_logs.html.haml +4 -0
  57. data/app/views/maily_herald/webui/dispatches/_schedules.html.haml +4 -0
  58. data/app/views/maily_herald/webui/dispatches/_toggle.js.erb +1 -0
  59. data/app/views/maily_herald/webui/lists/_details.html.haml +14 -0
  60. data/app/views/maily_herald/webui/lists/_details_form.html.haml +14 -0
  61. data/app/views/maily_herald/webui/lists/_form.html.haml +1 -0
  62. data/app/views/maily_herald/webui/lists/_header.html.haml +13 -0
  63. data/app/views/maily_herald/webui/lists/_items.html.haml +24 -0
  64. data/app/views/maily_herald/webui/lists/_opt_outs.html.haml +7 -0
  65. data/app/views/maily_herald/webui/lists/_potential_subscribers.html.haml +7 -0
  66. data/app/views/maily_herald/webui/lists/_subscribers.html.haml +7 -0
  67. data/app/views/maily_herald/webui/lists/context_variables.html.haml +15 -0
  68. data/app/views/maily_herald/webui/lists/subscribe.js.erb +10 -0
  69. data/app/views/maily_herald/webui/lists/unsubscribe.js.erb +7 -0
  70. data/app/views/maily_herald/webui/logs/_items.html.haml +34 -0
  71. data/app/views/maily_herald/webui/logs/preview.html.haml +22 -0
  72. data/app/views/maily_herald/webui/mailings-old/_entity.html.haml +17 -0
  73. data/app/views/maily_herald/webui/mailings-old/_entity_list.html.haml +26 -0
  74. data/app/views/maily_herald/webui/mailings-old/_form.html.haml +32 -0
  75. data/app/views/maily_herald/webui/mailings-old/_print.html.haml +123 -0
  76. data/app/views/maily_herald/webui/mailings-old/create.js.erb +1 -0
  77. data/app/views/maily_herald/webui/mailings-old/destroy.js.erb +1 -0
  78. data/app/views/maily_herald/webui/mailings-old/edit.html.haml +16 -0
  79. data/app/views/maily_herald/webui/mailings-old/edit.js.erb +2 -0
  80. data/app/views/maily_herald/webui/mailings-old/index.html.haml +9 -0
  81. data/app/views/maily_herald/webui/mailings-old/index.js.erb +1 -0
  82. data/app/views/maily_herald/webui/mailings-old/new.html.haml +16 -0
  83. data/app/views/maily_herald/webui/mailings-old/new.js.erb +1 -0
  84. data/app/views/maily_herald/webui/mailings-old/preview.js.erb +2 -0
  85. data/app/views/maily_herald/webui/mailings-old/refresh_list.js.erb +1 -0
  86. data/app/views/maily_herald/webui/mailings-old/show.html.haml +135 -0
  87. data/app/views/maily_herald/webui/mailings-old/show.js.erb +1 -0
  88. data/app/views/maily_herald/webui/mailings-old/update.js.erb +1 -0
  89. data/app/views/maily_herald/webui/mailings/_deliver.js.erb +1 -0
  90. data/app/views/maily_herald/webui/mailings/_details.html.haml +65 -0
  91. data/app/views/maily_herald/webui/mailings/_details_form.html.haml +39 -0
  92. data/app/views/maily_herald/webui/mailings/_form.html.haml +1 -0
  93. data/app/views/maily_herald/webui/mailings/_form_periodical.html.haml +2 -0
  94. data/app/views/maily_herald/webui/mailings/_form_sequence.html.haml +1 -0
  95. data/app/views/maily_herald/webui/mailings/_form_template_generic.html.haml +7 -0
  96. data/app/views/maily_herald/webui/mailings/_form_template_mailer.html.haml +4 -0
  97. data/app/views/maily_herald/webui/mailings/_header.html.haml +24 -0
  98. data/app/views/maily_herald/webui/mailings/_list.html.haml +27 -0
  99. data/app/views/maily_herald/webui/mailings/_template.html.haml +16 -0
  100. data/app/views/maily_herald/webui/mailings/_template_form.html.haml +7 -0
  101. data/app/views/maily_herald/webui/mailings/nav_secondary/_index.html.haml +3 -0
  102. data/app/views/maily_herald/webui/mailings/preview.html.haml +13 -0
  103. data/app/views/maily_herald/webui/mailings/update_form.js.erb +33 -0
  104. data/app/views/maily_herald/webui/resources/edit.js.erb +2 -0
  105. data/app/views/maily_herald/webui/resources/index.html.haml +11 -0
  106. data/app/views/maily_herald/webui/resources/index.js.erb +1 -0
  107. data/app/views/maily_herald/webui/resources/new.html.haml +5 -0
  108. data/app/views/maily_herald/webui/resources/show.html.haml +4 -0
  109. data/app/views/maily_herald/webui/resources/show.js.erb +3 -0
  110. data/app/views/maily_herald/webui/resources/update.js.erb +18 -0
  111. data/app/views/maily_herald/webui/sequences-old/_entity.html.haml +11 -0
  112. data/app/views/maily_herald/webui/sequences-old/_entity_list.html.haml +23 -0
  113. data/app/views/maily_herald/webui/sequences-old/_form.html.haml +17 -0
  114. data/app/views/maily_herald/webui/sequences-old/_log.html.haml +7 -0
  115. data/app/views/maily_herald/webui/sequences-old/_logs.html.haml +16 -0
  116. data/app/views/maily_herald/webui/sequences-old/_mailing.html.haml +4 -0
  117. data/app/views/maily_herald/webui/sequences-old/_mailing_list.html.haml +19 -0
  118. data/app/views/maily_herald/webui/sequences-old/edit.html.haml +14 -0
  119. data/app/views/maily_herald/webui/sequences-old/new.html.haml +13 -0
  120. data/app/views/maily_herald/webui/sequences-old/show.html.haml +122 -0
  121. data/app/views/maily_herald/webui/sequences-old/show.js.erb +2 -0
  122. data/app/views/maily_herald/webui/sequences-old/subscription.html.haml +79 -0
  123. data/app/views/maily_herald/webui/sequences/_details.html.haml +39 -0
  124. data/app/views/maily_herald/webui/sequences/_details_form.html.haml +27 -0
  125. data/app/views/maily_herald/webui/sequences/_form.html.haml +1 -0
  126. data/app/views/maily_herald/webui/sequences/_header.html.haml +11 -0
  127. data/app/views/maily_herald/webui/sequences/_list.html.haml +21 -0
  128. data/app/views/maily_herald/webui/sequences/_mailing_list.html.haml +21 -0
  129. data/app/views/maily_herald/webui/sequences/_mailings.html.haml +7 -0
  130. data/app/views/maily_herald/webui/sequences/update_form.js.erb +14 -0
  131. data/app/views/maily_herald/webui/shared/_context_attributes.html.haml +11 -0
  132. data/app/views/maily_herald/webui/subscribers/_item.html.haml +8 -0
  133. data/app/views/maily_herald/webui/subscribers/_list.html.haml +18 -0
  134. data/app/views/maily_herald/webui/subscription_groups/_form.html.haml +5 -0
  135. data/app/views/maily_herald/webui/subscription_groups/_subscription.html.haml +8 -0
  136. data/app/views/maily_herald/webui/subscription_groups/_subscription_list.html.haml +19 -0
  137. data/app/views/maily_herald/webui/subscription_groups/edit.html.haml +16 -0
  138. data/app/views/maily_herald/webui/subscription_groups/index.html.haml +35 -0
  139. data/app/views/maily_herald/webui/subscription_groups/new.html.haml +11 -0
  140. data/app/views/maily_herald/webui/subscription_groups/show.html.haml +42 -0
  141. data/app/views/maily_herald/webui/subscription_groups/show.js.erb +1 -0
  142. data/app/views/maily_herald/webui/subscriptions/show.html.haml +21 -0
  143. data/app/views/maily_herald/webui/subscriptions/toggle.js.erb +1 -0
  144. data/app/views/maily_herald/webui/webui/index.html.haml +136 -0
  145. data/app/views/maily_herald/webui/webui/show.html.haml +0 -0
  146. data/config/database.yml +5 -0
  147. data/config/initializers/smart_listing.rb +77 -0
  148. data/config/locales/en.yml +237 -0
  149. data/config/routes.rb +103 -0
  150. data/config/spring.rb +1 -0
  151. data/lib/maily_herald/webui.rb +15 -0
  152. data/lib/maily_herald/webui/breadcrumbs.rb +50 -0
  153. data/lib/maily_herald/webui/engine.rb +18 -0
  154. data/lib/maily_herald/webui/form_builder.rb +285 -0
  155. data/lib/maily_herald/webui/menu_manager.rb +66 -0
  156. data/lib/maily_herald/webui/version.rb +5 -0
  157. data/maily_herald-webui.gemspec +40 -0
  158. data/script/rails +8 -0
  159. data/spec/dummy/Guardfile +35 -0
  160. data/spec/dummy/README.rdoc +261 -0
  161. data/spec/dummy/Rakefile +7 -0
  162. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  163. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  164. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  165. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  166. data/spec/dummy/app/mailers/.gitkeep +0 -0
  167. data/spec/dummy/app/mailers/test_mailer.rb +11 -0
  168. data/spec/dummy/app/models/.gitkeep +0 -0
  169. data/spec/dummy/app/models/user.rb +7 -0
  170. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  171. data/spec/dummy/app/views/test_mailer/sample_mail.text.erb +1 -0
  172. data/spec/dummy/bin/rails +10 -0
  173. data/spec/dummy/bin/rake +7 -0
  174. data/spec/dummy/bin/rspec +7 -0
  175. data/spec/dummy/bin/spring +18 -0
  176. data/spec/dummy/config.ru +4 -0
  177. data/spec/dummy/config/application.rb +65 -0
  178. data/spec/dummy/config/boot.rb +10 -0
  179. data/spec/dummy/config/database.yml +25 -0
  180. data/spec/dummy/config/environment.rb +5 -0
  181. data/spec/dummy/config/environments/development.rb +38 -0
  182. data/spec/dummy/config/environments/production.rb +67 -0
  183. data/spec/dummy/config/environments/test.rb +37 -0
  184. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  185. data/spec/dummy/config/initializers/inflections.rb +15 -0
  186. data/spec/dummy/config/initializers/maily_herald.rb +101 -0
  187. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  188. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  189. data/spec/dummy/config/initializers/session_store.rb +8 -0
  190. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  191. data/spec/dummy/config/locales/en.yml +5 -0
  192. data/spec/dummy/config/locales/maily_herald.en.yml +28 -0
  193. data/spec/dummy/config/routes.rb +4 -0
  194. data/spec/dummy/db/migrate/20130723074347_create_users.rb +11 -0
  195. data/spec/dummy/db/migrate/20140804152249_create_maily_herald_tables.maily_herald.rb +68 -0
  196. data/spec/dummy/db/migrate/20140804152250_create_lists.maily_herald.rb +33 -0
  197. data/spec/dummy/db/schema.rb +79 -0
  198. data/spec/dummy/lib/assets/.gitkeep +0 -0
  199. data/spec/dummy/lib/tasks/dummy.rb +8 -0
  200. data/spec/dummy/log/.gitkeep +0 -0
  201. data/spec/dummy/public/404.html +26 -0
  202. data/spec/dummy/public/422.html +26 -0
  203. data/spec/dummy/public/500.html +25 -0
  204. data/spec/dummy/public/favicon.ico +0 -0
  205. data/spec/dummy/script/rails +6 -0
  206. data/spec/spec_helper.rb +46 -0
  207. data/vendor/assets/fonts/maily_herald/webui/FontAwesome.otf +0 -0
  208. data/vendor/assets/fonts/maily_herald/webui/Nexa_Free_Bold-webfont.eot +0 -0
  209. data/vendor/assets/fonts/maily_herald/webui/Nexa_Free_Bold-webfont.svg +1816 -0
  210. data/vendor/assets/fonts/maily_herald/webui/Nexa_Free_Bold-webfont.ttf +0 -0
  211. data/vendor/assets/fonts/maily_herald/webui/Nexa_Free_Bold-webfont.woff +0 -0
  212. data/vendor/assets/fonts/maily_herald/webui/fontawesome-webfont.eot +0 -0
  213. data/vendor/assets/fonts/maily_herald/webui/fontawesome-webfont.svg +520 -0
  214. data/vendor/assets/fonts/maily_herald/webui/fontawesome-webfont.ttf +0 -0
  215. data/vendor/assets/fonts/maily_herald/webui/fontawesome-webfont.woff +0 -0
  216. data/vendor/assets/fonts/maily_herald/webui/opensans-bold-webfont.eot +0 -0
  217. data/vendor/assets/fonts/maily_herald/webui/opensans-bold-webfont.svg +1825 -0
  218. data/vendor/assets/fonts/maily_herald/webui/opensans-bold-webfont.ttf +0 -0
  219. data/vendor/assets/fonts/maily_herald/webui/opensans-bold-webfont.woff +0 -0
  220. data/vendor/assets/fonts/maily_herald/webui/opensans-italic-webfont.eot +0 -0
  221. data/vendor/assets/fonts/maily_herald/webui/opensans-italic-webfont.svg +1825 -0
  222. data/vendor/assets/fonts/maily_herald/webui/opensans-italic-webfont.ttf +0 -0
  223. data/vendor/assets/fonts/maily_herald/webui/opensans-italic-webfont.woff +0 -0
  224. data/vendor/assets/fonts/maily_herald/webui/opensans-regular-webfont.eot +0 -0
  225. data/vendor/assets/fonts/maily_herald/webui/opensans-regular-webfont.svg +1825 -0
  226. data/vendor/assets/fonts/maily_herald/webui/opensans-regular-webfont.ttf +0 -0
  227. data/vendor/assets/fonts/maily_herald/webui/opensans-regular-webfont.woff +0 -0
  228. data/vendor/assets/javascripts/maily_herald/webui/bootstrap-datepicker.js +1681 -0
  229. data/vendor/assets/javascripts/maily_herald/webui/bootstrap.min.js +6 -0
  230. data/vendor/assets/javascripts/maily_herald/webui/d3.v3.js +5 -0
  231. data/vendor/assets/javascripts/maily_herald/webui/rickshaw.js +4067 -0
  232. data/vendor/assets/stylesheets/maily_herald/webui/bootstrap-datepicker.css +786 -0
  233. data/vendor/assets/stylesheets/maily_herald/webui/bootstrap.min.css +5 -0
  234. data/vendor/assets/stylesheets/maily_herald/webui/font-awesome.min.css +4 -0
  235. data/vendor/assets/stylesheets/maily_herald/webui/rickshaw.css +355 -0
  236. metadata +564 -0
data/config/routes.rb ADDED
@@ -0,0 +1,103 @@
1
+ MailyHerald::Webui::Engine.routes.draw do
2
+ root to: 'dashboard#index'
3
+ resources "logs" do
4
+ member do
5
+ get "preview"
6
+ end
7
+ end
8
+ resources "lists" do
9
+ member do
10
+ post "subscribe/:entity_id", action: :subscribe, as: :subscribe_to
11
+ post "unsubscribe/:entity_id", action: :unsubscribe, as: :unsubscribe_from
12
+ get "context_variables(/:context)", action: :context_variables, as: :context_variables
13
+ end
14
+ end
15
+ resources "subscriptions" do
16
+ member do
17
+ post "toggle"
18
+ end
19
+ end
20
+ resources "one_time_mailings" do
21
+ collection do
22
+ get "archived"
23
+ post "update_form"
24
+ end
25
+ member do
26
+ post "toggle"
27
+ post "deliver/(:entity_id)", action: :deliver, as: :deliver
28
+ get "preview/:entity_id", action: :preview, as: :preview
29
+ end
30
+ end
31
+ resources "periodical_mailings" do
32
+ collection do
33
+ get "archived"
34
+ post "update_form"
35
+ end
36
+ member do
37
+ post "toggle"
38
+ get "preview/:entity_id", action: :preview, as: :preview
39
+ end
40
+ end
41
+ resources "sequences" do
42
+ resources "sequence_mailings", as: "mailings", path: "mailings", except: [:index] do
43
+ collection do
44
+ get "archived"
45
+ post "update_form"
46
+ end
47
+ member do
48
+ post "toggle"
49
+ get "preview/:entity_id", action: :preview, as: :preview
50
+ end
51
+ end
52
+ collection do
53
+ get "archived"
54
+ post "update_form"
55
+ end
56
+ member do
57
+ post "toggle"
58
+ end
59
+ end
60
+
61
+ post "switch_mode/:mode", to: "sessions#switch_mode", as: "switch_mode"
62
+
63
+
64
+
65
+
66
+
67
+
68
+ #resources "sequences" do
69
+ #resources "mailings", :only => [:new, :create], :controller => "mailings", :mailing_type => :sequence
70
+ #member do
71
+ #get "subscription/:entity_id", :to => :subscription, :as => :subscription
72
+ #get "subscription/:entity_id/toggle", :to => :toggle_subscription, :as => :toggle_subscription
73
+ #get "toggle", :to => :toggle, :as => :toggle
74
+ #end
75
+ #end
76
+ #resources "mailings", :except => [:new, :create] do
77
+ #member do
78
+ #get "subscription/:entity_id", :to => :subscription, :as => :subscription
79
+ #get "subscription/:entity_id/toggle", :to => :toggle_subscription, :as => :toggle_subscription
80
+ #get "dashboard/:entity_id", :to => :dashboard, :as => :dashboard
81
+ #get "deliver/(:entity_id)", :to => :deliver, :as => :deliver
82
+ #get "toggle", :to => :toggle, :as => :toggle
83
+ #get "preview/:subscription_id", :to => :preview, :as => :preview
84
+ #end
85
+ #collection do
86
+ #get "context_attributes/(:context_name)", :to => :context_attributes, :as => :context_attributes
87
+ #end
88
+ #end
89
+ #resources "sequences_mailings", :only => [:index, :new], :controller => "mailings", :mailing_type => :sequence
90
+ #resources "one_time_mailings", :only => [:index, :new, :create], :controller => "mailings", :mailing_type => :one_time
91
+ #resources "periodical_mailings", :only => [:index, :new, :create], :controller => "mailings", :mailing_type => :periodical
92
+ #resources "subscription_groups" do
93
+ #member do
94
+ #get "subscription/:subscription_id/toggle", :to => :toggle_subscription, :as => :toggle_subscription
95
+ #end
96
+ #end
97
+ #resources "dashboard", :only => [:index, :show] do
98
+ #collection do
99
+ #get "time_travel"
100
+ #get "forget"
101
+ #end
102
+ #end
103
+ end
data/config/spring.rb ADDED
@@ -0,0 +1 @@
1
+ Spring.application_root = "./spec/dummy"
@@ -0,0 +1,15 @@
1
+ require 'maily_herald/webui/version'
2
+
3
+ require 'smart_listing'
4
+ require 'haml'
5
+
6
+ if defined?(::Rails::Engine)
7
+ require "maily_herald/webui/engine"
8
+ end
9
+
10
+ module MailyHerald
11
+ module Webui
12
+ autoload :Breadcrumbs, 'maily_herald/webui/breadcrumbs'
13
+ autoload :MenuManager, 'maily_herald/webui/menu_manager'
14
+ end
15
+ end
@@ -0,0 +1,50 @@
1
+ module MailyHerald
2
+ module Webui
3
+ module Breadcrumbs
4
+ module ControllerExtensions
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ base.send :include, MailyHerald::Webui::Breadcrumbs::ControllerExtensions::InstanceMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ protected
12
+
13
+ def add_breadcrumb name, url = nil, options = {}
14
+ before_filter options do |controller|
15
+ controller.send(:add_breadcrumb, name, url, options)
16
+ end
17
+ end
18
+ end
19
+
20
+ module InstanceMethods
21
+ protected
22
+
23
+ def self.included(base)
24
+ base.extend ClassMethods
25
+ end
26
+
27
+ def add_breadcrumb name, url = nil, options = {}
28
+ return unless name
29
+
30
+ @breadcrumbs ||= []
31
+ url = self.instance_eval(&url) if url.is_a?(Proc)
32
+ url = eval(url.to_s) if url.to_s =~ /_path|_url|@/
33
+ url = url.merge(:d => current_domain.id.to_s, :host => current_domain.hostname) if url && options[:localized]
34
+ @breadcrumbs << {:name => name, :url => url, :intitle => options[:intitle], :intitle_only => options[:intitle_only]}
35
+ end
36
+
37
+ def disable_breadcrumbs
38
+ @breadcrumbs_disabled = true
39
+ end
40
+ end
41
+ end
42
+
43
+ module HelperExtensions
44
+ def has_breadcrumbs?
45
+ !@breadcrumbs_disabled && @breadcrumbs && !@breadcrumbs.empty?
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ module MailyHerald
2
+ module Webui
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace MailyHerald::Webui
5
+
6
+ config.generators do |g|
7
+ g.test_framework :rspec, :fixture => false
8
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
9
+ end
10
+ config.autoload_paths += Dir["#{config.root}/lib/**/"]
11
+
12
+ initializer :assets do |config|
13
+ Rails.application.config.assets.paths << root.join("vendor", "assets", "fonts")
14
+ Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,285 @@
1
+ module MailyHerald
2
+ module Webui
3
+ class FormBuilder < ActionView::Helpers::FormBuilder
4
+ FIELD_HELPERS = %w{text_field text_area}
5
+
6
+ attr_reader :layout, :label_col, :control_col, :has_error, :inline_errors, :acts_like_form_tag
7
+
8
+ delegate :content_tag, :capture, :concat, :t, :tw, to: :@template
9
+
10
+ def initialize(object_name, object, template, options, proc = nil)
11
+ @layout = options[:layout]
12
+ @label_col = options[:label_col] || default_label_col
13
+ @control_col = options[:control_col] || default_control_col
14
+ @inline_errors = options[:inline_errors] != false
15
+ @help_scope = options[:help_scope]
16
+ super
17
+ end
18
+
19
+ def prepend_and_append_input(options, &block)
20
+ options = options.extract!(:prepend, :append)
21
+ input = capture(&block)
22
+ input = content_tag(:span, options[:prepend], class: options[:prepend].include?("button") ? "input-group-btn" : "input-group-addon") + input if options[:prepend]
23
+ input << content_tag(:span, options[:append], class: options[:append].include?("button") ? "input-group-btn" : "input-group-addon") if options[:append]
24
+ input = content_tag(:div, input, class: "input-group") unless options.empty?
25
+ input
26
+ end
27
+
28
+ FIELD_HELPERS.each do |method_name|
29
+ with_method_name = "#{method_name}_with_maily"
30
+ without_method_name = "#{method_name}_without_maily"
31
+ define_method(with_method_name) do |name, options = {}|
32
+ form_group_builder(name, options) do
33
+ prepend_and_append_input(options) do
34
+ send(without_method_name, name, options)
35
+ end
36
+ end
37
+ end
38
+ alias_method_chain method_name, :maily
39
+ end
40
+
41
+
42
+ def select_with_maily(method, choices, options = {}, html_options = {})
43
+ form_group_builder(method, options, html_options) do
44
+ content_tag(:span, class: ["select-wrap", ("has-error" if has_error?(method))]) do
45
+ select_without_maily(method, choices, options, html_options)
46
+ end
47
+ end
48
+ end
49
+ alias_method_chain :select, :maily
50
+
51
+ def check_box_with_maily(method, options = {}, checked_value = "1", unchecked_value = "0")
52
+ form_group_builder(method, options.merge(hide_label: true)) do
53
+ content_tag(:div, class: "checkbox") do
54
+ label method do
55
+ concat(content_tag(:span, check_box_without_maily(method, options, checked_value, unchecked_value), class: "checkbox-wrap"))
56
+ concat(object.class.human_attribute_name(method))
57
+ end
58
+ end
59
+ end
60
+ end
61
+ alias_method_chain :check_box, :maily
62
+
63
+ def radio_button_with_maily(method, options = {}, checked_value = "1", unchecked_value = "0")
64
+ form_group_builder(method, options.merge(hide_label: true)) do
65
+ content_tag(:div, class: "radio-wrap") do
66
+ label method do
67
+ concat(content_tag(:span, check_box_without_maily(method, options, checked_value, unchecked_value), class: "radio-btn"))
68
+ concat(object.class.human_attribute_name(method))
69
+ end
70
+ end
71
+ end
72
+ end
73
+ alias_method_chain :radio_button, :maily
74
+
75
+ def maily_context_select(options = {}, html_options = {})
76
+ choices = MailyHerald.contexts.values.collect do |context|
77
+ [@template.friendly_name(context), context.name]
78
+ end
79
+ select_with_maily :context_name, choices, options, html_options
80
+ end
81
+
82
+ def maily_mailer_select(options = {}, html_options = {})
83
+ choices = ObjectSpace.each_object(Class).select { |klass| klass < ActionMailer::Base }.collect do |mailer|
84
+ if mailer.name == "MailyHerald::Mailer"
85
+ ["Generic Mailer", "generic"]
86
+ else
87
+ [mailer.name, mailer.name]
88
+ end
89
+ end
90
+ select_with_maily :mailer_name, choices, options, html_options
91
+ end
92
+
93
+ def maily_list_select(options = {}, html_options = {})
94
+ choices = MailyHerald::List.all.collect do |list|
95
+ [@template.friendly_name(list), list.name]
96
+ end
97
+ select_with_maily :list, choices, options.merge(prompt: tw("commons.please_select")), {autocomplete: "off"}.merge(html_options)
98
+ end
99
+
100
+ def maily_from_field options = {}, html_options = {}
101
+ form_group_builder(:from, options.merge(wrapper_class: "mailing-from")) do
102
+ radio1 = content_tag(:label, content_tag(:span, @template.radio_button_tag(:mailing_from, "default", !object.from.present?), class: "radio-btn") + @template.display_mailing_from(object), class: "radio")
103
+ radio2 = content_tag(:label, content_tag(:span, @template.radio_button_tag(:mailing_from, "specify", object.from.present?), class: "radio-btn") + tw("mailings.from.specify"), class: "radio")
104
+
105
+ field = prepend_and_append_input(options) do
106
+ text_field_without_maily(:from, {class: "form-control", placeholder: tw("mailings.placeholders.from")})
107
+ end
108
+
109
+ concat(content_tag(:p, radio1 + radio2)).concat(field)
110
+ end
111
+ end
112
+
113
+ def maily_start_at_field options = {}, html_options = {}
114
+ form_group_builder(:start_at, options.merge(wrapper_class: "dispatch-start-at")) do
115
+ radio1 = content_tag(:label, content_tag(:span, @template.radio_button_tag(:mailing_from, "absolute", !object.from.present?), class: "radio-btn") + tw("mailings.start_at.absolute"), class: "radio")
116
+ radio2 = content_tag(:label, content_tag(:span, @template.radio_button_tag(:mailing_from, "relative", object.from.present?), class: "radio-btn") + tw("mailings.start_at.relative"), class: "radio")
117
+ calendar_btn = content_tag(:button, @template.icon(:calendar), class: "btn btn-default", type: "button")
118
+ list_btn = @template.link_to_context_attributes_overview(object.list, class: "btn btn-default")
119
+
120
+ field = prepend_and_append_input({append: calendar_btn + list_btn}) do
121
+ text_field_without_maily(:start_at, {class: "form-control", placeholder: tw("mailings.placeholders.start_at")})
122
+ end
123
+
124
+ #concat(content_tag(:p, radio1 + radio2)).concat(field)
125
+ field
126
+ end
127
+ end
128
+
129
+ def maily_period_field options = {}, html_options = {}
130
+ text_field :period_in_days, help: true, append: tw("mailings.help.period_unit"), placeholder: tw("mailings.placeholders.period")
131
+ end
132
+
133
+ def maily_absolute_delay_field options = {}, html_options = {}
134
+ text_field :absolute_delay_in_days, help: true, append: tw("mailings.help.absolute_delay_unit"), placeholder: tw("mailings.placeholders.absolute_delay")
135
+ end
136
+
137
+ def form_group(*args, &block)
138
+ options = args.extract_options!
139
+ name = args.first
140
+
141
+ options[:class] = ["form-group", options[:class]].compact.join(' ')
142
+ options[:class] << " #{error_class}" if has_error?(name)
143
+ options[:class] << " #{feedback_class}" if options[:icon]
144
+
145
+ content_tag(:div, options.except(:id, :label, :help, :icon, :label_col, :control_col, :layout)) do
146
+ label = generate_label(options[:id], name, options[:label], options[:label_col], options[:layout], options[:help]) if options[:label]
147
+ control = capture(&block).to_s
148
+ control.concat(generate_help(name, options[:help]).to_s)
149
+ #control.concat(generate_help(options[:help].is_a?(TrueClass) ? name : options[:help])) if options[:help]
150
+ control.concat(generate_icon(options[:icon])) if options[:icon]
151
+
152
+ if get_group_layout(options[:layout]) == :horizontal
153
+ control_class = (options[:control_col] || control_col)
154
+
155
+ unless options[:label]
156
+ control_offset = offset_col(/([0-9]+)$/.match(options[:label_col] || default_label_col))
157
+ control_class.concat(" #{control_offset}")
158
+ end
159
+ control = content_tag(:div, control, class: control_class)
160
+ end
161
+
162
+ concat(label).concat(control)
163
+ end
164
+ end
165
+
166
+ def buttons *bs
167
+ form_group do
168
+ bs.each do |button|
169
+ if button.is_a?(Array)
170
+ label = button.last
171
+ button = button.first
172
+ end
173
+ if button.is_a?(Symbol)
174
+ case button
175
+ when :submit
176
+ concat(content_tag(:button, label || tw("commons.submit"), :class => "btn btn-webui", :type => "submit"))
177
+ when :create
178
+ concat(content_tag(:button, label || tw("commons.create"), :class => "btn btn-webui", :type => "submit", :name => "submit"))
179
+ when :save
180
+ concat(content_tag(:button, label || tw("commons.save"), :class => "btn btn-webui", :type => "submit", :name => "submit"))
181
+ when :save_continue
182
+ concat(content_tag(:button, label || tw("commons.save_continue"), :class => "btn btn-webui", :type => "submit", :name => "submit_continue"))
183
+ when :cancel
184
+ concat(content_tag(:button, label || tw("commons.cancel"), :class => "btn btn-webui-alternative cancel"))
185
+ end
186
+ else
187
+ concat(content_tag(:button, button[:text], :class => button[:class], :type => button[:type]))
188
+ end
189
+ concat(" ")
190
+ end
191
+ end
192
+ end
193
+
194
+ private
195
+
196
+ def form_group_builder(method, options, html_options = nil)
197
+ options.symbolize_keys!
198
+ html_options.symbolize_keys! if html_options
199
+
200
+ # Add control_class; allow it to be overridden by :control_class option
201
+ css_options = html_options || options
202
+ control_classes = css_options.delete(:control_class) { control_class }
203
+ css_options[:class] = [control_classes, css_options[:class]].compact.join(" ")
204
+
205
+ label = options.delete(:label)
206
+ label_class = hide_class if options.delete(:hide_label)
207
+ wrapper_class = options.delete(:wrapper_class)
208
+ help = options.delete(:help)
209
+ icon = options.delete(:icon)
210
+ label_col = options.delete(:label_col)
211
+ control_col = options.delete(:control_col)
212
+ layout = get_group_layout(options.delete(:layout))
213
+
214
+ form_group(method, id: options[:id], label: { text: label, class: label_class }, help: help, icon: icon, label_col: label_col, control_col: control_col, layout: layout, class: wrapper_class) do
215
+ yield
216
+ end
217
+ end
218
+
219
+ def horizontal?
220
+ layout == :horizontal
221
+ end
222
+
223
+ def get_group_layout(group_layout)
224
+ group_layout || layout
225
+ end
226
+
227
+ def default_label_col
228
+ "col-sm-2"
229
+ end
230
+ def offset_col(offset)
231
+ "col-sm-offset-#{offset}"
232
+ end
233
+ def default_control_col
234
+ "col-sm-10"
235
+ end
236
+ def hide_class
237
+ "sr-only" # still accessible for screen readers
238
+ end
239
+ def control_class
240
+ "form-control"
241
+ end
242
+ def label_class
243
+ "control-label"
244
+ end
245
+ def error_class
246
+ "has-error"
247
+ end
248
+ def feedback_class
249
+ "has-feedback"
250
+ end
251
+
252
+ def has_error?(name)
253
+ object.respond_to?(:errors) && !(name.nil? || object.errors[name].empty? || object.errors[name.to_s.chomp("_id").to_sym].empty?)
254
+ end
255
+
256
+ def generate_label(id, name, options, custom_label_col, group_layout, help)
257
+ options[:for] = id if acts_like_form_tag
258
+ classes = [options[:class], label_class]
259
+ classes << (custom_label_col || label_col) if get_group_layout(group_layout) == :horizontal
260
+ options[:class] = classes.compact.join(" ")
261
+
262
+ text = options[:text] || object.class.human_attribute_name(name)
263
+ text += " " + generate_help_icon(help.is_a?(TrueClass) ? name : help) if help
264
+
265
+ label(name, text.html_safe, options.except(:text))
266
+ end
267
+
268
+ def generate_help_icon(help)
269
+ @template.display_help_icon help, scope: @help_scope, placement: "top"
270
+ end
271
+
272
+ def generate_help(name, help_text)
273
+ help_text = object.errors[name].join(", ") if has_error?(name) && inline_errors
274
+ return if help_text === false
275
+
276
+ help_text ||= I18n.t(name, scope: "activerecord.help.#{object.class.to_s.downcase}", default: '')
277
+ content_tag(:span, help_text, class: 'help-block') if help_text.present? && help_text.is_a?(String)
278
+ end
279
+
280
+ def generate_icon(icon)
281
+ content_tag(:span, "", class: "glyphicon glyphicon-#{icon} form-control-feedback")
282
+ end
283
+ end
284
+ end
285
+ end