2017-09-15 12:51:29 +02:00
|
|
|
var PerformEditsDialog = {};
|
|
|
|
|
2018-03-04 11:55:47 +01:00
|
|
|
PerformEditsDialog.launch = function(logged_in_username, max_severity) {
|
2017-09-15 12:51:29 +02:00
|
|
|
var self = this;
|
2018-02-22 19:15:05 +01:00
|
|
|
var elmts = this._elmts;
|
|
|
|
var frame = this.frame;
|
|
|
|
|
|
|
|
if (this.missingSchema) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-15 12:51:29 +02:00
|
|
|
|
|
|
|
this._level = DialogSystem.showDialog(frame);
|
2020-08-22 17:58:56 +02:00
|
|
|
this._elmts.dialogHeader.text($.i18n('perform-wikibase-edits/dialog-header', WikibaseManager.getSelectedWikibaseName()));
|
|
|
|
this._elmts.loggedInAs.text($.i18n('perform-wikibase-edits/logged-in-as'));
|
|
|
|
this._elmts.editSummaryLabel.text($.i18n('perform-wikibase-edits/edit-summary-label'));
|
|
|
|
this._elmts.editSummary.attr('placeholder', $.i18n('perform-wikibase-edits/edit-summary-placeholder'));
|
|
|
|
this._elmts.maxlagLabel.text($.i18n('perform-wikibase-edits/maxlag-label'));
|
|
|
|
this._elmts.maxlag.val(WikibaseManager.getSelectedWikibaseMaxlag());
|
|
|
|
this._elmts.maxlag.attr('placeholder', WikibaseManager.getSelectedWikibaseMaxlag());
|
|
|
|
this._elmts.explainMaxlag.html($.i18n('perform-wikibase-edits/explain-maxlag'));
|
|
|
|
this._elmts.performEditsButton.text($.i18n('perform-wikibase-edits/perform-edits'));
|
|
|
|
this._elmts.cancelButton.text($.i18n('perform-wikibase-edits/cancel'));
|
2018-02-22 19:43:28 +01:00
|
|
|
|
2020-04-20 09:16:06 +02:00
|
|
|
var hiddenIframe = $('#hiddenIframe').contents();
|
|
|
|
|
2017-09-15 12:51:29 +02:00
|
|
|
var dismiss = function() {
|
|
|
|
DialogSystem.dismissUntil(self._level - 1);
|
|
|
|
};
|
|
|
|
|
2020-04-20 09:16:06 +02:00
|
|
|
|
|
|
|
var doFormSubmit = function() {
|
|
|
|
hiddenIframe.find('body').append(elmts.performEditsForm.clone());
|
|
|
|
var formCopy = hiddenIframe.find("#wikibase-perform-edits-form");
|
|
|
|
formCopy.submit();
|
|
|
|
|
2020-08-22 17:58:56 +02:00
|
|
|
if (elmts.editSummary.val().length === 0) {
|
2020-04-20 09:16:06 +02:00
|
|
|
elmts.editSummary.focus();
|
2020-08-22 17:58:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elmts.maxlag.val().length === 0) {
|
|
|
|
elmts.maxlag.val(WikibaseManager.getSelectedWikibaseMaxlag());
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate maxlag
|
|
|
|
if (!/^\+?[1-9]\d*$/.test(elmts.maxlag.val())) {
|
|
|
|
elmts.maxlag.focus();
|
|
|
|
alert($.i18n('perform-wikibase-edits/maxlag-validation'));
|
|
|
|
return;
|
2020-04-20 09:16:06 +02:00
|
|
|
}
|
2020-08-22 17:58:56 +02:00
|
|
|
|
|
|
|
Refine.postProcess(
|
|
|
|
"wikidata",
|
|
|
|
"perform-wikibase-edits",
|
|
|
|
{},
|
|
|
|
{ summary: elmts.editSummary.val(), maxlag: elmts.maxlag.val() },
|
|
|
|
{ includeEngine: true, cellsChanged: true, columnStatsChanged: true },
|
|
|
|
{ onDone: function() { dismiss(); } }
|
|
|
|
);
|
2020-06-19 04:56:07 +02:00
|
|
|
};
|
2020-08-22 17:58:56 +02:00
|
|
|
|
2018-03-04 11:55:47 +01:00
|
|
|
elmts.loggedInUsername
|
|
|
|
.text(logged_in_username)
|
2020-08-22 17:58:56 +02:00
|
|
|
.attr('href', WikibaseManager.getSelectedWikibaseRoot() + 'User:' + logged_in_username);
|
|
|
|
|
2017-09-15 12:51:29 +02:00
|
|
|
frame.find('.cancel-button').click(function() {
|
2020-04-20 09:16:06 +02:00
|
|
|
dismiss();
|
2017-09-15 12:51:29 +02:00
|
|
|
});
|
|
|
|
|
2020-04-20 09:16:06 +02:00
|
|
|
this._elmts.editSummary.keypress(function (evt) {
|
|
|
|
if (evt.which === 13) {
|
|
|
|
doFormSubmit();
|
|
|
|
evt.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2018-10-28 10:06:19 +01:00
|
|
|
|
2018-03-04 11:55:47 +01:00
|
|
|
if (max_severity === 'CRITICAL') {
|
2020-04-20 09:16:06 +02:00
|
|
|
elmts.performEditsButton.prop("disabled",true).addClass("button-disabled");
|
2018-03-04 11:55:47 +01:00
|
|
|
} else {
|
|
|
|
elmts.performEditsButton.click(function() {
|
2020-04-20 09:16:06 +02:00
|
|
|
doFormSubmit();
|
2018-03-04 11:55:47 +01:00
|
|
|
});
|
|
|
|
}
|
2017-09-15 12:51:29 +02:00
|
|
|
};
|
|
|
|
|
2018-04-28 11:25:49 +02:00
|
|
|
PerformEditsDialog.updateEditCount = function(edit_count) {
|
2020-08-22 17:58:56 +02:00
|
|
|
this._elmts.reviewYourEdits.html($.i18n('perform-wikibase-edits/review-your-edits',
|
|
|
|
edit_count,
|
|
|
|
WikibaseManager.getSelectedWikibaseMainPage(),
|
|
|
|
WikibaseManager.getSelectedWikibaseName(),
|
|
|
|
));
|
2020-06-19 04:56:07 +02:00
|
|
|
};
|
2018-04-28 11:25:49 +02:00
|
|
|
|
2018-02-22 19:15:05 +01:00
|
|
|
PerformEditsDialog._updateWarnings = function(data) {
|
|
|
|
var warnings = data.warnings;
|
|
|
|
var mainDiv = this._elmts.warningsArea;
|
|
|
|
|
|
|
|
// clear everything
|
|
|
|
mainDiv.empty();
|
2018-04-28 11:25:49 +02:00
|
|
|
PerformEditsDialog.updateEditCount(data.edit_count);
|
2018-02-22 19:15:05 +01:00
|
|
|
|
|
|
|
var table = $('<table></table>').appendTo(mainDiv);
|
2020-08-22 17:58:56 +02:00
|
|
|
for (var i = 0; i < warnings.length; i++) {
|
2018-02-22 19:15:05 +01:00
|
|
|
var rendered = WarningsRenderer._renderWarning(warnings[i]);
|
|
|
|
rendered.appendTo(table);
|
2020-08-22 17:58:56 +02:00
|
|
|
}
|
2020-06-19 04:56:07 +02:00
|
|
|
};
|
2018-02-22 19:15:05 +01:00
|
|
|
|
2017-09-15 12:51:29 +02:00
|
|
|
PerformEditsDialog.checkAndLaunch = function () {
|
2018-02-22 19:15:05 +01:00
|
|
|
this.frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/perform-edits-dialog.html"));
|
|
|
|
this._elmts = DOM.bind(this.frame);
|
|
|
|
this.missingSchema = false;
|
|
|
|
|
2020-06-19 04:56:07 +02:00
|
|
|
var onSaved = function () {
|
|
|
|
ManageAccountDialog.ensureLoggedIn(function (logged_in_username) {
|
2020-08-22 17:58:56 +02:00
|
|
|
var discardWaiter = DialogSystem.showBusy($.i18n('perform-wikibase-edits/analyzing-edits'));
|
2020-06-19 04:56:07 +02:00
|
|
|
Refine.postCSRF(
|
|
|
|
"command/wikidata/preview-wikibase-schema?" + $.param({project: theProject.id}),
|
2020-08-22 17:58:56 +02:00
|
|
|
{manifest: JSON.stringify(WikibaseManager.getSelectedWikibase()), engine: JSON.stringify(ui.browsingEngine.getJSON())},
|
2020-06-19 04:56:07 +02:00
|
|
|
function (data) {
|
|
|
|
discardWaiter();
|
2020-08-22 17:58:56 +02:00
|
|
|
if (data['code'] !== 'error') {
|
2020-06-19 04:56:07 +02:00
|
|
|
PerformEditsDialog._updateWarnings(data);
|
|
|
|
PerformEditsDialog.launch(logged_in_username, data['max_severity']);
|
|
|
|
} else {
|
2020-08-22 17:58:56 +02:00
|
|
|
SchemaAlignment.launch();
|
2020-06-19 04:56:07 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
2018-04-28 11:25:49 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-08-22 17:58:56 +02:00
|
|
|
if (SchemaAlignment.isSetUp() && SchemaAlignment._hasUnsavedChanges) {
|
|
|
|
SchemaAlignment._save(onSaved);
|
2018-04-28 11:25:49 +02:00
|
|
|
} else {
|
|
|
|
onSaved();
|
2018-03-30 18:26:24 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 12:51:29 +02:00
|
|
|
};
|