phorge/webroot/rsrc/js/application/projects/behavior-reorder-columns.js
epriestley 24a6eeb8d8 Allow the workboard backlog column to be reordered
Summary:
Fixes T5677.

  - Instead of using `sequence == 0` to mean "this is the backlog column", flag the column explicitly.
  - Migrate existing sequence 0 columns to have the flag.
  - Add the flag when initializing or copying a board.
  - Remove special backlog logic when reordering columns.

Test Plan:
  - Migrated columns, viewed some boards, they looked identical.
  - Reordered the backlog column a bunch of times (first, last, middle, dragged other stuff around).
  - Added tasks to a project, saw them show up in the reordered backlog.
  - Initialized a new board and saw a backlog column show up.
  - Copied an existing board and saw the backlog column come over.
  - Tried to hide a backlog column.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5677

Differential Revision: https://secure.phabricator.com/D10189
2014-08-08 15:50:36 -07:00

59 lines
1.5 KiB
JavaScript

/**
* @provides javelin-behavior-reorder-columns
* @requires javelin-behavior
* javelin-stratcom
* javelin-workflow
* javelin-dom
* phabricator-draggable-list
*/
JX.behavior('reorder-columns', function(config) {
var root = JX.$(config.listID);
var list = new JX.DraggableList('board-column', root)
.setFindItemsHandler(function() {
return JX.DOM.scry(root, 'li', 'board-column');
});
list.listen('didDrop', function(node) {
var nodes = list.findItems();
var node_data = JX.Stratcom.getData(node);
// Find the column sequence of the previous node.
var sequence = null;
var data;
for (var ii = 0; ii < nodes.length; ii++) {
data = JX.Stratcom.getData(nodes[ii]);
if (data.columnPHID === node_data.columnPHID) {
break;
}
sequence = data.columnSequence;
}
list.lock();
JX.DOM.alterClass(node, 'drag-sending', true);
var parameters = {
columnPHID: node_data.columnPHID,
sequence: (sequence === null) ? 0 : (parseInt(sequence, 10) + 1)
};
new JX.Workflow(config.reorderURI, parameters)
.setHandler(function(r) {
// Adjust metadata for the new sequence numbers.
for (var ii = 0; ii < nodes.length; ii++) {
var data = JX.Stratcom.getData(nodes[ii]);
data.columnSequence = r.sequenceMap[data.columnPHID];
}
list.unlock();
JX.DOM.alterClass(node, 'drag-sending', false);
})
.start();
});
});