adva 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/adva.gemspec +3 -0
- data/app/assets/config/manifest.js +6 -0
- data/app/assets/javascripts/adva_cms/ckeditor.js.erb +12 -0
- data/app/assets/javascripts/adva_cms/concat_main_menus.js +13 -0
- data/app/assets/javascripts/adva_cms/jquery.table_tree.js +704 -0
- data/app/assets/javascripts/adva_cms.js +7 -0
- data/app/assets/javascripts/ckeditor/config.js.erb +94 -0
- data/app/assets/stylesheets/adva_cms/admin/common.scss +15 -1
- data/app/assets/stylesheets/adva_cms/admin/projection.scss +2 -5
- data/app/assets/stylesheets/adva_cms/admin/sidebar.scss +30 -9
- data/app/assets/stylesheets/adva_cms/admin.scss +1 -1
- data/app/controllers/admin/base_controller.rb +10 -24
- data/app/controllers/admin/page/articles_controller.rb +8 -27
- data/app/controllers/admin/page/categories_controller.rb +6 -9
- data/app/controllers/admin/page/links_controller.rb +6 -9
- data/app/controllers/admin/sections_controller.rb +7 -9
- data/app/controllers/admin/sites_controller.rb +9 -12
- data/app/controllers/admin/users_controller.rb +6 -9
- data/app/controllers/articles_controller.rb +30 -52
- data/app/controllers/base_controller.rb +8 -8
- data/app/controllers/password_controller.rb +3 -5
- data/app/controllers/session_controller.rb +3 -5
- data/app/helpers/activities_helper.rb +9 -20
- data/app/helpers/admin/base_helper.rb +4 -22
- data/app/helpers/base_helper.rb +1 -1
- data/app/helpers/content_helper.rb +7 -5
- data/app/helpers/resource_helper.rb +4 -5
- data/app/helpers/users_helper.rb +1 -1
- data/app/models/activity.rb +3 -0
- data/app/models/article.rb +0 -11
- data/app/models/category.rb +3 -3
- data/app/models/content.rb +10 -39
- data/app/models/link.rb +0 -1
- data/app/models/password_mailer.rb +6 -9
- data/app/models/section.rb +6 -7
- data/app/models/site.rb +0 -2
- data/app/models/user.rb +1 -2
- data/app/views/activity_notifier/new_content_notification.html.erb +5 -5
- data/app/views/admin/activities/_activities.html.erb +4 -4
- data/app/views/admin/activities/_comment.html.erb +21 -21
- data/app/views/admin/activities/_content.html.erb +4 -3
- data/app/views/admin/activities/_topic.html.erb +5 -5
- data/app/views/admin/install/confirmation.html.erb +3 -3
- data/app/views/admin/install/index.html.erb +14 -14
- data/app/views/admin/page/articles/_form.html.erb +28 -25
- data/app/views/admin/page/articles/_options.html.erb +3 -4
- data/app/views/admin/page/articles/edit.html.erb +3 -3
- data/app/views/admin/page/articles/new.html.erb +4 -4
- data/app/views/admin/page/categories/edit.html.erb +9 -9
- data/app/views/admin/page/categories/index.html.erb +16 -16
- data/app/views/admin/page/categories/new.html.erb +5 -3
- data/app/views/admin/page/contents/index.html.erb +3 -18
- data/app/views/admin/page/links/_form.html.erb +17 -17
- data/app/views/admin/page/links/_options.html.erb +16 -19
- data/app/views/admin/page/links/edit.html.erb +3 -3
- data/app/views/admin/page/links/new.html.erb +3 -3
- data/app/views/admin/sections/_form.html.haml +5 -5
- data/app/views/admin/sections/edit.html.haml +2 -2
- data/app/views/admin/sections/index.html.erb +18 -18
- data/app/views/admin/sections/new.html.erb +15 -13
- data/app/views/admin/sections/settings/_page.html.haml +4 -6
- data/app/views/admin/shared/_header.html.erb +5 -4
- data/app/views/admin/shared/_section_tree.html.erb +2 -2
- data/app/views/admin/sites/_email_notifications.html.erb +6 -7
- data/app/views/admin/sites/_form.html.erb +7 -7
- data/app/views/admin/sites/_recent_users.html.erb +4 -2
- data/app/views/admin/sites/_unapproved_comments.html.erb +1 -1
- data/app/views/admin/sites/index.html.erb +1 -1
- data/app/views/admin/sites/new.html.erb +2 -2
- data/app/views/admin/sites/show.html.erb +7 -8
- data/app/views/admin/users/edit.html.erb +1 -1
- data/app/views/admin/users/index.html.erb +10 -10
- data/app/views/admin/users/new.html.erb +1 -1
- data/app/views/admin/users/show.html.erb +7 -7
- data/app/views/layouts/admin.html.haml +3 -5
- data/app/views/layouts/login.html.erb +1 -1
- data/app/views/password/edit.html.erb +12 -5
- data/app/views/password/new.html.erb +7 -7
- data/app/views/password_mailer/reset_password_email.html.erb +21 -1
- data/app/views/password_mailer/updated_password_email.html.erb +3 -1
- data/app/views/session/new.html.erb +9 -9
- data/app/views/shared/_flash.html.erb +2 -2
- data/app/views/shared/_sidebar.html.erb +2 -2
- data/config/initializers/ckeditor.rb +61 -0
- data/config/initializers/time_format.rb +2 -0
- data/lib/adva/authenticate_user.rb +193 -0
- data/lib/{active_record → adva}/belongs_to_author.rb +4 -4
- data/lib/adva/event.rb +34 -0
- data/lib/adva/extensible_forms.rb +285 -0
- data/lib/{has_options.rb → adva/has_options.rb} +5 -7
- data/lib/adva/has_permalink.rb +36 -0
- data/lib/adva/version.rb +1 -1
- data/lib/adva.rb +10 -36
- data/lib/rails_ext/action_controller/event_helper.rb +1 -1
- data/lib/rails_ext.rb +0 -9
- data/vendor/gems/cacheable_flash/.gitignore +8 -0
- data/vendor/gems/cacheable_flash/Gemfile +8 -0
- data/vendor/gems/cacheable_flash/README.md +35 -0
- data/vendor/gems/cacheable_flash/Rakefile +4 -0
- data/vendor/gems/cacheable_flash/bin/console +15 -0
- data/vendor/gems/cacheable_flash/bin/setup +8 -0
- data/vendor/gems/cacheable_flash/cacheable_flash.gemspec +38 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash/controller.rb +29 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash/javascript.js +19 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash/middleware.rb +30 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash/version.rb +5 -0
- data/vendor/gems/cacheable_flash/lib/cacheable_flash.rb +12 -0
- data/vendor/gems/simple_taggable/lib/tag_list.rb +1 -1
- data/vendor/gems/tags/lib/menu.rb +1 -1
- data/vendor/gems/tags/lib/tags/tag.rb +1 -1
- metadata +71 -144
- data/app/assets/javascripts/adva_cms/admin/jquery.admin.js +0 -23
- data/app/assets/javascripts/adva_cms/admin/jquery.article.js +0 -22
- data/app/assets/javascripts/adva_cms/admin/jquery.cached_pages.js +0 -14
- data/app/assets/javascripts/adva_cms/admin/jquery.table_tree.js +0 -7
- data/app/assets/javascripts/adva_cms/application.js +0 -13
- data/app/assets/javascripts/adva_cms/base.js +0 -4
- data/app/assets/javascripts/adva_cms/cookie.js +0 -49
- data/app/assets/javascripts/adva_cms/jquery/jquery-lowpro.js +0 -224
- data/app/assets/javascripts/adva_cms/jquery/jquery.qtip.js +0 -2085
- data/app/assets/javascripts/adva_cms/jquery/jquery.table_tree.js +0 -307
- data/app/assets/javascripts/adva_cms/jquery/jquery.tablednd_0_5.js +0 -386
- data/app/assets/javascripts/adva_cms/jquery.common.js +0 -41
- data/app/assets/javascripts/adva_cms/jquery.dates.js +0 -51
- data/app/assets/javascripts/adva_cms/jquery.flash.js +0 -59
- data/app/assets/javascripts/adva_cms/jquery.roles.js +0 -25
- data/app/assets/javascripts/adva_cms/json.js +0 -139
- data/app/controllers/admin/base_account_controller.rb +0 -13
- data/app/controllers/admin/install_controller.rb +0 -61
- data/app/controllers/admin/plugins_controller.rb +0 -38
- data/app/helpers/meta_tags_helper.rb +0 -30
- data/app/models/account.rb +0 -7
- data/app/models/event.rb +0 -34
- data/app/views/admin/articles/_meta_tags.html.erb +0 -7
- data/app/views/admin/cached_pages/_filter.html.erb +0 -8
- data/app/views/admin/cached_pages/destroy.js.erb +0 -18
- data/app/views/admin/cached_pages/index.html.erb +0 -26
- data/app/views/admin/plugins/_form.html.erb +0 -11
- data/app/views/admin/plugins/index.html.erb +0 -16
- data/app/views/admin/plugins/show.html.erb +0 -43
- data/app/views/admin/shared/_language_select.html.erb +0 -6
- data/app/views/admin/shared/_section_summary.html.erb +0 -23
- data/app/views/admin/sites/_meta_tags.html.erb +0 -15
- data/app/views/layouts/default.html.erb +0 -38
- data/app/views/layouts/simple.html.erb +0 -22
- data/app/views/shared/_footer.html.erb +0 -4
- data/app/views/shared/messages/insufficient_permissions.html.erb +0 -4
- data/config/initializers/article.rb +0 -8
- data/config/initializers/has_options.rb +0 -2
- data/config/initializers/has_permalink.rb +0 -2
- data/config/initializers/site.rb +0 -8
- data/config/locales/en.yml +0 -1319
- data/lib/action_controller/authenticate_anonymous.rb +0 -69
- data/lib/action_controller/authenticate_user.rb +0 -203
- data/lib/core_ext.rb +0 -7
- data/lib/extensible_forms.rb +0 -284
- data/lib/has_permalink.rb +0 -33
- data/lib/login/helper_integration.rb +0 -11
- data/lib/login/mail_config.rb +0 -39
- data/lib/rails_ext/action_controller/cacheable_flash.rb +0 -30
- data/lib/rails_ext/action_controller/content_for_assignments.rb +0 -106
- data/lib/rails_ext/action_controller/page_caching.rb +0 -23
- data/lib/rails_ext/action_controller/responds_to_parent.rb +0 -46
- data/lib/rails_ext/active_record/exists.rb +0 -5
- data/lib/rails_ext/active_record/sti_instantiation.rb +0 -35
- data/lib/rails_ext/active_record/sticky_changes.rb +0 -30
- data/lib/rails_ext/railties/plugin.rb +0 -58
- data/lib/rails_ext/railties/plugin_configuration.rb +0 -72
- data/lib/registry.rb +0 -49
- data/lib/tasks/translation.rake +0 -69
- data/lib/time_hacks.rb +0 -57
- data/lib/webrat_patch.rb +0 -11
- data/test/meta_tags_test.rb +0 -42
- data/vendor/gems/has_counter/.gitignore +0 -17
- data/vendor/gems/has_counter/Gemfile +0 -4
- data/vendor/gems/has_counter/LICENSE +0 -22
- data/vendor/gems/has_counter/MIT-LICENSE +0 -20
- data/vendor/gems/has_counter/README.markdown +0 -64
- data/vendor/gems/has_counter/README.md +0 -29
- data/vendor/gems/has_counter/Rakefile +0 -2
- data/vendor/gems/has_counter/db/migrate/20080601194338_create_counters_table.rb.rb +0 -13
- data/vendor/gems/has_counter/has_counter.gemspec +0 -17
- data/vendor/gems/has_counter/lib/active_record/has_counter.rb +0 -67
- data/vendor/gems/has_counter/lib/counter.rb +0 -23
- data/vendor/gems/has_counter/lib/has_counter/version.rb +0 -3
- data/vendor/gems/has_counter/lib/has_counter.rb +0 -4
- data/vendor/gems/has_counter/spec/has_counter.sqlite3.db +0 -0
- data/vendor/gems/has_counter/spec/has_counter_spec.rb +0 -55
- data/vendor/gems/has_counter/spec/spec_helper.rb +0 -117
- data/vendor/gems/has_filter/.gitignore +0 -17
- data/vendor/gems/has_filter/Gemfile +0 -4
- data/vendor/gems/has_filter/LICENSE +0 -22
- data/vendor/gems/has_filter/README.md +0 -29
- data/vendor/gems/has_filter/Rakefile +0 -2
- data/vendor/gems/has_filter/app/assets/images/has_filter/filter_add.png +0 -0
- data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_left.png +0 -0
- data/vendor/gems/has_filter/app/assets/images/has_filter/filter_button_right.png +0 -0
- data/vendor/gems/has_filter/app/assets/images/has_filter/filter_remove.png +0 -0
- data/vendor/gems/has_filter/app/assets/javascripts/has_filter/filter.js +0 -35
- data/vendor/gems/has_filter/app/assets/javascripts/has_filter/jquery.filter.js +0 -23
- data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/alternate/filter.scss +0 -102
- data/vendor/gems/has_filter/app/assets/stylesheets/has_filter/filter.scss +0 -100
- data/vendor/gems/has_filter/app/helpers/filter_helper.rb +0 -3
- data/vendor/gems/has_filter/has_filter.gemspec +0 -17
- data/vendor/gems/has_filter/init.rb +0 -3
- data/vendor/gems/has_filter/lib/has_filter/active_record/act_macro.rb +0 -102
- data/vendor/gems/has_filter/lib/has_filter/filter/base.rb +0 -67
- data/vendor/gems/has_filter/lib/has_filter/filter/categorized.rb +0 -24
- data/vendor/gems/has_filter/lib/has_filter/filter/chain.rb +0 -45
- data/vendor/gems/has_filter/lib/has_filter/filter/set.rb +0 -80
- data/vendor/gems/has_filter/lib/has_filter/filter/state.rb +0 -25
- data/vendor/gems/has_filter/lib/has_filter/filter/tagged.rb +0 -22
- data/vendor/gems/has_filter/lib/has_filter/filter/text.rb +0 -55
- data/vendor/gems/has_filter/lib/has_filter/filter.rb +0 -17
- data/vendor/gems/has_filter/lib/has_filter/version.rb +0 -3
- data/vendor/gems/has_filter/lib/has_filter.rb +0 -22
- data/vendor/gems/has_filter/test/db/setup.rb +0 -45
- data/vendor/gems/has_filter/test/db/test.sqlite3.db +0 -0
- data/vendor/gems/has_filter/test/fixtures.rb +0 -15
- data/vendor/gems/has_filter/test/has_filter/filter_chain_test.rb +0 -41
- data/vendor/gems/has_filter/test/has_filter/filter_scopes_test.rb +0 -102
- data/vendor/gems/has_filter/test/has_filter/filter_tags_test.rb +0 -113
- data/vendor/gems/has_filter/test/has_filter/integration.rb +0 -15
- data/vendor/gems/has_filter/test/has_filter/scopes_test.rb +0 -48
- data/vendor/gems/has_filter/test/log/test.log +0 -34346
- data/vendor/gems/has_filter/test/models.rb +0 -23
- data/vendor/gems/has_filter/test/templates/has_filter/test/index.html.erb +0 -5
- data/vendor/gems/has_filter/test/test_helper.rb +0 -66
- data/vendor/gems/xss_terminate/.gitignore +0 -17
- data/vendor/gems/xss_terminate/Gemfile +0 -4
- data/vendor/gems/xss_terminate/LICENSE +0 -22
- data/vendor/gems/xss_terminate/MIT-LICENSE +0 -20
- data/vendor/gems/xss_terminate/README +0 -94
- data/vendor/gems/xss_terminate/README.md +0 -29
- data/vendor/gems/xss_terminate/Rakefile +0 -23
- data/vendor/gems/xss_terminate/lib/html5lib_sanitize.rb +0 -2453
- data/vendor/gems/xss_terminate/lib/rails_sanitize.rb +0 -8
- data/vendor/gems/xss_terminate/lib/xss_terminate/version.rb +0 -3
- data/vendor/gems/xss_terminate/lib/xss_terminate.rb +0 -141
- data/vendor/gems/xss_terminate/tasks/xss_terminate_tasks.rake +0 -7
- data/vendor/gems/xss_terminate/test/models/comment.rb +0 -5
- data/vendor/gems/xss_terminate/test/models/entry.rb +0 -7
- data/vendor/gems/xss_terminate/test/models/message.rb +0 -3
- data/vendor/gems/xss_terminate/test/models/person.rb +0 -5
- data/vendor/gems/xss_terminate/test/models/review.rb +0 -5
- data/vendor/gems/xss_terminate/test/schema.rb +0 -34
- data/vendor/gems/xss_terminate/test/setup_test.rb +0 -16
- data/vendor/gems/xss_terminate/test/xss_terminate_test.rb +0 -50
- data/vendor/gems/xss_terminate/xss_terminate.gemspec +0 -17
- /data/lib/tasks/{adva_cms.rake → adva.rake} +0 -0
@@ -1,307 +0,0 @@
|
|
1
|
-
TableTree = {
|
2
|
-
tableDnDOptions: {
|
3
|
-
onDragClass: 'drag',
|
4
|
-
onDragStart: function(table, row) {
|
5
|
-
TableTree.startOffset = jQuery.tableDnD.mouseOffset.x;
|
6
|
-
$(row).mousemove(TableTree.mousemove);
|
7
|
-
if (node = $(row).ttnode()) node.dragStart();
|
8
|
-
},
|
9
|
-
onDrag: function(table, row) {
|
10
|
-
TableTree.current_table.dirty = true;
|
11
|
-
if (node = $(row).ttnode()) node.update_children();
|
12
|
-
},
|
13
|
-
onDrop: function(table, row) {
|
14
|
-
$(row).unbind('mousemove', TableTree.mousemove);
|
15
|
-
if (node = $(row).ttnode()) node.drop();
|
16
|
-
TableTree.current_table.rebuild();
|
17
|
-
TableTree.current_table.update_remote(row);
|
18
|
-
},
|
19
|
-
onAllowDrop: function(draggedRow, row, movingDown) {
|
20
|
-
var node = $(row).ttnode();
|
21
|
-
next = movingDown ? $(node.next_row_sibling()).ttnode() : node;
|
22
|
-
if (next && (next.parent.level >= $(draggedRow).ttnode().level)) return false;
|
23
|
-
return $(row).ttnode() ? true : false;
|
24
|
-
}
|
25
|
-
},
|
26
|
-
toggle: function(table, type, collection_url) {
|
27
|
-
TableTree.current_table ? TableTree.teardown(table) : TableTree.setup(table, type, collection_url);
|
28
|
-
},
|
29
|
-
setup: function(table, type, collection_url) {
|
30
|
-
$('tbody', table).tableDnD(TableTree.tableDnDOptions);
|
31
|
-
TableTree.current_table = new TableTree.Table($(table).get(0), type, collection_url);
|
32
|
-
TableTree.current_table.setSortable();
|
33
|
-
},
|
34
|
-
teardown: function(table) {
|
35
|
-
// TableTree.current_table.update_remote();
|
36
|
-
jQuery.tableDnD.teardown(table);
|
37
|
-
TableTree.current_table.setUnsortable();
|
38
|
-
TableTree.current_table = null;
|
39
|
-
},
|
40
|
-
level: function(element) {
|
41
|
-
var match = element.className.match(/level_([\d]+)/);
|
42
|
-
return match ? parseInt(match[1]) : 0;
|
43
|
-
},
|
44
|
-
mousemove: function(event) {
|
45
|
-
if (!TableTree.current_table.is_tree) return;
|
46
|
-
|
47
|
-
var offset = jQuery.tableDnD.getMouseOffset(this, event).x - TableTree.startOffset;
|
48
|
-
if(offset > 25) {
|
49
|
-
TableTree.current_table.dirty = true;
|
50
|
-
$(this).ttnode().increment_level(event);
|
51
|
-
} else if(offset < -25) {
|
52
|
-
TableTree.current_table.dirty = true;
|
53
|
-
$(this).ttnode().decrement_level(event);
|
54
|
-
}
|
55
|
-
},
|
56
|
-
Base: function() {},
|
57
|
-
Table: function(table, type, collection_url) {
|
58
|
-
this.is_tree = $(table).hasClass('tree')
|
59
|
-
this.table = table; //$('tbody', table)
|
60
|
-
this.type = type;
|
61
|
-
this.level = -1;
|
62
|
-
this.collection_url = collection_url;
|
63
|
-
this.rebuild();
|
64
|
-
},
|
65
|
-
Node: function(parent, element, level) {
|
66
|
-
var _this = this;
|
67
|
-
this.parent = parent;
|
68
|
-
this.element = element;
|
69
|
-
this.level = level;
|
70
|
-
|
71
|
-
this.children = this.find_children().map(function() {
|
72
|
-
var level = TableTree.level(this);
|
73
|
-
if(level == _this.level + 1) { return new TableTree.Node(_this, this, level); }
|
74
|
-
});
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
TableTree.Base.prototype = {
|
79
|
-
find_node: function(element) {
|
80
|
-
for (var i = 0; i < this.children.length; i++) {
|
81
|
-
var child = this.children[i];
|
82
|
-
if (this.children[i].element == element) {
|
83
|
-
return this.children[i];
|
84
|
-
} else {
|
85
|
-
var result = this.children[i].find_node(element);
|
86
|
-
if (result) return result;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}
|
90
|
-
}
|
91
|
-
TableTree.Table.prototype = jQuery.extend(new TableTree.Base(), {
|
92
|
-
rebuild: function() {
|
93
|
-
var _this = this;
|
94
|
-
this.children = $('tr', this.table).map(function() {
|
95
|
-
if(TableTree.level(this) == 0) { return new TableTree.Node(_this, this, TableTree.level(this)); }
|
96
|
-
});
|
97
|
-
},
|
98
|
-
setSortable: function() {
|
99
|
-
$('tr', this.table).each(function() {
|
100
|
-
// thead
|
101
|
-
cells = $('th', this);
|
102
|
-
cells.each(function(ix) {
|
103
|
-
if(ix == 0) {
|
104
|
-
this.setAttribute('colspan', cells.length);
|
105
|
-
} else {
|
106
|
-
$(this).hide();
|
107
|
-
}
|
108
|
-
});
|
109
|
-
|
110
|
-
// tbody
|
111
|
-
cells = $('td', this);
|
112
|
-
cells.each(function(ix) {
|
113
|
-
if (ix == 0) {
|
114
|
-
element = this;
|
115
|
-
this.setAttribute('colspan', cells.length);
|
116
|
-
$('a', this).each(function() {
|
117
|
-
$(this).hide();
|
118
|
-
element.appendChild(document.createTextNode($(this).text()))
|
119
|
-
});
|
120
|
-
} else {
|
121
|
-
$(this).hide();
|
122
|
-
}
|
123
|
-
});
|
124
|
-
});
|
125
|
-
},
|
126
|
-
setUnsortable: function() {
|
127
|
-
$('tr', this.table).each(function(ix) {
|
128
|
-
// thead
|
129
|
-
cells = $('th', this);
|
130
|
-
cells.each(function(ix) {
|
131
|
-
if(ix == 0) {
|
132
|
-
this.setAttribute('colspan', 1);
|
133
|
-
} else {
|
134
|
-
$(this).show();
|
135
|
-
}
|
136
|
-
});
|
137
|
-
|
138
|
-
// tbody
|
139
|
-
$('td', this).each(function(ix) {
|
140
|
-
if(ix == 0) {
|
141
|
-
$('a', this).each(function() {
|
142
|
-
$(this).show();
|
143
|
-
});
|
144
|
-
$('img.spinner', this).remove();
|
145
|
-
this.removeChild(this.lastChild);
|
146
|
-
this.setAttribute('colspan', 1);
|
147
|
-
} else {
|
148
|
-
$(this).show();
|
149
|
-
}
|
150
|
-
});
|
151
|
-
});
|
152
|
-
},
|
153
|
-
update_remote: function(row) {
|
154
|
-
if(!this.dirty) return;
|
155
|
-
this.dirty = false;
|
156
|
-
_this = this;
|
157
|
-
|
158
|
-
this.show_spinner(row);
|
159
|
-
$.ajax({
|
160
|
-
type: "POST",
|
161
|
-
url: this.collection_url,
|
162
|
-
data: jQuery.extend(this.serialize(row), { authenticity_token: window._auth_token, '_method': 'put' }),
|
163
|
-
success: function(msg) { _this.hide_spinner(row); },
|
164
|
-
error: function(msg) { _this.hide_spinner(row); }
|
165
|
-
});
|
166
|
-
},
|
167
|
-
serialize: function(row) {
|
168
|
-
row = $(row).ttnode();
|
169
|
-
data = {};
|
170
|
-
data[this.type + '[' + row.id() + '][parent_id]'] = row.parent_id();
|
171
|
-
data[this.type +'[' + row.id() + '][left_id]'] = row.left_id();
|
172
|
-
return data;
|
173
|
-
},
|
174
|
-
show_spinner: function(row) {
|
175
|
-
img = document.createElement('img');
|
176
|
-
img.src = 'data:image/gif;base64,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';
|
177
|
-
img.className = 'spinner';
|
178
|
-
$('td', row)[0].appendChild(img);
|
179
|
-
},
|
180
|
-
hide_spinner: function(row) {
|
181
|
-
cell = $('td', row)[0];
|
182
|
-
cell.removeChild(cell.lastChild);
|
183
|
-
}
|
184
|
-
});
|
185
|
-
|
186
|
-
TableTree.Node.prototype = jQuery.extend(new TableTree.Base(), {
|
187
|
-
find_children: function() {
|
188
|
-
var lvl = this.level;
|
189
|
-
var stop = false;
|
190
|
-
return this.row_siblings().slice(this.row_index() + 1).filter(function() {
|
191
|
-
var level = TableTree.level(this);
|
192
|
-
if(lvl == level) stop = true; // how to break from a jquery iterator?
|
193
|
-
return !stop && lvl + 1 == level;
|
194
|
-
});
|
195
|
-
},
|
196
|
-
depth: function() {
|
197
|
-
if (this.children.length > 0) {
|
198
|
-
return Math.max.apply(Math, this.children.map(function() { return this.depth() }).get());
|
199
|
-
} else {
|
200
|
-
return this.level;
|
201
|
-
}
|
202
|
-
},
|
203
|
-
siblings: function() {
|
204
|
-
return this.parent.children;
|
205
|
-
},
|
206
|
-
id: function() {
|
207
|
-
return this.element ? this.to_int(this.element.id) : 'null';
|
208
|
-
},
|
209
|
-
parent_id: function() {
|
210
|
-
return this.parent.element ? this.to_int(this.parent.element.id) : 'null';
|
211
|
-
},
|
212
|
-
left_id: function() {
|
213
|
-
left = this.left()
|
214
|
-
return left ? this.to_int(left.element.id) : 'null';
|
215
|
-
},
|
216
|
-
left: function() {
|
217
|
-
siblings = this.siblings().get();
|
218
|
-
ix = siblings.indexOf(this) - 1;
|
219
|
-
if(ix >= 0) return siblings[ix];
|
220
|
-
},
|
221
|
-
to_int: function(str) {
|
222
|
-
if(str) return str.replace(/[\D]+/, '')
|
223
|
-
},
|
224
|
-
next_row_sibling: function () {
|
225
|
-
return this.row_siblings()[this.row_index() + 1];
|
226
|
-
},
|
227
|
-
row_siblings: function() {
|
228
|
-
if(!this._row_siblings) { this._row_siblings = $(this.element).parent().children(); }
|
229
|
-
return this._row_siblings;
|
230
|
-
},
|
231
|
-
row_index: function() {
|
232
|
-
return this.row_siblings().get().indexOf(this.element);
|
233
|
-
},
|
234
|
-
dragStart: function() {
|
235
|
-
$(this.element).addClass('drag');
|
236
|
-
this.children.each(function() { this.dragStart(); })
|
237
|
-
},
|
238
|
-
drop: function() {
|
239
|
-
$(this.element).removeClass('drag');
|
240
|
-
this.children.each(function() { this.drop(); })
|
241
|
-
this.adjust_level();
|
242
|
-
},
|
243
|
-
increment_level: function(event) {
|
244
|
-
var prev = $(this.element).prev().ttnode();
|
245
|
-
if(!prev || prev.level < this.level || this.depth() >= 5) return;
|
246
|
-
this.update_level(event, this.level + 1);
|
247
|
-
},
|
248
|
-
decrement_level: function(event) {
|
249
|
-
if(this.level == 0) return;
|
250
|
-
this.update_level(event, this.level - 1);
|
251
|
-
},
|
252
|
-
update_level: function(event, level) {
|
253
|
-
if (event) TableTree.startOffset = jQuery.tableDnD.getMouseOffset(this.element, event).x;
|
254
|
-
|
255
|
-
$(this.element).removeClass('level_' + this.level);
|
256
|
-
$(this.element).addClass('level_' + level);
|
257
|
-
|
258
|
-
this.level = level;
|
259
|
-
this.children.each(function() { this.update_level(event, level + 1); });
|
260
|
-
},
|
261
|
-
adjust_level: function() {
|
262
|
-
var prev = $(this.element).prev().ttnode();
|
263
|
-
if(!prev) {
|
264
|
-
this.update_level(null, 0);
|
265
|
-
} else if(prev.level + 1 < this.level) {
|
266
|
-
this.update_level(null, prev.level + 1);
|
267
|
-
}
|
268
|
-
},
|
269
|
-
update_children: function() {
|
270
|
-
this.children.each(function() { this.element.parentNode.removeChild(this.element); });
|
271
|
-
var _this = this;
|
272
|
-
var _next = _this.element.nextSibling;
|
273
|
-
this.children.each(function() { _this.element.parentNode.insertBefore(this.element, _next); });
|
274
|
-
this.children.each(function() { this.update_children() });
|
275
|
-
}
|
276
|
-
});
|
277
|
-
|
278
|
-
jQuery.fn.extend({
|
279
|
-
ttnode: function() {
|
280
|
-
var subject = this.push ? this[0] : this;
|
281
|
-
return TableTree.current_table.find_node(subject);
|
282
|
-
}
|
283
|
-
});
|
284
|
-
|
285
|
-
jQuery.extend(jQuery.tableDnD, {
|
286
|
-
teardown: function(table) {
|
287
|
-
jQuery('tr', table).each(function() { $(this).unbind('mousedown'); }).css('cursor', 'auto');
|
288
|
-
jQuery.tableDnD.dragObject = null;
|
289
|
-
jQuery.tableDnD.currentTable = null;
|
290
|
-
jQuery.tableDnD.mouseOffset = null;
|
291
|
-
}
|
292
|
-
});
|
293
|
-
//
|
294
|
-
// tableDnD {
|
295
|
-
// toggle: function() {
|
296
|
-
// if (table.hasClass('tree')) {
|
297
|
-
// setupTree()
|
298
|
-
// }
|
299
|
-
// }
|
300
|
-
// // aslödkjföksdfk
|
301
|
-
// Tree {
|
302
|
-
//
|
303
|
-
// }
|
304
|
-
// }
|
305
|
-
//
|
306
|
-
//
|
307
|
-
//
|
@@ -1,386 +0,0 @@
|
|
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
|
-
// TODO worry about what happens when there are multiple TBODIES
|
273
|
-
if (movingDown && jQuery.tableDnD.dragObject != currentRow) {
|
274
|
-
jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);
|
275
|
-
} else if (! movingDown && jQuery.tableDnD.dragObject != currentRow) {
|
276
|
-
jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);
|
277
|
-
}
|
278
|
-
if (config.onDrag) {
|
279
|
-
config.onDrag(jQuery.tableDnD.currentTable, jQuery.tableDnD.dragObject);
|
280
|
-
}
|
281
|
-
}
|
282
|
-
}
|
283
|
-
|
284
|
-
return false;
|
285
|
-
},
|
286
|
-
|
287
|
-
/** We're only worried about the y position really, because we can only move rows up and down */
|
288
|
-
findDropTargetRow: function(draggedRow, y, movingDown) {
|
289
|
-
var rows = jQuery.tableDnD.currentTable.rows;
|
290
|
-
for (var i=0; i<rows.length; i++) {
|
291
|
-
var row = rows[i];
|
292
|
-
var rowY = this.getPosition(row).y;
|
293
|
-
var rowHeight = parseInt(row.offsetHeight)/2;
|
294
|
-
if (row.offsetHeight == 0) {
|
295
|
-
rowY = this.getPosition(row.firstChild).y;
|
296
|
-
rowHeight = parseInt(row.firstChild.offsetHeight)/2;
|
297
|
-
}
|
298
|
-
// Because we always have to insert before, we need to offset the height a bit
|
299
|
-
if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
|
300
|
-
// that's the row we're over
|
301
|
-
// If it's the same as the current row, ignore it
|
302
|
-
if (row == draggedRow.get(0)) {return null;}
|
303
|
-
var config = jQuery.tableDnD.currentTable.tableDnDConfig;
|
304
|
-
if (config.onAllowDrop) {
|
305
|
-
if (config.onAllowDrop(draggedRow, row, movingDown)) {
|
306
|
-
return row;
|
307
|
-
} else {
|
308
|
-
return null;
|
309
|
-
}
|
310
|
-
} else {
|
311
|
-
// If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)
|
312
|
-
var nodrop = $(row).hasClass("nodrop");
|
313
|
-
if (! nodrop) {
|
314
|
-
return row;
|
315
|
-
} else {
|
316
|
-
return null;
|
317
|
-
}
|
318
|
-
}
|
319
|
-
return row;
|
320
|
-
}
|
321
|
-
}
|
322
|
-
return null;
|
323
|
-
},
|
324
|
-
|
325
|
-
mouseup: function(e) {
|
326
|
-
if (jQuery.tableDnD.currentTable && jQuery.tableDnD.dragObject) {
|
327
|
-
var droppedRow = jQuery.tableDnD.dragObject;
|
328
|
-
var config = jQuery.tableDnD.currentTable.tableDnDConfig;
|
329
|
-
// If we have a dragObject, then we need to release it,
|
330
|
-
// The row will already have been moved to the right place so we just reset stuff
|
331
|
-
if (config.onDragClass) {
|
332
|
-
jQuery(droppedRow).removeClass(config.onDragClass);
|
333
|
-
} else {
|
334
|
-
jQuery(droppedRow).css(config.onDropStyle);
|
335
|
-
}
|
336
|
-
jQuery.tableDnD.dragObject = null;
|
337
|
-
if (config.onDrop) {
|
338
|
-
// Call the onDrop method if there is one
|
339
|
-
config.onDrop(jQuery.tableDnD.currentTable, droppedRow);
|
340
|
-
}
|
341
|
-
jQuery.tableDnD.currentTable = null; // let go of the table too
|
342
|
-
}
|
343
|
-
},
|
344
|
-
|
345
|
-
serialize: function() {
|
346
|
-
if (jQuery.tableDnD.currentTable) {
|
347
|
-
return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);
|
348
|
-
} else {
|
349
|
-
return "Error: No Table id set, you need to set an id on your table and every row";
|
350
|
-
}
|
351
|
-
},
|
352
|
-
|
353
|
-
serializeTable: function(table) {
|
354
|
-
var result = "";
|
355
|
-
var tableId = table.id;
|
356
|
-
var rows = table.rows;
|
357
|
-
for (var i=0; i<rows.length; i++) {
|
358
|
-
if (result.length > 0) result += "&";
|
359
|
-
var rowId = rows[i].id;
|
360
|
-
if (rowId && rowId && table.tableDnDConfig && table.tableDnDConfig.serializeRegexp) {
|
361
|
-
rowId = rowId.match(table.tableDnDConfig.serializeRegexp)[0];
|
362
|
-
}
|
363
|
-
|
364
|
-
result += tableId + '[]=' + rows[i].id;
|
365
|
-
}
|
366
|
-
return result;
|
367
|
-
},
|
368
|
-
|
369
|
-
serializeTables: function() {
|
370
|
-
var result = "";
|
371
|
-
this.each(function() {
|
372
|
-
// this is now bound to each matching table
|
373
|
-
result += jQuery.tableDnD.serializeTable(this);
|
374
|
-
});
|
375
|
-
return result;
|
376
|
-
}
|
377
|
-
|
378
|
-
}
|
379
|
-
|
380
|
-
jQuery.fn.extend(
|
381
|
-
{
|
382
|
-
tableDnD : jQuery.tableDnD.build,
|
383
|
-
tableDnDUpdate : jQuery.tableDnD.updateTables,
|
384
|
-
tableDnDSerialize: jQuery.tableDnD.serializeTables
|
385
|
-
}
|
386
|
-
);
|