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>
|
2022-08-14 20:24:05 +02:00
|
|
|
<option value="group" data-i18n="status.scope.group"></option>
|
2022-12-09 16:33:40 +01:00
|
|
|
<option value="target" data-i18n="status.scope.selected"></option>
|
2015-08-19 22:14:45 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
2019-05-23 17:39:34 +02:00
|
|
|
<div class="form-row node-input-target-row">
|
2022-09-04 16:21:34 +02:00
|
|
|
<button type="button" id="node-input-status-target-select" class="red-ui-button" data-i18n="common.label.selectNodes"></button>
|
2019-05-23 17:39:34 +02:00
|
|
|
</div>
|
2020-06-01 22:09:58 +02:00
|
|
|
<div class="form-row node-input-target-row node-input-target-list-row" style="position: relative; min-height: 100px">
|
|
|
|
<div style="position: absolute; top: -30px; right: 0;"><input type="text" id="node-input-status-target-filter"></div>
|
2019-05-23 17:39:34 +02:00
|
|
|
<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:""},
|
2021-01-08 15:19:12 +01:00
|
|
|
scope: {value:null, type:"*[]"}
|
2015-08-19 22:14:45 +02:00
|
|
|
},
|
|
|
|
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() {
|
2023-05-29 23:47:29 +02:00
|
|
|
if (this.name) {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
if (this.scope === "group") {
|
|
|
|
return this._("status.statusGroup");
|
|
|
|
} else if (Array.isArray(this.scope)) {
|
|
|
|
return this._("status.statusNodes",{number:this.scope.length});
|
|
|
|
}
|
|
|
|
return 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
|
|
|
};
|
2020-06-03 16:54:51 +02:00
|
|
|
var search = $("#node-input-status-target-filter").searchBox({
|
2020-06-01 22:09:58 +02:00
|
|
|
style: "compact",
|
|
|
|
delay: 300,
|
|
|
|
change: function() {
|
2020-06-05 17:00:02 +02:00
|
|
|
var val = $(this).val().trim().toLowerCase();
|
2020-06-01 22:09:58 +02:00
|
|
|
if (val === "") {
|
|
|
|
dirList.treeList("filter", null);
|
2020-06-03 16:54:51 +02:00
|
|
|
search.searchBox("count","");
|
2020-06-01 22:09:58 +02:00
|
|
|
} else {
|
2020-06-03 16:54:51 +02:00
|
|
|
var count = dirList.treeList("filter", function(item) {
|
2020-06-05 17:00:02 +02:00
|
|
|
return item.label.toLowerCase().indexOf(val) > -1 || item.node.type.toLowerCase().indexOf(val) > -1
|
2020-06-01 22:09:58 +02:00
|
|
|
});
|
2020-06-03 16:54:51 +02:00
|
|
|
search.searchBox("count",count+" / "+candidateNodes.length);
|
2020-06-01 22:09:58 +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,
|
2020-05-21 11:39:49 +02:00
|
|
|
selected: isChecked,
|
|
|
|
checkbox: true
|
2019-05-23 17:39:34 +02:00
|
|
|
};
|
|
|
|
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");
|
2022-08-14 20:24:05 +02:00
|
|
|
} else if(this.scope === "group"){
|
|
|
|
$("#node-input-scope-select").val("group");
|
2015-08-19 22:14:45 +02:00
|
|
|
} 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;
|
2022-08-14 20:24:05 +02:00
|
|
|
} else if(scope === 'group') {
|
|
|
|
this.scope = "group";
|
2015-08-19 22:14:45 +02:00
|
|
|
} 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>
|