Skip to content
Snippets Groups Projects
Commit be779c04 authored by anttil's avatar anttil
Browse files

Remember dataset type, sample identifier and property values of each dataset type in upload dialog

parent 94989f52
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,10 @@ define([],
connection: {
name: null,
candidateName: null
}
},
uploadDataSetType: null,
uploadDataSetTypes: {},
uploadEntityIdentifier: ''
}
}
)
\ No newline at end of file
......@@ -39,15 +39,26 @@ define([
if (response.ok) {
response.json()
.then(function (data) {
//console.log(data.dataSetTypes)
var change_input_fields = function () {
hideSpinner()
cleanErrors()
var oldType = state.uploadDataSetType
if (oldType != null && !(oldType in state.uploadDataSetTypes)) {
state.uploadDataSetTypes[oldType] = {}
}
state.uploadDataSetType = dataset_types.options[dataset_types.selectedIndex].value
// remove existing input fields
while (input_fields.firstChild) {
input_fields.removeChild(input_fields.firstChild)
var element = input_fields.firstChild
if (element.nodeName === "INPUT" && state.uploadDataSetType != null) {
state.uploadDataSetTypes[oldType][element.name] = element.value
}
input_fields.removeChild(element)
}
// for every property assignment, create an input field.
......@@ -63,6 +74,12 @@ define([
input_field.size = 90
input_field.style.width="100%"
var mem = state.uploadDataSetTypes[dts[dataset_types.selectedIndex].code]
if (mem == null) {
mem = {}
}
input_field.value = pa.code in mem ? mem[pa.code] : ""
input_fields.appendChild(input_title)
input_fields.appendChild(input_error)
input_fields.appendChild(input_field)
......@@ -76,12 +93,21 @@ define([
while (dataset_types.firstChild) {
dataset_types.removeChild(dataset_types.firstChild);
}
var index = 0
var selectedIndex = -1
for (dt of dts) {
var option = document.createElement("OPTION")
option.value = dt.code
option.textContent = dt.description ? dt.code + ": " + dt.description : dt.code
dataset_types.appendChild(option)
if (dt.code === state.uploadDataSetType) {
selectedIndex = index
}
index++
}
dataset_types.selectedIndex = selectedIndex === -1 ? 0 : selectedIndex
// change the input fields, since we just received new datasetTypes
change_input_fields()
......@@ -130,7 +156,7 @@ define([
sampleIdentifier.type = "text"
sampleIdentifier.name = 'sampleIdentifier'
sampleIdentifier.placeholder = "Sample Identifier or permId"
sampleIdentifier.value = ''
sampleIdentifier.value = state.uploadEntityIdentifier
sampleIdentifier.size = "90"
sampleIdentifier.style.width="100%"
......@@ -159,6 +185,16 @@ define([
var uploadDialogBox = $('<div/>').append(inputs)
function saveState() {
state.uploadDataSetTypes[state.uploadDataSetType] = {}
for (element of input_fields.children) {
if (element.nodeName === "INPUT" && state.uploadDataSetType != null) {
state.uploadDataSetTypes[state.uploadDataSetType][element.name] = element.value
}
}
state.uploadEntityIdentifier = sampleIdentifier.value
}
function onOk() {
var connection_name = state.connection.name
......@@ -199,6 +235,7 @@ define([
data: JSON.stringify(dataSetInfo),
contentType: 'application/json',
success: function (data) {
saveState()
$('div.modal').remove()
$('div.modal-backdrop').remove()
common.createFeedback('success', data.statusText)
......@@ -219,22 +256,16 @@ define([
if ("errors" in data.responseJSON) {
var errors = data.responseJSON.errors
for (error of errors) {
let key, value
Object.keys(error).forEach(k => {
key = k
value = error[k]
})
var element;
if (key in errorElements) {
element = errorElements[key]
} else {
element = errorElements['main']
}
element.textContent = element.textContent.concat(value)
errorElements[key in errorElements ? key : "main"].textContent = value
}
} else {
errorElements["main"].textContent = "Server error"
}
}
}
......@@ -245,6 +276,11 @@ define([
return false
}
function onCancel() {
saveState()
return true
}
if (IPython.notebook.dirty === true) {
dialog.modal({
body: 'Please save the notebook before uploading it to openBIS.',
......@@ -260,7 +296,9 @@ define([
body: uploadDialogBox,
title: 'Upload openBIS DataSet',
buttons: {
'Cancel': {},
'Cancel': {
click: onCancel
},
'Upload': {
class: 'btn-primary btn-large',
click: onOk
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment