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.

227 lines
6.4 KiB

  1. // Library dialog
  2. enyo.kind({
  3. name: "VideoViewer.LibraryDialog",
  4. kind: enyo.Popup,
  5. classes: "library-dialog",
  6. centered: false,
  7. modal: false,
  8. floating: true,
  9. components: [
  10. {name: "scroller", kind: "Scroller", components: [
  11. {name: "items", classes: "library-content", kind: "Repeater", onSetupItem: "setupItem", components: [
  12. { classes: "library", components: [
  13. { name: "itemImage", classes: "libraryImage", kind: "Image", onerror: "defaultImage", ontap: "selectLibrary" },
  14. { name: "itemOverlay", classes: "libraryOverlay", ontap: "selectLibrary" },
  15. { name: "itemTitle", classes: "libraryTitle", content: "", ontap: "selectLibrary" },
  16. { name: "itemIcon", classes: "libraryIcon", kind: "Image", src: "icons/library.svg", ontap: "selectLibrary" },
  17. { name: "itemRemove", classes: "libraryRemove", kind: "Image", src: "icons/list-remove.svg", ontap: "removeLibrary" }
  18. ]}
  19. ]},
  20. ]},
  21. { name: "itemAdd", classes: "libraryAdd", kind: "Image", src: "icons/list-add.svg", ontap: "addLibrary" }
  22. ],
  23. // Constructor
  24. create: function() {
  25. this.inherited(arguments);
  26. },
  27. render: function() {
  28. this.inherited(arguments);
  29. this.draw();
  30. },
  31. draw: function() {
  32. this.$.items.applyStyle("height", document.getElementById(app.$.content.id).style.height);
  33. this.$.items.setCount(Util.context.libraries.length);
  34. },
  35. reload: function() {
  36. this.$.items.setCount(Util.context.libraries.length);
  37. },
  38. // Init setup for a line
  39. setupItem: function(inSender, inEvent) {
  40. var imgurl = Util.context.libraries[inEvent.index].image;
  41. if (imgurl.startsWith("http://", 0) && typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
  42. // HACK: When in Chrome App image should be load using a XmlHttpRequest
  43. var xhr = new XMLHttpRequest();
  44. var that = inEvent.item;
  45. xhr.open('GET', imgurl, true);
  46. xhr.responseType = 'blob';
  47. xhr.onload = function(e) {
  48. that.$.itemImage.setAttribute("src", window.URL.createObjectURL(this.response));
  49. };
  50. xhr.send();
  51. } else {
  52. inEvent.item.$.itemImage.setAttribute("src", imgurl);
  53. }
  54. inEvent.item.$.itemTitle.setContent(Util.context.libraries[inEvent.index].title);
  55. },
  56. // Process events
  57. closeDialog: function() {
  58. this.hide();
  59. },
  60. defaultImage: function(inSender, inEvent) {
  61. inEvent.dispatchTarget.setAttribute("src", "images/nolibrary.png");
  62. },
  63. selectLibrary: function(inSender, inEvent) {
  64. Util.setLibrary(Util.context.libraries[inEvent.index]);
  65. Util.saveContext();
  66. app.loadDatabase();
  67. this.closeDialog();
  68. },
  69. removeLibrary: function(inSender, inEvent) {
  70. Util.removeLibrary(Util.context.libraries[inEvent.index]);
  71. Util.saveContext();
  72. this.draw();
  73. },
  74. addLibrary: function() {
  75. app.$.addLibraryDialog.show();
  76. }
  77. });
  78. // Video dialog
  79. enyo.kind({
  80. name: "VideoViewer.VideoDialog",
  81. kind: enyo.Popup,
  82. classes: "video-dialog",
  83. centered: false,
  84. modal: true,
  85. floating: true,
  86. published: {
  87. item: null
  88. },
  89. components: [
  90. {name: "header", classes: "video-header toolbar", components: [
  91. {name: "favoritebutton", kind: "Button", classes: "toolbutton video-favorite-button pull-left", title: "Favorite", ontap: "setFavorite"},
  92. {name: "title", classes: "video-title", content: ""},
  93. {name: "closebutton", kind: "Button", classes: "toolbutton video-close-button pull-right", title: "Close", ontap: "closeDialog"}
  94. ]},
  95. {name: "video", classes: "video-item", kind: "enyo.Video", fitToWindow: false, autoplay: true, showControls: true, poster: "images/notloaded.png"},
  96. ],
  97. // Constructor
  98. create: function() {
  99. this.inherited(arguments);
  100. this.itemChanged();
  101. },
  102. rendered: function() {
  103. if (this.item != null) {
  104. this.$.favoritebutton.applyStyle("background-image", "url(icons/"+(!this.item.isFavorite?"not":"")+"favorite.svg)");
  105. if (!this.init) {
  106. this.init = true;
  107. var time = Util.getReadTime(this.item.code);
  108. if (time)
  109. this.$.video.setCurrentTime(time);
  110. }
  111. }
  112. },
  113. itemChanged: function() {
  114. this.init = false;
  115. if (this.item != null) {
  116. this.$.title.setContent(this.item.title);
  117. this.$.video.setSrc(this.item.videoURL());
  118. this.render();
  119. }
  120. },
  121. // Process events
  122. closeDialog: function() {
  123. this.$.video.pause();
  124. Util.setReadTime(this.item.code, this.$.video.getCurrentTime());
  125. this.$.video.unload();
  126. this.item = null;
  127. Util.saveContext();
  128. this.hide();
  129. if (Util.onSugar()) {
  130. // HACK: Force refresh screen on Sugar to avoid video issue
  131. Util.sugar.sendMessage("refresh-screen", Util.context);
  132. }
  133. },
  134. setFavorite: function() {
  135. this.item.setIsFavorite(!this.item.isFavorite);
  136. Util.setFavorite(this.item.code, this.item.isFavorite);
  137. this.rendered();
  138. }
  139. });
  140. // Add library dialog
  141. enyo.kind({
  142. name: "VideoViewer.AddLibraryDialog",
  143. kind: "enyo.Popup",
  144. classes: "module-dialog",
  145. centered: true,
  146. modal: true,
  147. floating: true,
  148. autoDismiss: false,
  149. components: [
  150. {name: "toolbar", classes: "toolbar", components: [
  151. {name: "icon", classes: "module-icon"},
  152. {name: "text", content: "Add library", classes: "module-text"},
  153. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  154. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  155. ]},
  156. {content: "Library description URL:", classes: "server-message"},
  157. {name: "content", classes: "server-content", components: [
  158. {content: "http://", classes: "server-httplabel"},
  159. {name: "servername", kind: "Input", classes: "server-servername", onkeydown: "enterclick"}
  160. ]}
  161. ],
  162. // Constructor
  163. create: function() {
  164. this.inherited(arguments);
  165. this.init();
  166. },
  167. init: function() {
  168. },
  169. rendered: function() {
  170. },
  171. // Event handling
  172. cancel: function() {
  173. this.hide();
  174. },
  175. ok: function() {
  176. this.hide();
  177. var ajax = new enyo.Ajax({
  178. url: "http://"+this.$.servername.getValue(),
  179. method: "GET",
  180. handleAs: "json"
  181. });
  182. var that = this;
  183. ajax.response(function(inSender, inResponse) {
  184. if (!inResponse.name || !inResponse.image || !inResponse.title || !inResponse.database || !inResponse.images) {
  185. console.log("Incorrect format for library 'http://"+that.$.servername.getValue()+"'");
  186. return;
  187. }
  188. Util.addLibrary(inResponse);
  189. Util.saveContext();
  190. app.$.libraryDialog.draw();
  191. });
  192. ajax.error(function() {
  193. console.log("Unable to load 'http://"+that.$.servername.getValue()+"'");
  194. });
  195. ajax.go();
  196. },
  197. enterclick: function(inSender, inEvent) {
  198. if (inEvent.keyCode === 13) {
  199. this.ok();
  200. return true;
  201. }
  202. }
  203. });