not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.7 KiB

  1. define(["sugar-web/activity/activity","activity/SpeakActivity","facepalette","speechpalette","languagepalette","activity/sax","activity/dom-js","activity/AIMLInterpreter","activity/Speech"], function (activity, speakActivity, facepalette, speechpalette, languagepalette) {
  2. // Manipulate the DOM only when it is ready.
  3. requirejs(['domReady!'], function (doc) {
  4. // Initialize the activity.
  5. activity.setup();
  6. var datastoreObject = activity.getDatastoreObject();
  7. var faceButton = document.getElementById("face-button");
  8. var faceButtonPalette = new facepalette.ActivityPalette(
  9. faceButton, datastoreObject);
  10. var speechButton = document.getElementById("speech-button");
  11. var speechButtonPalette = new speechpalette.ActivityPalette(
  12. speechButton, datastoreObject);
  13. var languageButton = document.getElementById("language-button");
  14. var languagePalette = new languagepalette.ActivityPalette(
  15. languageButton, datastoreObject);
  16. //Loads talk history when instance is existing
  17. activity.getDatastoreObject().loadAsText(function(error, metadata, data) {
  18. if (error==null && data!=null) {
  19. speakArray = JSON.parse(data);
  20. removeExtra(speakArray); // Removes extra element and organizes list.
  21. speakComboBox();
  22. //console.log(speakArray);
  23. }
  24. });
  25. // Saves talk history in Journal on Stop
  26. document.getElementById("stop-button").addEventListener('click', function (event) {
  27. console.log("writing...");
  28. var jsonData = JSON.stringify(speakArray);
  29. console.log(jsonData);
  30. activity.getDatastoreObject().setDataAsText(jsonData);
  31. activity.getDatastoreObject().save(function (error) {
  32. if (error === null) {
  33. console.log("write done.");
  34. } else {
  35. console.log("write failed.");
  36. }
  37. });
  38. });
  39. // Function that creates options for select tag. Value of options is equal to saved talk.
  40. function speakComboBox() {
  41. for (var i = 0; i < speakArray.length; i ++) {
  42. var addUserInput = document.createElement("OPTION");
  43. addUserInput.setAttribute("value", speakArray[i]);
  44. addUserInput.text = speakArray[i];
  45. document.getElementById("combo-box").appendChild(addUserInput);
  46. }
  47. }
  48. //Function that removes extra elements in the select tag.
  49. function removeExtra(element) {
  50. element.sort();
  51. for (var x = element.length-1; x--;) {
  52. if (element[x] === element[x + 1]) {
  53. element.splice(x, 1);
  54. }
  55. }
  56. }
  57. });
  58. });