Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support batch requested moves #1888

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions modules/twinklexfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ Twinkle.xfd.callback.change_category = function twinklexfdCallbackChangeCategory
tooltip: 'Use this option when you are unable to perform this uncontroversial move yourself because of a technical reason (e.g. a page already exists at the new title, or the page is protected)',
checked: false,
event: function() {
form.newname.required = this.checked;
$('input[name="newname"]', form).prop('required', this.checked);
$('input[type="button"][value="more"]', form)[0].sublist.inputs[1].required = this.checked;
},
subgroup: {
type: 'checkbox',
Expand All @@ -703,15 +704,27 @@ Twinkle.xfd.callback.change_category = function twinklexfdCallbackChangeCategory
]
});
work_area.append({
type: 'input',
name: 'newname',
label: 'New title:',
tooltip: 'Required for technical requests. Otherwise, if unsure of the appropriate title, you may leave it blank.'
type: 'dyninput',
inputs: [
{
label: 'From:',
name: 'currentname',
required: true
},
{
label: 'To:',
name: 'newname',
tooltip: 'Required for technical requests. Otherwise, if unsure of the appropriate title, you may leave it blank.'
}
],
min: 1
});

appendReasonBox();
work_area = work_area.render();
old_area.parentNode.replaceChild(work_area, old_area);

form.currentname.value = Morebits.pageNameNorm;
break;

default:
Expand Down Expand Up @@ -764,12 +777,17 @@ Twinkle.xfd.callbacks = {
// U+00A0 NO-BREAK SPACE; U+2013 EN RULE
}
if (venue === 'rm') {
// even if invoked from talk page, propose the subject page for move
var pageName = new mw.Title(Morebits.pageNameNorm).getSubjectPage().toText();
var rmtrDiscuss = params['rmtr-discuss'] ? '|discuss=no' : '';
var rmtr = '{{subst:RMassist|1=' + pageName + '|2=' + params.newname + rmtrDiscuss + '|reason=' + params.reason + '}}';
var requestedMove = '{{subst:Requested move|current1=' + pageName + '|new1=' + params.newname + '|reason=' + params.reason + '}}';
return params.rmtr ? rmtr : requestedMove;
if (params.rmtr) {
var rmtrDiscuss = params['rmtr-discuss'] ? '|discuss=no' : '';
return params.currentname
.map((currentname, i) => `{{subst:RMassist|1=${currentname}|2=${params.newname[i]}${rmtrDiscuss}|reason=${params.reason}}}`)
.join('\n');
}
return `{{subst:Requested move${
params.currentname
.map((currentname, i) => `|current${i + 1}=${currentname}|new${i + 1}=${params.newname[i]}`)
.join('')
}|reason=${params.reason}}}`;
}

var text = '{{subst:' + venue + '2';
Expand Down
89 changes: 57 additions & 32 deletions morebits.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ Morebits.quickForm.prototype.append = function QuickFormAppend(data) {
* - `number`: A number input box.
* - Attributes: Everything the text `input` has, as well as: min, max, step, list
* - `dyninput`: A set of text boxes with "Remove" buttons and an "Add" button.
* - Attributes: name, label, min, max, sublabel, value, size, maxlength, event
* - Attributes: name, label, min, max, inputs, sublabel, value, size, maxlength, event
* - `hidden`: An invisible form field.
* - Attributes: name, value
* - `header`: A level 5 header.
Expand All @@ -371,7 +371,7 @@ Morebits.quickForm.prototype.append = function QuickFormAppend(data) {
* There is some difference on how types handle the `label` attribute:
* - `div`, `select`, `field`, `checkbox`/`radio`, `input`, `textarea`, `header`, and `dyninput` can accept an array of items,
* and the label item(s) can be `Element`s.
* - `option`, `optgroup`, `_dyninput_element`, `submit`, and `button` accept only a single string.
* - `option`, `optgroup`, `_dyninput_cell`, `submit`, and `button` accept only a single string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my understanding, what does _dyninput_cell do and why did its name change?

*
* @memberof Morebits.quickForm
* @class
Expand Down Expand Up @@ -730,14 +730,17 @@ Morebits.quickForm.element.prototype.compute = function QuickFormElementCompute(
var moreButton = more[1];

var sublist = {
type: '_dyninput_element',
label: data.sublabel || data.label,
name: data.name,
value: data.value,
size: data.size,
type: '_dyninput_row',
remove: false,
maxlength: data.maxlength,
event: data.event
event: data.event,
inputs: data.inputs || [{
// compatibility
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my understanding, what's going on with the compatibility sub-section here?

label: data.sublabel || data.label,
name: data.name,
value: data.value,
size: data.size
}]
};

for (i = 0; i < min; ++i) {
Expand All @@ -753,31 +756,13 @@ Morebits.quickForm.element.prototype.compute = function QuickFormElementCompute(
moreButton.max = max - min;
moreButton.counter = 0;
break;
case '_dyninput_element': // Private, similar to normal input
case '_dyninput_row': // Private
node = document.createElement('div');

if (data.label) {
label = node.appendChild(document.createElement('label'));
label.appendChild(document.createTextNode(data.label));
label.setAttribute('for', id);
label.style.marginRight = '3px';
}

subnode = node.appendChild(document.createElement('input'));
if (data.value) {
subnode.setAttribute('value', data.value);
}
subnode.setAttribute('name', data.name);
subnode.setAttribute('type', 'text');
if (data.size) {
subnode.setAttribute('size', data.size);
}
if (data.maxlength) {
subnode.setAttribute('maxlength', data.maxlength);
}
if (data.event) {
subnode.addEventListener('keyup', data.event, false);
}
data.inputs.forEach(function(subdata) {
var cell = new Morebits.quickForm.element($.extend(subdata, { type: '_dyninput_cell' }));
node.appendChild(cell.render());
});
if (data.remove) {
var remove = this.compute({
type: 'button',
Expand All @@ -800,6 +785,41 @@ Morebits.quickForm.element.prototype.compute = function QuickFormElementCompute(
removeButton.morebutton = data.morebutton;
}
break;
case '_dyninput_cell': // Private, similar to normal input
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my understanding, why did this case move down?

node = document.createElement('span');

if (data.label) {
label = node.appendChild(document.createElement('label'));
label.appendChild(document.createTextNode(data.label));
label.setAttribute('for', id + '_input');
label.style.marginRight = '3px';
}

subnode = node.appendChild(document.createElement('input'));
subnode.setAttribute('id', id + '_input');
if (data.value) {
subnode.setAttribute('value', data.value);
}
subnode.setAttribute('name', data.name);
subnode.setAttribute('type', 'text');
subnode.setAttribute('data-dyninput', 'data-dyninput');
if (data.size) {
subnode.setAttribute('size', data.size);
}
if (data.maxlength) {
subnode.setAttribute('maxlength', data.maxlength);
}
if (data.required) {
subnode.setAttribute('required', 'required');
}
if (data.disabled) {
subnode.setAttribute('required', 'disabled');
}
if (data.event) {
subnode.addEventListener('keyup', data.event, false);
}
node.style.marginRight = '3px';
break;
case 'hidden':
node = document.createElement('input');
node.setAttribute('type', 'hidden');
Expand Down Expand Up @@ -979,7 +999,12 @@ Morebits.quickForm.getInputData = function(form) {
break;
case 'text': // falls through
case 'textarea':
result[fieldNameNorm] = field.value.trim();
if (field.dataset.dyninput) {
result[fieldNameNorm] = result[fieldNameNorm] || [];
result[fieldNameNorm].push(field.value.trim());
} else {
result[fieldNameNorm] = field.value.trim();
}
break;
default: // could be select-one, date, number, email, etc
if (field.value) {
Expand Down
Loading