adva 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/adva.gemspec +3 -0
  3. data/app/assets/config/manifest.js +6 -0
  4. data/app/assets/javascripts/adva_cms/ckeditor.js.erb +12 -0
  5. data/app/assets/javascripts/adva_cms/concat_main_menus.js +13 -0
  6. data/app/assets/javascripts/adva_cms/jquery.table_tree.js +704 -0
  7. data/app/assets/javascripts/adva_cms.js +7 -0
  8. data/app/assets/javascripts/ckeditor/config.js.erb +94 -0
  9. data/app/assets/stylesheets/adva_cms/admin/common.scss +15 -1
  10. data/app/assets/stylesheets/adva_cms/admin/projection.scss +2 -5
  11. data/app/assets/stylesheets/adva_cms/admin/sidebar.scss +30 -9
  12. data/app/assets/stylesheets/adva_cms/admin.scss +1 -1
  13. data/app/controllers/admin/base_controller.rb +10 -24
  14. data/app/controllers/admin/page/articles_controller.rb +8 -27
  15. data/app/controllers/admin/page/categories_controller.rb +6 -9
  16. data/app/controllers/admin/page/links_controller.rb +6 -9
  17. data/app/controllers/admin/sections_controller.rb +7 -9
  18. data/app/controllers/admin/sites_controller.rb +9 -12
  19. data/app/controllers/admin/users_controller.rb +6 -9
  20. data/app/controllers/articles_controller.rb +30 -52
  21. data/app/controllers/base_controller.rb +8 -8
  22. data/app/controllers/password_controller.rb +3 -5
  23. data/app/controllers/session_controller.rb +3 -5
  24. data/app/helpers/activities_helper.rb +9 -20
  25. data/app/helpers/admin/base_helper.rb +4 -22
  26. data/app/helpers/base_helper.rb +1 -1
  27. data/app/helpers/content_helper.rb +7 -5
  28. data/app/helpers/resource_helper.rb +4 -5
  29. data/app/helpers/users_helper.rb +1 -1
  30. data/app/models/activity.rb +3 -0
  31. data/app/models/article.rb +0 -11
  32. data/app/models/category.rb +3 -3
  33. data/app/models/content.rb +10 -39
  34. data/app/models/link.rb +0 -1
  35. data/app/models/password_mailer.rb +6 -9
  36. data/app/models/section.rb +6 -7
  37. data/app/models/site.rb +0 -2
  38. data/app/models/user.rb +1 -2
  39. data/app/views/activity_notifier/new_content_notification.html.erb +5 -5
  40. data/app/views/admin/activities/_activities.html.erb +4 -4
  41. data/app/views/admin/activities/_comment.html.erb +21 -21
  42. data/app/views/admin/activities/_content.html.erb +4 -3
  43. data/app/views/admin/activities/_topic.html.erb +5 -5
  44. data/app/views/admin/install/confirmation.html.erb +3 -3
  45. data/app/views/admin/install/index.html.erb +14 -14
  46. data/app/views/admin/page/articles/_form.html.erb +28 -25
  47. data/app/views/admin/page/articles/_options.html.erb +3 -4
  48. data/app/views/admin/page/articles/edit.html.erb +3 -3
  49. data/app/views/admin/page/articles/new.html.erb +4 -4
  50. data/app/views/admin/page/categories/edit.html.erb +9 -9
  51. data/app/views/admin/page/categories/index.html.erb +16 -16
  52. data/app/views/admin/page/categories/new.html.erb +5 -3
  53. data/app/views/admin/page/contents/index.html.erb +3 -18
  54. data/app/views/admin/page/links/_form.html.erb +17 -17
  55. data/app/views/admin/page/links/_options.html.erb +16 -19
  56. data/app/views/admin/page/links/edit.html.erb +3 -3
  57. data/app/views/admin/page/links/new.html.erb +3 -3
  58. data/app/views/admin/sections/_form.html.haml +5 -5
  59. data/app/views/admin/sections/edit.html.haml +2 -2
  60. data/app/views/admin/sections/index.html.erb +18 -18
  61. data/app/views/admin/sections/new.html.erb +15 -13
  62. data/app/views/admin/sections/settings/_page.html.haml +4 -6
  63. data/app/views/admin/shared/_header.html.erb +5 -4
  64. data/app/views/admin/shared/_section_tree.html.erb +2 -2
  65. data/app/views/admin/sites/_email_notifications.html.erb +6 -7
  66. data/app/views/admin/sites/_form.html.erb +7 -7
  67. data/app/views/admin/sites/_recent_users.html.erb +4 -2
  68. data/app/views/admin/sites/_unapproved_comments.html.erb +1 -1
  69. data/app/views/admin/sites/index.html.erb +1 -1
  70. data/app/views/admin/sites/new.html.erb +2 -2
  71. data/app/views/admin/sites/show.html.erb +7 -8
  72. data/app/views/admin/users/edit.html.erb +1 -1
  73. data/app/views/admin/users/index.html.erb +10 -10
  74. data/app/views/admin/users/new.html.erb +1 -1
  75. data/app/views/admin/users/show.html.erb +7 -7
  76. data/app/views/layouts/admin.html.haml +3 -5
  77. data/app/views/layouts/login.html.erb +1 -1
  78. data/app/views/password/edit.html.erb +12 -5
  79. data/app/views/password/new.html.erb +7 -7
  80. data/app/views/password_mailer/reset_password_email.html.erb +21 -1
  81. data/app/views/password_mailer/updated_password_email.html.erb +3 -1
  82. data/app/views/session/new.html.erb +9 -9
  83. data/app/views/shared/_flash.html.erb +2 -2
  84. data/app/views/shared/_sidebar.html.erb +2 -2
  85. data/config/initializers/ckeditor.rb +61 -0
  86. data/config/initializers/time_format.rb +2 -0
  87. data/lib/adva/authenticate_user.rb +193 -0
  88. data/lib/{active_record → adva}/belongs_to_author.rb +4 -4
  89. data/lib/adva/event.rb +34 -0
  90. data/lib/adva/extensible_forms.rb +285 -0
  91. data/lib/{has_options.rb → adva/has_options.rb} +5 -7
  92. data/lib/adva/has_permalink.rb +36 -0
  93. data/lib/adva/version.rb +1 -1
  94. data/lib/adva.rb +10 -36
  95. data/lib/rails_ext/action_controller/event_helper.rb +1 -1
  96. data/lib/rails_ext.rb +0 -9
  97. data/vendor/gems/cacheable_flash/.gitignore +8 -0
  98. data/vendor/gems/cacheable_flash/Gemfile +8 -0
  99. data/vendor/gems/cacheable_flash/README.md +35 -0
  100. data/vendor/gems/cacheable_flash/Rakefile +4 -0
  101. data/vendor/gems/cacheable_flash/bin/console +15 -0
  102. data/vendor/gems/cacheable_flash/bin/setup +8 -0
  103. data/vendor/gems/cacheable_flash/cacheable_flash.gemspec +38 -0
  104. data/vendor/gems/cacheable_flash/lib/cacheable_flash/controller.rb +29 -0
  105. data/vendor/gems/cacheable_flash/lib/cacheable_flash/javascript.js +19 -0
  106. data/vendor/gems/cacheable_flash/lib/cacheable_flash/middleware.rb +30 -0
  107. data/vendor/gems/cacheable_flash/lib/cacheable_flash/version.rb +5 -0
  108. data/vendor/gems/cacheable_flash/lib/cacheable_flash.rb +12 -0
  109. data/vendor/gems/simple_taggable/lib/tag_list.rb +1 -1
  110. data/vendor/gems/tags/lib/menu.rb +1 -1
  111. data/vendor/gems/tags/lib/tags/tag.rb +1 -1
  112. metadata +71 -144
  113. data/app/assets/javascripts/adva_cms/admin/jquery.admin.js +0 -23
  114. data/app/assets/javascripts/adva_cms/admin/jquery.article.js +0 -22
  115. data/app/assets/javascripts/adva_cms/admin/jquery.cached_pages.js +0 -14
  116. data/app/assets/javascripts/adva_cms/admin/jquery.table_tree.js +0 -7
  117. data/app/assets/javascripts/adva_cms/application.js +0 -13
  118. data/app/assets/javascripts/adva_cms/base.js +0 -4
  119. data/app/assets/javascripts/adva_cms/cookie.js +0 -49
  120. data/app/assets/javascripts/adva_cms/jquery/jquery-lowpro.js +0 -224
  121. data/app/assets/javascripts/adva_cms/jquery/jquery.qtip.js +0 -2085
  122. data/app/assets/javascripts/adva_cms/jquery/jquery.table_tree.js +0 -307
  123. data/app/assets/javascripts/adva_cms/jquery/jquery.tablednd_0_5.js +0 -386
  124. data/app/assets/javascripts/adva_cms/jquery.common.js +0 -41
  125. data/app/assets/javascripts/adva_cms/jquery.dates.js +0 -51
  126. data/app/assets/javascripts/adva_cms/jquery.flash.js +0 -59
  127. data/app/assets/javascripts/adva_cms/jquery.roles.js +0 -25
  128. data/app/assets/javascripts/adva_cms/json.js +0 -139
  129. data/app/controllers/admin/base_account_controller.rb +0 -13
  130. data/app/controllers/admin/install_controller.rb +0 -61
  131. data/app/controllers/admin/plugins_controller.rb +0 -38
  132. data/app/helpers/meta_tags_helper.rb +0 -30
  133. data/app/models/account.rb +0 -7
  134. data/app/models/event.rb +0 -34
  135. data/app/views/admin/articles/_meta_tags.html.erb +0 -7
  136. data/app/views/admin/cached_pages/_filter.html.erb +0 -8
  137. data/app/views/admin/cached_pages/destroy.js.erb +0 -18
  138. data/app/views/admin/cached_pages/index.html.erb +0 -26
  139. data/app/views/admin/plugins/_form.html.erb +0 -11
  140. data/app/views/admin/plugins/index.html.erb +0 -16
  141. data/app/views/admin/plugins/show.html.erb +0 -43
  142. data/app/views/admin/shared/_language_select.html.erb +0 -6
  143. data/app/views/admin/shared/_section_summary.html.erb +0 -23
  144. data/app/views/admin/sites/_meta_tags.html.erb +0 -15
  145. data/app/views/layouts/default.html.erb +0 -38
  146. data/app/views/layouts/simple.html.erb +0 -22
  147. data/app/views/shared/_footer.html.erb +0 -4
  148. data/app/views/shared/messages/insufficient_permissions.html.erb +0 -4
  149. data/config/initializers/article.rb +0 -8
  150. data/config/initializers/has_options.rb +0 -2
  151. data/config/initializers/has_permalink.rb +0 -2
  152. data/config/initializers/site.rb +0 -8
  153. data/config/locales/en.yml +0 -1319
  154. data/lib/action_controller/authenticate_anonymous.rb +0 -69
  155. data/lib/action_controller/authenticate_user.rb +0 -203
  156. data/lib/core_ext.rb +0 -7
  157. data/lib/extensible_forms.rb +0 -284
  158. data/lib/has_permalink.rb +0 -33
  159. data/lib/login/helper_integration.rb +0 -11
  160. data/lib/login/mail_config.rb +0 -39
  161. data/lib/rails_ext/action_controller/cacheable_flash.rb +0 -30
  162. data/lib/rails_ext/action_controller/content_for_assignments.rb +0 -106
  163. data/lib/rails_ext/action_controller/page_caching.rb +0 -23
  164. data/lib/rails_ext/action_controller/responds_to_parent.rb +0 -46
  165. data/lib/rails_ext/active_record/exists.rb +0 -5
  166. data/lib/rails_ext/active_record/sti_instantiation.rb +0 -35
  167. data/lib/rails_ext/active_record/sticky_changes.rb +0 -30
  168. data/lib/rails_ext/railties/plugin.rb +0 -58
  169. data/lib/rails_ext/railties/plugin_configuration.rb +0 -72
  170. data/lib/registry.rb +0 -49
  171. data/lib/tasks/translation.rake +0 -69
  172. data/lib/time_hacks.rb +0 -57
  173. data/lib/webrat_patch.rb +0 -11
  174. data/test/meta_tags_test.rb +0 -42
  175. data/vendor/gems/has_counter/.gitignore +0 -17
  176. data/vendor/gems/has_counter/Gemfile +0 -4
  177. data/vendor/gems/has_counter/LICENSE +0 -22
  178. data/vendor/gems/has_counter/MIT-LICENSE +0 -20
  179. data/vendor/gems/has_counter/README.markdown +0 -64
  180. data/vendor/gems/has_counter/README.md +0 -29
  181. data/vendor/gems/has_counter/Rakefile +0 -2
  182. data/vendor/gems/has_counter/db/migrate/20080601194338_create_counters_table.rb.rb +0 -13
  183. data/vendor/gems/has_counter/has_counter.gemspec +0 -17
  184. data/vendor/gems/has_counter/lib/active_record/has_counter.rb +0 -67
  185. data/vendor/gems/has_counter/lib/counter.rb +0 -23
  186. data/vendor/gems/has_counter/lib/has_counter/version.rb +0 -3
  187. data/vendor/gems/has_counter/lib/has_counter.rb +0 -4
  188. data/vendor/gems/has_counter/spec/has_counter.sqlite3.db +0 -0
  189. data/vendor/gems/has_counter/spec/has_counter_spec.rb +0 -55
  190. data/vendor/gems/has_counter/spec/spec_helper.rb +0 -117
  191. data/vendor/gems/has_filter/.gitignore +0 -17
  192. data/vendor/gems/has_filter/Gemfile +0 -4
  193. data/vendor/gems/has_filter/LICENSE +0 -22
  194. data/vendor/gems/has_filter/README.md +0 -29
  195. data/vendor/gems/has_filter/Rakefile +0 -2
  196. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_add.png +0 -0
  197. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_left.png +0 -0
  198. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_right.png +0 -0
  199. data/vendor/gems/has_filter/app/assets/images/has_filter/filter_remove.png +0 -0
  200. data/vendor/gems/has_filter/app/assets/javascripts/has_filter/filter.js +0 -35
  201. data/vendor/gems/has_filter/app/assets/javascripts/has_filter/jquery.filter.js +0 -23
  202. data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/alternate/filter.scss +0 -102
  203. data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/filter.scss +0 -100
  204. data/vendor/gems/has_filter/app/helpers/filter_helper.rb +0 -3
  205. data/vendor/gems/has_filter/has_filter.gemspec +0 -17
  206. data/vendor/gems/has_filter/init.rb +0 -3
  207. data/vendor/gems/has_filter/lib/has_filter/active_record/act_macro.rb +0 -102
  208. data/vendor/gems/has_filter/lib/has_filter/filter/base.rb +0 -67
  209. data/vendor/gems/has_filter/lib/has_filter/filter/categorized.rb +0 -24
  210. data/vendor/gems/has_filter/lib/has_filter/filter/chain.rb +0 -45
  211. data/vendor/gems/has_filter/lib/has_filter/filter/set.rb +0 -80
  212. data/vendor/gems/has_filter/lib/has_filter/filter/state.rb +0 -25
  213. data/vendor/gems/has_filter/lib/has_filter/filter/tagged.rb +0 -22
  214. data/vendor/gems/has_filter/lib/has_filter/filter/text.rb +0 -55
  215. data/vendor/gems/has_filter/lib/has_filter/filter.rb +0 -17
  216. data/vendor/gems/has_filter/lib/has_filter/version.rb +0 -3
  217. data/vendor/gems/has_filter/lib/has_filter.rb +0 -22
  218. data/vendor/gems/has_filter/test/db/setup.rb +0 -45
  219. data/vendor/gems/has_filter/test/db/test.sqlite3.db +0 -0
  220. data/vendor/gems/has_filter/test/fixtures.rb +0 -15
  221. data/vendor/gems/has_filter/test/has_filter/filter_chain_test.rb +0 -41
  222. data/vendor/gems/has_filter/test/has_filter/filter_scopes_test.rb +0 -102
  223. data/vendor/gems/has_filter/test/has_filter/filter_tags_test.rb +0 -113
  224. data/vendor/gems/has_filter/test/has_filter/integration.rb +0 -15
  225. data/vendor/gems/has_filter/test/has_filter/scopes_test.rb +0 -48
  226. data/vendor/gems/has_filter/test/log/test.log +0 -34346
  227. data/vendor/gems/has_filter/test/models.rb +0 -23
  228. data/vendor/gems/has_filter/test/templates/has_filter/test/index.html.erb +0 -5
  229. data/vendor/gems/has_filter/test/test_helper.rb +0 -66
  230. data/vendor/gems/xss_terminate/.gitignore +0 -17
  231. data/vendor/gems/xss_terminate/Gemfile +0 -4
  232. data/vendor/gems/xss_terminate/LICENSE +0 -22
  233. data/vendor/gems/xss_terminate/MIT-LICENSE +0 -20
  234. data/vendor/gems/xss_terminate/README +0 -94
  235. data/vendor/gems/xss_terminate/README.md +0 -29
  236. data/vendor/gems/xss_terminate/Rakefile +0 -23
  237. data/vendor/gems/xss_terminate/lib/html5lib_sanitize.rb +0 -2453
  238. data/vendor/gems/xss_terminate/lib/rails_sanitize.rb +0 -8
  239. data/vendor/gems/xss_terminate/lib/xss_terminate/version.rb +0 -3
  240. data/vendor/gems/xss_terminate/lib/xss_terminate.rb +0 -141
  241. data/vendor/gems/xss_terminate/tasks/xss_terminate_tasks.rake +0 -7
  242. data/vendor/gems/xss_terminate/test/models/comment.rb +0 -5
  243. data/vendor/gems/xss_terminate/test/models/entry.rb +0 -7
  244. data/vendor/gems/xss_terminate/test/models/message.rb +0 -3
  245. data/vendor/gems/xss_terminate/test/models/person.rb +0 -5
  246. data/vendor/gems/xss_terminate/test/models/review.rb +0 -5
  247. data/vendor/gems/xss_terminate/test/schema.rb +0 -34
  248. data/vendor/gems/xss_terminate/test/setup_test.rb +0 -16
  249. data/vendor/gems/xss_terminate/test/xss_terminate_test.rb +0 -50
  250. data/vendor/gems/xss_terminate/xss_terminate.gemspec +0 -17
  251. /data/lib/tasks/{adva_cms.rake → adva.rake} +0 -0
@@ -0,0 +1,704 @@
1
+ //= require jquery
2
+
3
+ $(function() {
4
+ $('a.reorder').click(function(event) {
5
+ event.preventDefault();
6
+ $(this).parent().toggleClass('active');
7
+ TableTree.toggle($('table.list'), this.id.replace('reorder_', ''), this.href);
8
+ });
9
+ });
10
+
11
+ // adva_cms/jquery/jquery.tablednd_0_5
12
+ /**
13
+ * TableDnD plug-in for JQuery, allows you to drag and drop table rows
14
+ * You can set up various options to control how the system will work
15
+ * Copyright (c) Denis Howlett <denish@isocra.com>
16
+ * Licensed like jQuery, see http://docs.jquery.com/License.
17
+ *
18
+ * Configuration options:
19
+ *
20
+ * onDragStyle
21
+ * This is the style that is assigned to the row during drag. There are limitations to the styles that can be
22
+ * associated with a row (such as you can't assign a border--well you can, but it won't be
23
+ * displayed). (So instead consider using onDragClass.) The CSS style to apply is specified as
24
+ * a map (as used in the jQuery css(...) function).
25
+ * onDropStyle
26
+ * This is the style that is assigned to the row when it is dropped. As for onDragStyle, there are limitations
27
+ * to what you can do. Also this replaces the original style, so again consider using onDragClass which
28
+ * is simply added and then removed on drop.
29
+ * onDragClass
30
+ * This class is added for the duration of the drag and then removed when the row is dropped. It is more
31
+ * flexible than using onDragStyle since it can be inherited by the row cells and other content. The default
32
+ * is class is tDnD_whileDrag. So to use the default, simply customise this CSS class in your
33
+ * stylesheet.
34
+ * onDrop
35
+ * Pass a function that will be called when the row is dropped. The function takes 2 parameters: the table
36
+ * and the row that was dropped. You can work out the new order of the rows by using
37
+ * table.rows.
38
+ * onDragStart
39
+ * Pass a function that will be called when the user starts dragging. The function takes 2 parameters: the
40
+ * table and the row which the user has started to drag.
41
+ * onAllowDrop
42
+ * Pass a function that will be called as a row is over another row. If the function returns true, allow
43
+ * dropping on that row, otherwise not. The function takes 2 parameters: the dragged row and the row under
44
+ * the cursor. It returns a boolean: true allows the drop, false doesn't allow it.
45
+ * scrollAmount
46
+ * This is the number of pixels to scroll if the user moves the mouse cursor to the top or bottom of the
47
+ * window. The page should automatically scroll up or down as appropriate (tested in IE6, IE7, Safari, FF2,
48
+ * FF3 beta
49
+ * dragHandle
50
+ * This is the name of a class that you assign to one or more cells in each row that is draggable. If you
51
+ * specify this class, then you are responsible for setting cursor: move in the CSS and only these cells
52
+ * will have the drag behaviour. If you do not specify a dragHandle, then you get the old behaviour where
53
+ * the whole row is draggable.
54
+ *
55
+ * Other ways to control behaviour:
56
+ *
57
+ * Add class="nodrop" to any rows for which you don't want to allow dropping, and class="nodrag" to any rows
58
+ * that you don't want to be draggable.
59
+ *
60
+ * Inside the onDrop method you can also call $.tableDnD.serialize() this returns a string of the form
61
+ * <tableID>[]=<rowID1>&<tableID>[]=<rowID2> so that you can send this back to the server. The table must have
62
+ * an ID as must all the rows.
63
+ *
64
+ * Other methods:
65
+ *
66
+ * $("...").tableDnDUpdate()
67
+ * Will update all the matching tables, that is it will reapply the mousedown method to the rows (or handle cells).
68
+ * This is useful if you have updated the table rows using Ajax and you want to make the table draggable again.
69
+ * The table maintains the original configuration (so you don't have to specify it again).
70
+ *
71
+ * $("...").tableDnDSerialize()
72
+ * Will serialize and return the serialized string as above, but for each of the matching tables--so it can be
73
+ * called from anywhere and isn't dependent on the currentTable being set up correctly before calling
74
+ *
75
+ * Known problems:
76
+ * - Auto-scoll has some problems with IE7 (it scrolls even when it shouldn't), work-around: set scrollAmount to 0
77
+ *
78
+ * Version 0.2: 2008-02-20 First public version
79
+ * Version 0.3: 2008-02-07 Added onDragStart option
80
+ * Made the scroll amount configurable (default is 5 as before)
81
+ * Version 0.4: 2008-03-15 Changed the noDrag/noDrop attributes to nodrag/nodrop classes
82
+ * Added onAllowDrop to control dropping
83
+ * Fixed a bug which meant that you couldn't set the scroll amount in both directions
84
+ * Added serialize method
85
+ * Version 0.5: 2008-05-16 Changed so that if you specify a dragHandle class it doesn't make the whole row
86
+ * draggable
87
+ * Improved the serialize method to use a default (and settable) regular expression.
88
+ * Added tableDnDupate() and tableDnDSerialize() to be called when you are outside the table
89
+ */
90
+ jQuery.tableDnD = {
91
+ /** Keep hold of the current table being dragged */
92
+ currentTable : null,
93
+ /** Keep hold of the current drag object if any */
94
+ dragObject: null,
95
+ /** The current mouse offset */
96
+ mouseOffset: null,
97
+ /** Remember the old value of Y so that we don't do too much processing */
98
+ oldY: 0,
99
+
100
+ /** Actually build the structure */
101
+ build: function(options) {
102
+ // Set up the defaults if any
103
+
104
+ this.each(function() {
105
+ // This is bound to each matching table, set up the defaults and override with user options
106
+ this.tableDnDConfig = $.extend({
107
+ onDragStyle: null,
108
+ onDropStyle: null,
109
+ // Add in the default class for whileDragging
110
+ onDragClass: "tDnD_whileDrag",
111
+ onDrop: null,
112
+ onDrag: null, // ADDED
113
+ onDragStart: null,
114
+ scrollAmount: 5,
115
+ serializeRegexp: /[^\-]*$/, // The regular expression to use to trim row IDs
116
+ serializeParamName: null, // If you want to specify another parameter name instead of the table ID
117
+ dragHandle: null // If you give the name of a class here, then only Cells with this class will be draggable
118
+ }, options || {});
119
+ // Now make the rows draggable
120
+ jQuery.tableDnD.makeDraggable(this);
121
+ });
122
+
123
+ // Now we need to capture the mouse up and mouse move event
124
+ // We can use bind so that we don't interfere with other event handlers
125
+ jQuery(document)
126
+ .bind('mousemove', jQuery.tableDnD.mousemove)
127
+ .bind('mouseup', jQuery.tableDnD.mouseup);
128
+
129
+ // Don't break the chain
130
+ return this;
131
+ },
132
+
133
+ /** This function makes all the rows on the table draggable apart from those marked as "NoDrag" */
134
+ makeDraggable: function(table) {
135
+ var config = table.tableDnDConfig;
136
+ if (table.tableDnDConfig.dragHandle) {
137
+ // We only need to add the event to the specified cells
138
+ var cells = $("td."+table.tableDnDConfig.dragHandle, table);
139
+ cells.each(function() {
140
+ // The cell is bound to "this"
141
+ jQuery(this).mousedown(function(ev) {
142
+ jQuery.tableDnD.dragObject = this.parentNode;
143
+ jQuery.tableDnD.currentTable = table;
144
+ jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
145
+ if (config.onDragStart) {
146
+ // Call the onDrop method if there is one
147
+ config.onDragStart(table, this);
148
+ }
149
+ return false;
150
+ });
151
+ })
152
+ } else {
153
+ // For backwards compatibility, we add the event to the whole row
154
+ var rows = jQuery("tr", table); // get all the rows as a wrapped set
155
+ rows.each(function() {
156
+ // Iterate through each row, the row is bound to "this"
157
+ var row = $(this);
158
+ if (! row.hasClass("nodrag")) {
159
+ row.mousedown(function(ev) {
160
+ if (ev.target.tagName == "TD") {
161
+ jQuery.tableDnD.dragObject = this;
162
+ jQuery.tableDnD.currentTable = table;
163
+ jQuery.tableDnD.mouseOffset = jQuery.tableDnD.getMouseOffset(this, ev);
164
+ if (config.onDragStart) {
165
+ // Call the onDrop method if there is one
166
+ config.onDragStart(table, this);
167
+ }
168
+ return false;
169
+ }
170
+ }).css("cursor", "move"); // Store the tableDnD object
171
+ }
172
+ });
173
+ }
174
+ },
175
+
176
+ updateTables: function() {
177
+ this.each(function() {
178
+ // this is now bound to each matching table
179
+ if (this.tableDnDConfig) {
180
+ jQuery.tableDnD.makeDraggable(this);
181
+ }
182
+ })
183
+ },
184
+
185
+ /** Get the mouse coordinates from the event (allowing for browser differences) */
186
+ mouseCoords: function(ev){
187
+ if(ev.pageX || ev.pageY){
188
+ return {x:ev.pageX, y:ev.pageY};
189
+ }
190
+ return {
191
+ x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
192
+ y:ev.clientY + document.body.scrollTop - document.body.clientTop
193
+ };
194
+ },
195
+
196
+ /** Given a target element and a mouse event, get the mouse offset from that element.
197
+ To do this we need the element's position and the mouse position */
198
+ getMouseOffset: function(target, ev) {
199
+ ev = ev || window.event;
200
+
201
+ var docPos = this.getPosition(target);
202
+ var mousePos = this.mouseCoords(ev);
203
+ return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
204
+ },
205
+
206
+ /** Get the position of an element by going up the DOM tree and adding up all the offsets */
207
+ getPosition: function(e){
208
+ var left = 0;
209
+ var top = 0;
210
+ /** Safari fix -- thanks to Luis Chato for this! */
211
+ if (e.offsetHeight == 0) {
212
+ /** Safari 2 doesn't correctly grab the offsetTop of a table row
213
+ this is detailed here:
214
+ http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari/
215
+ the solution is likewise noted there, grab the offset of a table cell in the row - the firstChild.
216
+ note that firefox will return a text node as a first child, so designing a more thorough
217
+ solution may need to take that into account, for now this seems to work in firefox, safari, ie */
218
+ e = e.firstChild; // a table cell
219
+ }
220
+
221
+ while (e.offsetParent){
222
+ left += e.offsetLeft;
223
+ top += e.offsetTop;
224
+ e = e.offsetParent;
225
+ }
226
+
227
+ left += e.offsetLeft;
228
+ top += e.offsetTop;
229
+
230
+ return {x:left, y:top};
231
+ },
232
+
233
+ mousemove: function(ev) {
234
+ if (jQuery.tableDnD.dragObject == null) {
235
+ return;
236
+ }
237
+
238
+ var dragObj = jQuery(jQuery.tableDnD.dragObject);
239
+ var config = jQuery.tableDnD.currentTable.tableDnDConfig;
240
+ var mousePos = jQuery.tableDnD.mouseCoords(ev);
241
+ var y = mousePos.y - jQuery.tableDnD.mouseOffset.y;
242
+ //auto scroll the window
243
+ var yOffset = window.pageYOffset;
244
+ if (document.all) {
245
+ // Windows version
246
+ //yOffset=document.body.scrollTop;
247
+ if (typeof document.compatMode != 'undefined' &&
248
+ document.compatMode != 'BackCompat') {
249
+ yOffset = document.documentElement.scrollTop;
250
+ }
251
+ else if (typeof document.body != 'undefined') {
252
+ yOffset=document.body.scrollTop;
253
+ }
254
+
255
+ }
256
+
257
+ if (mousePos.y-yOffset < config.scrollAmount) {
258
+ window.scrollBy(0, -config.scrollAmount);
259
+ } else {
260
+ var windowHeight = window.innerHeight ? window.innerHeight
261
+ : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
262
+ if (windowHeight-(mousePos.y-yOffset) < config.scrollAmount) {
263
+ window.scrollBy(0, config.scrollAmount);
264
+ }
265
+ }
266
+
267
+
268
+ if (y != jQuery.tableDnD.oldY) {
269
+ // work out if we're going up or down...
270
+ var movingDown = y > jQuery.tableDnD.oldY;
271
+ // update the old value
272
+ jQuery.tableDnD.oldY = y;
273
+ // update the style to show we're dragging
274
+ if (config.onDragClass) {
275
+ dragObj.addClass(config.onDragClass);
276
+ } else {
277
+ dragObj.css(config.onDragStyle);
278
+ }
279
+ // If we're over a row then move the dragged row to there so that the user sees the
280
+ // effect dynamically
281
+ var currentRow = jQuery.tableDnD.findDropTargetRow(dragObj, y, movingDown);
282
+ if (currentRow) {
283
+ // TODO worry about what happens when there are multiple TBODIES
284
+ if (movingDown && jQuery.tableDnD.dragObject != currentRow) {
285
+ jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);
286
+ } else if (! movingDown && jQuery.tableDnD.dragObject != currentRow) {
287
+ jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);
288
+ }
289
+ if (config.onDrag) {
290
+ config.onDrag(jQuery.tableDnD.currentTable, jQuery.tableDnD.dragObject);
291
+ }
292
+ }
293
+ }
294
+
295
+ return false;
296
+ },
297
+
298
+ /** We're only worried about the y position really, because we can only move rows up and down */
299
+ findDropTargetRow: function(draggedRow, y, movingDown) {
300
+ var rows = jQuery.tableDnD.currentTable.rows;
301
+ for (var i=0; i<rows.length; i++) {
302
+ var row = rows[i];
303
+ var rowY = this.getPosition(row).y;
304
+ var rowHeight = parseInt(row.offsetHeight)/2;
305
+ if (row.offsetHeight == 0) {
306
+ rowY = this.getPosition(row.firstChild).y;
307
+ rowHeight = parseInt(row.firstChild.offsetHeight)/2;
308
+ }
309
+ // Because we always have to insert before, we need to offset the height a bit
310
+ if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
311
+ // that's the row we're over
312
+ // If it's the same as the current row, ignore it
313
+ if (row == draggedRow.get(0)) {return null;}
314
+ var config = jQuery.tableDnD.currentTable.tableDnDConfig;
315
+ if (config.onAllowDrop) {
316
+ if (config.onAllowDrop(draggedRow, row, movingDown)) {
317
+ return row;
318
+ } else {
319
+ return null;
320
+ }
321
+ } else {
322
+ // If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)
323
+ var nodrop = $(row).hasClass("nodrop");
324
+ if (! nodrop) {
325
+ return row;
326
+ } else {
327
+ return null;
328
+ }
329
+ }
330
+ return row;
331
+ }
332
+ }
333
+ return null;
334
+ },
335
+
336
+ mouseup: function(e) {
337
+ if (jQuery.tableDnD.currentTable && jQuery.tableDnD.dragObject) {
338
+ var droppedRow = jQuery.tableDnD.dragObject;
339
+ var config = jQuery.tableDnD.currentTable.tableDnDConfig;
340
+ // If we have a dragObject, then we need to release it,
341
+ // The row will already have been moved to the right place so we just reset stuff
342
+ if (config.onDragClass) {
343
+ jQuery(droppedRow).removeClass(config.onDragClass);
344
+ } else {
345
+ jQuery(droppedRow).css(config.onDropStyle);
346
+ }
347
+ jQuery.tableDnD.dragObject = null;
348
+ if (config.onDrop) {
349
+ // Call the onDrop method if there is one
350
+ config.onDrop(jQuery.tableDnD.currentTable, droppedRow);
351
+ }
352
+ jQuery.tableDnD.currentTable = null; // let go of the table too
353
+ }
354
+ },
355
+
356
+ serialize: function() {
357
+ if (jQuery.tableDnD.currentTable) {
358
+ return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);
359
+ } else {
360
+ return "Error: No Table id set, you need to set an id on your table and every row";
361
+ }
362
+ },
363
+
364
+ serializeTable: function(table) {
365
+ var result = "";
366
+ var tableId = table.id;
367
+ var rows = table.rows;
368
+ for (var i=0; i<rows.length; i++) {
369
+ if (result.length > 0) result += "&";
370
+ var rowId = rows[i].id;
371
+ if (rowId && rowId && table.tableDnDConfig && table.tableDnDConfig.serializeRegexp) {
372
+ rowId = rowId.match(table.tableDnDConfig.serializeRegexp)[0];
373
+ }
374
+
375
+ result += tableId + '[]=' + rows[i].id;
376
+ }
377
+ return result;
378
+ },
379
+
380
+ serializeTables: function() {
381
+ var result = "";
382
+ this.each(function() {
383
+ // this is now bound to each matching table
384
+ result += jQuery.tableDnD.serializeTable(this);
385
+ });
386
+ return result;
387
+ }
388
+
389
+ }
390
+
391
+ jQuery.fn.extend(
392
+ {
393
+ tableDnD : jQuery.tableDnD.build,
394
+ tableDnDUpdate : jQuery.tableDnD.updateTables,
395
+ tableDnDSerialize: jQuery.tableDnD.serializeTables
396
+ }
397
+ );
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+ // adva_cms/jquery/jquery.table_tree
409
+ TableTree = {
410
+ tableDnDOptions: {
411
+ onDragClass: 'drag',
412
+ onDragStart: function(table, row) {
413
+ TableTree.startOffset = jQuery.tableDnD.mouseOffset.x;
414
+ $(row).mousemove(TableTree.mousemove);
415
+ if (node = $(row).ttnode()) node.dragStart();
416
+ },
417
+ onDrag: function(table, row) {
418
+ TableTree.current_table.dirty = true;
419
+ if (node = $(row).ttnode()) node.update_children();
420
+ },
421
+ onDrop: function(table, row) {
422
+ $(row).unbind('mousemove', TableTree.mousemove);
423
+ if (node = $(row).ttnode()) node.drop();
424
+ TableTree.current_table.rebuild();
425
+ TableTree.current_table.update_remote(row);
426
+ },
427
+ onAllowDrop: function(draggedRow, row, movingDown) {
428
+ var node = $(row).ttnode();
429
+ next = movingDown ? $(node.next_row_sibling()).ttnode() : node;
430
+ if (next && (next.parent.level >= $(draggedRow).ttnode().level)) return false;
431
+ return $(row).ttnode() ? true : false;
432
+ }
433
+ },
434
+ toggle: function(table, type, collection_url) {
435
+ TableTree.current_table ? TableTree.teardown(table) : TableTree.setup(table, type, collection_url);
436
+ },
437
+ setup: function(table, type, collection_url) {
438
+ $('tbody', table).tableDnD(TableTree.tableDnDOptions);
439
+ TableTree.current_table = new TableTree.Table($(table).get(0), type, collection_url);
440
+ TableTree.current_table.setSortable();
441
+ },
442
+ teardown: function(table) {
443
+ // TableTree.current_table.update_remote();
444
+ jQuery.tableDnD.teardown(table);
445
+ TableTree.current_table.setUnsortable();
446
+ TableTree.current_table = null;
447
+ },
448
+ level: function(element) {
449
+ var match = element.className.match(/level_([\d]+)/);
450
+ return match ? parseInt(match[1]) : 0;
451
+ },
452
+ mousemove: function(event) {
453
+ if (!TableTree.current_table.is_tree) return;
454
+
455
+ var offset = jQuery.tableDnD.getMouseOffset(this, event).x - TableTree.startOffset;
456
+ if(offset > 25) {
457
+ TableTree.current_table.dirty = true;
458
+ $(this).ttnode().increment_level(event);
459
+ } else if(offset < -25) {
460
+ TableTree.current_table.dirty = true;
461
+ $(this).ttnode().decrement_level(event);
462
+ }
463
+ },
464
+ Base: function() {},
465
+ Table: function(table, type, collection_url) {
466
+ this.is_tree = $(table).hasClass('tree')
467
+ this.table = table; //$('tbody', table)
468
+ this.type = type;
469
+ this.level = -1;
470
+ this.collection_url = collection_url;
471
+ this.rebuild();
472
+ },
473
+ Node: function(parent, element, level) {
474
+ var _this = this;
475
+ this.parent = parent;
476
+ this.element = element;
477
+ this.level = level;
478
+
479
+ this.children = this.find_children().map(function() {
480
+ var level = TableTree.level(this);
481
+ if(level == _this.level + 1) { return new TableTree.Node(_this, this, level); }
482
+ });
483
+ }
484
+ }
485
+
486
+ TableTree.Base.prototype = {
487
+ find_node: function(element) {
488
+ for (var i = 0; i < this.children.length; i++) {
489
+ var child = this.children[i];
490
+ if (this.children[i].element == element) {
491
+ return this.children[i];
492
+ } else {
493
+ var result = this.children[i].find_node(element);
494
+ if (result) return result;
495
+ }
496
+ }
497
+ }
498
+ }
499
+ TableTree.Table.prototype = jQuery.extend(new TableTree.Base(), {
500
+ rebuild: function() {
501
+ var _this = this;
502
+ this.children = $('tr', this.table).map(function() {
503
+ if(TableTree.level(this) == 0) { return new TableTree.Node(_this, this, TableTree.level(this)); }
504
+ });
505
+ },
506
+ setSortable: function() {
507
+ $('tr', this.table).each(function() {
508
+ // thead
509
+ cells = $('th', this);
510
+ cells.each(function(ix) {
511
+ if(ix == 0) {
512
+ this.setAttribute('colspan', cells.length);
513
+ } else {
514
+ $(this).hide();
515
+ }
516
+ });
517
+
518
+ // tbody
519
+ cells = $('td', this);
520
+ cells.each(function(ix) {
521
+ if (ix == 0) {
522
+ element = this;
523
+ this.setAttribute('colspan', cells.length);
524
+ $('a', this).each(function() {
525
+ $(this).hide();
526
+ element.appendChild(document.createTextNode($(this).text()))
527
+ });
528
+ } else {
529
+ $(this).hide();
530
+ }
531
+ });
532
+ });
533
+ },
534
+ setUnsortable: function() {
535
+ $('tr', this.table).each(function(ix) {
536
+ // thead
537
+ cells = $('th', this);
538
+ cells.each(function(ix) {
539
+ if(ix == 0) {
540
+ this.setAttribute('colspan', 1);
541
+ } else {
542
+ $(this).show();
543
+ }
544
+ });
545
+
546
+ // tbody
547
+ $('td', this).each(function(ix) {
548
+ if(ix == 0) {
549
+ $('a', this).each(function() {
550
+ $(this).show();
551
+ });
552
+ $('img.spinner', this).remove();
553
+ this.removeChild(this.lastChild);
554
+ this.setAttribute('colspan', 1);
555
+ } else {
556
+ $(this).show();
557
+ }
558
+ });
559
+ });
560
+ },
561
+ update_remote: function(row) {
562
+ if(!this.dirty) return;
563
+ this.dirty = false;
564
+ _this = this;
565
+
566
+ this.show_spinner(row);
567
+
568
+ $.ajax({
569
+ type: "POST",
570
+ url: this.collection_url,
571
+ beforeSend: function(xhr) {
572
+ xhr.setRequestHeader("Accept", "text/javascript, text/html, application/xml, text/xml, */*");
573
+ },
574
+ data: jQuery.extend(this.serialize(row), { authenticity_token: window._auth_token, '_method': 'put' }),
575
+ success: function(msg) { _this.hide_spinner(row); },
576
+ error: function(msg) { _this.hide_spinner(row); }
577
+ });
578
+ },
579
+ serialize: function(row) {
580
+ row = $(row).ttnode();
581
+ data = {};
582
+ data[this.type + '[' + row.id() + '][parent_id]'] = row.parent_id();
583
+ data[this.type +'[' + row.id() + '][left_id]'] = row.left_id();
584
+ return data;
585
+ },
586
+ show_spinner: function(row) {
587
+ img = document.createElement('img');
588
+ img.src = 'data:image/gif;base64,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';
589
+ img.className = 'spinner';
590
+ $('td', row)[0].appendChild(img);
591
+ },
592
+ hide_spinner: function(row) {
593
+ cell = $('td', row)[0];
594
+ cell.removeChild(cell.lastChild);
595
+ }
596
+ });
597
+
598
+ TableTree.Node.prototype = jQuery.extend(new TableTree.Base(), {
599
+ find_children: function() {
600
+ var lvl = this.level;
601
+ var stop = false;
602
+ return this.row_siblings().slice(this.row_index() + 1).filter(function() {
603
+ var level = TableTree.level(this);
604
+ if(lvl == level) stop = true; // how to break from a jquery iterator?
605
+ return !stop && lvl + 1 == level;
606
+ });
607
+ },
608
+ depth: function() {
609
+ if (this.children.length > 0) {
610
+ return Math.max.apply(Math, this.children.map(function() { return this.depth() }).get());
611
+ } else {
612
+ return this.level;
613
+ }
614
+ },
615
+ siblings: function() {
616
+ return this.parent.children;
617
+ },
618
+ id: function() {
619
+ return this.element ? this.to_int(this.element.id) : 'null';
620
+ },
621
+ parent_id: function() {
622
+ return this.parent.element ? this.to_int(this.parent.element.id) : 'null';
623
+ },
624
+ left_id: function() {
625
+ left = this.left()
626
+ return left ? this.to_int(left.element.id) : 'null';
627
+ },
628
+ left: function() {
629
+ siblings = this.siblings().get();
630
+ ix = siblings.indexOf(this) - 1;
631
+ if(ix >= 0) return siblings[ix];
632
+ },
633
+ to_int: function(str) {
634
+ if(str) return str.replace(/[\D]+/, '')
635
+ },
636
+ next_row_sibling: function () {
637
+ return this.row_siblings()[this.row_index() + 1];
638
+ },
639
+ row_siblings: function() {
640
+ if(!this._row_siblings) { this._row_siblings = $(this.element).parent().children(); }
641
+ return this._row_siblings;
642
+ },
643
+ row_index: function() {
644
+ return this.row_siblings().get().indexOf(this.element);
645
+ },
646
+ dragStart: function() {
647
+ $(this.element).addClass('drag');
648
+ this.children.each(function() { this.dragStart(); })
649
+ },
650
+ drop: function() {
651
+ $(this.element).removeClass('drag');
652
+ this.children.each(function() { this.drop(); })
653
+ this.adjust_level();
654
+ },
655
+ increment_level: function(event) {
656
+ var prev = $(this.element).prev().ttnode();
657
+ if(!prev || prev.level < this.level || this.depth() >= 5) return;
658
+ this.update_level(event, this.level + 1);
659
+ },
660
+ decrement_level: function(event) {
661
+ if(this.level == 0) return;
662
+ this.update_level(event, this.level - 1);
663
+ },
664
+ update_level: function(event, level) {
665
+ if (event) TableTree.startOffset = jQuery.tableDnD.getMouseOffset(this.element, event).x;
666
+
667
+ $(this.element).removeClass('level_' + this.level);
668
+ $(this.element).addClass('level_' + level);
669
+
670
+ this.level = level;
671
+ this.children.each(function() { this.update_level(event, level + 1); });
672
+ },
673
+ adjust_level: function() {
674
+ var prev = $(this.element).prev().ttnode();
675
+ if(!prev) {
676
+ this.update_level(null, 0);
677
+ } else if(prev.level + 1 < this.level) {
678
+ this.update_level(null, prev.level + 1);
679
+ }
680
+ },
681
+ update_children: function() {
682
+ this.children.each(function() { this.element.parentNode.removeChild(this.element); });
683
+ var _this = this;
684
+ var _next = _this.element.nextSibling;
685
+ this.children.each(function() { _this.element.parentNode.insertBefore(this.element, _next); });
686
+ this.children.each(function() { this.update_children() });
687
+ }
688
+ });
689
+
690
+ jQuery.fn.extend({
691
+ ttnode: function() {
692
+ var subject = this.push ? this[0] : this;
693
+ return TableTree.current_table.find_node(subject);
694
+ }
695
+ });
696
+
697
+ jQuery.extend(jQuery.tableDnD, {
698
+ teardown: function(table) {
699
+ jQuery('tr', table).each(function() { $(this).unbind('mousedown'); }).css('cursor', 'auto');
700
+ jQuery.tableDnD.dragObject = null;
701
+ jQuery.tableDnD.currentTable = null;
702
+ jQuery.tableDnD.mouseOffset = null;
703
+ }
704
+ });