|
| 1 | +<!-- |
| 2 | + Copyright 2014 IBM Corp. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +--> |
| 16 | + |
| 17 | +<script type="text/x-red" data-template-name="cloudant"> |
| 18 | + <div class="form-row"> |
| 19 | + <label for="node-config-input-hostname"><i class="fa fa-bookmark"></i> Host</label> |
| 20 | + <input class="input-append-left" type="text" id="node-config-input-hostname" |
| 21 | + placeholder="https://[username].cloudant.com"> |
| 22 | + </div> |
| 23 | + |
| 24 | + <div class="form-row"> |
| 25 | + <label for="node-config-input-user"><i class="fa fa-user"></i> Username</label> |
| 26 | + <input type="text" id="node-config-input-user"> |
| 27 | + </div> |
| 28 | + |
| 29 | + <div class="form-row"> |
| 30 | + <label for="node-config-input-pass"><i class="fa fa-lock"></i> Password</label> |
| 31 | + <input type="password" id="node-config-input-pass"> |
| 32 | + </div> |
| 33 | + |
| 34 | + <div class="form-row"> |
| 35 | + <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label> |
| 36 | + <input type="text" id="node-config-input-name" placeholder="Name"> |
| 37 | + </div> |
| 38 | +</script> |
| 39 | + |
| 40 | +<script type="text/javascript"> |
| 41 | + RED.nodes.registerType("cloudant",{ |
| 42 | + category: "config", |
| 43 | + color: "rgb(114, 199, 231)", |
| 44 | + defaults: { |
| 45 | + hostname: { value: "", required: true }, |
| 46 | + name: { value: "" }, |
| 47 | + //user -> credentials |
| 48 | + //pass -> credentials |
| 49 | + }, |
| 50 | + label: function() { |
| 51 | + return this.name || this.hostname; |
| 52 | + }, |
| 53 | + oneditprepare: function() { |
| 54 | + $.getJSON("cloudant/"+this.id, function(data) { |
| 55 | + if (data.user) { |
| 56 | + $("#node-config-input-user").val(data.user); |
| 57 | + } |
| 58 | + if (data.hasPassword) { |
| 59 | + $("#node-config-input-pass").val("__PWRD__"); |
| 60 | + } else { |
| 61 | + $("#node-config-input-pass").val(""); |
| 62 | + } |
| 63 | + }); |
| 64 | + }, |
| 65 | + oneditsave: function() { |
| 66 | + var newUser = $("#node-config-input-user").val(); |
| 67 | + var newPass = $("#node-config-input-pass").val(); |
| 68 | + var credentials = {}; |
| 69 | + credentials.user = newUser; |
| 70 | + if (newPass != "__PWRD__") { |
| 71 | + credentials.password = newPass; |
| 72 | + } |
| 73 | + $.ajax({ |
| 74 | + url: "cloudant/"+this.id, |
| 75 | + type: "POST", |
| 76 | + data: credentials, |
| 77 | + success: function(result) {} |
| 78 | + }); |
| 79 | + }, |
| 80 | + ondelete: function() { |
| 81 | + $.ajax({ |
| 82 | + url: "cloudant/"+this.id, |
| 83 | + type: "DELETE", |
| 84 | + success: function(result) {} |
| 85 | + }); |
| 86 | + } |
| 87 | + }); |
| 88 | +</script> |
| 89 | + |
| 90 | +<script type="text/x-red" data-template-name="cloudant out"> |
| 91 | + <div class="form-row"> |
| 92 | + <label for="node-input-cloudant"><i class="fa fa-tag"></i> Account</label> |
| 93 | + <input type="text" id="node-input-cloudant"> |
| 94 | + </div> |
| 95 | + |
| 96 | + <div class="form-row"> |
| 97 | + <label for="node-input-db"><i class="fa fa-briefcase"></i> Database</label> |
| 98 | + <input type="text" id="node-input-db" placeholder="database"> |
| 99 | + </div> |
| 100 | + |
| 101 | + </div> |
| 102 | + <div class="form-row"> |
| 103 | + <label for="node-input-operation"><i class="fa fa-wrench"></i> Operation</label> |
| 104 | + <select type="text" id="node-input-operation" |
| 105 | + style="display: inline-block; vertical-align: top;"> |
| 106 | + <option value="insert">insert</option> |
| 107 | + <option value="delete">remove</option> |
| 108 | + </select> |
| 109 | + </div> |
| 110 | + |
| 111 | + <div class="form-row node-input-payonly"> |
| 112 | + <label> </label> |
| 113 | + <input type="checkbox" id="node-input-payonly" placeholder="Only" |
| 114 | + style="display: inline-block; width: auto; vertical-align: top;"> |
| 115 | + <label for="node-input-payonly" style="width: 70%;">Only store msg.payload object?</label> |
| 116 | + </div> |
| 117 | + |
| 118 | + <div class="form-row"> |
| 119 | + <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> |
| 120 | + <input type="text" id="node-input-name" placeholder="Name"> |
| 121 | + </div> |
| 122 | + |
| 123 | + <script> |
| 124 | + $("#node-input-operation").change(function() { |
| 125 | + var id = $("#node-input-operation option:selected").val(); |
| 126 | + if (id == "delete") $(".node-input-payonly").hide(); |
| 127 | + else $(".node-input-payonly").show(); |
| 128 | + }); |
| 129 | + </script> |
| 130 | +</script> |
| 131 | + |
| 132 | +<script type="text/x-red" data-help-name="cloudant out"> |
| 133 | + <p> |
| 134 | + A simple Cloudant output node. Stores <b>msg</b> in a chosen database. |
| 135 | + </p> |
| 136 | + <p> |
| 137 | + Cloudant generates a random id for the <b>msg._id</b> property if one |
| 138 | + is not specified and a new document will be <b>inserted</b> each time. |
| 139 | + If you want to <b>update</b> an existing document you must specify a |
| 140 | + value for <b>msg._id</b> in your object. |
| 141 | + </p> |
| 142 | + <p> |
| 143 | + You can <b>insert</b> only the <b>payload</b> by checking the checkbox |
| 144 | + in the configuration window. |
| 145 | + </p> |
| 146 | + <p> |
| 147 | + It is also possible to <b>delete</b> documents from the database by |
| 148 | + providing values for <b>msg.payload._id</b> and <b>msg.payload._rev</b> |
| 149 | + and selecting the <b>remove</b> option for the node. |
| 150 | + </p> |
| 151 | +</script> |
| 152 | + |
| 153 | +<script type="text/javascript"> |
| 154 | + RED.nodes.registerType("cloudant out", { |
| 155 | + category: "storage-output", |
| 156 | + color: "rgb(114, 199, 231)", |
| 157 | + defaults: { |
| 158 | + cloudant: { type: "cloudant", required: true }, |
| 159 | + name: { value: "" }, |
| 160 | + db: { value: "", required: true }, |
| 161 | + payonly: { value: false }, |
| 162 | + operation: { value: "insert" } |
| 163 | + }, |
| 164 | + inputs: 1, |
| 165 | + outputs: 0, |
| 166 | + icon: "cloudant.png", |
| 167 | + align: "right", |
| 168 | + label: function() { |
| 169 | + return this.name || "cloudant"; |
| 170 | + }, |
| 171 | + labelStyle: function() { |
| 172 | + return this.name ? "node_label_italic" : ""; |
| 173 | + } |
| 174 | + }); |
| 175 | +</script> |
0 commit comments