|
79 | 79 | <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label> |
80 | 80 | <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"> |
81 | 81 | </div> |
| 82 | + <div class="form-row"> |
| 83 | + <label for="node-input-statusCode"><i class="fa fa-long-arrow-left"></i> <span data-i18n="httpin.label.status"></span></label> |
| 84 | + <input type="text" id="node-input-statusCode" placeholder="msg.statusCode"> |
| 85 | + </div> |
| 86 | + <div class="form-row" style="margin-bottom:0;"> |
| 87 | + <label><i class="fa fa-list"></i> <span data-i18n="httpin.label.headers"></span></label> |
| 88 | + </div> |
| 89 | + <div class="form-row node-input-headers-container-row"> |
| 90 | + <ol id="node-input-headers-container"></ol> |
| 91 | + </div> |
82 | 92 | <div class="form-tips"><span data-i18n="[html]httpin.tip.res"></span></div> |
83 | 93 | </script> |
84 | 94 |
|
|
92 | 102 | pairs to be added as response headers.</li> |
93 | 103 | <li><code>cookies</code>, if set, can be used to set or delete cookies. |
94 | 104 | </ul> |
| 105 | + <p>The <code>statusCode</code> and <code>headers</code> can also be set within |
| 106 | + the node itself. If a property is set within the node, it cannot be overridden |
| 107 | + by the corresponding message property.</p> |
95 | 108 | <h3>Cookie handling</h3> |
96 | 109 | <p>The <code>cookies</code> property must be an object of name/value pairs. |
97 | 110 | The value can be either a string to set the value of the cookie with default |
@@ -120,6 +133,7 @@ <h3>Cookie handling</h3> |
120 | 133 | </script> |
121 | 134 |
|
122 | 135 | <script type="text/javascript"> |
| 136 | +(function() { |
123 | 137 | RED.nodes.registerType('http in',{ |
124 | 138 | category: 'input', |
125 | 139 | color:"rgb(231, 231, 174)", |
@@ -180,22 +194,153 @@ <h3>Cookie handling</h3> |
180 | 194 | } |
181 | 195 |
|
182 | 196 | }); |
| 197 | + var headerTypes = [ |
| 198 | + {value:"content-type",label:"Content-Type",hasValue: false}, |
| 199 | + {value:"location",label:"Location",hasValue: false}, |
| 200 | + {value:"other",label:"other",icon:"red/images/typedInput/az.png"} |
| 201 | + ] |
| 202 | + var contentTypes = [ |
| 203 | + {value:"application/json",label:"application/json",hasValue: false}, |
| 204 | + {value:"application/xml",label:"application/xml",hasValue: false}, |
| 205 | + {value:"text/css",label:"text/css",hasValue: false}, |
| 206 | + {value:"text/html",label:"text/html",hasValue: false}, |
| 207 | + {value:"text/plain",label:"text/plain",hasValue: false}, |
| 208 | + {value:"image/gif",label:"image/gif",hasValue: false}, |
| 209 | + {value:"image/png",label:"image/png",hasValue: false}, |
| 210 | + {value:"other",label:"other",icon:"red/images/typedInput/az.png"} |
| 211 | + ]; |
183 | 212 |
|
184 | 213 | RED.nodes.registerType('http response',{ |
185 | 214 | category: 'output', |
186 | 215 | color:"rgb(231, 231, 174)", |
187 | 216 | defaults: { |
188 | | - name: {value:""} |
| 217 | + name: {value:""}, |
| 218 | + statusCode: {value:"",validate: RED.validators.number(true)}, |
| 219 | + headers: {value:{}} |
189 | 220 | }, |
190 | 221 | inputs:1, |
191 | 222 | outputs:0, |
192 | 223 | align: "right", |
193 | 224 | icon: "white-globe.png", |
194 | 225 | label: function() { |
195 | | - return this.name||"http"; |
| 226 | + return this.name||("http"+(this.statusCode?" ("+this.statusCode+")":"")); |
196 | 227 | }, |
197 | 228 | labelStyle: function() { |
198 | 229 | return this.name?"node_label_italic":""; |
| 230 | + }, |
| 231 | + oneditprepare: function() { |
| 232 | + function resizeRule(rule) { |
| 233 | + var newWidth = rule.width(); |
| 234 | + rule.find('.red-ui-typedInput').typedInput("width",(newWidth-15)/2); |
| 235 | + |
| 236 | + } |
| 237 | + var headerList = $("#node-input-headers-container").css('min-height','150px').css('min-width','450px').editableList({ |
| 238 | + addItem: function(container,i,header) { |
| 239 | + var row = $('<div/>').appendTo(container); |
| 240 | + var propertyName = $('<input/>',{class:"node-input-header-name",type:"text"}) |
| 241 | + .appendTo(row) |
| 242 | + .typedInput({types:headerTypes}); |
| 243 | + |
| 244 | + var propertyValue = $('<input/>',{class:"node-input-header-value",type:"text",style:"margin-left: 10px"}) |
| 245 | + .appendTo(row) |
| 246 | + .typedInput({types: |
| 247 | + header.h === 'content-type'?contentTypes:[{value:"other",label:"other",icon:"red/images/typedInput/az.png"}] |
| 248 | + }); |
| 249 | + |
| 250 | + var matchedType = headerTypes.filter(function(ht) { |
| 251 | + return ht.value === header.h |
| 252 | + }); |
| 253 | + if (matchedType.length === 0) { |
| 254 | + propertyName.typedInput('type','other'); |
| 255 | + propertyName.typedInput('value',header.h); |
| 256 | + propertyValue.typedInput('value',header.v); |
| 257 | + } else { |
| 258 | + propertyName.typedInput('type',header.h); |
| 259 | + |
| 260 | + if (header.h === "content-type") { |
| 261 | + matchedType = contentTypes.filter(function(ct) { |
| 262 | + return ct.value === header.v; |
| 263 | + }); |
| 264 | + if (matchedType.length === 0) { |
| 265 | + propertyValue.typedInput('type','other'); |
| 266 | + propertyValue.typedInput('value',header.v); |
| 267 | + } else { |
| 268 | + propertyValue.typedInput('type',header.v); |
| 269 | + } |
| 270 | + } else { |
| 271 | + propertyValue.typedInput('value',header.v); |
| 272 | + } |
| 273 | + } |
| 274 | + |
| 275 | + matchedType = headerTypes.filter(function(ht) { |
| 276 | + return ht.value === header.h |
| 277 | + }); |
| 278 | + if (matchedType.length === 0) { |
| 279 | + propertyName.typedInput('type','other'); |
| 280 | + propertyName.typedInput('value',header.h); |
| 281 | + } else { |
| 282 | + propertyName.typedInput('type',header.h); |
| 283 | + } |
| 284 | + |
| 285 | + propertyName.on('change',function(event) { |
| 286 | + var type = propertyName.typedInput('type'); |
| 287 | + if (type === 'content-type') { |
| 288 | + propertyValue.typedInput('types',contentTypes); |
| 289 | + } else { |
| 290 | + propertyValue.typedInput('types',[{value:"other",label:"other",icon:"red/images/typedInput/az.png"}]); |
| 291 | + } |
| 292 | + }); |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + resizeRule(container); |
| 297 | + }, |
| 298 | + resizeItem: resizeRule, |
| 299 | + removable: true |
| 300 | + }); |
| 301 | + |
| 302 | + if (this.headers) { |
| 303 | + for (var key in this.headers) { |
| 304 | + if (this.headers.hasOwnProperty(key)) { |
| 305 | + headerList.editableList('addItem',{h:key,v:this.headers[key]}); |
| 306 | + } |
| 307 | + } |
| 308 | + } |
| 309 | + }, |
| 310 | + oneditsave: function() { |
| 311 | + var headers = $("#node-input-headers-container").editableList('items'); |
| 312 | + var node = this; |
| 313 | + node.headers = {}; |
| 314 | + headers.each(function(i) { |
| 315 | + var header = $(this); |
| 316 | + var keyType = header.find(".node-input-header-name").typedInput('type'); |
| 317 | + var keyValue = header.find(".node-input-header-name").typedInput('value'); |
| 318 | + var valueType = header.find(".node-input-header-value").typedInput('type'); |
| 319 | + var valueValue = header.find(".node-input-header-value").typedInput('value'); |
| 320 | + var key = keyType; |
| 321 | + var value = valueType; |
| 322 | + if (keyType === 'other') { |
| 323 | + key = keyValue; |
| 324 | + } |
| 325 | + if (valueType === 'other') { |
| 326 | + value = valueValue; |
| 327 | + } |
| 328 | + if (key !== '') { |
| 329 | + node.headers[key] = value; |
| 330 | + } |
| 331 | + }); |
| 332 | + }, |
| 333 | + oneditresize: function(size) { |
| 334 | + var rows = $("#dialog-form>div:not(.node-input-headers-container-row)"); |
| 335 | + var height = size.height; |
| 336 | + for (var i=0; i<rows.size(); i++) { |
| 337 | + height -= $(rows[i]).outerHeight(true); |
| 338 | + } |
| 339 | + var editorRow = $("#dialog-form>div.node-input-headers-container-row"); |
| 340 | + height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom"))); |
| 341 | + |
| 342 | + $("#node-input-headers-container").editableList('height',height); |
199 | 343 | } |
200 | 344 | }); |
| 345 | +})(); |
201 | 346 | </script> |
0 commit comments