guara 0.0.1.rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (512) hide show
  1. data/.gitignore +23 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +33 -0
  4. data/Gemfile +82 -0
  5. data/Gemfile.lock +323 -0
  6. data/Guardfile +32 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +8 -0
  9. data/Rakefile +7 -0
  10. data/app/admin/business_activities.rb +3 -0
  11. data/app/admin/business_departments.rb +3 -0
  12. data/app/admin/business_segments.rb +13 -0
  13. data/app/admin/cities.rb +3 -0
  14. data/app/admin/company_businesses.rb +3 -0
  15. data/app/admin/dashboard.rb +39 -0
  16. data/app/admin/districts.rb +3 -0
  17. data/app/admin/states.rb +3 -0
  18. data/app/admin/task_types.rb +3 -0
  19. data/app/admin/user_groups.rb +3 -0
  20. data/app/admin/users.rb +3 -0
  21. data/app/assets/images/close.gif +0 -0
  22. data/app/assets/images/custom/logo.png +0 -0
  23. data/app/assets/images/custom/nav_logo.png +0 -0
  24. data/app/assets/images/custom/nav_logo.psd +0 -0
  25. data/app/assets/images/rails.png +0 -0
  26. data/app/assets/javascripts/active_admin.js +5 -0
  27. data/app/assets/javascripts/application.js +97 -0
  28. data/app/assets/javascripts/business_departments.js.coffee +3 -0
  29. data/app/assets/javascripts/company_businesses.js.coffee +3 -0
  30. data/app/assets/javascripts/crm.js.coffee +14 -0
  31. data/app/assets/javascripts/fcbk.js +556 -0
  32. data/app/assets/javascripts/jquery-ui-timepicker-addon.js +1326 -0
  33. data/app/assets/javascripts/jquery.mask.1.3.js +7 -0
  34. data/app/assets/javascripts/jquery.multiselect.filter.xjs +173 -0
  35. data/app/assets/javascripts/jquery.multiselect.xjs +668 -0
  36. data/app/assets/javascripts/system_task_status.js.coffee +3 -0
  37. data/app/assets/javascripts/tests/ajaxes.js.coffee +3 -0
  38. data/app/assets/stylesheets/abilities.css.scss +6 -0
  39. data/app/assets/stylesheets/active_admin.css.scss +65 -0
  40. data/app/assets/stylesheets/application.css +19 -0
  41. data/app/assets/stylesheets/business_departments.css.scss +3 -0
  42. data/app/assets/stylesheets/company_businesses.css.scss +3 -0
  43. data/app/assets/stylesheets/custom.css.scss +322 -0
  44. data/app/assets/stylesheets/customer.scss +7 -0
  45. data/app/assets/stylesheets/fcbk.css +165 -0
  46. data/app/assets/stylesheets/guara.css.scss +159 -0
  47. data/app/assets/stylesheets/jquery-ui.css +567 -0
  48. data/app/assets/stylesheets/jquery_bootstrap.css.scss +92 -0
  49. data/app/assets/stylesheets/jquery_multiselect_filter.xcss +3 -0
  50. data/app/assets/stylesheets/scaffolds.css.scss +42 -0
  51. data/app/assets/stylesheets/users.css.scss +10 -0
  52. data/app/controllers/abilities_controller.rb +37 -0
  53. data/app/controllers/application_controller.rb +12 -0
  54. data/app/controllers/business_activities_controller.rb +87 -0
  55. data/app/controllers/business_departments_controller.rb +90 -0
  56. data/app/controllers/business_segments_controller.rb +88 -0
  57. data/app/controllers/company_businesses_controller.rb +46 -0
  58. data/app/controllers/contacts_controller.rb +105 -0
  59. data/app/controllers/customers_controller.rb +117 -0
  60. data/app/controllers/microposts_controller.rb +31 -0
  61. data/app/controllers/sessions_controller.rb +32 -0
  62. data/app/controllers/static_pages_controller.rb +23 -0
  63. data/app/controllers/system_task_status_controller.rb +84 -0
  64. data/app/controllers/task_feedbacks_controller.rb +6 -0
  65. data/app/controllers/task_types_controller.rb +85 -0
  66. data/app/controllers/tasks_controller.rb +107 -0
  67. data/app/controllers/tests/ajaxes_controller.rb +115 -0
  68. data/app/controllers/tests/lab_ajax_controller.rb +27 -0
  69. data/app/controllers/users_controller.rb +62 -0
  70. data/app/helpers/ability_helper.rb +15 -0
  71. data/app/helpers/application_helper.rb +32 -0
  72. data/app/helpers/business_activities_helper.rb +2 -0
  73. data/app/helpers/business_departments_helper.rb +2 -0
  74. data/app/helpers/business_segments_helper.rb +2 -0
  75. data/app/helpers/company_businesses_helper.rb +2 -0
  76. data/app/helpers/contacts_helper.rb +2 -0
  77. data/app/helpers/customers_helper.rb +23 -0
  78. data/app/helpers/email_helper.rb +8 -0
  79. data/app/helpers/form_ajax_helper.rb +8 -0
  80. data/app/helpers/guara_views_helper.rb +38 -0
  81. data/app/helpers/locale_helper.rb +24 -0
  82. data/app/helpers/menu_helper.rb +55 -0
  83. data/app/helpers/sessions_helper.rb +56 -0
  84. data/app/helpers/tasks_helper.rb +20 -0
  85. data/app/helpers/tests/ajaxes_helper.rb +2 -0
  86. data/app/helpers/user_abilities_helper.rb +12 -0
  87. data/app/helpers/users_helper.rb +29 -0
  88. data/app/mailers/.gitkeep +0 -0
  89. data/app/models/.gitkeep +0 -0
  90. data/app/models/ability.rb +52 -0
  91. data/app/models/address.rb +7 -0
  92. data/app/models/business_activity.rb +5 -0
  93. data/app/models/business_department.rb +3 -0
  94. data/app/models/business_segment.rb +5 -0
  95. data/app/models/city.rb +7 -0
  96. data/app/models/company_business.rb +6 -0
  97. data/app/models/contact.rb +69 -0
  98. data/app/models/customer.rb +117 -0
  99. data/app/models/customer_activity.rb +9 -0
  100. data/app/models/customer_financial.rb +10 -0
  101. data/app/models/customer_has_customers.rb +7 -0
  102. data/app/models/customer_pf.rb +13 -0
  103. data/app/models/customer_pj.rb +71 -0
  104. data/app/models/customer_pj_has_customers_pj.rb +7 -0
  105. data/app/models/customer_product.rb +3 -0
  106. data/app/models/customer_segment.rb +9 -0
  107. data/app/models/district.rb +6 -0
  108. data/app/models/email.rb +7 -0
  109. data/app/models/micropost.rb +10 -0
  110. data/app/models/relationship.rb +9 -0
  111. data/app/models/search.rb +17 -0
  112. data/app/models/state.rb +3 -0
  113. data/app/models/system_ability.rb +16 -0
  114. data/app/models/system_module.rb +16 -0
  115. data/app/models/system_task_resolution.rb +26 -0
  116. data/app/models/system_task_status.rb +19 -0
  117. data/app/models/task.rb +76 -0
  118. data/app/models/task_feedback.rb +11 -0
  119. data/app/models/task_type.rb +12 -0
  120. data/app/models/tests.rb +5 -0
  121. data/app/models/tests/ajax.rb +3 -0
  122. data/app/models/user.rb +126 -0
  123. data/app/models/user_ability.rb +23 -0
  124. data/app/models/user_group.rb +9 -0
  125. data/app/models/user_type.rb +9 -0
  126. data/app/models/users_has_groups.rb +9 -0
  127. data/app/validators/customer_cnpj_validator.rb +14 -0
  128. data/app/validators/email_validator.rb +21 -0
  129. data/app/views/abilities/index.html.erb +25 -0
  130. data/app/views/active_extend/_one_to_many_inputs.html.erb +7 -0
  131. data/app/views/active_extend/_one_to_many_inputs_fields.html.erb +10 -0
  132. data/app/views/active_extend/_one_to_many_inputs_with_glyph.html.erb +21 -0
  133. data/app/views/business_activities/_business_activity.html.erb +0 -0
  134. data/app/views/business_activities/_form.html.erb +25 -0
  135. data/app/views/business_activities/edit.html.erb +6 -0
  136. data/app/views/business_activities/index.html.erb +33 -0
  137. data/app/views/business_activities/new.html.erb +5 -0
  138. data/app/views/business_activities/show.html.erb +15 -0
  139. data/app/views/business_departments/_form.html.erb +10 -0
  140. data/app/views/business_departments/edit.html.erb +6 -0
  141. data/app/views/business_departments/index.html.erb +33 -0
  142. data/app/views/business_departments/new.html.erb +5 -0
  143. data/app/views/business_departments/show.html.erb +15 -0
  144. data/app/views/business_segments/_business_segment.html.erb +8 -0
  145. data/app/views/business_segments/_form.html.erb +25 -0
  146. data/app/views/business_segments/edit.html.erb +6 -0
  147. data/app/views/business_segments/index.html.erb +33 -0
  148. data/app/views/business_segments/new.html.erb +5 -0
  149. data/app/views/business_segments/show.html.erb +15 -0
  150. data/app/views/company_businesses/_form.html.erb +10 -0
  151. data/app/views/company_businesses/edit.html.erb +6 -0
  152. data/app/views/company_businesses/index.html.erb +25 -0
  153. data/app/views/company_businesses/new.html.erb +5 -0
  154. data/app/views/company_businesses/show.html.erb +15 -0
  155. data/app/views/contacts/_form.html.erb +53 -0
  156. data/app/views/contacts/_header.html.erb +3 -0
  157. data/app/views/contacts/_list.html.erb +46 -0
  158. data/app/views/contacts/_side_panel.html.erb +61 -0
  159. data/app/views/contacts/edit.html.erb +6 -0
  160. data/app/views/contacts/index.html.erb +72 -0
  161. data/app/views/contacts/new.html.erb +5 -0
  162. data/app/views/contacts/show.html.erb +52 -0
  163. data/app/views/customers/_businesses_done.html.erb +18 -0
  164. data/app/views/customers/_customer_segment.html.erb +9 -0
  165. data/app/views/customers/_form.html.erb +177 -0
  166. data/app/views/customers/_form_search.html.erb +119 -0
  167. data/app/views/customers/_modules.html.erb +6 -0
  168. data/app/views/customers/_navbar.html.erb +23 -0
  169. data/app/views/customers/_segment.html.erb +10 -0
  170. data/app/views/customers/edit.html.erb +8 -0
  171. data/app/views/customers/index.html.erb +46 -0
  172. data/app/views/customers/new.pj.html.erb +4 -0
  173. data/app/views/customers/show.pj.html.erb +200 -0
  174. data/app/views/devise/confirmations/new.html.erb +12 -0
  175. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  176. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  177. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  178. data/app/views/devise/passwords/edit.html.erb +16 -0
  179. data/app/views/devise/passwords/new.html.erb +12 -0
  180. data/app/views/devise/registrations/edit.html.erb +25 -0
  181. data/app/views/devise/registrations/new.html.erb +18 -0
  182. data/app/views/devise/sessions/new.html.erb +24 -0
  183. data/app/views/devise/shared/_links.erb +25 -0
  184. data/app/views/devise/unlocks/new.html.erb +12 -0
  185. data/app/views/emails/_email_fields.html.erb +1 -0
  186. data/app/views/layouts/_active_admin_footer.html.erb +4 -0
  187. data/app/views/layouts/_active_admin_header.html.erb +5 -0
  188. data/app/views/layouts/_footer.html.erb +12 -0
  189. data/app/views/layouts/_header.html.erb +51 -0
  190. data/app/views/layouts/_shim.html.erb +3 -0
  191. data/app/views/layouts/active_admin.html.arb +1 -0
  192. data/app/views/layouts/application.html.erb +24 -0
  193. data/app/views/microposts/_micropost.html.erb +11 -0
  194. data/app/views/sessions/new.html.erb +18 -0
  195. data/app/views/shared/_calendar.html.erb +17 -0
  196. data/app/views/shared/_error_messages.html.erb +13 -0
  197. data/app/views/shared/_feed.html.erb +10 -0
  198. data/app/views/shared/_feed_item.html.erb +15 -0
  199. data/app/views/shared/_micropost_form.html.erb +7 -0
  200. data/app/views/shared/_multi_selection.html.erb +16 -0
  201. data/app/views/shared/_multi_selection.html_checkbox.erb +11 -0
  202. data/app/views/shared/_multi_selection_autocomple.html.erb +5 -0
  203. data/app/views/shared/_notifies.html.erb +17 -0
  204. data/app/views/shared/_user_info.html.erb +14 -0
  205. data/app/views/static_pages/about.html.erb +5 -0
  206. data/app/views/static_pages/contact.html.erb +5 -0
  207. data/app/views/static_pages/help.html.erb +5 -0
  208. data/app/views/static_pages/home.html.erb +37 -0
  209. data/app/views/static_pages/news.html.erb +2 -0
  210. data/app/views/system_task_status/_form.html.erb +9 -0
  211. data/app/views/system_task_status/edit.html.erb +6 -0
  212. data/app/views/system_task_status/index.html.erb +23 -0
  213. data/app/views/system_task_status/new.html.erb +5 -0
  214. data/app/views/system_task_status/show.html.erb +10 -0
  215. data/app/views/task_feedbacks/_list.html.erb +51 -0
  216. data/app/views/task_feedbacks/_side_form.html.erb +56 -0
  217. data/app/views/task_feedbacks/_side_panel.html.erb +64 -0
  218. data/app/views/task_types/_form.html.erb +10 -0
  219. data/app/views/task_types/edit.html.erb +6 -0
  220. data/app/views/task_types/index.html.erb +23 -0
  221. data/app/views/task_types/new.html.erb +5 -0
  222. data/app/views/task_types/show.html.erb +10 -0
  223. data/app/views/tasks/_form.html.erb +52 -0
  224. data/app/views/tasks/_header.html.erb +3 -0
  225. data/app/views/tasks/_list.html.erb +50 -0
  226. data/app/views/tasks/_side_panel.html.erb +64 -0
  227. data/app/views/tasks/create.js.erb +1 -0
  228. data/app/views/tasks/edit.html.erb +6 -0
  229. data/app/views/tasks/index.html.erb +61 -0
  230. data/app/views/tasks/new.html.erb +5 -0
  231. data/app/views/tasks/show.html.erb +46 -0
  232. data/app/views/tests/ajaxes/_form.html.erb +10 -0
  233. data/app/views/tests/ajaxes/_list.html.erb +6 -0
  234. data/app/views/tests/ajaxes/add_and_update.html.erb +22 -0
  235. data/app/views/tests/ajaxes/all.js.erb +2 -0
  236. data/app/views/tests/ajaxes/edit.html.erb +6 -0
  237. data/app/views/tests/ajaxes/index.html.erb +25 -0
  238. data/app/views/tests/ajaxes/new.html.erb +5 -0
  239. data/app/views/tests/ajaxes/show.html.erb +15 -0
  240. data/app/views/tests/js.js +51 -0
  241. data/app/views/tests/lab_ajax/multiselection.html.erb +84 -0
  242. data/app/views/users/_user.html.erb +8 -0
  243. data/app/views/users/edit.html.erb +27 -0
  244. data/app/views/users/index.html.erb +9 -0
  245. data/app/views/users/new.html.erb +24 -0
  246. data/app/views/users/show.html.erb +26 -0
  247. data/bundle +0 -0
  248. data/config.ru +4 -0
  249. data/config/application.rb +73 -0
  250. data/config/boot.rb +6 -0
  251. data/config/database.yml +38 -0
  252. data/config/environment.rb +31 -0
  253. data/config/environments/development.rb +42 -0
  254. data/config/environments/production.rb +68 -0
  255. data/config/environments/test.rb +39 -0
  256. data/config/guara/menus.rb +34 -0
  257. data/config/initializers/active_admin.rb +210 -0
  258. data/config/initializers/backtrace_silencers.rb +7 -0
  259. data/config/initializers/cmgb_rules.rb +2 -0
  260. data/config/initializers/devise.rb +216 -0
  261. data/config/initializers/formtastic.rb +77 -0
  262. data/config/initializers/inflections.rb +19 -0
  263. data/config/initializers/json_paches_utf8.rb +13 -0
  264. data/config/initializers/kaminari.rb +21 -0
  265. data/config/initializers/locale.rb +7 -0
  266. data/config/initializers/meta_search.rb +10 -0
  267. data/config/initializers/mime_types.rb +5 -0
  268. data/config/initializers/secret_token.rb +7 -0
  269. data/config/initializers/session_store.rb +8 -0
  270. data/config/initializers/string.rb +9 -0
  271. data/config/initializers/wrap_parameters.rb +14 -0
  272. data/config/locales/devise.en.yml +57 -0
  273. data/config/locales/devise.pt-BR.yml +62 -0
  274. data/config/locales/pt-BR.yml +404 -0
  275. data/config/routes.rb +129 -0
  276. data/db/migrate/20120610142404_create_users.rb +10 -0
  277. data/db/migrate/20120610183820_add_index_to_users_email.rb +5 -0
  278. data/db/migrate/20120610185217_add_password_digest_to_users.rb +5 -0
  279. data/db/migrate/20120612000411_add_remember_token_to_users.rb +6 -0
  280. data/db/migrate/20120616162515_add_admin_to_users.rb +5 -0
  281. data/db/migrate/20120616215835_create_microposts.rb +11 -0
  282. data/db/migrate/20120617224530_create_relationships.rb +14 -0
  283. data/db/migrate/20120621095918_create_customers.rb +36 -0
  284. data/db/migrate/20120621100528_create_customer_pfs.rb +14 -0
  285. data/db/migrate/20120621100534_create_customer_pjs.rb +13 -0
  286. data/db/migrate/20120621100557_create_emails.rb +13 -0
  287. data/db/migrate/20120621100618_create_tasks.rb +26 -0
  288. data/db/migrate/20120621100639_create_customer_products.rb +14 -0
  289. data/db/migrate/20120621100705_create_districts.rb +11 -0
  290. data/db/migrate/20120621100720_create_cities.rb +11 -0
  291. data/db/migrate/20120624192444_create_business_segments.rb +10 -0
  292. data/db/migrate/20120624224245_create_business_activities.rb +13 -0
  293. data/db/migrate/20120628092744_create_customer_activities.rb +9 -0
  294. data/db/migrate/20120628092754_create_customer_segments.rb +9 -0
  295. data/db/migrate/20120703102859_create_states.rb +10 -0
  296. data/db/migrate/20120705121011_create_contacts.rb +18 -0
  297. data/db/migrate/20120711233943_add_devise_to_users.rb +56 -0
  298. data/db/migrate/20120723102847_create_user_abilities.rb +10 -0
  299. data/db/migrate/20120723104500_create_system_modules.rb +9 -0
  300. data/db/migrate/20120723104639_create_system_abilities.rb +9 -0
  301. data/db/migrate/20120728181903_create_user_groups.rb +10 -0
  302. data/db/migrate/20120729112600_create_users_has_groups.rb +14 -0
  303. data/db/migrate/20120729121922_add_groups_to_users.rb +6 -0
  304. data/db/migrate/20120910002835_create_system_task_status.rb +7 -0
  305. data/db/migrate/20120910010153_create_system_task_resolutions.rb +7 -0
  306. data/db/migrate/20120911021535_create_task_types.rb +10 -0
  307. data/db/migrate/20120911070836_create_task_feedbacks.rb +14 -0
  308. data/db/migrate/20120924022719_create_tests_ajaxes.rb +10 -0
  309. data/db/migrate/20121007131035_create_business_departments.rb +10 -0
  310. data/db/migrate/20121013120849_add_notes_and_other_contacts_to_customer.rb +5 -0
  311. data/db/migrate/20121014201255_create_company_businesses.rb +10 -0
  312. data/db/migrate/20121014202449_add_company_business_to_task_type.rb +6 -0
  313. data/db/migrate/20121014212430_add_primary_company_business_to_user.rb +5 -0
  314. data/db/migrate/20121015101844_add_parent_id_to_system_task_resolution.rb +5 -0
  315. data/db/migrate/20121026231241_create_customer_has_customers.rb +10 -0
  316. data/db/migrate/20121026232755_create_customer_pj_has_customers_pjs.rb +10 -0
  317. data/db/migrate/20121029094047_create_admin_notes.rb +17 -0
  318. data/db/migrate/20121029094048_move_admin_notes_to_comments.rb +25 -0
  319. data/db/migrate/20121103183646_add_enabled_to_cities.rb +5 -0
  320. data/db/migrate/20121104135014_create_customer_financials.rb +17 -0
  321. data/db/migrate/20121104141751_create_addresses.rb +19 -0
  322. data/db/migrate/20121205150619_add_type_id_to_users.rb +5 -0
  323. data/db/schema.rb~ +378 -0
  324. data/db/seeds.rb +99 -0
  325. data/gemfiles/Gemfile.rails.3.2.x +82 -0
  326. data/guara.gemspec +31 -0
  327. data/lib/active_extend/README.md +19 -0
  328. data/lib/active_extend/active_disablable.rb +59 -0
  329. data/lib/active_extend/string_helper.rb +9 -0
  330. data/lib/active_migration.rb +4 -0
  331. data/lib/active_migration/converters/rtf_to_html.rb +123 -0
  332. data/lib/active_migration/dictionary.rb +19 -0
  333. data/lib/active_migration/migration.rb +211 -0
  334. data/lib/active_migration/schemas.rb +143 -0
  335. data/lib/active_migration/spelling_fix.rb +20 -0
  336. data/lib/active_migration/transformer/grouped_field_fixed_spelling.rb +110 -0
  337. data/lib/assets/.gitkeep +0 -0
  338. data/lib/cmgb_rules/app/models/task.rb +19 -0
  339. data/lib/guara/version.rb +3 -0
  340. data/lib/spec/asserts/sheet1.xls +0 -0
  341. data/lib/spec/lib/active_migration_schemas_spec.rb +40 -0
  342. data/lib/spec/lib/active_migration_spec.rb +78 -0
  343. data/lib/spec/spec_helper.rb +121 -0
  344. data/lib/spec/support/active_migration_helper.rb +109 -0
  345. data/lib/spec/support/utilities.rb +7 -0
  346. data/lib/tasks/.gitkeep +0 -0
  347. data/lib/tasks/add_privilegies.rake +6 -0
  348. data/lib/tasks/external_migration.rake +22 -0
  349. data/lib/tasks/sample_data.rake +77 -0
  350. data/lib/tasks/smaple_data_test.rake +13 -0
  351. data/lib/templates/erb/scaffold/_form.html.erb +11 -0
  352. data/public/404.html +26 -0
  353. data/public/422.html +26 -0
  354. data/public/500.html +25 -0
  355. data/public/data.txt +1 -0
  356. data/public/favicon.ico +0 -0
  357. data/public/javascripts/autocomplete-rails.js +16 -0
  358. data/public/robots.txt +5 -0
  359. data/script/create_db +5 -0
  360. data/script/rails +6 -0
  361. data/script/recreate_db +5 -0
  362. data/script/recreate_db.bat +9 -0
  363. data/script/recreate_db_test +5 -0
  364. data/script/recreate_development_db +10 -0
  365. data/spec/controllers/business_activities_controller_spec.disabled +167 -0
  366. data/spec/controllers/business_departments_controller_spec.disabled +164 -0
  367. data/spec/controllers/business_segments_controller_spec.disabled +165 -0
  368. data/spec/controllers/company_businesses_controller_spec.disabled +164 -0
  369. data/spec/controllers/system_task_status_controller_spec.disabled +164 -0
  370. data/spec/controllers/system_task_status_spec.disabled +11 -0
  371. data/spec/controllers/task_types_controller_spec.disabled +164 -0
  372. data/spec/controllers/tasks_controller_spec.disabled +23 -0
  373. data/spec/controllers/tests/ajaxes_controller_spec.disabled +164 -0
  374. data/spec/factories.rb +101 -0
  375. data/spec/factories/addresses.rb +13 -0
  376. data/spec/factories/business_departments.rb +8 -0
  377. data/spec/factories/company_businesses.rb +8 -0
  378. data/spec/factories/customer_financials.rb +11 -0
  379. data/spec/factories/customer_has_customers.rb +8 -0
  380. data/spec/factories/customer_pj_has_customers_pjs.rb +8 -0
  381. data/spec/factories/system_task_resolutions.rb +7 -0
  382. data/spec/factories/system_task_status.rb +7 -0
  383. data/spec/factories/task.rb +17 -0
  384. data/spec/factories/task_feedbacks.rb +19 -0
  385. data/spec/factories/task_types.rb +8 -0
  386. data/spec/factories/tests_ajaxes.rb +8 -0
  387. data/spec/helpers/business_activities_helper_spec.rb +15 -0
  388. data/spec/helpers/business_departments_helper_spec.rb +15 -0
  389. data/spec/helpers/business_segments_helper_spec.rb +15 -0
  390. data/spec/helpers/company_businesses_helper_spec.rb +15 -0
  391. data/spec/helpers/customers/contacts_helper_spec.rb +15 -0
  392. data/spec/helpers/menu_helper_spec.rb +25 -0
  393. data/spec/helpers/tests/ajaxes_helper_spec.rb +15 -0
  394. data/spec/helpers/users_helpers_spec.rb +32 -0
  395. data/spec/models/address_spec.rb +5 -0
  396. data/spec/models/business_activity_spec.rb +5 -0
  397. data/spec/models/business_department_spec.rb +5 -0
  398. data/spec/models/business_segment_spec.rb +5 -0
  399. data/spec/models/city_spec.rb +5 -0
  400. data/spec/models/company_business_spec.rb +19 -0
  401. data/spec/models/contact_spec.rb +60 -0
  402. data/spec/models/customer_activity_spec.rb +5 -0
  403. data/spec/models/customer_financial_spec.rb +48 -0
  404. data/spec/models/customer_has_customers_spec.rb +18 -0
  405. data/spec/models/customer_pf_spec.rb +24 -0
  406. data/spec/models/customer_pj_has_customers_pj_spec.rb +34 -0
  407. data/spec/models/customer_pj_spec.rb +72 -0
  408. data/spec/models/customer_product_spec.rb +5 -0
  409. data/spec/models/customer_segment_spec.rb +5 -0
  410. data/spec/models/customer_spec.rb +135 -0
  411. data/spec/models/district_spec.rb +5 -0
  412. data/spec/models/emails_spec.rb +24 -0
  413. data/spec/models/micropost_spec.rb +49 -0
  414. data/spec/models/relationship_spec.rb +38 -0
  415. data/spec/models/state_spec.rb +5 -0
  416. data/spec/models/system_ability_spec.rb +5 -0
  417. data/spec/models/system_module_spec.rb +5 -0
  418. data/spec/models/system_task_resolution_spec.rb +17 -0
  419. data/spec/models/system_task_status_spec.rb +17 -0
  420. data/spec/models/task_feedback_spec.rb +46 -0
  421. data/spec/models/task_spec.rb +176 -0
  422. data/spec/models/task_type_spec.rb +27 -0
  423. data/spec/models/tests/ajax_spec.rb +5 -0
  424. data/spec/models/user_ability_spec.rb +35 -0
  425. data/spec/models/user_group_spec.rb +26 -0
  426. data/spec/models/user_spec.rb +274 -0
  427. data/spec/models/users_has_groups_spec.rb +29 -0
  428. data/spec/requests/authentication_pages_spec.rb +157 -0
  429. data/spec/requests/business_activities_spec.rb +7 -0
  430. data/spec/requests/business_departments_spec.rb +7 -0
  431. data/spec/requests/business_segments_spec.rb +7 -0
  432. data/spec/requests/company_businesses_spec.rb +11 -0
  433. data/spec/requests/customer_contacts_pages_spec.rb +96 -0
  434. data/spec/requests/customer_pages_spec.rb +60 -0
  435. data/spec/requests/micropost_pages_spec.rb +58 -0
  436. data/spec/requests/static_pages_spec.rb +57 -0
  437. data/spec/requests/task_pages_spec.rb +124 -0
  438. data/spec/requests/tests/tests_ajaxes_spec.rb +11 -0
  439. data/spec/requests/user_abilities_pages_spec.rb +73 -0
  440. data/spec/requests/user_pages_spec.rb +116 -0
  441. data/spec/routing/business_activities_routing_spec.rb +35 -0
  442. data/spec/routing/business_departments_routing_spec.rb +35 -0
  443. data/spec/routing/business_segments_routing_spec.rb +35 -0
  444. data/spec/routing/company_businesses_routing_spec.rb +35 -0
  445. data/spec/routing/system_task_status_routing_spec.rb +35 -0
  446. data/spec/routing/task_types_routing_spec.rb +35 -0
  447. data/spec/routing/tests/ajaxes_routing_spec.rb +35 -0
  448. data/spec/spec_helper.rb +123 -0
  449. data/spec/support/custom_matchers.rb +9 -0
  450. data/spec/support/utilities.rb +120 -0
  451. data/spec/views/business_departments/edit.html.erb_spec.rb +20 -0
  452. data/spec/views/business_departments/index.html.erb_spec.disabled +23 -0
  453. data/spec/views/business_departments/new.html.erb_spec.rb +20 -0
  454. data/spec/views/business_departments/show.html.erb_spec.rb +17 -0
  455. data/spec/views/company_businesses/edit.html.erb_spec.rb +20 -0
  456. data/spec/views/company_businesses/index.html.erb_spec.rb +23 -0
  457. data/spec/views/company_businesses/new.html.erb_spec.rb +20 -0
  458. data/spec/views/company_businesses/show.html.erb_spec.rb +17 -0
  459. data/spec/views/task_types/edit.html.erb_spec.rb +18 -0
  460. data/spec/views/task_types/index.html.erb_spec.rb +20 -0
  461. data/spec/views/task_types/new.html.erb_spec.rb +18 -0
  462. data/spec/views/task_types/show.html.erb_spec.rb +15 -0
  463. data/test/fixtures/.gitkeep +0 -0
  464. data/test/functional/.gitkeep +0 -0
  465. data/test/integration/.gitkeep +0 -0
  466. data/test/performance/browsing_test.rb +12 -0
  467. data/test/test_helper.rb +13 -0
  468. data/test/unit/.gitkeep +0 -0
  469. data/vendor/assets/javascripts/.gitkeep +0 -0
  470. data/vendor/assets/stylesheets/.gitkeep +0 -0
  471. data/vendor/assets/stylesheets/active_admin/_base.css.scss +45 -0
  472. data/vendor/assets/stylesheets/active_admin/_forms.css.scss +270 -0
  473. data/vendor/assets/stylesheets/active_admin/_header.css.scss +137 -0
  474. data/vendor/assets/stylesheets/active_admin/_mixins.css.scss +1 -0
  475. data/vendor/assets/stylesheets/active_admin/_typography.css.scss +100 -0
  476. data/vendor/assets/stylesheets/active_admin/components/_batch_actions.css.scss +11 -0
  477. data/vendor/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
  478. data/vendor/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
  479. data/vendor/assets/stylesheets/active_admin/components/_buttons.scss +11 -0
  480. data/vendor/assets/stylesheets/active_admin/components/_columns.scss +3 -0
  481. data/vendor/assets/stylesheets/active_admin/components/_comments.css.scss +40 -0
  482. data/vendor/assets/stylesheets/active_admin/components/_date_picker.css.scss +123 -0
  483. data/vendor/assets/stylesheets/active_admin/components/_dropdown_menu.scss +151 -0
  484. data/vendor/assets/stylesheets/active_admin/components/_flash_messages.css.scss +39 -0
  485. data/vendor/assets/stylesheets/active_admin/components/_grid.scss +9 -0
  486. data/vendor/assets/stylesheets/active_admin/components/_links.scss +5 -0
  487. data/vendor/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
  488. data/vendor/assets/stylesheets/active_admin/components/_panels.scss +6 -0
  489. data/vendor/assets/stylesheets/active_admin/components/_popovers.css.scss +123 -0
  490. data/vendor/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
  491. data/vendor/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
  492. data/vendor/assets/stylesheets/active_admin/components/_table_tools.css.scss +94 -0
  493. data/vendor/assets/stylesheets/active_admin/components/_tables.css.scss +108 -0
  494. data/vendor/assets/stylesheets/active_admin/mixins/_all.css.scss +11 -0
  495. data/vendor/assets/stylesheets/active_admin/mixins/_buttons.css.scss +66 -0
  496. data/vendor/assets/stylesheets/active_admin/mixins/_gradients.css.scss +37 -0
  497. data/vendor/assets/stylesheets/active_admin/mixins/_icons.css.scss +24 -0
  498. data/vendor/assets/stylesheets/active_admin/mixins/_reset.css.scss +165 -0
  499. data/vendor/assets/stylesheets/active_admin/mixins/_rounded.css.scss +43 -0
  500. data/vendor/assets/stylesheets/active_admin/mixins/_sections.css.scss +36 -0
  501. data/vendor/assets/stylesheets/active_admin/mixins/_shadows.css.scss +22 -0
  502. data/vendor/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
  503. data/vendor/assets/stylesheets/active_admin/mixins/_utilities.scss +26 -0
  504. data/vendor/assets/stylesheets/active_admin/mixins/_variables.css.scss +24 -0
  505. data/vendor/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
  506. data/vendor/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
  507. data/vendor/assets/stylesheets/active_admin/print.css.scss +290 -0
  508. data/vendor/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
  509. data/vendor/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
  510. data/vendor/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
  511. data/vendor/plugins/.gitkeep +0 -0
  512. metadata +731 -0
data/Guardfile ADDED
@@ -0,0 +1,32 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
5
+ watch('config/application.rb')
6
+ watch('config/environment.rb')
7
+ watch(%r{^config/environments/.+\.rb$})
8
+ watch(%r{^config/initializers/.+\.rb$})
9
+ watch('Gemfile')
10
+ watch('Gemfile.lock')
11
+ watch('spec/spec_helper.rb')
12
+ watch('test/test_helper.rb')
13
+ end
14
+
15
+ guard 'rspec', :version => 2, :all_after_pass => false, :cli => '--drb' do
16
+ watch(%r{^spec/.+_spec\.rb$})
17
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
18
+ watch('spec/spec_helper.rb') { "spec" }
19
+
20
+ # Rails example
21
+ watch(%r{^spec/.+_spec\.rb$})
22
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
23
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
24
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
25
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
26
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
27
+ watch('spec/spec_helper.rb') { "spec" }
28
+ watch('config/routes.rb') { "spec/routing" }
29
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
30
+ # Capybara request specs
31
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
32
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2009-2012 Plataformatec. http://plataformatec.com.br
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Guara-CRM
2
+ =========
3
+
4
+ [![Build Status](https://secure.travis-ci.org/woese/guara-crm.png)](http://travis-ci.org/woese/guara-crm)
5
+ [![Dependency Status](https://gemnasium.com/woese/guara-crm.png)](https://gemnasium.com/woese/guara-crm)
6
+ [![Code Quality](https://codeclimate.com/badge.png)](https://codeclimate.com/github/woese/guara-crm)
7
+
8
+ ## Guara CRM
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ GUARACRM::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register BusinessActivity, :namespace => :maintence do
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register BusinessDepartment, :namespace => :maintence do
2
+
3
+ end
@@ -0,0 +1,13 @@
1
+ ActiveAdmin.register BusinessSegment, :namespace => :maintence do
2
+
3
+ filter :enabled, :as => :check_boxes
4
+
5
+ index do
6
+ column :name
7
+ column :enabled
8
+
9
+
10
+ default_actions
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register City, :namespace => :maintence do
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register CompanyBusiness, :namespace => "maintence" do
2
+
3
+ end
@@ -0,0 +1,39 @@
1
+ ActiveAdmin.register_page "Dashboard" do
2
+
3
+ controller.skip_authorization_check
4
+
5
+ def authenticate_admin!
6
+ redirect_to new_user_session_path unless current_user.is_admin?
7
+ end
8
+
9
+ menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
10
+
11
+ content :title => proc{ I18n.t("active_admin.dashboard") } do
12
+ div :class => "blank_slate_container", :id => "dashboard_default_message" do
13
+ span :class => "blank_slate" do
14
+ span "Welcome to Active Admin. This is the default dashboard page."
15
+ small "To add dashboard sections, checkout 'app/admin/dashboards.rb'"
16
+ end
17
+ end
18
+
19
+ # Here is an example of a simple dashboard with columns and panels.
20
+ #
21
+ # columns do
22
+ # column do
23
+ # panel "Recent Posts" do
24
+ # ul do
25
+ # Post.recent(5).map do |post|
26
+ # li link_to(post.title, admin_post_path(post))
27
+ # end
28
+ # end
29
+ # end
30
+ # end
31
+
32
+ # column do
33
+ # panel "Info" do
34
+ # para "Welcome to ActiveAdmin."
35
+ # end
36
+ # end
37
+ # end
38
+ end # content
39
+ end
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register District, :namespace => :maintence do
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register State, :namespace => :maintence do
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register TaskType, :namespace => :maintence do
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register UserGroup do
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ ActiveAdmin.register User do
2
+
3
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ //= require active_admin/base
2
+ //= require jquery
3
+ //= require jquery-ui
4
+ //= require jquery_ujs
5
+ //= require bootstrap
@@ -0,0 +1,97 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery-ui
15
+ //= require jquery_ujs
16
+ //= require bootstrap
17
+ //= #require bootstrap-datepicker
18
+ //= #require bootstrap-datepicker/locales/bootstrap-datepicker.pt
19
+ //= require jquery-ui-timepicker-addon
20
+ //= require_tree .
21
+
22
+ $(document).on("focus", "[data-behaviour~='datepicker']", function(e){
23
+ $(this).datepicker({"format": "dd/mm/yyyy hh:mm", "weekStart": 1, "autoclose": true});
24
+ });
25
+
26
+ $(document).on("focus", "[data-behaviour~='datetimepicker']", function(e){
27
+ $(this).datetimepicker({ dateFormat: "dd/mm/yy", timeFormat: "hh:mm", "weekStart": 1, "autoclose": true,
28
+ hourGrid: 4, minuteGrid: 10});
29
+ });
30
+
31
+ $(document).ready(function(){
32
+
33
+ $('.remote_form')
34
+ .bind("ajax:beforeSend", function(evt, xhr, settings){
35
+ var $submitButton = $(this).find('input[name="commit"]');
36
+
37
+ // Update the text of the submit button to let the user know stuff is happening.
38
+ // But first, store the original text of the submit button, so it can be restored when the request is finished.
39
+ $submitButton.data( 'origText', $(this).text() );
40
+ $submitButton.text( "Submitting..." );
41
+
42
+ })
43
+ .bind("ajax:success", function(evt, data, status, xhr){
44
+ var $form = $(this);
45
+
46
+ // Reset fields and any validation errors, so form can be used again, but leave hidden_field values intact.
47
+ $form.find('textarea,input[type="text"],input[type="file"]').val("");
48
+ $form.find('div.validation-error').empty();
49
+
50
+ // Insert response partial into page below the form.
51
+ $('#comments').append(xhr.responseText);
52
+
53
+ })
54
+ .bind('ajax:complete', function(evt, xhr, status){
55
+ var $submitButton = $(this).find('input[name="commit"]');
56
+
57
+ // Restore the original submit button text
58
+ $submitButton.text( $(this).data('origText') );
59
+ })
60
+ .bind("ajax:error", function(evt, xhr, status, error){
61
+ var $form = $(this),
62
+ errors,
63
+ errorText;
64
+
65
+ try {
66
+ // Populate errorText with the comment errors
67
+ errors = $.parseJSON(xhr.responseText);
68
+ } catch(err) {
69
+ // If the responseText is not valid JSON (like if a 500 exception was thrown), populate errors with a generic error message.
70
+ errors = {message: "Por favor, ocorreu um erro ao tratar a resposta do servidor, tente mais tarde."};
71
+ }
72
+
73
+ // Build an unordered list from the list of errors
74
+ errorText = "<div class=\"alert alert-block alert-error\"><h4>Erros ao registrar dados:</h4> \n<ul>";
75
+
76
+ for ( error in errors ) {
77
+ errorText += "<li>" + error + ': ' + errors[error] + "</li> ";
78
+ }
79
+
80
+ errorText += "</ul></div>";
81
+
82
+ $(document).scrollTop();
83
+
84
+ // Insert error list into form
85
+ $form.find('div.validation-error').html(errorText);
86
+ });
87
+
88
+ });
89
+
90
+ function showMessage(message_content) {
91
+ $(".alert-ajax").show().html(message_content);
92
+ $(document).scrollTop();
93
+ }
94
+
95
+ $(function() {
96
+ $( "#accordion" ).accordion();
97
+ });
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,14 @@
1
+ # Place all the behaviors and hooks related to the matching controller here.
2
+ # All this logic will automatically be available in application.js.
3
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
4
+ jQuery ->
5
+ $('form').on 'click', '.remove_fields', (event) ->
6
+ $(this).prev('input[type=hidden]').val('1')
7
+ $(this).closest('fieldset').hide()
8
+ event.preventDefault()
9
+
10
+ $('form').on 'click', '.add_fields', (event) ->
11
+ time = new Date().getTime()
12
+ regexp = new RegExp($(this).data('id'), 'g')
13
+ $(this).before($(this).data('fields').replace(regexp, time))
14
+ event.preventDefault()
@@ -0,0 +1,556 @@
1
+ /** FCBKcomplete v2.8.9.3 is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> */
2
+ (function($, undefined) {
3
+ $.fn.fcbkcomplete = function(opt) {
4
+ return this.queue(function() {
5
+ function init() {
6
+ createFCBK();
7
+ addInput(0)
8
+ }
9
+ function createFCBK() {
10
+ holder = $('<ul class="holder"></ul>').width(options.width);
11
+ if (options.attachto) {
12
+ if (typeof(options.attachto) == "object") {
13
+ options.attachto.append(holder)
14
+ } else {
15
+ $(options.attachto).append(holder)
16
+ }
17
+ } else {
18
+ element.after(holder)
19
+ }
20
+ complete = $('<div class="facebook-auto">').width(options.width);
21
+ if (options.complete_text != "") {
22
+ var completeText = options.complete_text;
23
+ complete.append('<div class="default">' + completeText + '</div>');
24
+ if (options.select_all_text) {
25
+ complete.children('.default').append(
26
+ $('<a href="" class="select_all_items">' + options.select_all_text + '</a>').click(function() {
27
+ $(element).trigger('selectAll');
28
+ return false
29
+ }))
30
+ }
31
+ }
32
+ complete.hover(function() {
33
+ complete_hover = 0
34
+ },
35
+ function() {
36
+ complete_hover = 1
37
+ });
38
+ feed = $('<ul id="' + elemid + '_feed"></ul>').width(options.width);
39
+ holder.after(complete.prepend(feed));
40
+ elPrepare()
41
+ }
42
+ function elPrepare() {
43
+ name = element.attr("name");
44
+ if (options.bricket) {
45
+ if (typeof(name) != 'undefined' && name.indexOf("[]") == -1) {
46
+ name = name + "[]"
47
+ }
48
+ }
49
+ var temp_elem = $('<' + element.get(0).tagName + ' name="' + name + '" id="' + elemid + '" multiple="multiple" class="' + element.get(0).className + ' hidden">').data('cache', {});
50
+ $.each(element.children('option'),
51
+ function(i, option) {
52
+ option = $(option);
53
+ temp_elem.data('cache')[option.val()] = option.text();
54
+ if (option.hasClass("selected")) {
55
+ var id = addItem(option.text(), option.val(), true, option.hasClass("locked"));
56
+ temp_elem.append('<option value="' + option.val() + '" selected="selected" id="opt_' + id + '"class="selected">' + option.text() + '</option>')
57
+ }
58
+ });
59
+ element.after(temp_elem);
60
+ element.remove();
61
+ element = temp_elem;
62
+ $(element).bind("addItem",
63
+ function(event, data) {
64
+ addItem(data.title, data.value, 0, 0, 0)
65
+ });
66
+ $(element).bind("removeItem",
67
+ function(event, data) {
68
+ var item = holder.children('li[rel=' + data.value + ']');
69
+ if (item.length) {
70
+ removeItem(item)
71
+ }
72
+ });
73
+ $(element).bind("destroy",
74
+ function(event, data) {
75
+ holder.remove();
76
+ complete.remove();
77
+ element.show()
78
+ });
79
+ $(element).bind("selectAll",
80
+ function(event, data) {
81
+ var currVals = $(element).val() || [];
82
+ $.each($(element).data('cache'),
83
+ function(key, value) {
84
+ if ($.inArray(key, currVals) === -1) {
85
+ addItem(value, key, 0, 0, 0)
86
+ }
87
+ });
88
+ feed.parent().hide()
89
+ })
90
+ }
91
+ function addItem(title, value, preadded, locked, focusme) {
92
+ if (!maxItems()) {
93
+ return false
94
+ }
95
+ var liclass = "bit-box" + (locked ? " locked": "");
96
+ var id = randomId();
97
+ var txt = document.createTextNode(xssDisplay(title));
98
+ var aclose = $('<a class="closebutton" href="#"></a>');
99
+ var li = $('<li class="' + liclass + '" rel="' + value + '" id="pt_' + id + '"></li>').prepend(txt).append(aclose);
100
+ holder.append(li);
101
+ aclose.click(function() {
102
+ removeItem($(this).parent("li"));
103
+ return false
104
+ });
105
+ if (!preadded) {
106
+ $("#" + elemid + "_annoninput").remove();
107
+ addInput(focusme);
108
+ var _item = $('<option value="' + xssDisplay(value, 1) + '" id="opt_' + id + '" class="selected" selected="selected">' + xssDisplay(title) + '</option>');
109
+ element.append(_item);
110
+ if (options.onselect) {
111
+ funCall(options.onselect, _item)
112
+ }
113
+ element.change()
114
+ }
115
+ holder.children("li.bit-box.deleted").removeClass("deleted");
116
+ clear_feed(1);
117
+ return id
118
+ }
119
+ function removeItem(item) {
120
+ if (!item.hasClass('locked')) {
121
+ item.fadeOut("fast");
122
+ var id = item.attr('id');
123
+ if (options.onremove) {
124
+ var _item = id ? $("#o" + id + "") : element.children("option[value=" + item.attr("rel") + "]");
125
+ funCall(options.onremove, _item)
126
+ }
127
+ if (id) {
128
+ $("#o" + id + "").remove()
129
+ } else {
130
+ element.children('option[value="' + item.attr("rel") + '"]').remove()
131
+ }
132
+ item.remove();
133
+ element.change();
134
+ deleting = 0
135
+ }
136
+ }
137
+ function addInput(focusme) {
138
+ var li = $('<li class="bit-input" id="' + elemid + '_annoninput">');
139
+ var input = $('<input type="text" class="maininput" size="' + options.input_min_size + '" autocomplete="off">');
140
+ if (options.input_tabindex > 0) input.attr("tabindex", options.input_tabindex);
141
+ if (options.input_name != "") input.attr("name", options.input_name);
142
+ holder.append(li.append(input));
143
+ input.focus(function() {
144
+ isactive = true;
145
+ if (maxItems()) {
146
+ complete.fadeIn("fast")
147
+ }
148
+ });
149
+ input.blur(function() {
150
+ isactive = false;
151
+ if (complete_hover) {
152
+ complete.fadeOut("fast")
153
+ } else {
154
+ input.focus()
155
+ }
156
+ });
157
+ holder.click(function() {
158
+ if (options.input_min_size < 0 && feed.length) {
159
+ load_feed(xssPrevent(input.val(), 1))
160
+ }
161
+ input.focus();
162
+ if (feed.length && input.val().length > options.input_min_size) {
163
+ feed.show()
164
+ } else {
165
+ clear_feed(1);
166
+ complete.children(".default").show()
167
+ }
168
+ });
169
+ input.keypress(function(event) {
170
+ if (event.keyCode == _key.enter) {
171
+ return false
172
+ }
173
+ var newsize = (options.input_min_size > input.val().length) ? options.input_min_size: (input.val().length + 1);
174
+ input.attr("size", newsize).width(parseInt(input.css('font-size')) * newsize)
175
+ });
176
+ input.keyup(function(event) {
177
+ var etext = xssPrevent(input.val(), 1);
178
+ if (event.keyCode == _key.backspace && etext.length == 0) {
179
+ clear_feed(1);
180
+ if (!holder.children("li.bit-box:last").hasClass('locked')) {
181
+ if (holder.children("li.bit-box.deleted").length == 0) {
182
+ holder.children("li.bit-box:last").addClass("deleted");
183
+ return false
184
+ } else {
185
+ if (deleting) {
186
+ return
187
+ }
188
+ deleting = 1;
189
+ holder.children("li.bit-box.deleted").fadeOut("fast",
190
+ function() {
191
+ removeItem($(this));
192
+ return false
193
+ })
194
+ }
195
+ }
196
+ }
197
+ if (event.keyCode != _key.downarrow && event.keyCode != _key.uparrow && event.keyCode != _key.leftarrow && event.keyCode != _key.rightarrow && etext.length > options.input_min_size) {
198
+ load_feed(etext);
199
+ complete.children(".default").hide();
200
+ feed.show()
201
+ }
202
+ });
203
+ if (options.oncreate) {
204
+ funCall(options.oncreate, input)
205
+ }
206
+ if (focusme) {
207
+ setTimeout(function() {
208
+ input.focus();
209
+ complete.children(".default").show()
210
+ },
211
+ 1)
212
+ }
213
+ }
214
+ function addMembers(etext, data) {
215
+ feed.html('');
216
+ if (!options.cache && data != null) {
217
+ cache.clear()
218
+ }
219
+ addTextItem(etext);
220
+ if (data != null && data.length) {
221
+ $.each(data,
222
+ function(i, val) {
223
+ cache.set(xssPrevent(val.key), xssPrevent(val.value))
224
+ })
225
+ }
226
+ var maximum = options.maxshownitems < cache.length() ? options.maxshownitems: cache.length();
227
+ var content = '';
228
+ $.each(cache.search(etext),
229
+ function(i, object) {
230
+ if (maximum) {
231
+ if (options.filter_selected && element.children('option[value="' + object.key + '"]').hasClass("selected")) {} else {
232
+ content += '<li rel="' + object.key + '">' + xssDisplay(itemIllumination(object.value, etext)) + '</li>';
233
+ counter++;
234
+ maximum--
235
+ }
236
+ }
237
+ });
238
+ feed.append(content);
239
+ if (options.firstselected) {
240
+ focuson = feed.children("li:visible:first");
241
+ focuson.addClass("auto-focus")
242
+ }
243
+ if (counter > options.height) {
244
+ feed.css({
245
+ "height": (options.height * 24) + "px",
246
+ "overflow": "auto"
247
+ })
248
+ } else {
249
+ feed.css("height", "auto")
250
+ }
251
+ if (maxItems() && complete.is(':hidden')) {
252
+ complete.show()
253
+ }
254
+ }
255
+ function itemIllumination(text, etext) {
256
+ var string_regex_adder = options.filter_begin ? '': '(.*)';
257
+ var regex_result = options.filter_begin ? '<em>$1</em>$2': '$1<em>$2</em>$3';
258
+ var string_regex = string_regex_adder + (options.filter_case ? "(" + etext + ")(.*)": "(" + etext.toLowerCase() + ")(.*)");
259
+ try {
260
+ var regex = new RegExp(string_regex, ((options.filter_case) ? "g": "gi"));
261
+ var text = text.replace(regex, regex_result)
262
+ } catch(ex) {};
263
+ return text
264
+ }
265
+ function bindFeedEvent() {
266
+ feed.children("li").mouseover(function() {
267
+ feed.children("li").removeClass("auto-focus");
268
+ focuson = $(this);
269
+ focuson.addClass("auto-focus")
270
+ });
271
+ feed.children("li").mouseout(function() {
272
+ $(this).removeClass("auto-focus");
273
+ focuson = null
274
+ })
275
+ }
276
+ function removeFeedEvent() {
277
+ feed.unbind("mouseover").unbind("mouseout").mousemove(function() {
278
+ bindFeedEvent();
279
+ feed.unbind("mousemove")
280
+ })
281
+ }
282
+ function bindEvents() {
283
+ var maininput = $("#" + elemid + "_annoninput").children(".maininput");
284
+ bindFeedEvent();
285
+ feed.children("li").unbind("mousedown").mousedown(function() {
286
+ var option = $(this);
287
+ addItem(option.text(), option.attr("rel"), 0, 0, 1);
288
+ clear_feed(1);
289
+ complete.hide()
290
+ });
291
+ maininput.unbind("keydown");
292
+ maininput.keydown(function(event) {
293
+ if (event.keyCode != _key.backspace) {
294
+ holder.children("li.bit-box.deleted").removeClass("deleted")
295
+ }
296
+ if ((event.keyCode == _key.enter || event.keyCode == _key.tab || event.keyCode == _key.comma) && checkFocusOn()) {
297
+ var option = focuson;
298
+ addItem(option.text(), option.attr("rel"), 0, 0, 1);
299
+ return _preventDefault(event)
300
+ }
301
+ if ((event.keyCode == _key.enter || event.keyCode == _key.tab || event.keyCode == _key.comma) && !checkFocusOn()) {
302
+ if (options.newel) {
303
+ var value = xssPrevent($(this).val());
304
+ addItem(value, value, 0, 0, 1);
305
+ return _preventDefault(event)
306
+ }
307
+ if ((options.addontab || options.addoncomma) && options.newel) {
308
+ focuson = feed.children("li:visible:first");
309
+ var option = focuson;
310
+ addItem(option.text(), option.attr("rel"), 0, 0, 1);
311
+ return _preventDefault(event)
312
+ }
313
+ }
314
+ if (event.keyCode == _key.downarrow) {
315
+ nextItem('first')
316
+ }
317
+ if (event.keyCode == _key.uparrow) {
318
+ nextItem('last')
319
+ }
320
+ })
321
+ }
322
+ function nextItem(position) {
323
+ removeFeedEvent();
324
+ if (focuson == null || focuson.length == 0) {
325
+ focuson = feed.children("li:visible:" + position);
326
+ feed.get(0).scrollTop = position == 'first' ? 0: parseInt(focuson.get(0).scrollHeight, 10) * (parseInt(feed.children("li:visible").length, 10) - Math.round(options.height / 2))
327
+ } else {
328
+ focuson.removeClass("auto-focus");
329
+ focuson = position == 'first' ? focuson.nextAll("li:visible:first") : focuson.prevAll("li:visible:first");
330
+ var prev = parseInt(focuson.prevAll("li:visible").length, 10);
331
+ var next = parseInt(focuson.nextAll("li:visible").length, 10);
332
+ if (((position == 'first' ? prev: next) > Math.round(options.height / 2) || (position == 'first' ? prev: next) <= Math.round(options.height / 2)) && typeof(focuson.get(0)) != "undefined") {
333
+ feed.get(0).scrollTop = parseInt(focuson.get(0).scrollHeight, 10) * (prev - Math.round(options.height / 2))
334
+ }
335
+ }
336
+ feed.children("li").removeClass("auto-focus");
337
+ focuson.addClass("auto-focus")
338
+ }
339
+ function _preventDefault(event) {
340
+ complete.hide();
341
+ event.preventDefault();
342
+ focuson = null;
343
+ return false
344
+ }
345
+ function maxItems() {
346
+ return options.maxitems != 0 && (holder.children("li.bit-box").length < options.maxitems)
347
+ }
348
+ function addTextItem(value) {
349
+ if (options.newel && maxItems()) {
350
+ feed.children("li[fckb=1]").remove();
351
+ if (value.length == 0) {
352
+ return
353
+ }
354
+ var li = $('<li rel="' + value + '" fckb="1">').html(xssDisplay(value));
355
+ feed.prepend(li);
356
+ counter++
357
+ }
358
+ return
359
+ }
360
+ function funCall(func, item) {
361
+ var _object = {};
362
+ for (i = 0; i < item.get(0).attributes.length; i++) {
363
+ if (item.get(0).attributes[i].nodeValue != null) {
364
+ _object["_" + item.get(0).attributes[i].nodeName] = item.get(0).attributes[i].nodeValue
365
+ }
366
+ }
367
+ return func.call(func, _object)
368
+ }
369
+ function checkFocusOn() {
370
+ if (focuson == null || focuson.length == 0) {
371
+ return false
372
+ }
373
+ return true
374
+ }
375
+ function xssPrevent(string, flag) {
376
+ if (typeof flag != "undefined") {
377
+ for (i = 0; i < string.length; i++) {
378
+ var charcode = string.charCodeAt(i);
379
+ if ((_key.exclamation <= charcode && charcode <= _key.slash) || (_key.colon <= charcode && charcode <= _key.at) || (_key.squarebricket_left <= charcode && charcode <= _key.apostrof)) {
380
+ string = string.replace(string[i], escape(string[i]))
381
+ }
382
+ }
383
+ string = string.replace(/(\{|\}|\*)/i, "\\$1")
384
+ }
385
+ return string.replace(/script(.*)/g, "")
386
+ }
387
+ function xssDisplay(string, flag) {
388
+ string = string.toString();
389
+ string = string.replace('\\', "");
390
+ if (typeof flag != "undefined") {
391
+ return string
392
+ }
393
+ return unescape(string)
394
+ }
395
+ function clear_feed(flag) {
396
+ feed.children().remove();
397
+ if (flag) {
398
+ feed.hide()
399
+ }
400
+ }
401
+ function load_feed(etext) {
402
+ counter = 0;
403
+ if (options.json_url && maxItems()) {
404
+ if (options.cache && json_cache_object.get(etext)) {
405
+ addMembers(etext);
406
+ bindEvents()
407
+ } else {
408
+ getBoxTimeout++;
409
+ var getBoxTimeoutValue = getBoxTimeout;
410
+ setTimeout(function() {
411
+ if (getBoxTimeoutValue != getBoxTimeout) return;
412
+ $.getJSON(options.json_url, {
413
+ "tag": xssDisplay(etext)
414
+ },
415
+ function(data) {
416
+ if (!isactive) return;
417
+ addMembers(etext, data);
418
+ json_cache_object.set(etext, 1);
419
+ bindEvents()
420
+ })
421
+ },
422
+ options.delay)
423
+ }
424
+ } else {
425
+ addMembers(etext);
426
+ bindEvents()
427
+ }
428
+ }
429
+ var options = $.extend({
430
+ json_url: null,
431
+ width: 512,
432
+ cache: false,
433
+ height: "10",
434
+ newel: false,
435
+ addontab: false,
436
+ addoncomma: false,
437
+ firstselected: false,
438
+ filter_case: false,
439
+ filter_selected: false,
440
+ filter_begin: false,
441
+ complete_text: "Comece a digitar...",
442
+ select_all_text: null,
443
+ maxshownitems: 30,
444
+ maxitems: 10,
445
+ oncreate: null,
446
+ onselect: null,
447
+ onremove: null,
448
+ attachto: null,
449
+ delay: 350,
450
+ input_tabindex: 0,
451
+ input_min_size: 1,
452
+ input_name: "",
453
+ bricket: true
454
+ },
455
+ opt);
456
+ var holder = null;
457
+ var feed = null;
458
+ var complete = null;
459
+ var counter = 0;
460
+ var isactive = false;
461
+ var focuson = null;
462
+ var deleting = 0;
463
+ var complete_hover = 1;
464
+ var element = $(this);
465
+ var elemid = element.attr("id");
466
+ var getBoxTimeout = 0;
467
+ var json_cache_object = {
468
+ 'set': function(id, val) {
469
+ var data = element.data("jsoncache");
470
+ data[id] = val;
471
+ element.data("jsoncache", data)
472
+ },
473
+ 'get': function(id) {
474
+ return element.data("jsoncache")[id] != 'undefined' ? element.data("jsoncache")[id] : null
475
+ },
476
+ 'init': function() {
477
+ element.data("jsoncache", {})
478
+ }
479
+ };
480
+ var _key = {
481
+ 'enter': 13,
482
+ 'tab': 9,
483
+ 'comma': 188,
484
+ 'backspace': 8,
485
+ 'leftarrow': 37,
486
+ 'uparrow': 38,
487
+ 'rightarrow': 39,
488
+ 'downarrow': 40,
489
+ 'exclamation': 33,
490
+ 'slash': 47,
491
+ 'colon': 58,
492
+ 'at': 64,
493
+ 'squarebricket_left': 91,
494
+ 'apostrof': 96
495
+ };
496
+ var randomId = function() {
497
+ var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
498
+ var randomstring = '';
499
+ for (var i = 0; i < 32; i++) {
500
+ var rnum = Math.floor(Math.random() * chars.length);
501
+ randomstring += chars.substring(rnum, rnum + 1)
502
+ }
503
+ return randomstring
504
+ };
505
+ var cache = {
506
+ 'search': function(text, callback) {
507
+ var temp = new Array();
508
+ var regex = new RegExp((options.filter_begin ? '^': '') + text, (options.filter_case ? "g": "gi"));
509
+ $.each(element.data("cache"),
510
+ function(i, _elem) {
511
+ if (typeof _elem.search === 'function') {
512
+ if (_elem.search(regex) != -1) {
513
+ temp.push({
514
+ 'key': i,
515
+ 'value': _elem
516
+ })
517
+ }
518
+ }
519
+ });
520
+ return temp
521
+ },
522
+ 'set': function(id, val) {
523
+ var data = element.data("cache");
524
+ data[id] = val;
525
+ element.data("cache", data)
526
+ },
527
+ 'get': function(id) {
528
+ return element.data("cache")[id] != 'undefined' ? element.data("cache")[id] : null
529
+ },
530
+ 'clear': function() {
531
+ element.data("cache", {})
532
+ },
533
+ 'length': function() {
534
+ if (typeof(element.data('cache')) == "object") {
535
+ var _length = 0;
536
+ for (i in element.data('cache')) {
537
+ _length++
538
+ }
539
+ return _length
540
+ } else {
541
+ return element.data("cache").length
542
+ }
543
+ },
544
+ 'init': function() {
545
+ if (element.data("cache") == 'undefined') {
546
+ element.data("cache", {})
547
+ }
548
+ }
549
+ };
550
+ init();
551
+ json_cache_object.init();
552
+ cache.init();
553
+ return this
554
+ })
555
+ }
556
+ })(jQuery);