|
98 | 98 | 'ja-JP': 'Japanese' |
99 | 99 | }; |
100 | 100 |
|
| 101 | + // sorting functions |
| 102 | + tts.onlyUnique = function (value, index, self) { |
| 103 | + return self.indexOf(value) === index; |
| 104 | + } |
| 105 | + |
101 | 106 | // Called to complete the languages selection table |
102 | | - function processLanguages() { |
| 107 | + tts.processLanguages = function () { |
103 | 108 | if (!tts.languages && tts.voices) { |
104 | 109 | tts.languages = tts.voices.map(function(m) { |
105 | 110 | return m.language; |
106 | 111 | }); |
107 | 112 | } |
108 | 113 | if (tts.languages) { |
109 | 114 | $('select#node-input-lang').empty(); |
110 | | - var unique_langs = tts.languages.filter(onlyUnique); |
| 115 | + var unique_langs = tts.languages.filter(tts.onlyUnique); |
111 | 116 |
|
112 | 117 | unique_langs.forEach(function(l) { |
113 | 118 | var selectedText = ''; |
|
127 | 132 | } |
128 | 133 |
|
129 | 134 | // Populate the Voices selection field |
130 | | - function populateVoices() { |
| 135 | + tts.populateVoices = function () { |
131 | 136 | if (!tts.voicenames && tts.voices) { |
132 | 137 | tts.voicenames = tts.voices.map(function(m) { |
133 | 138 | //return m.name.split('_')[1]; |
134 | 139 | return m.name; |
135 | 140 | }); |
136 | | - var unique_voices = tts.voicenames.filter(onlyUnique); |
| 141 | + var unique_voices = tts.voicenames.filter(tts.onlyUnique); |
137 | 142 | tts.voicenames = unique_voices; |
138 | 143 | } |
139 | 144 | if (!tts.voicedata && tts.voicenames){ |
|
171 | 176 |
|
172 | 177 |
|
173 | 178 | // Called to work through the voices, completing the dyanmic selection fields. |
174 | | - function processVoices() { |
| 179 | + tts.processVoices = function () { |
175 | 180 | if (tts.voices) { |
176 | | - processLanguages(); |
177 | | - populateVoices(); |
| 181 | + tts.processLanguages(); |
| 182 | + tts.populateVoices(); |
178 | 183 | } |
179 | 184 | } |
180 | 185 |
|
181 | | - function visibilityCheck() |
| 186 | + tts.visibilityCheck = function () |
182 | 187 | { |
183 | 188 | if (tts.voices) { |
184 | 189 | $('label#node-label-message').parent().hide(); |
|
194 | 199 |
|
195 | 200 | // Function called when either when the voices have been retrieved, or |
196 | 201 | // on dialog load, if the voices has already been retrieved |
197 | | - function postVoiceCheck(){ |
198 | | - processVoices(); |
199 | | - visibilityCheck(); |
| 202 | + tts.postVoiceCheck = function (){ |
| 203 | + tts.processVoices(); |
| 204 | + tts.visibilityCheck(); |
200 | 205 | } |
201 | 206 |
|
202 | 207 | // Retrieve the available voices from the server, if data is returned, then |
203 | 208 | // can enable the dynamic selection fields. |
204 | | - function getVoices(){ |
| 209 | + tts.getVoices = function (){ |
205 | 210 | var u = $('#node-input-username').val(); |
206 | 211 | var p = $('#node-input-password').val(); |
207 | 212 |
|
|
211 | 216 | $('label#node-label-message').text(data.error); |
212 | 217 | } else if (data.voices) { |
213 | 218 | tts.voices = data.voices; |
214 | | - postVoiceCheck(); |
| 219 | + tts.postVoiceCheck(); |
215 | 220 | } |
216 | 221 | }).fail(function (err) { |
217 | 222 | $('label#node-label-message').parent().show(); |
|
226 | 231 | // restart, the settings for the dynamic fields are lost. |
227 | 232 | // So hidden (text) fields are being used to squirrel away the values, so that |
228 | 233 | // they can be restored. |
229 | | - function restoreFromHidden() { |
| 234 | + tts.restoreFromHidden = function () { |
230 | 235 | tts.language_selected = $('#node-input-langhidden').val(); |
231 | 236 | $('select#node-input-lang').val(tts.language_selected); |
232 | 237 |
|
|
236 | 241 |
|
237 | 242 | // Simple check that is only invoked if the service is not bound into bluemix. In this case the |
238 | 243 | // user has to provide credentials. Once there are credentials, then the tts.voices are retrieved. |
239 | | - function checkCredentials() { |
| 244 | + tts.checkCredentials = function () { |
240 | 245 | var u = $('#node-input-username').val(); |
241 | 246 | var p = $('#node-input-password').val(); |
242 | 247 |
|
243 | 248 | if (u && u.length && p) { |
244 | 249 | if (!tts.voices) { |
245 | | - getVoices(); |
| 250 | + tts.getVoices(); |
246 | 251 | } |
247 | 252 | } |
248 | 253 | } |
249 | 254 |
|
250 | 255 | // Language Setting has changed, modofy voice options appropriately |
251 | | - function checkLanguage(){ |
| 256 | + tts.checkLanguage = function (){ |
252 | 257 | //var lang = $('#node-input-lang').val(); |
253 | 258 | //$('#node-input-voice option.' + lang).show(); |
254 | 259 | //$('#node-input-voice option:not(.' + lang + ')').hide(); |
|
259 | 264 | } |
260 | 265 |
|
261 | 266 | // Voice Setting has changed, modofy voice options appropriately |
262 | | - function checkVoice(){ |
| 267 | + tts.checkVoice = function (){ |
263 | 268 | tts.voice_selected = $('#node-input-voice').val(); |
264 | 269 | } |
265 | 270 |
|
266 | 271 |
|
267 | 272 | // Register the onchange handlers |
268 | | - function registerHandlers() { |
| 273 | + tts.registerHandlers = function () { |
269 | 274 | $('#node-input-username').change(function(val){ |
270 | | - checkCredentials(); |
| 275 | + tts.checkCredentials(); |
271 | 276 | }); |
272 | 277 | $('#node-input-password').change(function(val){ |
273 | | - checkCredentials(); |
| 278 | + tts.checkCredentials(); |
274 | 279 | }); |
275 | 280 | $('#node-input-lang').change(function () { |
276 | | - checkLanguage(); |
277 | | - populateVoices(); |
| 281 | + tts.checkLanguage(); |
| 282 | + tts.populateVoices(); |
278 | 283 | }); |
279 | 284 | $('#node-input-voice').change(function () { |
280 | | - checkVoice(); |
| 285 | + tts.checkVoice(); |
281 | 286 | }); |
282 | 287 |
|
283 | 288 | } |
284 | 289 |
|
285 | 290 | // Function to be used at the start, as don't want to expose any fields, unless the models are |
286 | 291 | // available. The models can only be fetched if the credentials are available. |
287 | | - function hideEverything() { |
| 292 | + tts.hideEverything = function () { |
288 | 293 | if (!stt.models) { |
289 | 294 | $('label#node-label-message').parent().hide(); |
290 | 295 | $('select#node-input-lang').parent().hide(); |
|
294 | 299 |
|
295 | 300 | // This is the on edit prepare function, which will be invoked everytime the dialog |
296 | 301 | // is shown. |
297 | | - function oneditprepare() { |
298 | | - hideEverything(); |
299 | | - restoreFromHidden(); |
300 | | - registerHandlers(); |
| 302 | + function ttsoneditprepare() { |
| 303 | + console.log('In on Edit Prepare'); |
| 304 | + tts.hideEverything(); |
| 305 | + tts.restoreFromHidden(); |
| 306 | + tts.registerHandlers(); |
301 | 307 |
|
302 | 308 | $.getJSON('watson-text-to-speech/vcap/') |
303 | 309 | .done(function (service) { |
304 | | - restoreFromHidden(); |
| 310 | + tts.restoreFromHidden(); |
305 | 311 | $('.credentials').toggle(!service); |
306 | | - if (!tts.voices) {getVoices();} |
307 | | - else {postVoiceCheck();} |
| 312 | + if (!tts.voices) {tts.getVoices();} |
| 313 | + else {tts.postVoiceCheck();} |
308 | 314 | }) |
309 | 315 | .fail(function () { |
310 | 316 | $('.credentials').show(); |
|
314 | 320 | } |
315 | 321 |
|
316 | 322 | // Save the values in the dyanmic lists to the hidden fields. |
317 | | - function oneditsave(){ |
| 323 | + function ttsoneditsave(){ |
318 | 324 | $('#node-input-langhidden').val(tts.language_selected); |
319 | 325 | $('#node-input-voicehidden').val(tts.voice_selected); |
320 | 326 | } |
|
346 | 352 | labelStyle: function() { |
347 | 353 | return this.name ? "node_label_italic" : ""; |
348 | 354 | }, |
349 | | - oneditsave: oneditsave, |
350 | | - oneditprepare: oneditprepare |
| 355 | + oneditsave: ttsoneditsave, |
| 356 | + oneditprepare: ttsoneditprepare |
351 | 357 | }); |
352 | 358 | })(); |
353 | 359 | </script> |
0 commit comments