-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinto-skill-datetime.html
128 lines (120 loc) · 5.07 KB
/
linto-skill-datetime.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
118
119
120
121
122
123
124
125
126
127
128
<script type="text/x-red" data-template-name="linto-skill-datetime">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"/><span data-i18n="linto-skill-datetime.label.name" /></label>
<div style="display: inline-block; width: 70%">
<input type="text" id="node-input-name" data-i18n="[placeholder]linto-skill-datetime.placeholder.name" />
</div>
</div>
<div class="form-row" style="margin-bottom: 0px;" >
<label for="node-input-command" style="width: auto;">
<i class="fa fa-wrench" />
<span data-i18n="linto-skill-datetime.label.command" />
<span style="color:RED; font-weight: bold;" id="node-input-command-custom" data-i18n="linto-skill-datetime.label.custom"/>
<span style="color:GREEN; font-weight: bold;" id="node-input-command-default" data-i18n="linto-skill-datetime.label.default"/>
</label>
<input type="hidden" id="node-input-command" autofocus="autofocus" />
</div>
<div class="form-row node-text-editor-row" style="position:relative">
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-command-editor" />
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType("linto-skill-datetime", {
defaults: {
name: {
value: ""
},
command: {
value: RED.settings.lintoSkillDatetime.command
}
},
...RED.settings.lintoSkillDatetime.template,
label: function () {
return this.name || "linto-skill-datetime"
},
oneditprepare: function () {
if ($("#node-input-command").val() === RED.settings.lintoSkillDatetime.command) {
$("#node-input-command-custom").hide()
$("#node-input-command-default").show()
} else {
$("#node-input-command-custom").show()
$("#node-input-command-default").hide()
}
var that = this;
this.editor = RED.editor.createEditor({
id: 'node-input-command-editor',
mode: 'ace/mode/markdown',
value: $("#node-input-command").val(),
syntax: 'markdown',
globals: {
msg: true,
context: true,
RED: true,
util: true,
flow: true,
global: true,
console: true,
Buffer: true,
setTimeout: true,
clearTimeout: true,
setInterval: true,
clearInterval: true
}
});
RED.library.create({
url: "skills", // where to get the data from
type: "skills", // the type of object the library is for
editor: that.editor, // the field name the main text body goes to
mode: "ace/mode/markdown",
fields: ["name"]
});
this.editor.focus();
$("#node-function-expand-js").click(function (e) {
e.preventDefault();
var value = that.editor.getValue();
RED.editor.editJavaScript({
value: value,
width: "Infinity",
cursor: that.editor.getCursorPosition(),
mode: "ace/mode/markdown",
complete: function (v, cursor) {
that.editor.setValue(v, -1);
that.editor.gotoLine(cursor.row + 1, cursor.column, false);
setTimeout(function () {
that.editor.focus();
}, 300);
}
})
})
},
oneditsave: function () {
var annot = this.editor.getSession().getAnnotations();
this.noerr = 0;
$("#node-input-noerr").val(0);
for (var k = 0; k < annot.length; k++) {
if (annot[k].type === "error") {
$("#node-input-noerr").val(annot.length);
this.noerr = annot.length;
}
}
$("#node-input-command").val(this.editor.getValue());
this.editor.destroy();
delete this.editor;
},
oneditcancel: function () {
this.editor.destroy();
delete this.editor;
},
oneditresize: function (size) {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i = 0; i < rows.size(); i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop")) + parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height", height + "px");
this.editor.resize();
}
})
</script>