mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 15:22:41 +01:00
fae23e0860
Summary: Ref T5476. Currently, the task edit code assumes it knows what the UI looks like and sends back where on the column an item should be inserted. This is buggy after adding filters, and relatively complex. Instead, send down the ordering on the whole column and sort it in the UI. This is a bit simpler overall and more general. It makes it easier to further generalize this code for T5476. Test Plan: - Edited a task on a board, changing priority. Saw it reorder properly. - Edited a task on a board in a field of other tasks at the same top-level priority. Saw it refresh without reordering. Reviewers: chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T5476 Differential Revision: https://secure.phabricator.com/D9832
173 lines
4.5 KiB
JavaScript
173 lines
4.5 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-project-boards
|
|
* @requires javelin-behavior
|
|
* javelin-dom
|
|
* javelin-util
|
|
* javelin-stratcom
|
|
* javelin-workflow
|
|
* phabricator-draggable-list
|
|
*/
|
|
|
|
JX.behavior('project-boards', function(config) {
|
|
|
|
function finditems(col) {
|
|
return JX.DOM.scry(col, 'li', 'project-card');
|
|
}
|
|
|
|
function onupdate(node) {
|
|
JX.DOM.alterClass(node, 'project-column-empty', !this.findItems().length);
|
|
}
|
|
|
|
function onresponse(response, item, list) {
|
|
list.unlock();
|
|
JX.DOM.alterClass(item, 'drag-sending', false);
|
|
JX.DOM.replace(item, JX.$H(response.task));
|
|
}
|
|
|
|
function colsort(u, v) {
|
|
var ud = JX.Stratcom.getData(u).sort || [];
|
|
var vd = JX.Stratcom.getData(v).sort || [];
|
|
|
|
for (var ii = 0; ii < ud.length; ii++) {
|
|
if (ud[ii] < vd[ii]) {
|
|
return 1;
|
|
}
|
|
if (ud[ii] > vd[ii]) {
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
function ondrop(list, item, after) {
|
|
list.lock();
|
|
JX.DOM.alterClass(item, 'drag-sending', true);
|
|
|
|
var item_phid = JX.Stratcom.getData(item).objectPHID;
|
|
var data = {
|
|
objectPHID: item_phid,
|
|
columnPHID: JX.Stratcom.getData(list.getRootNode()).columnPHID
|
|
};
|
|
|
|
var after_phid = null;
|
|
var items = finditems(list.getRootNode());
|
|
if (after) {
|
|
after_phid = JX.Stratcom.getData(after).objectPHID;
|
|
data.afterPHID = after_phid;
|
|
}
|
|
var ii;
|
|
var ii_item;
|
|
var ii_item_phid;
|
|
var ii_prev_item_phid = null;
|
|
var before_phid = null;
|
|
for (ii = 0; ii < items.length; ii++) {
|
|
ii_item = items[ii];
|
|
ii_item_phid = JX.Stratcom.getData(ii_item).objectPHID;
|
|
if (ii_item_phid == item_phid) {
|
|
// skip the item we just dropped
|
|
continue;
|
|
}
|
|
// note this handles when there is no after phid - we are at the top of
|
|
// the list - quite nicely
|
|
if (ii_prev_item_phid == after_phid) {
|
|
before_phid = ii_item_phid;
|
|
break;
|
|
}
|
|
ii_prev_item_phid = ii_item_phid;
|
|
}
|
|
if (before_phid) {
|
|
data.beforePHID = before_phid;
|
|
}
|
|
|
|
var workflow = new JX.Workflow(config.moveURI, data)
|
|
.setHandler(function(response) {
|
|
onresponse(response, item, list);
|
|
});
|
|
|
|
workflow.start();
|
|
}
|
|
|
|
var lists = [];
|
|
var ii;
|
|
var cols = JX.DOM.scry(JX.$(config.boardID), 'ul', 'project-column');
|
|
|
|
for (ii = 0; ii < cols.length; ii++) {
|
|
var list = new JX.DraggableList('project-card', cols[ii])
|
|
.setFindItemsHandler(JX.bind(null, finditems, cols[ii]));
|
|
|
|
list.listen('didSend', JX.bind(list, onupdate, cols[ii]));
|
|
list.listen('didReceive', JX.bind(list, onupdate, cols[ii]));
|
|
|
|
list.listen('didDrop', JX.bind(null, ondrop, list));
|
|
|
|
lists.push(list);
|
|
}
|
|
|
|
for (ii = 0; ii < lists.length; ii++) {
|
|
lists[ii].setGroup(lists);
|
|
}
|
|
|
|
var onedit = function(card, column, r) {
|
|
var new_card = JX.$H(r.tasks).getNode();
|
|
var new_data = JX.Stratcom.getData(new_card);
|
|
var items = finditems(column);
|
|
|
|
for (var ii = 0; ii < items.length; ii++) {
|
|
var item = items[ii];
|
|
|
|
var data = JX.Stratcom.getData(item);
|
|
var phid = data.objectPHID;
|
|
|
|
if (phid == new_data.objectPHID) {
|
|
items[ii] = new_card;
|
|
data = new_data;
|
|
}
|
|
|
|
data.sort = r.data.sortMap[data.objectPHID] || data.sort;
|
|
}
|
|
|
|
items.sort(colsort);
|
|
|
|
JX.DOM.setContent(column, items);
|
|
};
|
|
|
|
JX.Stratcom.listen(
|
|
'click',
|
|
['edit-project-card'],
|
|
function(e) {
|
|
e.kill();
|
|
var card = e.getNode('project-card');
|
|
var column = e.getNode('project-column');
|
|
var request_data = {
|
|
'responseType' : 'card',
|
|
'columnPHID' : JX.Stratcom.getData(column).columnPHID };
|
|
new JX.Workflow(e.getNode('tag:a').href, request_data)
|
|
.setHandler(JX.bind(null, onedit, card, column))
|
|
.start();
|
|
});
|
|
|
|
JX.Stratcom.listen(
|
|
'click',
|
|
['column-add-task'],
|
|
function (e) {
|
|
e.kill();
|
|
var column_phid = e.getNodeData('column-add-task').columnPHID;
|
|
var request_data = {
|
|
'responseType' : 'card',
|
|
'columnPHID' : column_phid,
|
|
'projects' : config.projectPHID };
|
|
var cols = JX.DOM.scry(JX.$(config.boardID), 'ul', 'project-column');
|
|
var ii;
|
|
var column;
|
|
for (ii = 0; ii < cols.length; ii++) {
|
|
if (JX.Stratcom.getData(cols[ii]).columnPHID == column_phid) {
|
|
column = cols[ii];
|
|
break;
|
|
}
|
|
}
|
|
new JX.Workflow(config.createURI, request_data)
|
|
.setHandler(JX.bind(null, onedit, null, column))
|
|
.start();
|
|
});
|
|
});
|