mirror of
https://github.com/nasa/openmct.git
synced 2024-12-20 13:43:09 +00:00
[Fixed Position] Improve button support
Improve button support from toolbars by adding a click function when generating structures for mct-toolbar based on view definitions. WTD-879.
This commit is contained in:
parent
7fced99390
commit
db2f2eb098
@ -15,6 +15,8 @@ view's scope.) These additional properties are:
|
|||||||
then that function is assumed to be an accessor-mutator function
|
then that function is assumed to be an accessor-mutator function
|
||||||
(that is, it will be called with no arguments to get, and with
|
(that is, it will be called with no arguments to get, and with
|
||||||
an argument to set.)
|
an argument to set.)
|
||||||
|
* `method`: Name of a method to invoke upon a selected object when
|
||||||
|
a control is activated, e.g. on a button click.
|
||||||
* `inclusive`: Optional; true if this control should be considered
|
* `inclusive`: Optional; true if this control should be considered
|
||||||
applicable whenever at least one element in the selection has
|
applicable whenever at least one element in the selection has
|
||||||
the associated property. Otherwise, all members of the current
|
the associated property. Otherwise, all members of the current
|
||||||
|
@ -106,23 +106,41 @@ define(
|
|||||||
// to the current selection.
|
// to the current selection.
|
||||||
function isApplicable(item) {
|
function isApplicable(item) {
|
||||||
var property = (item || {}).property,
|
var property = (item || {}).property,
|
||||||
|
method = (item || {}).method,
|
||||||
exclusive = !(item || {}).inclusive;
|
exclusive = !(item || {}).inclusive;
|
||||||
|
|
||||||
// Check if a selected item defines this property
|
// Check if a selected item defines this property
|
||||||
function hasProperty(selected) {
|
function hasProperty(selected) {
|
||||||
return selected[property] !== undefined;
|
return (property && (selected[property] !== undefined)) ||
|
||||||
|
(method && (typeof selected[method] === 'function'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return property && selection.map(hasProperty).reduce(
|
return selection.map(hasProperty).reduce(
|
||||||
exclusive ? and : or,
|
exclusive ? and : or,
|
||||||
exclusive
|
exclusive
|
||||||
) && isConsistent(property);
|
) && isConsistent(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invoke all functions in selections with the given name
|
||||||
|
function invoke(method, value) {
|
||||||
|
if (method) {
|
||||||
|
selection.forEach(function (selected) {
|
||||||
|
if (typeof selected[method] === 'function') {
|
||||||
|
selected[method](value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare a toolbar item based on current selection
|
// Prepare a toolbar item based on current selection
|
||||||
function convertItem(item) {
|
function convertItem(item) {
|
||||||
var converted = Object.create(item || {});
|
var converted = Object.create(item || {});
|
||||||
converted.key = addKey(item.property);
|
if (item.property) {
|
||||||
|
converted.key = addKey(item.property);
|
||||||
|
}
|
||||||
|
if (item.method) {
|
||||||
|
converted.click = function (v) { invoke(item.method, v); };
|
||||||
|
}
|
||||||
return converted;
|
return converted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user