fe 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +16 -36
  3. data/app/assets/javascripts/fe/admin.js +0 -1
  4. data/app/assets/javascripts/fe/fe.admin.js +40 -16
  5. data/app/assets/javascripts/fe/fe.common.js +48 -14
  6. data/app/assets/javascripts/fe/fe.public.js +1 -414
  7. data/app/assets/javascripts/fe/fe.public.nojquery.js +450 -0
  8. data/app/assets/javascripts/fe/jquery.validate.pack.js +3 -15
  9. data/app/assets/stylesheets/360front.css +0 -0
  10. data/app/assets/stylesheets/fe/fe.screen.css.scss.erb +69 -10
  11. data/app/controllers/fe/admin/elements_controller.rb +64 -48
  12. data/app/controllers/fe/admin/email_templates_controller.rb +2 -2
  13. data/app/controllers/fe/admin/question_pages_controller.rb +1 -1
  14. data/app/controllers/fe/admin/question_sheets_controller.rb +2 -103
  15. data/app/controllers/fe/concerns/admin/question_sheets_controller_concern.rb +112 -0
  16. data/app/controllers/fe/concerns/answer_pages_controller_concern.rb +2 -1
  17. data/app/controllers/fe/concerns/answer_sheets_controller_concern.rb +1 -1
  18. data/app/controllers/fe/concerns/application_controller_concern.rb +13 -0
  19. data/app/controllers/fe/reference_sheets_controller.rb +2 -0
  20. data/app/controllers/fe/references_controller.rb +1 -0
  21. data/app/helpers/fe/application_helper.rb +5 -0
  22. data/app/mailers/fe/notifier.rb +11 -4
  23. data/app/models/answer_sheet.rb +2 -0
  24. data/app/models/fe/application.rb +2 -1
  25. data/app/models/fe/concerns/answer_pages_presenter_concern.rb +10 -1
  26. data/app/models/fe/concerns/answer_sheet_concern.rb +38 -8
  27. data/app/models/fe/concerns/choice_field_concern.rb +17 -10
  28. data/app/models/fe/date_field.rb +1 -1
  29. data/app/models/fe/element.rb +105 -31
  30. data/app/models/fe/page.rb +52 -20
  31. data/app/models/fe/page_element.rb +6 -1
  32. data/app/models/fe/page_link.rb +6 -3
  33. data/app/models/fe/person.rb +11 -8
  34. data/app/models/fe/question.rb +2 -6
  35. data/app/models/fe/question_grid.rb +1 -1
  36. data/app/models/fe/question_grid_with_total.rb +15 -0
  37. data/app/models/fe/question_set.rb +1 -1
  38. data/app/models/fe/question_sheet.rb +15 -13
  39. data/app/models/fe/reference_question.rb +0 -10
  40. data/app/models/fe/reference_sheet.rb +17 -13
  41. data/app/models/staff.rb +2 -0
  42. data/app/validators/email_validator.rb +11 -0
  43. data/app/views/fe/admin/elements/create.js.erb +1 -0
  44. data/app/views/fe/admin/elements/drop.js.erb +1 -0
  45. data/app/views/fe/admin/elements/duplicate.js.erb +1 -0
  46. data/app/views/fe/admin/panels/_advanced_options.html.erb +9 -3
  47. data/app/views/fe/admin/panels/_common_fields.html.erb +19 -5
  48. data/app/views/fe/admin/panels/_page.html.erb +1 -1
  49. data/app/views/fe/admin/panels/_prop_choice_field.html.erb +20 -11
  50. data/app/views/fe/admin/panels/_prop_element.html.erb +2 -9
  51. data/app/views/fe/admin/panels/_prop_page.html.erb +8 -3
  52. data/app/views/fe/admin/panels/_prop_paragraph.html.erb +38 -24
  53. data/app/views/fe/admin/panels/_prop_section.html.erb +8 -2
  54. data/app/views/fe/admin/panels/_prop_sheet.html.erb +4 -1
  55. data/app/views/fe/admin/question_pages/_element.html.erb +11 -1
  56. data/app/views/fe/answer_pages/_answer_page.html.erb +9 -8
  57. data/app/views/fe/answer_pages/_element.html.erb +6 -7
  58. data/app/views/fe/answer_pages/_page_name.html.erb +1 -0
  59. data/app/views/fe/answer_pages/update.js.erb +3 -3
  60. data/app/views/fe/answer_sheets/_answer_sheet.html.erb +3 -3
  61. data/app/views/fe/answer_sheets/_element.html.erb +52 -34
  62. data/app/views/fe/answer_sheets/_incomplete.html.erb +1 -1
  63. data/app/views/fe/answer_sheets/_page_link.html.erb +2 -2
  64. data/app/views/fe/answer_sheets/_pages_list.html.erb +3 -3
  65. data/app/views/fe/answer_sheets/_submit_to.html.erb +1 -0
  66. data/app/views/fe/answer_sheets/edit.html.erb +14 -14
  67. data/app/views/fe/answer_sheets/incomplete.js.erb +3 -0
  68. data/app/views/fe/answer_sheets/index.html.erb +3 -3
  69. data/app/views/fe/answer_sheets/show.html.erb +1 -1
  70. data/app/views/fe/applications/_logout.html.erb +1 -0
  71. data/app/views/fe/applications/show.html.erb +1 -0
  72. data/app/views/fe/questions/fe/_acceptance.html.erb +3 -3
  73. data/app/views/fe/questions/fe/_attachment_field.html.erb +7 -3
  74. data/app/views/fe/questions/fe/_checkbox_field.html.erb +26 -24
  75. data/app/views/fe/questions/fe/_date_field.html.erb +1 -2
  76. data/app/views/fe/questions/fe/_date_field_mmyy.html.erb +2 -2
  77. data/app/views/fe/questions/fe/_drop_down_field.html.erb +3 -2
  78. data/app/views/fe/questions/fe/_paragraph.html.erb +1 -1
  79. data/app/views/fe/questions/fe/_question_grid.html.erb +14 -9
  80. data/app/views/fe/questions/fe/_question_grid_with_total.html.erb +21 -14
  81. data/app/views/fe/questions/fe/_questions.html.erb +2 -2
  82. data/app/views/fe/questions/fe/_radio_button_field.html.erb +12 -11
  83. data/app/views/fe/questions/fe/_rating.html.erb +9 -8
  84. data/app/views/fe/questions/fe/_reference_discipler.html.erb +1 -1
  85. data/app/views/fe/questions/fe/_reference_friend.html.erb +1 -1
  86. data/app/views/fe/questions/fe/_reference_parent.html.erb +1 -1
  87. data/app/views/fe/questions/fe/_reference_peer.html.erb +1 -1
  88. data/app/views/fe/questions/fe/_reference_question.html.erb +22 -15
  89. data/app/views/fe/questions/fe/_reference_roommate.html.erb +1 -1
  90. data/app/views/fe/questions/fe/_reference_spiritual.html.erb +1 -1
  91. data/app/views/fe/questions/fe/_reference_staff.html.erb +1 -1
  92. data/app/views/fe/questions/fe/_section.html.erb +1 -1
  93. data/app/views/fe/questions/fe/_text_area_field.html.erb +10 -3
  94. data/app/views/fe/questions/fe/_text_field.html.erb +1 -1
  95. data/app/views/fe/questions/fe/_yes_no_field.erb +3 -3
  96. data/app/views/fe/reference_pages/_reference.html.erb +11 -11
  97. data/app/views/fe/reference_pages/edit.html.erb +7 -7
  98. data/app/views/fe/reference_sheets/done.html.erb +2 -2
  99. data/app/views/fe/reference_sheets/not_found.html.erb +4 -4
  100. data/app/views/fe/references/edit.html.erb +6 -6
  101. data/app/views/fe/references/show.html.erb +7 -7
  102. data/app/views/fe/references/submit.js.erb +1 -1
  103. data/app/views/fe/submit_pages/_thankyou.html.erb +1 -1
  104. data/app/views/fe/submit_pages/edit.html.erb +9 -9
  105. data/app/views/layouts/fe/_error_messages_for.html.erb +7 -0
  106. data/app/views/layouts/fe/application.html.erb +1 -1
  107. data/config/routes.rb +0 -36
  108. data/db/migrate/20131003044250_create_reference_sheets.rb +1 -0
  109. data/db/migrate/20140623153424_create_fe_people.rb +1 -1
  110. data/db/migrate/20140624180246_create_fe_addresses.rb +1 -1
  111. data/db/migrate/20140624182216_create_fe_phone_numbers.rb +16 -0
  112. data/db/migrate/20140625160545_create_fe_users.rb +1 -1
  113. data/db/migrate/20150504221439_add_all_element_ids_to_pages.rb +5 -0
  114. data/db/migrate/20150713022326_add_locale_columns.rb +9 -0
  115. data/db/migrate/20150714220730_add_locale_to_answer_sheet.rb +5 -0
  116. data/db/migrate/20150928085325_change_pages_all_element_ids_to_text.rb +5 -0
  117. data/db/migrate/20150930191538_add_locale_to_reference_sheets.rb +5 -0
  118. data/lib/access_key_generator.rb +12 -0
  119. data/lib/distinct_distinct_patch.rb +20 -0
  120. data/lib/fe.rb +4 -0
  121. data/lib/fe/engine.rb +16 -4
  122. data/lib/fe/version.rb +1 -1
  123. data/spec/controllers/fe/admin/elements_controller_spec.rb +201 -1
  124. data/spec/controllers/fe/admin/email_templates_controller_spec.rb +26 -1
  125. data/spec/controllers/fe/admin/question_pages_controller_spec.rb +8 -1
  126. data/spec/controllers/fe/admin/question_sheets_controller_spec.rb +48 -1
  127. data/spec/controllers/fe/answer_pages_controller_spec.rb +73 -1
  128. data/spec/controllers/fe/answer_sheets_controller_spec.rb +80 -1
  129. data/spec/controllers/fe/reference_pages_controller.rb +4 -0
  130. data/spec/controllers/fe/references_controller_spec.rb +4 -0
  131. data/spec/controllers/fe/submit_pages_controller_spec.rb +4 -0
  132. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  133. data/spec/dummy/app/helpers/application_helper.rb +9 -0
  134. data/spec/dummy/app/models/application.rb +3 -0
  135. data/spec/dummy/app/models/person.rb +11 -0
  136. data/spec/dummy/app/models/user.rb +3 -0
  137. data/spec/dummy/config/application.rb +2 -1
  138. data/spec/dummy/config/database.yml +20 -17
  139. data/spec/dummy/config/environments/production.rb +1 -5
  140. data/spec/dummy/config/environments/test.rb +3 -1
  141. data/spec/dummy/config/initializers/fast_gettext.rb +5 -0
  142. data/spec/dummy/config/secrets.yml +2 -2
  143. data/spec/dummy/db/migrate/20141203214017_core.fe_engine.rb +92 -0
  144. data/spec/dummy/db/migrate/20141203214018_create_reference_sheets.fe_engine.rb +25 -0
  145. data/spec/dummy/db/migrate/20141203214019_add_element_and_answer_fields.fe_engine.rb +11 -0
  146. data/spec/dummy/db/migrate/20141203214020_create_email_templates.fe_engine.rb +18 -0
  147. data/spec/dummy/db/migrate/20141203214021_add_max_lengths.fe_engine.rb +9 -0
  148. data/spec/dummy/db/migrate/20141203214022_create_join_table.fe_engine.rb +12 -0
  149. data/spec/dummy/db/migrate/20141203214023_remove_question_id_from_element.fe_engine.rb +10 -0
  150. data/spec/dummy/db/migrate/20141203214024_create_fe_people.fe_engine.rb +13 -0
  151. data/spec/dummy/db/migrate/20141203214025_create_fe_addresses.fe_engine.rb +21 -0
  152. data/{db/migrate/20140624182216_create_create_fe_phone_numbers.rb → spec/dummy/db/migrate/20141203214026_create_create_fe_phone_numbers.fe_engine.rb} +1 -0
  153. data/spec/dummy/db/migrate/20141203214027_create_fe_users.fe_engine.rb +13 -0
  154. data/spec/dummy/db/migrate/20141203214028_add_conditional_type_to_elements.fe_engine.rb +6 -0
  155. data/spec/dummy/db/migrate/20141203214029_add_conditional_answer_to_elements.fe_engine.rb +6 -0
  156. data/spec/dummy/db/migrate/20141203214030_remove_short_value_column.fe_engine.rb +6 -0
  157. data/spec/dummy/db/migrate/20141203214031_move_conditional_ids_used_for_choice_field_to_their_own_column.fe_engine.rb +8 -0
  158. data/spec/dummy/db/migrate/20150123215803_create_users.rb +9 -0
  159. data/spec/dummy/db/migrate/20150504222619_add_all_element_ids_to_pages.fe_engine.rb +6 -0
  160. data/spec/dummy/db/migrate/20150930190001_create_fe_phone_numbers.fe_engine.rb +20 -0
  161. data/spec/dummy/db/migrate/20150930190002_add_locale_columns.fe_engine.rb +10 -0
  162. data/spec/dummy/db/migrate/20150930190003_add_locale_to_answer_sheet.fe_engine.rb +6 -0
  163. data/spec/dummy/db/migrate/20150930190004_change_pages_all_element_ids_to_text.fe_engine.rb +6 -0
  164. data/spec/dummy/db/migrate/20150930191756_add_locale_to_reference_sheets.fe_engine.rb +6 -0
  165. data/spec/dummy/db/schema.rb +50 -20
  166. data/spec/dummy/log/development.log +5 -0
  167. data/spec/factories/applications.rb +0 -1
  168. data/spec/factories/dummy_applications.rb +6 -0
  169. data/spec/factories/dummy_people.rb +6 -0
  170. data/spec/factories/dummy_users.rb +6 -0
  171. data/spec/factories/elements.rb +28 -3
  172. data/spec/factories/email_templates.rb +5 -0
  173. data/spec/factories/fe_email_templates.rb +9 -0
  174. data/spec/factories/fe_people.rb +0 -2
  175. data/spec/factories/fe_user.rb +6 -0
  176. data/spec/factories/question_sheet.rb +1 -1
  177. data/spec/factories/reference_sheets.rb +9 -0
  178. data/spec/mailers/fe/notifier_spec.rb +39 -0
  179. data/spec/models/fe/choice_field_spec.rb +20 -0
  180. data/spec/models/fe/element_spec.rb +185 -0
  181. data/spec/models/fe/page_spec.rb +112 -0
  182. data/spec/models/fe/question_sheet_spec.rb +106 -0
  183. data/spec/models/fe/reference_sheet_spec.rb +20 -0
  184. data/spec/rails_helper.rb +41 -13
  185. data/spec/support/choices.xml +6 -0
  186. metadata +136 -48
  187. data/app/assets/javascripts/fe/rails.extra.js +0 -6
  188. data/app/controllers/fe/applications_controller.rb +0 -183
  189. data/app/controllers/fe/payments_controller.rb +0 -184
  190. data/app/models/fe/payment.rb +0 -77
  191. data/app/models/fe/payment_question.rb +0 -22
  192. data/app/views/fe/admin/panels/_prop_payment_question.html.erb +0 -1
  193. data/app/views/fe/application/_logout.html.erb +0 -1
  194. data/app/views/fe/payment_pages/_credit.html.erb +0 -47
  195. data/app/views/fe/payment_pages/_mail.html.erb +0 -27
  196. data/app/views/fe/payment_pages/_payment.html.erb +0 -6
  197. data/app/views/fe/payment_pages/_staff.html.erb +0 -25
  198. data/app/views/fe/payment_pages/_staff_results.html.erb +0 -17
  199. data/app/views/fe/payment_pages/edit.html.erb +0 -75
  200. data/app/views/fe/payment_pages/staff_search.js.erb +0 -2
  201. data/app/views/fe/payments/_credit.html.erb +0 -47
  202. data/app/views/fe/payments/_errors.html.erb +0 -1
  203. data/app/views/fe/payments/_payment.html.erb +0 -13
  204. data/app/views/fe/payments/_staff.html.erb +0 -21
  205. data/app/views/fe/payments/_staff_results.html.erb +0 -18
  206. data/app/views/fe/payments/approve.js.erb +0 -3
  207. data/app/views/fe/payments/create.js.erb +0 -19
  208. data/app/views/fe/payments/destroy.js.erb +0 -7
  209. data/app/views/fe/payments/edit.html.erb +0 -56
  210. data/app/views/fe/payments/error.js.erb +0 -3
  211. data/app/views/fe/payments/no_access.html.erb +0 -7
  212. data/app/views/fe/payments/staff_search.js.erb +0 -1
  213. data/app/views/fe/payments/update.html.erb +0 -24
  214. data/app/views/fe/questions/fe/_payment_question.html.erb +0 -70
  215. data/db/migrate/20140828045339_create_payments.rb +0 -13
  216. data/spec/dummy/db/test.sqlite3 +0 -0
  217. data/spec/factories/payments.rb +0 -7
  218. data/spec/models/fe/payment_question_spec.rb +0 -65
File without changes
@@ -182,6 +182,7 @@ ul#nav-controls li a:hover {
182
182
  .list-elements #at a { background-image: url("<%= asset_path('fe/icons/paper-clip.png') %>");}
183
183
  .list-elements #ref a { background-image: url("<%= asset_path('fe/icons/book-open-list.png') %>");}
184
184
 
185
+ .fe_textfield textarea { width: 90%; }
185
186
 
186
187
 
187
188
  /* BODY SIDE */
@@ -236,7 +237,7 @@ span.required {
236
237
  width:16px;
237
238
  }
238
239
 
239
- label {
240
+ label:not(.no_label_styles) { /* allow labels without styling, for the feature of clicking the label and having focus go to its corresponding input field */
240
241
  min-width: 150px;
241
242
  font-weight: bold;
242
243
  font-size: 14px;
@@ -263,7 +264,8 @@ ul.questions li {
263
264
  }
264
265
 
265
266
  .field_check input[type=checkbox],
266
- .field_check input[type=radio] {
267
+ .field_check input[type=radio],
268
+ .radio-set input[type=radio] {
267
269
  float: left;
268
270
  }
269
271
 
@@ -473,6 +475,9 @@ td.actions a {padding: 2px 10px 2px 20px;}
473
475
  .archive {background: url("<%= asset_path('fe/icons/briefcase.png') %>") no-repeat 0% 50%;}
474
476
  .delete {background: url("<%= asset_path('fe/icons/minus-button.png') %>") no-repeat 0% 50%;}
475
477
 
478
+ table.ratings tr {
479
+ margin-right: 20px;
480
+ }
476
481
 
477
482
  /* HEADER */
478
483
  #header {
@@ -487,17 +492,17 @@ td.actions a {padding: 2px 10px 2px 20px;}
487
492
 
488
493
  #header li a {
489
494
  color: #fff;
490
- padding: 0px;
495
+ padding: 6px;
496
+ display: block;
491
497
  }
492
498
 
493
499
  #header li {
494
500
  float: left;
501
+ margin-right: 5px;
495
502
  }
496
503
 
497
504
  #header li.active a {
498
505
  background: #2e7ba7;
499
- padding: 6px;
500
- display: block;
501
506
  }
502
507
 
503
508
  #nav-main {
@@ -524,10 +529,30 @@ td.actions a {padding: 2px 10px 2px 20px;}
524
529
  width:auto;
525
530
  }
526
531
  .droppable-active {
527
- min-height: 200px;
528
- border-width: 4px;
529
- padding: 4px;
530
- margin: -8px;
532
+ background: #EBFCEB;
533
+ min-height: 200px;
534
+ border-width: 4px;
535
+ padding: 4px;
536
+ margin: -8px;
537
+ }
538
+ .droppable-hover {
539
+ background: #2F7EAB;
540
+ }
541
+
542
+ .droppable.around-container {
543
+ //border: 1px solid black;
544
+ border: 0px;
545
+ }
546
+
547
+ .droppable.around-container:not(.droppable-activated) {
548
+ height: 0px;
549
+ }
550
+ .droppable-active.around-container {
551
+ //display: inline;
552
+ padding: 0px;
553
+ margin: 10px 0px 10px 0px;;
554
+ min-height: 100px;
555
+ border-width: 1px;
531
556
  }
532
557
 
533
558
  .inlinecheck {
@@ -543,4 +568,38 @@ td.actions a {padding: 2px 10px 2px 20px;}
543
568
  color:red;
544
569
  font-weight: bold;
545
570
  }
546
- }
571
+ }
572
+
573
+ .future_affect {
574
+ label { display: inline-block; min-width: 0px; }
575
+ input[type=radio] { margin-left: 10px; }
576
+ }
577
+
578
+ /* SPINNER */
579
+
580
+ #page_ajax_spinner {
581
+ position: absolute;
582
+ top: -52px;
583
+ width: 1000px;
584
+ z-index: 100;
585
+ }
586
+
587
+ #page_ajax_spinner div {
588
+ -moz-box-shadow: 0 0 10px #666666;
589
+ -webkit-box-shadow: 0 0 10px #666666;
590
+ box-shadow: 0 0 10px #666666;
591
+ background: none repeat scroll 0 0 #FFFFFF;
592
+ border: 2px solid #411E08;
593
+ color: #411E08;
594
+ margin: 0 auto;
595
+ padding: 10px;
596
+ text-align: center;
597
+ width: 200px;
598
+ }
599
+
600
+ input[type="text"].char-count {
601
+ font-size: 10px;
602
+ display: inline-block;
603
+ width: 50px;
604
+ }
605
+
@@ -1,44 +1,35 @@
1
1
  class Fe::Admin::ElementsController < ApplicationController
2
2
  before_filter :check_valid_user
3
3
  layout 'fe/fe.admin'
4
-
5
- before_filter :get_page
6
-
7
- # GET /elements/1
8
- def show
9
- @element = Fe::Element.find(params[:id])
10
4
 
11
- respond_to do |format|
12
- format.js
13
- end
14
- end
5
+ before_filter :get_page
15
6
 
16
7
  # GET /element/1/edit
17
8
  def edit
18
- @element = Fe::Element.find(params[:id])
19
-
9
+ @element = @page.all_elements.find(params[:id])
10
+
20
11
  # for dependencies
21
12
  if @element.question?
22
13
  (3 - @element.conditions.length).times { @element.conditions.build }
23
- @questions_before_this = @page.questions_before_position(@element.position(@page))
14
+ @questions_before_this = @page.questions_before_position(@element.position(@page))
24
15
  end
25
-
16
+
26
17
  respond_to do |format|
27
18
  format.js
28
19
  end
29
20
  end
30
-
21
+
31
22
  def new
32
23
  @questions = params[:element_type].constantize.active.order('label')
33
24
 
34
25
  @style = element_params[:style]
35
26
  if @style
36
- @questions = @questions.where(:style => @style).uniq
27
+ @questions = @questions.where(:style => @style).to_a.uniq
37
28
  end
38
29
  end
39
-
30
+
40
31
  def use_existing
41
- @element = Fe::Element.find(params[:id])
32
+ @element = Fe::Element.find(params[:id]) # NOTE the enclosing app might want to override this method and check that they have access to the questionnaire that the existing element is used on
42
33
  # Don't put the same question on a questionnaire twice
43
34
  unless @page.question_sheet.elements.include?(@element)
44
35
  @page_element = Fe::PageElement.create(:element => @element, :page => @page)
@@ -54,24 +45,24 @@ class Fe::Admin::ElementsController < ApplicationController
54
45
  @question_sheet = @page.question_sheet
55
46
 
56
47
  respond_to do |format|
57
- if @element.save!
48
+ if @element.save
58
49
  @page_element = Fe::PageElement.create(:element => @element, :page => @page)
59
50
  format.js
60
51
  else
61
- format.js { render :action => 'error.rjs' }
52
+ format.js { render :action => 'error.js.erb' }
62
53
  end
63
54
  end
64
55
  end
65
56
 
66
57
  # PUT /elements/1
67
58
  def update
68
- @element = Fe::Element.find(params[:id])
59
+ @element = @page.all_elements.find(params[:id])
69
60
 
70
61
  respond_to do |format|
71
62
  if @element.update_attributes(element_params)
72
63
  format.js
73
64
  else
74
- format.js { render :action => 'error.rjs' }
65
+ format.js { render :action => 'error.js.erb' }
75
66
  end
76
67
  end
77
68
  end
@@ -79,11 +70,11 @@ class Fe::Admin::ElementsController < ApplicationController
79
70
  # DELETE /elements/1
80
71
  # DELETE /elements/1.xml
81
72
  def destroy
82
- @element = Fe::Element.find(params[:id])
73
+ @element = @page.all_elements.find(params[:id])
83
74
  # Start by removing the element from the page
84
75
  page_element = Fe::PageElement.where(:element_id => @element.id, :page_id => @page.id).first
85
76
  page_element.destroy if page_element
86
-
77
+
87
78
  # If this element is not on any other pages, is not a question or has no answers, Destroy it
88
79
  if @element.reuseable? && (Fe::PageElement.where(:element_id => params[:id]).present? || @element.has_response?)
89
80
  @element.update_attributes(:question_grid_id => nil, :conditional_id => nil)
@@ -95,24 +86,24 @@ class Fe::Admin::ElementsController < ApplicationController
95
86
  format.js
96
87
  end
97
88
  end
98
-
99
- def reorder
89
+
90
+ def reorder
100
91
  # since we don't know the name of the list, just find the first param that is an array
101
- params.each_key do |key|
92
+ params.each_key do |key|
102
93
  if key.include?('questions_list')
103
94
  grid_id = key.sub('questions_list_', '').to_i
104
95
  # See if we're ordering inside of a grid
105
96
  if grid_id > 0
106
- Fe::Element.find(grid_id).elements.each do |element|
97
+ @page.all_elements.find(grid_id).elements.each do |element|
107
98
  if index = params[key].index(element.id.to_s)
108
- element.position = index + 1
99
+ element.position = index + 1
109
100
  element.save(:validate => false)
110
101
  end
111
102
  end
112
103
  else
113
104
  @page.page_elements.each do |page_element|
114
105
  if index = params[key].index(page_element.element_id.to_s)
115
- page_element.position = index + 1
106
+ page_element.position = index + 1
116
107
  page_element.save(:validate => false)
117
108
  @element = page_element.element
118
109
  end
@@ -120,17 +111,36 @@ class Fe::Admin::ElementsController < ApplicationController
120
111
  end
121
112
  end
122
113
  end
123
-
114
+
124
115
  respond_to do |format|
125
116
  format.js
126
117
  end
127
118
  end
128
-
119
+
129
120
  def drop
130
- element = Fe::Element.find(params[:draggable_element].split('_')[1]) # element being dropped
131
- target = Fe::Element.find(params[:id])
121
+ element = @page.all_elements.find(params[:draggable_element].split('_')[1]) # element being dropped
122
+ target = @page.all_elements.find(params[:id])
123
+
124
+ if [params[:before], params[:after]].include?('true')
125
+ # move the element out of its parent and back onto the page directly, placing it before the target
126
+ page_element = Fe::PageElement.where(page_id: @page.id, element_id: element.id).first_or_create
127
+ @page.page_elements << page_element
128
+
129
+ parent_element = element.question_grid || element.choice_field
130
+ parent_page_element = @page.page_elements.find_by(element_id: parent_element.id)
131
+ if params[:before]
132
+ page_element.insert_at(parent_page_element.position)
133
+ else
134
+ page_element.insert_at(parent_page_element.position + 1)
135
+ end
136
+
137
+ # remove question grid / choice_field ref since it's directly on the page now
138
+ element.update_attributes(question_grid_id: nil, choice_field_id: nil)
139
+ return
140
+ end
141
+
132
142
  case target.class.to_s
133
- when 'QuestionGrid', 'QuestionGridWithTotal'
143
+ when 'Fe::QuestionGrid', 'Fe::QuestionGridWithTotal'
134
144
  # abort if the element is already in this box
135
145
  if element.question_grid_id == params[:id].to_i
136
146
  render :nothing => true
@@ -138,48 +148,54 @@ class Fe::Admin::ElementsController < ApplicationController
138
148
  element.question_grid_id = params[:id]
139
149
  element.save!
140
150
  end
141
- when 'ChoiceField'
151
+ when 'Fe::ChoiceField'
142
152
  # abort if the element is already in this box
143
- if element.conditional_id == params[:id].to_i
153
+ if element.choice_field_id == params[:id].to_i
144
154
  render :nothing => true
145
155
  else
146
- element.conditional_id = params[:id]
156
+ element.choice_field_id = params[:id]
147
157
  element.save!
148
158
  end
149
159
  end
150
160
  # Remove page element for this page since it's now in a grid
151
161
  Fe::PageElement.where(:page_id => @page.id, :element_id => element.id).first.try(:destroy)
152
162
  end
153
-
163
+
154
164
  def remove_from_grid
155
- element = Fe::Element.find(params[:id])
165
+ element = @page.all_elements.find(params[:id])
156
166
  Fe::PageElement.create(:element_id => element.id, :page_id => @page.id) unless Fe::PageElement.where(:element_id => element.id, :page_id => @page.id).first
157
167
  if element.question_grid_id
158
- element.set_position(element.question_grid.position(@page), @page)
168
+ element.set_position(element.question_grid.position(@page), @page)
159
169
  element.question_grid_id = nil
160
170
  elsif element.choice_field_id
161
- element.set_position(element.choice_field.position(@page), @page)
171
+ element.set_position(element.choice_field.position(@page), @page)
162
172
  element.choice_field_id = nil
163
173
  end
164
174
  element.save!
165
175
  render :action => :drop
166
176
  end
167
-
177
+
168
178
  def duplicate
169
- element = Fe::Element.find(params[:id])
170
- @element = element.duplicate(@page, element.question_grid || element.choice_field)
179
+ element = @page.all_elements.find(params[:id])
180
+ @element = element.duplicate(@page, element.question_grid || element.question_grid_with_total || element.choice_field)
171
181
  respond_to do |format|
172
- format.js
182
+ format.js
173
183
  end
174
184
  end
175
-
185
+
176
186
  private
177
187
  def get_page
178
188
  @page = Fe::Page.find(params[:page_id])
179
189
  end
180
190
 
181
191
  def element_params
182
- params.fetch(:element, {}).permit(:style, :label, :tooltip, :position, :source, :value_xpath, :text_xpath, :question_grid_id, :cols, :total_cols, :css_id, :css_class, :related_question_sheet_id, :conditional_id, :hide_option_labels, :slug, :required, :is_confidential, :hide_label, :object_name, :attribute_name, :max_length, :content, :conditional_type, :conditional_id, :conditional_answer)
192
+ params.fetch(:element, {}).permit({label_translations: Fe::LANGUAGES.keys}, {tip_translations: Fe::LANGUAGES.keys}, {content_translations: Fe::LANGUAGES.keys},
193
+ :style, :label, :tooltip,
194
+ :position, :source, :value_xpath,
195
+ :text_xpath, :question_grid_id, :cols, :total_cols, :css_id, :css_class,
196
+ :related_question_sheet_id, :conditional_id, :hide_option_labels, :slug,
197
+ :required, :is_confidential, :hide_label, :object_name, :attribute_name,
198
+ :max_length, :content, :conditional_type, :conditional_id, :conditional_answer)
183
199
  end
184
200
 
185
201
  end
@@ -31,7 +31,7 @@ class Fe::Admin::EmailTemplatesController < ApplicationController
31
31
 
32
32
  respond_to do |format|
33
33
  if @email_template.save
34
- format.html { redirect_to admin_email_templates_path }
34
+ format.html { redirect_to fe_admin_email_templates_path }
35
35
  else
36
36
  format.html { render :action => :new }
37
37
  end
@@ -55,7 +55,7 @@ class Fe::Admin::EmailTemplatesController < ApplicationController
55
55
  @email_template.destroy
56
56
 
57
57
  respond_to do |format|
58
- format.html { redirect_to email_templates_path }
58
+ format.html { redirect_to fe_admin_email_templates_path }
59
59
  end
60
60
  end
61
61
 
@@ -108,6 +108,6 @@ class Fe::Admin::QuestionPagesController < ApplicationController
108
108
  end
109
109
 
110
110
  def page_params
111
- params.fetch(:fe_page, {}).permit(:label, :hidden, :no_cache)
111
+ params.fetch(:fe_page, {}).permit({label_translations: Fe::LANGUAGES.keys}, :label, :hidden, :no_cache)
112
112
  end
113
113
  end
@@ -1,107 +1,6 @@
1
1
  # QuestionSheets is used exclusively on the administration side to design a Questionniare
2
2
  # which can than be instantiated as an AnswerSheet for data capture on the front-end
3
-
4
3
  class Fe::Admin::QuestionSheetsController < ApplicationController
5
- before_filter :check_valid_user
6
- before_filter :get_question_sheet, :only => [:show, :archive, :unarchive, :destroy, :edit, :update, :duplicate]
7
- layout 'fe/fe.admin'
8
-
9
- # list of all questionnaires/forms to edit
10
- # GET /question_sheets
11
- def index
12
- @active_question_sheets = Fe::QuestionSheet.active.order('label')
13
- @archived_question_sheets = Fe::QuestionSheet.archived.order('label')
14
-
15
- respond_to do |format|
16
- format.html # index.rhtml
17
- format.xml { render :xml => @question_sheets.to_xml }
18
- end
19
- end
20
-
21
- def archive
22
- @question_sheet.update_attribute(:archived, true)
23
- redirect_to :back
24
- end
25
-
26
- def unarchive
27
- @question_sheet.update_attribute(:archived, false)
28
- redirect_to :back
29
- end
30
-
31
- def duplicate
32
- @question_sheet.duplicate
33
- redirect_to :back
34
- end
35
-
36
- # entry point: display form designer with page 1 and panels loaded
37
- # GET /question_sheets/1
38
- def show
39
- @all_pages = @question_sheet.pages
40
- @page = @all_pages[0]
41
-
42
- respond_to do |format|
43
- format.html # show.rhtml
44
- format.xml { render :xml => @question_sheet.to_xml }
45
- end
46
- end
47
-
48
- # create sheet with inital page, redirect to show
49
- # POST /question_sheets
50
- def create
51
- @question_sheet = Fe::QuestionSheet.new_with_page
52
-
53
- respond_to do |format|
54
- if @question_sheet.save
55
- format.html { redirect_to fe_admin_question_sheet_path(@question_sheet) }
56
- format.xml { head :created, :location => admin_question_sheet_path(@question_sheet) }
57
- else
58
- format.html { render :action => "new" }
59
- format.xml { render :xml => @question_sheet.errors.to_xml }
60
- end
61
- end
62
- end
63
-
64
-
65
- # display sheet properties panel
66
- # GET /question_sheets/1/edit
67
- def edit
68
-
69
- respond_to do |format|
70
- format.js
71
- end
72
- end
73
-
74
- # save changes to properties panel (label, language)
75
- # PUT /question_sheets/1
76
- def update
77
- params.require(:fe_question_sheet).permit!
78
-
79
- respond_to do |format|
80
- if @question_sheet.update_attributes(params[:fe_question_sheet])
81
- format.html { redirect_to fe_admin_question_sheet_path(@question_sheet) }
82
- format.js
83
- format.xml { head :ok }
84
- else
85
- format.html { render :action => "edit" }
86
- format.js { render :action => "error.rjs"}
87
- format.xml { render :xml => @question_sheet.errors.to_xml }
88
- end
89
- end
90
- end
91
-
92
- # mark sheet as destroyed
93
- # DELETE /question_sheets/1
94
- def destroy
95
- @question_sheet.destroy
96
-
97
- respond_to do |format|
98
- format.html { redirect_to fe_admin_question_sheets_path }
99
- format.xml { head :ok }
100
- end
101
- end
102
-
103
- protected
104
- def get_question_sheet
105
- @question_sheet = Fe::QuestionSheet.find(params[:id])
106
- end
4
+ include Fe::Admin::QuestionSheetsControllerConcern
107
5
  end
6
+