Skip to content

Commit 4fcd29d

Browse files
committed
[BUG FIX] Order of dropped item was off by 1
Acts as list uses 1 based position, rather than 0 based order.
1 parent cc3160c commit 4fcd29d

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

app/assets/javascripts/cms/new-sitemap.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,20 @@ Sitemap.prototype.enableMenuButtons = function() {
139139

140140
// @param [Number] node_id
141141
// @param [Number] target_node_id
142-
// @param [Number] order
143-
Sitemap.prototype.move_to = function(node_id, target_node_id, order) {
142+
// @param [Number] position A 1 based position for order
143+
Sitemap.prototype.move_to = function(node_id, target_node_id, position) {
144144
var path = "/cms/section_nodes/" + node_id + '/move_to_position'
145145
$.cms_ajax.put({
146146
url: path,
147147
data: {
148148
target_node_id: target_node_id,
149-
position: order
149+
position: position
150150
},
151151
success: function(result) {
152152
sitemap.clickWebsite();
153153
}
154154
});
155-
console.log("Dropping node", node_id, "into", target_node_id, "at", order);
155+
console.log("Dropping node", node_id, "into", target_node_id, "at position", position);
156156

157157
};
158158
var sitemap = new Sitemap();
@@ -174,7 +174,7 @@ $(function() {
174174
stop: function(event, ui) {
175175
var parent_section = ui.item.parents('ul:first');
176176
var moving_node_id = ui.item.children('a:first').data('node-id');
177-
sitemap.move_to(moving_node_id, parent_section.data('node-id'), ui.item.index());
177+
sitemap.move_to(moving_node_id, parent_section.data('node-id'), ui.item.index() + 1);
178178
}
179179
});
180180

app/models/cms/section_node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def move_to(section, position)
7575
#This helps prevent the position from getting out of whack
7676
#If you pass in a really high number for position,
7777
#this just corrects it to the right number
78-
node_count =Cms::SectionNode.count(:conditions => {:ancestry => ancestry})
78+
node_count = Cms::SectionNode.count(:conditions => {:ancestry => ancestry})
7979
position = node_count if position > node_count
8080
end
8181

todo_ui_Revamp.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Tasks:
22

33
- Move sitemap items
44
-- [BUG] After moving a node, the section_node_ids are probably wrong. This means moving a node twice won't work (though it will appear to).
5-
-- [BUG] Can't move an item into the 'last' position in a section (It ends up as the 2nd to last).
65
-- It's hard visually to drop items into a section (especially if empty). (Should create obvious drop targets when you start dragging).
76
-- Need to expand sections as you pass over them.
87
-- Need an image/section name for hover element when it leaves a parent section.

0 commit comments

Comments
 (0)