5757 < input type = "hidden" id = "node-input-bandhidden" />
5858 < / d i v >
5959
60-
6160 < div class = "form-row" >
6261 < label for = "node-input-continuous" > < i class = "fa fa-audio-o" > </ i > Continuous</ label >
6362 < input type = "checkbox" id = "node-input-continuous" > </ input >
9089</ script >
9190
9291< script type ="text/javascript ">
93- var models = null ;
94- var languages = null ;
95- var bands = null ;
9692
97- var language_selected = '' ;
98- var band_selected = '' ;
93+ // Need to simulate a namespace, as some of the variables had started to leak across nodes
94+ function STT ( ) {
95+ var models = null ;
96+ }
97+
98+ // This is the namespace for stt. Currently only contains models, but more vars and functions may need to be
99+ // moved in if there is a clash with other nodes.
100+ var stt = new STT ( ) ;
99101
100102 var LANGUAGES = { 'en-US' : 'US English' ,
101103 'pt-BR' : 'Portuguese Braziilian' ,
106108 'ja-JP' : 'Japanese'
107109 } ;
108110
111+ var languages = null ;
112+ var bands = null ;
113+
114+ var language_selected = '' ;
115+ var band_selected = '' ;
116+
109117
110118 // sorting functions
111119 function onlyUnique ( value , index , self ) {
115123 // Function to be used at the start, as don't want to expose any fields, unless the models are
116124 // available. The models can only be fetched if the credentials are available.
117125 function hideEverything ( ) {
118- if ( ! models ) {
126+ if ( ! stt . models ) {
119127 $ ( '#credentials-not-found' ) . show ( ) ;
120128 $ ( 'label#node-label-message' ) . parent ( ) . hide ( ) ;
121129 $ ( 'input#node-input-continuous' ) . parent ( ) . hide ( ) ;
127135 // Check if there is a model then can show the fields.
128136 // available. The models can only be fetched if the credentials are available.
129137 function visibilityCheck ( ) {
130- if ( models ) {
138+ if ( stt . models ) {
131139 $ ( 'label#node-label-message' ) . parent ( ) . hide ( ) ;
132140 $ ( 'input#node-input-continuous' ) . parent ( ) . show ( ) ;
133141 $ ( 'select#node-input-lang' ) . parent ( ) . show ( ) ;
142150
143151
144152 // Simple check that is only invoked if the service is not bound into bluemix. In this case the
145- // user has to provide credentials. Once there are credentials, then the models are retrieved.
153+ // user has to provide credentials. Once there are credentials, then the stt. models are retrieved.
146154 function checkCredentials ( ) {
147155 var u = $ ( '#node-input-username' ) . val ( ) ;
148156 var p = $ ( '#node-input-password' ) . val ( ) ;
149157
150158 if ( u && u . length && p ) {
151- if ( ! models ) {
159+ if ( ! stt . models ) {
152160 getModels ( ) ;
153161 }
154162 }
155163 }
156164
157165 // Populate the quality select field
158166 function populateBands ( ) {
159- if ( ! bands && models ) {
160- bands = models . map ( function ( m ) {
167+ if ( ! bands && stt . models ) {
168+ bands = stt . models . map ( function ( m ) {
161169 return m . name . split ( '_' ) [ 1 ] ;
162170 } ) ;
163171 var unique_bands = bands . filter ( onlyUnique ) ;
215223 var u = $ ( '#node-input-username' ) . val ( ) ;
216224 var p = $ ( '#node-input-password' ) . val ( ) ;
217225
218- $ . getJSON ( '/ watson-speech-to-text/models/' , { un : u , pwd : p } ) . done ( function ( data ) {
226+ $ . getJSON ( 'watson-speech-to-text/models/' , { un : u , pwd : p } ) . done ( function ( data ) {
219227 if ( data . error ) {
220228 $ ( 'label#node-label-message' ) . parent ( ) . show ( ) ;
221229 $ ( 'label#node-label-message' ) . text ( data . error ) ;
222230 } else if ( data . models ) {
223- models = data . models ;
231+ stt . models = data . models ;
224232 //have_credentials = true;
225233 postModelCheck ( ) ;
226234 }
233241
234242 // Called to complete the languages selection table
235243 function processLanguages ( ) {
236- if ( ! languages && models ) {
237- languages = models . map ( function ( m ) {
244+ if ( ! languages && stt . models ) {
245+ languages = stt . models . map ( function ( m ) {
238246 return m . language ;
239247 } ) ;
240248 }
261269
262270 // Called to work through the models, completing the dyanmic selection fields.
263271 function processModels ( ) {
264- if ( models ) {
272+ if ( stt . models ) {
265273 processLanguages ( ) ;
266274 populateBands ( ) ;
267275 }
293301 . done ( function ( service ) {
294302 restoreFromHidden ( ) ;
295303 $ ( '.credentials' ) . toggle ( ! service ) ;
296- if ( ! models ) { getModels ( service ) ; }
304+ if ( ! stt . models ) { getModels ( service ) ; }
297305 else { postModelCheck ( ) ; }
298306 } )
299307 . fail ( function ( ) {
340348 oneditsave : oneditsave
341349 } ) ;
342350 } ) ( ) ;
351+
343352</ script >
0 commit comments