8989</ script >
9090
9191< script type ="text/javascript ">
92- var models = null ;
93- var languages = null ;
94- var bands = null ;
9592
96- var language_selected = '' ;
97- 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 ( ) ;
98101
99102 var LANGUAGES = { 'en-US' : 'US English' ,
100103 'pt-BR' : 'Portuguese Braziilian' ,
105108 'ja-JP' : 'Japanese'
106109 } ;
107110
111+ var languages = null ;
112+ var bands = null ;
113+
114+ var language_selected = '' ;
115+ var band_selected = '' ;
116+
108117
109118 // sorting functions
110119 function onlyUnique ( value , index , self ) {
114123 // Function to be used at the start, as don't want to expose any fields, unless the models are
115124 // available. The models can only be fetched if the credentials are available.
116125 function hideEverything ( ) {
117- if ( ! models ) {
126+ if ( ! stt . models ) {
118127 $ ( '#credentials-not-found' ) . show ( ) ;
119128 $ ( 'label#node-label-message' ) . parent ( ) . hide ( ) ;
120129 $ ( 'input#node-input-continuous' ) . parent ( ) . hide ( ) ;
126135 // Check if there is a model then can show the fields.
127136 // available. The models can only be fetched if the credentials are available.
128137 function visibilityCheck ( ) {
129- if ( models ) {
138+ if ( stt . models ) {
130139 $ ( 'label#node-label-message' ) . parent ( ) . hide ( ) ;
131140 $ ( 'input#node-input-continuous' ) . parent ( ) . show ( ) ;
132141 $ ( 'select#node-input-lang' ) . parent ( ) . show ( ) ;
141150
142151
143152 // Simple check that is only invoked if the service is not bound into bluemix. In this case the
144- // 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.
145154 function checkCredentials ( ) {
146155 var u = $ ( '#node-input-username' ) . val ( ) ;
147156 var p = $ ( '#node-input-password' ) . val ( ) ;
148157
149158 if ( u && u . length && p ) {
150- if ( ! models ) {
159+ if ( ! stt . models ) {
151160 getModels ( ) ;
152161 }
153162 }
154163 }
155164
156165 // Populate the quality select field
157166 function populateBands ( ) {
158- if ( ! bands && models ) {
159- bands = models . map ( function ( m ) {
167+ if ( ! bands && stt . models ) {
168+ bands = stt . models . map ( function ( m ) {
160169 return m . name . split ( '_' ) [ 1 ] ;
161170 } ) ;
162171 var unique_bands = bands . filter ( onlyUnique ) ;
211220 // Retrieve the available models from the server, if data is returned, then
212221 // can enable the dynamic selection fields.
213222 function getModels ( haveCredentials ) {
214- console . log ( 'Fetching models' ) ;
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 ) {
219- console . log ( 'Models have been retrieved' ) ;
226+ $ . getJSON ( 'watson-speech-to-text/models/' , { un : u , pwd : p } ) . done ( function ( data ) {
220227 if ( data . error ) {
221228 $ ( 'label#node-label-message' ) . parent ( ) . show ( ) ;
222229 $ ( 'label#node-label-message' ) . text ( data . error ) ;
223230 } else if ( data . models ) {
224- models = data . models ;
231+ stt . models = data . models ;
225232 //have_credentials = true;
226233 postModelCheck ( ) ;
227234 }
234241
235242 // Called to complete the languages selection table
236243 function processLanguages ( ) {
237- if ( ! languages && models ) {
238- languages = models . map ( function ( m ) {
244+ if ( ! languages && stt . models ) {
245+ languages = stt . models . map ( function ( m ) {
239246 return m . language ;
240247 } ) ;
241248 }
262269
263270 // Called to work through the models, completing the dyanmic selection fields.
264271 function processModels ( ) {
265- if ( models ) {
272+ if ( stt . models ) {
266273 processLanguages ( ) ;
267274 populateBands ( ) ;
268275 }
284291 // This is the on edit prepare function, which will be invoked everytime the dialog
285292 // is shown.
286293 function oneditprepare ( ) {
287- console . log ( 'In oneditprepare' ) ;
288294 hideEverything ( ) ;
289295 restoreFromHidden ( ) ;
290296 handlersUI ( ) ;
295301 . done ( function ( service ) {
296302 restoreFromHidden ( ) ;
297303 $ ( '.credentials' ) . toggle ( ! service ) ;
298- if ( ! models ) { getModels ( service ) ; }
304+ if ( ! stt . models ) { getModels ( service ) ; }
299305 else { postModelCheck ( ) ; }
300306 } )
301307 . fail ( function ( ) {
342348 oneditsave : oneditsave
343349 } ) ;
344350 } ) ( ) ;
351+
345352</ script >
0 commit comments