5151 </div >
5252
5353 < div class = "form-row" >
54- < label for = "node-input-domain" > < i class = "fa fa-book" > </ i > Domains </ label >
54+ < label for = "node-input-domain" > < i class = "fa fa-book" > </ i > DDomains </ label >
5555 < select type = "text" id = "node-input-domain" style = "display: inline-block; vertical-align:middle; width: 70%;" >
5656 </ select >
5757 </ div >
182182 } ;
183183
184184 // convert an id in the form it-ko into Italian - Korean for display
185- function idToText ( id ) {
185+ function changeIdToText ( id ) {
186+ console . log ( 'in changeIdToText' ) ;
186187 var txt = "" ;
187188 var langs = id . split ( '-' ) ;
188189 var first = true ;
199200
200201 // Function to be used at the start, as don't want to expose any fields, unless the model is
201202 // available. The model it self can only be fetched if the credentials are available.
202- function hideEverything ( ) {
203+ function hideAll ( ) {
204+ console . log ( 'in hideAll' ) ;
203205 if ( ! models ) {
204206 $ ( '#credentials-not-found' ) . show ( ) ;
205207 $ ( '#node-input-action' ) . parent ( ) . hide ( ) ;
219221 // the model has been retrieved then this function is invoked to update what fields
220222 // are shown without the user having to close the dialog.
221223 // Problem is that the onchange is only invoked when the user tabs to another field.
222- function visibilityCheck ( ) {
224+ function checkVisibility ( ) {
225+ console . log ( 'in checkVisibility' ) ;
223226 if ( models ) {
224227 $ ( '#node-input-action' ) . parent ( ) . show ( ) ;
225- selectAction ( ) ;
228+ checkActionSelected ( ) ;
226229 }
227230 }
228231
229232 // sorting functions
230- function onlyUnique ( value , index , self ) {
233+ function checkUnique ( value , index , self ) {
231234 return self . indexOf ( value ) === index ;
232235 }
233236
234237
235238 // Retrieve the available models from the server, if data is returned, then
236239 // can enable the dynamic selection fields.
237- function getModels ( ) {
240+ function checkModels ( ) {
241+ console . log ( 'in checkModels' ) ;
238242 var u = $ ( '#node-input-username' ) . val ( ) ;
239243 var p = $ ( '#node-input-password' ) . val ( ) ;
240244
241245 $ . getJSON ( 'watson-translate/models/' , { un : u , pwd : p } ) . done ( function ( data ) {
242246 if ( data . models ) {
243247 models = data . models ;
244248 have_credentials = true ;
245- visibilityCheck ( ) ;
249+ checkVisibility ( ) ;
246250 }
247251 } ) . fail ( function ( err ) {
248252 console . log ( err ) ;
251255
252256 // Simple check that is only invoked if the service is not bound into bluemix. In this case the
253257 // user has to provide credentials. Once there are credentials, then the models are retrieved.
254- function checkCredentials ( ) {
258+ function getCredentials ( ) {
259+ console . log ( 'in getCredentials' ) ;
255260 var u = $ ( '#node-input-username' ) . val ( ) ;
256261 var p = $ ( '#node-input-password' ) . val ( ) ;
257262
258263 if ( u && u . length && p ) {
259264 if ( ! models ) {
260- getModels ( ) ;
265+ checkModels ( ) ;
261266 if ( models ) { $ ( '#node-input-action' ) . parent ( ) . show ( ) ; }
262267 }
263268 } else if ( ! models ) {
268273 // function that is called when the domain or the source language is changed. In this case the
269274 // destination language selection field is dynamically repopulated, and reselected if the
270275 // previously selection is still in the new list.
271- function destlangAvailable ( ) {
276+ function langDestAvailable ( ) {
277+ console . log ( 'in langDestAvailable' ) ;
272278 if ( ! domain_type ) { return ; }
273279
274280 var pair_lang = domain_type . map ( function ( a ) {
301307
302308 // Populates the domains selection field.
303309 // If domains have already been retrieved then no need to refetch them.
304- function domainsAvailable ( ) {
310+ function checkDomains ( ) {
311+ console . log ( 'in checkDomains' ) ;
305312 if ( ! domains ) {
306313 domains = models . map ( function ( a ) {
307314 return a . domain ;
308315 } ) ;
309316 }
310317 if ( domains ) {
311318 $ ( 'select#node-input-domain' ) . empty ( ) ;
312- var unique_domains = domains . filter ( onlyUnique ) ;
319+ var unique_domains = domains . filter ( checkUnique ) ;
313320
314321 unique_domains . forEach ( function ( domain ) {
315322 var selectedText = '' ;
326333 + '</option>' ) ;
327334 } ) ;
328335
329- selectDomain ( ) ;
336+ checkDomainSelected ( ) ;
330337 }
331338 }
332339
333340 // Populates the base model field. These are the models that are available to be customised.
334- function basemodelsAvailable ( ) {
341+ function checkBaseModels ( ) {
342+ console . log ( 'in checkBaseModels' ) ;
335343 if ( ! basemodels && models ) {
336344 basemodels = models . filter ( function ( model ) {
337345 return model . customizable === true ;
349357 + '"' + base_model . model_id + '"'
350358 + selectedText
351359 + '>'
352- + idToText ( base_model . model_id )
360+ + changeIdToText ( base_model . model_id )
353361 + '</option>' ) ;
354362 } ) ;
355363 }
360368 // will happen is by a page refresh. Need to have a trigger everytime the create
361369 // new model is triggerd, but that is a little complicated and needs to be done on
362370 // a clear mind.
363- function customsAvailable ( ) {
371+ function checkCustomsAvailable ( ) {
372+ console . log ( 'in checkCustomsAvailable' ) ;
364373 if ( ! custommodels && models ) {
365374 custommodels = models . filter ( function ( m ) {
366375 return ( m . base_model_id && ( '' != m . base_model_id ) ) ;
390399
391400 // UI Handler for the Mode / switch.
392401 // Princliple function is to show / hide the appropriate fields.
393- function selectAction ( ) {
402+ function checkActionSelected ( ) {
403+ console . log ( 'in checkActionSelected' ) ;
394404 action = $ ( '#node-input-action' ) . val ( ) ;
395405 if ( models ) {
396406 $ ( '#credentials-not-found' ) . hide ( ) ;
425435 $ ( 'select#node-input-basemodel, select#node-input-filetype' ) . parent ( '' ) . hide ( ) ;
426436 break ;
427437 }
428- domainsAvailable ( ) ;
429- basemodelsAvailable ( ) ;
430- customsAvailable ( ) ;
438+ checkDomains ( ) ;
439+ checkBaseModels ( ) ;
440+ checkCustomsAvailable ( ) ;
431441 } else {
432442 $ ( '#credentials-not-found' ) . show ( ) ;
433443 }
434444 }
435445
436446 // UI Handler for the domain switch
437447 // Repopulate the source and languages based on the available translations for the domain
438- function selectDomain ( ) {
448+ function checkDomainSelected ( ) {
449+ console . log ( 'in checkDomainSelected' ) ;
439450 $ ( '#node-input-srclang' ) . empty ( ) ;
440451 $ ( '#node-input-destlang' ) . empty ( ) ;
441452 if ( models && domains ) {
449460 var output_lang = domain_type . map ( function ( a ) {
450461 return a . target ;
451462 } ) ;
452- input_lang_unique = input_lang . filter ( onlyUnique ) ;
453- output_lang_unique = output_lang . filter ( onlyUnique ) ;
463+ input_lang_unique = input_lang . filter ( checkUnique ) ;
464+ output_lang_unique = output_lang . filter ( checkUnique ) ;
454465
455466 input_lang_unique . forEach ( function ( lang ) {
456467 var selectedText = '' ;
468479 // Having repopulated the input language selection, the old selected item
469480 // may no longer be in the list, so refresh it.
470481 srclang_selected = $ ( '#node-input-srclang' ) . val ( ) ;
471- destlangAvailable ( ) ;
482+ langDestAvailable ( ) ;
472483 }
473484 }
474485
475486
476487 // Register the handlers for the fields
477- function handlersUI ( ) {
488+ function UIListeners ( ) {
489+ console . log ( 'in UIListeners' ) ;
478490 $ ( '#node-input-username' ) . change ( function ( val ) {
479- checkCredentials ( ) ;
491+ getCredentials ( ) ;
480492 if ( have_credentials ) {
481- selectAction ( ) ; }
493+ checkActionSelected ( ) ; }
482494 } ) ;
483495 $ ( '#node-input-password' ) . change ( function ( val ) {
484- checkCredentials ( ) ;
496+ getCredentials ( ) ;
485497 if ( have_credentials ) {
486- selectAction ( ) ;
498+ checkActionSelected ( ) ;
487499 }
488500 } ) ;
489501
490502 $ ( '#node-input-action' ) . change ( function ( val ) {
491503 action = $ ( '#node-input-action' ) . val ( ) ;
492- selectAction ( ) ;
504+ checkActionSelected ( ) ;
493505 } ) ;
494506
495507 $ ( '#node-input-domain' ) . change ( function ( val ) {
496508 domain_selected = $ ( '#node-input-domain' ) . val ( ) ;
497- selectDomain ( ) ;
509+ checkDomainSelected ( ) ;
498510 } ) ;
499511
500512 $ ( '#node-input-custom' ) . change ( function ( ) {
503515
504516 $ ( '#node-input-srclang' ) . change ( function ( ) {
505517 srclang_selected = $ ( '#node-input-srclang' ) . val ( ) ;
506- destlangAvailable ( ) ;
518+ langDestAvailable ( ) ;
507519 } ) ;
508520
509521 $ ( '#node-input-destlang' ) . change ( function ( ) {
520532 // restart, the settings for the dynamic fields are lost.
521533 // So hidden (text) fields are being used to squirrel away the values, so that
522534 // they can be restored.
523- function restoreFromHidden ( ) {
535+ function restoreHidden ( ) {
536+ console . log ( 'in restoreHidden' ) ;
524537 domain_selected = $ ( '#node-input-domainhidden' ) . val ( ) ;
525538 $ ( 'select#node-input-domain' ) . val ( domain_selected ) ;
526539 srclang_selected = $ ( '#node-input-srclanghidden' ) . val ( ) ;
537550 // This is the on edit prepare function, which will be invoked everytime the dialog
538551 // is shown.
539552 function oneditprepare ( ) {
540- hideEverything ( ) ;
541- restoreFromHidden ( ) ;
553+ console . log ( 'in oneditprepare' ) ;
554+
555+ hideAll ( ) ;
556+ restoreHidden ( ) ;
542557
543- handlersUI ( ) ;
558+ UIListeners ( ) ;
544559 // Look for VCAP Json file, done is called if found or not, with service indicating
545560 // if the translation service is actually bound into this application.
546561 if ( ! have_credentials ) {
547562 $ . getJSON ( 'watson-translate/vcap/' )
548563 . done ( function ( service ) {
549- // for some reason the getJSON resets the vars so need to restoreFromHidden again
564+ // for some reason the getJSON resets the vars so need to restoreHidden again
550565 // so again.
551- restoreFromHidden ( ) ;
566+ restoreHidden ( ) ;
552567 $ ( '.credentials' ) . toggle ( ! service ) ;
553568 if ( ! service ) {
554569 // no bound service, so check local settings to see if they are valid
555570 using_local_credentials = true ;
556- checkCredentials ( ) ;
571+ getCredentials ( ) ;
557572 } else {
558573 // credentials are only valid if we can get hold of the models using them
559574 using_local_credentials = false ;
560- if ( ! models ) { getModels ( ) ; }
575+ if ( ! models ) { checkModels ( ) ; }
561576 }
562577 } ) . fail ( function ( ) {
563578 $ ( '.credentials' ) . show ( ) ;
575590 if ( using_local_credentials ) {
576591 $ ( '.credentials' ) . show ( ) ;
577592 }
578- selectAction ( ) ;
593+ checkActionSelected ( ) ;
579594 }
580595 }
581596
582597 // Save the values in the dyanmic lists to the hidden fields.
583598 function oneditsave ( ) {
599+ console . log ( 'in oneditsave' ) ;
584600 $ ( '#node-input-domainhidden' ) . val ( domain_selected ) ;
585601 $ ( '#node-input-srclanghidden' ) . val ( srclang_selected ) ;
586602 $ ( '#node-input-destlanghidden' ) . val ( destlang_selected ) ;
629645 } ) ;
630646 } ) ( ) ;
631647
632- </ script >
648+ </ script >
0 commit comments