drewda_rails_admin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (372) hide show
  1. data/Gemfile +53 -0
  2. data/LICENSE.md +20 -0
  3. data/README.md +160 -0
  4. data/Rakefile +19 -0
  5. data/app/assets/images/rails_admin/aristo/images/bg_fallback.png +0 -0
  6. data/app/assets/images/rails_admin/aristo/images/icon_sprite.png +0 -0
  7. data/app/assets/images/rails_admin/aristo/images/progress_bar.gif +0 -0
  8. data/app/assets/images/rails_admin/aristo/images/slider_handles.png +0 -0
  9. data/app/assets/images/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
  10. data/app/assets/images/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
  11. data/app/assets/images/rails_admin/bullet_black.png +0 -0
  12. data/app/assets/images/rails_admin/bullet_white.png +0 -0
  13. data/app/assets/images/rails_admin/calendar.png +0 -0
  14. data/app/assets/images/rails_admin/clock.png +0 -0
  15. data/app/assets/images/rails_admin/colorpicker/colorpicker_background.png +0 -0
  16. data/app/assets/images/rails_admin/colorpicker/colorpicker_hex.png +0 -0
  17. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_b.png +0 -0
  18. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_h.png +0 -0
  19. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_s.png +0 -0
  20. data/app/assets/images/rails_admin/colorpicker/colorpicker_indic.gif +0 -0
  21. data/app/assets/images/rails_admin/colorpicker/colorpicker_overlay.png +0 -0
  22. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_b.png +0 -0
  23. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_g.png +0 -0
  24. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_r.png +0 -0
  25. data/app/assets/images/rails_admin/colorpicker/colorpicker_select.gif +0 -0
  26. data/app/assets/images/rails_admin/colorpicker/colorpicker_submit.png +0 -0
  27. data/app/assets/images/rails_admin/colorpicker/custom_background.png +0 -0
  28. data/app/assets/images/rails_admin/colorpicker/custom_hex.png +0 -0
  29. data/app/assets/images/rails_admin/colorpicker/custom_hsb_b.png +0 -0
  30. data/app/assets/images/rails_admin/colorpicker/custom_hsb_h.png +0 -0
  31. data/app/assets/images/rails_admin/colorpicker/custom_hsb_s.png +0 -0
  32. data/app/assets/images/rails_admin/colorpicker/custom_indic.gif +0 -0
  33. data/app/assets/images/rails_admin/colorpicker/custom_rgb_b.png +0 -0
  34. data/app/assets/images/rails_admin/colorpicker/custom_rgb_g.png +0 -0
  35. data/app/assets/images/rails_admin/colorpicker/custom_rgb_r.png +0 -0
  36. data/app/assets/images/rails_admin/colorpicker/custom_submit.png +0 -0
  37. data/app/assets/images/rails_admin/colorpicker/select.png +0 -0
  38. data/app/assets/images/rails_admin/colorpicker/select2.png +0 -0
  39. data/app/assets/images/rails_admin/colorpicker/slider.png +0 -0
  40. data/app/assets/images/rails_admin/logo.png +0 -0
  41. data/app/assets/images/rails_admin/magnifier.png +0 -0
  42. data/app/assets/images/rails_admin/multiselect/icon_sprite.png +0 -0
  43. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-dark.png +0 -0
  44. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-light.png +0 -0
  45. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-dark.png +0 -0
  46. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-light.png +0 -0
  47. data/app/assets/javascripts/rails_admin/custom/ui.js +12 -0
  48. data/app/assets/javascripts/rails_admin/jquery.colorpicker.js +484 -0
  49. data/app/assets/javascripts/rails_admin/jquery.pjax.js +431 -0
  50. data/app/assets/javascripts/rails_admin/jquery.ui.timepicker.js +1371 -0
  51. data/app/assets/javascripts/rails_admin/ra.datetimepicker.js +67 -0
  52. data/app/assets/javascripts/rails_admin/ra.filter-box.js +129 -0
  53. data/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +280 -0
  54. data/app/assets/javascripts/rails_admin/ra.filtering-select.js +181 -0
  55. data/app/assets/javascripts/rails_admin/ra.nested-form-hooks.coffee +40 -0
  56. data/app/assets/javascripts/rails_admin/ra.remote-form.js +150 -0
  57. data/app/assets/javascripts/rails_admin/rails_admin.js.erb +25 -0
  58. data/app/assets/javascripts/rails_admin/themes/default/ui.js +12 -0
  59. data/app/assets/javascripts/rails_admin/ui.js.coffee +61 -0
  60. data/app/assets/stylesheets/rails_admin/aristo/images/bg_fallback.png +0 -0
  61. data/app/assets/stylesheets/rails_admin/aristo/images/icon_sprite.png +0 -0
  62. data/app/assets/stylesheets/rails_admin/aristo/images/progress_bar.gif +0 -0
  63. data/app/assets/stylesheets/rails_admin/aristo/images/slider_handles.png +0 -0
  64. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
  65. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
  66. data/app/assets/stylesheets/rails_admin/aristo/jquery-ui-1.8.7.custom.css.scss +733 -0
  67. data/app/assets/stylesheets/rails_admin/base/README +2 -0
  68. data/app/assets/stylesheets/rails_admin/base/mixins.css.scss +1 -0
  69. data/app/assets/stylesheets/rails_admin/base/theming.css.scss +263 -0
  70. data/app/assets/stylesheets/rails_admin/base/variables.css.scss +1 -0
  71. data/app/assets/stylesheets/rails_admin/custom/mixins.css.scss +12 -0
  72. data/app/assets/stylesheets/rails_admin/custom/theming.css.scss +13 -0
  73. data/app/assets/stylesheets/rails_admin/custom/variables.css.scss +15 -0
  74. data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +76 -0
  75. data/app/assets/stylesheets/rails_admin/jquery.colorpicker.css.scss +180 -0
  76. data/app/assets/stylesheets/rails_admin/jquery.ui.timepicker.css.scss +69 -0
  77. data/app/assets/stylesheets/rails_admin/ra.calendar-additions.css.scss +25 -0
  78. data/app/assets/stylesheets/rails_admin/ra.filtering-multiselect.css.scss +85 -0
  79. data/app/assets/stylesheets/rails_admin/rails_admin.css +4 -0
  80. data/app/assets/stylesheets/rails_admin/themes/default/mixins.css.scss +8 -0
  81. data/app/assets/stylesheets/rails_admin/themes/default/theming.css.scss +11 -0
  82. data/app/assets/stylesheets/rails_admin/themes/default/variables.css.scss +12 -0
  83. data/app/controllers/rails_admin/application_controller.rb +82 -0
  84. data/app/controllers/rails_admin/main_controller.rb +151 -0
  85. data/app/helpers/rails_admin/application_helper.rb +123 -0
  86. data/app/helpers/rails_admin/form_builder.rb +104 -0
  87. data/app/helpers/rails_admin/main_helper.rb +36 -0
  88. data/app/views/kaminari/twitter-bootstrap/_gap.html.haml +2 -0
  89. data/app/views/kaminari/twitter-bootstrap/_next_page.html.haml +4 -0
  90. data/app/views/kaminari/twitter-bootstrap/_page.html.haml +4 -0
  91. data/app/views/kaminari/twitter-bootstrap/_paginator.html.haml +10 -0
  92. data/app/views/kaminari/twitter-bootstrap/_prev_page.html.haml +4 -0
  93. data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +12 -0
  94. data/app/views/layouts/rails_admin/application.html.haml +39 -0
  95. data/app/views/rails_admin/main/_dashboard_history.html.haml +10 -0
  96. data/app/views/rails_admin/main/_delete_notice.html.haml +18 -0
  97. data/app/views/rails_admin/main/_form_colorpicker.html.haml +24 -0
  98. data/app/views/rails_admin/main/_form_datetime.html.haml +4 -0
  99. data/app/views/rails_admin/main/_form_enumeration.html.haml +4 -0
  100. data/app/views/rails_admin/main/_form_field.html.haml +1 -0
  101. data/app/views/rails_admin/main/_form_file_upload.html.haml +18 -0
  102. data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +59 -0
  103. data/app/views/rails_admin/main/_form_filtering_select.html.haml +47 -0
  104. data/app/views/rails_admin/main/_form_nested_many.html.haml +41 -0
  105. data/app/views/rails_admin/main/_form_nested_one.html.haml +35 -0
  106. data/app/views/rails_admin/main/_form_polymorphic_association.html.haml +34 -0
  107. data/app/views/rails_admin/main/_form_text.html.haml +9 -0
  108. data/app/views/rails_admin/main/_submit_buttons.html.haml +15 -0
  109. data/app/views/rails_admin/main/bulk_delete.html.haml +11 -0
  110. data/app/views/rails_admin/main/dashboard.html.haml +31 -0
  111. data/app/views/rails_admin/main/delete.html.haml +18 -0
  112. data/app/views/rails_admin/main/edit.html.haml +2 -0
  113. data/app/views/rails_admin/main/export.html.haml +75 -0
  114. data/app/views/rails_admin/main/history.html.haml +42 -0
  115. data/app/views/rails_admin/main/index.html.haml +140 -0
  116. data/app/views/rails_admin/main/new.html.haml +2 -0
  117. data/app/views/rails_admin/main/show.html.haml +14 -0
  118. data/config/initializers/active_record_extensions.rb +19 -0
  119. data/config/initializers/devise_patch.rb +9 -0
  120. data/config/initializers/haml.rb +2 -0
  121. data/config/initializers/mongoid_extensions.rb +4 -0
  122. data/config/locales/fr.yml +24 -0
  123. data/config/locales/rails_admin.en.yml +130 -0
  124. data/config/routes.rb +12 -0
  125. data/lib/generators/rails_admin/install_generator.rb +84 -0
  126. data/lib/generators/rails_admin/templates/drop.rb +18 -0
  127. data/lib/generators/rails_admin/templates/initializer.erb +101 -0
  128. data/lib/generators/rails_admin/templates/migration.rb +18 -0
  129. data/lib/generators/rails_admin/uninstall_generator.rb +22 -0
  130. data/lib/generators/rails_admin/utils.rb +30 -0
  131. data/lib/rails_admin.rb +34 -0
  132. data/lib/rails_admin/abstract_model.rb +110 -0
  133. data/lib/rails_admin/adapters/active_record.rb +247 -0
  134. data/lib/rails_admin/adapters/active_record/abstract_object.rb +32 -0
  135. data/lib/rails_admin/adapters/mongoid.rb +333 -0
  136. data/lib/rails_admin/adapters/mongoid/abstract_object.rb +32 -0
  137. data/lib/rails_admin/adapters/mongoid/extension.rb +27 -0
  138. data/lib/rails_admin/config.rb +322 -0
  139. data/lib/rails_admin/config/actions.rb +121 -0
  140. data/lib/rails_admin/config/actions/base.rb +117 -0
  141. data/lib/rails_admin/config/actions/bulk_delete.rb +55 -0
  142. data/lib/rails_admin/config/actions/dashboard.rb +44 -0
  143. data/lib/rails_admin/config/actions/delete.rb +53 -0
  144. data/lib/rails_admin/config/actions/edit.rb +60 -0
  145. data/lib/rails_admin/config/actions/export.rb +40 -0
  146. data/lib/rails_admin/config/actions/history_index.rb +38 -0
  147. data/lib/rails_admin/config/actions/history_show.rb +38 -0
  148. data/lib/rails_admin/config/actions/index.rb +85 -0
  149. data/lib/rails_admin/config/actions/new.rb +64 -0
  150. data/lib/rails_admin/config/actions/show.rb +32 -0
  151. data/lib/rails_admin/config/actions/show_in_app.rb +28 -0
  152. data/lib/rails_admin/config/configurable.rb +92 -0
  153. data/lib/rails_admin/config/fields.rb +88 -0
  154. data/lib/rails_admin/config/fields/association.rb +108 -0
  155. data/lib/rails_admin/config/fields/base.rb +281 -0
  156. data/lib/rails_admin/config/fields/factories/belongs_to_association.rb +29 -0
  157. data/lib/rails_admin/config/fields/factories/carrierwave.rb +31 -0
  158. data/lib/rails_admin/config/fields/factories/devise.rb +27 -0
  159. data/lib/rails_admin/config/fields/factories/dragonfly.rb +27 -0
  160. data/lib/rails_admin/config/fields/factories/enum.rb +11 -0
  161. data/lib/rails_admin/config/fields/factories/paperclip.rb +26 -0
  162. data/lib/rails_admin/config/fields/factories/password.rb +17 -0
  163. data/lib/rails_admin/config/fields/factories/serialized.rb +17 -0
  164. data/lib/rails_admin/config/fields/group.rb +78 -0
  165. data/lib/rails_admin/config/fields/types.rb +27 -0
  166. data/lib/rails_admin/config/fields/types/all.rb +26 -0
  167. data/lib/rails_admin/config/fields/types/belongs_to_association.rb +41 -0
  168. data/lib/rails_admin/config/fields/types/boolean.rb +31 -0
  169. data/lib/rails_admin/config/fields/types/bson_object_id.rb +42 -0
  170. data/lib/rails_admin/config/fields/types/carrierwave.rb +31 -0
  171. data/lib/rails_admin/config/fields/types/color.rb +37 -0
  172. data/lib/rails_admin/config/fields/types/date.rb +24 -0
  173. data/lib/rails_admin/config/fields/types/datetime.rb +165 -0
  174. data/lib/rails_admin/config/fields/types/decimal.rb +14 -0
  175. data/lib/rails_admin/config/fields/types/dragonfly.rb +41 -0
  176. data/lib/rails_admin/config/fields/types/enum.rb +35 -0
  177. data/lib/rails_admin/config/fields/types/file_upload.rb +61 -0
  178. data/lib/rails_admin/config/fields/types/float.rb +14 -0
  179. data/lib/rails_admin/config/fields/types/has_and_belongs_to_many_association.rb +14 -0
  180. data/lib/rails_admin/config/fields/types/has_many_association.rb +32 -0
  181. data/lib/rails_admin/config/fields/types/has_one_association.rb +39 -0
  182. data/lib/rails_admin/config/fields/types/hidden.rb +21 -0
  183. data/lib/rails_admin/config/fields/types/integer.rb +22 -0
  184. data/lib/rails_admin/config/fields/types/mongoid_type.rb +25 -0
  185. data/lib/rails_admin/config/fields/types/paperclip.rb +28 -0
  186. data/lib/rails_admin/config/fields/types/password.rb +39 -0
  187. data/lib/rails_admin/config/fields/types/polymorphic_association.rb +76 -0
  188. data/lib/rails_admin/config/fields/types/serialized.rb +22 -0
  189. data/lib/rails_admin/config/fields/types/string.rb +41 -0
  190. data/lib/rails_admin/config/fields/types/text.rb +36 -0
  191. data/lib/rails_admin/config/fields/types/time.rb +36 -0
  192. data/lib/rails_admin/config/fields/types/timestamp.rb +18 -0
  193. data/lib/rails_admin/config/groupable.rb +18 -0
  194. data/lib/rails_admin/config/has_fields.rb +135 -0
  195. data/lib/rails_admin/config/has_groups.rb +23 -0
  196. data/lib/rails_admin/config/hideable.rb +28 -0
  197. data/lib/rails_admin/config/model.rb +88 -0
  198. data/lib/rails_admin/config/proxyable.rb +12 -0
  199. data/lib/rails_admin/config/proxyable/proxy.rb +43 -0
  200. data/lib/rails_admin/config/sections.rb +38 -0
  201. data/lib/rails_admin/config/sections/base.rb +29 -0
  202. data/lib/rails_admin/config/sections/create.rb +11 -0
  203. data/lib/rails_admin/config/sections/edit.rb +11 -0
  204. data/lib/rails_admin/config/sections/export.rb +11 -0
  205. data/lib/rails_admin/config/sections/list.rb +27 -0
  206. data/lib/rails_admin/config/sections/nested.rb +10 -0
  207. data/lib/rails_admin/config/sections/show.rb +10 -0
  208. data/lib/rails_admin/config/sections/update.rb +10 -0
  209. data/lib/rails_admin/engine.rb +22 -0
  210. data/lib/rails_admin/extension.rb +29 -0
  211. data/lib/rails_admin/extensions/cancan.rb +5 -0
  212. data/lib/rails_admin/extensions/cancan/authorization_adapter.rb +59 -0
  213. data/lib/rails_admin/extensions/history.rb +5 -0
  214. data/lib/rails_admin/extensions/history/auditing_adapter.rb +37 -0
  215. data/lib/rails_admin/extensions/history/history.rb +69 -0
  216. data/lib/rails_admin/extensions/paper_trail.rb +5 -0
  217. data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +92 -0
  218. data/lib/rails_admin/i18n_support.rb +43 -0
  219. data/lib/rails_admin/support/core_extensions.rb +44 -0
  220. data/lib/rails_admin/support/csv_converter.rb +109 -0
  221. data/lib/rails_admin/version.rb +6 -0
  222. data/lib/tasks/prepare_ci_env.rake +27 -0
  223. data/lib/tasks/rails_admin.rake +18 -0
  224. data/spec/ci.sh +2 -0
  225. data/spec/controllers/application_controller_spec.rb +30 -0
  226. data/spec/controllers/main_controller_spec.rb +180 -0
  227. data/spec/database_helpers.rb +15 -0
  228. data/spec/dummy_app/Gemfile +58 -0
  229. data/spec/dummy_app/Rakefile +7 -0
  230. data/spec/dummy_app/app/assets/images/rails.png +0 -0
  231. data/spec/dummy_app/app/assets/javascripts/application.js +15 -0
  232. data/spec/dummy_app/app/assets/stylesheets/application.css +13 -0
  233. data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
  234. data/spec/dummy_app/app/controllers/players_controller.rb +5 -0
  235. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  236. data/spec/dummy_app/app/locales/models.en.yml +16 -0
  237. data/spec/dummy_app/app/models/abstract.rb +5 -0
  238. data/spec/dummy_app/app/models/article.rb +9 -0
  239. data/spec/dummy_app/app/models/author.rb +6 -0
  240. data/spec/dummy_app/app/models/ball.rb +8 -0
  241. data/spec/dummy_app/app/models/category.rb +3 -0
  242. data/spec/dummy_app/app/models/cms.rb +5 -0
  243. data/spec/dummy_app/app/models/cms/basic_page.rb +7 -0
  244. data/spec/dummy_app/app/models/cms/unscoped_page.rb +3 -0
  245. data/spec/dummy_app/app/models/comment.rb +3 -0
  246. data/spec/dummy_app/app/models/division.rb +12 -0
  247. data/spec/dummy_app/app/models/draft.rb +11 -0
  248. data/spec/dummy_app/app/models/fan.rb +5 -0
  249. data/spec/dummy_app/app/models/field_test.rb +20 -0
  250. data/spec/dummy_app/app/models/hardball.rb +2 -0
  251. data/spec/dummy_app/app/models/league.rb +10 -0
  252. data/spec/dummy_app/app/models/mongoid_field_test.rb +22 -0
  253. data/spec/dummy_app/app/models/nested_field_test.rb +6 -0
  254. data/spec/dummy_app/app/models/player.rb +23 -0
  255. data/spec/dummy_app/app/models/rel_test.rb +6 -0
  256. data/spec/dummy_app/app/models/tag.rb +7 -0
  257. data/spec/dummy_app/app/models/team.rb +25 -0
  258. data/spec/dummy_app/app/models/user.rb +21 -0
  259. data/spec/dummy_app/app/uploaders/carrierwave_uploader.rb +53 -0
  260. data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
  261. data/spec/dummy_app/app/views/players/show.html.haml +1 -0
  262. data/spec/dummy_app/config.ru +4 -0
  263. data/spec/dummy_app/config/application.rb +62 -0
  264. data/spec/dummy_app/config/boot.rb +6 -0
  265. data/spec/dummy_app/config/database.yml +25 -0
  266. data/spec/dummy_app/config/environment.rb +5 -0
  267. data/spec/dummy_app/config/environments/development.rb +37 -0
  268. data/spec/dummy_app/config/environments/production.rb +67 -0
  269. data/spec/dummy_app/config/environments/test.rb +37 -0
  270. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  271. data/spec/dummy_app/config/initializers/devise.rb +148 -0
  272. data/spec/dummy_app/config/initializers/inflections.rb +15 -0
  273. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  274. data/spec/dummy_app/config/initializers/rails_admin.rb +11 -0
  275. data/spec/dummy_app/config/initializers/secret_token.rb +7 -0
  276. data/spec/dummy_app/config/initializers/session_store.rb +8 -0
  277. data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
  278. data/spec/dummy_app/config/mongoid.yml +17 -0
  279. data/spec/dummy_app/config/routes.rb +10 -0
  280. data/spec/dummy_app/db/migrate/00000000000001_create_divisions_migration.rb +13 -0
  281. data/spec/dummy_app/db/migrate/00000000000002_create_drafts_migration.rb +19 -0
  282. data/spec/dummy_app/db/migrate/00000000000003_create_leagues_migration.rb +12 -0
  283. data/spec/dummy_app/db/migrate/00000000000004_create_players_migration.rb +20 -0
  284. data/spec/dummy_app/db/migrate/00000000000005_create_teams_migration.rb +22 -0
  285. data/spec/dummy_app/db/migrate/00000000000006_devise_create_users.rb +49 -0
  286. data/spec/dummy_app/db/migrate/00000000000007_create_histories_table.rb +16 -0
  287. data/spec/dummy_app/db/migrate/00000000000008_create_fans_migration.rb +12 -0
  288. data/spec/dummy_app/db/migrate/00000000000009_create_fans_teams_migration.rb +11 -0
  289. data/spec/dummy_app/db/migrate/00000000000010_add_revenue_to_team_migration.rb +9 -0
  290. data/spec/dummy_app/db/migrate/00000000000011_add_suspended_to_player_migration.rb +9 -0
  291. data/spec/dummy_app/db/migrate/00000000000012_add_avatar_columns_to_user.rb +16 -0
  292. data/spec/dummy_app/db/migrate/00000000000013_add_roles_to_user.rb +9 -0
  293. data/spec/dummy_app/db/migrate/00000000000014_add_color_to_team_migration.rb +9 -0
  294. data/spec/dummy_app/db/migrate/20101223222233_create_rel_tests.rb +15 -0
  295. data/spec/dummy_app/db/migrate/20110103205808_create_comments.rb +15 -0
  296. data/spec/dummy_app/db/migrate/20110123042530_rename_histories_to_rails_admin_histories.rb +9 -0
  297. data/spec/dummy_app/db/migrate/20110224184303_create_field_tests.rb +22 -0
  298. data/spec/dummy_app/db/migrate/20110328193014_create_cms_basic_pages.rb +14 -0
  299. data/spec/dummy_app/db/migrate/20110329183136_remove_league_id_from_teams.rb +9 -0
  300. data/spec/dummy_app/db/migrate/20110607152842_add_format_to_field_test.rb +9 -0
  301. data/spec/dummy_app/db/migrate/20110714095433_create_balls.rb +12 -0
  302. data/spec/dummy_app/db/migrate/20110831090841_add_protected_field_and_restricted_field_to_field_tests.rb +6 -0
  303. data/spec/dummy_app/db/migrate/20110901131551_change_division_primary_key.rb +19 -0
  304. data/spec/dummy_app/db/migrate/20110901142530_rename_league_id_foreign_key_on_divisions.rb +5 -0
  305. data/spec/dummy_app/db/migrate/20110901150912_set_primary_key_not_null_for_divisions.rb +21 -0
  306. data/spec/dummy_app/db/migrate/20110901154834_change_length_for_rails_admin_histories.rb +9 -0
  307. data/spec/dummy_app/db/migrate/20111103174459_create_unscoped_pages.rb +9 -0
  308. data/spec/dummy_app/db/migrate/20111108143642_add_dragonfly_and_carrierwave_to_field_tests.rb +7 -0
  309. data/spec/dummy_app/db/migrate/20111115041025_add_type_to_balls.rb +5 -0
  310. data/spec/dummy_app/db/migrate/20111123092549_create_nested_field_tests.rb +10 -0
  311. data/spec/dummy_app/db/migrate/20111130075338_add_dragonfly_asset_name_to_field_tests.rb +5 -0
  312. data/spec/dummy_app/db/migrate/20111215083258_create_foo_bars.rb +8 -0
  313. data/spec/dummy_app/db/migrate/20120117151733_add_custom_field_to_teams.rb +5 -0
  314. data/spec/dummy_app/db/migrate/20120118122004_add_categories.rb +7 -0
  315. data/spec/dummy_app/db/seeds.rb +18 -0
  316. data/spec/dummy_app/doc/README_FOR_APP +2 -0
  317. data/spec/dummy_app/public/404.html +26 -0
  318. data/spec/dummy_app/public/422.html +26 -0
  319. data/spec/dummy_app/public/500.html +25 -0
  320. data/spec/dummy_app/public/favicon.ico +0 -0
  321. data/spec/dummy_app/public/robots.txt +5 -0
  322. data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg +0 -0
  323. data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg.meta +1 -0
  324. data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg +0 -0
  325. data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg.meta +1 -0
  326. data/spec/dummy_app/public/system/paperclip_assets/1/original/Boston City Flow.jpg +0 -0
  327. data/spec/dummy_app/public/system/paperclip_assets/1/thumb/Boston City Flow.jpg +0 -0
  328. data/spec/dummy_app/public/system/paperclip_assets/3/original/Costa Rican Frog.jpg +0 -0
  329. data/spec/dummy_app/public/system/paperclip_assets/3/thumb/Costa Rican Frog.jpg +0 -0
  330. data/spec/dummy_app/public/system/paperclip_assets/6/original/liste-electorale.pdf +0 -0
  331. data/spec/dummy_app/public/system/paperclip_assets/6/thumb/liste-electorale.pdf +148 -0
  332. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/Boston_City_Flow.jpg +0 -0
  333. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/thumb_Boston_City_Flow.jpg +0 -0
  334. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/Costa_Rican_Frog.jpg +0 -0
  335. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/thumb_Costa_Rican_Frog.jpg +0 -0
  336. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/Pensive_Parakeet.jpg +0 -0
  337. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/thumb_Pensive_Parakeet.jpg +0 -0
  338. data/spec/dummy_app/script/rails +6 -0
  339. data/spec/factories.rb +89 -0
  340. data/spec/helpers/application_helper_spec.rb +277 -0
  341. data/spec/integration/authorization/cancan_spec.rb +349 -0
  342. data/spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +25 -0
  343. data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +44 -0
  344. data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +154 -0
  345. data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +23 -0
  346. data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +27 -0
  347. data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +56 -0
  348. data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +109 -0
  349. data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +87 -0
  350. data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +392 -0
  351. data/spec/integration/basic/new/rails_admin_basic_new_spec.rb +74 -0
  352. data/spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb +31 -0
  353. data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +91 -0
  354. data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +219 -0
  355. data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +954 -0
  356. data/spec/integration/config/list/rails_admin_config_list_spec.rb +509 -0
  357. data/spec/integration/config/show/rails_admin_config_show_spec.rb +302 -0
  358. data/spec/integration/history/rails_admin_history_spec.rb +66 -0
  359. data/spec/integration/rails_admin_spec.rb +113 -0
  360. data/spec/integration/relation_spec.rb +26 -0
  361. data/spec/spec_helper.rb +86 -0
  362. data/spec/support/tableless.rb +27 -0
  363. data/spec/unit/adapters/active_record/abstract_object_spec.rb +131 -0
  364. data/spec/unit/adapters/active_record_spec.rb +373 -0
  365. data/spec/unit/adapters/mongoid/abstract_object_spec.rb +30 -0
  366. data/spec/unit/adapters/mongoid_spec.rb +581 -0
  367. data/spec/unit/config/actions_spec.rb +181 -0
  368. data/spec/unit/config/fields/base_spec.rb +300 -0
  369. data/spec/unit/config/model_spec.rb +75 -0
  370. data/spec/unit/config/sections_spec.rb +123 -0
  371. data/spec/unit/config_spec.rb +273 -0
  372. metadata +823 -0
data/Gemfile ADDED
@@ -0,0 +1,53 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Bundle gems for the local environment. Make sure to
4
+ # put test-only gems in this group so their generators
5
+ # and rake tasks are available in development mode:
6
+ group :development, :test do
7
+ platforms :jruby do
8
+ case ENV['CI_DB_ADAPTER']
9
+ when 'mysql'
10
+ gem 'activerecord-jdbcmysql-adapter', '~> 1.2'
11
+ gem 'jdbc-mysql', '~> 5.1'
12
+ when 'postgresql'
13
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 1.2'
14
+ gem 'jdbc-postgres', '~> 9.0'
15
+ else
16
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 1.2'
17
+ gem 'jdbc-sqlite3', '~> 3.6'
18
+ end
19
+ end
20
+
21
+ platforms :ruby, :mswin, :mingw do
22
+ case ENV['CI_DB_ADAPTER']
23
+ when 'mysql'
24
+ gem 'mysql', '~> 2.8'
25
+ when 'postgresql'
26
+ gem 'pg', '~> 0.13'
27
+ else
28
+ gem 'sqlite3', '~> 1.3'
29
+ end
30
+ end
31
+
32
+ gem 'bson_ext'
33
+ gem 'mongoid'
34
+ gem 'cancan'
35
+ end
36
+
37
+ group :debug do
38
+ platform :mri_18 do
39
+ gem 'ruby-debug'
40
+ gem 'linecache'
41
+ end
42
+
43
+ platform :mri_19 do
44
+ gem 'ruby-debug19'
45
+ gem 'simplecov', :require => false
46
+ end
47
+ end
48
+
49
+ platforms :jruby, :mingw_18, :ruby_18 do
50
+ gem 'fastercsv', '~> 1.5'
51
+ end
52
+
53
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Erik Michaels-Ober
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.
@@ -0,0 +1,160 @@
1
+ # RailsAdmin [![Build Status](https://secure.travis-ci.org/sferik/rails_admin.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/sferik/rails_admin.png?travis)][gemnasium] [![Click here to lend your support to: RailsAdmin and make a donation at www.pledgie.com !](https://www.pledgie.com/campaigns/15917.png?skin_name=chrome)][pledgie]
2
+ RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data.
3
+
4
+ [travis]: http://travis-ci.org/sferik/rails_admin
5
+ [gemnasium]: https://gemnasium.com/sferik/rails_admin
6
+ [pledgie]: http://www.pledgie.com/campaigns/15917
7
+
8
+ It started as a port of [MerbAdmin][merb-admin] to Rails 3 and was implemented
9
+ as a [Ruby Summer of Code project][rubysoc] by [Bogdan Gaza][hurrycane] with
10
+ mentors [Erik Michaels-Ober][sferik], [Yehuda Katz][wycats], [Luke van der
11
+ Hoeven][plukevdh], and [Rein Henrichs][reinh].
12
+
13
+ [merb-admin]: https://github.com/sferik/merb-admin
14
+ [rubysoc]: http://www.rubysoc.org/projects
15
+ [hurrycane]: https://github.com/hurrycane
16
+ [sferik]: https://github.com/sferik
17
+ [wycats]: https://github.com/wycats
18
+ [plukevdh]: https://github.com/plukevdh
19
+ [reinh]: https://github.com/reinh
20
+
21
+ ## <a name="features"></a>Features
22
+
23
+ * Display database tables
24
+ * Create new data
25
+ * Easily update data
26
+ * Safely delete data
27
+ * Custom actions
28
+ * Automatic form validation
29
+ * Search and filtering
30
+ * Export data to CSV/JSON/XML
31
+ * Authentication (via [Devise](https://github.com/plataformatec/devise))
32
+ * Authorization (via [Cancan](https://github.com/ryanb/cancan))
33
+ * User action history (internally or via [PaperTrail](https://github.com/airblade/paper_trail))
34
+ * Supported ORMs
35
+ * ActiveRecord
36
+ * Mongoid [new]
37
+
38
+ ## <a name="demo"></a>Demo
39
+
40
+ Take RailsAdmin for a [test drive][demo] with sample data. ([Source code.][dummy_app])
41
+
42
+ [demo]: http://rails-admin-tb.herokuapp.com/
43
+ [dummy_app]: https://github.com/bbenezech/dummy_app
44
+
45
+ ## <a name="installation"></a>Installation
46
+ In your `Gemfile`, add the following dependencies:
47
+
48
+ gem 'fastercsv' # Only required on Ruby 1.8 and below
49
+ gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
50
+
51
+ Run:
52
+
53
+ $ bundle install
54
+
55
+ And then run:
56
+
57
+ $ rails g rails_admin:install
58
+
59
+ This generator will install RailsAdmin and [Devise](https://github.com/plataformatec/devise) if you
60
+ don't already have it installed. [Devise](https://github.com/plataformatec/devise) is strongly
61
+ recommended to protect your data from anonymous users.
62
+ It will modify your `config/routes.rb`, adding:
63
+
64
+ ```ruby
65
+ mount RailsAdmin::Engine => '/admin', :as => 'rails_admin' # Feel free to change '/admin' to any namespace you need.
66
+ ```
67
+
68
+ It will also add an intializer that will help you getting started. (head for config/initializers/rails_admin.rb)
69
+
70
+ Optionally, you may wish to set up [Cancan](https://github.com/ryanb/cancan),
71
+ [PaperTrail](https://github.com/airblade/paper_trail), [CKeditor](https://github.com/galetahub/ckeditor)
72
+
73
+ More on that in the [Wiki](https://github.com/sferik/rails_admin/wiki)
74
+
75
+ ## <a name="usage"></a>Usage
76
+ Start the server:
77
+
78
+ $ rails server
79
+
80
+ You should now be able to administer your site at
81
+ [http://localhost:3000/admin](http://localhost:3000/admin).
82
+
83
+ ## <a name="configuration"></a>Configuration
84
+
85
+ All configuration documentation has moved to the wiki: https://github.com/sferik/rails_admin/wiki
86
+
87
+ ## <a name="support"></a>Support
88
+ Please see [list of known issues](https://github.com/sferik/rails_admin/wiki/Known-issues) first.
89
+
90
+ If you have a question, please check this README, the wiki, and the list of known issues.
91
+
92
+ If you still have a question, you can ask the [official RailsAdmin mailing
93
+ list](http://groups.google.com/group/rails_admin) or ping sferik on IRC in
94
+ [#railsadmin on
95
+ irc.freenode.net](http://webchat.freenode.net/?channels=railsadmin).
96
+
97
+ If you think you found a bug in RailsAdmin, you can [submit an
98
+ issue](https://github.com/sferik/rails_admin#issues).
99
+ No feature requests or questions please (the mailing list is
100
+ active and is the preferred venue for feature requests and questions).
101
+
102
+ ## <a name="contributing"></a>Contributing
103
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html),
104
+ **everyone** is encouraged to help improve this project.
105
+
106
+ Here are some ways *you* can contribute:
107
+
108
+ * by using alpha, beta, and prerelease versions
109
+ * by reporting bugs
110
+ * by suggesting new features
111
+ * by [translating to a new language](https://github.com/sferik/rails_admin/wiki/Translations)
112
+ * by writing or editing documentation
113
+ * by writing specifications
114
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
115
+ * by refactoring code
116
+ * by resolving [issues](https://github.com/sferik/rails_admin/issues)
117
+ * by reviewing patches
118
+ * [financially](http://pledgie.com/campaigns/15917)
119
+
120
+ ## <a name="issues"></a>Submitting an Issue
121
+ We use the [GitHub issue tracker](https://github.com/sferik/rails_admin/issues) to track bugs and
122
+ features. Before submitting a bug report or feature request, please check to make sure it hasn't already
123
+ been submitted. You can indicate support for an existing issue by voting it up. When submitting a
124
+ bug report, please include a [Gist](https://gist.github.com/) that includes a stack trace and any
125
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
126
+ operating system. Ideally, a bug report should include a pull request with failing specs.
127
+
128
+ ## <a name="pulls"></a>Submitting a Pull Request
129
+ 1. Fork the project.
130
+ 2. Create a topic branch.
131
+ 3. Implement your feature or bug fix. *NOTE* - there's a small test app located in the
132
+ spec/dummy_app directory that you can use to experiment with rails_admin.
133
+ 4. Add documentation for your feature or bug fix.
134
+ 5. Run `bundle exec rake doc:yard`. If your changes are not 100% documented, go back to step 4.
135
+ 6. Add specs for your feature or bug fix.
136
+ 7. Run `bundle exec rake spec`. If your changes are not 100% covered, go back to step 6.
137
+ 8. Commit and push your changes.
138
+ 9. Submit a pull request. Please do not include changes to the gemspec, version, or history file.
139
+ (If you want to create your own version for some reason, please do so in a separate commit.)
140
+
141
+ ## <a name="versions"></a>Supported Ruby Versions
142
+ This library aims to support and is [tested against][travis] the following Ruby implementations:
143
+
144
+ * Ruby 1.8.7
145
+ * Ruby 1.9.2
146
+ * Ruby 1.9.3
147
+ * [Rubinius][]
148
+ * [Ruby Enterprise Edition][ree]
149
+ * [JRuby][jruby]
150
+
151
+ [rubinius]: http://rubini.us/
152
+ [ree]: http://www.rubyenterpriseedition.com/
153
+ [jruby]:http://jruby.org/
154
+
155
+ ## <a name="screenshots"></a>Screenshots
156
+ ![Dashboard view](https://github.com/sferik/rails_admin/raw/master/screenshots/dashboard.png "dashboard view")
157
+ ![Delete view](https://github.com/sferik/rails_admin/raw/master/screenshots/delete.png "delete view")
158
+ ![List view](https://github.com/sferik/rails_admin/raw/master/screenshots/list.png "list view")
159
+ ![Nested view](https://github.com/sferik/rails_admin/raw/master/screenshots/nested.png "nested view")
160
+ ![Polymophic edit view](https://github.com/sferik/rails_admin/raw/master/screenshots/polymorphic.png "polymorphic view")
@@ -0,0 +1,19 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ Dir['lib/tasks/*.rake'].each { |rake| load rake }
5
+
6
+ require "rubygems"
7
+ require "bundler/setup"
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ task :test => :spec
13
+ task :default => :spec
14
+ namespace :spec do
15
+ task :coverage do
16
+ ENV['INVOKE_SIMPLECOV'] = 'true'
17
+ Rake::Task[:spec].invoke
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ /*
2
+ Meant to be overriden in user's app/assets/javascripts/rails_admin/custom directory. no content here
3
+
4
+ Available resources:
5
+
6
+ http://twitter.github.com/bootstrap/javascript.html
7
+ https://github.com/twitter/bootstrap/tree/master/js
8
+ http://jquery.com/
9
+ http://jqueryui.com/ (parts of it)
10
+
11
+ rename to ui.js.coffee if needed.
12
+ */
@@ -0,0 +1,484 @@
1
+ /**
2
+ *
3
+ * Color picker
4
+ * Author: Stefan Petre www.eyecon.ro
5
+ *
6
+ * Dual licensed under the MIT and GPL licenses
7
+ *
8
+ */
9
+ (function ($) {
10
+ var ColorPicker = function () {
11
+ var
12
+ ids = {},
13
+ inAction,
14
+ charMin = 65,
15
+ visible,
16
+ tpl = '<div class="colorpicker"><div class="colorpicker_color"><div><div></div></div></div><div class="colorpicker_hue"><div></div></div><div class="colorpicker_new_color"></div><div class="colorpicker_current_color"></div><div class="colorpicker_hex"><input type="text" maxlength="6" size="6" /></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_submit"></div></div>',
17
+ defaults = {
18
+ eventName: 'click',
19
+ onShow: function () {},
20
+ onBeforeShow: function(){},
21
+ onHide: function () {},
22
+ onChange: function () {},
23
+ onSubmit: function () {},
24
+ color: 'ff0000',
25
+ livePreview: true,
26
+ flat: false
27
+ },
28
+ fillRGBFields = function (hsb, cal) {
29
+ var rgb = HSBToRGB(hsb);
30
+ $(cal).data('colorpicker').fields
31
+ .eq(1).val(rgb.r).end()
32
+ .eq(2).val(rgb.g).end()
33
+ .eq(3).val(rgb.b).end();
34
+ },
35
+ fillHSBFields = function (hsb, cal) {
36
+ $(cal).data('colorpicker').fields
37
+ .eq(4).val(hsb.h).end()
38
+ .eq(5).val(hsb.s).end()
39
+ .eq(6).val(hsb.b).end();
40
+ },
41
+ fillHexFields = function (hsb, cal) {
42
+ $(cal).data('colorpicker').fields
43
+ .eq(0).val(HSBToHex(hsb)).end();
44
+ },
45
+ setSelector = function (hsb, cal) {
46
+ $(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({h: hsb.h, s: 100, b: 100}));
47
+ $(cal).data('colorpicker').selectorIndic.css({
48
+ left: parseInt(150 * hsb.s/100, 10),
49
+ top: parseInt(150 * (100-hsb.b)/100, 10)
50
+ });
51
+ },
52
+ setHue = function (hsb, cal) {
53
+ $(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h/360, 10));
54
+ },
55
+ setCurrentColor = function (hsb, cal) {
56
+ $(cal).data('colorpicker').currentColor.css('backgroundColor', '#' + HSBToHex(hsb));
57
+ },
58
+ setNewColor = function (hsb, cal) {
59
+ $(cal).data('colorpicker').newColor.css('backgroundColor', '#' + HSBToHex(hsb));
60
+ },
61
+ keyDown = function (ev) {
62
+ var pressedKey = ev.charCode || ev.keyCode || -1;
63
+ if ((pressedKey > charMin && pressedKey <= 90) || pressedKey == 32) {
64
+ return false;
65
+ }
66
+ var cal = $(this).parent().parent();
67
+ if (cal.data('colorpicker').livePreview === true) {
68
+ change.apply(this);
69
+ }
70
+ },
71
+ change = function (ev) {
72
+ var cal = $(this).parent().parent(), col;
73
+ if (this.parentNode.className.indexOf('_hex') > 0) {
74
+ cal.data('colorpicker').color = col = HexToHSB(fixHex(this.value));
75
+ } else if (this.parentNode.className.indexOf('_hsb') > 0) {
76
+ cal.data('colorpicker').color = col = fixHSB({
77
+ h: parseInt(cal.data('colorpicker').fields.eq(4).val(), 10),
78
+ s: parseInt(cal.data('colorpicker').fields.eq(5).val(), 10),
79
+ b: parseInt(cal.data('colorpicker').fields.eq(6).val(), 10)
80
+ });
81
+ } else {
82
+ cal.data('colorpicker').color = col = RGBToHSB(fixRGB({
83
+ r: parseInt(cal.data('colorpicker').fields.eq(1).val(), 10),
84
+ g: parseInt(cal.data('colorpicker').fields.eq(2).val(), 10),
85
+ b: parseInt(cal.data('colorpicker').fields.eq(3).val(), 10)
86
+ }));
87
+ }
88
+ if (ev) {
89
+ fillRGBFields(col, cal.get(0));
90
+ fillHexFields(col, cal.get(0));
91
+ fillHSBFields(col, cal.get(0));
92
+ }
93
+ setSelector(col, cal.get(0));
94
+ setHue(col, cal.get(0));
95
+ setNewColor(col, cal.get(0));
96
+ cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]);
97
+ },
98
+ blur = function (ev) {
99
+ var cal = $(this).parent().parent();
100
+ cal.data('colorpicker').fields.parent().removeClass('colorpicker_focus');
101
+ },
102
+ focus = function () {
103
+ charMin = this.parentNode.className.indexOf('_hex') > 0 ? 70 : 65;
104
+ $(this).parent().parent().data('colorpicker').fields.parent().removeClass('colorpicker_focus');
105
+ $(this).parent().addClass('colorpicker_focus');
106
+ },
107
+ downIncrement = function (ev) {
108
+ var field = $(this).parent().find('input').focus();
109
+ var current = {
110
+ el: $(this).parent().addClass('colorpicker_slider'),
111
+ max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
112
+ y: ev.pageY,
113
+ field: field,
114
+ val: parseInt(field.val(), 10),
115
+ preview: $(this).parent().parent().data('colorpicker').livePreview
116
+ };
117
+ $(document).bind('mouseup', current, upIncrement);
118
+ $(document).bind('mousemove', current, moveIncrement);
119
+ },
120
+ moveIncrement = function (ev) {
121
+ ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
122
+ if (ev.data.preview) {
123
+ change.apply(ev.data.field.get(0), [true]);
124
+ }
125
+ return false;
126
+ },
127
+ upIncrement = function (ev) {
128
+ change.apply(ev.data.field.get(0), [true]);
129
+ ev.data.el.removeClass('colorpicker_slider').find('input').focus();
130
+ $(document).unbind('mouseup', upIncrement);
131
+ $(document).unbind('mousemove', moveIncrement);
132
+ return false;
133
+ },
134
+ downHue = function (ev) {
135
+ var current = {
136
+ cal: $(this).parent(),
137
+ y: $(this).offset().top
138
+ };
139
+ current.preview = current.cal.data('colorpicker').livePreview;
140
+ $(document).bind('mouseup', current, upHue);
141
+ $(document).bind('mousemove', current, moveHue);
142
+ },
143
+ moveHue = function (ev) {
144
+ change.apply(
145
+ ev.data.cal.data('colorpicker')
146
+ .fields
147
+ .eq(4)
148
+ .val(parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10))
149
+ .get(0),
150
+ [ev.data.preview]
151
+ );
152
+ return false;
153
+ },
154
+ upHue = function (ev) {
155
+ fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
156
+ fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
157
+ $(document).unbind('mouseup', upHue);
158
+ $(document).unbind('mousemove', moveHue);
159
+ return false;
160
+ },
161
+ downSelector = function (ev) {
162
+ var current = {
163
+ cal: $(this).parent(),
164
+ pos: $(this).offset()
165
+ };
166
+ current.preview = current.cal.data('colorpicker').livePreview;
167
+ $(document).bind('mouseup', current, upSelector);
168
+ $(document).bind('mousemove', current, moveSelector);
169
+ },
170
+ moveSelector = function (ev) {
171
+ change.apply(
172
+ ev.data.cal.data('colorpicker')
173
+ .fields
174
+ .eq(6)
175
+ .val(parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10))
176
+ .end()
177
+ .eq(5)
178
+ .val(parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10))
179
+ .get(0),
180
+ [ev.data.preview]
181
+ );
182
+ return false;
183
+ },
184
+ upSelector = function (ev) {
185
+ fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
186
+ fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
187
+ $(document).unbind('mouseup', upSelector);
188
+ $(document).unbind('mousemove', moveSelector);
189
+ return false;
190
+ },
191
+ enterSubmit = function (ev) {
192
+ $(this).addClass('colorpicker_focus');
193
+ },
194
+ leaveSubmit = function (ev) {
195
+ $(this).removeClass('colorpicker_focus');
196
+ },
197
+ clickSubmit = function (ev) {
198
+ var cal = $(this).parent();
199
+ var col = cal.data('colorpicker').color;
200
+ cal.data('colorpicker').origColor = col;
201
+ setCurrentColor(col, cal.get(0));
202
+ cal.data('colorpicker').onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el);
203
+ },
204
+ show = function (ev) {
205
+ var cal = $('#' + $(this).data('colorpickerId'));
206
+ cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]);
207
+ var pos = $(this).offset();
208
+ var viewPort = getViewport();
209
+ var top = pos.top + this.offsetHeight;
210
+ var left = pos.left;
211
+ if (top + 176 > viewPort.t + viewPort.h) {
212
+ top -= this.offsetHeight + 176;
213
+ }
214
+ if (left + 356 > viewPort.l + viewPort.w) {
215
+ left -= 356;
216
+ }
217
+ cal.css({left: left + 'px', top: top + 'px'});
218
+ if (cal.data('colorpicker').onShow.apply(this, [cal.get(0)]) != false) {
219
+ cal.show();
220
+ }
221
+ $(document).bind('mousedown', {cal: cal}, hide);
222
+ return false;
223
+ },
224
+ hide = function (ev) {
225
+ if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
226
+ if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
227
+ ev.data.cal.hide();
228
+ }
229
+ $(document).unbind('mousedown', hide);
230
+ }
231
+ },
232
+ isChildOf = function(parentEl, el, container) {
233
+ if (parentEl == el) {
234
+ return true;
235
+ }
236
+ if (parentEl.contains) {
237
+ return parentEl.contains(el);
238
+ }
239
+ if ( parentEl.compareDocumentPosition ) {
240
+ return !!(parentEl.compareDocumentPosition(el) & 16);
241
+ }
242
+ var prEl = el.parentNode;
243
+ while(prEl && prEl != container) {
244
+ if (prEl == parentEl)
245
+ return true;
246
+ prEl = prEl.parentNode;
247
+ }
248
+ return false;
249
+ },
250
+ getViewport = function () {
251
+ var m = document.compatMode == 'CSS1Compat';
252
+ return {
253
+ l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
254
+ t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
255
+ w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
256
+ h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
257
+ };
258
+ },
259
+ fixHSB = function (hsb) {
260
+ return {
261
+ h: Math.min(360, Math.max(0, hsb.h)),
262
+ s: Math.min(100, Math.max(0, hsb.s)),
263
+ b: Math.min(100, Math.max(0, hsb.b))
264
+ };
265
+ },
266
+ fixRGB = function (rgb) {
267
+ return {
268
+ r: Math.min(255, Math.max(0, rgb.r)),
269
+ g: Math.min(255, Math.max(0, rgb.g)),
270
+ b: Math.min(255, Math.max(0, rgb.b))
271
+ };
272
+ },
273
+ fixHex = function (hex) {
274
+ var len = 6 - hex.length;
275
+ if (len > 0) {
276
+ var o = [];
277
+ for (var i=0; i<len; i++) {
278
+ o.push('0');
279
+ }
280
+ o.push(hex);
281
+ hex = o.join('');
282
+ }
283
+ return hex;
284
+ },
285
+ HexToRGB = function (hex) {
286
+ var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
287
+ return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
288
+ },
289
+ HexToHSB = function (hex) {
290
+ return RGBToHSB(HexToRGB(hex));
291
+ },
292
+ RGBToHSB = function (rgb) {
293
+ var hsb = {
294
+ h: 0,
295
+ s: 0,
296
+ b: 0
297
+ };
298
+ var min = Math.min(rgb.r, rgb.g, rgb.b);
299
+ var max = Math.max(rgb.r, rgb.g, rgb.b);
300
+ var delta = max - min;
301
+ hsb.b = max;
302
+ if (max != 0) {
303
+
304
+ }
305
+ hsb.s = max != 0 ? 255 * delta / max : 0;
306
+ if (hsb.s != 0) {
307
+ if (rgb.r == max) {
308
+ hsb.h = (rgb.g - rgb.b) / delta;
309
+ } else if (rgb.g == max) {
310
+ hsb.h = 2 + (rgb.b - rgb.r) / delta;
311
+ } else {
312
+ hsb.h = 4 + (rgb.r - rgb.g) / delta;
313
+ }
314
+ } else {
315
+ hsb.h = -1;
316
+ }
317
+ hsb.h *= 60;
318
+ if (hsb.h < 0) {
319
+ hsb.h += 360;
320
+ }
321
+ hsb.s *= 100/255;
322
+ hsb.b *= 100/255;
323
+ return hsb;
324
+ },
325
+ HSBToRGB = function (hsb) {
326
+ var rgb = {};
327
+ var h = Math.round(hsb.h);
328
+ var s = Math.round(hsb.s*255/100);
329
+ var v = Math.round(hsb.b*255/100);
330
+ if(s == 0) {
331
+ rgb.r = rgb.g = rgb.b = v;
332
+ } else {
333
+ var t1 = v;
334
+ var t2 = (255-s)*v/255;
335
+ var t3 = (t1-t2)*(h%60)/60;
336
+ if(h==360) h = 0;
337
+ if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
338
+ else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
339
+ else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
340
+ else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
341
+ else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
342
+ else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
343
+ else {rgb.r=0; rgb.g=0; rgb.b=0}
344
+ }
345
+ return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
346
+ },
347
+ RGBToHex = function (rgb) {
348
+ var hex = [
349
+ rgb.r.toString(16),
350
+ rgb.g.toString(16),
351
+ rgb.b.toString(16)
352
+ ];
353
+ $.each(hex, function (nr, val) {
354
+ if (val.length == 1) {
355
+ hex[nr] = '0' + val;
356
+ }
357
+ });
358
+ return hex.join('');
359
+ },
360
+ HSBToHex = function (hsb) {
361
+ return RGBToHex(HSBToRGB(hsb));
362
+ },
363
+ restoreOriginal = function () {
364
+ var cal = $(this).parent();
365
+ var col = cal.data('colorpicker').origColor;
366
+ cal.data('colorpicker').color = col;
367
+ fillRGBFields(col, cal.get(0));
368
+ fillHexFields(col, cal.get(0));
369
+ fillHSBFields(col, cal.get(0));
370
+ setSelector(col, cal.get(0));
371
+ setHue(col, cal.get(0));
372
+ setNewColor(col, cal.get(0));
373
+ };
374
+ return {
375
+ init: function (opt) {
376
+ opt = $.extend({}, defaults, opt||{});
377
+ if (typeof opt.color == 'string') {
378
+ opt.color = HexToHSB(opt.color);
379
+ } else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
380
+ opt.color = RGBToHSB(opt.color);
381
+ } else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
382
+ opt.color = fixHSB(opt.color);
383
+ } else {
384
+ return this;
385
+ }
386
+ return this.each(function () {
387
+ if (!$(this).data('colorpickerId')) {
388
+ var options = $.extend({}, opt);
389
+ options.origColor = opt.color;
390
+ var id = 'collorpicker_' + parseInt(Math.random() * 1000);
391
+ $(this).data('colorpickerId', id);
392
+ var cal = $(tpl).attr('id', id);
393
+ if (options.flat) {
394
+ cal.appendTo(this).show();
395
+ } else {
396
+ cal.appendTo(document.body);
397
+ }
398
+ options.fields = cal
399
+ .find('input')
400
+ .bind('keyup', keyDown)
401
+ .bind('change', change)
402
+ .bind('blur', blur)
403
+ .bind('focus', focus);
404
+ cal
405
+ .find('span').bind('mousedown', downIncrement).end()
406
+ .find('>div.colorpicker_current_color').bind('click', restoreOriginal);
407
+ options.selector = cal.find('div.colorpicker_color').bind('mousedown', downSelector);
408
+ options.selectorIndic = options.selector.find('div div');
409
+ options.el = this;
410
+ options.hue = cal.find('div.colorpicker_hue div');
411
+ cal.find('div.colorpicker_hue').bind('mousedown', downHue);
412
+ options.newColor = cal.find('div.colorpicker_new_color');
413
+ options.currentColor = cal.find('div.colorpicker_current_color');
414
+ cal.data('colorpicker', options);
415
+ cal.find('div.colorpicker_submit')
416
+ .bind('mouseenter', enterSubmit)
417
+ .bind('mouseleave', leaveSubmit)
418
+ .bind('click', clickSubmit);
419
+ fillRGBFields(options.color, cal.get(0));
420
+ fillHSBFields(options.color, cal.get(0));
421
+ fillHexFields(options.color, cal.get(0));
422
+ setHue(options.color, cal.get(0));
423
+ setSelector(options.color, cal.get(0));
424
+ setCurrentColor(options.color, cal.get(0));
425
+ setNewColor(options.color, cal.get(0));
426
+ if (options.flat) {
427
+ cal.css({
428
+ position: 'relative',
429
+ display: 'block'
430
+ });
431
+ } else {
432
+ $(this).bind(options.eventName, show);
433
+ }
434
+ }
435
+ });
436
+ },
437
+ showPicker: function() {
438
+ return this.each( function () {
439
+ if ($(this).data('colorpickerId')) {
440
+ show.apply(this);
441
+ }
442
+ });
443
+ },
444
+ hidePicker: function() {
445
+ return this.each( function () {
446
+ if ($(this).data('colorpickerId')) {
447
+ $('#' + $(this).data('colorpickerId')).hide();
448
+ }
449
+ });
450
+ },
451
+ setColor: function(col) {
452
+ if (typeof col == 'string') {
453
+ col = HexToHSB(col);
454
+ } else if (col.r != undefined && col.g != undefined && col.b != undefined) {
455
+ col = RGBToHSB(col);
456
+ } else if (col.h != undefined && col.s != undefined && col.b != undefined) {
457
+ col = fixHSB(col);
458
+ } else {
459
+ return this;
460
+ }
461
+ return this.each(function(){
462
+ if ($(this).data('colorpickerId')) {
463
+ var cal = $('#' + $(this).data('colorpickerId'));
464
+ cal.data('colorpicker').color = col;
465
+ cal.data('colorpicker').origColor = col;
466
+ fillRGBFields(col, cal.get(0));
467
+ fillHSBFields(col, cal.get(0));
468
+ fillHexFields(col, cal.get(0));
469
+ setHue(col, cal.get(0));
470
+ setSelector(col, cal.get(0));
471
+ setCurrentColor(col, cal.get(0));
472
+ setNewColor(col, cal.get(0));
473
+ }
474
+ });
475
+ }
476
+ };
477
+ }();
478
+ $.fn.extend({
479
+ ColorPicker: ColorPicker.init,
480
+ ColorPickerHide: ColorPicker.hidePicker,
481
+ ColorPickerShow: ColorPicker.showPicker,
482
+ ColorPickerSetColor: ColorPicker.setColor
483
+ });
484
+ })(jQuery)