-
Notifications
You must be signed in to change notification settings - Fork 2
/
konecty-queue.html
117 lines (113 loc) · 3.85 KB
/
konecty-queue.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<script type="text/x-red" data-template-name="konecty-queue">
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i> Konecty</label>
<input type="text" id="node-input-server" placeholder="Konecty Server">
</div>
<div class="form-row">
<label for="node-input-token"><i class="fa fa-key"></i> <span data-i18n="konecty-queue.label.token"></span></label>
<input type="text" id="node-input-token" data-i18n="[placeholder]konecty-queue.label.token">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="konecty-queue.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]konecty-queue.label.name">
</div>
<div class="form-row">
<label for="node-input-queue"><i class="fa fa-tag"></i> <span data-i18n="konecty-queue.label.queue"></span></label>
<input type="text" style="width: 70%;" id="node-input-queue" data-i18n="[placeholder]konecty-queue.label.queue">
<div id="queue-autocomplete-row" class="form-row" style="margin-top: 5px; margin-left: 104px;width: 70%;display:none;">
<input type="text" style="width: 100%;" id="node-input-queue-autocomplete" data-i18n="[placeholder]konecty-queue.placeholder.autocomplete">
<input type="hidden" id="node-input-queue-autocomplete-id">
</div>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('konecty-queue', {
category: 'Konecty',
color: '#68B7E0',
defaults: {
server: { value: '', type: 'konecty-server' },
name: { value: '' },
queueType: { value: 'msg' },
queue: { value: '' },
queueData: { value: '' },
token: { value: '', validate: RED.validators.typedInput('tokenType') },
tokenType: { value: 'str' }
},
inputs: 1,
outputs: 2,
outputLabels: function(labelIndex) {
return [this._('konecty-queue.output.success'), this._('konecty-queue.output.fail')][labelIndex];
},
icon: 'konecty.png',
paletteLabel: 'Next from queue',
label: function() {
return this.name || 'Next from queue';
},
oneditprepare: function() {
const node = this;
$('#node-input-token').typedInput({
default: node.tokenType || 'str',
types: ['msg', 'flow', 'global', 'env', 'str']
});
$('#node-input-queue')
.typedInput({
default: node.queueType || 'msg',
types: [
'msg',
'flow',
'global',
'env',
'str',
{
value: 'form',
label: node._('konecty-queue.label.autocomplete'),
hasValue: false
}
]
})
.change(function() {
var type = $(this).typedInput('type');
if (type === 'form') {
$('#queue-autocomplete-row').show();
} else {
$('#queue-autocomplete-row').hide();
}
});
$('#node-input-queue-autocomplete').autocomplete({
source: function(request, response) {
const server = $('#node-input-server').val();
$.ajax({
url: 'konecty-server/' + server + '/lookupDocument/Queue/name/' + request.term,
type: 'GET',
dataType: 'json',
success: options => {
response((options || []).map(opt => ({ id: opt._id, value: opt.name })));
}
});
},
minLength: 2,
select: function(event, ui) {
$('#node-input-queue-autocomplete-id').val(ui.item.id);
}
});
if (node.queueType === 'form') {
const { i, l } = JSON.parse(node.queueData);
$('#node-input-queue-autocomplete').val(l);
$('#node-input-queue-autocomplete-id').val(i);
}
},
oneditsave: function() {
const node = this;
node.tokenType = $('#node-input-token').typedInput('type');
node.queueType = $('#node-input-queue').typedInput('type');
if (node.queueType === 'form') {
node.queueData = JSON.stringify({
i: $('#node-input-queue-autocomplete-id').val(),
l: $('#node-input-queue-autocomplete').val()
});
} else {
node.queueData = '{}';
}
}
});
</script>