MediaWiki:Gadget-articlefeedback-tools.js: Difference between revisions

no edit summary
No edit summary
Tag: Manual revert
No edit summary
 
Line 1:
"use strict";
 
/** <nowiki>
* Secondary gadget for the wiki article feedback feature, which runs solely on
Line 7 ⟶ 9:
*/
 
var conf = mw.config.get(['wgPageName']),
main = {
'wgPageName'
]),/**
* Startup method
*/
init: function init() {
var wrappers = $('.gloop-feedback-wrapper');
 
// Loop through all of the feedback on the page, and add a link to resolve them
main = {
for (var i = 0; i < wrappers.length; i++) {
/**
var *current Startup= methodwrappers[i];
*/main.handleWrapper(current);
init: function () {}
},
var wrappers = $('.gloop-feedback-wrapper');
handleWrapper: function handleWrapper(wrapper) {
// LoopGet throughthe allID of the feedback on the page, and add a link to resolve themsection
for (var ifeedbackId = 0; i < wrappers$(wrapper).lengthdata('id'); i++) {
if (!feedbackId) {
var current = wrappers[i];
// No ID exists, main.handleWrapper(current);don't do anything
console.warn('Could not init feedback actions: no ID present', wrapper);
}
},return;
}
handleWrapper: function (wrapper) {
// Get the ID of the feedback section
var feedbackId = $(wrapper).data('id');
 
// Find the toggle to resolve the feedback
if (!feedbackId) {
var toggle = $(wrapper).find('.gloop-feedback-resolve-toggle');
// No ID exists, don't do anything
if (!toggle.length) {
console.warn('Could not init feedback actions: no ID present', wrapper);
// No toggle exists, don't do anything
return;
console.warn('Could not init feedback actions: no toggle present', wrapper);
}
}
if (toggle.hasClass('table-bg-green')) {
// Find the toggle to resolve the feedback
var// toggleAlready =resolved, $(wrapper).find(don'.gloop-feedback-t let people resolve-toggle'); it again
return;
}
if (!toggle.length) {
// No $(toggle exists).css('cursor', don't do anythingpointer');
$(toggle).on('click', function () {
console.warn('Could not init feedback actions: no toggle present', wrapper);
main.doResolveConfirm(feedbackId, toggle);
}
});
},
if (toggle.hasClass('table-bg-green')) {
/**
// Already resolved, don't let people resolve it again
* Shows a confirmation popup for resolving feedback
return;
}**/
doResolveConfirm: function doResolveConfirm(feedbackId, toggle) {
$(toggle)console.csslog('cursorfeedback id', 'pointer'feedbackId);
OO.ui.confirm('Clicking OK will resolve this feedback, marking it as complete/no action needed. You cannot unresolve feedback after resolving it.').done(function (confirmed) {
$(toggle).on('click', function () {
if (confirmed) {
main.doResolveConfirm(feedbackId, toggle);
main.doResolve(feedbackId, toggle);
});
},
/**
* Shows a confirmation popup for resolving feedback
**/
doResolveConfirm: function (feedbackId, toggle) {
console.log('feedback id', feedbackId);
OO.ui.confirm('Clicking OK will resolve this feedback, marking it as complete/no action needed. You cannot unresolve feedback after resolving it.').done(function (confirmed) {
if (confirmed) {
main.doResolve(feedbackId, toggle);
}
});
},
doResolve: function (feedbackId, toggle) {
var searchString = '\\|id=' + feedbackId + '\n\\|date=(.*)\n\\|resolved=no';
var regex = new RegExp(searchString, 'gim');
new mw.Api().edit(
conf.wgPageName,
function (revision) {
return {
text: revision.content.replace( regex, '|id=' + feedbackId + '\n|date=$1\n|resolved=yes' ),
summary: 'Resolving user-submitted feedback',
assert: 'user',
minor: true
};
}
)
.then(function () {
$(toggle).removeClass('table-bg-red');
$(toggle).addClass('table-bg-green');
$(toggle).find('span').text('Resolved');
$(toggle).off('click');
});
}
});
},
 
doResolve: function doResolve(feedbackId, toggle) {
var searchString = '\\|id=' + feedbackId + '\n\\|date=(.*)\n\\|resolved=no';
var regex = new RegExp(searchString, 'gim');
new mw.Api().edit(conf.wgPageName, function (revision) {
return {
text: revision.content.replace(regex, '|id=' + feedbackId + '\n|date=$1\n|resolved=yes'),
summary: 'Resolving user-submitted feedback',
assert: 'user',
minor: true
};
}).then(function () {
$(toggle).removeClass('table-bg-red');
$(toggle).addClass('table-bg-green');
$(toggle).find('span').text('Resolved');
$(toggle).off('click');
});
}
};
mw.loader.using(['mediawiki.api', 'oojs-ui-core', 'oojs-ui-windows'], function () {
$(main.init);
});