|
32 | 32 | <label for="node-input-password"><i class="fa fa-key"></i> Password</label> |
33 | 33 | <input type="password" id="node-input-password" placeholder="Password"> |
34 | 34 | </div> |
| 35 | + |
| 36 | + <div class="form-row credentials"> |
| 37 | + <label> </label> |
| 38 | + <input type="checkbox" id="node-input-default-endpoint" style="display: inline-block; width: auto; vertical-align: top;"> |
| 39 | + <label for="node-input-default-endpoint" style="width: 70%;"> Use Default Service Endpoint</label> |
| 40 | + </div> |
| 41 | + <div class="form-row"> |
| 42 | + <label for="node-input-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label> |
| 43 | + <input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/natural-language-classifier/api"> |
| 44 | + </div> |
| 45 | + |
35 | 46 | <div class="form-row"> |
36 | 47 | <label for="node-input-mode"><i class="fa fa-question"></i> Mode</label> |
37 | 48 | <select type="text" id="node-input-mode" style="display: inline-block; width: 70%;" > |
|
88 | 99 | </script> |
89 | 100 |
|
90 | 101 | <script type="text/javascript"> |
| 102 | + // Need to simulate a namespace, so that some of the variables don't leak across nodes |
| 103 | + function NaturalLanguageClassifierV1 () {} |
| 104 | + |
| 105 | + // This is the namespace for this version of this Node. |
| 106 | + var nlcV1 = new NaturalLanguageClassifierV1(); |
| 107 | + |
| 108 | + nlcV1.CreateIListener = function(listen, action, opp) { |
| 109 | + opp = typeof opp === 'undefined' ? false : opp; |
| 110 | + listen.change(function(val){ |
| 111 | + var isSet = listen.prop('checked'); |
| 112 | + if (opp) { |
| 113 | + isSet = !isSet; |
| 114 | + } |
| 115 | + nluV1.setVisibility(action, isSet); |
| 116 | + }); |
| 117 | + } |
| 118 | + |
| 119 | + nlcV1.UIListeners = function () { |
| 120 | + $('#node-input-mode').change(function () { |
| 121 | + var mode = $('#node-input-mode').val(); |
| 122 | + $('.form-row.mode.' + mode).show(); |
| 123 | + $('.form-row.mode:not(.' + mode + ')').hide(); |
| 124 | + }); |
| 125 | + |
| 126 | + nlcV1.CreateIListener($('#node-input-default-endpoint'), |
| 127 | + $('#node-input-service-endpoint'), true); |
| 128 | + }; |
| 129 | + |
| 130 | + nlcV1.checkForPrepare = function () { |
| 131 | + nlcV1.UIListeners(); |
| 132 | + }; |
| 133 | + |
| 134 | + // This is the on edit prepare function, which will be |
| 135 | + //invoked everytime the dialog is shown. |
| 136 | + function nlconeditprepare() { |
| 137 | + |
| 138 | + |
| 139 | + nlcV1.checkForPrepare(); |
| 140 | + $.getJSON('watson-natural-language-classifier/vcap/') |
| 141 | + .done(function (service) { |
| 142 | + $('.credentials').toggle(!service); |
| 143 | + }) |
| 144 | + .fail(function () { |
| 145 | + $('.credentials').show(); |
| 146 | + }).always(function () { |
| 147 | + $('#credentials-check').hide(); |
| 148 | + }) |
| 149 | + } |
| 150 | + |
| 151 | + |
91 | 152 | (function() { |
92 | 153 | RED.nodes.registerType('watson-natural-language-classifier', { |
93 | 154 | category: 'IBM Watson', |
94 | 155 | defaults: { |
95 | 156 | name: {value: ""}, |
96 | 157 | mode: {value: "classify"}, |
97 | 158 | language: {value: "en"}, |
98 | | - classifier: {value: ""} |
| 159 | + classifier: {value: ""}, |
| 160 | + 'default-endpoint' :{value: true}, |
| 161 | + 'service-endpoint' :{value: 'https://gateway.watsonplatform.net/natural-language-classifier/api'} |
99 | 162 | }, |
100 | 163 | credentials: { |
101 | 164 | username: {type:"text"}, |
|
112 | 175 | labelStyle: function() { |
113 | 176 | return this.name ? "node_label_italic" : ""; |
114 | 177 | }, |
115 | | - oneditprepare: function() { |
116 | | - $('#node-input-mode').change(function () { |
117 | | - var mode = $('#node-input-mode').val(); |
118 | | - $('.form-row.mode.' + mode).show(); |
119 | | - $('.form-row.mode:not(.' + mode + ')').hide(); |
120 | | - }) |
121 | | - $.getJSON('watson-natural-language-classifier/vcap/') |
122 | | - .done(function (service) { |
123 | | - $('.credentials').toggle(!service); |
124 | | - }) |
125 | | - .fail(function () { |
126 | | - $('.credentials').show(); |
127 | | - }).always(function () { |
128 | | - $('#credentials-check').hide(); |
129 | | - }) |
130 | | - } |
| 178 | + oneditprepare: nlconeditprepare |
131 | 179 | }); |
132 | 180 | })(); |
133 | 181 | </script> |
0 commit comments