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.

88 lines
2.8 KiB

  1. define(["sugar-web/graphics/palette"], function (palette) {
  2. 'use strict';
  3. var presencepalette = {};
  4. presencepalette.PresencePalette = function (invoker, primaryText, menuData) {
  5. palette.Palette.call(this, invoker, primaryText);
  6. this.sharedEvent = document.createEvent("CustomEvent");
  7. this.sharedEvent.initCustomEvent('shared', true, true, {});
  8. var div = document.createElement('div');
  9. var txt = document.createElement('span');
  10. txt.innerHTML = "Private";
  11. txt.className = 'network-text';
  12. var hr = document.createElement('hr');
  13. var privatebutton = document.createElement('button');
  14. privatebutton.className = 'toolbutton';
  15. privatebutton.setAttribute('id','private-button');
  16. privatebutton.onclick = function() {
  17. that.setShared(false);
  18. }
  19. var sharedbutton = document.createElement('button');
  20. sharedbutton.className = 'toolbutton';
  21. sharedbutton.setAttribute('id','shared-button');
  22. sharedbutton.onclick = function() {
  23. that.setShared(true);
  24. }
  25. this.setShared = function(state) {
  26. if (state) {
  27. txt.innerHTML = "My neighborhood";
  28. privatebutton.disabled = true;
  29. sharedbutton.disabled = true;
  30. invoker.style.backgroundImage = 'url(lib/sugar-web/graphics/icons/actions/zoom-neighborhood.svg)';
  31. that.getPalette().childNodes[0].style.backgroundImage = 'url(lib/sugar-web/graphics/icons/actions/zoom-neighborhood.svg)';
  32. that.getPalette().dispatchEvent(that.sharedEvent);
  33. } else {
  34. txt.innerHTML = "Private";
  35. privatebutton.disabled = false;
  36. sharedbutton.disabled = false;
  37. }
  38. }
  39. div.appendChild(txt);
  40. div.appendChild(hr);
  41. div.appendChild(privatebutton);
  42. div.appendChild(sharedbutton);
  43. var usersDiv = document.createElement('div');
  44. usersDiv.setAttribute("id", "presence-users");
  45. div.appendChild(usersDiv);
  46. this.setContent([div]);
  47. // Pop-down the palette when a item in the menu is clicked.
  48. this.buttons = div.querySelectorAll('button');
  49. var that = this;
  50. function popDownOnButtonClick(event) {
  51. that.popDown();
  52. }
  53. for (var i = 0; i < this.buttons.length; i++) {
  54. if (this.buttons[i].id == "shared-button")
  55. this.buttons[i].addEventListener('shared', popDownOnButtonClick);
  56. }
  57. };
  58. var addEventListener = function (type, listener, useCapture) {
  59. return this.getPalette().addEventListener(type, listener, useCapture);
  60. };
  61. presencepalette.PresencePalette.prototype =
  62. Object.create(palette.Palette.prototype, {
  63. addEventListener: {
  64. value: addEventListener,
  65. enumerable: true,
  66. configurable: true,
  67. writable: true
  68. }
  69. });
  70. presencepalette.PresencePalette.prototype.setShared = function(state) {
  71. this.setShared(state);
  72. }
  73. return presencepalette;
  74. });