adva-core 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (285) hide show
  1. data/app/controllers/admin/base_controller.rb +20 -0
  2. data/app/controllers/admin/pages_controller.rb +7 -0
  3. data/app/controllers/admin/sections_controller.rb +22 -0
  4. data/app/controllers/admin/sites_controller.rb +16 -0
  5. data/app/controllers/articles_controller.rb +3 -0
  6. data/app/controllers/base_controller.rb +18 -0
  7. data/app/controllers/installations_controller.rb +28 -0
  8. data/app/controllers/pages_controller.rb +2 -0
  9. data/app/controllers/sections_controller.rb +3 -0
  10. data/app/helpers/form_helper.rb +13 -0
  11. data/app/helpers/sections_helper.rb +7 -0
  12. data/app/helpers/url_helper.rb +18 -0
  13. data/app/models/account.rb +3 -0
  14. data/app/models/article.rb +2 -0
  15. data/app/models/content.rb +4 -0
  16. data/app/models/page.rb +9 -0
  17. data/app/models/section.rb +49 -0
  18. data/app/models/site.rb +24 -0
  19. data/app/views/admin/contents/_menu.html.rb +17 -0
  20. data/app/views/admin/pages/_menu.html.rb +10 -0
  21. data/app/views/admin/pages/new.html.rb +19 -0
  22. data/app/views/admin/pages/show.html.rb +25 -0
  23. data/app/views/admin/sections/_menu.html.rb +45 -0
  24. data/app/views/admin/sections/_section.html.rb +7 -0
  25. data/app/views/admin/sections/_select_type.html.rb +16 -0
  26. data/app/views/admin/sections/index.html.rb +28 -0
  27. data/app/views/admin/sites/_menu.html.rb +2 -0
  28. data/app/views/admin/sites/edit.html.rb +22 -0
  29. data/app/views/admin/sites/index.html.rb +24 -0
  30. data/app/views/admin/sites/new.html.rb +39 -0
  31. data/app/views/admin/sites/show.html.rb +7 -0
  32. data/app/views/installations/new.html.rb +39 -0
  33. data/app/views/installations/show.html.rb +9 -0
  34. data/app/views/layouts/admin.rb +55 -0
  35. data/app/views/layouts/admin/_header.rb +48 -0
  36. data/app/views/layouts/admin/_tabs.html.rb +18 -0
  37. data/app/views/layouts/admin/_top.rb +62 -0
  38. data/app/views/layouts/base.rb +64 -0
  39. data/app/views/layouts/default.rb +46 -0
  40. data/app/views/layouts/default/_menu.rb +19 -0
  41. data/app/views/layouts/simple.rb +16 -0
  42. data/app/views/pages/show.html.rb +7 -0
  43. data/config/initializers/simple_form.rb +53 -0
  44. data/config/locales/en.yml +129 -0
  45. data/config/redirects.rb +8 -0
  46. data/config/routes.rb +21 -0
  47. data/lib/adva-core.rb +1 -0
  48. data/lib/adva.rb +40 -0
  49. data/lib/adva/active_record/has_one_default.rb +40 -0
  50. data/lib/adva/active_record/has_options.rb +55 -0
  51. data/lib/adva/cli.rb +16 -0
  52. data/lib/adva/controller.rb +7 -0
  53. data/lib/adva/controller/abstract_actions.rb +92 -0
  54. data/lib/adva/controller/internal_redirect.rb +26 -0
  55. data/lib/adva/controller/references.rb +28 -0
  56. data/lib/adva/core.rb +94 -0
  57. data/lib/adva/engine.rb +44 -0
  58. data/lib/adva/generators.rb +8 -0
  59. data/lib/adva/generators/app.rb +121 -0
  60. data/lib/adva/generators/engine.rb +58 -0
  61. data/lib/adva/generators/gemfile.rb +50 -0
  62. data/lib/adva/generators/install.rb +31 -0
  63. data/lib/adva/generators/templates/app/app_template.rb +3 -0
  64. data/lib/adva/generators/templates/engine/Gemfile.erb +3 -0
  65. data/lib/adva/generators/templates/engine/all.rb +1 -0
  66. data/lib/adva/generators/templates/engine/en.yml.erb +2 -0
  67. data/lib/adva/generators/templates/engine/engine.rb.erb +11 -0
  68. data/lib/adva/generators/templates/engine/gemspec.erb +21 -0
  69. data/lib/adva/generators/templates/engine/migration.rb.erb +11 -0
  70. data/lib/adva/generators/templates/engine/redirects.rb.erb +3 -0
  71. data/lib/adva/generators/templates/engine/routes.rb.erb +3 -0
  72. data/lib/adva/generators/templates/engine/test_helper.rb.erb +3 -0
  73. data/lib/adva/rack.rb +5 -0
  74. data/lib/adva/rack/static.rb +50 -0
  75. data/lib/adva/registry.rb +62 -0
  76. data/lib/adva/responder.rb +21 -0
  77. data/lib/adva/responder/redirect.rb +31 -0
  78. data/lib/adva/routing_filters/section_path.rb +72 -0
  79. data/lib/adva/routing_filters/section_root.rb +65 -0
  80. data/lib/adva/tasks/core.rake +9 -0
  81. data/lib/adva/tasks/core.rb +160 -0
  82. data/lib/adva/testing.rb +58 -0
  83. data/lib/adva/testing/engine.rb +37 -0
  84. data/lib/adva/view.rb +7 -0
  85. data/lib/adva/view/form.rb +44 -0
  86. data/lib/adva/view/form/tabs.rb +46 -0
  87. data/lib/adva/view/helper/i18n.rb +10 -0
  88. data/lib/adva/view/menu.rb +73 -0
  89. data/lib/adva/view/menu/admin.rb +100 -0
  90. data/lib/adva/view/menu/items.rb +26 -0
  91. data/lib/adva/view/tabs.rb +28 -0
  92. data/lib/adva_core/version.rb +3 -0
  93. data/lib/core_ext/rails/action_view/has_many_through_collection_helpers.rb +27 -0
  94. data/lib/core_ext/rails/active_record/skip_callbacks.rb +51 -0
  95. data/lib/core_ext/ruby/array/flatten_once.rb +9 -0
  96. data/lib/core_ext/ruby/kernel/silence_stream.rb +17 -0
  97. data/lib/core_ext/ruby/module/include_anonymous.rb +36 -0
  98. data/lib/core_ext/ruby/module/option_reader.rb +9 -0
  99. data/lib/patches/inherited_resources.rb +35 -0
  100. data/lib/patches/rails/asset_expansion_multiple_registrations.rb +21 -0
  101. data/lib/patches/rails/integretion_runner_respond_to.rb +13 -0
  102. data/lib/patches/rails/polymorphic_url_for.rb +115 -0
  103. data/lib/patches/rails/recognize_path_env.rb +42 -0
  104. data/lib/patches/rails/route_set_to_param.rb +25 -0
  105. data/lib/patches/rails/route_set_trailing_segment.rb +13 -0
  106. data/lib/patches/rails/sti_associations.rb +17 -0
  107. data/lib/patches/rails/template_resolver_caching.rb +9 -0
  108. data/lib/patches/rails/translation_helper.rb +18 -0
  109. data/lib/patches/responders/flash_responder.rb +17 -0
  110. data/lib/patches/simple_form.rb +37 -0
  111. data/lib/patches/thor/core_ext/hash.rb +7 -0
  112. data/lib/patches/thor/group/symbolized_options.rb +8 -0
  113. data/lib/patches/webrat/links-data-method.rb +15 -0
  114. data/lib/patches/webrat/logger.rb +14 -0
  115. data/lib/patches/webrat/upload_file.rb +23 -0
  116. data/lib/testing/assertions.rb +19 -0
  117. data/lib/testing/env.rb +41 -0
  118. data/lib/testing/factories.rb +28 -0
  119. data/lib/testing/helpers/global_helpers.rb +9 -0
  120. data/lib/testing/paths.rb +54 -0
  121. data/lib/testing/step_definitions/common_steps.rb +287 -0
  122. data/lib/testing/step_definitions/debug_steps.rb +22 -0
  123. data/lib/testing/step_definitions/menu_steps.rb +11 -0
  124. data/lib/testing/step_definitions/routes_steps.rb +18 -0
  125. data/lib/testing/step_definitions/transforms.rb +50 -0
  126. data/lib/testing/step_definitions/webrat_steps.rb +284 -0
  127. data/lib/testing/step_definitions/within_steps.rb +16 -0
  128. data/lib/webrat/integrations/rails.rb +33 -0
  129. data/public/images/adva-core/admin/header_bg.png +0 -0
  130. data/public/images/adva-core/admin/menu_checkmark.png +0 -0
  131. data/public/images/adva-core/admin/section_menu_bg.png +0 -0
  132. data/public/images/adva-core/admin/tab_action_active.png +0 -0
  133. data/public/images/adva-core/admin/tab_main_active.png +0 -0
  134. data/public/images/adva-core/admin/tab_sidebar_active.png +0 -0
  135. data/public/images/adva-core/admin/tab_top_active.png +0 -0
  136. data/public/images/adva-core/asset_selected.png +0 -0
  137. data/public/images/adva-core/avatar.gif +0 -0
  138. data/public/images/adva-core/feed.mini.png +0 -0
  139. data/public/images/adva-core/filter-bg.png +0 -0
  140. data/public/images/adva-core/grid.png +0 -0
  141. data/public/images/adva-core/icons/accept.png +0 -0
  142. data/public/images/adva-core/icons/add.png +0 -0
  143. data/public/images/adva-core/icons/arrow_cross.png +0 -0
  144. data/public/images/adva-core/icons/arrow_cross_2.png +0 -0
  145. data/public/images/adva-core/icons/arrow_cross_3.png +0 -0
  146. data/public/images/adva-core/icons/arrow_up_down.png +0 -0
  147. data/public/images/adva-core/icons/assets/audio.png +0 -0
  148. data/public/images/adva-core/icons/assets/doc.png +0 -0
  149. data/public/images/adva-core/icons/assets/pdf.png +0 -0
  150. data/public/images/adva-core/icons/assets/video.png +0 -0
  151. data/public/images/adva-core/icons/attach.png +0 -0
  152. data/public/images/adva-core/icons/bin.png +0 -0
  153. data/public/images/adva-core/icons/bin_closed.png +0 -0
  154. data/public/images/adva-core/icons/bin_empty.png +0 -0
  155. data/public/images/adva-core/icons/bullet_black.png +0 -0
  156. data/public/images/adva-core/icons/bullet_delete.png +0 -0
  157. data/public/images/adva-core/icons/bullet_error.png +0 -0
  158. data/public/images/adva-core/icons/bullet_go.png +0 -0
  159. data/public/images/adva-core/icons/bullet_red.png +0 -0
  160. data/public/images/adva-core/icons/bullet_white.png +0 -0
  161. data/public/images/adva-core/icons/bullet_yellow.png +0 -0
  162. data/public/images/adva-core/icons/cancel.png +0 -0
  163. data/public/images/adva-core/icons/comment.gif +0 -0
  164. data/public/images/adva-core/icons/comment.png +0 -0
  165. data/public/images/adva-core/icons/comment_add.png +0 -0
  166. data/public/images/adva-core/icons/comment_blue.gif +0 -0
  167. data/public/images/adva-core/icons/comment_delete.png +0 -0
  168. data/public/images/adva-core/icons/comment_edit.png +0 -0
  169. data/public/images/adva-core/icons/comment_yellow.gif +0 -0
  170. data/public/images/adva-core/icons/cross.png +0 -0
  171. data/public/images/adva-core/icons/delete.png +0 -0
  172. data/public/images/adva-core/icons/eye.png +0 -0
  173. data/public/images/adva-core/icons/favorites.png +0 -0
  174. data/public/images/adva-core/icons/help.png +0 -0
  175. data/public/images/adva-core/icons/hourglass.png +0 -0
  176. data/public/images/adva-core/icons/icon_attachment.gif +0 -0
  177. data/public/images/adva-core/icons/icon_padlock.gif +0 -0
  178. data/public/images/adva-core/icons/link.png +0 -0
  179. data/public/images/adva-core/icons/lock.png +0 -0
  180. data/public/images/adva-core/icons/magnifier.png +0 -0
  181. data/public/images/adva-core/icons/minus.gif +0 -0
  182. data/public/images/adva-core/icons/page_add.png +0 -0
  183. data/public/images/adva-core/icons/page_delete.png +0 -0
  184. data/public/images/adva-core/icons/page_edit.png +0 -0
  185. data/public/images/adva-core/icons/page_favorites.png +0 -0
  186. data/public/images/adva-core/icons/page_go.png +0 -0
  187. data/public/images/adva-core/icons/page_green.png +0 -0
  188. data/public/images/adva-core/icons/page_red.png +0 -0
  189. data/public/images/adva-core/icons/page_white_add.png +0 -0
  190. data/public/images/adva-core/icons/page_white_delete.png +0 -0
  191. data/public/images/adva-core/icons/page_white_edit.png +0 -0
  192. data/public/images/adva-core/icons/page_white_go.png +0 -0
  193. data/public/images/adva-core/icons/page_white_link.png +0 -0
  194. data/public/images/adva-core/icons/page_white_magnify.png +0 -0
  195. data/public/images/adva-core/icons/pencil.png +0 -0
  196. data/public/images/adva-core/icons/star.png +0 -0
  197. data/public/images/adva-core/icons/stop.png +0 -0
  198. data/public/images/adva-core/icons/tag_green.png +0 -0
  199. data/public/images/adva-core/icons/tick.png +0 -0
  200. data/public/images/adva-core/icons/zoom.png +0 -0
  201. data/public/images/adva-core/indicator.gif +0 -0
  202. data/public/images/adva-core/lines.png +0 -0
  203. data/public/images/adva-core/preview.png +0 -0
  204. data/public/images/adva-core/theme_selected.png +0 -0
  205. data/public/javascripts/adva-core/admin.js +22 -0
  206. data/public/javascripts/adva-core/jquery/jquery-1.4.2.min.js +154 -0
  207. data/public/javascripts/adva-core/jquery/jquery.table_tree.js +296 -0
  208. data/public/javascripts/adva-core/jquery/jquery.tablednd_0_5.js +385 -0
  209. data/public/javascripts/adva-core/rails.js +127 -0
  210. data/public/javascripts/backup/admin/jquery.admin.js +75 -0
  211. data/public/javascripts/backup/admin/jquery.article.js +22 -0
  212. data/public/javascripts/backup/admin/jquery.cached_pages.js +14 -0
  213. data/public/javascripts/backup/admin/jquery.table_tree.backup.js +279 -0
  214. data/public/javascripts/backup/admin/jquery.table_tree.js +10 -0
  215. data/public/javascripts/backup/application.js +38 -0
  216. data/public/javascripts/backup/application.prototype.js +135 -0
  217. data/public/javascripts/backup/builder.js +136 -0
  218. data/public/javascripts/backup/controls.js +965 -0
  219. data/public/javascripts/backup/cookie.js +49 -0
  220. data/public/javascripts/backup/dragdrop.js +975 -0
  221. data/public/javascripts/backup/effects.js +1130 -0
  222. data/public/javascripts/backup/flash.js +49 -0
  223. data/public/javascripts/backup/jquery.dates.js +49 -0
  224. data/public/javascripts/backup/jquery.flash.js +40 -0
  225. data/public/javascripts/backup/jquery.roles.js +23 -0
  226. data/public/javascripts/backup/jquery/jquery-lowpro.js +224 -0
  227. data/public/javascripts/backup/jquery/jquery-ui.js +273 -0
  228. data/public/javascripts/backup/jquery/jquery.js +19 -0
  229. data/public/javascripts/backup/jquery/jquery.qtip.min.js +15 -0
  230. data/public/javascripts/backup/json.js +139 -0
  231. data/public/javascripts/backup/lowpro.js +320 -0
  232. data/public/javascripts/backup/parseuri.js +39 -0
  233. data/public/javascripts/backup/prototype.js +4320 -0
  234. data/public/javascripts/backup/roles.js +16 -0
  235. data/public/javascripts/backup/scriptaculous.js +60 -0
  236. data/public/javascripts/backup/slider.js +275 -0
  237. data/public/javascripts/backup/sound.js +55 -0
  238. data/public/javascripts/backup/unittest.js +568 -0
  239. data/public/stylesheets/adva-core/admin/forms.css +172 -0
  240. data/public/stylesheets/adva-core/admin/layout.css +38 -0
  241. data/public/stylesheets/adva-core/admin/lists.css +54 -0
  242. data/public/stylesheets/adva-core/admin/navigation.css +234 -0
  243. data/public/stylesheets/adva-core/admin/sidebar.css +87 -0
  244. data/public/stylesheets/adva-core/admin/styles.css +130 -0
  245. data/public/stylesheets/adva-core/common/forms.css +174 -0
  246. data/public/stylesheets/adva-core/common/layout.css +93 -0
  247. data/public/stylesheets/adva-core/common/reset.css +42 -0
  248. data/public/stylesheets/adva-core/common/styles.css +41 -0
  249. data/public/stylesheets/adva-core/default/layout.css +0 -0
  250. data/public/stylesheets/adva-core/default/styles.css +0 -0
  251. data/public/stylesheets/adva-core/simple/layout.css +11 -0
  252. data/public/stylesheets/backup/alternate/common.css +76 -0
  253. data/public/stylesheets/backup/alternate/forms.css +121 -0
  254. data/public/stylesheets/backup/alternate/header.css +125 -0
  255. data/public/stylesheets/backup/alternate/layout.css +103 -0
  256. data/public/stylesheets/backup/alternate/lists.css +153 -0
  257. data/public/stylesheets/backup/alternate/sidebar.css +65 -0
  258. data/public/stylesheets/backup/alternate/top.css +123 -0
  259. data/public/stylesheets/backup/content.css +11 -0
  260. data/public/stylesheets/backup/helptip.css +35 -0
  261. data/public/stylesheets/backup/jquery/alternate/jquery.tooltip.css +13 -0
  262. data/public/stylesheets/backup/jquery/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  263. data/public/stylesheets/backup/jquery/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  264. data/public/stylesheets/backup/jquery/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  265. data/public/stylesheets/backup/jquery/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  266. data/public/stylesheets/backup/jquery/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  267. data/public/stylesheets/backup/jquery/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  268. data/public/stylesheets/backup/jquery/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  269. data/public/stylesheets/backup/jquery/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  270. data/public/stylesheets/backup/jquery/images/ui-icons_222222_256x240.png +0 -0
  271. data/public/stylesheets/backup/jquery/images/ui-icons_2e83ff_256x240.png +0 -0
  272. data/public/stylesheets/backup/jquery/images/ui-icons_454545_256x240.png +0 -0
  273. data/public/stylesheets/backup/jquery/images/ui-icons_888888_256x240.png +0 -0
  274. data/public/stylesheets/backup/jquery/images/ui-icons_cd0a0a_256x240.png +0 -0
  275. data/public/stylesheets/backup/jquery/jquery-ui.css +405 -0
  276. data/public/stylesheets/backup/jquery/jquery.tooltip.css +10 -0
  277. data/public/stylesheets/backup/layout.css +22 -0
  278. data/public/stylesheets/backup/lists.css +17 -0
  279. data/public/stylesheets/backup/menu.css +129 -0
  280. data/public/stylesheets/backup/projection.css +118 -0
  281. data/public/stylesheets/backup/screen/top.css +8 -0
  282. data/public/stylesheets/backup/themes.css +49 -0
  283. data/public/stylesheets/backup/users.css +40 -0
  284. metadata +338 -40
  285. data/lib/bundler/repository.rb +0 -118
@@ -0,0 +1,385 @@
1
+ /**
2
+ * TableDnD plug-in for JQuery, allows you to drag and drop table rows
3
+ * You can set up various options to control how the system will work
4
+ * Copyright (c) Denis Howlett <denish@isocra.com>
5
+ * Licensed like jQuery, see http://docs.jquery.com/License.
6
+ *
7
+ * Configuration options:
8
+ *
9
+ * onDragStyle
10
+ * This is the style that is assigned to the row during drag. There are limitations to the styles that can be
11
+ * associated with a row (such as you can't assign a border--well you can, but it won't be
12
+ * displayed). (So instead consider using onDragClass.) The CSS style to apply is specified as
13
+ * a map (as used in the jQuery css(...) function).
14
+ * onDropStyle
15
+ * This is the style that is assigned to the row when it is dropped. As for onDragStyle, there are limitations
16
+ * to what you can do. Also this replaces the original style, so again consider using onDragClass which
17
+ * is simply added and then removed on drop.
18
+ * onDragClass
19
+ * This class is added for the duration of the drag and then removed when the row is dropped. It is more
20
+ * flexible than using onDragStyle since it can be inherited by the row cells and other content. The default
21
+ * is class is tDnD_whileDrag. So to use the default, simply customise this CSS class in your
22
+ * stylesheet.
23
+ * onDrop
24
+ * Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table
25
+ * and the row that was dropped. You can work out the new order of the rows by using
26
+ * table.rows.
27
+ * onDragStart
28
+ * Pass a function that will be called when the user starts dragging. The function takes 2 parameters: the
29
+ * table and the row which the user has started to drag.
30
+ * onAllowDrop
31
+ * Pass a function that will be called as a row is over another row. If the function returns true, allow
32
+ * dropping on that row, otherwise not. The function takes 2 parameters: the dragged row and the row under
33
+ * the cursor. It returns a boolean: true allows the drop, false doesn't allow it.
34
+ * scrollAmount
35
+ * This is the number of pixels to scroll if the user moves the mouse cursor to the top or bottom of the
36
+ * window. The page should automatically scroll up or down as appropriate (tested in IE6, IE7, Safari, FF2,
37
+ * FF3 beta
38
+ * dragHandle
39
+ * This is the name of a class that you assign to one or more cells in each row that is draggable. If you
40
+ * specify this class, then you are responsible for setting cursor: move in the CSS and only these cells
41
+ * will have the drag behaviour. If you do not specify a dragHandle, then you get the old behaviour where
42
+ * the whole row is draggable.
43
+ *
44
+ * Other ways to control behaviour:
45
+ *
46
+ * Add class="nodrop" to any rows for which you don't want to allow dropping, and class="nodrag" to any rows
47
+ * that you don't want to be draggable.
48
+ *
49
+ * Inside the onDrop method you can also call $.tableDnD.serialize() this returns a string of the form
50
+ * <tableID>[]=<rowID1>&<tableID>[]=<rowID2> so that you can send this back to the server. The table must have
51
+ * an ID as must all the rows.
52
+ *
53
+ * Other methods:
54
+ *
55
+ * $("...").tableDnDUpdate()
56
+ * Will update all the matching tables, that is it will reapply the mousedown method to the rows (or handle cells).
57
+ * This is useful if you have updated the table rows using Ajax and you want to make the table draggable again.
58
+ * The table maintains the original configuration (so you don't have to specify it again).
59
+ *
60
+ * $("...").tableDnDSerialize()
61
+ * Will serialize and return the serialized string as above, but for each of the matching tables--so it can be
62
+ * called from anywhere and isn't dependent on the currentTable being set up correctly before calling
63
+ *
64
+ * Known problems:
65
+ * - Auto-scoll has some problems with IE7 (it scrolls even when it shouldn't), work-around: set scrollAmount to 0
66
+ *
67
+ * Version 0.2: 2008-02-20 First public version
68
+ * Version 0.3: 2008-02-07 Added onDragStart option
69
+ * Made the scroll amount configurable (default is 5 as before)
70
+ * Version 0.4: 2008-03-15 Changed the noDrag/noDrop attributes to nodrag/nodrop classes
71
+ * Added onAllowDrop to control dropping
72
+ * Fixed a bug which meant that you couldn't set the scroll amount in both directions
73
+ * Added serialize method
74
+ * Version 0.5: 2008-05-16 Changed so that if you specify a dragHandle class it doesn't make the whole row
75
+ * draggable
76
+ * Improved the serialize method to use a default (and settable) regular expression.
77
+ * Added tableDnDupate() and tableDnDSerialize() to be called when you are outside the table
78
+ */
79
+ jQuery.tableDnD = {
80
+ /** Keep hold of the current table being dragged */
81
+ currentTable : null,
82
+ /** Keep hold of the current drag object if any */
83
+ dragObject: null,
84
+ /** The current mouse offset */
85
+ mouseOffset: null,
86
+ /** Remember the old value of Y so that we don't do too much processing */
87
+ oldY: 0,
88
+
89
+ /** Actually build the structure */
90
+ build: function(options) {
91
+ // Set up the defaults if any
92
+
93
+ this.each(function() {
94
+ // This is bound to each matching table, set up the defaults and override with user options
95
+ this.tableDnDConfig = $.extend({
96
+ onDragStyle: null,
97
+ onDropStyle: null,
98
+ // Add in the default class for whileDragging
99
+ onDragClass: "tDnD_whileDrag",
100
+ onDrop: null,
101
+ onDrag: null, // ADDED
102
+ onDragStart: null,
103
+ scrollAmount: 5,
104
+ serializeRegexp: /[^\-]*$/, // The regular expression to use to trim row IDs
105
+ serializeParamName: null, // If you want to specify another parameter name instead of the table ID
106
+ dragHandle: null // If you give the name of a class here, then only Cells with this class will be draggable
107
+ }, options || {});
108
+ // Now make the rows draggable
109
+ jQuery.tableDnD.makeDraggable(this);
110
+ });
111
+
112
+ // Now we need to capture the mouse up and mouse move event
113
+ // We can use bind so that we don't interfere with other event handlers
114
+ jQuery(document)
115
+ .bind('mousemove', jQuery.tableDnD.mousemove)
116
+ .bind('mouseup', jQuery.tableDnD.mouseup);
117
+
118
+ // Don't break the chain
119
+ return this;
120
+ },
121
+
122
+ /** This function makes all the rows on the table draggable apart from those marked as "NoDrag" */
123
+ makeDraggable: function(table) {
124
+ var config = table.tableDnDConfig;
125
+ if (table.tableDnDConfig.dragHandle) {
126
+ // We only need to add the event to the specified cells
127
+ var cells = $("td."+table.tableDnDConfig.dragHandle, table);
128
+ cells.each(function() {
129
+ // The cell is bound to "this"
130
+ jQuery(this).mousedown(function(ev) {
131
+ jQuery.tableDnD.dragObject = this.parentNode;
132
+ jQuery.tableDnD.currentTable = table;
133
+ jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
134
+ if (config.onDragStart) {
135
+ // Call the onDrop method if there is one
136
+ config.onDragStart(table, this);
137
+ }
138
+ return false;
139
+ });
140
+ })
141
+ } else {
142
+ // For backwards compatibility, we add the event to the whole row
143
+ var rows = jQuery("tr", table); // get all the rows as a wrapped set
144
+ rows.each(function() {
145
+ // Iterate through each row, the row is bound to "this"
146
+ var row = $(this);
147
+ if (! row.hasClass("nodrag")) {
148
+ row.mousedown(function(ev) {
149
+ if (ev.target.tagName == "TD") {
150
+ jQuery.tableDnD.dragObject = this;
151
+ jQuery.tableDnD.currentTable = table;
152
+ jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
153
+ if (config.onDragStart) {
154
+ // Call the onDrop method if there is one
155
+ config.onDragStart(table, this);
156
+ }
157
+ return false;
158
+ }
159
+ }).css("cursor", "move"); // Store the tableDnD object
160
+ }
161
+ });
162
+ }
163
+ },
164
+
165
+ updateTables: function() {
166
+ this.each(function() {
167
+ // this is now bound to each matching table
168
+ if (this.tableDnDConfig) {
169
+ jQuery.tableDnD.makeDraggable(this);
170
+ }
171
+ })
172
+ },
173
+
174
+ /** Get the mouse coordinates from the event (allowing for browser differences) */
175
+ mouseCoords: function(ev){
176
+ if(ev.pageX || ev.pageY){
177
+ return {x:ev.pageX, y:ev.pageY};
178
+ }
179
+ return {
180
+ x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
181
+ y:ev.clientY + document.body.scrollTop - document.body.clientTop
182
+ };
183
+ },
184
+
185
+ /** Given a target element and a mouse event, get the mouse offset from that element.
186
+ To do this we need the element's position and the mouse position */
187
+ getMouseOffset: function(target, ev) {
188
+ ev = ev || window.event;
189
+
190
+ var docPos = this.getPosition(target);
191
+ var mousePos = this.mouseCoords(ev);
192
+ return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
193
+ },
194
+
195
+ /** Get the position of an element by going up the DOM tree and adding up all the offsets */
196
+ getPosition: function(e){
197
+ var left = 0;
198
+ var top = 0;
199
+ /** Safari fix -- thanks to Luis Chato for this! */
200
+ if (e.offsetHeight == 0) {
201
+ /** Safari 2 doesn't correctly grab the offsetTop of a table row
202
+ this is detailed here:
203
+ http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari/
204
+ the solution is likewise noted there, grab the offset of a table cell in the row - the firstChild.
205
+ note that firefox will return a text node as a first child, so designing a more thorough
206
+ solution may need to take that into account, for now this seems to work in firefox, safari, ie */
207
+ e = e.firstChild; // a table cell
208
+ }
209
+
210
+ while (e.offsetParent){
211
+ left += e.offsetLeft;
212
+ top += e.offsetTop;
213
+ e = e.offsetParent;
214
+ }
215
+
216
+ left += e.offsetLeft;
217
+ top += e.offsetTop;
218
+
219
+ return {x:left, y:top};
220
+ },
221
+
222
+ mousemove: function(ev) {
223
+ if (jQuery.tableDnD.dragObject == null) {
224
+ return;
225
+ }
226
+
227
+ var dragObj = jQuery(jQuery.tableDnD.dragObject);
228
+ var config = jQuery.tableDnD.currentTable.tableDnDConfig;
229
+ var mousePos = jQuery.tableDnD.mouseCoords(ev);
230
+ var y = mousePos.y - jQuery.tableDnD.mouseOffset.y;
231
+ //auto scroll the window
232
+ var yOffset = window.pageYOffset;
233
+ if (document.all) {
234
+ // Windows version
235
+ //yOffset=document.body.scrollTop;
236
+ if (typeof document.compatMode != 'undefined' &&
237
+ document.compatMode != 'BackCompat') {
238
+ yOffset = document.documentElement.scrollTop;
239
+ }
240
+ else if (typeof document.body != 'undefined') {
241
+ yOffset=document.body.scrollTop;
242
+ }
243
+
244
+ }
245
+
246
+ if (mousePos.y-yOffset < config.scrollAmount) {
247
+ window.scrollBy(0, -config.scrollAmount);
248
+ } else {
249
+ var windowHeight = window.innerHeight ? window.innerHeight
250
+ : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
251
+ if (windowHeight-(mousePos.y-yOffset) < config.scrollAmount) {
252
+ window.scrollBy(0, config.scrollAmount);
253
+ }
254
+ }
255
+
256
+
257
+ if (y != jQuery.tableDnD.oldY) {
258
+ // work out if we're going up or down...
259
+ var movingDown = y > jQuery.tableDnD.oldY;
260
+ // update the old value
261
+ jQuery.tableDnD.oldY = y;
262
+ // update the style to show we're dragging
263
+ if (config.onDragClass) {
264
+ dragObj.addClass(config.onDragClass);
265
+ } else {
266
+ dragObj.css(config.onDragStyle);
267
+ }
268
+ // If we're over a row then move the dragged row to there so that the user sees the
269
+ // effect dynamically
270
+ var currentRow = jQuery.tableDnD.findDropTargetRow(dragObj, y, movingDown);
271
+ if (currentRow) {
272
+ if (movingDown && jQuery.tableDnD.dragObject != currentRow) {
273
+ jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);
274
+ } else if (! movingDown && jQuery.tableDnD.dragObject != currentRow) {
275
+ jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);
276
+ }
277
+ if (config.onDrag) {
278
+ config.onDrag(jQuery.tableDnD.currentTable, jQuery.tableDnD.dragObject);
279
+ }
280
+ }
281
+ }
282
+
283
+ return false;
284
+ },
285
+
286
+ /** We're only worried about the y position really, because we can only move rows up and down */
287
+ findDropTargetRow: function(draggedRow, y, movingDown) {
288
+ var rows = jQuery.tableDnD.currentTable.rows;
289
+ for (var i=0; i<rows.length; i++) {
290
+ var row = rows[i];
291
+ var rowY = this.getPosition(row).y;
292
+ var rowHeight = parseInt(row.offsetHeight)/2;
293
+ if (row.offsetHeight == 0) {
294
+ rowY = this.getPosition(row.firstChild).y;
295
+ rowHeight = parseInt(row.firstChild.offsetHeight)/2;
296
+ }
297
+ // Because we always have to insert before, we need to offset the height a bit
298
+ if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
299
+ // that's the row we're over
300
+ // If it's the same as the current row, ignore it
301
+ if (row == draggedRow.get(0)) {return null;}
302
+ var config = jQuery.tableDnD.currentTable.tableDnDConfig;
303
+ if (config.onAllowDrop) {
304
+ if (config.onAllowDrop(draggedRow, row, movingDown)) {
305
+ return row;
306
+ } else {
307
+ return null;
308
+ }
309
+ } else {
310
+ // If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)
311
+ var nodrop = $(row).hasClass("nodrop");
312
+ if (! nodrop) {
313
+ return row;
314
+ } else {
315
+ return null;
316
+ }
317
+ }
318
+ return row;
319
+ }
320
+ }
321
+ return null;
322
+ },
323
+
324
+ mouseup: function(e) {
325
+ if (jQuery.tableDnD.currentTable && jQuery.tableDnD.dragObject) {
326
+ var droppedRow = jQuery.tableDnD.dragObject;
327
+ var config = jQuery.tableDnD.currentTable.tableDnDConfig;
328
+ // If we have a dragObject, then we need to release it,
329
+ // The row will already have been moved to the right place so we just reset stuff
330
+ if (config.onDragClass) {
331
+ jQuery(droppedRow).removeClass(config.onDragClass);
332
+ } else {
333
+ jQuery(droppedRow).css(config.onDropStyle);
334
+ }
335
+ jQuery.tableDnD.dragObject = null;
336
+ if (config.onDrop) {
337
+ // Call the onDrop method if there is one
338
+ config.onDrop(jQuery.tableDnD.currentTable, droppedRow);
339
+ }
340
+ jQuery.tableDnD.currentTable = null; // let go of the table too
341
+ }
342
+ },
343
+
344
+ serialize: function() {
345
+ if (jQuery.tableDnD.currentTable) {
346
+ return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);
347
+ } else {
348
+ return "Error: No Table id set, you need to set an id on your table and every row";
349
+ }
350
+ },
351
+
352
+ serializeTable: function(table) {
353
+ var result = "";
354
+ var tableId = table.id;
355
+ var rows = table.rows;
356
+ for (var i=0; i<rows.length; i++) {
357
+ if (result.length > 0) result += "&";
358
+ var rowId = rows[i].id;
359
+ if (rowId && rowId && table.tableDnDConfig && table.tableDnDConfig.serializeRegexp) {
360
+ rowId = rowId.match(table.tableDnDConfig.serializeRegexp)[0];
361
+ }
362
+
363
+ result += tableId + '[]=' + rows[i].id;
364
+ }
365
+ return result;
366
+ },
367
+
368
+ serializeTables: function() {
369
+ var result = "";
370
+ this.each(function() {
371
+ // this is now bound to each matching table
372
+ result += jQuery.tableDnD.serializeTable(this);
373
+ });
374
+ return result;
375
+ }
376
+
377
+ }
378
+
379
+ jQuery.fn.extend(
380
+ {
381
+ tableDnD : jQuery.tableDnD.build,
382
+ tableDnDUpdate : jQuery.tableDnD.updateTables,
383
+ tableDnDSerialize: jQuery.tableDnD.serializeTables
384
+ }
385
+ );
@@ -0,0 +1,127 @@
1
+ jQuery(function ($) {
2
+ var csrf_token = $('meta[name=csrf-token]').attr('content'),
3
+ csrf_param = $('meta[name=csrf-param]').attr('content');
4
+
5
+ $.fn.extend({
6
+ /**
7
+ * Triggers a custom event on an element and returns the event result
8
+ * this is used to get around not being able to ensure callbacks are placed
9
+ * at the end of the chain.
10
+ *
11
+ * deprecate with jQuery 1.4.2 release, in favor of subscribing to our
12
+ * own events and placing ourselves at the end of the chain.
13
+ */
14
+ triggerAndReturn: function (name, data) {
15
+ var event = new $.Event(name);
16
+ this.trigger(event, data);
17
+
18
+ return event.result !== false;
19
+ },
20
+
21
+ /**
22
+ * Handles execution of remote calls firing overridable events along the way
23
+ */
24
+ callRemote: function () {
25
+ var el = this,
26
+ method = el.attr('method') || el.attr('data-method') || 'GET',
27
+ url = el.attr('action') || el.attr('href'),
28
+ dataType = el.attr('data-type') || 'script';
29
+
30
+ if (url === undefined) {
31
+ throw "No URL specified for remote call (action or href must be present).";
32
+ } else {
33
+ if (el.triggerAndReturn('ajax:before')) {
34
+ var data = el.is('form') ? el.serializeArray() : [];
35
+ $.ajax({
36
+ url: url,
37
+ data: data,
38
+ dataType: dataType,
39
+ type: method.toUpperCase(),
40
+ beforeSend: function (xhr) {
41
+ el.trigger('ajax:loading', xhr);
42
+ },
43
+ success: function (data, status, xhr) {
44
+ el.trigger('ajax:success', [data, status, xhr]);
45
+ },
46
+ complete: function (xhr) {
47
+ el.trigger('ajax:complete', xhr);
48
+ },
49
+ error: function (xhr, status, error) {
50
+ el.trigger('ajax:failure', [xhr, status, error]);
51
+ }
52
+ });
53
+ }
54
+
55
+ el.trigger('ajax:after');
56
+ }
57
+ }
58
+ });
59
+
60
+ /**
61
+ * confirmation handler
62
+ */
63
+ $('a[data-confirm],input[data-confirm]').live('click', function () {
64
+ var el = $(this);
65
+ if (el.triggerAndReturn('confirm')) {
66
+ if (!confirm(el.attr('data-confirm'))) {
67
+ return false;
68
+ }
69
+ }
70
+ });
71
+
72
+
73
+ /**
74
+ * remote handlers
75
+ */
76
+ $('form[data-remote]').live('submit', function (e) {
77
+ $(this).callRemote();
78
+ e.preventDefault();
79
+ });
80
+
81
+ $('a[data-remote],input[data-remote]').live('click', function (e) {
82
+ $(this).callRemote();
83
+ e.preventDefault();
84
+ });
85
+
86
+ $('a[data-method]:not([data-remote])').live('click', function (e){
87
+ var link = $(this),
88
+ href = link.attr('href'),
89
+ method = link.attr('data-method'),
90
+ form = $('<form method="post" action="'+href+'"></form>'),
91
+ metadata_input = '<input name="_method" value="'+method+'" type="hidden" />';
92
+
93
+ if (csrf_param != null && csrf_token != null) {
94
+ metadata_input += '<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />';
95
+ }
96
+
97
+ form.hide()
98
+ .append(metadata_input)
99
+ .appendTo('body');
100
+
101
+ e.preventDefault();
102
+ form.submit();
103
+ });
104
+
105
+ /**
106
+ * disable-with handlers
107
+ */
108
+ var disable_with_input_selector = 'input[data-disable-with]';
109
+ var disable_with_form_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
110
+
111
+ $(disable_with_form_selector).live('ajax:before', function () {
112
+ $(this).find(disable_with_input_selector).each(function () {
113
+ var input = $(this);
114
+ input.data('enable-with', input.val())
115
+ .attr('value', input.attr('data-disable-with'))
116
+ .attr('disabled', 'disabled');
117
+ });
118
+ });
119
+
120
+ $(disable_with_form_selector).live('ajax:complete', function () {
121
+ $(this).find(disable_with_input_selector).each(function () {
122
+ var input = $(this);
123
+ input.removeAttr('disabled')
124
+ .val(input.data('enable-with'));
125
+ });
126
+ });
127
+ });