Summary: First stab at a batch editor for Maniphest. Basically, you can select a group of tasks and then import them into the "batch" interface, where you can edit all of them at once. High level goal is to make it easier for users in PM/filer/support/QA roles to deal with large numbers of tasks quickly. This implementation has a few major limitations: - The only available actions are "add projects" and "remove projects". - There is no review / undo / log stuff. - All the changes are applied in-process, which may not scale terribly well. However, the immediate need is just around projects and this seemed like a reasonable place to draw the line for a minimal useful version of the tool. Test Plan: Used batch editor to add and remove projects from groups of tasks. Reviewers: btrahan, yairlivne Reviewed By: btrahan CC: aran, epriestley, sandra Maniphest Tasks: T441 Differential Revision: https://secure.phabricator.com/D1680
155 lines
3.4 KiB
JavaScript
155 lines
3.4 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-maniphest-batch-selector
|
|
* @requires javelin-behavior
|
|
* javelin-dom
|
|
* javelin-stratcom
|
|
*/
|
|
|
|
JX.behavior('maniphest-batch-selector', function(config) {
|
|
|
|
// When a task row's selection state is changed, this issues updates to other
|
|
// parts of the application.
|
|
|
|
var onchange = function(task) {
|
|
var input = JX.DOM.find(task, 'input', 'maniphest-batch');
|
|
var state = input.checked;
|
|
|
|
JX.DOM.alterClass(task, 'maniphest-batch-selected', state);
|
|
|
|
JX.Stratcom.invoke(
|
|
(state ? 'maniphest-batch-task-add' : 'maniphest-batch-task-rem'),
|
|
null,
|
|
{id: input.value})
|
|
};
|
|
|
|
|
|
// Change the selected state of a task.
|
|
// If 'to' is undefined, toggle. Otherwise, set to true or false.
|
|
|
|
var change = function(task, to) {
|
|
|
|
var input = JX.DOM.find(task, 'input', 'maniphest-batch');
|
|
var state = input.checked;
|
|
if (to === undefined) {
|
|
input.checked = !input.checked;
|
|
} else {
|
|
input.checked = to;
|
|
}
|
|
onchange(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, 'table', 'maniphest-task');
|
|
for (var ii = 0; ii < inputs.length; ii++) {
|
|
change(inputs[ii], to);
|
|
}
|
|
}
|
|
|
|
|
|
// Update the status text showing how many tasks are selected, and the button
|
|
// state.
|
|
|
|
var selected = {};
|
|
var selected_count = 0;
|
|
|
|
var update = function() {
|
|
var status = (selected_count == 1)
|
|
? '1 Selected Task'
|
|
: selected_count + ' Selected Tasks';
|
|
JX.DOM.setContent(JX.$(config.status), status);
|
|
|
|
var submit = JX.$(config.submit);
|
|
var disable = (selected_count == 0);
|
|
submit.disabled = disable;
|
|
JX.DOM.alterClass(submit, 'disabled', disable);
|
|
};
|
|
|
|
|
|
// When the user clicks the entire <td /> surrounding the checkbox, count it
|
|
// as a checkbox click.
|
|
|
|
JX.Stratcom.listen(
|
|
'click',
|
|
'maniphest-task',
|
|
function(e) {
|
|
if (!JX.DOM.isNode(e.getTarget(), 'td')) {
|
|
// Only count clicks in the <td />, not (e.g.) the table border.
|
|
return;
|
|
}
|
|
|
|
// Check if the clicked <td /> contains a checkbox.
|
|
var inputs = JX.DOM.scry(e.getTarget(), 'input', 'maniphest-batch');
|
|
if (!inputs.length) {
|
|
return;
|
|
}
|
|
|
|
change(e.getNode('maniphest-task'));
|
|
});
|
|
|
|
|
|
// When he user clicks the <input />, update the rest of the application
|
|
// state.
|
|
|
|
JX.Stratcom.listen(
|
|
['click', 'onchange'],
|
|
'maniphest-batch',
|
|
function(e) {
|
|
onchange(e.getNode('maniphest-task'));
|
|
});
|
|
|
|
|
|
// 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();
|
|
});
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
'maniphest-batch-task-add',
|
|
null,
|
|
function(e) {
|
|
var id = e.getData().id;
|
|
if (!(id in selected)) {
|
|
selected[id] = true;
|
|
selected_count++;
|
|
update();
|
|
}
|
|
});
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
'maniphest-batch-task-rem',
|
|
null,
|
|
function(e) {
|
|
var id = e.getData().id;
|
|
if (id in selected) {
|
|
delete selected[id];
|
|
selected_count--;
|
|
update();
|
|
}
|
|
});
|
|
|
|
});
|