1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 07:50:57 +01:00
phorge-phorge/webroot/rsrc/js/application/projects/behavior-project-boards.js

134 lines
3.5 KiB
JavaScript
Raw Normal View History

/**
* @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 ondrop(list, item, after, from) {
list.lock();
JX.DOM.alterClass(item, 'drag-sending', true);
var data = {
objectPHID: JX.Stratcom.getData(item).objectPHID,
columnPHID: JX.Stratcom.getData(list.getRootNode()).columnPHID
};
if (after) {
data.afterPHID = JX.Stratcom.getData(after).objectPHID;
}
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);
var items = finditems(column);
var insert_after = r.data.insertAfterPHID;
if (!insert_after) {
JX.DOM.prependContent(column, new_card);
if (card) {
JX.DOM.remove(card);
}
return;
}
var ii;
var item;
var item_phid;
for (ii = 0; ii< items.length; ii++) {
item = items[ii];
item_phid = JX.Stratcom.getData(item).objectPHID;
if (item_phid == insert_after) {
JX.DOM.replace(item, [item, new_card]);
if (card) {
JX.DOM.remove(card);
}
return;
}
}
};
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();
});
});