Joeytje50 has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/353961 )
Change subject: Fix problem with the prop not already existing
......................................................................
Fix problem with the prop not already existing
When adding a new property with autoedittoggle when the action is add or
toggle, the parser function would have unexpected behaviour. This fixes
those problems.
Change-Id: Iee89be45e48828dabb615cbae961d8f3a26b5105
---
M libs/PF_autoedit.js
1 file changed, 21 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms
refs/changes/61/353961/1
diff --git a/libs/PF_autoedit.js b/libs/PF_autoedit.js
index 8fa29c6..c1949c4 100644
--- a/libs/PF_autoedit.js
+++ b/libs/PF_autoedit.js
@@ -96,6 +96,13 @@
var $autoedit = $trigger.closest( '.autoedit' );
var $result = $autoedit.find( '.autoedit-result' );
var $data = $autoedit.find( 'form.autoedit-data' );
+ var target = $data.find( '[name="target"]' ).val();
+
+ if (autoedittogglepending.indexOf(target) == -1) {
+ autoedittogglepending.push(target);
+ } else {
+ return; // another autoedittoggle is already editing
this target page
+ }
$trigger.attr( 'class', 'autoedit-trigger
autoedit-trigger-wait' );
$result.attr( 'class', 'autoedit-result autoedit-result-wait' );
@@ -104,7 +111,7 @@
//first retrieve the current value stored in the `prop` on the
target page.
var inputs = {
- target: $data.find( '[name="target"]' ).val(),
+ target: target,
form: $data.find( '[name="form"]' ).val(),
prop: $data.find( '[name="prop"]' ).val(),
toggle: $data.find( '[name="toggle"]' ).val(),
@@ -176,13 +183,18 @@
end++;
} while (lvl > 0 && end < content.length);
var re_split = new RegExp('\\s*' + inputs.sep +
'\\s*');
+ if (!found)
+ content = '';
var values = $.trim(content.substring(start,
end)).split(re_split);
- console.log(values);
var idx = values.indexOf(inputs.toggle)
if (idx == -1 && (inputs.action == 'add' ||
inputs.action == 'toggle'))
values.push(inputs.toggle);
else if (idx != -1 && (inputs.action ==
'remove' || inputs.action == 'toggle'))
values.splice(idx, 1);
+ for (var i = 0; i < values.length; i++) {
+ if (values[i] === '') // find empty
entries and remove them
+ values.splice(i, 1);
+ }
// with the new value found, start submitting
the new value
$('<input/>', {
type: 'hidden',
@@ -193,12 +205,19 @@
$data.find('[name="prop"], [name="toggle"],
[name="separator"], [name="action"]').remove();
window.autoEditHandler = autoEditHandler;
autoEditHandler.call($trigger); // move on to
submit the autoEdit with the generated contents.
+ var pendingindex =
autoedittogglepending.indexOf(target);
+ console.log(pendingindex);
+ if (pendingindex != -1)
+ // after calling the autoedit handler,
remove the target from the pending list
+
autoedittogglepending.splice(pendingindex, 1);
+
},
error: autoEditAPIError.bind($trigger),
} );
}
$( function ( ) { // shorthand for $(document).ready(..)
+ window.autoedittogglepending = [];
$( '.autoedit-trigger' ).click( autoEditHandler );
$( '.autoedit-toggle' ).click( autoEditToggleHandler );
} );
--
To view, visit https://gerrit.wikimedia.org/r/353961
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iee89be45e48828dabb615cbae961d8f3a26b5105
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageForms
Gerrit-Branch: master
Gerrit-Owner: Joeytje50 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits