Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
js.tag-wizard.js Maven / Gradle / Ivy
/**
* Tag wizard
*
* @param $
* @param molgenis
*/
(function ($, molgenis) {
"use strict";
var selectedAttributeName,
relationIRI,
selectedOntologyIds = [],
entityTypeId;
function noOntologySelectedHandler(messageType) {
molgenis.createAlert([{
'message': 'You need at least one ontology selected before being able to tag.'
}], messageType);
}
function createNewButtonHtml(attributeName, tag) {
var btnHtml = '';
btnHtml += '';
btnHtml += tag.label + ' ';
btnHtml += ' ';
btnHtml += ' ';
return btnHtml;
}
function createDynamicSelectDropdown() {
$('#tag-dropdown').select2({
width: '100%',
minimumInputLength: 1,
multiple: true,
closeOnSelect: true,
query: function (options) {
$.ajax({
url: 'tagwizard/getontologyterms',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
'searchTerm': options.term,
'ontologyIds': selectedOntologyIds
}),
success: function (data) {
options.callback({
results: data,
more: false
});
}
});
},
formatSelection: function (term) {
return term.label;
},
formatResult: function (term) {
return term.label;
},
id: function (term) {
return term.IRI;
}
});
}
$(function () {
entityTypeId = $('#global-information').data('entity');
$('#select-target').on('change', function () {
$('#change-entity-form').submit();
}).select2();
$('#tag-mapping-table').scrollTableBody();
$('#ontology-select').select2();
if ($('#ontology-select').val()) {
selectedOntologyIds = $('#ontology-select').val();
}
$('#ontology-select').on('change', function () {
if ($(this).val() === null) {
selectedOntologyIds = []
} else {
selectedOntologyIds = $(this).val();
}
});
$('#automatic-tag-btn').on('click', function () {
if (selectedOntologyIds.length > 0) {
$.ajax({
url: 'tagwizard/autotagattributes',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
'entityTypeId': entityTypeId,
'ontologyIds': selectedOntologyIds
}),
success: function (data) {
molgenis.createAlert([{
'message': 'Automatic tagging has been succesfully completed'
}], 'success');
$.each(data, function (attributeName, tags) {
if (tags.ontologyTerm) {
$('#' + attributeName + '-tag-column').append(createNewButtonHtml(attributeName, tags.ontologyTerm));
}
});
}
});
} else {
noOntologySelectedHandler('warning');
}
});
$('#clear-all-tags-btn').on('click', function () {
bootbox.confirm("Are you sure you want to remove all tags?", function (result) {
if (result === true) {
$.ajax({
url: 'tagwizard/clearalltags',
type: 'POST',
data: {
'entityTypeId': entityTypeId
},
success: function () {
// empty columns with class tag-column
$('td.tag-column').empty();
molgenis.createAlert([{
'message': 'All tags have been succesfully removed'
}], 'success');
}
});
}
});
});
$('.edit-attribute-tags-btn').on('click', function (event) {
if (selectedOntologyIds.length > 0) {
selectedAttributeName = $(this).data('attribute');
relationIRI = $(this).data('relation');
} else {
noOntologySelectedHandler('warning');
event.stopPropagation();
event.preventDefault()
}
});
// Dynamic dropdown for selecting ontologyterms as tags
createDynamicSelectDropdown();
$('#save-tag-selection-btn').on('click', function () {
var attributeName = selectedAttributeName,
ontologyTermIRIs = $('#tag-dropdown').select2('val');
$.ajax({
url: 'tagwizard/tagattribute',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
'entityTypeId': entityTypeId,
'attributeName': attributeName,
'relationIRI': relationIRI,
'ontologyTermIRIs': ontologyTermIRIs
}),
success: function (ontologyTag) {
$('#tag-dropdown').select2('val', '');
if (ontologyTag !== undefined) {
$('#' + attributeName + '-tag-column').append(createNewButtonHtml(attributeName, ontologyTag.ontologyTerm));
}
}
});
});
$('.tag-column').on('click', '.remove-tag-btn', function () {
var attributeName = $(this).data('attribute'),
ontologyTermIRI = $(this).data('tag');
relationIRI = $(this).data('relation');
$.ajax({
url: 'tagwizard/deletesingletag',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({
'entityTypeId': entityTypeId,
'attributeName': attributeName,
'relationIRI': relationIRI,
'ontologyTermIRI': ontologyTermIRI
})
});
$(this).remove();
});
});
}($, window.top.molgenis = window.top.molgenis || {}));