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.

62 lines
2.0 KiB

  1. define(["sugar-web/activity/activity", "sugar-web/datastore", "sugar-web/env"], function (activity, datastore, env) {
  2. // Manipulate the DOM only when it is ready.
  3. requirejs(['domReady!'], function (doc) {
  4. // Initialize the activity.
  5. activity.setup();
  6. // HACK: Clone stop button to remove default stop handling
  7. var oldStopButton = document.getElementById("stop-button");
  8. var stopButton = oldStopButton.cloneNode(true);
  9. document.getElementById("main-toolbar").replaceChild(stopButton, oldStopButton);
  10. // Handle Stop click
  11. stopButton.addEventListener('click', function (event) {
  12. document.getElementById("myBlocks").addEventListener('click', function (event) {
  13. console.log("writing...");
  14. var data = document.getElementById("myBlocks").value;
  15. activity.getDatastoreObject().setDataAsText(data);
  16. activity.getDatastoreObject().save(function (error) {
  17. if (error === null) {
  18. console.log("write done.");
  19. } else {
  20. console.log("write failed.");
  21. }
  22. window.onbeforeunload = null;
  23. activity.close();
  24. });
  25. });
  26. var found = false;
  27. for (var i = 0; i < document.body.getElementsByTagName("span").length; i++){
  28. var spanElement = document.getElementsByTagName("span")[i];
  29. if (spanElement.innerHTML == "Save to Sugarizer"){
  30. spanElement.click();
  31. found = true;
  32. break;
  33. }
  34. }
  35. console.log(found?"Call saved successfully":"Unable to save");
  36. });
  37. env.getEnvironment(function(err, environment) {
  38. if (environment.objectId) {
  39. activity.getDatastoreObject().loadAsText(function(error, metadata, data){
  40. if (error==null && data!=null){
  41. var found = false;
  42. for (var i = 0; i < document.body.getElementsByTagName("span").length; i++){
  43. var spanElement = document.getElementsByTagName("span")[i];
  44. if (spanElement.innerHTML == "Load from Sugarizer"){
  45. document.getElementById("myBlocks").value = data;
  46. found = true;
  47. break;
  48. }
  49. }
  50. console.log(found?"Loaded successfully":"Unable to load");
  51. }
  52. });
  53. }
  54. });
  55. });
  56. });