Skip to content

Commit 85a4588

Browse files
committed
refactoring code
1 parent c637074 commit 85a4588

File tree

1 file changed

+70
-75
lines changed

1 file changed

+70
-75
lines changed

77-cloudant-cf.html

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
</script>
8989

9090
<script type="text/x-red" data-template-name="cloudant out">
91-
9291
<div class="form-row">
9392
<label for="node-input-service"><i class="fa fa-folder-close"></i> Service</label>
9493
<select id="node-input-service">
@@ -136,7 +135,77 @@
136135
else $(".node-input-payonly").show();
137136
});
138137
</script>
138+
</script>
139139

140+
<script type="text/javascript">
141+
RED.nodes.registerType("cloudant out", {
142+
category: "storage-output",
143+
color: "rgb(114, 199, 231)",
144+
defaults: {
145+
service: { value: "", required: true },
146+
cloudant: { type: "cloudant", validate: validateServer},
147+
name: { value: "" },
148+
database: { value: "", required: true },
149+
payonly: { value: false },
150+
operation: { value: "insert" }
151+
},
152+
inputs: 1,
153+
outputs: 0,
154+
icon: "cloudant.png",
155+
align: "right",
156+
label: label,
157+
labelStyle: function() {
158+
return this.name?"node_label_italic":"";
159+
},
160+
oneditprepare: oneditprepare
161+
});
162+
163+
function oneditprepare() {
164+
var select = $('#node-input-service');
165+
var node = this;
166+
167+
$.getJSON('cloudant/vcap/',function(data) {
168+
var last = select.children().last();
169+
var opts = [];
170+
171+
for (var i=0; i < data.length; i++) {
172+
var selected = node.service == data[i].name;
173+
opts.push(
174+
'<option value="' + data[i].name + '"' + (selected ? " selected":"") + '>' +
175+
data[i].name +
176+
'</option>'
177+
);
178+
}
179+
180+
if (opts.length == 0) {
181+
node.service = "_ext_";
182+
select.find("option").filter(function() {
183+
return $(this).val() == node.service;
184+
}).attr('selected', true);
185+
} else {
186+
last.before(opts.join(""));
187+
}
188+
189+
select.change();
190+
});
191+
192+
select.change(function() {
193+
var service = select.val();
194+
if (service == "_ext_") {
195+
$("#node-input-external-details").show();
196+
} else {
197+
$("#node-input-external-details").hide();
198+
}
199+
});
200+
}
201+
202+
function label() {
203+
return this.name || this.database || "cloudant";
204+
}
205+
206+
function validateServer(v) {
207+
return this.service != "_ext_" || v != "_ADD_";
208+
}
140209
</script>
141210

142211
<script type="text/x-red" data-help-name="cloudant out">
@@ -159,77 +228,3 @@
159228
and selecting the <b>remove</b> option for the node.
160229
</p>
161230
</script>
162-
163-
<script type="text/javascript"> //js functions
164-
(function() {
165-
166-
function oneditprepare() {
167-
var select = $('#node-input-service');
168-
var node = this;
169-
170-
$.getJSON('cloudant/vcap/',function(data) {
171-
var last = select.children().last();
172-
var opts = [];
173-
174-
for (var i=0; i < data.length; i++) {
175-
var selected = node.service == data[i].name;
176-
opts.push(
177-
'<option value="' + data[i].name + '"' + (selected ? " selected":"") + '>' +
178-
data[i].name +
179-
'</option>'
180-
);
181-
}
182-
183-
if (opts.length == 0) {
184-
node.service = "_ext_";
185-
select.find("option").filter(function() {
186-
return $(this).val() == node.service;
187-
}).attr('selected', true);
188-
} else {
189-
last.before(opts.join(""));
190-
}
191-
192-
select.change();
193-
});
194-
195-
select.change(function() {
196-
var service = select.val();
197-
if (service == "_ext_") {
198-
$("#node-input-external-details").show();
199-
} else {
200-
$("#node-input-external-details").hide();
201-
}
202-
});
203-
}
204-
205-
function label() {
206-
return this.name || this.database || "cloudant";
207-
}
208-
209-
function validateServer(v) {
210-
return this.service != "_ext_" || v != "_ADD_";
211-
}
212-
213-
RED.nodes.registerType("cloudant out", {
214-
category: "storage-output",
215-
color: "rgb(114, 199, 231)",
216-
defaults: {
217-
service: { value: "", required: true },
218-
cloudant: { type: "cloudant", validate: validateServer},
219-
name: { value: "" },
220-
database: { value: "", required: true },
221-
payonly: { value: false },
222-
operation: { value: "insert" }
223-
},
224-
inputs: 1,
225-
outputs: 0,
226-
icon: "cloudant.png",
227-
align: "right",
228-
label: label,
229-
labelStyle: function() {
230-
return this.name?"node_label_italic":"";
231-
},
232-
oneditprepare: oneditprepare
233-
});
234-
})();
235-
</script>

0 commit comments

Comments
 (0)