operationprogressbar.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2018
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. (function() {
  11. var OperationProgressBar = OC.Backbone.View.extend({
  12. tagName: 'div',
  13. id: 'uploadprogresswrapper',
  14. events: {
  15. 'click button.stop': '_onClickCancel'
  16. },
  17. render: function() {
  18. this.$el.html(OCA.Files.Templates['operationprogressbar']({
  19. textCancelButton: t('Cancel operation')
  20. }));
  21. this.setProgressBarText(t('Uploading …'), t('…'));
  22. },
  23. hideProgressBar: function() {
  24. var self = this;
  25. $('#uploadprogresswrapper .stop').fadeOut();
  26. $('#uploadprogressbar').fadeOut(function() {
  27. self.$el.trigger(new $.Event('resized'));
  28. });
  29. this.setProgressBarText('', '');
  30. },
  31. hideCancelButton: function() {
  32. var self = this;
  33. $('#uploadprogresswrapper .stop').fadeOut(function() {
  34. self.$el.trigger(new $.Event('resized'));
  35. });
  36. },
  37. showProgressBar: function(showCancelButton) {
  38. if (showCancelButton) {
  39. showCancelButton = true;
  40. }
  41. $('#uploadprogressbar').progressbar({value: 0});
  42. if(showCancelButton) {
  43. $('#uploadprogresswrapper .stop').show();
  44. } else {
  45. $('#uploadprogresswrapper .stop').hide();
  46. }
  47. $('#uploadprogresswrapper .label').show();
  48. $('#uploadprogressbar').fadeIn();
  49. this.$el.trigger(new $.Event('resized'));
  50. },
  51. setProgressBarValue: function(value) {
  52. $('#uploadprogressbar').progressbar({value: value});
  53. },
  54. setProgressBarText: function(textDesktop, textMobile, title) {
  55. var labelHtml = OCA.Files.Templates['operationprogressbarlabel']({textDesktop: textDesktop, textMobile: textMobile});
  56. $('#uploadprogressbar .ui-progressbar-value').html(labelHtml);
  57. $('#uploadprogressbar .ui-progressbar-value>em').addClass('inner');
  58. $('#uploadprogressbar>em').replaceWith(labelHtml);
  59. $('#uploadprogressbar>em').addClass('outer');
  60. if (title) {
  61. $('#uploadprogressbar').attr('title', title);
  62. $('#uploadprogresswrapper .tooltip-inner').text(title);
  63. }
  64. if(textDesktop || textMobile) {
  65. $('#uploadprogresswrapper .stop').show();
  66. }
  67. },
  68. _onClickCancel: function (event) {
  69. this.trigger('cancel');
  70. return false;
  71. }
  72. });
  73. OCA.Files.OperationProgressBar = OperationProgressBar;
  74. })(OC, OCA);