surveyor_gui 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +44 -0
  3. data/.travis.yml +17 -0
  4. data/Gemfile +7 -0
  5. data/LICENSE +21 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +159 -0
  8. data/Rakefile +66 -0
  9. data/app/controllers/answers_controller.rb +3 -0
  10. data/app/controllers/application_controller.rb +3 -0
  11. data/app/controllers/dependencys_controller.rb +286 -0
  12. data/app/controllers/question_groups_controller.rb +84 -0
  13. data/app/controllers/questions_controller.rb +187 -0
  14. data/app/controllers/survey_sections_controller.rb +80 -0
  15. data/app/controllers/surveyforms_controller.rb +4 -0
  16. data/app/controllers/surveyor_controller.rb +89 -0
  17. data/app/controllers/surveyor_gui/reports_controller.rb +339 -0
  18. data/app/controllers/surveyor_gui/responses_controller.rb +39 -0
  19. data/app/controllers/surveyor_gui/survey_controller.rb +16 -0
  20. data/app/facades/report_formatter.rb +44 -0
  21. data/app/facades/report_preview_wrapper.rb +11 -0
  22. data/app/facades/report_response_generator.rb +147 -0
  23. data/app/helpers/application_helper.rb +2 -0
  24. data/app/helpers/dependency_helper.rb +5 -0
  25. data/app/helpers/question_helper.rb +22 -0
  26. data/app/helpers/surveyform_helper.rb +179 -0
  27. data/app/helpers/surveyor_gui/report_helper.rb +19 -0
  28. data/app/helpers/surveyor_helper.rb +4 -0
  29. data/app/inputs/currency_input.rb +5 -0
  30. data/app/inputs/date_picker_input.rb +7 -0
  31. data/app/inputs/datetime_picker_input.rb +5 -0
  32. data/app/inputs/percent_input.rb +5 -0
  33. data/app/inputs/time_picker_input.rb +5 -0
  34. data/app/mailers/.gitkeep +0 -0
  35. data/app/models/.gitkeep +0 -0
  36. data/app/models/answer.rb +4 -0
  37. data/app/models/column.rb +3 -0
  38. data/app/models/dependency.rb +4 -0
  39. data/app/models/dependency_condition.rb +4 -0
  40. data/app/models/permitted_params_decorator.rb +80 -0
  41. data/app/models/question.rb +4 -0
  42. data/app/models/question_group.rb +4 -0
  43. data/app/models/question_type.rb +7 -0
  44. data/app/models/response.rb +4 -0
  45. data/app/models/response_set.rb +4 -0
  46. data/app/models/row.rb +3 -0
  47. data/app/models/survey.rb +4 -0
  48. data/app/models/survey_section.rb +4 -0
  49. data/app/models/surveyform.rb +103 -0
  50. data/app/uploaders/blob_uploader.rb +48 -0
  51. data/app/views/dependencys/_column.html.erb +1 -0
  52. data/app/views/dependencys/_dependency.html.erb +22 -0
  53. data/app/views/dependencys/_dependency_condition_fields.html.erb +48 -0
  54. data/app/views/dependencys/_form.html.erb +20 -0
  55. data/app/views/dependencys/blank.html.erb +0 -0
  56. data/app/views/dependencys/edit.html.erb +1 -0
  57. data/app/views/dependencys/new.html.erb +1 -0
  58. data/app/views/layouts/application.html.erb +14 -0
  59. data/app/views/layouts/surveyor_gui_blank.html.erb +12 -0
  60. data/app/views/layouts/surveyor_gui_default.html.erb +16 -0
  61. data/app/views/layouts/surveyor_modified.html.erb +14 -0
  62. data/app/views/partials/_answer.html.haml +33 -0
  63. data/app/views/partials/_question.html.haml +33 -0
  64. data/app/views/partials/_question_group.html.haml +73 -0
  65. data/app/views/partials/_section.html.haml +13 -0
  66. data/app/views/question_groups/_form.html.erb +56 -0
  67. data/app/views/question_groups/_group_inline_field.html.erb +21 -0
  68. data/app/views/question_groups/_group_inline_fields.html.erb +25 -0
  69. data/app/views/question_groups/blank.html.erb +0 -0
  70. data/app/views/question_groups/edit.html.erb +1 -0
  71. data/app/views/question_groups/new.html.erb +1 -0
  72. data/app/views/questions/_answer_fields.html.erb +23 -0
  73. data/app/views/questions/_answer_options.html.erb +28 -0
  74. data/app/views/questions/_form.html.erb +65 -0
  75. data/app/views/questions/_grid_dropdown_columns.html.erb +10 -0
  76. data/app/views/questions/_grid_dropdown_fields.html.erb +42 -0
  77. data/app/views/questions/_grid_fields.html.erb +9 -0
  78. data/app/views/questions/_no_picks.html.erb +29 -0
  79. data/app/views/questions/_pick.html +21 -0
  80. data/app/views/questions/_picks.html.erb +12 -0
  81. data/app/views/questions/blank.html.erb +0 -0
  82. data/app/views/questions/edit.html.erb +1 -0
  83. data/app/views/questions/new.html.erb +1 -0
  84. data/app/views/survey_sections/_form.html.erb +13 -0
  85. data/app/views/survey_sections/blank.html.erb +0 -0
  86. data/app/views/survey_sections/edit.html.erb +1 -0
  87. data/app/views/survey_sections/new.html.erb +1 -0
  88. data/app/views/surveyforms/_form.html.erb +50 -0
  89. data/app/views/surveyforms/_question_field.html.erb +148 -0
  90. data/app/views/surveyforms/_question_group.html.erb +116 -0
  91. data/app/views/surveyforms/_question_group_fields.html.erb +3 -0
  92. data/app/views/surveyforms/_question_name_and_number.html.erb +6 -0
  93. data/app/views/surveyforms/_question_section.html.erb +15 -0
  94. data/app/views/surveyforms/_question_wrapper.html.erb +109 -0
  95. data/app/views/surveyforms/_survey_section_fields.html.erb +138 -0
  96. data/app/views/surveyforms/clone_survey.html.erb +13 -0
  97. data/app/views/surveyforms/edit.html.erb +5 -0
  98. data/app/views/surveyforms/index.html.erb +40 -0
  99. data/app/views/surveyforms/new.html.erb +1 -0
  100. data/app/views/surveyforms/show.html.erb +5 -0
  101. data/app/views/surveyor_gui/reports/_graphs.html.haml +21 -0
  102. data/app/views/surveyor_gui/reports/_grid.html.haml +42 -0
  103. data/app/views/surveyor_gui/reports/_grid_dropdown.html.haml +56 -0
  104. data/app/views/surveyor_gui/reports/_repeater.html.haml +28 -0
  105. data/app/views/surveyor_gui/reports/_show_report.html.haml +33 -0
  106. data/app/views/surveyor_gui/reports/_single_question.html.haml +70 -0
  107. data/app/views/surveyor_gui/reports/show.html.erb +14 -0
  108. data/app/views/surveyor_gui/responses/_grid.html.haml +20 -0
  109. data/app/views/surveyor_gui/responses/_grid_dropdown.html.haml +20 -0
  110. data/app/views/surveyor_gui/responses/_repeater.html.haml +22 -0
  111. data/app/views/surveyor_gui/responses/_survey_results.html.haml +40 -0
  112. data/app/views/surveyor_gui/responses/index.html.haml +24 -0
  113. data/app/views/surveyor_gui/responses/show.html.haml +42 -0
  114. data/app/views/surveyor_gui/shared/_grid_comments.html.haml +10 -0
  115. data/app/views/surveyor_gui/shared/_new_line.html.haml +2 -0
  116. data/app/views/surveyor_gui/shared/_pick_comments.html.haml +15 -0
  117. data/app/views/surveyor_gui/shared/_question_number.html.haml +9 -0
  118. data/app/views/surveyor_gui/shared/_report_data.html.haml +24 -0
  119. data/app/views/surveyor_gui/shared/_stars_report_data.html.haml +14 -0
  120. data/config.ru +4 -0
  121. data/config/environment.rb +0 -0
  122. data/config/routes.rb +71 -0
  123. data/db/migrate/20140307204049_add_template_to_surveys.rb +5 -0
  124. data/db/migrate/20140307235607_add_test_data_to_response_sets.rb +5 -0
  125. data/db/migrate/20140308171947_add_original_choice_to_answers.rb +5 -0
  126. data/db/migrate/20140308172118_add_blob_to_responses.rb +5 -0
  127. data/db/migrate/20140308172417_add_modifiable_to_survey_section.rb +5 -0
  128. data/db/migrate/20140308174532_add_modifiable_to_question.rb +5 -0
  129. data/db/migrate/20140308175305_add_dynamically_generate_to_questions.rb +5 -0
  130. data/db/migrate/20140311032923_add_dummy_blob_to_questions.rb +5 -0
  131. data/db/migrate/20140311160609_add_dynamic_source_to_questions.rb +5 -0
  132. data/db/migrate/20140311161714_add_report_code_to_questions.rb +5 -0
  133. data/db/migrate/20140530181134_add_is_comment_to_questions.rb +5 -0
  134. data/db/migrate/20140531012006_add_is_comment_to_answers.rb +5 -0
  135. data/db/migrate/20140531225529_create_rows.rb +9 -0
  136. data/db/migrate/20140601011151_create_columns.rb +11 -0
  137. data/db/migrate/20140602030330_add_column_id_to_answers.rb +5 -0
  138. data/db/migrate/20140603155606_add_column_id_to_responses.rb +5 -0
  139. data/db/migrate/20140606023527_add_column_id_to_dependency_conditions.rb +5 -0
  140. data/db/migrate/20140815165307_add_user_id_to_survey.rb +5 -0
  141. data/lib/assets/.gitkeep +0 -0
  142. data/lib/assets/images/addicon.png +0 -0
  143. data/lib/assets/images/datepicker.gif +0 -0
  144. data/lib/assets/images/delete.gif +0 -0
  145. data/lib/assets/images/delete.png +0 -0
  146. data/lib/assets/images/images/border.png +0 -0
  147. data/lib/assets/images/images/controls.png +0 -0
  148. data/lib/assets/images/images/loading.gif +0 -0
  149. data/lib/assets/images/images/loading_background.png +0 -0
  150. data/lib/assets/images/images/overlay.png +0 -0
  151. data/lib/assets/images/rails.png +0 -0
  152. data/lib/assets/images/star.gif +0 -0
  153. data/lib/assets/javascripts/.gitkeep +0 -0
  154. data/lib/assets/javascripts/surveyor_gui/jquery.MetaData.js +121 -0
  155. data/lib/assets/javascripts/surveyor_gui/jquery.blockUI.js +619 -0
  156. data/lib/assets/javascripts/surveyor_gui/jquery.rating.js +377 -0
  157. data/lib/assets/javascripts/surveyor_gui/jquery.validate.js +1188 -0
  158. data/lib/assets/javascripts/surveyor_gui/surveyor_add_ons.js +10 -0
  159. data/lib/assets/javascripts/surveyor_gui/surveyor_gui.js +1417 -0
  160. data/lib/assets/stylesheets/.gitkeep +0 -0
  161. data/lib/assets/stylesheets/surveyor_gui/jquery.rating.css +12 -0
  162. data/lib/assets/stylesheets/surveyor_gui/surveyor_add_ons.css +3 -0
  163. data/lib/assets/stylesheets/surveyor_gui/surveyor_gui.sass +650 -0
  164. data/lib/enumerable_extenders.rb +31 -0
  165. data/lib/generators/surveyor_gui/install_generator.rb +57 -0
  166. data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_add_ons.js +2 -0
  167. data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_gui_all.js +24 -0
  168. data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_add_ons.css.sass +1 -0
  169. data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_gui_all.css.sass +8 -0
  170. data/lib/generators/surveyor_gui/templates/app/helpers/surveyor_helper.rb +4 -0
  171. data/lib/generators/surveyor_gui/templates/app/models/response_set_user.rb +13 -0
  172. data/lib/generators/surveyor_gui/templates/app/views/layouts/surveyor_gui_default.html.erb +16 -0
  173. data/lib/generators/surveyor_gui/templates/config/initializers/simple_form.rb +140 -0
  174. data/lib/generators/surveyor_gui/templates/config/locales/en.yml +5 -0
  175. data/lib/surveyor_gui.rb +17 -0
  176. data/lib/surveyor_gui/engine.rb +30 -0
  177. data/lib/surveyor_gui/helpers/surveyor_helper_methods.rb +19 -0
  178. data/lib/surveyor_gui/models/answer_methods.rb +24 -0
  179. data/lib/surveyor_gui/models/column_methods.rb +43 -0
  180. data/lib/surveyor_gui/models/dependency_condition_methods.rb +53 -0
  181. data/lib/surveyor_gui/models/dependency_methods.rb +83 -0
  182. data/lib/surveyor_gui/models/question_and_group_shared_methods.rb +11 -0
  183. data/lib/surveyor_gui/models/question_group_methods.rb +55 -0
  184. data/lib/surveyor_gui/models/question_methods.rb +435 -0
  185. data/lib/surveyor_gui/models/question_type_methods.rb +493 -0
  186. data/lib/surveyor_gui/models/response_methods.rb +67 -0
  187. data/lib/surveyor_gui/models/response_set_methods.rb +54 -0
  188. data/lib/surveyor_gui/models/row_methods.rb +11 -0
  189. data/lib/surveyor_gui/models/survey_methods.rb +32 -0
  190. data/lib/surveyor_gui/models/survey_section_methods.rb +32 -0
  191. data/lib/surveyor_gui/surveyforms_controller_methods.rb +258 -0
  192. data/lib/surveyor_gui/version.rb +3 -0
  193. data/lib/tasks/.gitkeep +0 -0
  194. data/lib/tasks/surveyor_gui_tasks.rake +4 -0
  195. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  196. data/spec/controllers/surveyforms_controller_spec.rb +361 -0
  197. data/spec/controllers/surveyor_controller_spec.rb +303 -0
  198. data/spec/factories.rb +181 -0
  199. data/spec/features/create_survey_spec.rb +418 -0
  200. data/spec/features/dependencies_spec.rb +61 -0
  201. data/spec/features/rearrange_survey_spec.rb +118 -0
  202. data/spec/features/ui_spec.rb +469 -0
  203. data/spec/fixtures/REDCapDemoDatabase_DataDictionary.csv +127 -0
  204. data/spec/fixtures/chinese_survey.rb +14 -0
  205. data/spec/fixtures/everything.rb +215 -0
  206. data/spec/fixtures/favorites-ish.rb +22 -0
  207. data/spec/fixtures/favorites.rb +22 -0
  208. data/spec/fixtures/feelings.rb +38 -0
  209. data/spec/fixtures/lifestyle.rb +55 -0
  210. data/spec/fixtures/numbers.rb +21 -0
  211. data/spec/fixtures/redcap_new_headers.csv +1 -0
  212. data/spec/fixtures/redcap_siblings.csv +1 -0
  213. data/spec/fixtures/redcap_whitespace.csv +1 -0
  214. data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
  215. data/spec/helpers/surveyor_helper_spec.rb +116 -0
  216. data/spec/lib/common_spec.rb +37 -0
  217. data/spec/lib/parser_spec.rb +393 -0
  218. data/spec/lib/rake_kitchen_sink.rb +42 -0
  219. data/spec/lib/redcap_parser_spec.rb +129 -0
  220. data/spec/lib/unparser_spec.rb +126 -0
  221. data/spec/models/answer_spec.rb +144 -0
  222. data/spec/models/dependency_condition_spec.rb +428 -0
  223. data/spec/models/dependency_spec.rb +90 -0
  224. data/spec/models/question_group_spec.rb +66 -0
  225. data/spec/models/question_spec.rb +176 -0
  226. data/spec/models/response_set_spec.rb +452 -0
  227. data/spec/models/response_spec.rb +208 -0
  228. data/spec/models/survey_section_spec.rb +58 -0
  229. data/spec/models/survey_spec.rb +155 -0
  230. data/spec/models/surveyor_gui/question_spec.rb +60 -0
  231. data/spec/models/surveyor_gui/question_type_spec.rb +268 -0
  232. data/spec/models/validation_condition_spec.rb +98 -0
  233. data/spec/models/validation_spec.rb +64 -0
  234. data/spec/spec.opts +4 -0
  235. data/spec/spec_helper.rb +119 -0
  236. data/spec/support/scenario_outline_helper.rb +39 -0
  237. data/spec/support/shared.rb +10 -0
  238. data/spec/support/surveyforms_creation_helpers.rb +312 -0
  239. data/spec/support/surveyforms_rearrangement_helpers.rb +170 -0
  240. data/spec/support/surveyor_api_helpers.rb +15 -0
  241. data/spec/support/surveyor_ui_helpers.rb +108 -0
  242. data/spec/support/wait_for_ajax.rb +11 -0
  243. data/spec/views/questions/edit.html.erb_spec.rb +73 -0
  244. data/spec/views/surveyforms/edit.html.erb_spec.rb +126 -0
  245. data/surveyor_gui.gemspec +52 -0
  246. data/test/dummy/README.rdoc +261 -0
  247. data/test/dummy/Rakefile +7 -0
  248. data/test/dummy/app/assets/javascripts/application.js +15 -0
  249. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  250. data/test/dummy/app/controllers/application_controller.rb +3 -0
  251. data/test/dummy/app/helpers/application_helper.rb +2 -0
  252. data/test/dummy/app/mailers/.gitkeep +0 -0
  253. data/test/dummy/app/models/.gitkeep +0 -0
  254. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  255. data/test/dummy/config.ru +4 -0
  256. data/test/dummy/config/application.rb +59 -0
  257. data/test/dummy/config/boot.rb +10 -0
  258. data/test/dummy/config/database.yml +25 -0
  259. data/test/dummy/config/environment.rb +5 -0
  260. data/test/dummy/config/environments/development.rb +37 -0
  261. data/test/dummy/config/environments/production.rb +67 -0
  262. data/test/dummy/config/environments/test.rb +37 -0
  263. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  264. data/test/dummy/config/initializers/inflections.rb +15 -0
  265. data/test/dummy/config/initializers/mime_types.rb +5 -0
  266. data/test/dummy/config/initializers/secret_token.rb +7 -0
  267. data/test/dummy/config/initializers/session_store.rb +8 -0
  268. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  269. data/test/dummy/config/locales/en.yml +5 -0
  270. data/test/dummy/config/routes.rb +58 -0
  271. data/test/dummy/lib/assets/.gitkeep +0 -0
  272. data/test/dummy/log/.gitkeep +0 -0
  273. data/test/dummy/public/404.html +26 -0
  274. data/test/dummy/public/422.html +26 -0
  275. data/test/dummy/public/500.html +25 -0
  276. data/test/dummy/public/favicon.ico +0 -0
  277. data/test/dummy/script/rails +6 -0
  278. data/test/surveyor-gui_test.rb +7 -0
  279. data/test/test_helper.rb +15 -0
  280. data/vendor/assets/stylesheets/.gitkeep +0 -0
  281. data/vendor/assets/stylesheets/custom.sass +5 -0
  282. data/vendor/plugins/.gitkeep +0 -0
  283. metadata +664 -0
@@ -0,0 +1,10 @@
1
+
2
+ ( function($) {
3
+ $(document).ready(function() {
4
+ //modifiers for surveyor form
5
+ $('.q_stars').find('input[type=radio]').rating();
6
+ //end surveyor modifiers
7
+
8
+ });
9
+
10
+ } ) ( jQuery );
@@ -0,0 +1,1417 @@
1
+ ( function($) {
2
+ $(document).ready(function() {
3
+ application_js_code();
4
+ });
5
+
6
+ } ) ( jQuery );
7
+
8
+ function application_js_code(){
9
+
10
+ // jquery_trigger_ready.js
11
+ // this function is added to jQuery, it allows access to the readylist
12
+ // it works for jQuery 1.3.2, it might break on future versions
13
+ // if (!Modernizr.input.required) {
14
+ $.ajaxSetup({
15
+ headers: {
16
+ 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
17
+ }
18
+ });
19
+
20
+ $('[required="required"]').addClass('required');
21
+ $.validator.addMethod('require-check',
22
+ function (value,element) {
23
+ return $(element).closest('ol').find('.require-check:checked').size() > 0;
24
+ },
25
+ 'Please check at least one box.'
26
+ );
27
+ $.validator.addMethod('uislider',
28
+ function (value,element) {
29
+ return $(element).val() != null;
30
+ },
31
+ 'Please make a choice.'
32
+ );
33
+ $('form').each(function(){
34
+ $(this).validate({
35
+ ignore:':not(input[class*="star-rating-applied"], select[class*="uislider"]):hidden',
36
+ groups: getGroups(),
37
+ errorPlacement: function(error, element) {
38
+ if (element.attr("type") === "checkbox" )
39
+ error.insertAfter($(element).closest('ol').find('li').last());
40
+ else if(element.attr("type") === "radio") {
41
+ if (element.is('.star-rating-applied'))
42
+ error.insertAfter($(element).closest('ol'));
43
+ else
44
+ error.insertAfter($(element).closest('ol').find('li').last());
45
+ }
46
+ else if (element.is('.uislider'))
47
+ error.insertAfter($(element).closest('ol'));
48
+ else
49
+ error.insertAfter(element);
50
+ }
51
+ });
52
+ });
53
+
54
+ $.blockUI.defaults.css = {
55
+ padding: 0,
56
+ margin: 0,
57
+ width: '100px',
58
+ top: '40%',
59
+ left: '35%',
60
+ textAlign: 'center',
61
+ color: '#000',
62
+ border: 'none',
63
+ backgroundColor:'#fff',
64
+ cursor: 'wait'
65
+ };
66
+
67
+ $(document).bind('cbox_open', function(){
68
+ if($(parent.$.find('input#pass_cbox_data')).length>0) {
69
+ $(parent.$.find('input#pass_cbox_data')).val('false');
70
+ }
71
+ });
72
+ $(document).on("click", "#survey_section_submit, #question_submit, #question_group_submit, #dependency_submit", function(event) {
73
+ //pass_cbox_data is a div at the top of /views/surveyforms/_form.html.erb
74
+ $(parent.$.find('input#pass_cbox_data')).val('true');
75
+ });
76
+ $(document).on('ajaxComplete', 'form.question, form.survey_section, form.dependency, form.edit_survey_section', function(event) {
77
+ if ($("#errorExplanation").length===0){
78
+ if($(parent.$.find('input#pass_cbox_data')).length>0) {
79
+ if($(parent.$.find('input#pass_cbox_data')).val()==='true'){
80
+ parent.$.fn.colorbox.close();
81
+ }
82
+ }
83
+ }
84
+ else {
85
+ $(parent.$.find('input#pass_cbox_data')).val('false');
86
+ }
87
+ });
88
+
89
+ $(window).load(function() {
90
+ if ($("#errorExplanation").length===0){
91
+ if($(parent.$.find('input#pass_cbox_data')).length>0) {
92
+ if($(parent.$.find('input#pass_cbox_data')).val()==='true'){
93
+ parent.$.fn.colorbox.close();
94
+ }
95
+ }
96
+ }
97
+ else {
98
+ $(parent.$.find('input#pass_cbox_data')).val('false');
99
+ }
100
+ var isInIFrame = (window.location != window.parent.location) ? true : false;
101
+ if(isInIFrame) {
102
+ $('body').css({background:'#f3f3f3'});
103
+ }
104
+ });
105
+
106
+
107
+ $(document).on('click', '#edit_section_title', function() {
108
+ var edit_survey_section_url = $(this).data('edit_survey_section_url');
109
+ var replace_survey_section_url = $(this).data('replace_survey_section_url');
110
+ var survey_section_id = $(this).data('survey_section_id');
111
+ $.colorbox({
112
+ width:"40%",
113
+ height:"30%",
114
+ scrolling:false,
115
+ iframe:true,
116
+ onClosed:function(){
117
+ submitted = $("input#pass_cbox_data").val();
118
+ if (submitted) {
119
+ $.get(replace_survey_section_url,
120
+ {},
121
+ function(response){
122
+ $("#survey_section_"+survey_section_id).html(replace_idx($("#survey_section_"+survey_section_id),"survey_sections", response));
123
+ refresh_stars();
124
+ }
125
+ );
126
+ };
127
+ },
128
+ href: edit_survey_section_url,
129
+ opacity:.3
130
+ });
131
+ });
132
+
133
+ $(document).on('click', '#delete_section', function() {
134
+ var survey_section_url = $(this).data('survey_section_url');
135
+ var survey_section_id = $(this).data('survey_section_id');
136
+ $.ajax({
137
+ type: "DELETE",
138
+ url: survey_section_url,
139
+ success: function(msg){
140
+ if (typeof msg !== undefined && msg.length>0) {
141
+ alert(msg);
142
+ }
143
+ else {
144
+ $("#survey_section_"+survey_section_id).remove();
145
+ update_question_numbers();
146
+ update_dependency_questions();
147
+ }
148
+ }
149
+ });
150
+ });
151
+
152
+
153
+ $(document).on('click', '#add_question', function() {
154
+ var insert_new_question_url = $(this).data('insert_new_question_url');
155
+ var new_question_url = $(this).data('new_question_url');
156
+ var survey_section_id = $(this).parents("div.survey_section").find("input[id$=\'id\']").first().val()
157
+ var prev_question_id = $(this).data('prev_question_id');
158
+ var question_id = null;
159
+ //provides a way to check that this function is complete in tests. It disappears on complete when
160
+ //the contents of div#box are replaced.
161
+ $('div#box').addClass('jquery_add_question_started');
162
+ $.colorbox({
163
+ width:"850px",
164
+ height:"772px",
165
+ scrolling:true,
166
+ iframe:true,
167
+ onCleanup:function(){
168
+ $("#cboxLoadedContent iframe").load(function(){
169
+ question_id = $("iframe.cboxIframe").contents().find("#cboxQuestionId").html();
170
+ });
171
+ },
172
+ onClosed:function(){
173
+ submitted = $("input#pass_cbox_data").val();
174
+ if (submitted==="true") {
175
+ $.get(insert_new_question_url+"?question_id="+question_id,
176
+ {},
177
+ function(response) {
178
+ replace_surveyform_contents(response);
179
+ }
180
+ );
181
+ }
182
+ },
183
+ href: new_question_url+'?survey_section_id='+survey_section_id+(prev_question_id ? '&prev_question_id='+prev_question_id : ''),
184
+ opacity:.3}
185
+ );
186
+ });
187
+
188
+ $(document).on('click', '#add_section', function() {
189
+ var insert_survey_section_url = $(this).data('insert_survey_section_url');
190
+ var new_survey_section_url = $(this).data('new_survey_section_url');
191
+ var survey_section_id = $(this).data('survey_section_id');
192
+ var survey_id = $(this).data('survey_id');
193
+ //provides a way to check that this function is complete in tests. It disappears on complete when
194
+ //the contents of div#box are replaced.
195
+ $('div#box').addClass('jquery_add_section_started');
196
+ $.colorbox({width:"517px;",
197
+ height:"167px;",
198
+ scrolling:false,
199
+ iframe:true,
200
+ onClosed:function(){
201
+ submitted = $("input#pass_cbox_data").val();
202
+ if (submitted) {
203
+ $.get(insert_survey_section_url,
204
+ {},
205
+ function(response) {
206
+ $("#survey_section_"+survey_section_id).after(replace_idx($(".survey_section"),"survey_sections", response));
207
+ $('div#box').removeClass('jquery_add_section_started');
208
+ }
209
+ );
210
+ }
211
+ },
212
+ href: new_survey_section_url+'?prev_section_id='+survey_section_id+'&suppress_header=true&survey_id='+survey_id,
213
+ opacity:.3
214
+ });
215
+ });
216
+
217
+ $(document).on('click', '#edit_question', function() {
218
+ var replace_question_url = $(this).data('replace_question_url');
219
+ var edit_question_url = $(this).data('edit_question_url');
220
+ var survey_section_id = $(this).closest('.survey_section').find('input#surveyform_survey_sections_attributes_0_id').val();
221
+ var question_id = $(this).data('question_id');
222
+ $.colorbox({
223
+ width:"850px",
224
+ height:"772px",
225
+ scrolling:true,
226
+ iframe:true,
227
+ onClosed:function(){
228
+ submitted = $("input#pass_cbox_data").val();
229
+ if (submitted) {
230
+ $.get(replace_question_url,
231
+ {},
232
+ function(response) {
233
+ if (response=="not found"){
234
+ $.get("/surveyforms/"+survey_section_id+"/replace_survey_section?survey_section_id="+survey_section_id,
235
+ {},
236
+ function(response){
237
+ $("#survey_section_"+survey_section_id).html(replace_idx($("#survey_section_"+survey_section_id),"survey_sections", response));
238
+ refresh_stars();
239
+ }
240
+ );
241
+ }
242
+ else {
243
+ $("#question_"+question_id).html(replace_idx($("#question_"+question_id),"questions", response));
244
+ refresh_stars();
245
+ $("#question_"+question_id).update_single_uislider();
246
+ update_question_numbers();
247
+ }
248
+ }
249
+ );
250
+ };
251
+ },
252
+ href: edit_question_url,
253
+ opacity:.3
254
+ });
255
+ });
256
+
257
+ $(document).on('click', '#cut_section', function() {
258
+ var cut_section_surveyform_url = $(this).data('cut_section_surveyform_url');
259
+ var section_already_cut = $(this).data('section_already_cut');
260
+ //provides a way to check that this function is complete in tests. It disappears on complete when
261
+ //the contents of div#box are replaced.
262
+ $('div#box').addClass('jquery_cut_section_started');
263
+ $.get(cut_section_surveyform_url,
264
+ {},
265
+ function(response) {
266
+ replace_surveyform_contents(response);
267
+ }
268
+ );
269
+ });
270
+
271
+ $(document).on('click', '#paste_section', function() {
272
+ var paste_section_surveyform_url = $(this).data('paste_section_surveyform_url');
273
+ //provides a way to check that this function is complete in tests. It disappears on complete when
274
+ //the contents of div#box are replaced.
275
+ $('div#box').addClass('jquery_paste_section_started');
276
+ $.get(paste_section_surveyform_url,
277
+ {},
278
+ function(response) {
279
+ replace_surveyform_contents(response);
280
+ }
281
+ );
282
+ });
283
+
284
+ $(document).on('click', '#cut_question', function() {
285
+ var cut_question_surveyform_url = $(this).data('cut_question_surveyform_url');
286
+ var question_already_cut = $(this).data('question_already_cut');
287
+ //provides a way to check that this function is complete in tests. It disappears on complete when
288
+ //the contents of div#box are replaced.
289
+ $('div#box').addClass('jquery_cut_question_started');
290
+ $.get(cut_question_surveyform_url,
291
+ {},
292
+ function(response) {
293
+ replace_surveyform_contents(response);
294
+ }
295
+ );
296
+ });
297
+
298
+ $(document).on('click', '#paste_question', function() {
299
+ var paste_question_surveyform_url = $(this).data('paste_question_surveyform_url');
300
+ //provides a way to check that this function is complete in tests. It disappears on complete when
301
+ //the contents of div#box are replaced.
302
+ $('div#box').addClass('jquery_paste_question_started');
303
+ $.get(paste_question_surveyform_url,
304
+ {},
305
+ function(response) {
306
+ replace_surveyform_contents(response);
307
+ }
308
+ );
309
+ });
310
+
311
+ $(document).on('click', '#delete_question', function() {
312
+ var question_url = $(this).data('question_url');
313
+ var replace_form_surveyform_url = $(this).data('replace_form_surveyform_url');
314
+ $.ajax({
315
+ type: "DELETE",
316
+ url: question_url,
317
+ success: function(msg){
318
+ if (typeof msg !== undefined && msg.length>0) {
319
+ alert(msg);
320
+ }
321
+ else {
322
+ $.get(replace_form_surveyform_url,
323
+ {},
324
+ function(response) {
325
+ replace_surveyform_contents(response);
326
+ }
327
+ );
328
+ }
329
+ },
330
+ error: function(){
331
+ alert("This question cannot be deleted.");
332
+ }
333
+ });
334
+ });
335
+
336
+ $(document).on('click', '#edit_logic', function() {
337
+ var replace_question_url = $(this).data('replace_question_url');
338
+ var edit_dependency_url = $(this).data('edit_dependency_url');
339
+ var question_id = $(this).data('question_id');
340
+ $.colorbox({
341
+ width:"98%",
342
+ height:"80%",
343
+ scrolling:true,
344
+ iframe:true,
345
+ onClosed:function(){
346
+ submitted = $("input#pass_cbox_data").val();
347
+ if (submitted) {
348
+
349
+ $.get(replace_question_url,
350
+ {},
351
+ function(response) {
352
+ var question=$("#question_"+question_id).html(replace_idx($("#question_"+question_id),"questions", response));
353
+ refresh_stars(question);
354
+ update_question_numbers();
355
+ }
356
+ );
357
+ };
358
+ },
359
+ href: edit_dependency_url,
360
+ opacity:.3
361
+ });
362
+ });
363
+
364
+ $(document).on('click', '#delete_logic', function() {
365
+ var replace_question_url = $(this).data('replace_question_url');
366
+ var dependency_url = $(this).data('dependency_url');
367
+ var question_id = $(this).data('question_id');
368
+ $.ajax({
369
+ type: "DELETE",
370
+ url: dependency_url,
371
+ success: function(msg){
372
+ $.get(replace_question_url,
373
+ {},
374
+ function(response) {
375
+ var question=$("#question_"+question_id).html(replace_idx($("#question_"+question_id),"questions", response));
376
+ refresh_stars(question);
377
+ update_question_numbers();
378
+ }
379
+ );
380
+ },
381
+ error: function(){
382
+ alert("This logic cannot be deleted.");
383
+ }
384
+ });
385
+ });
386
+
387
+ $(document).on('click', '#add_logic', function() {
388
+ var replace_question_url = $(this).data('replace_question_url');
389
+ var new_dependency_url = $(this).data('new_dependency_url');
390
+ var question_id = $(this).data('question_id');
391
+ $.colorbox({
392
+ width:"98%",
393
+ height:"50%",
394
+ scrolling:true,
395
+ iframe:true,
396
+ onClosed:function(){
397
+ submitted = $("input#pass_cbox_data").val();
398
+ if (submitted) {
399
+ $.get(
400
+ replace_question_url,
401
+ {},
402
+ function(response) {
403
+ var question=$("#question_"+question_id).html(replace_idx($("#question_"+question_id),"questions", response));
404
+ refresh_stars(question);
405
+ update_question_numbers();
406
+ }
407
+ );
408
+ };
409
+ },
410
+ href: new_dependency_url,
411
+ opacity:.3
412
+ });
413
+ });
414
+
415
+ $(document).on('click', '.go_back', function() {
416
+ history.back();
417
+ });
418
+
419
+ sortable_sections_and_questions();
420
+
421
+ $.fn.sortable_answers = function(){
422
+ $('#sortable_answers').sortable({
423
+ axis:"y",
424
+ opacity: 0.6,
425
+ scroll: true,
426
+ update: function(){
427
+ update_answer_display_order();
428
+ }
429
+ });
430
+ };
431
+
432
+
433
+ update_uislider();
434
+ update_datepickers();
435
+
436
+ $.fn.check_dynamic_source = function (){
437
+ if ($(this).closest('#answer_choice').find('input[id^="question_dynamically_generate_true"]').prop('checked')) {
438
+ $(this).closest('div#answer_choice').find('div#dynamic_source').show();
439
+ $(this).closest('div#answer_choice').find('div#fixed_source').hide();
440
+ // $('#question_answers_attributes_0_text').val('String');
441
+ }
442
+ else{
443
+ $(this).closest('div#answer_choice').find('div#dynamic_source').hide();
444
+ $(this).closest('div#answer_choice').find('div#fixed_source').show();
445
+ }
446
+ };
447
+
448
+ $.fn.render_no_picks_partial = function (){
449
+ here = $(this)
450
+ $.get(
451
+ "/question/render_no_picks_partial?id=" + $(this).closest('.questions').find('input#question_id').val(),
452
+ function(data){
453
+ here.html(data);
454
+ }
455
+ );
456
+ }
457
+
458
+ $.fn.render_answer_fields_partial = function (add_row){
459
+ here = $(this);
460
+ if (add_row === true) {
461
+ var option = "&add_row=true";
462
+ }
463
+ else {
464
+ option = ' ';
465
+ }
466
+ $.get(
467
+ "/question/render_answer_fields_partial?id=" + $(this).closest('.questions').find('input#question_id').val() + option,
468
+ function(data){
469
+ if (add_row == true) {
470
+ data = replace_idx($(".question_answers_text"),"answers", data)
471
+ here.append(data);
472
+ }
473
+ else {
474
+ here.html(data);
475
+ }
476
+ here.check_dynamic_source();
477
+ here.sortable_answers();
478
+ }
479
+ );
480
+ }
481
+
482
+ $.fn.render_grid_fields_partial = function (question_type, index){
483
+ here = $(this);
484
+ index = typeof index !== 'undefined' ? index : null;
485
+ $.get(
486
+ "/question/render_grid_partial?id="
487
+ + $(this).closest('.questions').find('input#question_id').val()
488
+ + "&question_type_id="+question_type
489
+ + "&index=" + parseInt(index)
490
+ ,
491
+ function(data){
492
+ here.html(data);
493
+ here.check_dynamic_source();
494
+ here.sortable_answers();
495
+ update_uislider();
496
+ check_dropdown_column_count();
497
+ }
498
+ );
499
+ }
500
+
501
+ function render_question (){
502
+ var here = $('body');
503
+ var survey_section_id = $('input[id$="survey_section_id"]').val();
504
+ var text = $('textarea[id*="question"][id$="_text"]').val();
505
+ var display_order = $('input[id$="display_order"]').last().val();
506
+ var question_id = $('.questions').find('input#question_group_question_id').val()
507
+ var question_type_id = $('div.question_type input[id*="question_type_id"]:checked').val();
508
+ if (question_id != undefined && question_id != "") {
509
+ var question_clause = "/"+question_id+"/edit";
510
+ }
511
+ else
512
+ var question_clause = "/new";
513
+ window.location.href = "/questions"+question_clause +"?survey_section_id="+
514
+ survey_section_id+"&text="+text+
515
+ "&display_order="+display_order +
516
+ "&question_type_id="+question_type_id;
517
+ }
518
+
519
+ function render_question_group (){
520
+ var here = $('body');
521
+ //var original_question_id = $('input[id="question_id"]')
522
+ var survey_section_id = $('input[id$="survey_section_id"]').val();
523
+ var text = $('textarea[id*="question"][id$="_text"]').val();
524
+ var display_order = $('input[id$="display_order"]').last().val();
525
+ var question_id = $('input#question_id').val();
526
+ var question_group_id = $('.questions').find('input[id*="question_group_id"]').val();
527
+ var question_type_id = $('div.question_type input[id*="question_type_id"]:checked').val();
528
+ if (question_group_id != undefined && question_group_id != "") {
529
+ var question_group_clause = "/"+question_group_id+"/edit";
530
+ }
531
+ else
532
+ var question_group_clause = "/new";
533
+
534
+ window.location.href = "/question_groups"+question_group_clause+"?survey_section_id="+
535
+ survey_section_id+"&text="+text+
536
+ "&display_order="+display_order +
537
+ "&question_id="+question_id +
538
+ "&question_type_id="+question_type_id;
539
+
540
+ }
541
+
542
+ $.fn.render_group_inline_fields_partial = function (add_row){
543
+ here = $(this);
544
+ var survey_section_id = $('input#question_group_survey_section_id').val();
545
+ if (add_row === true) {
546
+ var option = "&add_row=true";
547
+ }
548
+ else {
549
+ option = ' ';
550
+ }
551
+ var last_question = $(this).closest('.questions').find('input#question_group_id').first();
552
+ var display_order = (this).closest('.questions').find('input[id$="display_order"]').last().val();
553
+ display_order = parseInt(display_order) + 1;
554
+ $.get(
555
+ "/question_group/render_group_inline_partial?id="
556
+ + last_question.val() +
557
+ "&display_order=" + display_order +
558
+ option,
559
+ function(data){
560
+ if (add_row == true) {
561
+ data = replace_idx($(".group_inline_question"),"questions", data)
562
+ $('.sortable_group_questions').last().after(data);
563
+ }
564
+ else {
565
+ $('#answer_choice').html(data);
566
+ }
567
+ $('.group_inline_question').last().show_group_answers();
568
+ $('.group_inline_question').each(function(){
569
+ $('input[id$="survey_section_id"]').val(survey_section_id);
570
+ });
571
+ update_group_answers();
572
+ sortable_sections_and_questions();
573
+ }
574
+ );
575
+ }
576
+
577
+ //$.fn.render_grid_dropdown_columns = function (i){
578
+ // here = $(this);
579
+ // $.get(
580
+ // "/question/render_grid_dropdown_columns?id="
581
+ // + $(this).closest('.questions').find('input#question_id').val()+
582
+ // "&index=" + parseInt(i) + "&question_type_id='grid_dropdown'",
583
+ // function(data){
584
+ // here.append(data);
585
+ // here.check_dynamic_source();
586
+ // here.sortable_answers();
587
+ // update_uislider();
588
+ // }
589
+ // );
590
+ //}
591
+
592
+ $('#answer_choice').on('click', '.add_answer img', function () {
593
+ $('#sortable_answers').render_answer_fields_partial(true);
594
+ });
595
+
596
+
597
+ $('#answer_choice').on('click','.add_group_inline_question', function() {
598
+ $(this).render_group_inline_fields_partial(true);
599
+ });
600
+
601
+ $.fn.show_answers = function (){
602
+ if ($(this).val()
603
+ in {
604
+ 'pick_one':1,
605
+ 'pick_any':1,
606
+ 'slider':1,
607
+ 'dropdown':1}){
608
+ $('#question_answers_attributes_0_text').val($('#original_choice').data('original_choice'));
609
+ $('#answer_choice').show();
610
+ $(this).check_dynamic_source();
611
+ $(document).on('click','input[id^="question_dynamically_generate"]', function() {
612
+ $(this).check_dynamic_source();
613
+ });
614
+ $('#sortable_answers').render_answer_fields_partial();
615
+ if ($('input[id^="question_dynamically_generate"]:checked').val() in {'t':1,'true':1}){
616
+ $('#fixed_source').hide();
617
+ $('#dynamic_source').show();
618
+ }
619
+ }
620
+ else if ($(this).val() in {'grid_one':1, 'grid_any':1, 'grid_dropdown':1}){
621
+ $('#question_answers_attributes_0_text').val($('#original_choice').data('original_choice'));
622
+ $('#sortable_answers').render_grid_fields_partial((this).val());
623
+ $('#answer_choice').show();
624
+ }
625
+ else if ($(this).val() in {"group_inline":1, "group_default":1, "repeater":1}){
626
+ $('#question_answers_attributes_0_text').val($('#original_choice').data('original_choice'));
627
+ //$('#sortable_answers').render_group_inline_fields_partial((this).val());
628
+ render_question_group();
629
+ }
630
+ else
631
+ {
632
+ $('#answer_choice').hide();
633
+ $('#sortable_answers').html('');
634
+ switch($(this).val)
635
+ {
636
+ case 'Number':
637
+ $('#question_answers_attributes_0_text').val('Float');
638
+ break;
639
+ case 'Text':
640
+ $('#question_answers_attributes_0_text').val('Text');
641
+ break;
642
+ default:
643
+ $('#question_answers_attributes_0_text').val('String');
644
+ }
645
+ }
646
+ };
647
+
648
+ $.fn.show_group_answers = function () {
649
+ if ($(this).val()
650
+ in {
651
+ 'pick_one':1,
652
+ 'pick_any':1,
653
+ 'slider':1,
654
+ 'dropdown':1})
655
+ $(this).closest('.group_inline_question').find('.group_answers_textbox').show();
656
+ else
657
+ $(this).closest('.group_inline_question').find('.group_answers_textbox').hide();
658
+ }
659
+
660
+ $.fn.show_number_questions = function (){
661
+ if ($(this).val() === "number"){
662
+ $('#number_questions').render_no_picks_partial();
663
+ }
664
+ else
665
+ {
666
+ $('#number_questions').html('');
667
+ }
668
+ };
669
+
670
+ function update_group_answers(){
671
+ $('.group_inline_question').on('change', 'select[id^="question_group_questions_attributes_"]', function(){
672
+ $(this).show_group_answers();
673
+ });
674
+ }
675
+
676
+ /*
677
+ $.fn.update_widgets = function(){
678
+ $(this).find('select.uislider').each(function() {
679
+ $(this).selectToUISlider({
680
+ labels:2,
681
+ labelSrc: "text",
682
+ sliderOptions: {
683
+ stop: function(e, ui) { // handle stop sliding event
684
+ $(this).parents('form').trigger('slider_change');
685
+ }
686
+ }
687
+ }).hide();
688
+ });
689
+ $(this).find("input.date_picker").datepicker(
690
+ { duration: 'fast', showOn: 'both', buttonImage: '../../assets/datepicker.gif', buttonImageOnly: true }
691
+ );
692
+ }
693
+ */
694
+ $('input[id^="question_question_type_"],input[id^="question_group_question_type_"]').on('change', function(event){
695
+ if (!($(this).val() in {"group_inline":1,"group_default":1,"repeater":1}) && $('.edit_question_group, .new_question_group').length > 0){
696
+ render_question();
697
+ }
698
+ else {
699
+ $(this).show_answers();
700
+ $(this).show_number_questions();
701
+ }
702
+ });
703
+
704
+ $('.group_inline_question').each( function(){
705
+ $(this).find('select[id$="question_type_id"]').show_group_answers();
706
+ });
707
+ $('.group_inline_question').on('change', 'select[id^="question_group_questions_attributes_"]', function(){
708
+ $(this).show_group_answers();
709
+ });
710
+
711
+
712
+
713
+ $('input[id^="question_question_type_"]:checked').each(function(event){
714
+ $(this).show_number_questions();
715
+ $(this).show_answers();
716
+ });
717
+
718
+ $('input#dependency_submit').on('click').trigger('submit');
719
+
720
+ $('.surveyor_gui_report .report_data_display').hide();
721
+
722
+ $.fn.render_dependency_conditions_partial = function (add_row){
723
+ if ($(this).length > 0) {
724
+ here = $(this);
725
+ if (add_row === true) {
726
+ var option = "&add_row=true";
727
+ }
728
+ else {
729
+ option = ' ';
730
+ }
731
+ $.get(
732
+ "/dependency/render_dependency_conditions_partial?id=" + $(this).data('question_id') +
733
+ "&dependency_id=" + $(this).data('dependency_id') + option,
734
+ function(data){
735
+ if (add_row === true) {
736
+ data = replace_idx($(".question_dependency_dependency_conditions_question_id"),"dependency_conditions", data)
737
+ here.append(data);
738
+ }
739
+ else {
740
+ here.html(data);
741
+ }
742
+ $('select[id*="dependency_conditions_attributes"][id$="question_id"]').each( function() {
743
+ $(this).determine_dependency_question_type();
744
+ });
745
+ $('select[id$="join_operator"]').first().parents('tr').hide();
746
+ }
747
+ );
748
+ }
749
+ }
750
+
751
+ $('#dependency_conditions_partial').render_dependency_conditions_partial();
752
+
753
+ $('div.dependency_editor').on('click', '.add_condition img', function () {
754
+ $(this).closest('div').find('#dependency_conditions_partial').render_dependency_conditions_partial(true);
755
+ });
756
+
757
+
758
+ //when modifying dependency logic, change the answers based on the question selected
759
+ //and change the answer field from a pulldown to an entry field, depending on the question type
760
+ // $('select[id^="question_dependency_attributes_dependency_conditions_attributes"][id$="question_id"]').each( function() {
761
+ // $(this).determine_dependency_question_type();
762
+ // });
763
+ $('.dependency_editor').on('change', 'select[id*="dependency_conditions_attributes"][id$="question_id"]', function(event) {
764
+ $(event.target).determine_dependency_question_type();
765
+ });
766
+ $('.dependency_editor').on('change', 'select[id*="dependency_conditions_attributes"][id$="column_id"]', function(event) {
767
+ $(event.target).refresh_dependency_answers();
768
+ });
769
+
770
+ $('input.autocomplete').each(function(){
771
+ update_autocomplete_idx(this);
772
+ });
773
+
774
+ $("form[id^='survey_form']").find('.filename_with_link').find('a').each(function(){
775
+ var filenamediv = $(this).parent('.filename_with_link');
776
+ //regexp filter finds the input with the correct response id field, e.g. r_4, and extracts the id
777
+ var response_id = $(this).closest('ol').find('input').filter(function() {
778
+ return /r_\d+_id/.test( $(this).attr('id'));
779
+ }).val();
780
+ insert_file_delete_icon(filenamediv,response_id);
781
+ });
782
+
783
+ $('.surveyor_gui_report .show_data').on('click', function(){ show_survey_report_data(); });
784
+ $('.surveyor_gui_report .hide_data').on('click', function(){ hide_survey_report_data(); });
785
+
786
+
787
+ //when uploading a file, modify the view current name and link
788
+ //with new version of jquery, the jquery-ujs iframe call is coming back with an error on json results. Does not seem to affect surveyor.js
789
+ //and cannot figure out how to get the result to return without error.
790
+ //Seems to be interpreted by jquery as an xml result even though its json, and the <textarea> tag seems to throw off the parser.
791
+ $('form').bind("ajax:success, ajax:error", function(){
792
+ if ( $(this).data('remotipartSubmitted') ){
793
+ var object_names=$(this).find('input[type="file"]');
794
+ //if the upload is associated with a survey question, retrieve the response, extract filename, and display it, with a link to view file.
795
+ object_names.each(function(){
796
+ var object_name=$(this).attr('data-object-class');
797
+ var object_id = $(this).attr('id');
798
+ indexRegExp1 = /[0-9]+/g;
799
+ var idx = parseInt(indexRegExp1.exec(object_id));
800
+ indexRegExp1.lastIndex = 0;
801
+ if (object_name=='Response') {
802
+ var response_set_id=$(this).closest('ol').find('input[type="file"]').attr('data-response_set_id');
803
+ var question_id = $(this).closest('ol').find('input[type="file"]').closest('ol').find('input[id$="question_id"]').val();
804
+ $.get('/surveyor/get_response_id?question_id='+question_id+"&response_set_id="+response_set_id, function(data){
805
+ var response_id = data
806
+ if (response_id) {
807
+ //now get the the name of the file, so we can display the name of the file and a link to the user.
808
+ $.get('/pages/get_filename?object='+object_name+'&id='+response_id, function(data){
809
+ //we'll stuff the link into the div called filename_with_link
810
+ var filenamediv = $('input[id$="question_id"][value="'+question_id+'"]').closest('ol').find('.filename_with_link');
811
+ filenamediv.html('current file is: ' + data );
812
+ //add a delete icon
813
+ insert_file_delete_icon(filenamediv,response_id,idx);
814
+
815
+ //insert the response.id so we don't do insert when update needed
816
+ insert_id_if_missing(filenamediv.closest('ol').find('input'), response_id);
817
+
818
+ //now insert the response id inputs for star and slider fields, which also would be handled by jquery.surveyor.js, but were bypassed.
819
+ //nested associations will force an insert of these fields, and the response ids are necessary to avoid duplicate inserts in further
820
+ //further operations
821
+ selects = $("form[id^='survey_form'] select").add("form[id^='survey_form'] li.star");
822
+ selects.each(function(){
823
+ var question_id = $(this).closest('ol').find('input[id$="question_id"]').val();
824
+ var context = this
825
+ $.get('/surveyor/get_response_id?question_id='+question_id+"&response_set_id="+response_set_id, function(data2){
826
+ insert_id_if_missing($(context).closest('ol').find('input'), data2);
827
+ });
828
+ });
829
+ //ajax done, unblock
830
+ $('input, select, submit').unblock();
831
+ });
832
+ }
833
+ });
834
+ }
835
+ });
836
+ }
837
+ });
838
+ }
839
+
840
+ function replace_surveyform_contents(response) {
841
+ $("div#box").filter(":last").replaceWith(response);
842
+ sortable_sections_and_questions();
843
+ refresh_stars();
844
+ update_uislider();
845
+ update_datepickers();
846
+ }
847
+
848
+ function check_dropdown_column_count() {
849
+ $('select[id="question_dropdown_column_count"]').on('change', function(event){
850
+ count = $(this).val()
851
+ // for (var i = 0; i < count; i++) {
852
+ // var grid_dropdown_columns = $(this).closest('div').nextAll('.grid_dropdown_columns');
853
+ // grid_dropdown_columns.html("");
854
+ $(this).closest('#sortable_answers').render_grid_fields_partial('grid_dropdown', count);
855
+ // };
856
+ });
857
+ }
858
+ function getAllSerialize() {
859
+ $('.sortable_questions').each(function(index, value) {
860
+ if (index === 0) {
861
+ newarr = $(this).sortable('serialize',{key:$(this).attr('id')+'[]'});
862
+ }
863
+ else{
864
+ newarr = newarr+'&'+$(this).sortable('serialize',{key:$(this).attr('id')+'[]'});
865
+ }
866
+ });
867
+ return newarr;
868
+ }
869
+
870
+ function insert_id_if_missing(wrapped_set, response_id){
871
+ //get the id of the form element
872
+ var first_id = wrapped_set[0].id;
873
+ indexRegExp1 = /[0-9]+/g;
874
+ //extract the index
875
+ idx = parseInt(indexRegExp1.exec(first_id));
876
+ //determine if the r_<idx>_id input field exists.
877
+ var id_input_exists = wrapped_set.filter(function() {
878
+ return /r_\d+_id/.test( $(this).attr('id'));
879
+ }).length;
880
+ //if the input field does not exist, create it, to avoid inserting a duplicate response through the nested attributes processing
881
+ //this would normally be handled by the successfulSave method of jquery.surveyor.js, but gets bypassed by remotipart in
882
+ //order to process the file upload.
883
+ if (!id_input_exists) {
884
+ wrapped_set.filter('input[id$="question_id"]').after('<input id="r_'+idx+'_id" class="" type="hidden" value="'+response_id+'" name="r['+idx+'][id]">');
885
+ };
886
+ indexRegExp1.lastIndex = 0;
887
+ }
888
+
889
+ function insert_file_delete_icon(filenamediv, response_id, idx){
890
+ //retrieve the link to the delete icon
891
+ if (filenamediv.find('img').length==0 && response_id) {
892
+ var img = filenamediv.attr('data-image-path');
893
+ //create the link
894
+ var js = "remove_attachment('Response',"+response_id+","+idx+"); return false;";
895
+ var newclick = new Function(js);
896
+ filenamediv.append('<img src="'+img+'" />').find('img').attr('onclick', '').click(newclick);
897
+ }
898
+ }
899
+
900
+ function CurrencyFormatted(amount) {
901
+ var i = parseFloat(amount);
902
+ if(isNaN(i)) { i = 0.00; }
903
+ var minus = '';
904
+ if(i < 0) { minus = '-'; }
905
+ i = Math.abs(i);
906
+ i = parseInt((i + .005) * 100);
907
+ i = i / 100;
908
+ s = new String(i);
909
+ if(s.indexOf('.') < 0) { s += '.00'; }
910
+ if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
911
+ s = minus + s;
912
+ return s;
913
+ }
914
+
915
+ function copy_fieldset(link) {
916
+ var last_fieldset = link.closest('fieldset').filter(':last').find('input, select').filter(':first');
917
+ var idx = get_1st_index(link.closest('form').find('fieldset').filter(':last').find('tr.fields input').filter(':first'));
918
+ idx = idx+1;
919
+ var new_fieldset = link.closest('form').find('fieldset').filter(':last').clone();
920
+ new_fieldset.find('input, select').each(function(){
921
+ var old_id = this.id;
922
+ //replace first occurrence of a number (dont want to change anything but the lowest nested attribute)
923
+ var new_id = old_id.replace(/\d/,idx);
924
+ this.id = new_id;$('#sortable_answers')
925
+ var old_name = this.name;
926
+ var new_name = old_name.replace(/\d/,idx);
927
+ this.name = new_name;
928
+ $(this).removeAttr('value');
929
+ this.disabled = null;
930
+ });
931
+ last_fieldset.closest('fieldset').after(new_fieldset)
932
+ new_fieldset.before('<br />');
933
+ new_fieldset.focus();
934
+ return new_fieldset;
935
+ }
936
+ function copy_row(link_source,destination) {
937
+ var last_tr = link_source.closest('fieldset').find('tr.fields').filter(':last').find('input, select').filter(':first');
938
+ var fsindex = get_1st_index(link_source.closest('fieldset').find('tr.fields input').filter(':first'));
939
+ var idx = get_index(last_tr);
940
+ idx = idx+1;
941
+ var new_tr = link_source.closest('fieldset').find('tr.fields').filter(':last').clone();
942
+ new_tr.find('input, select').each(function(){
943
+ var old_id = this.id;
944
+ //replace last occurrence of a number (dont want to change anything but the lowest nested attribute)
945
+ var new_id = old_id.replace(/\d(?!.*\d)/g,idx);
946
+ new_id = new_id.replace(/\d+(?=_fs_products_attributes)/g,fsindex);
947
+ this.id = new_id;
948
+ var old_name = this.name;
949
+ var new_name = old_name.replace(/\d(?!.*\d)/g,idx);
950
+ new_name = new_name.replace(/\d+(?=_fs_products_attributes)/g,fsindex);
951
+ this.name = new_name;
952
+ $(this).removeAttr('value');
953
+ this.disabled = null;
954
+ });
955
+ $(destination).closest('tr').before(new_tr);
956
+ return new_tr;
957
+ }
958
+
959
+ function update_display_order(link) {
960
+ $(link).each(function(index, value){
961
+ $(value).find('input[id$="display_order"]').first().val(index+1);
962
+ });
963
+ }
964
+
965
+ function get_index(link) {
966
+ var object_id = link.attr('name');
967
+ var indexRegExp1 = /\d+(?!.*\d)/g;
968
+ var idx = parseInt(indexRegExp1.exec(object_id));
969
+ indexRegExp1.lastIndex = 0;
970
+ return idx;
971
+ }
972
+
973
+
974
+ function get_1st_index(link) {
975
+ //ugly hack. replace later with a more generalized function that pulls the nth index
976
+ var object_id = link.attr('name');
977
+ var indexRegExp1 = /\d+/;
978
+ var idx = parseInt(indexRegExp1.exec(object_id));
979
+ indexRegExp1.lastIndex = 0;
980
+ return idx;
981
+ }
982
+
983
+
984
+ function replace_idx(link, association, content) {
985
+ var indexRegExp1 = new RegExp("[0-9]+");
986
+ var idx = $(link).length+1;
987
+ indexRegExp1.lastIndex = 0;
988
+ var regexp = new RegExp(association+"_attributes_0", "g");
989
+ var content = content.replace(regexp, association+"_attributes_"+idx);
990
+ regexp = new RegExp(association+"_attributes\]\\[0", "g");
991
+ content = content.replace(regexp, association+"_attributes]["+idx);
992
+ return content;
993
+ }
994
+
995
+ function update_question_numbers() {
996
+ //span.questions gets the text for the question, e.g. "1) what is your name?"
997
+ $('span.questions').each(function(index, value){
998
+ var regexp = /\d+\)/g;
999
+ $(value).html($(value).html().replace(regexp, (index+1)+')'));
1000
+ //display order is a hidden field placed just before span.questions in the DOM
1001
+ $(value).prev('input[id$="display_order"]').val(index+1);
1002
+ });
1003
+ }
1004
+
1005
+
1006
+ function update_answer_display_order () {
1007
+ $('#sortable_answers').find('input[id$="display_order"]').each(function(index, value){
1008
+ $(value).val(index);
1009
+ });
1010
+ }
1011
+
1012
+ function update_dependency_questions() {
1013
+ $('.question_logic_notifier').closest('div.question').each(function(){
1014
+ var id = $(this).closest('div.question').attr('id').match(/\d+/)[0]
1015
+ $.get("/surveyforms/0/replace_question?question_id="+id,
1016
+ {},
1017
+ function(response) {
1018
+ $("#question_"+id).html(replace_idx($("#question_"+id),"questions", response));
1019
+ //update_question_numbers();
1020
+ $.unblockUI();
1021
+ }
1022
+ );
1023
+ });
1024
+ }
1025
+
1026
+ function refresh_stars(link) {
1027
+ if (link === undefined){
1028
+ $('input[type=radio].star').rating();
1029
+ }
1030
+ else {
1031
+ $(link).find('input[type=radio].star').rating();
1032
+ }
1033
+
1034
+ }
1035
+
1036
+
1037
+ function sortable_sections_and_questions() {
1038
+ var survey_locked = $('.sortable_sections').data('survey_locked');
1039
+
1040
+ if (!survey_locked) {
1041
+ $('.sortable_sections').sortable({
1042
+ axis:"y",
1043
+ opacity: 0.6,
1044
+ scroll: true,
1045
+ update: function(){
1046
+ $.ajax({
1047
+ type: 'post',
1048
+ data: $('.sortable_sections').sortable('serialize')+'&survey_id='+$('input#surveyform_id')[0].value,
1049
+ dataType: 'script',
1050
+ complete: function(request){
1051
+ $('#survey_section').effect('highlight');
1052
+ },
1053
+ url: '/survey_sections/sort'})
1054
+ }
1055
+ });
1056
+
1057
+
1058
+ $('.sortable_group_questions').sortable({
1059
+ axis:"y",
1060
+ opacity: 0.6,
1061
+ scroll: true,
1062
+ connectWith: ".sortable_group_questions",
1063
+ update: function(){
1064
+ var questions = $('.group_inline_question')
1065
+ var display_order = Math.min.apply(
1066
+ null,
1067
+ questions.find(
1068
+ 'input[id*="display_order"]'
1069
+ ).map(
1070
+ function(){
1071
+ return parseInt($(this).val());
1072
+ }
1073
+ ).toArray()
1074
+ );
1075
+ $('.group_inline_question').each(function(index, value){
1076
+ questions.eq(index).find('input[id*="display_order"]').val(display_order+index);
1077
+ });
1078
+ }
1079
+ });
1080
+
1081
+ $('.sortable_questions').sortable({
1082
+ axis:"y",
1083
+ opacity: 0.6,
1084
+ scroll: true,
1085
+ connectWith: ".sortable_questions",
1086
+ update: function(){
1087
+ $.ajax({
1088
+ type: 'post',
1089
+ data: getAllSerialize()+'&survey_id='+$('input[id*="surveyform_id"]')[0].value,
1090
+ dataType: 'script',
1091
+ complete: function(request){
1092
+ $('#survey_section').effect('highlight');
1093
+ update_question_numbers();
1094
+ },
1095
+ url: '/questions/sort'
1096
+ })
1097
+ }
1098
+ });
1099
+ }
1100
+ }
1101
+
1102
+
1103
+ function show_dependency_value(data, target) {
1104
+ target = target.closest('tr').find('td.answer_field');
1105
+ data = data.split(',');
1106
+ var pick = data[0];
1107
+ var question_type = data[1];
1108
+ var question_id = data[2];
1109
+ target.find('.dependency_pick_multiple_choice').hide();
1110
+ target.find('.dependency_float').hide();
1111
+ target.find('.dependency_star').hide();
1112
+ target.find('.dependency_number').hide();
1113
+ target.find('.dependency_text_box').hide();
1114
+ target.find('.dependency_date').hide();
1115
+ target.find('.dependency_text').hide();
1116
+ target.closest('tr .column_id').hide();
1117
+ if (/(one|any)/.test(question_type)) {
1118
+ target.find('.dependency_pick_multiple_choice').show();
1119
+ }
1120
+ else if (question_type=="dropdown") {
1121
+ target.find('.dependency_pick_multiple_choice').show();
1122
+ }
1123
+ else if (question_type=="grid_dropdown") {
1124
+ target.find('.dependency_pick_multiple_choice').show();
1125
+ target.refresh_dependency_columns(question_type, question_id);
1126
+ }
1127
+ else if (question_type=="stars"){
1128
+ target.find('.dependency_star').show();
1129
+ }
1130
+ else if (question_type=='number'){
1131
+ target.find('.dependency_float').show();
1132
+ }
1133
+ else if (question_type=='box'){
1134
+ target.find('.dependency_text_box').show();
1135
+ }
1136
+ else if (question_type=='date'){
1137
+ target.find('.dependency_date').show();
1138
+ }
1139
+ else {
1140
+ target.find('.dependency_text').show();
1141
+ }
1142
+ target.refresh_dependency_answers();
1143
+ }
1144
+
1145
+ function remove_fields(link, dom_to_hide) {
1146
+ dom_to_hide = dom_to_hide || ".fields";
1147
+ $(link).prev("input[type=hidden]").val("1");
1148
+ $(link).closest(dom_to_hide).hide();
1149
+ }
1150
+
1151
+ function remove_dependency_condition(link) {
1152
+ $(link).prev("input[type=hidden]").val("1");
1153
+ $(link).closest("tr").hide().prev("tr").hide();
1154
+ }
1155
+
1156
+
1157
+ function remove_fieldset(link) {
1158
+ $(link).prev("input[type=hidden]").val("1");
1159
+ $(link).closest('fieldset').filter(':first').hide();
1160
+ }
1161
+
1162
+ function remove_relation(link, url) {
1163
+ var return_value =
1164
+ $.ajax( {
1165
+ type: "GET",
1166
+ url: url,
1167
+ async: false
1168
+ }
1169
+ ).responseText;
1170
+ if (return_value === "success"){
1171
+ $(link).closest('tr').remove();
1172
+ }
1173
+ else {
1174
+ $(link).closest('tr').remove();
1175
+ }
1176
+ }
1177
+
1178
+ function add_fields(link, association, content) {
1179
+ var new_id = new Date().getTime();
1180
+ var regexp = new RegExp("new_" + association, "g");
1181
+ a=$(link).parent().before(content.replace(regexp, new_id)).prev().find('input[type!="hidden"]').first().focus();
1182
+ // alert($(link).parent().prev().find('select').last().attr('id'));
1183
+ }
1184
+
1185
+
1186
+ function update_autocomplete_idx(link) {
1187
+ elements = $(link).attr('data-update-elements');
1188
+ if (elements) {
1189
+ var regexp = new RegExp("autocompleteidx", "g");
1190
+ var id = $(link).attr('id');
1191
+ indexRegExp1 = /[0-9]+/g;
1192
+ idx = parseInt(indexRegExp1.exec(id));
1193
+ indexRegExp1.lastIndex = 0;
1194
+ elements = elements.replace(regexp,idx);
1195
+ $(link).attr('data-update-elements',elements);
1196
+ }
1197
+ }
1198
+
1199
+ function remove_attachment(object,id,idx) {
1200
+ //remove the carrierwave attachment, return the mandatory attribute
1201
+ $.get('/pages/remove_attachment?object='+object+'&id='+id, function(data){
1202
+ //clear the div containing the old name and delete icon
1203
+ $('.filename_with_link').html('');
1204
+
1205
+ //clear the filename from the form. Unlike other fields, HTML prohibits us from directly altering the value in a file field.
1206
+ //instead, we need to remove the current <input type='file'> and replace it with a freshly inserted input field.
1207
+ var file_input = $('input[id="r_'+idx+'_id"]').nextAll('li').find('input[type="file"]');
1208
+ var par=file_input.parent();
1209
+ var fi = $('<input>',{
1210
+ id: file_input.attr('id'),
1211
+ name: file_input.attr('name'),
1212
+ type: 'file'
1213
+ });
1214
+ fi.attr('data-response_set_id',file_input.attr('data-response_set_id'));
1215
+ fi.attr('data-object-id',file_input.attr('data-object-id'));
1216
+ fi.attr('data-object-class', file_input.attr('data-object-class'));
1217
+ //data returns true if mandatory field or nil
1218
+ if (data && data==="true") {
1219
+ fi.attr("required","required");
1220
+ }
1221
+ par.html(fi);
1222
+
1223
+ //since the response object is gone, need to remove the r_id to, or the controller will think
1224
+ //this question has a response. That would let a blank field pass even if mandatory, and,
1225
+ //since this is in a nested form, would get the controller to try an update when the object of the update no longer exists.
1226
+ $('input[id="r_'+idx+'_id"]').remove();
1227
+ });
1228
+ }
1229
+
1230
+ function go_back() {
1231
+ $('#initial_buttons').show();
1232
+ $('#deny_buttons').hide();
1233
+ $('#revise_buttons').hide();
1234
+ $('#show_schedule').show();
1235
+ $('#revise_schedule').hide();
1236
+ }
1237
+ function go_back_2() {
1238
+ $('#revision_requests').show();
1239
+ $('#revision_form').hide();
1240
+ $('#withdrawal_form').hide();
1241
+ $('#make_revisions_button').show();
1242
+ }
1243
+ function show_survey_report_data() {
1244
+ $('.non_repeater .report_data').show();
1245
+ $('.show_survey_report_data_button').hide();
1246
+ }
1247
+ function hide_survey_report_data() {
1248
+ $('.surveyor_gui_report .report_data').hide();
1249
+ $('.show_survey_report_data_button').show();
1250
+ }
1251
+
1252
+ function getGroups() {
1253
+ var result = {};
1254
+ var checkbox_names = {};
1255
+ var ols = $('input[type="checkbox"], input[type="radio"]').closest('ol');
1256
+ ols.each(function(i) {
1257
+ var checkbox_names = $.map(
1258
+ $(this).find('input[type="checkbox"]'),
1259
+ function(e,i) {
1260
+ return $(e).attr("name");
1261
+ }
1262
+ ).join(" ");
1263
+ result['fieldPair_' + i] = checkbox_names;
1264
+ });
1265
+ return result;
1266
+ }
1267
+
1268
+ $.fn.update_single_uislider = function(){
1269
+ var slider_element = $(this).find('select.uislider').first();
1270
+ if(slider_element.length>0 && typeof slider_element.selectToUISlider == 'function') {
1271
+ slider_element.selectToUISlider({
1272
+ labels:2,
1273
+ labelSrc: "text",
1274
+ sliderOptions: {
1275
+ stop: function(e, ui) { // handle stop sliding event
1276
+ slider_element.parents('form').trigger('slider_change');
1277
+ }
1278
+ }
1279
+ }).hide();
1280
+ }
1281
+ }
1282
+
1283
+ function update_uislider(){
1284
+ $('select.uislider').each(function() {
1285
+ if(typeof $(this).selectToUISlider == 'function') {
1286
+ $(this).selectToUISlider({
1287
+ labels:2,
1288
+ labelSrc: "text",
1289
+ sliderOptions: {
1290
+ stop: function(e, ui) { // handle stop sliding event
1291
+ $(this).parents('form').trigger('slider_change');
1292
+ }
1293
+ }
1294
+ }).hide();
1295
+ }
1296
+ });
1297
+ }
1298
+
1299
+ function update_datepickers(){
1300
+ $("input.date_picker")
1301
+ .datepicker({
1302
+ duration: 'fast',
1303
+ showOn: 'both',
1304
+ buttonImage: '../../assets/datepicker.gif',
1305
+ buttonImageOnly: true
1306
+ });
1307
+ $("input.datetime_picker")
1308
+ .datetimepicker({
1309
+ duration: 'fast',
1310
+ showOn: 'both',
1311
+ buttonImage: '../../assets/datepicker.gif',
1312
+ buttonImageOnly: true
1313
+ });
1314
+ $("input.time_picker")
1315
+ .timepicker({
1316
+ duration: 'fast',
1317
+ showOn: 'both',
1318
+ buttonImage: '../../assets/datepicker.gif',
1319
+ buttonImageOnly: true
1320
+ });
1321
+ }
1322
+
1323
+ $.fn.determine_dependency_question_type = function () {
1324
+ var target = $(this);
1325
+ $.get('/dependencys/get_question_type',
1326
+ 'question_id='+$(this).val(),
1327
+ function(data){
1328
+ show_dependency_value(data,target);
1329
+ }
1330
+ );
1331
+ }
1332
+
1333
+ $.fn.refresh_dependency_answers = function() {
1334
+ var question_id =
1335
+ $(this).closest("tr").find('[id*="dependency_attributes_dependency_conditions_attributes"][id$="question_id"]').val();
1336
+ var column_id =
1337
+ $(this).closest("tr").find('[id*="dependency_attributes_dependency_conditions_attributes"][id$="column_id"]').val();
1338
+ var dependency_condition_id =
1339
+ $(this).closest("tr").find('[id*="dependency_attributes_dependency_conditions_attributes"][id$="_id"]').val();
1340
+ $(this).closest('tr').find('[id*="dependency_attributes_dependency_conditions_attributes"][id$="answer_id"]')
1341
+ .load(
1342
+ '/dependencys/get_answers',
1343
+ 'question_id='+question_id +
1344
+ '&dependency_condition_id='+dependency_condition_id +
1345
+ '&column_id='+column_id
1346
+ );
1347
+ }
1348
+
1349
+ $.fn.refresh_dependency_columns = function(question_type, question_id) {
1350
+ var column = $(this).closest('tr').find('[id*="dependency_attributes_dependency_conditions_attributes"][id$="column_id"]');
1351
+ var dependency_condition_id =
1352
+ $(this).closest("tr").find('[id*="dependency_attributes_dependency_conditions_attributes"][id$="_id"]').val();
1353
+ column.closest('.column_id').show()
1354
+ $.get(
1355
+ '/dependencys/get_columns',
1356
+ 'question_id='+question_id +
1357
+ '&dependency_condition_id='+dependency_condition_id,
1358
+ function(data){
1359
+ column.html(data);
1360
+ column.refresh_dependency_answers();
1361
+ });
1362
+ }
1363
+ function modal_dialog(title, dialog_content,yes_callback,no_callback){
1364
+ /* var modal_response="";
1365
+ $('.modal_button').live('click',function(){
1366
+ $.colorbox.close();
1367
+ modal_response = $(this).text();
1368
+ });
1369
+ $.colorbox({
1370
+ html: dialog_content,
1371
+ width:"400px",
1372
+ height:"250px",
1373
+ fixed: true,
1374
+ scrolling:false,
1375
+ onLoad: function() {
1376
+ $('#cboxClose').remove();
1377
+ },
1378
+ onClosed:function(){
1379
+ if (modal_response==="No") {
1380
+ no_callback();
1381
+ }
1382
+ else {
1383
+ yes_callback();
1384
+ }
1385
+ },
1386
+ opacity:.3
1387
+ });
1388
+ */
1389
+ $('<div></div>').appendTo('body')
1390
+ .html(dialog_content)
1391
+ .dialog({
1392
+ closeOnEscape: false,
1393
+ modal: true,
1394
+ title: title,
1395
+ zIndex: 10000,
1396
+ autoOpen: false,
1397
+ fixed: true,
1398
+ width: 'auto',
1399
+ resizable: false,
1400
+ buttons: {
1401
+ Yes: function() {
1402
+ $(this).dialog("close");
1403
+ yes_callback ();
1404
+ },
1405
+ No: function() {
1406
+ $(this).dialog("close");
1407
+ no_callback ();
1408
+ }
1409
+ },
1410
+ open: function(event, ui) {
1411
+ $(".ui-dialog-titlebar-close").hide();
1412
+ },
1413
+ close: function (event, ui) {
1414
+ $(this).remove();
1415
+ }
1416
+ }).parent().css({position:"fixed"}).end().dialog('open');
1417
+ }