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.

95 lines
2.6 KiB

  1. 
  2. // Main app class
  3. enyo.kind({
  4. name: "TamTam.App",
  5. kind: "FittableRows",
  6. published: {activity: null},
  7. components: [
  8. {name: "content", kind: "Scroller", fit: true, classes: "maincontent", onresize: "resize",
  9. components: [
  10. {name: "collections", classes: "collections", components: [
  11. ]},
  12. {name: "items", classes: "items", components: [
  13. ]}
  14. ]}
  15. ],
  16. // Constructor
  17. create: function() {
  18. this.inherited(arguments);
  19. this.collection = 0;
  20. this.computeSize();
  21. var that = this;
  22. requirejs(["sugar-web/env"], function(env) {
  23. env.getEnvironment(function(err, environment) {
  24. that.userColor = environment.user.colorvalue;
  25. that.draw();
  26. });
  27. });
  28. },
  29. computeSize: function() {
  30. var toolbar = document.getElementById("main-toolbar");
  31. var canvas = document.getElementById("body");
  32. var canvas_height = canvas.offsetHeight;
  33. this.$.content.applyStyle("height", (canvas_height-toolbar.offsetHeight)+"px");
  34. },
  35. resize: function() {
  36. this.computeSize();
  37. this.draw();
  38. },
  39. // Draw screen
  40. draw: function() {
  41. // Remove collections
  42. var items = [];
  43. enyo.forEach(this.$.collections.getControls(), function(item) { items.push(item); });
  44. for (var i = 0 ; i < items.length ; i++) { items[i].destroy(); }
  45. // Display collections
  46. document.getElementById("body").style.backgroundColor = this.userColor.fill;
  47. this.$.collections.applyStyle("background-color", this.userColor.fill);
  48. var len = TamTam.collections.length;
  49. for(var i = 0 ; i < len ; i++ ) {
  50. this.$.collections.createComponent(
  51. { kind: "TamTam.Collection", name: TamTam.collections[i].name, selection: (i == this.collection), ontap: "changeCollection" },
  52. { owner: this }
  53. ).render();
  54. }
  55. // Remove items
  56. var items = [];
  57. this.$.items.applyStyle("background-color", this.userColor.fill);
  58. enyo.forEach(this.$.items.getControls(), function(item) { items.push(item); });
  59. for (var i = 0 ; i < items.length ; i++) { items[i].destroy(); }
  60. // Display items
  61. var collection = TamTam.collections[this.collection];
  62. var len = collection.content.length;
  63. for(var i = 0 ; i < len ; i++ ) {
  64. var item = this.$.items.createComponent(
  65. { kind: "TamTam.Item", name: collection.content[i] },
  66. { owner: this }
  67. );
  68. item.applyStyle("background-color", this.userColor.stroke);
  69. item.render();
  70. }
  71. },
  72. // Handle event
  73. changeCollection: function(s, e) {
  74. // Stop sound
  75. sound.pause();
  76. // Select the collection
  77. var len = TamTam.collections.length;
  78. for(var i = 0 ; i < len ; i++) {
  79. if (TamTam.collections[i].name == s.name) {
  80. this.collection = i;
  81. this.draw();
  82. return;
  83. }
  84. }
  85. }
  86. });