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);
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
this._elmts.dialogHeader.text($.i18n('perform-wikidata-edits/dialog-header'));
|
|
|
|
this._elmts.loggedInAs.text($.i18n('perform-wikidata-edits/logged-in-as'));
|
|
|
|
this._elmts.editSummaryLabel.text($.i18n('perform-wikidata-edits/edit-summary-label'));
|
|
|
|
this._elmts.editSummary.attr('placeholder', $.i18n('perform-wikidata-edits/edit-summary-placeholder'));
|
|
|
|
this._elmts.performEditsButton.text($.i18n('perform-wikidata-edits/perform-edits'));
|
|
|
|
this._elmts.cancelButton.text($.i18n('perform-wikidata-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();
|
|
|
|
|
|
|
|
if(elmts.editSummary.val().length == 0) {
|
|
|
|
elmts.editSummary.focus();
|
|
|
|
} else {
|
|
|
|
Refine.postProcess(
|
|
|
|
"wikidata",
|
|
|
|
"perform-wikibase-edits",
|
|
|
|
{},
|
|
|
|
{ summary: elmts.editSummary.val(), },
|
|
|
|
{ includeEngine: true, cellsChanged: true, columnStatsChanged: true },
|
|
|
|
{ onDone: function() { dismiss(); } }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-04 11:55:47 +01:00
|
|
|
elmts.loggedInUsername
|
|
|
|
.text(logged_in_username)
|
|
|
|
.attr('href','https://www.wikidata.org/wiki/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) {
|
|
|
|
this._elmts.reviewYourEdits.html(
|
2020-04-20 09:16:06 +02:00
|
|
|
$.i18n('perform-wikidata-edits/review-your-edits')
|
|
|
|
.replace('{nb_edits}', edit_count));
|
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);
|
|
|
|
for (var i = 0; i != warnings.length; i++) {
|
|
|
|
var rendered = WarningsRenderer._renderWarning(warnings[i]);
|
|
|
|
rendered.appendTo(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 12:51:29 +02:00
|
|
|
PerformEditsDialog.checkAndLaunch = function () {
|
2018-02-22 19:15:05 +01:00
|
|
|
var self = this;
|
|
|
|
this.frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/perform-edits-dialog.html"));
|
|
|
|
this._elmts = DOM.bind(this.frame);
|
|
|
|
this.missingSchema = false;
|
|
|
|
|
2018-04-28 11:25:49 +02:00
|
|
|
var onSaved = function() {
|
|
|
|
ManageAccountDialog.ensureLoggedIn(function(logged_in_username) {
|
|
|
|
if (logged_in_username) {
|
2018-11-21 18:30:00 +01:00
|
|
|
var discardWaiter = DialogSystem.showBusy($.i18n('perform-wikidata-edits/analyzing-edits'));
|
2019-10-17 11:42:05 +02:00
|
|
|
Refine.postCSRF(
|
2018-04-28 11:25:49 +02:00
|
|
|
"command/wikidata/preview-wikibase-schema?" + $.param({ project: theProject.id }),
|
|
|
|
{ engine: JSON.stringify(ui.browsingEngine.getJSON()) },
|
|
|
|
function(data) {
|
|
|
|
discardWaiter();
|
|
|
|
if(data['code'] != 'error') {
|
|
|
|
PerformEditsDialog._updateWarnings(data);
|
|
|
|
PerformEditsDialog.launch(logged_in_username, data['max_severity']);
|
|
|
|
} else {
|
|
|
|
SchemaAlignmentDialog.launch(
|
|
|
|
PerformEditsDialog.checkAndLaunch);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-03-30 18:26:24 +02:00
|
|
|
if (SchemaAlignmentDialog.isSetUp() && SchemaAlignmentDialog._hasUnsavedChanges) {
|
2018-04-28 11:25:49 +02:00
|
|
|
SchemaAlignmentDialog._save(onSaved);
|
|
|
|
} else {
|
|
|
|
onSaved();
|
2018-03-30 18:26:24 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 12:51:29 +02:00
|
|
|
};
|