RandomSec/extensions/wikidata/module/scripts/dialogs/perform-edits-dialog.js
2018-04-27 09:17:32 +02:00

82 lines
2.2 KiB
JavaScript

var PerformEditsDialog = {};
PerformEditsDialog.launch = function(logged_in_username) {
var self = this;
var elmts = this._elmts;
var frame = this.frame;
console.log(this.missingSchema);
if (this.missingSchema) {
return;
}
this._level = DialogSystem.showDialog(frame);
var dismiss = function() {
DialogSystem.dismissUntil(self._level - 1);
};
elmts.loggedInUsername.text(logged_in_username);
frame.find('.cancel-button').click(function() {
dismiss();
});
elmts.performEditsButton.click(function() {
Refine.postProcess(
"wikidata",
"perform-wikibase-edits",
{},
{ strategy : "SNAK_QUALIFIERS",
action: "MERGE",
summary: elmts.editSummary.val(),
},
{ includeEngine: true, cellsChanged: true, columnStatsChanged: true },
{ onDone:
function() {
dismiss();
}
});
});
};
PerformEditsDialog._updateWarnings = function(data) {
var warnings = data.warnings;
var mainDiv = this._elmts.warningsArea;
// clear everything
mainDiv.empty();
var table = $('<table></table>').appendTo(mainDiv);
for (var i = 0; i != warnings.length; i++) {
var rendered = WarningsRenderer._renderWarning(warnings[i]);
rendered.appendTo(table);
}
}
PerformEditsDialog.checkAndLaunch = function () {
var self = this;
this.frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/perform-edits-dialog.html"));
this._elmts = DOM.bind(this.frame);
this.missingSchema = false;
ManageAccountDialog.ensureLoggedIn(function(logged_in_username) {
if (logged_in_username) {
$.post(
"command/wikidata/preview-wikibase-schema?" + $.param({ project: theProject.id }),
{ engine: JSON.stringify(ui.browsingEngine.getJSON()) },
function(data) {
if(data['status'] != 'error') {
PerformEditsDialog._updateWarnings(data);
PerformEditsDialog.launch(logged_in_username);
} else {
SchemaAlignmentDialog.launch(
PerformEditsDialog.checkAndLaunch);
}
},
"json"
);
}
});
};