2014-05-16 04:12:40 +02:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-dashboard-move-panels
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-util
|
|
|
|
* javelin-stratcom
|
|
|
|
* javelin-workflow
|
|
|
|
* phabricator-draggable-list
|
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('dashboard-move-panels', function(config) {
|
|
|
|
|
2017-02-14 23:08:56 +01:00
|
|
|
var itemSigil = 'panel-movable';
|
2014-05-16 04:12:40 +02:00
|
|
|
|
|
|
|
function finditems(col) {
|
|
|
|
return JX.DOM.scry(col, 'div', itemSigil);
|
|
|
|
}
|
|
|
|
|
|
|
|
function markcolempty(col, toggle) {
|
2019-04-13 01:50:59 +02:00
|
|
|
JX.DOM.alterClass(col.parentNode, 'dashboard-column-empty', toggle);
|
2014-05-16 04:12:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onupdate(col) {
|
|
|
|
markcolempty(col, !this.findItems().length);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onresponse(response, item, list) {
|
|
|
|
list.unlock();
|
|
|
|
JX.DOM.alterClass(item, 'drag-sending', false);
|
|
|
|
}
|
|
|
|
|
2014-06-23 19:27:47 +02:00
|
|
|
function ondrop(list, item, after) {
|
2014-05-16 04:12:40 +02:00
|
|
|
list.lock();
|
|
|
|
JX.DOM.alterClass(item, 'drag-sending', true);
|
|
|
|
|
|
|
|
var data = {
|
2019-04-12 21:06:11 +02:00
|
|
|
panelKey: JX.Stratcom.getData(item).panelKey,
|
|
|
|
columnKey: JX.Stratcom.getData(list.getRootNode()).columnKey
|
2014-05-16 04:12:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (after) {
|
2019-04-12 21:06:11 +02:00
|
|
|
var after_data = JX.Stratcom.getData(after);
|
|
|
|
if (after_data.panelKey) {
|
|
|
|
data.afterKey = after_data.panelKey;
|
2014-05-16 04:12:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var workflow = new JX.Workflow(config.moveURI, data)
|
|
|
|
.setHandler(function(response) {
|
|
|
|
onresponse(response, item, list);
|
|
|
|
});
|
|
|
|
|
|
|
|
workflow.start();
|
|
|
|
}
|
|
|
|
|
2019-04-12 21:06:11 +02:00
|
|
|
var dashboard_node = JX.$(config.dashboardNodeID);
|
|
|
|
|
2014-05-16 04:12:40 +02:00
|
|
|
var lists = [];
|
2019-04-12 21:06:11 +02:00
|
|
|
var cols = JX.DOM.scry(dashboard_node, 'div', 'dashboard-column');
|
2014-05-16 04:12:40 +02:00
|
|
|
|
2019-04-12 21:06:11 +02:00
|
|
|
var ii;
|
2014-05-16 04:12:40 +02:00
|
|
|
for (ii = 0; ii < cols.length; ii++) {
|
2019-04-12 21:06:11 +02:00
|
|
|
var col = cols[ii];
|
2014-05-16 04:12:40 +02:00
|
|
|
var list = new JX.DraggableList(itemSigil, col)
|
2016-02-02 15:26:42 +01:00
|
|
|
.setFindItemsHandler(JX.bind(null, finditems, col))
|
|
|
|
.setCanDragX(true);
|
2014-05-16 04:12:40 +02:00
|
|
|
|
|
|
|
list.listen('didSend', JX.bind(list, onupdate, col));
|
|
|
|
list.listen('didReceive', JX.bind(list, onupdate, col));
|
|
|
|
list.listen('didDrop', JX.bind(null, ondrop, list));
|
|
|
|
|
|
|
|
lists.push(list);
|
2019-04-12 21:06:11 +02:00
|
|
|
|
2014-05-16 04:12:40 +02:00
|
|
|
markcolempty(col, finditems(col).length === 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ii = 0; ii < lists.length; ii++) {
|
|
|
|
lists[ii].setGroup(lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|