2015-02-20 02:17:24 +01:00
|
|
|
|
2020-01-15 03:40:48 +01:00
|
|
|
<script type="text/html" data-template-name="catch">
|
2015-08-13 14:58:19 +02:00
|
|
|
<div class="form-row">
|
|
|
|
<label style="width: auto" for="node-input-scope" data-i18n="catch.label.source"></label>
|
|
|
|
<select id="node-input-scope-select">
|
|
|
|
<option value="all" data-i18n="catch.scope.all"></option>
|
2022-08-14 20:28:34 +02:00
|
|
|
<option value="group" data-i18n="status.scope.group"></option>
|
2015-08-13 14:58:19 +02:00
|
|
|
<option value="target" data-i18n="catch.scope.selected"></options>
|
|
|
|
</select>
|
|
|
|
</div>
|
2019-02-05 15:28:20 +01:00
|
|
|
<div class="form-row node-input-uncaught-row">
|
|
|
|
<input type="checkbox" id="node-input-uncaught" style="display: inline-block; width: auto; vertical-align: top; margin-left: 30px; margin-right: 5px;">
|
|
|
|
<label for="node-input-uncaught" style="width: auto" data-i18n="catch.label.uncaught"></label>
|
|
|
|
</div>
|
2019-05-23 17:39:34 +02:00
|
|
|
<div class="form-row node-input-target-row">
|
|
|
|
<button id="node-input-catch-target-select" class="red-ui-button" data-i18n="common.label.selectNodes"></button>
|
2015-08-13 14:58:19 +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-catch-target-filter"></div>
|
2019-05-23 17:39:34 +02:00
|
|
|
<div id="node-input-catch-target-container-div"></div>
|
|
|
|
</div>
|
|
|
|
|
2015-02-20 02:17:24 +01:00
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
2015-05-26 22:11:14 +02:00
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
2015-02-20 02:17:24 +01:00
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('catch',{
|
2019-07-09 21:26:26 +02:00
|
|
|
category: 'common',
|
2015-02-20 02:17:24 +01:00
|
|
|
color:"#e49191",
|
|
|
|
defaults: {
|
2015-08-13 14:58:19 +02:00
|
|
|
name: {value:""},
|
2021-01-08 15:19:12 +01:00
|
|
|
scope: {value:null, type:"*[]"},
|
2019-02-05 15:28:20 +01:00
|
|
|
uncaught: {value:false}
|
2015-02-20 02:17:24 +01:00
|
|
|
},
|
|
|
|
inputs:0,
|
|
|
|
outputs:1,
|
2019-06-21 13:36:20 +02:00
|
|
|
icon: "alert.svg",
|
2015-02-20 02:17:24 +01:00
|
|
|
label: function() {
|
2019-02-05 15:28:20 +01:00
|
|
|
if (this.name) {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
if (this.scope) {
|
|
|
|
return this._("catch.catchNodes",{number:this.scope.length});
|
|
|
|
}
|
|
|
|
return this.uncaught?this._("catch.catchUncaught"):this._("catch.catch")
|
2015-02-20 02:17:24 +01:00
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
2015-08-13 14:58:19 +02:00
|
|
|
},
|
|
|
|
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-catch-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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-05-23 17:39:34 +02:00
|
|
|
var dirList = $("#node-input-catch-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-13 14:58:19 +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-13 14:58:19 +02:00
|
|
|
});
|
2019-05-23 17:39:34 +02:00
|
|
|
dirList.treeList('data',items);
|
2015-08-13 14:58:19 +02:00
|
|
|
|
2019-05-23 17:39:34 +02:00
|
|
|
$("#node-input-catch-target-select").on("click", function(e) {
|
2015-08-13 14:58:19 +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-13 14:58:19 +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-13 14:58:19 +02:00
|
|
|
if (scope === "target") {
|
|
|
|
$(".node-input-target-row").show();
|
2019-02-05 15:28:20 +01:00
|
|
|
$(".node-input-uncaught-row").hide();
|
2015-08-13 14:58:19 +02:00
|
|
|
} else {
|
|
|
|
$(".node-input-target-row").hide();
|
2019-02-05 15:28:20 +01:00
|
|
|
$(".node-input-uncaught-row").show();
|
2015-08-13 14:58:19 +02:00
|
|
|
}
|
2019-05-23 17:39:34 +02:00
|
|
|
node._resize();
|
2015-08-13 14:58:19 +02:00
|
|
|
});
|
2017-04-24 21:36:27 +02:00
|
|
|
if (this.scope === null) {
|
2015-08-13 14:58:19 +02:00
|
|
|
$("#node-input-scope-select").val("all");
|
2022-08-14 20:28:34 +02:00
|
|
|
} else if(this.scope === "group"){
|
|
|
|
$("#node-input-scope-select").val("group");
|
2015-08-13 14:58:19 +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-13 14:58:19 +02:00
|
|
|
},
|
|
|
|
oneditsave: function() {
|
2016-07-04 12:21:58 +02:00
|
|
|
var scope = $("#node-input-scope-select").val();
|
2015-08-13 14:58:19 +02:00
|
|
|
if (scope === 'all') {
|
|
|
|
this.scope = null;
|
2022-08-14 20:28:34 +02:00
|
|
|
} else if(scope === 'group') {
|
|
|
|
this.scope = "group";
|
2015-08-13 14:58:19 +02:00
|
|
|
} else {
|
2019-02-05 15:28:20 +01:00
|
|
|
$("#node-input-uncaught").prop("checked",false);
|
2019-05-23 17:39:34 +02:00
|
|
|
this.scope = $("#node-input-catch-target-container-div").treeList('selected').map(function(i) { return i.node.id})
|
2015-08-13 14:58:19 +02:00
|
|
|
}
|
2016-01-04 17:53:32 +01:00
|
|
|
},
|
|
|
|
oneditresize: function(size) {
|
2019-05-23 17:39:34 +02:00
|
|
|
this._resize();
|
2015-02-20 02:17:24 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|