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.

215 lines
6.2 KiB

  1. // Popup menu of the activity
  2. enyo.kind({
  3. name: "Sugar.Popup",
  4. kind: "enyo.Control",
  5. classes: "home-activity-popup",
  6. published: { margin: null, header: null, items: null, footer: null },
  7. components: [
  8. {name: "popuptitle", classes: "popup-title", ontap: "runHeaderAction", components: [
  9. {name: "icon", showing: false, kind: "Sugar.Icon", x: 5, y: 5, size: constant.iconSizeList},
  10. {name: "name", classes: "popup-name-text"},
  11. {name: "title", classes: "popup-title-text"},
  12. ]},
  13. {name: "items", classes: "popup-items", showing: false, components: [
  14. {name: "itemslist", kind: "Sugar.DesktopPopupListView"}
  15. ]},
  16. {name: "footer", classes: "popup-items", showing: false, components: [
  17. {name: "footerlist", kind: "Sugar.DesktopPopupListView"}
  18. ]}
  19. ],
  20. // Constructor
  21. create: function() {
  22. this.inherited(arguments);
  23. this.marginChanged();
  24. this.headerChanged();
  25. this.itemsChanged();
  26. this.footerChanged();
  27. this.timer = null;
  28. if (l10n.language.direction == "rtl") {
  29. this.$.popuptitle.setAttribute("dir", "rtl");
  30. }
  31. },
  32. // Property changed
  33. marginChanged: function() {
  34. if (this.margin == null) {
  35. this.margin = { left: constant.popupMarginLeft, top: constant.popupMarginTop };
  36. }
  37. this.applyStyle("left", (mouse.position.x+this.margin.left)+"px");
  38. this.applyStyle("top", (mouse.position.y+this.margin.top)+"px");
  39. },
  40. headerChanged: function() {
  41. if (this.header != null) {
  42. this.$.icon.setShowing(this.header.icon != null);
  43. if (this.header.icon != null) {
  44. this.$.icon.setIcon(this.header.icon);
  45. this.$.icon.setColorized(this.header.colorized);
  46. if (this.header.colorizedColor) {
  47. this.$.icon.setColorizedColor(this.header.colorizedColor);
  48. } else {
  49. this.$.icon.setColorizedColor(null);
  50. }
  51. this.$.icon.render();
  52. }
  53. this.$.name.setContent(this.header.name);
  54. if (l10n.language.direction == "rtl") {
  55. this.$.name.addClass("rtl-10");
  56. }
  57. if (this.header.title != null) {
  58. this.$.name.removeClass("popup-name-text-bottom");
  59. this.$.title.setContent(this.header.title);
  60. } else {
  61. this.$.title.setContent("");
  62. this.$.name.addClass("popup-name-text-bottom");
  63. }
  64. }
  65. },
  66. itemsChanged: function() {
  67. if (this.items != null) {
  68. this.$.itemslist.setItems(this.items);
  69. }
  70. },
  71. footerChanged: function() {
  72. if (this.footer != null) {
  73. this.$.footerlist.setItems(this.footer);
  74. }
  75. },
  76. // Control popup visibility
  77. showPopup: function() {
  78. if (this.margin == null) {
  79. this.margin = { left: constant.popupMarginLeft, top: constant.popupMarginTop };
  80. }
  81. var popupSize = 56;
  82. popupSize += ((this.footer == null || this.footer.length == 0) ? 0 : 53);
  83. popupSize += (this.items == null ? 0 : 42 * this.items.length);
  84. var delta = mouse.position.y + this.margin.top + popupSize - document.getElementById("canvas").offsetHeight;
  85. this.overflow = false;
  86. if (delta > 0 && (!this.container.hasNode() || !this.container.hasNode().style.overflowY)) {
  87. // Popup will overflow window, prepare to shift menu
  88. this.overflow = true;
  89. }
  90. this.setStyle("bottom", "");
  91. this.applyStyle("top", (mouse.position.y+this.margin.top)+"px");
  92. this.applyStyle("left", (mouse.position.x+this.margin.left)+"px");
  93. this.show();
  94. this.timer = window.setInterval(enyo.bind(this, "showContent"), constant.timerPopupDuration);
  95. },
  96. hidePopup: function() {
  97. this.hide();
  98. this.$.items.hide();
  99. this.$.itemslist.setItems(null);
  100. this.$.footer.hide();
  101. this.$.footerlist.setItems(null);
  102. },
  103. showContent: function() {
  104. window.clearInterval(this.timer);
  105. if (this.overflow) {
  106. this.setStyle("top", "");
  107. this.applyStyle("bottom", "0px");
  108. this.applyStyle("left", (mouse.position.x+this.margin.left)+"px");
  109. }
  110. this.timer = null;
  111. if (this.$.items && this.showing) {
  112. if (this.items != null && this.items.length > 0) {
  113. this.$.items.show();
  114. }
  115. if (this.footer != null && this.footer.length > 0) {
  116. this.$.footer.show();
  117. }
  118. }
  119. },
  120. // Click on the header icon, launch action
  121. runHeaderAction: function(s, e) {
  122. if (this.header.action != null) {
  123. this.header.action.apply(this, this.header.data);
  124. return true;
  125. }
  126. },
  127. // Test is cursor is inside the popup
  128. cursorIsInside: function() {
  129. return util.cursorIsInside(this);
  130. }
  131. });
  132. // Items popup ListView
  133. enyo.kind({
  134. name: "Sugar.DesktopPopupListView",
  135. kind: enyo.Scroller,
  136. published: { items: null },
  137. classes: "popup-item-listview",
  138. components: [
  139. {name: "itemList", classes: "item-list", kind: "Repeater", onSetupItem: "setupItem", components: [
  140. {name: "item", classes: "item-list-item", ontap: "runItemAction", components: [
  141. {name: "icon", kind: "Sugar.Icon", x: 5, y: 4, size: constant.iconSizeFavorite},
  142. {name: "name", classes: "item-name"}
  143. ]}
  144. ]}
  145. ],
  146. // Constructor: init list
  147. create: function() {
  148. this.inherited(arguments);
  149. this.itemsChanged();
  150. },
  151. // Items changed
  152. itemsChanged: function() {
  153. if (this.items != null) {
  154. this.$.itemList.set("count", this.items.length, true);
  155. } else {
  156. this.$.itemList.set("count", 0, true);
  157. }
  158. },
  159. // Init setup for a line
  160. setupItem: function(inSender, inEvent) {
  161. // Set item in the template
  162. inEvent.item.$.icon.setIcon(this.items[inEvent.index].icon);
  163. inEvent.item.$.name.setContent(this.items[inEvent.index].name);
  164. inEvent.item.$.icon.setColorized(this.items[inEvent.index].colorized);
  165. if (this.items[inEvent.index].colorizedColor) {
  166. inEvent.item.$.icon.setColorizedColor(this.items[inEvent.index].colorizedColor);
  167. } else {
  168. inEvent.item.$.icon.setColorizedColor(null);
  169. }
  170. if (this.items[inEvent.index].disable) {
  171. inEvent.item.$.name.addRemoveClass('item-name-disable', true);
  172. inEvent.item.$.name.addRemoveClass('item-name-enable', false);
  173. } else {
  174. inEvent.item.$.name.addRemoveClass('item-name-disable', false);
  175. inEvent.item.$.name.addRemoveClass('item-name-enable', true);
  176. }
  177. if (l10n.language.direction == "rtl") {
  178. inEvent.item.$.name.addClass("rtl-10");
  179. inEvent.item.$.item.setAttribute("dir", "rtl");
  180. }
  181. },
  182. // Run action on item
  183. runItemAction: function(inSender, inEvent) {
  184. // Nothing to do if item is disable
  185. if (this.items[inEvent.index].disable) {
  186. return;
  187. }
  188. // Get action and run it if it exist
  189. var action = this.items[inEvent.index].action;
  190. if (action != null) {
  191. action.apply(this, this.items[inEvent.index].data);
  192. }
  193. }
  194. });