Files
phabricator/webroot/rsrc/js/application/maniphest/behavior-batch-selector.js
epriestley 7f91c8c4ac Rebuild the bulk editor on SearchEngine
Summary:
Depends on D18805. Ref T13025. Fixes T10268.

Instead of using a list of IDs for the bulk editor, power it with SearchEngine queries. This gives us the full power of SearchEngine and lets us use a query key instead of a list of 20,000 IDs to avoid issues with URL lengths.

Also, split it into a base `BulkEngine` and per-application subclasses. This moves us toward T10005 and universal support for bulk operations.

Also:

  - Renames most of "batch" to "bulk": we're curently inconsitent about this, I like "bulk" better since I think it's more clear if you don't regularly interact with `.bat` files, and newer stuff mostly uses "bulk".
  - When objects in the result set can't be edited because you don't have permission, show the status more clearly.

This probably breaks some stuff a bit since I refactored so heavily, but it seems mostly OK from poking around. I'll clean up anything I missed in followups to deal with remaining items on T13025.

Test Plan:
{F5302300}

  - Bulk edited from Maniphest.
  - Bulk edited from a workboard (no more giant `?ids=....` in the URL).
  - Hit most of the error conditions, I think?
  - Clicked the "Cancel" button.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13025, T10268

Differential Revision: https://secure.phabricator.com/D18806
2018-01-19 12:40:08 -08:00

174 lines
3.7 KiB
JavaScript

/**
* @provides javelin-behavior-maniphest-batch-selector
* @requires javelin-behavior
* javelin-dom
* javelin-stratcom
* javelin-util
*/
JX.behavior('maniphest-batch-selector', function(config) {
var selected = {};
// Test if a task node is selected.
var get_id = function(task) {
return JX.Stratcom.getData(task).taskID;
};
var is_selected = function(task) {
return (get_id(task) in selected);
};
// Change the selected state of a task.
var change = function(task, to) {
if (to === undefined) {
to = !is_selected(task);
}
if (to) {
selected[get_id(task)] = true;
} else {
delete selected[get_id(task)];
}
JX.DOM.alterClass(
task,
'phui-oi-selected',
is_selected(task));
update();
};
var redraw = function (task) {
var selected = is_selected(task);
change(task, selected);
};
JX.Stratcom.listen(
'subpriority-changed',
null,
function (e) {
e.kill();
var data = e.getData();
redraw(data.task);
});
// Change all tasks to some state (used by "select all" / "clear selection"
// buttons).
var changeall = function(to) {
var inputs = JX.DOM.scry(document.body, 'li', 'maniphest-task');
for (var ii = 0; ii < inputs.length; ii++) {
change(inputs[ii], to);
}
};
// Clear any document text selection after toggling a task via shift click,
// since errant clicks tend to start selecting various ranges otherwise.
var clear_selection = function() {
if (window.getSelection) {
if (window.getSelection().empty) {
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) {
window.getSelection().removeAllRanges();
}
} else if (document.selection) {
document.selection.empty();
}
};
// Update the status text showing how many tasks are selected, and the button
// state.
var update = function() {
var count = JX.keys(selected).length;
var status;
if (count === 0) {
status = 'Shift-Click to Select Tasks';
} else if (status == 1) {
status = '1 Selected Task';
} else {
status = count + ' Selected Tasks';
}
JX.DOM.setContent(JX.$(config.status), status);
var submit = JX.$(config.submit);
var disable = (count === 0);
submit.disabled = disable;
JX.DOM.alterClass(submit, 'disabled', disable);
};
// When he user shift-clicks the task, update the rest of the application
// state.
JX.Stratcom.listen(
'click',
'maniphest-task',
function(e) {
var raw = e.getRawEvent();
if (!raw.shiftKey) {
return;
}
if (raw.ctrlKey || raw.altKey || raw.metaKey || e.isRightButton()) {
return;
}
if (JX.Stratcom.pass(e)) {
return;
}
e.kill();
change(e.getNode('maniphest-task'));
clear_selection();
});
// When the user clicks "Select All", select all tasks.
JX.DOM.listen(
JX.$(config.selectNone),
'click',
null,
function(e) {
changeall(false);
e.kill();
});
// When the user clicks "Clear Selection", clear the selection.
JX.DOM.listen(
JX.$(config.selectAll),
'click',
null,
function(e) {
changeall(true);
e.kill();
});
// When the user submits the form, dump selected state into it.
JX.DOM.listen(
JX.$(config.formID),
'submit',
null,
function() {
var ids = [];
for (var k in selected) {
ids.push(k);
}
ids = ids.join(',');
var input = JX.$N('input', {type: 'hidden', name: 'ids', value: ids});
JX.DOM.setContent(JX.$(config.idContainer), input);
});
update();
});