2017-08-29 19:22:41 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
|
|
|
* Neither the name of Google Inc. nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
var SchemaAlignment = {};
|
|
|
|
var SchemaAlignmentDialog = {};
|
|
|
|
|
2018-03-30 12:40:01 +02:00
|
|
|
/**
|
|
|
|
* Installs the tabs in the UI the first time the Wikidata
|
|
|
|
* extension is called.
|
|
|
|
*/
|
|
|
|
SchemaAlignmentDialog.setUpTabs = function() {
|
|
|
|
var self = this;
|
|
|
|
this._rightPanel = $('#right-panel');
|
|
|
|
this._viewPanel = $('#view-panel').addClass('main-view-panel-tab');
|
|
|
|
this._toolPanel = $('#tool-panel');
|
|
|
|
this._summaryBar = $('#summary-bar')
|
|
|
|
.addClass('main-view-panel-tab-header')
|
|
|
|
.addClass('active')
|
|
|
|
.attr('href', '#view-panel');
|
|
|
|
|
|
|
|
this._schemaPanel = $('<div id="wikidata-schema-panel"></div>')
|
|
|
|
.addClass('main-view-panel-tab')
|
|
|
|
.appendTo(this._rightPanel);
|
|
|
|
this._issuesPanel = $('<div id="wikidata-issues-panel"></div>')
|
|
|
|
.addClass('main-view-panel-tab')
|
|
|
|
.appendTo(this._rightPanel);
|
2018-03-30 18:26:24 +02:00
|
|
|
this._previewPanel = $('<div id="wikidata-preview-panel"></div>')
|
|
|
|
.addClass('main-view-panel-tab')
|
|
|
|
.appendTo(this._rightPanel);
|
2018-03-30 12:40:01 +02:00
|
|
|
|
|
|
|
var schemaButton = $('<div></div>')
|
|
|
|
.addClass('main-view-panel-tab-header')
|
|
|
|
.attr('href', '#wikidata-schema-panel')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('wikidata-schema/schema-tab-header'))
|
2018-03-30 12:40:01 +02:00
|
|
|
.appendTo(this._toolPanel);
|
|
|
|
var issuesButton = $('<div></div>')
|
|
|
|
.addClass('main-view-panel-tab-header')
|
|
|
|
.attr('href', '#wikidata-issues-panel')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('wikidata-schema/warnings-tab-header')+' ')
|
2018-03-30 12:40:01 +02:00
|
|
|
.appendTo(this._toolPanel);
|
2018-04-20 23:11:38 +02:00
|
|
|
this.issuesTabCount = $('<span></span>')
|
|
|
|
.addClass('schema-alignment-total-warning-count')
|
|
|
|
.appendTo(issuesButton)
|
|
|
|
.hide();
|
|
|
|
this.issueSpinner = $('<img />')
|
|
|
|
.attr('src', 'images/large-spinner.gif')
|
|
|
|
.attr('width', '16px')
|
|
|
|
.appendTo(issuesButton);
|
2018-03-30 18:26:24 +02:00
|
|
|
var previewButton = $('<div></div>')
|
|
|
|
.addClass('main-view-panel-tab-header')
|
|
|
|
.attr('href', '#wikidata-preview-panel')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('wikidata-schema/edits-preview-tab-header'))
|
2018-03-30 18:26:24 +02:00
|
|
|
.appendTo(this._toolPanel);
|
2018-04-20 23:11:38 +02:00
|
|
|
this.previewSpinner = $('<img />')
|
|
|
|
.attr('src', 'images/large-spinner.gif')
|
|
|
|
.attr('width', '16px')
|
|
|
|
.appendTo(previewButton);
|
2018-04-20 09:21:20 +02:00
|
|
|
|
|
|
|
this._unsavedIndicator = $('<span></span>')
|
|
|
|
.html(' *')
|
2018-11-21 18:30:00 +01:00
|
|
|
.attr('title', $.i18n('wikidata-schema/unsaved-changes-alt'))
|
2018-04-20 09:21:20 +02:00
|
|
|
.hide()
|
|
|
|
.appendTo(schemaButton);
|
|
|
|
|
2018-04-20 15:03:09 +02:00
|
|
|
$('.main-view-panel-tab-header').click(function(e) {
|
2018-03-30 12:40:01 +02:00
|
|
|
var targetTab = $(this).attr('href');
|
|
|
|
SchemaAlignmentDialog.switchTab(targetTab);
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2018-03-30 12:40:01 +02:00
|
|
|
});
|
|
|
|
|
2018-03-30 18:26:24 +02:00
|
|
|
/**
|
|
|
|
* Init the schema tab
|
|
|
|
*/
|
2018-03-30 12:40:01 +02:00
|
|
|
var schemaTab = $(DOM.loadHTML("wikidata", "scripts/schema-alignment-tab.html")).appendTo(this._schemaPanel);
|
|
|
|
var schemaElmts = this._schemaElmts = DOM.bind(schemaTab);
|
2018-11-21 18:30:00 +01:00
|
|
|
schemaElmts.dialogExplanation.text($.i18n('wikidata-schema/dialog-explanation'));
|
|
|
|
this._plusButton($.i18n('wikidata-schema/add-item-button'), schemaElmts.addItemButton);
|
2018-04-20 15:03:09 +02:00
|
|
|
schemaElmts.addItemButton.click(function(e) {
|
2018-03-30 12:40:01 +02:00
|
|
|
self._addItem();
|
|
|
|
SchemaAlignmentDialog._hasChanged();
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2018-03-30 12:40:01 +02:00
|
|
|
});
|
2018-04-20 09:21:20 +02:00
|
|
|
schemaElmts.saveButton
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('wikidata-schema/save-button'))
|
|
|
|
.attr('title', $.i18n('wikidata-schema/save-schema-alt'))
|
2018-04-20 09:21:20 +02:00
|
|
|
.prop('disabled', true)
|
|
|
|
.addClass('disabled')
|
|
|
|
.click(function() { SchemaAlignmentDialog._save(); });
|
|
|
|
schemaElmts.discardButton
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('wikidata-schema/discard-button'))
|
|
|
|
.attr('title', $.i18n('wikidata-schema/discard-schema-changes-alt'))
|
2018-04-20 09:21:20 +02:00
|
|
|
.prop('disabled', true)
|
|
|
|
.addClass('disabled')
|
|
|
|
.click(function() { SchemaAlignmentDialog._discardChanges(); });
|
2018-03-30 12:40:01 +02:00
|
|
|
|
|
|
|
this._wikibasePrefix = "http://www.wikidata.org/entity/"; // hardcoded for now
|
|
|
|
|
|
|
|
// Init the column area
|
2018-04-13 18:39:20 +02:00
|
|
|
this.updateColumns();
|
2018-03-30 12:40:01 +02:00
|
|
|
|
|
|
|
var url = ReconciliationManager.ensureDefaultServicePresent();
|
|
|
|
SchemaAlignmentDialog._reconService = ReconciliationManager.getServiceFromUrl(url);
|
|
|
|
|
2018-03-30 18:26:24 +02:00
|
|
|
/**
|
|
|
|
* Init the issues tab
|
|
|
|
*/
|
|
|
|
var issuesTab = $(DOM.loadHTML("wikidata", "scripts/issues-tab.html")).appendTo(this._issuesPanel);
|
2018-04-20 09:21:20 +02:00
|
|
|
var issuesElmts = this._issuesElmts = DOM.bind(issuesTab);
|
2018-11-21 18:30:00 +01:00
|
|
|
issuesElmts.invalidSchemaWarningIssues.text($.i18n('wikidata-schema/invalid-schema-warning-issues'));
|
2018-03-30 18:26:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Init the preview tab
|
|
|
|
*/
|
|
|
|
var previewTab = $(DOM.loadHTML("wikidata", "scripts/preview-tab.html")).appendTo(this._previewPanel);
|
2018-04-20 09:21:20 +02:00
|
|
|
var previewElmts = this._previewElmts = DOM.bind(previewTab);
|
2018-04-28 11:25:49 +02:00
|
|
|
SchemaAlignmentDialog.updateNbEdits(0);
|
2018-11-21 18:30:00 +01:00
|
|
|
previewElmts.invalidSchemaWarningPreview.text($.i18n('wikidata-schema/invalid-schema-warning-preview'));
|
2018-03-30 18:26:24 +02:00
|
|
|
|
2018-03-30 12:40:01 +02:00
|
|
|
this._previewPanes = $(".schema-alignment-dialog-preview");
|
2018-04-13 18:39:20 +02:00
|
|
|
|
|
|
|
// Load the existing schema
|
2018-04-20 09:21:20 +02:00
|
|
|
this._reset(theProject.overlayModels.wikibaseSchema);
|
2018-04-13 18:39:20 +02:00
|
|
|
// Perform initial preview
|
2018-03-30 12:40:01 +02:00
|
|
|
this.preview();
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:39:20 +02:00
|
|
|
SchemaAlignmentDialog.updateColumns = function() {
|
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
this._columnArea = $(".schema-alignment-dialog-columns-area");
|
|
|
|
this._columnArea.empty();
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
|
|
|
var reconConfig = column.reconConfig;
|
|
|
|
var cell = SchemaAlignmentDialog._createDraggableColumn(column.name,
|
|
|
|
reconConfig && reconConfig.identifierSpace === this._wikibasePrefix && column.reconStats);
|
|
|
|
this._columnArea.append(cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
$('.wbs-reconciled-column').draggable({
|
|
|
|
helper: "clone",
|
|
|
|
cursor: "crosshair",
|
|
|
|
snap: ".wbs-item-input input, .wbs-target-input input",
|
|
|
|
zIndex: 100,
|
|
|
|
});
|
|
|
|
$('.wbs-unreconciled-column').draggable({
|
|
|
|
helper: "clone",
|
|
|
|
cursor: "crosshair",
|
|
|
|
snap: ".wbs-target-input input",
|
|
|
|
zIndex: 100,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-30 12:40:01 +02:00
|
|
|
SchemaAlignmentDialog.switchTab = function(targetTab) {
|
|
|
|
$('.main-view-panel-tab').hide();
|
|
|
|
$('.main-view-panel-tab-header').removeClass('active');
|
|
|
|
$('.main-view-panel-tab-header[href="'+targetTab+'"]').addClass('active');
|
|
|
|
$(targetTab).show();
|
|
|
|
resizeAll();
|
2018-03-30 18:26:24 +02:00
|
|
|
var panelHeight = this._viewPanel.height();
|
|
|
|
this._schemaPanel.height(panelHeight);
|
|
|
|
this._issuesPanel.height(panelHeight);
|
|
|
|
this._previewPanel.height(panelHeight);
|
2018-04-20 19:51:33 +02:00
|
|
|
// Resize the inside of the schema panel
|
|
|
|
var headerHeight = this._schemaElmts.schemaHeader.outerHeight();
|
|
|
|
this._schemaElmts.canvas.height(panelHeight - headerHeight - 10);
|
2018-11-01 19:46:37 +01:00
|
|
|
|
|
|
|
if (targetTab === "#view-panel") {
|
|
|
|
ui.dataTableView.render();
|
|
|
|
}
|
2018-03-30 12:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.isSetUp = function() {
|
|
|
|
return $('#wikidata-schema-panel').length !== 0;
|
|
|
|
}
|
|
|
|
|
2017-08-29 19:22:41 +02:00
|
|
|
SchemaAlignmentDialog.launch = function(onDone) {
|
|
|
|
this._onDone = onDone;
|
|
|
|
this._hasUnsavedChanges = false;
|
|
|
|
|
2018-03-30 12:40:01 +02:00
|
|
|
if (!SchemaAlignmentDialog.isSetUp()) {
|
|
|
|
SchemaAlignmentDialog.setUpTabs();
|
|
|
|
}
|
|
|
|
SchemaAlignmentDialog.switchTab('#wikidata-schema-panel');
|
|
|
|
|
|
|
|
// this._createDialog();
|
2017-08-29 19:22:41 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 18:39:20 +02:00
|
|
|
|
2018-04-11 19:08:04 +02:00
|
|
|
var beforeUnload = function(e) {
|
|
|
|
if (SchemaAlignmentDialog.isSetUp() && SchemaAlignmentDialog._hasUnsavedChanges === true) {
|
2018-11-21 18:30:00 +01:00
|
|
|
return (e = $.i18n('wikidata-schema/unsaved-warning'));
|
2018-03-30 19:31:19 +02:00
|
|
|
}
|
2018-04-11 19:08:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$(window).bind('beforeunload', beforeUnload);
|
2018-03-30 19:31:19 +02:00
|
|
|
|
2018-04-20 09:21:20 +02:00
|
|
|
SchemaAlignmentDialog._reset = function(schema) {
|
2017-09-06 12:58:30 +02:00
|
|
|
this._originalSchema = schema || { itemDocuments: [] };
|
2017-08-31 16:45:25 +02:00
|
|
|
this._schema = cloneDeep(this._originalSchema); // this is what can be munched on
|
2019-03-01 10:59:08 +01:00
|
|
|
this._copiedReference = null;
|
2017-08-29 19:22:41 +02:00
|
|
|
|
2017-08-31 16:45:25 +02:00
|
|
|
$('#schema-alignment-statements-container').empty();
|
2017-08-29 19:22:41 +02:00
|
|
|
|
2017-09-06 12:58:30 +02:00
|
|
|
if (this._schema && this._schema.itemDocuments) {
|
|
|
|
for(var i = 0; i != this._schema.itemDocuments.length; i++) {
|
|
|
|
this._addItem(this._schema.itemDocuments[i]);
|
2017-09-04 10:40:47 +02:00
|
|
|
}
|
|
|
|
}
|
2017-08-29 19:22:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._save = function(onDone) {
|
|
|
|
var self = this;
|
2017-08-31 10:11:00 +02:00
|
|
|
var schema = this.getJSON();
|
2017-08-29 19:22:41 +02:00
|
|
|
|
2019-02-19 22:51:55 +01:00
|
|
|
if (schema === null) {
|
|
|
|
alert($.i18n('wikidata-schema/incomplete-schema-could-not-be-saved'));
|
|
|
|
}
|
|
|
|
|
2017-08-29 19:22:41 +02:00
|
|
|
Refine.postProcess(
|
2017-08-31 10:11:00 +02:00
|
|
|
"wikidata",
|
|
|
|
"save-wikibase-schema",
|
2017-08-29 19:22:41 +02:00
|
|
|
{},
|
2017-08-31 10:11:00 +02:00
|
|
|
{ schema: JSON.stringify(schema) },
|
2017-08-29 19:22:41 +02:00
|
|
|
{},
|
|
|
|
{
|
|
|
|
onDone: function() {
|
2017-08-31 10:11:00 +02:00
|
|
|
theProject.overlayModels.wikibaseSchema = schema;
|
2017-08-29 19:22:41 +02:00
|
|
|
|
2017-09-04 22:00:58 +02:00
|
|
|
$('.invalid-schema-warning').hide();
|
2018-04-20 09:21:20 +02:00
|
|
|
self._changesCleared();
|
2017-08-29 19:22:41 +02:00
|
|
|
|
|
|
|
if (onDone) onDone();
|
2018-03-18 16:53:23 +01:00
|
|
|
},
|
|
|
|
onError: function(e) {
|
2018-11-21 18:30:00 +01:00
|
|
|
alert($.i18n('wikidata-schema/incomplete-schema-could-not-be-saved'));
|
2018-03-18 16:53:23 +01:00
|
|
|
},
|
2017-08-29 19:22:41 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-04-20 09:21:20 +02:00
|
|
|
SchemaAlignmentDialog._discardChanges = function() {
|
|
|
|
this._reset(theProject.overlayModels.wikibaseSchema);
|
|
|
|
this._changesCleared();
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._changesCleared = function() {
|
|
|
|
this._hasUnsavedChanges = false;
|
|
|
|
this._unsavedIndicator.hide();
|
|
|
|
this._schemaElmts.saveButton
|
|
|
|
.prop('disabled', true)
|
|
|
|
.addClass('disabled');
|
|
|
|
this._schemaElmts.discardButton
|
|
|
|
.prop('disabled', true)
|
|
|
|
.addClass('disabled');
|
|
|
|
}
|
|
|
|
|
2017-09-04 10:40:47 +02:00
|
|
|
SchemaAlignmentDialog._createDraggableColumn = function(name, reconciled) {
|
|
|
|
var cell = $("<div></div>").addClass('wbs-draggable-column').text(name);
|
|
|
|
if (reconciled) {
|
|
|
|
cell.addClass('wbs-reconciled-column');
|
|
|
|
} else {
|
|
|
|
cell.addClass('wbs-unreconciled-column');
|
|
|
|
}
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2018-03-19 17:49:23 +01:00
|
|
|
SchemaAlignmentDialog._plusButton = function(label, element) {
|
|
|
|
var plus = $('<b></b>').html('+ ').appendTo(element);
|
|
|
|
var span = $('<span></span>').text(label)
|
|
|
|
.appendTo(element);
|
|
|
|
}
|
|
|
|
|
2018-03-03 18:11:44 +01:00
|
|
|
SchemaAlignmentDialog._makeDeleteButton = function (noText) {
|
2018-03-03 22:51:10 +01:00
|
|
|
var button = $('<div></div>').addClass('wbs-remove').append(
|
2018-03-03 18:11:44 +01:00
|
|
|
$('<span></span>').addClass('wbs-icon')
|
|
|
|
);
|
|
|
|
if(noText === undefined) {
|
|
|
|
button.append(
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<span></span>').text($.i18n('wikidata-schema/remove')));
|
2018-03-03 18:11:44 +01:00
|
|
|
}
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2017-09-08 18:18:22 +02:00
|
|
|
/**************/
|
|
|
|
/*** ITEMS ****/
|
|
|
|
/**************/
|
|
|
|
|
2017-09-04 10:40:47 +02:00
|
|
|
SchemaAlignmentDialog._addItem = function(json) {
|
|
|
|
var subject = null;
|
|
|
|
var statementGroups = null;
|
2017-10-01 19:01:31 +02:00
|
|
|
var nameDescs = null;
|
2017-09-04 10:40:47 +02:00
|
|
|
if (json) {
|
|
|
|
subject = json.subject;
|
|
|
|
statementGroups = json.statementGroups;
|
2017-10-01 19:01:31 +02:00
|
|
|
nameDescs = json.nameDescs;
|
2017-09-04 10:40:47 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 19:22:41 +02:00
|
|
|
var item = $('<div></div>').addClass('wbs-item');
|
2017-10-01 19:01:31 +02:00
|
|
|
$('#schema-alignment-statements-container').append(item);
|
2018-03-19 17:49:23 +01:00
|
|
|
var deleteToolbar = $('<div></div>').addClass('wbs-toolbar')
|
|
|
|
.attr('style', 'margin-top: 10px')
|
|
|
|
.appendTo(item);
|
|
|
|
var deleteButton = SchemaAlignmentDialog._makeDeleteButton()
|
|
|
|
.appendTo(deleteToolbar)
|
2018-04-20 15:03:09 +02:00
|
|
|
.click(function(e) {
|
2018-03-19 17:49:23 +01:00
|
|
|
item.remove();
|
|
|
|
SchemaAlignmentDialog._hasChanged();
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2018-03-19 17:49:23 +01:00
|
|
|
});
|
2017-08-31 10:11:00 +02:00
|
|
|
var inputContainer = $('<div></div>').addClass('wbs-item-input').appendTo(item);
|
2017-09-05 16:21:42 +02:00
|
|
|
SchemaAlignmentDialog._initField(inputContainer, "wikibase-item", subject);
|
2018-03-19 17:49:23 +01:00
|
|
|
var right = $('<div></div>').addClass('wbs-item-contents').appendTo(item);
|
|
|
|
|
|
|
|
// Terms
|
|
|
|
$('<span></span>').addClass('wbs-namedesc-header')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('wikidata-schema/terms-header')).appendTo(right);
|
2018-03-19 17:49:23 +01:00
|
|
|
$('<div></div>').addClass('wbs-namedesc-container')
|
2018-11-21 18:30:00 +01:00
|
|
|
.attr('data-emptyplaceholder', $.i18n('wikidata-schema/empty-terms'))
|
2018-03-19 17:49:23 +01:00
|
|
|
.appendTo(right);
|
2018-03-14 18:17:23 +01:00
|
|
|
var termToolbar = $('<div></div>').addClass('wbs-toolbar').appendTo(right);
|
2018-03-19 17:49:23 +01:00
|
|
|
var addNamedescButton = $('<a></a>').addClass('wbs-add-namedesc')
|
2018-04-20 15:03:09 +02:00
|
|
|
.click(function(e) {
|
2017-10-01 19:01:31 +02:00
|
|
|
SchemaAlignmentDialog._addNameDesc(item, null);
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2018-03-14 18:17:23 +01:00
|
|
|
}).appendTo(termToolbar);
|
2018-03-19 17:49:23 +01:00
|
|
|
SchemaAlignmentDialog._plusButton(
|
2018-11-21 18:30:00 +01:00
|
|
|
$.i18n('wikidata-schema/add-term'), addNamedescButton);
|
2018-03-19 17:49:23 +01:00
|
|
|
|
|
|
|
// Clear the float
|
|
|
|
$('<div></div>').attr('style', 'clear: right').appendTo(right);
|
|
|
|
|
|
|
|
// Statements
|
|
|
|
$('<div></div>').addClass('wbs-statements-header')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('wikidata-schema/statements-header')).appendTo(right);
|
2018-03-19 17:49:23 +01:00
|
|
|
$('<div></div>').addClass('wbs-statement-group-container')
|
2018-11-21 18:30:00 +01:00
|
|
|
.attr('data-emptyplaceholder', $.i18n('wikidata-schema/empty-statements'))
|
2018-03-19 17:49:23 +01:00
|
|
|
.appendTo(right);
|
2018-03-14 18:17:23 +01:00
|
|
|
var statementToolbar = $('<div></div>').addClass('wbs-toolbar').appendTo(right);
|
2018-03-19 17:49:23 +01:00
|
|
|
var addStatementButton = $('<a></a>').addClass('wbs-add-statement-group')
|
2018-04-20 15:03:09 +02:00
|
|
|
.click(function(e) {
|
2017-09-04 10:40:47 +02:00
|
|
|
SchemaAlignmentDialog._addStatementGroup(item, null);
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2018-03-14 18:17:23 +01:00
|
|
|
}).appendTo(statementToolbar);
|
2018-03-19 17:49:23 +01:00
|
|
|
|
|
|
|
SchemaAlignmentDialog._plusButton(
|
2018-11-21 18:30:00 +01:00
|
|
|
$.i18n('wikidata-schema/add-statement'), addStatementButton);
|
2017-10-01 19:01:31 +02:00
|
|
|
|
2017-09-04 10:40:47 +02:00
|
|
|
if (statementGroups) {
|
|
|
|
for(var i = 0; i != statementGroups.length; i++) {
|
|
|
|
SchemaAlignmentDialog._addStatementGroup(item, statementGroups[i]);
|
|
|
|
}
|
|
|
|
}
|
2017-10-01 19:01:31 +02:00
|
|
|
|
|
|
|
if (nameDescs) {
|
|
|
|
for(var i = 0; i != nameDescs.length; i++) {
|
|
|
|
SchemaAlignmentDialog._addNameDesc(item, nameDescs[i]);
|
|
|
|
}
|
|
|
|
}
|
2017-08-29 19:22:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-31 10:11:00 +02:00
|
|
|
SchemaAlignmentDialog._itemToJSON = function (item) {
|
2017-10-01 19:01:31 +02:00
|
|
|
var statementGroupLst = new Array();
|
2019-02-19 22:51:55 +01:00
|
|
|
var statementsDom = item.find('.wbs-statement-group');
|
|
|
|
statementsDom.each(function () {
|
|
|
|
var statementGroupJSON = SchemaAlignmentDialog._statementGroupToJSON($(this));
|
|
|
|
if (statementGroupJSON !== null) {
|
|
|
|
statementGroupLst.push(statementGroupJSON);
|
|
|
|
}
|
2017-10-01 19:01:31 +02:00
|
|
|
});
|
|
|
|
var nameDescLst = new Array();
|
2019-02-19 22:51:55 +01:00
|
|
|
var nameDescsDom = item.find('.wbs-namedesc');
|
|
|
|
nameDescsDom.each(function () {
|
|
|
|
var nameDescJSON = SchemaAlignmentDialog._nameDescToJSON($(this));
|
|
|
|
if (nameDescJSON !== null) {
|
|
|
|
nameDescLst.push(nameDescJSON);
|
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
});
|
|
|
|
var inputContainer = item.find(".wbs-item-input").first();
|
2019-02-19 22:51:55 +01:00
|
|
|
var subjectJSON = SchemaAlignmentDialog._inputContainerToJSON(inputContainer);
|
|
|
|
if (subjectJSON !== null &&
|
|
|
|
statementGroupLst.length === statementsDom.length &&
|
|
|
|
nameDescLst.length === nameDescsDom.length) {
|
|
|
|
return {subject: subjectJSON,
|
2017-10-01 19:01:31 +02:00
|
|
|
statementGroups: statementGroupLst,
|
|
|
|
nameDescs: nameDescLst};
|
2019-02-19 22:51:55 +01:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
};
|
|
|
|
|
2017-10-01 19:01:31 +02:00
|
|
|
/**************************
|
|
|
|
* NAMES AND DESCRIPTIONS *
|
|
|
|
**************************/
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._addNameDesc = function(item, json) {
|
2019-06-13 11:56:06 +02:00
|
|
|
var term_type = 'ALIAS';
|
2017-10-01 19:01:31 +02:00
|
|
|
var value = null;
|
2019-06-13 11:56:06 +02:00
|
|
|
var override = false;
|
2017-10-01 19:01:31 +02:00
|
|
|
if (json) {
|
2019-06-13 11:56:06 +02:00
|
|
|
term_type = json.name_type.replace('_IF_NEW', '');
|
2017-10-01 19:01:31 +02:00
|
|
|
value = json.value;
|
2019-06-13 11:56:06 +02:00
|
|
|
override = json.name_type.indexOf('_IF_NEW') == -1;
|
2017-10-01 19:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var container = item.find('.wbs-namedesc-container').first();
|
|
|
|
var namedesc = $('<div></div>').addClass('wbs-namedesc').appendTo(container);
|
|
|
|
var type_container = $('<div></div>').addClass('wbs-namedesc-type').appendTo(namedesc);
|
|
|
|
var type_input = $('<select></select>').appendTo(type_container);
|
|
|
|
$('<option></option>')
|
2020-08-06 13:47:31 +02:00
|
|
|
.val('LABEL')
|
2019-06-13 11:56:06 +02:00
|
|
|
.text($.i18n('wikidata-schema/label'))
|
2017-10-01 19:01:31 +02:00
|
|
|
.appendTo(type_input);
|
|
|
|
$('<option></option>')
|
2020-08-06 13:47:31 +02:00
|
|
|
.val('DESCRIPTION')
|
2019-06-13 11:56:06 +02:00
|
|
|
.text($.i18n('wikidata-schema/description'))
|
2017-10-01 19:01:31 +02:00
|
|
|
.appendTo(type_input);
|
|
|
|
$('<option></option>')
|
2020-08-06 13:47:31 +02:00
|
|
|
.val('ALIAS')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('wikidata-schema/alias'))
|
2017-10-01 19:01:31 +02:00
|
|
|
.appendTo(type_input);
|
2019-06-13 11:56:06 +02:00
|
|
|
type_input.val(term_type);
|
2017-10-01 19:01:31 +02:00
|
|
|
|
|
|
|
var toolbar = $('<div></div>').addClass('wbs-toolbar').appendTo(namedesc);
|
2018-04-20 15:03:09 +02:00
|
|
|
SchemaAlignmentDialog._makeDeleteButton().click(function(e) {
|
2017-10-01 19:01:31 +02:00
|
|
|
namedesc.remove();
|
2018-03-04 11:55:47 +01:00
|
|
|
SchemaAlignmentDialog._hasChanged();
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2017-10-01 19:01:31 +02:00
|
|
|
}).appendTo(toolbar);
|
|
|
|
|
|
|
|
var right = $('<div></div>').addClass('wbs-right').appendTo(namedesc);
|
|
|
|
var value_container = $('<div></div>').addClass('wbs-namedesc-value').appendTo(namedesc);
|
|
|
|
SchemaAlignmentDialog._initField(value_container, "monolingualtext", value);
|
|
|
|
|
2019-06-13 11:56:06 +02:00
|
|
|
var override_container = $('<div></div>').addClass('wbs-namedesc-override').appendTo(namedesc);
|
|
|
|
var label = $('<label></label>').appendTo(override_container);
|
|
|
|
var checkbox = $('<input></input>')
|
|
|
|
.attr('type', 'checkbox')
|
|
|
|
.prop('checked', override)
|
|
|
|
.appendTo(label);
|
|
|
|
var span = $('<span></span>').text($.i18n('wikidata-schema/override-term')).appendTo(label);
|
|
|
|
checkbox.on('change', function(e) {
|
|
|
|
SchemaAlignmentDialog._hasChanged();
|
|
|
|
});
|
|
|
|
type_input.on('change', function(e) {
|
|
|
|
var checkbox_visible = type_input.val() !== 'ALIAS';
|
|
|
|
if (checkbox_visible) {
|
|
|
|
override_container.show();
|
|
|
|
} else {
|
|
|
|
override_container.hide();
|
|
|
|
}
|
|
|
|
SchemaAlignmentDialog._hasChanged();
|
|
|
|
});
|
|
|
|
|
2017-10-01 19:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._nameDescToJSON = function (namedesc) {
|
2019-06-13 11:56:06 +02:00
|
|
|
var term_type = namedesc.find('select').first().val();
|
|
|
|
var type = term_type;
|
|
|
|
if (term_type !== 'ALIAS') {
|
2020-08-06 13:47:31 +02:00
|
|
|
var override = namedesc.find('input[type=checkbox]').first().prop('checked');
|
2019-06-13 11:56:06 +02:00
|
|
|
if (!override) {
|
|
|
|
type = term_type + '_IF_NEW';
|
|
|
|
}
|
|
|
|
}
|
2017-10-01 19:01:31 +02:00
|
|
|
var value = namedesc.find('.wbs-namedesc-value').first().data("jsonValue");
|
|
|
|
return {
|
2018-01-02 18:39:12 +01:00
|
|
|
type: "wbnamedescexpr",
|
2017-10-01 19:01:31 +02:00
|
|
|
name_type: type,
|
|
|
|
value: value,
|
2018-01-02 18:39:12 +01:00
|
|
|
};
|
2017-10-01 19:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-08 18:18:22 +02:00
|
|
|
/********************
|
|
|
|
* STATEMENT GROUPS *
|
|
|
|
********************/
|
|
|
|
|
2017-09-04 10:40:47 +02:00
|
|
|
SchemaAlignmentDialog._addStatementGroup = function(item, json) {
|
|
|
|
var property = null;
|
|
|
|
var statements = null;
|
|
|
|
if (json) {
|
|
|
|
property = json.property;
|
|
|
|
statements = json.statements;
|
|
|
|
}
|
|
|
|
|
2017-08-29 19:22:41 +02:00
|
|
|
var container = item.find('.wbs-statement-group-container').first();
|
|
|
|
var statementGroup = $('<div></div>').addClass('wbs-statement-group');
|
2017-08-31 10:11:00 +02:00
|
|
|
var inputContainer = $('<div></div>').addClass('wbs-prop-input').appendTo(statementGroup);
|
2017-08-29 19:22:41 +02:00
|
|
|
var right = $('<div></div>').addClass('wbs-right').appendTo(statementGroup);
|
2017-09-05 16:21:42 +02:00
|
|
|
var statementContainer = $('<div></div>').addClass('wbs-statement-container').appendTo(right);
|
|
|
|
SchemaAlignmentDialog._initPropertyField(inputContainer, statementContainer, property);
|
2017-08-29 19:22:41 +02:00
|
|
|
var toolbar = $('<div></div>').addClass('wbs-toolbar').appendTo(right);
|
2018-04-20 15:03:09 +02:00
|
|
|
var addValueButton = $('<a></a>').addClass('wbs-add-statement').click(function(e) {
|
2017-09-05 16:21:42 +02:00
|
|
|
var datatype = inputContainer.data("jsonValue").datatype;
|
|
|
|
SchemaAlignmentDialog._addStatement(statementContainer, datatype, null);
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2017-09-05 16:21:42 +02:00
|
|
|
}).appendTo(toolbar).hide();
|
2018-11-21 18:30:00 +01:00
|
|
|
SchemaAlignmentDialog._plusButton($.i18n('wikidata-schema/add-value'), addValueButton);
|
2018-03-19 17:49:23 +01:00
|
|
|
var removeButton = SchemaAlignmentDialog._makeDeleteButton()
|
|
|
|
.addClass('wbs-remove-statement-group')
|
|
|
|
.appendTo(toolbar)
|
2018-04-20 15:03:09 +02:00
|
|
|
.click(function(e) {
|
2018-03-19 17:49:23 +01:00
|
|
|
statementGroup.remove();
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2018-03-19 17:49:23 +01:00
|
|
|
});
|
2017-09-05 16:21:42 +02:00
|
|
|
|
2017-08-29 19:22:41 +02:00
|
|
|
container.append(statementGroup);
|
2017-09-04 10:40:47 +02:00
|
|
|
|
|
|
|
if (statements) {
|
|
|
|
for (var i = 0; i != statements.length; i++) {
|
2017-09-05 16:21:42 +02:00
|
|
|
SchemaAlignmentDialog._addStatement(statementContainer, property.datatype, statements[i]);
|
|
|
|
addValueButton.show();
|
2018-03-19 17:49:23 +01:00
|
|
|
removeButton.hide();
|
2017-09-04 10:40:47 +02:00
|
|
|
}
|
2018-03-19 18:55:33 +01:00
|
|
|
} else {
|
|
|
|
inputContainer.find('input').focus();
|
2017-09-04 10:40:47 +02:00
|
|
|
}
|
2017-09-05 16:21:42 +02:00
|
|
|
|
2017-08-29 19:22:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-31 10:11:00 +02:00
|
|
|
SchemaAlignmentDialog._statementGroupToJSON = function (statementGroup) {
|
|
|
|
var lst = new Array();
|
2019-02-19 22:51:55 +01:00
|
|
|
var domStatements = statementGroup.find('.wbs-statement-container').first().children('.wbs-statement');
|
|
|
|
domStatements.each(function () {
|
|
|
|
var statementJSON = SchemaAlignmentDialog._statementToJSON($(this));
|
|
|
|
if (statementJSON !== null) {
|
|
|
|
lst.push(statementJSON);
|
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
});
|
|
|
|
var inputContainer = statementGroup.find(".wbs-prop-input").first();
|
2019-02-19 22:51:55 +01:00
|
|
|
var propertyJSON = SchemaAlignmentDialog._inputContainerToJSON(inputContainer);
|
|
|
|
if (propertyJSON !== null && domStatements.length === lst.length && lst.length > 0) {
|
|
|
|
return {property: propertyJSON,
|
|
|
|
statements: lst};
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
};
|
|
|
|
|
2017-09-08 18:18:22 +02:00
|
|
|
/**************
|
|
|
|
* STATEMENTS *
|
|
|
|
**************/
|
2017-08-31 10:11:00 +02:00
|
|
|
|
2017-09-05 16:21:42 +02:00
|
|
|
SchemaAlignmentDialog._addStatement = function(container, datatype, json) {
|
2017-09-04 10:40:47 +02:00
|
|
|
var qualifiers = null;
|
2017-09-08 18:18:22 +02:00
|
|
|
var references = null;
|
2017-09-04 10:40:47 +02:00
|
|
|
var value = null;
|
|
|
|
if (json) {
|
|
|
|
qualifiers = json.qualifiers;
|
2017-09-08 18:18:22 +02:00
|
|
|
references = json.references;
|
2017-09-04 10:40:47 +02:00
|
|
|
value = json.value;
|
|
|
|
}
|
|
|
|
|
2017-08-29 19:22:41 +02:00
|
|
|
var statement = $('<div></div>').addClass('wbs-statement');
|
2017-08-31 10:11:00 +02:00
|
|
|
var inputContainer = $('<div></div>').addClass('wbs-target-input').appendTo(statement);
|
2017-09-05 16:21:42 +02:00
|
|
|
SchemaAlignmentDialog._initField(inputContainer, datatype, value);
|
2017-09-07 12:37:00 +02:00
|
|
|
|
2017-09-08 18:18:22 +02:00
|
|
|
// If we are in a mainsnak...
|
2017-09-18 11:19:38 +02:00
|
|
|
// (see https://www.mediawiki.org/wiki/Wikibase/DataModel#Snaks)
|
2017-09-07 12:37:00 +02:00
|
|
|
if (container.parents('.wbs-statement').length == 0) {
|
2018-03-19 17:49:23 +01:00
|
|
|
// add delete button
|
|
|
|
var toolbar1 = $('<div></div>').addClass('wbs-toolbar').appendTo(statement);
|
2018-04-20 15:03:09 +02:00
|
|
|
SchemaAlignmentDialog._makeDeleteButton().click(function(e) {
|
2018-03-19 17:49:23 +01:00
|
|
|
SchemaAlignmentDialog._removeStatement(statement);
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2018-03-19 17:49:23 +01:00
|
|
|
}).appendTo(toolbar1);
|
|
|
|
|
2018-03-03 18:11:44 +01:00
|
|
|
// add rank
|
|
|
|
var rank = $('<div></div>').addClass('wbs-rank-selector-icon').prependTo(inputContainer);
|
2017-09-08 18:18:22 +02:00
|
|
|
|
|
|
|
// add qualifiers...
|
|
|
|
var right = $('<div></div>').addClass('wbs-right').appendTo(statement);
|
2017-09-07 12:37:00 +02:00
|
|
|
var qualifierContainer = $('<div></div>').addClass('wbs-qualifier-container').appendTo(right);
|
|
|
|
var toolbar2 = $('<div></div>').addClass('wbs-toolbar').appendTo(right);
|
2018-03-19 17:49:23 +01:00
|
|
|
var addQualifierButton = $('<a></a>').addClass('wbs-add-qualifier')
|
2018-04-20 15:03:09 +02:00
|
|
|
.click(function(e) {
|
2017-09-07 12:37:00 +02:00
|
|
|
SchemaAlignmentDialog._addQualifier(qualifierContainer, null);
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2017-09-07 12:37:00 +02:00
|
|
|
}).appendTo(toolbar2);
|
2018-11-21 18:30:00 +01:00
|
|
|
SchemaAlignmentDialog._plusButton($.i18n('wikidata-schema/add-qualifier'), addQualifierButton);
|
2018-03-19 17:49:23 +01:00
|
|
|
|
2017-09-07 12:37:00 +02:00
|
|
|
if (qualifiers) {
|
|
|
|
for (var i = 0; i != qualifiers.length; i++) {
|
|
|
|
SchemaAlignmentDialog._addQualifier(qualifierContainer, qualifiers[i]);
|
|
|
|
}
|
|
|
|
}
|
2017-09-08 18:18:22 +02:00
|
|
|
|
|
|
|
// and references
|
2018-03-19 17:49:23 +01:00
|
|
|
$('<div></div>').attr('style', 'clear: right').appendTo(statement);
|
2017-09-08 18:18:22 +02:00
|
|
|
var referencesToggleContainer = $('<div></div>').addClass('wbs-references-toggle').appendTo(statement);
|
2018-03-19 17:49:23 +01:00
|
|
|
var triangle = $('<div></div>').addClass('triangle-icon').addClass('pointing-right').appendTo(referencesToggleContainer);
|
2017-09-08 18:18:22 +02:00
|
|
|
var referencesToggle = $('<a></a>').appendTo(referencesToggleContainer);
|
|
|
|
right = $('<div></div>').addClass('wbs-right').appendTo(statement);
|
|
|
|
var referenceContainer = $('<div></div>').addClass('wbs-reference-container').appendTo(right);
|
2018-10-28 10:14:34 +01:00
|
|
|
referencesToggleContainer.click(function(e) {
|
2018-03-19 17:49:23 +01:00
|
|
|
triangle.toggleClass('pointing-down');
|
|
|
|
triangle.toggleClass('pointing-right');
|
2017-09-08 18:18:22 +02:00
|
|
|
referenceContainer.toggle(100);
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2017-09-08 18:18:22 +02:00
|
|
|
});
|
2017-09-19 11:39:52 +02:00
|
|
|
referenceContainer.hide();
|
2017-09-08 18:18:22 +02:00
|
|
|
var right2 = $('<div></div>').addClass('wbs-right').appendTo(right);
|
|
|
|
var toolbar3 = $('<div></div>').addClass('wbs-toolbar').appendTo(right2);
|
2018-03-19 17:49:23 +01:00
|
|
|
var addReferenceButton = $('<a></a>').addClass('wbs-add-reference')
|
2018-04-20 15:03:09 +02:00
|
|
|
.click(function(e) {
|
2017-09-19 11:39:52 +02:00
|
|
|
referenceContainer.show();
|
2017-09-08 18:18:22 +02:00
|
|
|
SchemaAlignmentDialog._addReference(referenceContainer, null);
|
|
|
|
SchemaAlignmentDialog._updateReferencesNumber(referenceContainer);
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2017-09-08 18:18:22 +02:00
|
|
|
}).appendTo(toolbar3);
|
2018-11-21 18:30:00 +01:00
|
|
|
SchemaAlignmentDialog._plusButton($.i18n('wikidata-schema/add-reference'), addReferenceButton);
|
2019-02-19 22:51:55 +01:00
|
|
|
|
|
|
|
var pasteToolbar = $('<div></div>').addClass('wbs-toolbar').appendTo(referencesToggleContainer);
|
|
|
|
var referencePaste = $('<span></span>')
|
|
|
|
.addClass('wbs-paste-reference')
|
2019-02-22 19:24:55 +01:00
|
|
|
.appendTo(pasteToolbar);
|
|
|
|
if (SchemaAlignmentDialog._copiedReference === null) {
|
|
|
|
referencePaste.hide();
|
|
|
|
}
|
2019-02-19 22:51:55 +01:00
|
|
|
var pasteIcon = $('<span></span>').addClass('wbs-icon').appendTo(referencePaste);
|
|
|
|
var referencePasteButton = $('<a></a>')
|
|
|
|
.addClass('wbs-paste-reference-button')
|
|
|
|
.text($.i18n('wikidata-schema/paste-reference'))
|
|
|
|
.appendTo(referencePaste)
|
|
|
|
.click(function(e) {
|
|
|
|
if (SchemaAlignmentDialog._copiedReference !== null) {
|
|
|
|
SchemaAlignmentDialog._addReference(referenceContainer, SchemaAlignmentDialog._copiedReference);
|
|
|
|
SchemaAlignmentDialog._updateReferencesNumber(referenceContainer);
|
|
|
|
referencePaste.hide();
|
|
|
|
SchemaAlignmentDialog._hasChanged();
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2017-09-08 18:18:22 +02:00
|
|
|
if (references) {
|
|
|
|
for (var i = 0; i != references.length; i++) {
|
|
|
|
SchemaAlignmentDialog._addReference(referenceContainer, references[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SchemaAlignmentDialog._updateReferencesNumber(referenceContainer);
|
2017-09-07 12:37:00 +02:00
|
|
|
}
|
2017-08-29 19:22:41 +02:00
|
|
|
container.append(statement);
|
|
|
|
}
|
|
|
|
|
2017-08-31 10:11:00 +02:00
|
|
|
SchemaAlignmentDialog._statementToJSON = function (statement) {
|
|
|
|
var inputContainer = statement.find(".wbs-target-input").first();
|
2017-09-07 12:37:00 +02:00
|
|
|
var qualifiersList = new Array();
|
2017-09-08 18:18:22 +02:00
|
|
|
var referencesList = new Array();
|
2019-02-19 22:51:55 +01:00
|
|
|
var qualifiersDom = statement.find('.wbs-qualifier-container').first().children();
|
|
|
|
qualifiersDom.each(function () {
|
|
|
|
var qualifierJSON = SchemaAlignmentDialog._qualifierToJSON($(this));
|
|
|
|
if (qualifierJSON !== null) {
|
|
|
|
qualifiersList.push(qualifierJSON);
|
|
|
|
}
|
2017-09-07 12:37:00 +02:00
|
|
|
});
|
2019-02-19 22:51:55 +01:00
|
|
|
var referencesDom = statement.find('.wbs-reference-container').first().children();
|
|
|
|
referencesDom.each(function () {
|
|
|
|
var referenceJSON = SchemaAlignmentDialog._referenceToJSON($(this));
|
|
|
|
if (referenceJSON !== null) {
|
|
|
|
referencesList.push(referenceJSON);
|
|
|
|
}
|
2017-09-08 18:18:22 +02:00
|
|
|
});
|
2019-02-19 22:51:55 +01:00
|
|
|
var valueJSON = SchemaAlignmentDialog._inputContainerToJSON(inputContainer);
|
|
|
|
if (referencesList.length === referencesDom.length &&
|
|
|
|
qualifiersList.length === qualifiersDom.length &&
|
|
|
|
valueJSON !== null) {
|
|
|
|
return {
|
|
|
|
value: valueJSON,
|
2017-09-07 12:37:00 +02:00
|
|
|
qualifiers: qualifiersList,
|
2017-09-08 18:18:22 +02:00
|
|
|
references: referencesList,
|
2019-02-19 22:51:55 +01:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
};
|
|
|
|
|
2017-09-08 18:18:22 +02:00
|
|
|
/**************
|
|
|
|
* QUALIFIERS *
|
|
|
|
**************/
|
|
|
|
|
2017-09-07 12:37:00 +02:00
|
|
|
SchemaAlignmentDialog._addQualifier = function(container, json) {
|
|
|
|
var property = null;
|
2017-09-07 15:00:43 +02:00
|
|
|
var value = null;
|
2017-09-07 12:37:00 +02:00
|
|
|
if (json) {
|
2017-09-07 15:00:43 +02:00
|
|
|
property = json.prop;
|
|
|
|
value = json.value;
|
2017-09-07 12:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var qualifier = $('<div></div>').addClass('wbs-qualifier').appendTo(container);
|
|
|
|
var toolbar1 = $('<div></div>').addClass('wbs-toolbar').appendTo(qualifier);
|
|
|
|
var inputContainer = $('<div></div>').addClass('wbs-prop-input').appendTo(qualifier);
|
|
|
|
var right = $('<div></div>').addClass('wbs-right').appendTo(qualifier);
|
2018-03-19 17:49:23 +01:00
|
|
|
var deleteButton = SchemaAlignmentDialog._makeDeleteButton()
|
|
|
|
.addClass('wbs-remove-statement-group')
|
2018-04-20 15:03:09 +02:00
|
|
|
.appendTo(toolbar1).click(function(e) {
|
2018-03-19 17:49:23 +01:00
|
|
|
qualifier.remove();
|
|
|
|
SchemaAlignmentDialog._hasChanged();
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2018-03-19 17:49:23 +01:00
|
|
|
});
|
2017-09-07 12:37:00 +02:00
|
|
|
var statementContainer = $('<div></div>').addClass('wbs-statement-container').appendTo(right);
|
|
|
|
SchemaAlignmentDialog._initPropertyField(inputContainer, statementContainer, property);
|
2017-09-07 15:00:43 +02:00
|
|
|
if (value && property) {
|
|
|
|
SchemaAlignmentDialog._addStatement(statementContainer, property.datatype, {value:value});
|
2018-10-27 21:58:16 +02:00
|
|
|
} else {
|
|
|
|
inputContainer.find('input').focus();
|
2017-09-07 15:00:43 +02:00
|
|
|
}
|
2017-09-07 12:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._qualifierToJSON = function(elem) {
|
|
|
|
var prop = elem.find(".wbs-prop-input").first();
|
|
|
|
var target = elem.find(".wbs-target-input").first();
|
2019-02-19 22:51:55 +01:00
|
|
|
var propJSON = SchemaAlignmentDialog._inputContainerToJSON(prop);
|
|
|
|
var valueJSON = SchemaAlignmentDialog._inputContainerToJSON(target);
|
|
|
|
if (propJSON !== null && valueJSON !== null) {
|
|
|
|
return {
|
|
|
|
prop: propJSON,
|
|
|
|
value: valueJSON,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-09-07 12:37:00 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 18:18:22 +02:00
|
|
|
/**************
|
|
|
|
* REFERENCES *
|
|
|
|
**************/
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._addReference = function(container, json) {
|
|
|
|
var snaks = null;
|
|
|
|
if (json) {
|
|
|
|
snaks = json.snaks;
|
|
|
|
}
|
|
|
|
|
|
|
|
var reference = $('<div></div>').addClass('wbs-reference').appendTo(container);
|
|
|
|
var referenceHeader = $('<div></div>').addClass('wbs-reference-header').appendTo(reference);
|
2019-02-19 22:51:55 +01:00
|
|
|
var referenceCopy = $('<span></span>').addClass('wbs-copy-reference').appendTo(referenceHeader);
|
|
|
|
var referenceCopyIcon = $('<span></span>').addClass('wbs-icon').appendTo(referenceCopy);
|
|
|
|
var copyButton = $('<span></span>')
|
|
|
|
.addClass('wbs-copy-reference-button')
|
|
|
|
.text($.i18n('wikidata-schema/copy-reference'))
|
|
|
|
.appendTo(referenceCopy)
|
|
|
|
.click(function(e) {
|
|
|
|
if (SchemaAlignmentDialog._copyReference(reference)) {
|
|
|
|
$(this).text($.i18n('wikidata-schema/reference-copied'))
|
|
|
|
.parent().addClass('wbs-copied-reference');
|
|
|
|
container.parent().parent().find('.wbs-paste-reference').hide();
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2017-09-08 18:18:22 +02:00
|
|
|
var toolbarRef = $('<div></div>').addClass('wbs-toolbar').appendTo(referenceHeader);
|
2018-04-20 15:03:09 +02:00
|
|
|
SchemaAlignmentDialog._makeDeleteButton().click(function(e) {
|
2017-09-08 18:18:22 +02:00
|
|
|
reference.remove();
|
|
|
|
SchemaAlignmentDialog._updateReferencesNumber(container);
|
2017-09-18 11:19:38 +02:00
|
|
|
SchemaAlignmentDialog._hasChanged();
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2017-09-08 18:18:22 +02:00
|
|
|
}).appendTo(toolbarRef);
|
|
|
|
var right = $('<div></div>').addClass('wbs-right').appendTo(reference);
|
|
|
|
var qualifierContainer = $('<div></div>').addClass('wbs-qualifier-container').appendTo(right);
|
|
|
|
var toolbar2 = $('<div></div>').addClass('wbs-toolbar').appendTo(right);
|
2018-03-19 17:49:23 +01:00
|
|
|
var addSnakButton = $('<a></a>').addClass('wbs-add-qualifier')
|
2018-04-20 15:03:09 +02:00
|
|
|
.click(function(e) {
|
2017-09-08 18:18:22 +02:00
|
|
|
SchemaAlignmentDialog._addQualifier(qualifierContainer, null);
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2017-09-08 18:18:22 +02:00
|
|
|
}).appendTo(toolbar2);
|
2018-11-21 18:30:00 +01:00
|
|
|
SchemaAlignmentDialog._plusButton($.i18n('wikidata-schema/add-reference-snak'), addSnakButton);
|
2017-09-08 18:18:22 +02:00
|
|
|
|
|
|
|
if (snaks) {
|
|
|
|
for (var i = 0; i != snaks.length; i++) {
|
|
|
|
SchemaAlignmentDialog._addQualifier(qualifierContainer, snaks[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SchemaAlignmentDialog._addQualifier(qualifierContainer, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._referenceToJSON = function(reference) {
|
|
|
|
var snaks = reference.find('.wbs-qualifier-container').first().children();
|
|
|
|
var snaksList = new Array();
|
|
|
|
snaks.each(function () {
|
2019-02-19 22:51:55 +01:00
|
|
|
var qualifier = SchemaAlignmentDialog._qualifierToJSON($(this));
|
|
|
|
if (qualifier !== null) {
|
|
|
|
snaksList.push(qualifier);
|
|
|
|
}
|
2017-09-08 18:18:22 +02:00
|
|
|
});
|
2019-02-19 22:51:55 +01:00
|
|
|
if (snaksList.length === snaks.length) {
|
|
|
|
return {snaks:snaksList};
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-09-08 18:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._updateReferencesNumber = function(container) {
|
|
|
|
var childrenCount = container.children().length;
|
|
|
|
var statement = container.parents('.wbs-statement');
|
|
|
|
var a = statement.find('.wbs-references-toggle a').first();
|
2018-11-21 18:30:00 +01:00
|
|
|
a.html(childrenCount+$.i18n('wikidata-schema/nb-references'));
|
2017-09-08 18:18:22 +02:00
|
|
|
}
|
|
|
|
|
2019-02-19 22:51:55 +01:00
|
|
|
SchemaAlignmentDialog._copyReference = function(reference) {
|
|
|
|
// mark any other copied reference as not copied
|
|
|
|
$('.wbs-copy-reference-button')
|
|
|
|
.text($.i18n('wikidata-schema/copy-reference'));
|
|
|
|
$('.wbs-copy-reference')
|
|
|
|
.removeClass('wbs-copied-reference');
|
|
|
|
var copiedReference = SchemaAlignmentDialog._referenceToJSON(reference);
|
|
|
|
if (copiedReference !== null) {
|
|
|
|
SchemaAlignmentDialog._copiedReference = copiedReference;
|
|
|
|
$('.wbs-paste-reference').show();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 18:18:22 +02:00
|
|
|
/************************
|
|
|
|
* FIELD INITIALIZATION *
|
|
|
|
************************/
|
|
|
|
|
2017-09-05 16:21:42 +02:00
|
|
|
SchemaAlignmentDialog._getPropertyType = function(pid, callback) {
|
|
|
|
$.ajax({
|
|
|
|
url:'https://www.wikidata.org/w/api.php',
|
|
|
|
data: {
|
|
|
|
action: "wbgetentities",
|
|
|
|
format: "json",
|
|
|
|
ids: pid,
|
|
|
|
props: "datatype",
|
|
|
|
},
|
|
|
|
dataType: "jsonp",
|
2018-01-02 18:39:12 +01:00
|
|
|
success: function(data) {
|
2017-09-05 16:21:42 +02:00
|
|
|
callback(data.entities[pid].datatype);
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._initPropertyField = function(inputContainer, targetContainer, initialValue) {
|
2017-08-31 10:11:00 +02:00
|
|
|
var input = $('<input></input>').appendTo(inputContainer);
|
2018-11-21 18:30:00 +01:00
|
|
|
input.attr("placeholder", $.i18n('wikidata-schema/property-placeholder'));
|
2017-08-31 10:11:00 +02:00
|
|
|
|
|
|
|
if (this._reconService !== null) {
|
2017-09-05 16:21:42 +02:00
|
|
|
endpoint = this._reconService.suggest.property;
|
|
|
|
var suggestConfig = $.extend({}, endpoint);
|
|
|
|
suggestConfig.key = null;
|
|
|
|
suggestConfig.query_param_name = "prefix";
|
|
|
|
|
|
|
|
input.suggestP(suggestConfig).bind("fb-select", function(evt, data) {
|
|
|
|
// Fetch the type of this property and add the appropriate target value type
|
2017-09-07 12:37:00 +02:00
|
|
|
var statementGroup = inputContainer.parents(".wbs-statement-group, .wbs-qualifier").first();
|
2017-09-05 16:21:42 +02:00
|
|
|
SchemaAlignmentDialog._getPropertyType(data.id, function(datatype) {
|
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type : "wbpropconstant",
|
|
|
|
pid : data.id,
|
|
|
|
label: data.name,
|
|
|
|
datatype: datatype,
|
|
|
|
});
|
|
|
|
SchemaAlignmentDialog._addStatement(targetContainer, datatype, null);
|
|
|
|
var addValueButtons = targetContainer.parent().find('.wbs-add-statement');
|
2018-03-19 17:49:23 +01:00
|
|
|
var removeGroupButton = targetContainer.parent().find('.wbs-remove-statement-group');
|
|
|
|
removeGroupButton.hide();
|
2017-09-05 16:21:42 +02:00
|
|
|
addValueButtons.show();
|
|
|
|
});
|
|
|
|
SchemaAlignmentDialog._hasChanged();
|
|
|
|
}).bind("fb-textchange", function(evt, data) {
|
|
|
|
inputContainer.data("jsonValue", null);
|
|
|
|
targetContainer.find('.wbs-statement').remove();
|
|
|
|
var addValueButtons = targetContainer.parent().find('.wbs-add-statement');
|
2018-03-19 17:49:23 +01:00
|
|
|
var removeGroupButton = targetContainer.parent().find('.wbs-remove-statement-group');
|
2017-09-05 16:21:42 +02:00
|
|
|
addValueButtons.hide();
|
2018-03-19 17:49:23 +01:00
|
|
|
removeGroupButton.show();
|
2017-09-05 16:21:42 +02:00
|
|
|
});
|
2018-03-19 18:55:33 +01:00
|
|
|
// adds tweaks to display the validation status more clearly, like in Wikidata
|
|
|
|
fixSuggestInput(input);
|
2017-09-05 16:21:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init with the provided initial value.
|
|
|
|
if (initialValue) {
|
|
|
|
if (initialValue.type === "wbpropconstant") {
|
|
|
|
input.val(initialValue.label);
|
2018-03-19 18:55:33 +01:00
|
|
|
input.addClass('wbs-validated-input');
|
2017-09-05 16:21:42 +02:00
|
|
|
}
|
|
|
|
inputContainer.data("jsonValue", initialValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-28 17:59:03 +02:00
|
|
|
SchemaAlignmentDialog._initField = function(inputContainer, mode, initialValue, changedCallback) {
|
2017-09-05 16:21:42 +02:00
|
|
|
var input = $('<input></input>').appendTo(inputContainer);
|
2017-09-28 17:59:03 +02:00
|
|
|
|
|
|
|
if (! changedCallback) {
|
|
|
|
changedCallback = SchemaAlignmentDialog._hasChanged;
|
|
|
|
}
|
2017-09-05 16:21:42 +02:00
|
|
|
|
2018-03-03 22:51:10 +01:00
|
|
|
if (this._reconService !== null && (mode === "wikibase-item" || mode === "unit")) {
|
|
|
|
if (mode === "wikibase-item") {
|
2018-11-21 18:30:00 +01:00
|
|
|
input.attr("placeholder", $.i18n('wikidata-schema/item-or-reconciled-column'));
|
2018-03-03 22:51:10 +01:00
|
|
|
} else {
|
2018-11-21 18:30:00 +01:00
|
|
|
input.attr("placeholder", $.i18n('wikidata-schema/unit'));
|
2018-03-03 22:51:10 +01:00
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
var endpoint = null;
|
2017-09-05 16:21:42 +02:00
|
|
|
endpoint = this._reconService.suggest.entity;
|
2017-08-31 10:11:00 +02:00
|
|
|
var suggestConfig = $.extend({}, endpoint);
|
|
|
|
suggestConfig.key = null;
|
|
|
|
suggestConfig.query_param_name = "prefix";
|
2019-02-19 15:42:04 +01:00
|
|
|
if ('view' in this._reconService && 'url' in this._reconService.view && !('view_url' in endpoint)) {
|
2019-02-25 11:15:29 +01:00
|
|
|
suggestConfig.view_url = this._reconService.view.url;
|
2019-02-19 15:42:04 +01:00
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
|
|
|
|
|
2019-02-25 11:15:29 +01:00
|
|
|
input.suggest(suggestConfig).bind("fb-select", function(evt, data) {
|
2017-09-05 16:21:42 +02:00
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type : "wbitemconstant",
|
|
|
|
qid : data.id,
|
|
|
|
label: data.name,
|
|
|
|
});
|
2017-09-28 17:59:03 +02:00
|
|
|
changedCallback();
|
2017-08-31 10:11:00 +02:00
|
|
|
});
|
2018-03-19 18:55:33 +01:00
|
|
|
// adds tweaks to display the validation status more clearly, like in Wikidata
|
|
|
|
fixSuggestInput(input);
|
2018-03-04 00:46:22 +01:00
|
|
|
|
|
|
|
} else if (this._reconService !== null && mode === "wikibase-property") {
|
|
|
|
var endpoint = null;
|
|
|
|
endpoint = this._reconService.suggest.property;
|
|
|
|
var suggestConfig = $.extend({}, endpoint);
|
|
|
|
suggestConfig.key = null;
|
|
|
|
suggestConfig.query_param_name = "prefix";
|
|
|
|
|
|
|
|
input.suggestP(suggestConfig).bind("fb-select", function(evt, data) {
|
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type : "wbpropconstant",
|
|
|
|
pid : data.id,
|
|
|
|
label: data.name,
|
|
|
|
datatype: "not-important",
|
|
|
|
});
|
|
|
|
changedCallback();
|
|
|
|
});
|
2018-03-19 18:55:33 +01:00
|
|
|
// adds tweaks to display the validation status more clearly, like in Wikidata
|
|
|
|
fixSuggestInput(input);
|
2018-03-04 00:46:22 +01:00
|
|
|
|
2017-09-18 11:19:38 +02:00
|
|
|
} else if (mode === "time") {
|
2019-02-19 23:46:33 +01:00
|
|
|
input.attr("placeholder", "YYYY(-MM(-DD))");
|
2017-09-18 11:19:38 +02:00
|
|
|
var propagateValue = function(val) {
|
|
|
|
// TODO add validation here
|
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type: "wbdateconstant",
|
|
|
|
value: val,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
propagateValue("");
|
|
|
|
input.change(function() {
|
|
|
|
propagateValue($(this).val());
|
2017-09-28 17:59:03 +02:00
|
|
|
changedCallback();
|
2017-09-18 11:19:38 +02:00
|
|
|
});
|
2018-03-04 00:46:22 +01:00
|
|
|
|
2019-10-21 11:06:37 +02:00
|
|
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^((\d{4}(-[0-1]\d(-[0-3]\d)?)?)|TODAY)$/);
|
2017-09-19 11:39:52 +02:00
|
|
|
} else if (mode === "globe-coordinate") {
|
2018-03-23 13:25:50 +01:00
|
|
|
input.attr("placeholder", "lat,lon");
|
2017-09-18 11:19:38 +02:00
|
|
|
var propagateValue = function(val) {
|
|
|
|
// TODO add validation here
|
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type: "wblocationconstant",
|
|
|
|
value: val,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
propagateValue("");
|
|
|
|
input.change(function() {
|
|
|
|
propagateValue($(this).val());
|
2017-09-28 17:59:03 +02:00
|
|
|
changedCallback();
|
2017-09-18 11:19:38 +02:00
|
|
|
});
|
2018-03-04 00:46:22 +01:00
|
|
|
|
2018-03-23 13:25:50 +01:00
|
|
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^[\-+]?\d+(\.\d*)?[,\/][\-+]?\d+(\.\d*)?([,\/]\d+(\.\d*)?)?$/);
|
2017-09-28 17:59:03 +02:00
|
|
|
} else if (mode === "language") {
|
|
|
|
input.attr("placeholder", "lang");
|
2017-10-01 19:01:31 +02:00
|
|
|
input.addClass("wbs-language-input");
|
2017-09-28 17:59:03 +02:00
|
|
|
input.langsuggest().bind("fb-select", function(evt, data) {
|
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type: "wblanguageconstant",
|
|
|
|
id: data.id,
|
|
|
|
label: data.name,
|
|
|
|
});
|
|
|
|
changedCallback();
|
|
|
|
});
|
2018-03-19 18:55:33 +01:00
|
|
|
fixSuggestInput(input);
|
2018-03-04 00:46:22 +01:00
|
|
|
|
2017-09-28 17:59:03 +02:00
|
|
|
} else if (mode === "monolingualtext") {
|
|
|
|
input.remove();
|
|
|
|
var inputContainerLanguage = $('<div></div>')
|
|
|
|
.addClass('wbs-monolingual-container')
|
2018-03-03 22:51:10 +01:00
|
|
|
.width('30%')
|
2017-09-28 17:59:03 +02:00
|
|
|
.appendTo(inputContainer);
|
|
|
|
var inputContainerValue = $('<div></div>')
|
|
|
|
.addClass('wbs-monolingual-container')
|
2018-03-03 22:51:10 +01:00
|
|
|
.width('70%')
|
2017-09-28 17:59:03 +02:00
|
|
|
.appendTo(inputContainer);
|
|
|
|
|
|
|
|
var langValue = null;
|
|
|
|
var strValue = null;
|
|
|
|
if (initialValue) {
|
|
|
|
langValue = initialValue.language;
|
|
|
|
strValue = initialValue.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
var propagateValue = function() {
|
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type: "wbmonolingualexpr",
|
|
|
|
language: inputContainerLanguage.data("jsonValue"),
|
|
|
|
value: inputContainerValue.data("jsonValue"),
|
|
|
|
});
|
|
|
|
changedCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._initField(inputContainerLanguage, "language", langValue, propagateValue);
|
2018-03-03 22:51:10 +01:00
|
|
|
SchemaAlignmentDialog._initField(inputContainerValue, "string", strValue, propagateValue);
|
2018-03-04 00:46:22 +01:00
|
|
|
|
2018-03-03 22:51:10 +01:00
|
|
|
} else if (mode === "quantity") {
|
|
|
|
input.remove();
|
|
|
|
var inputContainerAmount = $('<div></div>')
|
|
|
|
.addClass('wbs-quantity-container')
|
|
|
|
.width('60%')
|
|
|
|
.appendTo(inputContainer);
|
|
|
|
var inputContainerUnit = $('<div></div>')
|
|
|
|
.addClass('wbs-quantity-container')
|
|
|
|
.width('40%')
|
|
|
|
.appendTo(inputContainer);
|
|
|
|
|
|
|
|
var amountValue = null;
|
|
|
|
var unitValue = null;
|
|
|
|
if (initialValue) {
|
|
|
|
amountValue = initialValue.amount;
|
2018-03-16 12:52:44 +01:00
|
|
|
unitValue = initialValue.unit;
|
2018-03-03 22:51:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var propagateValue = function() {
|
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type: "wbquantityexpr",
|
|
|
|
amount: inputContainerAmount.data("jsonValue"),
|
|
|
|
unit: inputContainerUnit.data("jsonValue"),
|
|
|
|
});
|
|
|
|
changedCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog._initField(inputContainerAmount, "amount", amountValue, propagateValue);
|
|
|
|
SchemaAlignmentDialog._initField(inputContainerUnit, "unit", unitValue, propagateValue);
|
2018-03-04 00:46:22 +01:00
|
|
|
|
|
|
|
} else {
|
2017-09-05 16:21:42 +02:00
|
|
|
var propagateValue = function(val) {
|
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type: "wbstringconstant",
|
|
|
|
value: val,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
propagateValue("");
|
|
|
|
input.change(function() {
|
|
|
|
propagateValue($(this).val());
|
2017-09-28 17:59:03 +02:00
|
|
|
changedCallback();
|
2017-09-05 16:21:42 +02:00
|
|
|
});
|
2018-03-03 22:51:10 +01:00
|
|
|
if (mode === "amount") {
|
2018-11-21 18:30:00 +01:00
|
|
|
input.attr("placeholder", $.i18n('wikidata-schema/amount'));
|
2018-03-23 13:25:50 +01:00
|
|
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^[\-+]?\d+(\.\d*)?(E[\-+]\d+)?$/);
|
2018-03-04 00:46:22 +01:00
|
|
|
} else if (mode === "url") {
|
2018-11-21 18:30:00 +01:00
|
|
|
input.attr("placeholder", $.i18n('wikidata-schema/full-url'));
|
2018-03-23 13:25:50 +01:00
|
|
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^https?:\/\/.+$/);
|
2018-03-04 00:46:22 +01:00
|
|
|
} else if (mode === "tabular-data") {
|
2018-11-21 18:30:00 +01:00
|
|
|
input.attr("placeholder", $.i18n('wikidata-schema/tabular-data-with-prefix'));
|
2018-03-23 13:25:50 +01:00
|
|
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^Data:.+$/);
|
2018-03-04 00:46:22 +01:00
|
|
|
} else if (mode === "commonsMedia") {
|
2018-11-21 18:30:00 +01:00
|
|
|
input.attr("placeholder", $.i18n('wikidata-schema/commons-media'));
|
2018-03-04 00:46:22 +01:00
|
|
|
} else if (mode === "math") {
|
2018-11-21 18:30:00 +01:00
|
|
|
input.attr("placeholder", $.i18n('wikidata-schema/math-expression'));
|
2018-03-04 00:46:22 +01:00
|
|
|
} else if (mode === "geo-shape") {
|
2018-11-21 18:30:00 +01:00
|
|
|
input.attr("placeholder", $.i18n('wikidata-schema/geoshape-with-prefix'));
|
2018-03-23 13:25:50 +01:00
|
|
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^Data:.+$/);
|
|
|
|
} else {
|
|
|
|
SchemaAlignmentDialog.setupStringInputValidation(input, /^.+$/);
|
2018-03-04 00:46:22 +01:00
|
|
|
}
|
|
|
|
if (mode !== "external-id" &&
|
|
|
|
mode !== "url" &&
|
|
|
|
mode !== "string" &&
|
|
|
|
mode !== "amount" &&
|
|
|
|
mode !== "tabular-data" &&
|
|
|
|
mode !== "commonsMedia" &&
|
|
|
|
mode !== "geo-shape" &&
|
|
|
|
mode !== "math") {
|
2018-11-21 18:30:00 +01:00
|
|
|
alert($.i18n('wikidata-schema/datatype-not-supported-yet'));
|
2018-03-03 22:51:10 +01:00
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
}
|
|
|
|
|
2017-09-04 10:40:47 +02:00
|
|
|
var acceptDraggableColumn = function(column) {
|
|
|
|
input.hide();
|
2018-03-16 12:52:44 +01:00
|
|
|
input.val("");
|
2017-09-04 10:40:47 +02:00
|
|
|
var columnDiv = $('<div></div>').appendTo(inputContainer);
|
|
|
|
column.appendTo(columnDiv);
|
2018-03-03 22:51:10 +01:00
|
|
|
var origText = column.text();
|
|
|
|
column.text("");
|
|
|
|
column.append($('<div></div>').addClass('wbs-restricted-column-name').text(origText));
|
2018-03-03 18:11:44 +01:00
|
|
|
var deleteButton = SchemaAlignmentDialog._makeDeleteButton(true).appendTo(column);
|
2018-11-21 18:30:00 +01:00
|
|
|
deleteButton.attr('alt', $.i18n('wikidata-schema/remove-column'));
|
2018-04-20 15:03:09 +02:00
|
|
|
deleteButton.click(function (e) {
|
2017-09-04 10:40:47 +02:00
|
|
|
columnDiv.remove();
|
|
|
|
input.show();
|
2018-03-16 12:52:44 +01:00
|
|
|
inputContainer.data("jsonValue", null);
|
2017-09-28 17:59:03 +02:00
|
|
|
changedCallback();
|
2018-04-20 15:03:09 +02:00
|
|
|
e.preventDefault();
|
2017-09-04 10:40:47 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-09-05 16:21:42 +02:00
|
|
|
// Make it droppable
|
|
|
|
var acceptClass = ".wbs-draggable-column";
|
|
|
|
var wbVariableType = "wbstringvariable";
|
2018-03-16 12:52:44 +01:00
|
|
|
if (mode === "wikibase-item" || mode === "unit") {
|
2017-09-05 16:21:42 +02:00
|
|
|
acceptClass = ".wbs-reconciled-column";
|
|
|
|
wbVariableType = "wbitemvariable";
|
2017-09-18 11:19:38 +02:00
|
|
|
} else if (mode === "time") {
|
|
|
|
wbVariableType = "wbdatevariable";
|
2017-09-19 11:39:52 +02:00
|
|
|
} else if (mode === "globe-coordinate") {
|
2017-09-18 11:19:38 +02:00
|
|
|
wbVariableType = "wblocationvariable";
|
2018-03-16 12:52:44 +01:00
|
|
|
} else if (mode === "monolingualtext" || mode === "quantity") {
|
2017-09-28 17:59:03 +02:00
|
|
|
wbVariableType = null; // not droppable directly
|
|
|
|
} else if (mode === "language") {
|
|
|
|
wbVariableType = "wblanguagevariable";
|
|
|
|
}
|
2017-09-05 16:21:42 +02:00
|
|
|
|
2017-09-28 17:59:03 +02:00
|
|
|
if (wbVariableType) {
|
|
|
|
inputContainer.droppable({
|
|
|
|
accept: acceptClass,
|
|
|
|
}).on("drop", function (evt, ui) {
|
|
|
|
var column = ui.draggable.clone();
|
|
|
|
acceptDraggableColumn(column);
|
|
|
|
inputContainer.data("jsonValue", {
|
|
|
|
type : wbVariableType,
|
|
|
|
columnName: ui.draggable.text(),
|
|
|
|
});
|
|
|
|
changedCallback();
|
|
|
|
return true;
|
|
|
|
}).on("dropactivate", function(evt, ui) {
|
|
|
|
input.addClass("wbs-accepting-input");
|
|
|
|
}).on("dropdeactivate", function(evt, ui) {
|
|
|
|
input.removeClass("wbs-accepting-input");
|
|
|
|
});
|
|
|
|
}
|
2017-09-05 16:21:42 +02:00
|
|
|
|
2017-09-04 10:40:47 +02:00
|
|
|
// Init with the provided initial value.
|
|
|
|
if (initialValue) {
|
2018-03-19 18:55:33 +01:00
|
|
|
if (initialValue.type === "wbitemconstant" || initialValue.type === "wbpropconstant") {
|
2017-09-04 10:40:47 +02:00
|
|
|
input.val(initialValue.label);
|
2018-03-19 18:55:33 +01:00
|
|
|
input.addClass("wbs-validated-input");
|
2017-09-04 10:40:47 +02:00
|
|
|
} else if (initialValue.type == "wbitemvariable") {
|
|
|
|
var cell = SchemaAlignmentDialog._createDraggableColumn(initialValue.columnName, true);
|
|
|
|
acceptDraggableColumn(cell);
|
2017-09-28 17:59:03 +02:00
|
|
|
} else if (initialValue.type === "wbstringconstant" ||
|
|
|
|
initialValue.type === "wbdateconstant" ||
|
|
|
|
initialValue.type === "wblocationconstant") {
|
2017-09-05 16:21:42 +02:00
|
|
|
input.val(initialValue.value);
|
2017-09-28 17:59:03 +02:00
|
|
|
} else if (initialValue.type === "wblanguageconstant") {
|
|
|
|
input.val(initialValue.id);
|
2018-04-11 19:08:04 +02:00
|
|
|
input.addClass("wbs-validated-input");
|
2017-09-28 17:59:03 +02:00
|
|
|
} else if (initialValue.type === "wbstringvariable" ||
|
|
|
|
initialValue.type === "wbdatevariable" ||
|
|
|
|
initialValue.type === "wblocationvariable" ||
|
|
|
|
initialValue.type === "wblanguagevariable") {
|
2017-09-05 16:21:42 +02:00
|
|
|
var cell = SchemaAlignmentDialog._createDraggableColumn(initialValue.columnName, false);
|
|
|
|
acceptDraggableColumn(cell);
|
2017-09-04 10:40:47 +02:00
|
|
|
}
|
|
|
|
inputContainer.data("jsonValue", initialValue);
|
|
|
|
}
|
2017-08-29 19:22:41 +02:00
|
|
|
}
|
|
|
|
|
2018-03-23 13:25:50 +01:00
|
|
|
SchemaAlignmentDialog.setupStringInputValidation = function(input, regex) {
|
|
|
|
input.focus(function() {
|
|
|
|
input.removeClass('wbs-unvalidated-input');
|
|
|
|
}).blur(function() {
|
|
|
|
var currentValue = input.val();
|
|
|
|
if (regex.test(currentValue)) {
|
|
|
|
input.addClass('wbs-validated-input');
|
|
|
|
} else {
|
|
|
|
input.addClass('wbs-unvalidated-input');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-31 10:11:00 +02:00
|
|
|
SchemaAlignmentDialog._inputContainerToJSON = function (inputContainer) {
|
2017-09-07 12:37:00 +02:00
|
|
|
var data = inputContainer.data();
|
2019-02-19 22:51:55 +01:00
|
|
|
if (data && 'jsonValue' in data) {
|
2017-09-07 12:37:00 +02:00
|
|
|
return data.jsonValue;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
};
|
|
|
|
|
2017-08-29 19:22:41 +02:00
|
|
|
SchemaAlignmentDialog._removeStatement = function(statement) {
|
2017-09-07 12:37:00 +02:00
|
|
|
var statementGroup = statement.parents('.wbs-statement-group, .wbs-qualifier').first();
|
2017-08-29 19:22:41 +02:00
|
|
|
statement.remove();
|
|
|
|
var remainingStatements = statementGroup.find('.wbs-statement').length;
|
|
|
|
if (remainingStatements === 0) {
|
|
|
|
statementGroup.remove();
|
|
|
|
}
|
2017-09-04 22:00:58 +02:00
|
|
|
SchemaAlignmentDialog._hasChanged();
|
2017-08-29 19:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SchemaAlignmentDialog.getJSON = function() {
|
2017-08-31 10:11:00 +02:00
|
|
|
var list = new Array();
|
2019-02-19 22:51:55 +01:00
|
|
|
var itemsDom = $('#schema-alignment-statements-container .wbs-item');
|
|
|
|
itemsDom.each(function () {
|
|
|
|
var itemJSON = SchemaAlignmentDialog._itemToJSON($(this));
|
|
|
|
if (itemJSON !== null) {
|
|
|
|
list.push(itemJSON);
|
|
|
|
}
|
2017-08-31 10:11:00 +02:00
|
|
|
});
|
2019-02-19 22:51:55 +01:00
|
|
|
if (list.length === itemsDom.length) {
|
|
|
|
return {
|
2017-09-06 12:58:30 +02:00
|
|
|
'itemDocuments': list,
|
2017-08-31 10:11:00 +02:00
|
|
|
'wikibasePrefix': this._wikibasePrefix,
|
2019-02-19 22:51:55 +01:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-08-29 19:22:41 +02:00
|
|
|
};
|
|
|
|
|
2017-09-04 22:00:58 +02:00
|
|
|
SchemaAlignmentDialog._hasChanged = function() {
|
2018-04-20 11:30:41 +02:00
|
|
|
SchemaAlignmentDialog._hasUnsavedChanges = true;
|
2018-04-20 15:03:09 +02:00
|
|
|
SchemaAlignmentDialog.preview();
|
2018-04-20 11:30:41 +02:00
|
|
|
SchemaAlignmentDialog._unsavedIndicator.show();
|
|
|
|
SchemaAlignmentDialog._schemaElmts.saveButton
|
2018-04-20 09:21:20 +02:00
|
|
|
.prop('disabled', false)
|
|
|
|
.removeClass('disabled');
|
2018-04-20 11:30:41 +02:00
|
|
|
SchemaAlignmentDialog._schemaElmts.discardButton
|
2018-04-20 09:21:20 +02:00
|
|
|
.prop('disabled', false)
|
|
|
|
.removeClass('disabled');
|
2019-02-22 19:24:55 +01:00
|
|
|
$('.wbs-copy-reference-button')
|
|
|
|
.text($.i18n('wikidata-schema/copy-reference'));
|
|
|
|
$('.wbs-copy-reference')
|
|
|
|
.removeClass('wbs-copied-reference');
|
2017-09-04 22:00:58 +02:00
|
|
|
}
|
|
|
|
|
2018-04-28 11:25:49 +02:00
|
|
|
SchemaAlignmentDialog.updateNbEdits = function(nb_edits) {
|
|
|
|
this._previewElmts.previewExplanation.text(
|
2018-11-21 18:30:00 +01:00
|
|
|
$.i18n('wikidata-schema/preview-explanation').replace('{nb_edits}',nb_edits));
|
2018-04-28 11:25:49 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 15:03:09 +02:00
|
|
|
SchemaAlignmentDialog.preview = function() {
|
2017-08-29 19:22:41 +02:00
|
|
|
var self = this;
|
|
|
|
|
2017-09-04 22:00:58 +02:00
|
|
|
$('.invalid-schema-warning').hide();
|
2017-08-29 19:22:41 +02:00
|
|
|
this._previewPanes.empty();
|
2018-04-28 11:25:49 +02:00
|
|
|
this.updateNbEdits(0);
|
2018-04-20 23:11:38 +02:00
|
|
|
this.issueSpinner.show();
|
|
|
|
this.previewSpinner.show();
|
2017-09-04 22:00:58 +02:00
|
|
|
var schema = this.getJSON();
|
2019-02-19 22:51:55 +01:00
|
|
|
if (schema === null) {
|
|
|
|
$('.invalid-schema-warning').show();
|
|
|
|
return;
|
|
|
|
}
|
2019-10-17 11:42:05 +02:00
|
|
|
Refine.postCSRF(
|
2017-09-04 22:00:58 +02:00
|
|
|
"command/wikidata/preview-wikibase-schema?" + $.param({ project: theProject.id }),
|
|
|
|
{ schema: JSON.stringify(schema), engine: JSON.stringify(ui.browsingEngine.getJSON()) },
|
2017-08-29 19:22:41 +02:00
|
|
|
function(data) {
|
2018-04-20 23:11:38 +02:00
|
|
|
self.issueSpinner.hide();
|
|
|
|
self.previewSpinner.hide();
|
2018-03-20 17:20:00 +01:00
|
|
|
if ("edits_preview" in data) {
|
|
|
|
var previewContainer = self._previewPanes[0];
|
|
|
|
EditRenderer.renderEdits(data.edits_preview, previewContainer);
|
2018-04-28 11:25:49 +02:00
|
|
|
self.updateNbEdits(data["edit_count"]);
|
2017-08-29 19:22:41 +02:00
|
|
|
}
|
2018-01-08 20:14:15 +01:00
|
|
|
|
2018-01-10 17:16:05 +01:00
|
|
|
if (data.warnings) {
|
2018-01-10 19:04:39 +01:00
|
|
|
self._updateWarnings(data.warnings, data.nb_warnings);
|
2018-01-10 17:16:05 +01:00
|
|
|
} else {
|
2018-01-10 19:04:39 +01:00
|
|
|
self._updateWarnings([], 0);
|
2018-01-10 17:16:05 +01:00
|
|
|
}
|
2018-01-08 20:14:15 +01:00
|
|
|
|
2017-09-04 22:00:58 +02:00
|
|
|
if ("code" in data && data.code === "error") {
|
|
|
|
$('.invalid-schema-warning').show();
|
2017-08-29 19:22:41 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-03-30 12:40:01 +02:00
|
|
|
Refine.registerUpdateFunction(function(options) {
|
2018-04-20 09:21:20 +02:00
|
|
|
// Inject tabs in any project where the schema has been defined
|
|
|
|
if(theProject.overlayModels.wikibaseSchema && !SchemaAlignmentDialog.isSetUp()) {
|
|
|
|
SchemaAlignmentDialog.setUpTabs();
|
|
|
|
}
|
2018-03-30 12:40:01 +02:00
|
|
|
if (SchemaAlignmentDialog.isSetUp() && (options.everythingChanged || options.modelsChanged ||
|
|
|
|
options.rowsChanged || options.rowMetadataChanged || options.cellsChanged || options.engineChanged)) {
|
2018-04-20 09:21:20 +02:00
|
|
|
if (!SchemaAlignmentDialog._hasUnsavedChanges) {
|
|
|
|
SchemaAlignmentDialog._discardChanges();
|
|
|
|
}
|
2018-04-13 18:39:20 +02:00
|
|
|
SchemaAlignmentDialog.updateColumns();
|
2018-04-20 09:21:20 +02:00
|
|
|
SchemaAlignmentDialog.preview();
|
2018-03-30 12:40:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-01-08 20:14:15 +01:00
|
|
|
/*************************
|
|
|
|
* WARNINGS RENDERING *
|
|
|
|
*************************/
|
|
|
|
|
2018-01-10 19:04:39 +01:00
|
|
|
SchemaAlignmentDialog._updateWarnings = function(warnings, totalCount) {
|
2018-03-30 12:40:01 +02:00
|
|
|
var mainDiv = $('#wikidata-issues-panel');
|
|
|
|
var countsElem = this.issuesTabCount;
|
2018-01-10 19:04:39 +01:00
|
|
|
|
|
|
|
// clear everything
|
2018-01-08 20:14:15 +01:00
|
|
|
mainDiv.empty();
|
2018-01-10 19:04:39 +01:00
|
|
|
countsElem.hide();
|
|
|
|
|
2018-01-08 20:14:15 +01:00
|
|
|
var table = $('<table></table>').appendTo(mainDiv);
|
|
|
|
for (var i = 0; i != warnings.length; i++) {
|
2018-02-22 19:15:05 +01:00
|
|
|
var rendered = WarningsRenderer._renderWarning(warnings[i]);
|
2018-01-08 20:14:15 +01:00
|
|
|
rendered.appendTo(table);
|
|
|
|
}
|
2018-01-10 19:04:39 +01:00
|
|
|
|
|
|
|
// update the counts
|
|
|
|
if (totalCount) {
|
|
|
|
countsElem.text(totalCount);
|
|
|
|
countsElem.show();
|
|
|
|
}
|
2018-01-08 20:14:15 +01:00
|
|
|
}
|
|
|
|
|