operationprogressbar.js 2.2 KB

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