-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Volumes: Standardized the volume selection dropdown
- Loading branch information
willp24
committed
Jul 20, 2018
1 parent
3963605
commit d7754cf
Showing
5 changed files
with
141 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* -*- mode: espresso; espresso-indent-level: 2; indent-tabs-mode: nil -*- */ | ||
/* vim: set softtabstop=2 shiftwidth=2 tabstop=2 expandtab: */ | ||
|
||
(function (CATMAID) { | ||
|
||
"use strict"; | ||
|
||
// Update volume list | ||
let initVolumeList = function (options, newSelectedIds) { | ||
return CATMAID.Volumes.listAll(project.id).then(function (json) { | ||
let volumes = json.sort(function (a, b) { | ||
return CATMAID.tools.compareStrings(a.name, b.name); | ||
}).map(function (volume) { | ||
return { | ||
title: volume.name, | ||
value: volume.id | ||
}; | ||
}); | ||
if (options.mode === "radio") { | ||
if (newSelectedIds.length > 1){ | ||
throw new CATMAID.ValueError("Radio select only takes one selected volume"); | ||
} | ||
let selectedVolume = newSelectedIds[0] || options.selectedVolumeIds[0]; | ||
// Create actual element based on the returned data | ||
let node = CATMAID.DOM.createRadioSelect('Volumes', volumes, | ||
selectedVolume, true); | ||
// Add a selection handler | ||
node.onchange = function (e) { | ||
let volumeId = e.target.value; | ||
let selected = true; | ||
|
||
if (CATMAID.tools.isFn(options.select)) { | ||
options.select(volumeId, selected, e.target); | ||
} | ||
}; | ||
return node; | ||
} else { | ||
let selectedVolumes = newSelectedIds || options.selectedVolumeIds; | ||
// Create actual element based on the returned data | ||
let node = CATMAID.DOM.createCheckboxSelect('Volumes', volumes, | ||
selectedVolumes, true, options.rowCallback); | ||
|
||
// Add a selection handler | ||
node.onchange = function (e) { | ||
let selected = e.target.checked; | ||
let volumeId = parseInt(e.target.value, 10); | ||
|
||
if (CATMAID.tools.isFn(options.select)) { | ||
options.select(volumeId, selected, e.target); | ||
} | ||
}; | ||
return node; | ||
} | ||
}); | ||
}; | ||
|
||
CATMAID.createVolumeSelector = function (options) { | ||
var volumeSelectionWrapper = document.createElement('span'); | ||
let volumeSelection; | ||
if (options.label){ | ||
volumeSelection = CATMAID.DOM.createLabeledAsyncPlaceholder(options.label, initVolumeList(options), options.title); | ||
} else { | ||
volumeSelection = CATMAID.DOM.createAsyncPlaceholder(initVolumeList(options)); | ||
} | ||
volumeSelectionWrapper.appendChild(volumeSelection); | ||
volumeSelectionWrapper.refresh = function(newSelectedIds){ | ||
while (0 !== volumeSelectionWrapper.children.length) { | ||
volumeSelectionWrapper.removeChild(volumeSelectionWrapper.children[0]); | ||
} | ||
var volumeSelection = CATMAID.DOM.createAsyncPlaceholder(initVolumeList(options, newSelectedIds)); | ||
volumeSelectionWrapper.appendChild(volumeSelection); | ||
}; | ||
return volumeSelectionWrapper; | ||
}; | ||
|
||
|
||
})(CATMAID); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters