Skip to content

Commit 6cdd12e

Browse files
committed
review code and prepare to publish on npm registry
1 parent 7115e52 commit 6cdd12e

File tree

4 files changed

+179
-176
lines changed

4 files changed

+179
-176
lines changed

77-cloudant-cf.html

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103
</div>
104104

105105
<div class="form-row">
106-
<label for="node-input-db"><i class="fa fa-briefcase"></i> Database</label>
107-
<input type="text" id="node-input-db" placeholder="database">
106+
<label for="node-input-database"><i class="fa fa-briefcase"></i> Database</label>
107+
<input type="text" id="node-input-database" placeholder="database">
108108
</div>
109109

110110
</div>
@@ -166,20 +166,32 @@
166166
function oneditprepare() {
167167
var select = $('#node-input-service');
168168
var node = this;
169-
$.getJSON('cloudantnode/vcap/',function(data) {
169+
170+
$.getJSON('cloudant/vcap/',function(data) {
170171
var last = select.children().last();
171172
var opts = [];
172-
for (var i =0;i<data.length;i++) {
173-
opts.push('<option value="'+data[i].name+'"'+(node.service==data[i].name?" selected":"")+'>'+data[i].name+'</option>');
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+
);
174181
}
182+
175183
if (opts.length == 0) {
176184
node.service = "_ext_";
177-
select.find("option").filter(function() {return $(this).val() == node.service;}).attr('selected',true);
185+
select.find("option").filter(function() {
186+
return $(this).val() == node.service;
187+
}).attr('selected', true);
178188
} else {
179189
last.before(opts.join(""));
180190
}
191+
181192
select.change();
182193
});
194+
183195
select.change(function() {
184196
var service = select.val();
185197
if (service == "_ext_") {
@@ -191,41 +203,33 @@
191203
}
192204

193205
function label() {
194-
var cloudantNode = RED.nodes.node(this.cloudant);
195-
if (this.name) {
196-
return this.name;
197-
}
198-
if (this.service == "_ext_") {
199-
return (cloudantNode?cloudantNode.label()+" "+this.collection:"cloudant");
200-
}
201-
return this.service||"cloudant";
206+
return this.name || this.database || "cloudant";
202207
}
203208

204209
function validateServer(v) {
205-
return this.service != "_ext_" || v!="_ADD_";
210+
return this.service != "_ext_" || v != "_ADD_";
206211
}
207212

208213
RED.nodes.registerType("cloudant out", {
209214
category: "storage-output",
210215
color: "rgb(114, 199, 231)",
211216
defaults: {
212217
service: { value: "", required: true },
213-
cloudant: { type:"cloudant",validate:validateServer}, //validate server
218+
cloudant: { type: "cloudant", validate: validateServer},
214219
name: { value: "" },
215-
db: { value: "", required: true },
220+
database: { value: "", required: true },
216221
payonly: { value: false },
217222
operation: { value: "insert" }
218223
},
219224
inputs: 1,
220225
outputs: 0,
221226
icon: "cloudant.png",
222227
align: "right",
223-
label: label, //called
228+
label: label,
224229
labelStyle: function() {
225230
return this.name?"node_label_italic":"";
226231
},
227-
oneditprepare: oneditprepare //called
232+
oneditprepare: oneditprepare
228233
});
229234
})();
230-
231235
</script>

0 commit comments

Comments
 (0)