upgrade_surveyor_gui 0.1.2

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