2015-08-19 22:14:45 +02:00
|
|
|
|
2020-01-15 03:40:48 +01:00
|
|
|
<script type="text/html" data-template-name="status">
|
2015-08-19 22:14:45 +02:00
|
|
|
<div class="form-row">
|
|
|
|
<label style="width: auto" for="node-input-scope" data-i18n="status.label.source"></label>
|
|
|
|
<select id="node-input-scope-select">
|
|
|
|
<option value="all" data-i18n="status.scope.all"></option>
|
|
|
|
<option value="target" data-i18n="status.scope.selected"></options>
|
|
|
|
</select>
|
|
|
|
</div>
|
2019-05-23 17:39:34 +02:00
|
|
|
<div class="form-row node-input-target-row">
|
|
|
|
<button id="node-input-status-target-select" class="red-ui-button" data-i18n="common.label.selectNodes"></button>
|
|
|
|
</div>
|
|
|
|
<div class="form-row node-input-target-row node-input-target-list-row" style="min-height: 100px">
|
|
|
|
<div id="node-input-status-target-container-div"></div>
|
2015-08-19 22:14:45 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
|
|
|
</div>
|
|
|
|
</script>
|
2018-11-30 14:02:15 +01:00
|
|
|
|
2015-08-19 22:14:45 +02:00
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('status',{
|
2019-07-09 21:26:26 +02:00
|
|
|
category: 'common',
|
2019-07-10 00:32:22 +02:00
|
|
|
color:"#94c1d0",
|
2015-08-19 22:14:45 +02:00
|
|
|
defaults: {
|
|
|
|
name: {value:""},
|
|
|
|
scope: {value:null}
|
|
|
|
},
|
|
|
|
inputs:0,
|
|
|
|
outputs:1,
|
2019-07-10 00:32:22 +02:00
|
|
|
icon: "status.svg",
|
2015-08-19 22:14:45 +02:00
|
|
|
label: function() {
|
2016-03-01 22:58:57 +01:00
|
|
|
return this.name||(this.scope?this._("status.statusNodes",{number:this.scope.length}):this._("status.status"));
|
2015-08-19 22:14:45 +02:00
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
|
|
|
var node = this;
|
2019-05-23 17:39:34 +02:00
|
|
|
var scope = node.scope || [];
|
|
|
|
this._resize = function() {
|
|
|
|
var rows = $("#dialog-form>div:not(.node-input-target-list-row)");
|
2016-01-04 17:53:32 +01:00
|
|
|
var height = $("#dialog-form").height();
|
2019-04-29 12:50:15 +02:00
|
|
|
for (var i=0;i<rows.length;i++) {
|
2016-01-04 17:53:32 +01:00
|
|
|
height -= $(rows[i]).outerHeight(true);
|
|
|
|
}
|
2019-05-23 17:39:34 +02:00
|
|
|
var editorRow = $("#dialog-form>div.node-input-target-list-row");
|
|
|
|
editorRow.css("height",height+"px");
|
2017-04-24 21:36:27 +02:00
|
|
|
};
|
2016-01-04 17:53:32 +01:00
|
|
|
|
2019-05-23 17:39:34 +02:00
|
|
|
var dirList = $("#node-input-status-target-container-div").css({width: "100%", height: "100%"})
|
|
|
|
.treeList({multi:true}).on("treelistitemmouseover", function(e, item) {
|
|
|
|
item.node.highlighted = true;
|
|
|
|
item.node.dirty = true;
|
|
|
|
RED.view.redraw();
|
|
|
|
}).on("treelistitemmouseout", function(e, item) {
|
|
|
|
item.node.highlighted = false;
|
|
|
|
item.node.dirty = true;
|
|
|
|
RED.view.redraw();
|
|
|
|
})
|
|
|
|
var candidateNodes = RED.nodes.filterNodes({z:node.z});
|
|
|
|
var allChecked = true;
|
|
|
|
var items = [];
|
|
|
|
var nodeItemMap = {};
|
|
|
|
|
|
|
|
candidateNodes.forEach(function(n) {
|
|
|
|
if (n.id === node.id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var isChecked = scope.indexOf(n.id) !== -1;
|
|
|
|
|
|
|
|
allChecked = allChecked && isChecked;
|
|
|
|
|
|
|
|
var nodeDef = RED.nodes.getType(n.type);
|
|
|
|
var label;
|
|
|
|
var sublabel;
|
|
|
|
if (nodeDef) {
|
|
|
|
var l = nodeDef.label;
|
|
|
|
label = (typeof l === "function" ? l.call(n) : l)||"";
|
|
|
|
sublabel = n.type;
|
|
|
|
if (sublabel.indexOf("subflow:") === 0) {
|
|
|
|
var subflowId = sublabel.substring(8);
|
|
|
|
var subflow = RED.nodes.subflow(subflowId);
|
|
|
|
sublabel = "subflow : "+subflow.name;
|
2015-08-19 22:14:45 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-23 17:39:34 +02:00
|
|
|
if (!nodeDef || !label) {
|
|
|
|
label = n.type;
|
|
|
|
}
|
|
|
|
nodeItemMap[n.id] = {
|
|
|
|
node: n,
|
|
|
|
label: label,
|
|
|
|
sublabel: sublabel,
|
|
|
|
selected: isChecked
|
|
|
|
};
|
|
|
|
items.push(nodeItemMap[n.id]);
|
2015-08-19 22:14:45 +02:00
|
|
|
});
|
2019-05-23 17:39:34 +02:00
|
|
|
dirList.treeList('data',items);
|
2015-08-19 22:14:45 +02:00
|
|
|
|
2019-05-23 17:39:34 +02:00
|
|
|
$("#node-input-status-target-select").on("click", function(e) {
|
2015-08-19 22:14:45 +02:00
|
|
|
e.preventDefault();
|
2019-05-23 17:39:34 +02:00
|
|
|
var preselected = dirList.treeList('selected').map(function(n) {return n.node.id});
|
|
|
|
RED.tray.hide();
|
|
|
|
RED.view.selectNodes({
|
|
|
|
selected: preselected,
|
|
|
|
onselect: function(selection) {
|
|
|
|
RED.tray.show();
|
|
|
|
var newlySelected = {};
|
|
|
|
selection.forEach(function(n) {
|
|
|
|
newlySelected[n.id] = true;
|
|
|
|
if (nodeItemMap[n.id]) {
|
|
|
|
nodeItemMap[n.id].treeList.select(true);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
preselected.forEach(function(id) {
|
|
|
|
if (!newlySelected[id]) {
|
|
|
|
nodeItemMap[id].treeList.select(false);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
oncancel: function() {
|
|
|
|
RED.tray.show();
|
|
|
|
},
|
|
|
|
filter: function(n) {
|
|
|
|
return n.id !== node.id;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
2015-08-19 22:14:45 +02:00
|
|
|
|
2019-04-29 12:50:15 +02:00
|
|
|
$("#node-input-scope-select").on("change", function(e) {
|
2016-07-04 12:21:58 +02:00
|
|
|
var scope = $(this).val();
|
2015-08-19 22:14:45 +02:00
|
|
|
if (scope === "target") {
|
|
|
|
$(".node-input-target-row").show();
|
|
|
|
} else {
|
|
|
|
$(".node-input-target-row").hide();
|
|
|
|
}
|
2019-05-23 17:39:34 +02:00
|
|
|
node._resize();
|
2015-08-19 22:14:45 +02:00
|
|
|
});
|
2017-04-24 21:36:27 +02:00
|
|
|
if (this.scope === null) {
|
2015-08-19 22:14:45 +02:00
|
|
|
$("#node-input-scope-select").val("all");
|
|
|
|
} else {
|
|
|
|
$("#node-input-scope-select").val("target");
|
|
|
|
}
|
2019-04-29 12:50:15 +02:00
|
|
|
$("#node-input-scope-select").trigger("change");
|
2015-08-19 22:14:45 +02:00
|
|
|
},
|
|
|
|
oneditsave: function() {
|
2016-07-04 12:21:58 +02:00
|
|
|
var scope = $("#node-input-scope-select").val();
|
2015-08-19 22:14:45 +02:00
|
|
|
if (scope === 'all') {
|
|
|
|
this.scope = null;
|
|
|
|
} else {
|
2019-05-23 17:39:34 +02:00
|
|
|
this.scope = $("#node-input-status-target-container-div").treeList('selected').map(function(i) { return i.node.id})
|
2015-08-19 22:14:45 +02:00
|
|
|
}
|
2016-01-04 17:53:32 +01:00
|
|
|
},
|
|
|
|
oneditresize: function(size) {
|
2019-05-23 17:39:34 +02:00
|
|
|
this._resize();
|
2015-08-19 22:14:45 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|