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.

196 lines
5.6 KiB

  1. 
  2. // Main app class
  3. enyo.kind({
  4. name: "VideoViewer.App",
  5. kind: "FittableRows",
  6. published: {
  7. activity: null,
  8. filter: null
  9. },
  10. components: [
  11. {name: "spinner", kind: "Image", src: "images/spinner-light.gif", classes: "mainspinner", showing: false },
  12. {name: "cloudwarning", kind: "Image", src: "images/cloud-warning.svg", classes: "cloudwarning", showing: false },
  13. {name: "content", kind: "Scroller", fit: true, classes: "main-content", onresize: "resize",
  14. components: [
  15. {name: "items", classes: "items", components: [
  16. ]}
  17. ]},
  18. {name: "footer", classes: "viewer-footer toolbar", fit: false, components: [
  19. {name: "previousbutton", kind: "Button", classes: "toolbutton previous-button pull-left", title:"Previous", ontap: "showPrevious", showing: false},
  20. {name: "pagecount", content: "0/0", classes: "page-count"},
  21. {name: "nextbutton", kind: "Button", classes: "toolbutton next-button pull-right", title:"Next", ontap: "showNext", showing: false}
  22. ]},
  23. {name: "libraryDialog", kind: "VideoViewer.LibraryDialog", onHide: "librariesHidden"},
  24. {name: "addLibraryDialog", kind: "VideoViewer.AddLibraryDialog"},
  25. {name: "videoDialog", kind: "VideoViewer.VideoDialog"}
  26. ],
  27. // Constructor
  28. create: function() {
  29. app = this;
  30. this.inherited(arguments);
  31. this.collection = [];
  32. this.index = 0;
  33. this.computeSize();
  34. this.favorite = false;
  35. document.getElementById("exportvideo-button").addEventListener("click", enyo.bind(this, "clickExportVideo"));
  36. var that = this;
  37. requirejs(["sugar-web/env","sugar-web/datastore"], function(env,datastore) {
  38. env.getEnvironment(function(err, environment) {
  39. that.$.content.applyStyle("background-color", environment.user.colorvalue.fill);
  40. that.datastore = datastore;
  41. });
  42. });
  43. },
  44. loadLibraries: function() {
  45. var that = this;
  46. Util.loadLibraries(
  47. function() {
  48. app.showLibraries();
  49. },
  50. function(sender) {
  51. that.$.spinner.setShowing(false);
  52. that.$.cloudwarning.setShowing(true);
  53. console.log("Error loading library on '"+sender.url+"'");
  54. }
  55. );
  56. },
  57. loadDatabase: function() {
  58. var that = this;
  59. this.$.spinner.setShowing(true);
  60. Util.loadDatabase(function(response) {
  61. that.index = 0;
  62. that.collection = response;
  63. that.$.spinner.setShowing(false);
  64. that.$.cloudwarning.setShowing(false);
  65. that.draw();
  66. }, function(sender) {
  67. that.$.spinner.setShowing(false);
  68. that.$.cloudwarning.setShowing(true);
  69. console.log("Error loading database on '"+sender.url+"'");
  70. });
  71. },
  72. computeSize: function() {
  73. var toolbar = document.getElementById("main-toolbar");
  74. var toolbaroffset = !Util.onSugar() ? toolbar.offsetHeight : 37.5;
  75. var canvas = document.getElementById("body");
  76. var canvas_height = canvas.offsetHeight;
  77. this.$.content.applyStyle("height", (canvas_height-(toolbaroffset*2))+"px");
  78. },
  79. resize: function() {
  80. if (!Util.onSugar()) {
  81. this.computeSize();
  82. this.draw();
  83. }
  84. },
  85. // Draw screen
  86. draw: function() {
  87. // Remove items
  88. var items = [];
  89. enyo.forEach(this.$.items.getControls(), function(item) { items.push(item); });
  90. for (var i = 0 ; i < items.length ; i++) { items[i].destroy(); }
  91. // Display items
  92. var collection = this.collection;
  93. var len = collection.length;
  94. var exportButton = document.getElementById("exportvideo-button");
  95. for(var i = 0 ; i < constant.pageCount && this.index+i < len ; i++ ) {
  96. this.$.items.createComponent(
  97. {
  98. kind: "VideoViewer.Item",
  99. code: collection[this.index+i].id,
  100. title: collection[this.index+i].title,
  101. category: collection[this.index+i].category,
  102. isFavorite: Util.getFavorite(collection[this.index+i].id),
  103. image: collection[this.index+i].image,
  104. onVideoPlayed: "showVideo",
  105. tojournal: exportButton.classList.contains("active")
  106. },
  107. { owner: this }
  108. ).render();
  109. }
  110. // Display button
  111. this.$.previousbutton.setShowing(this.index-constant.pageCount >= 0);
  112. var currentPage = (len?1:0)+Math.ceil(this.index/constant.pageCount);
  113. var lastPage = Math.ceil(len/constant.pageCount);
  114. this.$.pagecount.setContent(currentPage+"/"+lastPage);
  115. this.$.nextbutton.setShowing(currentPage < lastPage);
  116. },
  117. putItemsJournalModeTo: function(tojournal) {
  118. if (tojournal) {
  119. document.getElementById("exportvideo-button").classList.add("active");
  120. } else {
  121. document.getElementById("exportvideo-button").classList.remove("active");
  122. }
  123. enyo.forEach(this.$.items.getControls(), function(item) {
  124. item.tojournal = tojournal;
  125. item.tojournalChanged();
  126. });
  127. },
  128. // Page event
  129. showPrevious: function() {
  130. this.index -= constant.pageCount;
  131. this.saveContext();
  132. this.draw();
  133. },
  134. showNext: function() {
  135. this.index += constant.pageCount;
  136. this.saveContext();
  137. this.draw();
  138. },
  139. showVideo: function(item) {
  140. if (item.tojournal) {
  141. this.putItemsJournalModeTo(false);
  142. return;
  143. }
  144. this.$.videoDialog.show();
  145. this.$.videoDialog.setItem(item);
  146. },
  147. showLibraries: function() {
  148. this.$.libraryDialog.reload();
  149. this.$.libraryDialog.show();
  150. },
  151. hideLibraries: function() {
  152. this.$.libraryDialog.hide();
  153. },
  154. librariesHidden: function() {
  155. if (Util.getLibrary() == null)
  156. this.showLibraries();
  157. },
  158. setFilter: function(filter) {
  159. Util.setFilter(filter);
  160. },
  161. filterChanged: function(index) {
  162. this.collection = Util.getCollection();
  163. this.index = (index !== undefined ? index : 0);
  164. this.saveContext();
  165. this.draw();
  166. },
  167. clickExportVideo: function() {
  168. var exportButton = document.getElementById("exportvideo-button");
  169. var tojournal;
  170. tojournal = !exportButton.classList.contains("active");
  171. this.putItemsJournalModeTo(tojournal);
  172. },
  173. saveContext: function() {
  174. Util.setIndex(this.index);
  175. Util.saveContext();
  176. }
  177. });