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.
 
 
 

49 lines
949 B

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'html!ui/templates/progressBar/template',
  5. 'html!ui/templates/progressBar/templateBar',
  6. 'css!ui/templates/progressBar/styles'
  7. ], function (
  8. events,
  9. client,
  10. tpl,
  11. tplBar,
  12. styles
  13. ) {
  14. return {
  15. tpl: tpl,
  16. bars: [],
  17. postRender: function () {
  18. this.onEvent('onShowProgress', this.onShowProgress.bind(this));
  19. },
  20. onShowProgress: function (text, percentage) {
  21. let bar = this.bars.find(function (b) {
  22. return (b.text == text);
  23. });
  24. if (bar) {
  25. if (percentage >= 100) {
  26. bar.el.remove();
  27. this.bars.spliceWhere(function (b) {
  28. return (b == bar);
  29. });
  30. } else
  31. bar.el.find('.bar').css('width', percentage + '%');
  32. } else if (percentage < 100) {
  33. bar = $(tplBar).appendTo(this.el);
  34. bar.find('.bar').css('width', percentage + '%');
  35. bar.find('.text').html(text);
  36. this.bars.push({
  37. text: text,
  38. el: bar
  39. });
  40. }
  41. }
  42. };
  43. });