2014-01-13 21:23:57 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-project-boards
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-util
|
2014-01-13 21:24:36 +01:00
|
|
|
* javelin-stratcom
|
|
|
|
* javelin-workflow
|
2014-01-13 21:23:57 +01:00
|
|
|
* phabricator-draggable-list
|
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('project-boards', function(config) {
|
|
|
|
|
|
|
|
function finditems(col) {
|
|
|
|
return JX.DOM.scry(col, 'li', 'project-card');
|
|
|
|
}
|
|
|
|
|
2014-01-13 21:24:13 +01:00
|
|
|
function onupdate(node) {
|
|
|
|
JX.DOM.alterClass(node, 'project-column-empty', !this.findItems().length);
|
|
|
|
}
|
|
|
|
|
2014-01-13 21:24:36 +01:00
|
|
|
function onresponse(response) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function ondrop(list, item, after, from) {
|
|
|
|
list.lock();
|
|
|
|
JX.DOM.alterClass(item, 'drag-sending', true);
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
objectPHID: JX.Stratcom.getData(item).objectPHID,
|
2014-03-04 00:58:00 +01:00
|
|
|
columnPHID: JX.Stratcom.getData(list.getRootNode()).columnPHID
|
2014-01-13 21:24:36 +01:00
|
|
|
};
|
|
|
|
|
2014-03-04 00:58:00 +01:00
|
|
|
if (after) {
|
|
|
|
data.afterPHID = JX.Stratcom.getData(after).objectPHID;
|
|
|
|
}
|
|
|
|
|
2014-01-13 21:24:36 +01:00
|
|
|
var workflow = new JX.Workflow(config.moveURI, data)
|
|
|
|
.setHandler(function(response) {
|
|
|
|
onresponse(response);
|
|
|
|
list.unlock();
|
|
|
|
|
|
|
|
JX.DOM.alterClass(item, 'drag-sending', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
workflow.start();
|
|
|
|
}
|
|
|
|
|
2014-01-13 21:23:57 +01:00
|
|
|
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]));
|
2014-01-13 21:24:13 +01:00
|
|
|
|
|
|
|
list.listen('didSend', JX.bind(list, onupdate, cols[ii]));
|
|
|
|
list.listen('didReceive', JX.bind(list, onupdate, cols[ii]));
|
|
|
|
|
2014-01-13 21:24:36 +01:00
|
|
|
list.listen('didDrop', JX.bind(null, ondrop, list));
|
|
|
|
|
2014-01-13 21:23:57 +01:00
|
|
|
lists.push(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ii = 0; ii < lists.length; ii++) {
|
|
|
|
lists[ii].setGroup(lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|