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.
 
 
 

113 lines
2.2 KiB

  1. define([
  2. 'js/system/client',
  3. 'js/system/events',
  4. 'html!ui/templates/events/template',
  5. 'html!ui/templates/events/templateEvent',
  6. 'css!ui/templates/events/styles'
  7. ], function (
  8. client,
  9. events,
  10. tpl,
  11. templateEvent,
  12. styles
  13. ) {
  14. return {
  15. tpl: tpl,
  16. list: [],
  17. container: '.right',
  18. postRender: function () {
  19. this.onEvent('onRezone', this.onRezone.bind(this));
  20. this.onEvent('onObtainEvent', this.onObtainEvent.bind(this));
  21. this.onEvent('onRemoveEvent', this.onRemoveEvent.bind(this));
  22. this.onEvent('onUpdateEvent', this.onUpdateEvent.bind(this));
  23. this.onEvent('onCompleteEvent', this.onCompleteEvent.bind(this));
  24. },
  25. onRezone: function () {
  26. this.list = [];
  27. this.el.find('.list').empty();
  28. },
  29. onRemoveEvent: function (id) {
  30. let l = this.list.spliceFirstWhere(function (l) {
  31. return (l.id == id);
  32. });
  33. if (l)
  34. l.el.remove();
  35. },
  36. onObtainEvent: function (event) {
  37. let exists = this.list.find(function (l) {
  38. return (l.id == event.id);
  39. });
  40. if (exists) {
  41. exists.el.find('.name').html(event.name);
  42. exists.el.find('.description').html(event.description);
  43. return;
  44. }
  45. let container = this.el.find('.list');
  46. let html = templateEvent
  47. .replace('$NAME$', event.name)
  48. .replace('$DESCRIPTION$', event.description);
  49. let el = $(html).appendTo(container);
  50. if (event.isReady)
  51. el.addClass('ready');
  52. this.list.push({
  53. id: event.id,
  54. el: el,
  55. event: event
  56. });
  57. var event = container.find('.event');
  58. event
  59. .sort(function (a, b) {
  60. a = $(a).hasClass('active') ? 1 : 0;
  61. b = $(b).hasClass('active') ? 1 : 0;
  62. return b - a;
  63. })
  64. .appendTo(container);
  65. },
  66. onUpdateEvent: function (event) {
  67. let e = this.list.find(function (l) {
  68. return (l.id == event.id);
  69. });
  70. e.event.isReady = event.isReady;
  71. e.el.find('.description').html(event.description);
  72. e.el.removeClass('ready');
  73. if (event.isReady) {
  74. e.el.removeClass('disabled');
  75. e.el.addClass('ready');
  76. }
  77. },
  78. onCompleteEvent: function (id) {
  79. let e = this.list.find(function (l) {
  80. return (l.id == id);
  81. });
  82. if (!e)
  83. return;
  84. e.el.remove();
  85. this.list.spliceWhere(function (l) {
  86. return (l.id == id);
  87. });
  88. }
  89. };
  90. });