Skip to content

Commit aaeffe7

Browse files
committed
Merge pull request #116 from arlemi/master
Changed all functions names because of an unknown bug...
2 parents 8cab262 + 4221b7a commit aaeffe7

2 files changed

Lines changed: 43 additions & 43 deletions

File tree

services/language_translation/v2.html

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
};
183183

184184
// convert an id in the form it-ko into Italian - Korean for display
185-
function idToText(id) {
185+
function changeIdToText(id) {
186186
var txt = "";
187187
var langs = id.split('-');
188188
var first = true;
@@ -199,7 +199,7 @@
199199

200200
// Function to be used at the start, as don't want to expose any fields, unless the model is
201201
// available. The model it self can only be fetched if the credentials are available.
202-
function hideEverything() {
202+
function hideAll() {
203203
if (!models) {
204204
$('#credentials-not-found').show();
205205
$('#node-input-action').parent().hide();
@@ -219,30 +219,30 @@
219219
// the model has been retrieved then this function is invoked to update what fields
220220
// are shown without the user having to close the dialog.
221221
// Problem is that the onchange is only invoked when the user tabs to another field.
222-
function visibilityCheck() {
222+
function checkVisibility() {
223223
if (models) {
224224
$('#node-input-action').parent().show();
225-
selectAction();
225+
checkActionSelected();
226226
}
227227
}
228228

229229
// sorting functions
230-
function onlyUnique(value, index, self) {
230+
function checkUnique(value, index, self) {
231231
return self.indexOf(value) === index;
232232
}
233233

234234

235235
// Retrieve the available models from the server, if data is returned, then
236236
// can enable the dynamic selection fields.
237-
function getModels() {
237+
function checkModels() {
238238
var u = $('#node-input-username').val();
239239
var p = $('#node-input-password').val();
240240

241241
$.getJSON('watson-translate/models/', {un: u, pwd: p}).done(function (data) {
242242
if (data.models) {
243243
models = data.models;
244244
have_credentials = true;
245-
visibilityCheck();
245+
checkVisibility();
246246
}
247247
}).fail(function (err) {
248248
console.log(err);
@@ -251,13 +251,13 @@
251251

252252
// Simple check that is only invoked if the service is not bound into bluemix. In this case the
253253
// user has to provide credentials. Once there are credentials, then the models are retrieved.
254-
function checkCredentials() {
254+
function getCredentials() {
255255
var u = $('#node-input-username').val();
256256
var p = $('#node-input-password').val();
257257

258258
if (u && u.length && p) {
259259
if (!models) {
260-
getModels();
260+
checkModels();
261261
if (models) {$('#node-input-action').parent().show(); }
262262
}
263263
} else if (!models) {
@@ -268,7 +268,7 @@
268268
// function that is called when the domain or the source language is changed. In this case the
269269
// destination language selection field is dynamically repopulated, and reselected if the
270270
// previously selection is still in the new list.
271-
function destlangAvailable() {
271+
function langDestAvailable() {
272272
if (!domain_type) { return; }
273273

274274
var pair_lang = domain_type.map(function (a) {
@@ -301,15 +301,15 @@
301301

302302
// Populates the domains selection field.
303303
// If domains have already been retrieved then no need to refetch them.
304-
function domainsAvailable() {
304+
function checkDomains() {
305305
if (!domains) {
306306
domains = models.map(function (a) {
307307
return a.domain;
308308
});
309309
}
310310
if (domains) {
311311
$('select#node-input-domain').empty();
312-
var unique_domains = domains.filter(onlyUnique);
312+
var unique_domains = domains.filter(checkUnique);
313313

314314
unique_domains.forEach(function(domain) {
315315
var selectedText = '';
@@ -326,12 +326,12 @@
326326
+ '</option>');
327327
});
328328

329-
selectDomain();
329+
checkDomainSelected();
330330
}
331331
}
332332

333333
// Populates the base model field. These are the models that are available to be customised.
334-
function basemodelsAvailable() {
334+
function checkBaseModels() {
335335
if (!basemodels && models) {
336336
basemodels = models.filter(function (model) {
337337
return model.customizable === true;
@@ -349,7 +349,7 @@
349349
+ '"' + base_model.model_id + '"'
350350
+ selectedText
351351
+ '>'
352-
+ idToText(base_model.model_id)
352+
+ changeIdToText(base_model.model_id)
353353
+ '</option>');
354354
});
355355
}
@@ -360,7 +360,7 @@
360360
// will happen is by a page refresh. Need to have a trigger everytime the create
361361
// new model is triggerd, but that is a little complicated and needs to be done on
362362
// a clear mind.
363-
function customsAvailable() {
363+
function checkCustomsAvailable() {
364364
if (!custommodels && models) {
365365
custommodels = models.filter(function (m) {
366366
return (m.base_model_id && ('' != m.base_model_id));
@@ -390,7 +390,7 @@
390390

391391
// UI Handler for the Mode / switch.
392392
// Princliple function is to show / hide the appropriate fields.
393-
function selectAction() {
393+
function checkActionSelected() {
394394
action = $('#node-input-action').val();
395395
if (models) {
396396
$('#credentials-not-found').hide();
@@ -425,17 +425,17 @@
425425
$('select#node-input-basemodel, select#node-input-filetype').parent('').hide();
426426
break;
427427
}
428-
domainsAvailable();
429-
basemodelsAvailable();
430-
customsAvailable();
428+
checkDomains();
429+
checkBaseModels();
430+
checkCustomsAvailable();
431431
} else {
432432
$('#credentials-not-found').show();
433433
}
434434
}
435435

436436
// UI Handler for the domain switch
437437
// Repopulate the source and languages based on the available translations for the domain
438-
function selectDomain(){
438+
function checkDomainSelected(){
439439
$('#node-input-srclang').empty();
440440
$('#node-input-destlang').empty();
441441
if (models && domains) {
@@ -449,8 +449,8 @@
449449
var output_lang = domain_type.map(function (a) {
450450
return a.target;
451451
});
452-
input_lang_unique = input_lang.filter(onlyUnique);
453-
output_lang_unique = output_lang.filter(onlyUnique);
452+
input_lang_unique = input_lang.filter(checkUnique);
453+
output_lang_unique = output_lang.filter(checkUnique);
454454

455455
input_lang_unique.forEach(function(lang){
456456
var selectedText = '';
@@ -468,33 +468,33 @@
468468
// Having repopulated the input language selection, the old selected item
469469
// may no longer be in the list, so refresh it.
470470
srclang_selected = $('#node-input-srclang').val();
471-
destlangAvailable();
471+
langDestAvailable();
472472
}
473473
}
474474

475475

476476
// Register the handlers for the fields
477-
function handlersUI() {
477+
function UIListeners() {
478478
$('#node-input-username').change(function(val){
479-
checkCredentials();
479+
getCredentials();
480480
if (have_credentials) {
481-
selectAction();}
481+
checkActionSelected();}
482482
});
483483
$('#node-input-password').change(function(val){
484-
checkCredentials();
484+
getCredentials();
485485
if (have_credentials) {
486-
selectAction();
486+
checkActionSelected();
487487
}
488488
});
489489

490490
$('#node-input-action').change(function(val){
491491
action = $('#node-input-action').val();
492-
selectAction();
492+
checkActionSelected();
493493
});
494494

495495
$('#node-input-domain').change(function (val) {
496496
domain_selected = $('#node-input-domain').val();
497-
selectDomain();
497+
checkDomainSelected();
498498
});
499499

500500
$('#node-input-custom').change(function () {
@@ -503,7 +503,7 @@
503503

504504
$('#node-input-srclang').change(function () {
505505
srclang_selected = $('#node-input-srclang').val();
506-
destlangAvailable();
506+
langDestAvailable();
507507
});
508508

509509
$('#node-input-destlang').change(function () {
@@ -520,7 +520,7 @@
520520
// restart, the settings for the dynamic fields are lost.
521521
// So hidden (text) fields are being used to squirrel away the values, so that
522522
// they can be restored.
523-
function restoreFromHidden() {
523+
function restoreHidden() {
524524
domain_selected = $('#node-input-domainhidden').val();
525525
$('select#node-input-domain').val(domain_selected);
526526
srclang_selected = $('#node-input-srclanghidden').val();
@@ -537,27 +537,27 @@
537537
// This is the on edit prepare function, which will be invoked everytime the dialog
538538
// is shown.
539539
function oneditprepare() {
540-
hideEverything();
541-
restoreFromHidden();
540+
hideAll();
541+
restoreHidden();
542542

543-
handlersUI();
543+
UIListeners();
544544
// Look for VCAP Json file, done is called if found or not, with service indicating
545545
// if the translation service is actually bound into this application.
546546
if (!have_credentials) {
547547
$.getJSON('watson-translate/vcap/')
548548
.done(function (service) {
549-
// for some reason the getJSON resets the vars so need to restoreFromHidden again
549+
// for some reason the getJSON resets the vars so need to restoreHidden again
550550
// so again.
551-
restoreFromHidden();
551+
restoreHidden();
552552
$('.credentials').toggle(!service);
553553
if (!service) {
554554
// no bound service, so check local settings to see if they are valid
555555
using_local_credentials = true;
556-
checkCredentials();
556+
getCredentials();
557557
} else {
558558
// credentials are only valid if we can get hold of the models using them
559559
using_local_credentials = false;
560-
if (!models) {getModels();}
560+
if (!models) {checkModels();}
561561
}
562562
}).fail(function () {
563563
$('.credentials').show();
@@ -575,7 +575,7 @@
575575
if (using_local_credentials) {
576576
$('.credentials').show();
577577
}
578-
selectAction();
578+
checkActionSelected();
579579
}
580580
}
581581

@@ -629,4 +629,4 @@
629629
});
630630
})();
631631

632-
</script>
632+
</script>

services/language_translation/v2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,4 @@ module.exports = function (RED) {
398398
password: {type:'password'}
399399
}
400400
});
401-
};
401+
};

0 commit comments

Comments
 (0)