telephony 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (365) hide show
  1. checksums.yaml +15 -0
  2. data/README.md +105 -0
  3. data/Rakefile +39 -0
  4. data/app/assets/fonts/telephony/zest-telephony.eot +0 -0
  5. data/app/assets/fonts/telephony/zest-telephony.svg +73 -0
  6. data/app/assets/fonts/telephony/zest-telephony.ttf +0 -0
  7. data/app/assets/fonts/telephony/zest-telephony.woff +0 -0
  8. data/app/assets/images/telephony/backspace.png +0 -0
  9. data/app/assets/images/telephony/icon-spinner.gif +0 -0
  10. data/app/assets/javascripts/telephony/application.js +12 -0
  11. data/app/assets/javascripts/telephony/collections/agents.js +4 -0
  12. data/app/assets/javascripts/telephony/config.js.erb +11 -0
  13. data/app/assets/javascripts/telephony/models/agent.js +103 -0
  14. data/app/assets/javascripts/telephony/models/conversation.js +226 -0
  15. data/app/assets/javascripts/telephony/models/device.js +30 -0
  16. data/app/assets/javascripts/telephony/models/transfer.js +65 -0
  17. data/app/assets/javascripts/telephony/namespace.js +6 -0
  18. data/app/assets/javascripts/telephony/push.js +80 -0
  19. data/app/assets/javascripts/telephony/vendor/backbone.js +1159 -0
  20. data/app/assets/javascripts/telephony/vendor/chosen.jquery.js +1018 -0
  21. data/app/assets/javascripts/telephony/vendor/jquery.form.js +1117 -0
  22. data/app/assets/javascripts/telephony/vendor/pusher.js +1304 -0
  23. data/app/assets/javascripts/telephony/vendor/test_dependencies.js +18 -0
  24. data/app/assets/javascripts/telephony/vendor/underscore.js +839 -0
  25. data/app/assets/javascripts/telephony/views/agents_view.js +69 -0
  26. data/app/assets/javascripts/telephony/views/application_view.js +78 -0
  27. data/app/assets/javascripts/telephony/views/call_queue_view.js +21 -0
  28. data/app/assets/javascripts/telephony/views/conversation_buttons_view.js +15 -0
  29. data/app/assets/javascripts/telephony/views/conversation_view.js +322 -0
  30. data/app/assets/javascripts/telephony/views/status_view.js +36 -0
  31. data/app/assets/javascripts/telephony/views/transfer_view.js +87 -0
  32. data/app/assets/javascripts/telephony/views/twilio_client_view.js +117 -0
  33. data/app/assets/javascripts/telephony/views/widget_view.js +55 -0
  34. data/app/assets/javascripts/telephony/widget.js +5 -0
  35. data/app/assets/javascripts/templates/telephony/agents_view.jst.ejs +8 -0
  36. data/app/assets/javascripts/templates/telephony/call_queue_view.jst.ejs +2 -0
  37. data/app/assets/javascripts/templates/telephony/conversation_buttons_view.jst.ejs +23 -0
  38. data/app/assets/javascripts/templates/telephony/conversation_view.jst.ejs +10 -0
  39. data/app/assets/javascripts/templates/telephony/status_view.jst.ejs +4 -0
  40. data/app/assets/javascripts/templates/telephony/transfer_view.jst.ejs +38 -0
  41. data/app/assets/javascripts/templates/telephony/twilio_client_view.jst.ejs +10 -0
  42. data/app/assets/stylesheets/telephony/font.css +43 -0
  43. data/app/assets/stylesheets/telephony/reset.css.scss +10 -0
  44. data/app/assets/stylesheets/telephony/widget.css.scss +512 -0
  45. data/app/controllers/telephony/agents_controller.rb +46 -0
  46. data/app/controllers/telephony/application_controller.rb +4 -0
  47. data/app/controllers/telephony/call_centers_controller.rb +9 -0
  48. data/app/controllers/telephony/conversations_controller.rb +74 -0
  49. data/app/controllers/telephony/inbound/conversation_queues_controller.rb +21 -0
  50. data/app/controllers/telephony/playable_listeners_controller.rb +43 -0
  51. data/app/controllers/telephony/providers/twilio/application_controller.rb +26 -0
  52. data/app/controllers/telephony/providers/twilio/calls_controller.rb +130 -0
  53. data/app/controllers/telephony/providers/twilio/inbound_calls_controller.rb +54 -0
  54. data/app/controllers/telephony/providers/twilio/musics_controller.rb +12 -0
  55. data/app/controllers/telephony/providers/twilio/voicemails_controller.rb +29 -0
  56. data/app/controllers/telephony/signals/agents/presences_controller.rb +64 -0
  57. data/app/controllers/telephony/transfers_controller.rb +18 -0
  58. data/app/controllers/telephony/twilio_client_controller.rb +37 -0
  59. data/app/controllers/telephony/voicemails_controller.rb +13 -0
  60. data/app/controllers/telephony/widget_controller.rb +10 -0
  61. data/app/helpers/telephony/application_helper.rb +4 -0
  62. data/app/helpers/telephony/calls_helper.rb +13 -0
  63. data/app/models/telephony/agent.rb +186 -0
  64. data/app/models/telephony/agent_state_machine.rb +54 -0
  65. data/app/models/telephony/base.rb +7 -0
  66. data/app/models/telephony/blacklisted_number.rb +5 -0
  67. data/app/models/telephony/call.rb +94 -0
  68. data/app/models/telephony/call_center.rb +26 -0
  69. data/app/models/telephony/call_state_machine.rb +98 -0
  70. data/app/models/telephony/conversation.rb +273 -0
  71. data/app/models/telephony/conversation_state_machine.rb +109 -0
  72. data/app/models/telephony/conversations_presenter.rb +83 -0
  73. data/app/models/telephony/events.rb +6 -0
  74. data/app/models/telephony/events/answer.rb +6 -0
  75. data/app/models/telephony/events/base.rb +118 -0
  76. data/app/models/telephony/events/busy.rb +6 -0
  77. data/app/models/telephony/events/call_answered.rb +22 -0
  78. data/app/models/telephony/events/call_fail.rb +6 -0
  79. data/app/models/telephony/events/complete_hold.rb +28 -0
  80. data/app/models/telephony/events/complete_one_step_transfer.rb +17 -0
  81. data/app/models/telephony/events/complete_resume.rb +28 -0
  82. data/app/models/telephony/events/complete_two_step_transfer.rb +6 -0
  83. data/app/models/telephony/events/conference.rb +6 -0
  84. data/app/models/telephony/events/connect.rb +22 -0
  85. data/app/models/telephony/events/customer_left_two_step_transfer.rb +6 -0
  86. data/app/models/telephony/events/dial_agent.rb +6 -0
  87. data/app/models/telephony/events/ended.rb +19 -0
  88. data/app/models/telephony/events/enqueue.rb +6 -0
  89. data/app/models/telephony/events/fail_one_step_transfer.rb +9 -0
  90. data/app/models/telephony/events/fail_two_step_transfer.rb +6 -0
  91. data/app/models/telephony/events/initialize_widget.rb +15 -0
  92. data/app/models/telephony/events/initiate_hold.rb +6 -0
  93. data/app/models/telephony/events/initiate_one_step_transfer.rb +6 -0
  94. data/app/models/telephony/events/initiate_resume.rb +6 -0
  95. data/app/models/telephony/events/initiate_two_step_transfer.rb +6 -0
  96. data/app/models/telephony/events/leave_two_step_transfer.rb +17 -0
  97. data/app/models/telephony/events/leave_voicemail.rb +22 -0
  98. data/app/models/telephony/events/no_answer.rb +6 -0
  99. data/app/models/telephony/events/play_closed_greeting.rb +6 -0
  100. data/app/models/telephony/events/play_message.rb +6 -0
  101. data/app/models/telephony/events/reject.rb +6 -0
  102. data/app/models/telephony/events/rona.rb +6 -0
  103. data/app/models/telephony/events/start.rb +17 -0
  104. data/app/models/telephony/events/straight_to_voicemail.rb +6 -0
  105. data/app/models/telephony/events/terminate.rb +6 -0
  106. data/app/models/telephony/events/transfer.rb +35 -0
  107. data/app/models/telephony/inbound_conversation_queue.rb +101 -0
  108. data/app/models/telephony/playable.rb +7 -0
  109. data/app/models/telephony/playable_listener.rb +42 -0
  110. data/app/models/telephony/pusher_event_publisher.rb +26 -0
  111. data/app/models/telephony/recording.rb +4 -0
  112. data/app/models/telephony/voicemail.rb +36 -0
  113. data/app/observers/telephony/agent_observer.rb +8 -0
  114. data/app/observers/telephony/call_observer.rb +15 -0
  115. data/app/observers/telephony/conversation_observer.rb +9 -0
  116. data/app/observers/telephony/event_observer.rb +9 -0
  117. data/app/views/layouts/telephony/application.html.erb +14 -0
  118. data/app/views/telephony/providers/twilio/calls/child_detached.builder +5 -0
  119. data/app/views/telephony/providers/twilio/calls/complete_hold.builder +6 -0
  120. data/app/views/telephony/providers/twilio/calls/connect.builder +13 -0
  121. data/app/views/telephony/providers/twilio/calls/dial.builder +14 -0
  122. data/app/views/telephony/providers/twilio/calls/done.builder +5 -0
  123. data/app/views/telephony/providers/twilio/calls/join_conference.builder +7 -0
  124. data/app/views/telephony/providers/twilio/calls/whisper_tone.builder +3 -0
  125. data/app/views/telephony/providers/twilio/inbound_calls/closed_hours.builder +7 -0
  126. data/app/views/telephony/providers/twilio/inbound_calls/create.builder +8 -0
  127. data/app/views/telephony/providers/twilio/inbound_calls/enqueue.builder +8 -0
  128. data/app/views/telephony/providers/twilio/inbound_calls/reject.builder +5 -0
  129. data/app/views/telephony/providers/twilio/inbound_calls/wait_music.builder +5 -0
  130. data/app/views/telephony/providers/twilio/musics/hold.builder +5 -0
  131. data/app/views/telephony/providers/twilio/voicemails/new.builder +6 -0
  132. data/app/views/telephony/twilio_client/index.html.erb +74 -0
  133. data/app/views/telephony/widget/index.erb +3 -0
  134. data/config/cucumber.yml +8 -0
  135. data/config/database.yml +57 -0
  136. data/config/environment.rb +67 -0
  137. data/config/initializers/pusher.rb +21 -0
  138. data/config/initializers/telephony.rb +44 -0
  139. data/config/routes.rb +94 -0
  140. data/config/wopr.yml.example +38 -0
  141. data/db/migrate/20130806213053_bootstrap_db.rb +105 -0
  142. data/db/migrate/20131009204026_create_telephony_blacklisted_numbers.rb +11 -0
  143. data/lib/agent_generator.rb +24 -0
  144. data/lib/tasks/cucumber.rake +65 -0
  145. data/lib/tasks/jasmine.rake +8 -0
  146. data/lib/tasks/telephony_tasks.rake +4 -0
  147. data/lib/telephony.rb +34 -0
  148. data/lib/telephony/concerns/controllers/twilio_request_verifier.rb +39 -0
  149. data/lib/telephony/conversation_data.rb +67 -0
  150. data/lib/telephony/engine.rb +19 -0
  151. data/lib/telephony/error.rb +8 -0
  152. data/lib/telephony/error/agent_on_a_call.rb +2 -0
  153. data/lib/telephony/error/base.rb +3 -0
  154. data/lib/telephony/error/connection.rb +2 -0
  155. data/lib/telephony/error/not_in_progress.rb +2 -0
  156. data/lib/telephony/error/queue_empty.rb +2 -0
  157. data/lib/telephony/helper.rb +11 -0
  158. data/lib/telephony/jobs/agent_offline.rb +28 -0
  159. data/lib/telephony/jobs/pusher_event.rb +21 -0
  160. data/lib/telephony/providers/twilio_provider.rb +162 -0
  161. data/lib/telephony/version.rb +3 -0
  162. data/spec/controllers/telephony/agents_controller_spec.rb +117 -0
  163. data/spec/controllers/telephony/call_centers_controller_spec.rb +25 -0
  164. data/spec/controllers/telephony/conversations_controller_spec.rb +229 -0
  165. data/spec/controllers/telephony/playable_listeners_controller_spec.rb +138 -0
  166. data/spec/controllers/telephony/providers/twilio/calls_controller_spec.rb +33 -0
  167. data/spec/controllers/telephony/providers/twilio/musics_controller_spec.rb +20 -0
  168. data/spec/controllers/telephony/signals/agents/presences_controller_spec.rb +154 -0
  169. data/spec/controllers/telephony/twilio_client_controller_spec.rb +58 -0
  170. data/spec/controllers/telephony/widget_controller_spec.rb +25 -0
  171. data/spec/dummy/Rakefile +7 -0
  172. data/spec/dummy/app/assets/javascripts/application.js +6 -0
  173. data/spec/dummy/app/assets/javascripts/lib/event_logger.js +82 -0
  174. data/spec/dummy/app/assets/javascripts/vendor/backbone.js +1159 -0
  175. data/spec/dummy/app/assets/javascripts/vendor/chosen.jquery.js +1018 -0
  176. data/spec/dummy/app/assets/javascripts/vendor/jquery.form.js +1117 -0
  177. data/spec/dummy/app/assets/javascripts/vendor/underscore.js +839 -0
  178. data/spec/dummy/app/assets/stylesheets/application.css +23 -0
  179. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  180. data/spec/dummy/app/controllers/widget_host_controller.rb +2 -0
  181. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  182. data/spec/dummy/app/views/layouts/application.html.erb +12 -0
  183. data/spec/dummy/app/views/widget_host/index.html.erb +53 -0
  184. data/spec/dummy/config.ru +4 -0
  185. data/spec/dummy/config/application.rb +61 -0
  186. data/spec/dummy/config/boot.rb +10 -0
  187. data/spec/dummy/config/call_centers.yml +35 -0
  188. data/spec/dummy/config/call_centers.yml.example +35 -0
  189. data/spec/dummy/config/database.yml +56 -0
  190. data/spec/dummy/config/environment.rb +5 -0
  191. data/spec/dummy/config/environments/cucumber.rb +39 -0
  192. data/spec/dummy/config/environments/development.rb +39 -0
  193. data/spec/dummy/config/environments/production.rb +67 -0
  194. data/spec/dummy/config/environments/test.rb +39 -0
  195. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  196. data/spec/dummy/config/initializers/inflections.rb +15 -0
  197. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  198. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  199. data/spec/dummy/config/initializers/session_store.rb +8 -0
  200. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  201. data/spec/dummy/config/locales/en.yml +5 -0
  202. data/spec/dummy/config/pusher.yml +14 -0
  203. data/spec/dummy/config/pusher.yml.example +14 -0
  204. data/spec/dummy/config/routes.rb +5 -0
  205. data/spec/dummy/config/sms_whitelist.json.example +4 -0
  206. data/spec/dummy/config/twilio.yml +57 -0
  207. data/spec/dummy/config/twilio.yml.example +57 -0
  208. data/spec/dummy/db/schema.rb +122 -0
  209. data/spec/dummy/db/seeds.rb +6 -0
  210. data/spec/dummy/log/production.log +156 -0
  211. data/spec/dummy/log/test.log +13812 -0
  212. data/spec/dummy/public/404.html +26 -0
  213. data/spec/dummy/public/422.html +26 -0
  214. data/spec/dummy/public/500.html +25 -0
  215. data/spec/dummy/public/assets/application-628309db7ce8c0abdd91f8f796881599.js +32 -0
  216. data/spec/dummy/public/assets/application-628309db7ce8c0abdd91f8f796881599.js.gz +0 -0
  217. data/spec/dummy/public/assets/application-6c551430f3bdd32ba57c9c41e5f91846.css +24 -0
  218. data/spec/dummy/public/assets/application-6c551430f3bdd32ba57c9c41e5f91846.css.gz +0 -0
  219. data/spec/dummy/public/assets/telephony/backspace-9f5b195e049ed90eb20ecdda6e264b0a.png +0 -0
  220. data/spec/dummy/public/assets/telephony/icon-spinner-ddbae473a70c5425810aeee31d4a8ad7.gif +0 -0
  221. data/spec/dummy/public/assets/telephony/zest-telephony-0e6b13673634da80de9ae09bcca253e3.eot +0 -0
  222. data/spec/dummy/public/assets/telephony/zest-telephony-37f394757ccb11b978f16d9fd32cb3b5.ttf +0 -0
  223. data/spec/dummy/public/assets/telephony/zest-telephony-e7efdbc60c0a1c8404951bc79c7fb3a8.woff +0 -0
  224. data/spec/dummy/public/assets/telephony/zest-telephony-f34287df626936908408f53a33db9e83.svg +73 -0
  225. data/spec/dummy/public/favicon.ico +0 -0
  226. data/spec/dummy/script/rails +6 -0
  227. data/spec/dummy/tmp/cache/assets/C98/020/sprockets%2Fa83f8254d688334ff179984e423f502f +0 -0
  228. data/spec/dummy/tmp/cache/assets/CA4/550/sprockets%2F407f9191fe573f2435c55c017cb0d022 +0 -0
  229. data/spec/dummy/tmp/cache/assets/CAA/6A0/sprockets%2F3265550e2d2c7f5a864ca85d255504c2 +0 -0
  230. data/spec/dummy/tmp/cache/assets/CB0/F60/sprockets%2F462f9efed31e6710732376ae06c27208 +0 -0
  231. data/spec/dummy/tmp/cache/assets/CB6/E20/sprockets%2Fa7092cd9f16917099d754f1380af13e1 +0 -0
  232. data/spec/dummy/tmp/cache/assets/CC7/9F0/sprockets%2F0517100815cd45c43fec1d8510fcb630 +0 -0
  233. data/spec/dummy/tmp/cache/assets/CCA/BF0/sprockets%2F16ea15e0b5d367c34b812612a4207e3e +0 -0
  234. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  235. data/spec/dummy/tmp/cache/assets/CF1/960/sprockets%2F36ef26985821ec702c74dae4af789903 +0 -0
  236. data/spec/dummy/tmp/cache/assets/D07/F30/sprockets%2Fd12862f20df0c9ef7aa2b4216d247079 +0 -0
  237. data/spec/dummy/tmp/cache/assets/D09/BF0/sprockets%2F5c8595efaa8cc5235a09801c60e25a16 +0 -0
  238. data/spec/dummy/tmp/cache/assets/D0D/250/sprockets%2F5e759d66e374910dae5a51b221e6e3a4 +0 -0
  239. data/spec/dummy/tmp/cache/assets/D0D/E30/sprockets%2Fa282879e0788ba133f5bdc211cf134e8 +0 -0
  240. data/spec/dummy/tmp/cache/assets/D11/8E0/sprockets%2F2a193a8af29963f1113bef05788e02ff +0 -0
  241. data/spec/dummy/tmp/cache/assets/D14/270/sprockets%2F7f95a752910ed33d728532f8fabd340d +0 -0
  242. data/spec/dummy/tmp/cache/assets/D17/BE0/sprockets%2F58749d7aea4ca766c2520801f0f96b9b +0 -0
  243. data/spec/dummy/tmp/cache/assets/D18/270/sprockets%2Fbb2d88813b1795a97e9a7c14100eef77 +0 -0
  244. data/spec/dummy/tmp/cache/assets/D22/310/sprockets%2Fbae9148ce1229214dfbb0c425b0054d0 +0 -0
  245. data/spec/dummy/tmp/cache/assets/D30/EB0/sprockets%2F2c668b88beb4c9805d91ed4587f549e7 +0 -0
  246. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  247. data/spec/dummy/tmp/cache/assets/D3C/690/sprockets%2F681ba175fdd2da8d590b7e624b6135a6 +0 -0
  248. data/spec/dummy/tmp/cache/assets/D44/BC0/sprockets%2F7214f66dd91fdd51f00c3882293f5eea +0 -0
  249. data/spec/dummy/tmp/cache/assets/D46/FA0/sprockets%2F4f9543cd9e68ba3141fd488afb13681b +0 -0
  250. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  251. data/spec/dummy/tmp/cache/assets/D51/9A0/sprockets%2Fb6e4cbcf30f6f611671695f79ea846d5 +0 -0
  252. data/spec/dummy/tmp/cache/assets/D55/920/sprockets%2F0a02242aa4c4febcc796419aba103c69 +0 -0
  253. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  254. data/spec/dummy/tmp/cache/assets/D5F/6F0/sprockets%2F155e7bc44f326371cce0ca8bc5b2414e +0 -0
  255. data/spec/dummy/tmp/cache/assets/D6B/250/sprockets%2Fe4eecce7a3371b11038c92f07cb28e67 +0 -0
  256. data/spec/dummy/tmp/cache/assets/D6B/E70/sprockets%2F103a456ae3692e3cca20b7696fdee8f0 +0 -0
  257. data/spec/dummy/tmp/cache/assets/D7F/AD0/sprockets%2Fb1c02d12303b1fe2f981771cbb0c4cbd +0 -0
  258. data/spec/dummy/tmp/cache/assets/D81/D00/sprockets%2F0c68b6d9dce98681a2a710d9fc3f7e39 +0 -0
  259. data/spec/dummy/tmp/cache/assets/D94/4D0/sprockets%2F4608a5bdf27ddf11bcaed1375911e9a2 +0 -0
  260. data/spec/dummy/tmp/cache/assets/D9A/580/sprockets%2F433005b19aaf7ed5cba9c7f8cd30b775 +0 -0
  261. data/spec/dummy/tmp/cache/assets/DA4/270/sprockets%2F860ab3bd30204e02c0a5d82bd4bbabe1 +0 -0
  262. data/spec/dummy/tmp/cache/assets/DA4/480/sprockets%2F53e39285bb57a2ddb6ff856b2eb491da +0 -0
  263. data/spec/dummy/tmp/cache/assets/DA6/3C0/sprockets%2F587c7e35f47442eadaa530acc5e9f5e6 +0 -0
  264. data/spec/dummy/tmp/cache/assets/DAB/DA0/sprockets%2Fb8fb5e8518ed3d38a7f6a8f18a9208aa +0 -0
  265. data/spec/dummy/tmp/cache/assets/DB2/700/sprockets%2Ffa85cb79b94fce1b8344d983ea863d2e +0 -0
  266. data/spec/dummy/tmp/cache/assets/DCC/4F0/sprockets%2Fbc0f3c61e16afb5a285ba8b39846ed8b +0 -0
  267. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  268. data/spec/dummy/tmp/cache/assets/DDC/BE0/sprockets%2F2c0a4d4675a61b014aedbbabb3f071fc +0 -0
  269. data/spec/dummy/tmp/cache/assets/E04/640/sprockets%2F3c5ddf2bbefd9d70f1b506b519cf856e +0 -0
  270. data/spec/dummy/tmp/cache/assets/E04/7F0/sprockets%2F35f1b2ff729a5ec21f6dc5f7d6faa67b +0 -0
  271. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  272. data/spec/dummy/tmp/cache/assets/E07/230/sprockets%2Febd4f2dd708879d593aff008ccb75acc +0 -0
  273. data/spec/dummy/tmp/cache/assets/E17/9D0/sprockets%2F8db2b79f6c4eabe7a9ebe7a7898ec066 +0 -0
  274. data/spec/dummy/tmp/cache/assets/E31/F10/sprockets%2Fcebacf56667da1cc2961b59fd922eafb +0 -0
  275. data/spec/factories/agent.rb +26 -0
  276. data/spec/factories/calls.rb +106 -0
  277. data/spec/factories/conversations.rb +171 -0
  278. data/spec/factories/events.rb +250 -0
  279. data/spec/factories/playable_listeners.rb +6 -0
  280. data/spec/factories/recordings.rb +6 -0
  281. data/spec/factories/voicemails.rb +8 -0
  282. data/spec/fixtures/vcr_cassettes/Authenticating_an_online_user.yml +90 -0
  283. data/spec/fixtures/vcr_cassettes/Creating_a_conversation/creates_a_new_call.yml +42 -0
  284. data/spec/fixtures/vcr_cassettes/Creating_a_conversation/creates_a_new_conversation.yml +42 -0
  285. data/spec/fixtures/vcr_cassettes/Creating_a_conversation/returns_the_conversation_as_JSON.yml +42 -0
  286. data/spec/fixtures/vcr_cassettes/Pusher_channel_as_JSON.yml +90 -0
  287. data/spec/fixtures/vcr_cassettes/Pusher_to_publish_the_event.yml +32 -0
  288. data/spec/fixtures/vcr_cassettes/Reloading_the_widget_during_a_call/_create/during_a_call/after_a_failed_transfer/pushes_the_event_for_the_active_call.yml +1110 -0
  289. data/spec/fixtures/vcr_cassettes/Telephony_ConversationsController/_create/by_default/creates_a_new_call.yml +45 -0
  290. data/spec/fixtures/vcr_cassettes/Telephony_ConversationsController/_create/by_default/creates_a_new_conversation.yml +43 -0
  291. data/spec/fixtures/vcr_cassettes/Telephony_ConversationsController/_create/by_default/returns_the_conversation_as_JSON.yml +44 -0
  292. data/spec/fixtures/vcr_cassettes/Telephony_Providers_TwilioProvider/_call/allows_the_phone_to_ring_for_60_seconds.yml +42 -0
  293. data/spec/fixtures/vcr_cassettes/Telephony_Providers_TwilioProvider/_call/includes_a_status_change_callback_url.yml +42 -0
  294. data/spec/fixtures/vcr_cassettes/Telephony_Providers_TwilioProvider/_call/places_a_call.yml +42 -0
  295. data/spec/fixtures/vcr_cassettes/Telephony_Providers_TwilioProvider/_dial_into_conference/allows_the_phone_to_ring_for_15_seconds.yml +42 -0
  296. data/spec/fixtures/vcr_cassettes/Telephony_Providers_TwilioProvider/_dial_into_conference/places_a_call_to_redirect_the_participant_to_a_conference.yml +42 -0
  297. data/spec/fixtures/vcr_cassettes/Telephony_Providers_TwilioProvider/_hangup/by_default/hangs_up_the_call.yml +42 -0
  298. data/spec/fixtures/vcr_cassettes/buying_number_for_an_area_code.yml +42 -0
  299. data/spec/fixtures/vcr_cassettes/returns_success.yml +90 -0
  300. data/spec/javascripts/helpers/jasmine-jquery.js +546 -0
  301. data/spec/javascripts/helpers/mock-ajax.js +207 -0
  302. data/spec/javascripts/support/jasmine.yml +80 -0
  303. data/spec/javascripts/telephony/models/agent_spec.js +40 -0
  304. data/spec/javascripts/telephony/models/conversation_spec.js +515 -0
  305. data/spec/javascripts/telephony/models/device_spec.js +80 -0
  306. data/spec/javascripts/telephony/models/transfer_spec.js +22 -0
  307. data/spec/javascripts/telephony/push_spec.js +427 -0
  308. data/spec/javascripts/telephony/views/agents_view_spec.js +101 -0
  309. data/spec/javascripts/telephony/views/application_view_spec.js +74 -0
  310. data/spec/javascripts/telephony/views/conversation_view_spec.js +626 -0
  311. data/spec/javascripts/telephony/views/status_view_spec.js +30 -0
  312. data/spec/javascripts/telephony/views/transfer_view_spec.js +187 -0
  313. data/spec/javascripts/telephony/views/twilio_client_view_spec.js +77 -0
  314. data/spec/javascripts/telephony/views/widget_view_spec.js +20 -0
  315. data/spec/lib/telephony/concerns/controllers/twilio_request_verifier_spec.rb +77 -0
  316. data/spec/lib/telephony/conversation_data_spec.rb +342 -0
  317. data/spec/lib/telephony/helper_spec.rb +24 -0
  318. data/spec/lib/telephony/jobs/agent_offline_spec.rb +37 -0
  319. data/spec/lib/telephony/jobs/pusher_event_spec.rb +39 -0
  320. data/spec/lib/telephony/providers/twilio_provider_spec.rb +439 -0
  321. data/spec/lib/telephony_spec.rb +104 -0
  322. data/spec/models/telephony/agent_spec.rb +479 -0
  323. data/spec/models/telephony/agent_state_machine_spec.rb +131 -0
  324. data/spec/models/telephony/call_center_spec.rb +32 -0
  325. data/spec/models/telephony/call_spec.rb +597 -0
  326. data/spec/models/telephony/call_state_machine_spec.rb +472 -0
  327. data/spec/models/telephony/conversation_spec.rb +751 -0
  328. data/spec/models/telephony/conversation_state_machine_spec.rb +387 -0
  329. data/spec/models/telephony/conversations_presenter_spec.rb +40 -0
  330. data/spec/models/telephony/event_spec.rb +716 -0
  331. data/spec/models/telephony/inbound_conversation_queue_spec.rb +243 -0
  332. data/spec/models/telephony/playable_listener_spec.rb +43 -0
  333. data/spec/models/telephony/pusher_event_publisher_spec.rb +36 -0
  334. data/spec/models/telephony/recording_spec.rb +6 -0
  335. data/spec/models/telephony/voicemail_spec.rb +96 -0
  336. data/spec/observers/telephony/agent_observer_spec.rb +21 -0
  337. data/spec/observers/telephony/event_observer_spec.rb +19 -0
  338. data/spec/requests/create_conversation_spec.rb +39 -0
  339. data/spec/requests/dequeue_call_spec.rb +42 -0
  340. data/spec/requests/list_conversations_spec.rb +33 -0
  341. data/spec/requests/presences_spec.rb +51 -0
  342. data/spec/requests/providers/twilio/calls/child_answered_spec.rb +24 -0
  343. data/spec/requests/providers/twilio/calls/child_detached_spec.rb +249 -0
  344. data/spec/requests/providers/twilio/calls/dial_spec.rb +132 -0
  345. data/spec/requests/providers/twilio/calls/done_spec.rb +69 -0
  346. data/spec/requests/providers/twilio/calls/join_conference_spec.rb +56 -0
  347. data/spec/requests/providers/twilio/calls/leave_queue_spec.rb +44 -0
  348. data/spec/requests/providers/twilio/calls/parent_answered_spec.rb +59 -0
  349. data/spec/requests/providers/twilio/inbound/connect_dequeued_call_spec.rb +124 -0
  350. data/spec/requests/providers/twilio/inbound/enqueue_inbound_call_spec.rb +108 -0
  351. data/spec/requests/providers/twilio/inbound/enqueued_call_wait_music_spec.rb +13 -0
  352. data/spec/requests/providers/twilio/voicemails/leave_voicemail_spec.rb +78 -0
  353. data/spec/requests/search_conversations_spec.rb +101 -0
  354. data/spec/requests/transfer_spec.rb +65 -0
  355. data/spec/requests/voicemail_api_spec.rb +58 -0
  356. data/spec/spec_helper.rb +27 -0
  357. data/spec/support/factory_girl.rb +5 -0
  358. data/spec/support/matchers/be_complete_hold.rb +20 -0
  359. data/spec/support/matchers/be_whisper_tone.rb +35 -0
  360. data/spec/support/matchers/join_conference.rb +23 -0
  361. data/spec/support/nokogiri.rb +1 -0
  362. data/spec/support/pusher_helper.rb +24 -0
  363. data/spec/support/vcr.rb +12 -0
  364. data/spec/support/webmock.rb +1 -0
  365. metadata +692 -0
@@ -0,0 +1,1018 @@
1
+ // Chosen, a Select Box Enhancer for jQuery and Protoype
2
+ // by Patrick Filler for Harvest, http://getharvest.com
3
+ //
4
+ // Version 0.9.8
5
+ // Full source at https://github.com/harvesthq/chosen
6
+ // Copyright (c) 2011 Harvest http://getharvest.com
7
+
8
+ // MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
9
+ // This file is generated by `cake build`, do not edit it by hand.
10
+ (function() {
11
+ var SelectParser;
12
+
13
+ SelectParser = (function() {
14
+
15
+ function SelectParser() {
16
+ this.options_index = 0;
17
+ this.parsed = [];
18
+ }
19
+
20
+ SelectParser.prototype.add_node = function(child) {
21
+ if (child.nodeName.toUpperCase() === "OPTGROUP") {
22
+ return this.add_group(child);
23
+ } else {
24
+ return this.add_option(child);
25
+ }
26
+ };
27
+
28
+ SelectParser.prototype.add_group = function(group) {
29
+ var group_position, option, _i, _len, _ref, _results;
30
+ group_position = this.parsed.length;
31
+ this.parsed.push({
32
+ array_index: group_position,
33
+ group: true,
34
+ label: group.label,
35
+ children: 0,
36
+ disabled: group.disabled
37
+ });
38
+ _ref = group.childNodes;
39
+ _results = [];
40
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
41
+ option = _ref[_i];
42
+ _results.push(this.add_option(option, group_position, group.disabled));
43
+ }
44
+ return _results;
45
+ };
46
+
47
+ SelectParser.prototype.add_option = function(option, group_position, group_disabled) {
48
+ if (option.nodeName.toUpperCase() === "OPTION") {
49
+ if (option.text !== "") {
50
+ if (group_position != null) this.parsed[group_position].children += 1;
51
+ this.parsed.push({
52
+ array_index: this.parsed.length,
53
+ options_index: this.options_index,
54
+ value: option.value,
55
+ text: option.text,
56
+ html: option.innerHTML,
57
+ selected: option.selected,
58
+ disabled: group_disabled === true ? group_disabled : option.disabled,
59
+ group_array_index: group_position,
60
+ classes: option.className,
61
+ style: option.style.cssText
62
+ });
63
+ } else {
64
+ this.parsed.push({
65
+ array_index: this.parsed.length,
66
+ options_index: this.options_index,
67
+ empty: true
68
+ });
69
+ }
70
+ return this.options_index += 1;
71
+ }
72
+ };
73
+
74
+ return SelectParser;
75
+
76
+ })();
77
+
78
+ SelectParser.select_to_array = function(select) {
79
+ var child, parser, _i, _len, _ref;
80
+ parser = new SelectParser();
81
+ _ref = select.childNodes;
82
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
83
+ child = _ref[_i];
84
+ parser.add_node(child);
85
+ }
86
+ return parser.parsed;
87
+ };
88
+
89
+ this.SelectParser = SelectParser;
90
+
91
+ }).call(this);
92
+
93
+ /*
94
+ Chosen source: generate output using 'cake build'
95
+ Copyright (c) 2011 by Harvest
96
+ */
97
+
98
+ (function() {
99
+ var AbstractChosen, root;
100
+
101
+ root = this;
102
+
103
+ AbstractChosen = (function() {
104
+
105
+ function AbstractChosen(form_field, options) {
106
+ this.form_field = form_field;
107
+ this.options = options != null ? options : {};
108
+ this.set_default_values();
109
+ this.is_multiple = this.form_field.multiple;
110
+ this.set_default_text();
111
+ this.setup();
112
+ this.set_up_html();
113
+ this.register_observers();
114
+ this.finish_setup();
115
+ }
116
+
117
+ AbstractChosen.prototype.set_default_values = function() {
118
+ var _this = this;
119
+ this.click_test_action = function(evt) {
120
+ return _this.test_active_click(evt);
121
+ };
122
+ this.activate_action = function(evt) {
123
+ return _this.activate_field(evt);
124
+ };
125
+ this.active_field = false;
126
+ this.mouse_on_container = false;
127
+ this.results_showing = false;
128
+ this.result_highlighted = null;
129
+ this.result_single_selected = null;
130
+ this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false;
131
+ this.disable_search_threshold = this.options.disable_search_threshold || 0;
132
+ this.disable_search = this.options.disable_search || false;
133
+ this.search_contains = this.options.search_contains || false;
134
+ this.choices = 0;
135
+ this.single_backstroke_delete = this.options.single_backstroke_delete || false;
136
+ return this.max_selected_options = this.options.max_selected_options || Infinity;
137
+ };
138
+
139
+ AbstractChosen.prototype.set_default_text = function() {
140
+ if (this.form_field.getAttribute("data-placeholder")) {
141
+ this.default_text = this.form_field.getAttribute("data-placeholder");
142
+ } else if (this.is_multiple) {
143
+ this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || "Select Some Options";
144
+ } else {
145
+ this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || "Select an Option";
146
+ }
147
+ return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || "No results match";
148
+ };
149
+
150
+ AbstractChosen.prototype.mouse_enter = function() {
151
+ return this.mouse_on_container = true;
152
+ };
153
+
154
+ AbstractChosen.prototype.mouse_leave = function() {
155
+ return this.mouse_on_container = false;
156
+ };
157
+
158
+ AbstractChosen.prototype.input_focus = function(evt) {
159
+ var _this = this;
160
+ if (this.is_multiple) {
161
+ if (!this.active_field) {
162
+ return setTimeout((function() {
163
+ return _this.container_mousedown();
164
+ }), 50);
165
+ }
166
+ } else {
167
+ if (!this.active_field) return this.activate_field();
168
+ }
169
+ };
170
+
171
+ AbstractChosen.prototype.input_blur = function(evt) {
172
+ var _this = this;
173
+ if (!this.mouse_on_container) {
174
+ this.active_field = false;
175
+ return setTimeout((function() {
176
+ return _this.blur_test();
177
+ }), 100);
178
+ }
179
+ };
180
+
181
+ AbstractChosen.prototype.result_add_option = function(option) {
182
+ var classes, style;
183
+ if (!option.disabled) {
184
+ option.dom_id = this.container_id + "_o_" + option.array_index;
185
+ classes = option.selected && this.is_multiple ? [] : ["active-result"];
186
+ if (option.selected) classes.push("result-selected");
187
+ if (option.group_array_index != null) classes.push("group-option");
188
+ if (option.classes !== "") classes.push(option.classes);
189
+ style = option.style.cssText !== "" ? " style=\"" + option.style + "\"" : "";
190
+ return '<li id="' + option.dom_id + '" class="' + classes.join(' ') + '"' + style + '>' + option.html + '</li>';
191
+ } else {
192
+ return "";
193
+ }
194
+ };
195
+
196
+ AbstractChosen.prototype.results_update_field = function() {
197
+ if (!this.is_multiple) this.results_reset_cleanup();
198
+ this.result_clear_highlight();
199
+ this.result_single_selected = null;
200
+ return this.results_build();
201
+ };
202
+
203
+ AbstractChosen.prototype.results_toggle = function() {
204
+ if (this.results_showing) {
205
+ return this.results_hide();
206
+ } else {
207
+ return this.results_show();
208
+ }
209
+ };
210
+
211
+ AbstractChosen.prototype.results_search = function(evt) {
212
+ if (this.results_showing) {
213
+ return this.winnow_results();
214
+ } else {
215
+ return this.results_show();
216
+ }
217
+ };
218
+
219
+ AbstractChosen.prototype.keyup_checker = function(evt) {
220
+ var stroke, _ref;
221
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
222
+ this.search_field_scale();
223
+ switch (stroke) {
224
+ case 8:
225
+ if (this.is_multiple && this.backstroke_length < 1 && this.choices > 0) {
226
+ return this.keydown_backstroke();
227
+ } else if (!this.pending_backstroke) {
228
+ this.result_clear_highlight();
229
+ return this.results_search();
230
+ }
231
+ break;
232
+ case 13:
233
+ evt.preventDefault();
234
+ if (this.results_showing) return this.result_select(evt);
235
+ break;
236
+ case 27:
237
+ if (this.results_showing) this.results_hide();
238
+ return true;
239
+ case 9:
240
+ case 38:
241
+ case 40:
242
+ case 16:
243
+ case 91:
244
+ case 17:
245
+ break;
246
+ default:
247
+ return this.results_search();
248
+ }
249
+ };
250
+
251
+ AbstractChosen.prototype.generate_field_id = function() {
252
+ var new_id;
253
+ new_id = this.generate_random_id();
254
+ this.form_field.id = new_id;
255
+ return new_id;
256
+ };
257
+
258
+ AbstractChosen.prototype.generate_random_char = function() {
259
+ var chars, newchar, rand;
260
+ chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
261
+ rand = Math.floor(Math.random() * chars.length);
262
+ return newchar = chars.substring(rand, rand + 1);
263
+ };
264
+
265
+ return AbstractChosen;
266
+
267
+ })();
268
+
269
+ root.AbstractChosen = AbstractChosen;
270
+
271
+ }).call(this);
272
+
273
+ /*
274
+ Chosen source: generate output using 'cake build'
275
+ Copyright (c) 2011 by Harvest
276
+ */
277
+
278
+ (function() {
279
+ var $, Chosen, get_side_border_padding, root,
280
+ __hasProp = Object.prototype.hasOwnProperty,
281
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
282
+
283
+ root = this;
284
+
285
+ $ = jQuery;
286
+
287
+ $.fn.extend({
288
+ chosen: function(options) {
289
+ if ($.browser.msie && ($.browser.version === "6.0" || ($.browser.version === "7.0" && document.documentMode === 7))) {
290
+ return this;
291
+ }
292
+ return this.each(function(input_field) {
293
+ var $this;
294
+ $this = $(this);
295
+ if (!$this.hasClass("chzn-done")) {
296
+ return $this.data('chosen', new Chosen(this, options));
297
+ }
298
+ });
299
+ }
300
+ });
301
+
302
+ Chosen = (function(_super) {
303
+
304
+ __extends(Chosen, _super);
305
+
306
+ function Chosen() {
307
+ Chosen.__super__.constructor.apply(this, arguments);
308
+ }
309
+
310
+ Chosen.prototype.setup = function() {
311
+ this.form_field_jq = $(this.form_field);
312
+ this.current_value = this.form_field_jq.val();
313
+ return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
314
+ };
315
+
316
+ Chosen.prototype.finish_setup = function() {
317
+ return this.form_field_jq.addClass("chzn-done");
318
+ };
319
+
320
+ Chosen.prototype.set_up_html = function() {
321
+ var container_div, dd_top, dd_width, sf_width;
322
+ this.container_id = this.form_field.id.length ? this.form_field.id.replace(/[^\w]/g, '_') : this.generate_field_id();
323
+ this.container_id += "_chzn";
324
+ this.f_width = this.form_field_jq.outerWidth();
325
+ container_div = $("<div />", {
326
+ id: this.container_id,
327
+ "class": "chzn-container" + (this.is_rtl ? ' chzn-rtl' : ''),
328
+ style: 'width: ' + this.f_width + 'px;'
329
+ });
330
+ if (this.is_multiple) {
331
+ container_div.html('<ul class="chzn-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chzn-drop" style="left:-9000px;"><ul class="chzn-results"></ul></div>');
332
+ } else {
333
+ container_div.html('<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chzn-drop" style="left:-9000px;"><div class="chzn-search"><input type="text" autocomplete="off" /></div><ul class="chzn-results"></ul></div>');
334
+ }
335
+ this.form_field_jq.hide().after(container_div);
336
+ this.container = $('#' + this.container_id);
337
+ this.container.addClass("chzn-container-" + (this.is_multiple ? "multi" : "single"));
338
+ this.dropdown = this.container.find('div.chzn-drop').first();
339
+ dd_top = this.container.height();
340
+ dd_width = this.f_width - get_side_border_padding(this.dropdown);
341
+ this.dropdown.css({
342
+ "width": dd_width + "px",
343
+ "top": dd_top + "px"
344
+ });
345
+ this.search_field = this.container.find('input').first();
346
+ this.search_results = this.container.find('ul.chzn-results').first();
347
+ this.search_field_scale();
348
+ this.search_no_results = this.container.find('li.no-results').first();
349
+ if (this.is_multiple) {
350
+ this.search_choices = this.container.find('ul.chzn-choices').first();
351
+ this.search_container = this.container.find('li.search-field').first();
352
+ } else {
353
+ this.search_container = this.container.find('div.chzn-search').first();
354
+ this.selected_item = this.container.find('.chzn-single').first();
355
+ sf_width = dd_width - get_side_border_padding(this.search_container) - get_side_border_padding(this.search_field);
356
+ this.search_field.css({
357
+ "width": sf_width + "px"
358
+ });
359
+ }
360
+ this.results_build();
361
+ this.set_tab_index();
362
+ return this.form_field_jq.trigger("liszt:ready", {
363
+ chosen: this
364
+ });
365
+ };
366
+
367
+ Chosen.prototype.register_observers = function() {
368
+ var _this = this;
369
+ this.container.mousedown(function(evt) {
370
+ return _this.container_mousedown(evt);
371
+ });
372
+ this.container.mouseup(function(evt) {
373
+ return _this.container_mouseup(evt);
374
+ });
375
+ this.container.mouseenter(function(evt) {
376
+ return _this.mouse_enter(evt);
377
+ });
378
+ this.container.mouseleave(function(evt) {
379
+ return _this.mouse_leave(evt);
380
+ });
381
+ this.search_results.mouseup(function(evt) {
382
+ return _this.search_results_mouseup(evt);
383
+ });
384
+ this.search_results.mouseover(function(evt) {
385
+ return _this.search_results_mouseover(evt);
386
+ });
387
+ this.search_results.mouseout(function(evt) {
388
+ return _this.search_results_mouseout(evt);
389
+ });
390
+ this.form_field_jq.bind("liszt:updated", function(evt) {
391
+ return _this.results_update_field(evt);
392
+ });
393
+ this.form_field_jq.bind("liszt:activate", function(evt) {
394
+ return _this.activate_field(evt);
395
+ });
396
+ this.form_field_jq.bind("liszt:open", function(evt) {
397
+ return _this.container_mousedown(evt);
398
+ });
399
+ this.search_field.blur(function(evt) {
400
+ return _this.input_blur(evt);
401
+ });
402
+ this.search_field.keyup(function(evt) {
403
+ return _this.keyup_checker(evt);
404
+ });
405
+ this.search_field.keydown(function(evt) {
406
+ return _this.keydown_checker(evt);
407
+ });
408
+ this.search_field.focus(function(evt) {
409
+ return _this.input_focus(evt);
410
+ });
411
+ if (this.is_multiple) {
412
+ return this.search_choices.click(function(evt) {
413
+ return _this.choices_click(evt);
414
+ });
415
+ } else {
416
+ return this.container.click(function(evt) {
417
+ return evt.preventDefault();
418
+ });
419
+ }
420
+ };
421
+
422
+ Chosen.prototype.search_field_disabled = function() {
423
+ this.is_disabled = this.form_field_jq[0].disabled;
424
+ if (this.is_disabled) {
425
+ this.container.addClass('chzn-disabled');
426
+ this.search_field[0].disabled = true;
427
+ if (!this.is_multiple) {
428
+ this.selected_item.unbind("focus", this.activate_action);
429
+ }
430
+ return this.close_field();
431
+ } else {
432
+ this.container.removeClass('chzn-disabled');
433
+ this.search_field[0].disabled = false;
434
+ if (!this.is_multiple) {
435
+ return this.selected_item.bind("focus", this.activate_action);
436
+ }
437
+ }
438
+ };
439
+
440
+ Chosen.prototype.container_mousedown = function(evt) {
441
+ var target_closelink;
442
+ if (!this.is_disabled) {
443
+ target_closelink = evt != null ? ($(evt.target)).hasClass("search-choice-close") : false;
444
+ if (evt && evt.type === "mousedown" && !this.results_showing) {
445
+ evt.stopPropagation();
446
+ }
447
+ if (!this.pending_destroy_click && !target_closelink) {
448
+ if (!this.active_field) {
449
+ if (this.is_multiple) this.search_field.val("");
450
+ $(document).click(this.click_test_action);
451
+ this.results_show();
452
+ } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chzn-single").length)) {
453
+ evt.preventDefault();
454
+ this.results_toggle();
455
+ }
456
+ return this.activate_field();
457
+ } else {
458
+ return this.pending_destroy_click = false;
459
+ }
460
+ }
461
+ };
462
+
463
+ Chosen.prototype.container_mouseup = function(evt) {
464
+ if (evt.target.nodeName === "ABBR" && !this.is_disabled) {
465
+ return this.results_reset(evt);
466
+ }
467
+ };
468
+
469
+ Chosen.prototype.blur_test = function(evt) {
470
+ if (!this.active_field && this.container.hasClass("chzn-container-active")) {
471
+ return this.close_field();
472
+ }
473
+ };
474
+
475
+ Chosen.prototype.close_field = function() {
476
+ $(document).unbind("click", this.click_test_action);
477
+ this.active_field = false;
478
+ this.results_hide();
479
+ this.container.removeClass("chzn-container-active");
480
+ this.winnow_results_clear();
481
+ this.clear_backstroke();
482
+ this.show_search_field_default();
483
+ return this.search_field_scale();
484
+ };
485
+
486
+ Chosen.prototype.activate_field = function() {
487
+ this.container.addClass("chzn-container-active");
488
+ this.active_field = true;
489
+ this.search_field.val(this.search_field.val());
490
+ return this.search_field.focus();
491
+ };
492
+
493
+ Chosen.prototype.test_active_click = function(evt) {
494
+ if ($(evt.target).parents('#' + this.container_id).length) {
495
+ return this.active_field = true;
496
+ } else {
497
+ return this.close_field();
498
+ }
499
+ };
500
+
501
+ Chosen.prototype.results_build = function() {
502
+ var content, data, _i, _len, _ref;
503
+ this.parsing = true;
504
+ this.results_data = root.SelectParser.select_to_array(this.form_field);
505
+ if (this.is_multiple && this.choices > 0) {
506
+ this.search_choices.find("li.search-choice").remove();
507
+ this.choices = 0;
508
+ } else if (!this.is_multiple) {
509
+ this.selected_item.addClass("chzn-default").find("span").text(this.default_text);
510
+ if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) {
511
+ this.container.addClass("chzn-container-single-nosearch");
512
+ } else {
513
+ this.container.removeClass("chzn-container-single-nosearch");
514
+ }
515
+ }
516
+ content = '';
517
+ _ref = this.results_data;
518
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
519
+ data = _ref[_i];
520
+ if (data.group) {
521
+ content += this.result_add_group(data);
522
+ } else if (!data.empty) {
523
+ content += this.result_add_option(data);
524
+ if (data.selected && this.is_multiple) {
525
+ this.choice_build(data);
526
+ } else if (data.selected && !this.is_multiple) {
527
+ this.selected_item.removeClass("chzn-default").find("span").text(data.text);
528
+ if (this.allow_single_deselect) this.single_deselect_control_build();
529
+ }
530
+ }
531
+ }
532
+ this.search_field_disabled();
533
+ this.show_search_field_default();
534
+ this.search_field_scale();
535
+ this.search_results.html(content);
536
+ return this.parsing = false;
537
+ };
538
+
539
+ Chosen.prototype.result_add_group = function(group) {
540
+ if (!group.disabled) {
541
+ group.dom_id = this.container_id + "_g_" + group.array_index;
542
+ return '<li id="' + group.dom_id + '" class="group-result">' + $("<div />").text(group.label).html() + '</li>';
543
+ } else {
544
+ return "";
545
+ }
546
+ };
547
+
548
+ Chosen.prototype.result_do_highlight = function(el) {
549
+ var high_bottom, high_top, maxHeight, visible_bottom, visible_top;
550
+ if (el.length) {
551
+ this.result_clear_highlight();
552
+ this.result_highlight = el;
553
+ this.result_highlight.addClass("highlighted");
554
+ maxHeight = parseInt(this.search_results.css("maxHeight"), 10);
555
+ visible_top = this.search_results.scrollTop();
556
+ visible_bottom = maxHeight + visible_top;
557
+ high_top = this.result_highlight.position().top + this.search_results.scrollTop();
558
+ high_bottom = high_top + this.result_highlight.outerHeight();
559
+ if (high_bottom >= visible_bottom) {
560
+ return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0);
561
+ } else if (high_top < visible_top) {
562
+ return this.search_results.scrollTop(high_top);
563
+ }
564
+ }
565
+ };
566
+
567
+ Chosen.prototype.result_clear_highlight = function() {
568
+ if (this.result_highlight) this.result_highlight.removeClass("highlighted");
569
+ return this.result_highlight = null;
570
+ };
571
+
572
+ Chosen.prototype.results_show = function() {
573
+ var dd_top;
574
+ if (!this.is_multiple) {
575
+ this.selected_item.addClass("chzn-single-with-drop");
576
+ if (this.result_single_selected) {
577
+ this.result_do_highlight(this.result_single_selected);
578
+ }
579
+ } else if (this.max_selected_options <= this.choices) {
580
+ this.form_field_jq.trigger("liszt:maxselected", {
581
+ chosen: this
582
+ });
583
+ return false;
584
+ }
585
+ dd_top = this.is_multiple ? this.container.height() : this.container.height() - 1;
586
+ this.form_field_jq.trigger("liszt:showing_dropdown", {
587
+ chosen: this
588
+ });
589
+ this.dropdown.css({
590
+ "top": dd_top + "px",
591
+ "left": 0
592
+ });
593
+ this.results_showing = true;
594
+ this.search_field.focus();
595
+ this.search_field.val(this.search_field.val());
596
+ return this.winnow_results();
597
+ };
598
+
599
+ Chosen.prototype.results_hide = function() {
600
+ if (!this.is_multiple) {
601
+ this.selected_item.removeClass("chzn-single-with-drop");
602
+ }
603
+ this.result_clear_highlight();
604
+ this.form_field_jq.trigger("liszt:hiding_dropdown", {
605
+ chosen: this
606
+ });
607
+ this.dropdown.css({
608
+ "left": "-9000px"
609
+ });
610
+ return this.results_showing = false;
611
+ };
612
+
613
+ Chosen.prototype.set_tab_index = function(el) {
614
+ var ti;
615
+ if (this.form_field_jq.attr("tabindex")) {
616
+ ti = this.form_field_jq.attr("tabindex");
617
+ this.form_field_jq.attr("tabindex", -1);
618
+ return this.search_field.attr("tabindex", ti);
619
+ }
620
+ };
621
+
622
+ Chosen.prototype.show_search_field_default = function() {
623
+ if (this.is_multiple && this.choices < 1 && !this.active_field) {
624
+ this.search_field.val(this.default_text);
625
+ return this.search_field.addClass("default");
626
+ } else {
627
+ this.search_field.val("");
628
+ return this.search_field.removeClass("default");
629
+ }
630
+ };
631
+
632
+ Chosen.prototype.search_results_mouseup = function(evt) {
633
+ var target;
634
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
635
+ if (target.length) {
636
+ this.result_highlight = target;
637
+ this.result_select(evt);
638
+ return this.search_field.focus();
639
+ }
640
+ };
641
+
642
+ Chosen.prototype.search_results_mouseover = function(evt) {
643
+ var target;
644
+ target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first();
645
+ if (target) return this.result_do_highlight(target);
646
+ };
647
+
648
+ Chosen.prototype.search_results_mouseout = function(evt) {
649
+ if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) {
650
+ return this.result_clear_highlight();
651
+ }
652
+ };
653
+
654
+ Chosen.prototype.choices_click = function(evt) {
655
+ evt.preventDefault();
656
+ if (this.active_field && !($(evt.target).hasClass("search-choice" || $(evt.target).parents('.search-choice').first)) && !this.results_showing) {
657
+ return this.results_show();
658
+ }
659
+ };
660
+
661
+ Chosen.prototype.choice_build = function(item) {
662
+ var choice_id, html, link,
663
+ _this = this;
664
+ if (this.is_multiple && this.max_selected_options <= this.choices) {
665
+ this.form_field_jq.trigger("liszt:maxselected", {
666
+ chosen: this
667
+ });
668
+ return false;
669
+ }
670
+ choice_id = this.container_id + "_c_" + item.array_index;
671
+ this.choices += 1;
672
+ if (item.disabled) {
673
+ html = '<li class="search-choice search-choice-disabled" id="' + choice_id + '"><span>' + item.html + '</span></li>';
674
+ } else {
675
+ html = '<li class="search-choice" id="' + choice_id + '"><span>' + item.html + '</span><a href="javascript:void(0)" class="search-choice-close" rel="' + item.array_index + '"></a></li>';
676
+ }
677
+ this.search_container.before(html);
678
+ link = $('#' + choice_id).find("a").first();
679
+ return link.click(function(evt) {
680
+ return _this.choice_destroy_link_click(evt);
681
+ });
682
+ };
683
+
684
+ Chosen.prototype.choice_destroy_link_click = function(evt) {
685
+ evt.preventDefault();
686
+ if (!this.is_disabled) {
687
+ this.pending_destroy_click = true;
688
+ return this.choice_destroy($(evt.target));
689
+ } else {
690
+ return evt.stopPropagation;
691
+ }
692
+ };
693
+
694
+ Chosen.prototype.choice_destroy = function(link) {
695
+ if (this.result_deselect(link.attr("rel"))) {
696
+ this.choices -= 1;
697
+ this.show_search_field_default();
698
+ if (this.is_multiple && this.choices > 0 && this.search_field.val().length < 1) {
699
+ this.results_hide();
700
+ }
701
+ return link.parents('li').first().remove();
702
+ }
703
+ };
704
+
705
+ Chosen.prototype.results_reset = function() {
706
+ this.form_field.options[0].selected = true;
707
+ this.selected_item.find("span").text(this.default_text);
708
+ if (!this.is_multiple) this.selected_item.addClass("chzn-default");
709
+ this.show_search_field_default();
710
+ this.results_reset_cleanup();
711
+ this.form_field_jq.trigger("change");
712
+ if (this.active_field) return this.results_hide();
713
+ };
714
+
715
+ Chosen.prototype.results_reset_cleanup = function() {
716
+ this.current_value = this.form_field_jq.val();
717
+ return this.selected_item.find("abbr").remove();
718
+ };
719
+
720
+ Chosen.prototype.result_select = function(evt) {
721
+ var high, high_id, item, position;
722
+ if (this.result_highlight) {
723
+ high = this.result_highlight;
724
+ high_id = high.attr("id");
725
+ this.result_clear_highlight();
726
+ if (this.is_multiple) {
727
+ this.result_deactivate(high);
728
+ } else {
729
+ this.search_results.find(".result-selected").removeClass("result-selected");
730
+ this.result_single_selected = high;
731
+ this.selected_item.removeClass("chzn-default");
732
+ }
733
+ high.addClass("result-selected");
734
+ position = high_id.substr(high_id.lastIndexOf("_") + 1);
735
+ item = this.results_data[position];
736
+ item.selected = true;
737
+ this.form_field.options[item.options_index].selected = true;
738
+ if (this.is_multiple) {
739
+ this.choice_build(item);
740
+ } else {
741
+ this.selected_item.find("span").first().text(item.text);
742
+ if (this.allow_single_deselect) this.single_deselect_control_build();
743
+ }
744
+ if (!(evt.metaKey && this.is_multiple)) this.results_hide();
745
+ this.search_field.val("");
746
+ if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
747
+ this.form_field_jq.trigger("change", {
748
+ 'selected': this.form_field.options[item.options_index].value
749
+ });
750
+ }
751
+ this.current_value = this.form_field_jq.val();
752
+ return this.search_field_scale();
753
+ }
754
+ };
755
+
756
+ Chosen.prototype.result_activate = function(el) {
757
+ return el.addClass("active-result");
758
+ };
759
+
760
+ Chosen.prototype.result_deactivate = function(el) {
761
+ return el.removeClass("active-result");
762
+ };
763
+
764
+ Chosen.prototype.result_deselect = function(pos) {
765
+ var result, result_data;
766
+ result_data = this.results_data[pos];
767
+ if (!this.form_field.options[result_data.options_index].disabled) {
768
+ result_data.selected = false;
769
+ this.form_field.options[result_data.options_index].selected = false;
770
+ result = $("#" + this.container_id + "_o_" + pos);
771
+ result.removeClass("result-selected").addClass("active-result").show();
772
+ this.result_clear_highlight();
773
+ this.winnow_results();
774
+ this.form_field_jq.trigger("change", {
775
+ deselected: this.form_field.options[result_data.options_index].value
776
+ });
777
+ this.search_field_scale();
778
+ return true;
779
+ } else {
780
+ return false;
781
+ }
782
+ };
783
+
784
+ Chosen.prototype.single_deselect_control_build = function() {
785
+ if (this.allow_single_deselect && this.selected_item.find("abbr").length < 1) {
786
+ return this.selected_item.find("span").first().after("<abbr class=\"search-choice-close\"></abbr>");
787
+ }
788
+ };
789
+
790
+ Chosen.prototype.winnow_results = function() {
791
+ var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len2, _ref;
792
+ this.no_results_clear();
793
+ results = 0;
794
+ searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
795
+ regexAnchor = this.search_contains ? "" : "^";
796
+ regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
797
+ zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
798
+ _ref = this.results_data;
799
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
800
+ option = _ref[_i];
801
+ if (!option.disabled && !option.empty) {
802
+ if (option.group) {
803
+ $('#' + option.dom_id).css('display', 'none');
804
+ } else if (!(this.is_multiple && option.selected)) {
805
+ found = false;
806
+ result_id = option.dom_id;
807
+ result = $("#" + result_id);
808
+ if (regex.test(option.html)) {
809
+ found = true;
810
+ results += 1;
811
+ } else if (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0) {
812
+ parts = option.html.replace(/\[|\]/g, "").split(" ");
813
+ if (parts.length) {
814
+ for (_j = 0, _len2 = parts.length; _j < _len2; _j++) {
815
+ part = parts[_j];
816
+ if (regex.test(part)) {
817
+ found = true;
818
+ results += 1;
819
+ }
820
+ }
821
+ }
822
+ }
823
+ if (found) {
824
+ if (searchText.length) {
825
+ startpos = option.html.search(zregex);
826
+ text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
827
+ text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
828
+ } else {
829
+ text = option.html;
830
+ }
831
+ result.html(text);
832
+ this.result_activate(result);
833
+ if (option.group_array_index != null) {
834
+ $("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
835
+ }
836
+ } else {
837
+ if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
838
+ this.result_clear_highlight();
839
+ }
840
+ this.result_deactivate(result);
841
+ }
842
+ }
843
+ }
844
+ }
845
+ if (results < 1 && searchText.length) {
846
+ return this.no_results(searchText);
847
+ } else {
848
+ return this.winnow_results_set_highlight();
849
+ }
850
+ };
851
+
852
+ Chosen.prototype.winnow_results_clear = function() {
853
+ var li, lis, _i, _len, _results;
854
+ this.search_field.val("");
855
+ lis = this.search_results.find("li");
856
+ _results = [];
857
+ for (_i = 0, _len = lis.length; _i < _len; _i++) {
858
+ li = lis[_i];
859
+ li = $(li);
860
+ if (li.hasClass("group-result")) {
861
+ _results.push(li.css('display', 'auto'));
862
+ } else if (!this.is_multiple || !li.hasClass("result-selected")) {
863
+ _results.push(this.result_activate(li));
864
+ } else {
865
+ _results.push(void 0);
866
+ }
867
+ }
868
+ return _results;
869
+ };
870
+
871
+ Chosen.prototype.winnow_results_set_highlight = function() {
872
+ var do_high, selected_results;
873
+ if (!this.result_highlight) {
874
+ selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : [];
875
+ do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first();
876
+ if (do_high != null) return this.result_do_highlight(do_high);
877
+ }
878
+ };
879
+
880
+ Chosen.prototype.no_results = function(terms) {
881
+ var no_results_html;
882
+ no_results_html = $('<li class="no-results">' + this.results_none_found + ' "<span></span>"</li>');
883
+ no_results_html.find("span").first().html(terms);
884
+ return this.search_results.append(no_results_html);
885
+ };
886
+
887
+ Chosen.prototype.no_results_clear = function() {
888
+ return this.search_results.find(".no-results").remove();
889
+ };
890
+
891
+ Chosen.prototype.keydown_arrow = function() {
892
+ var first_active, next_sib;
893
+ if (!this.result_highlight) {
894
+ first_active = this.search_results.find("li.active-result").first();
895
+ if (first_active) this.result_do_highlight($(first_active));
896
+ } else if (this.results_showing) {
897
+ next_sib = this.result_highlight.nextAll("li.active-result").first();
898
+ if (next_sib) this.result_do_highlight(next_sib);
899
+ }
900
+ if (!this.results_showing) return this.results_show();
901
+ };
902
+
903
+ Chosen.prototype.keyup_arrow = function() {
904
+ var prev_sibs;
905
+ if (!this.results_showing && !this.is_multiple) {
906
+ return this.results_show();
907
+ } else if (this.result_highlight) {
908
+ prev_sibs = this.result_highlight.prevAll("li.active-result");
909
+ if (prev_sibs.length) {
910
+ return this.result_do_highlight(prev_sibs.first());
911
+ } else {
912
+ if (this.choices > 0) this.results_hide();
913
+ return this.result_clear_highlight();
914
+ }
915
+ }
916
+ };
917
+
918
+ Chosen.prototype.keydown_backstroke = function() {
919
+ var next_available_destroy;
920
+ if (this.pending_backstroke) {
921
+ this.choice_destroy(this.pending_backstroke.find("a").first());
922
+ return this.clear_backstroke();
923
+ } else {
924
+ next_available_destroy = this.search_container.siblings("li.search-choice").last();
925
+ if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) {
926
+ this.pending_backstroke = next_available_destroy;
927
+ if (this.single_backstroke_delete) {
928
+ return this.keydown_backstroke();
929
+ } else {
930
+ return this.pending_backstroke.addClass("search-choice-focus");
931
+ }
932
+ }
933
+ }
934
+ };
935
+
936
+ Chosen.prototype.clear_backstroke = function() {
937
+ if (this.pending_backstroke) {
938
+ this.pending_backstroke.removeClass("search-choice-focus");
939
+ }
940
+ return this.pending_backstroke = null;
941
+ };
942
+
943
+ Chosen.prototype.keydown_checker = function(evt) {
944
+ var stroke, _ref;
945
+ stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
946
+ this.search_field_scale();
947
+ if (stroke !== 8 && this.pending_backstroke) this.clear_backstroke();
948
+ switch (stroke) {
949
+ case 8:
950
+ this.backstroke_length = this.search_field.val().length;
951
+ break;
952
+ case 9:
953
+ if (this.results_showing && !this.is_multiple) this.result_select(evt);
954
+ this.mouse_on_container = false;
955
+ break;
956
+ case 13:
957
+ evt.preventDefault();
958
+ break;
959
+ case 38:
960
+ evt.preventDefault();
961
+ this.keyup_arrow();
962
+ break;
963
+ case 40:
964
+ this.keydown_arrow();
965
+ break;
966
+ }
967
+ };
968
+
969
+ Chosen.prototype.search_field_scale = function() {
970
+ var dd_top, div, h, style, style_block, styles, w, _i, _len;
971
+ if (this.is_multiple) {
972
+ h = 0;
973
+ w = 0;
974
+ style_block = "position:absolute; left: -1000px; top: -1000px; display:none;";
975
+ styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing'];
976
+ for (_i = 0, _len = styles.length; _i < _len; _i++) {
977
+ style = styles[_i];
978
+ style_block += style + ":" + this.search_field.css(style) + ";";
979
+ }
980
+ div = $('<div />', {
981
+ 'style': style_block
982
+ });
983
+ div.text(this.search_field.val());
984
+ $('body').append(div);
985
+ w = div.width() + 25;
986
+ div.remove();
987
+ if (w > this.f_width - 10) w = this.f_width - 10;
988
+ this.search_field.css({
989
+ 'width': w + 'px'
990
+ });
991
+ dd_top = this.container.height();
992
+ return this.dropdown.css({
993
+ "top": dd_top + "px"
994
+ });
995
+ }
996
+ };
997
+
998
+ Chosen.prototype.generate_random_id = function() {
999
+ var string;
1000
+ string = "sel" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char();
1001
+ while ($("#" + string).length > 0) {
1002
+ string += this.generate_random_char();
1003
+ }
1004
+ return string;
1005
+ };
1006
+
1007
+ return Chosen;
1008
+
1009
+ })(AbstractChosen);
1010
+
1011
+ get_side_border_padding = function(elmt) {
1012
+ var side_border_padding;
1013
+ return side_border_padding = elmt.outerWidth() - elmt.width();
1014
+ };
1015
+
1016
+ root.get_side_border_padding = get_side_border_padding;
1017
+
1018
+ }).call(this);