operationprogressbar.js 2.3 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. },
  30. hideCancelButton: function() {
  31. var self = this;
  32. $('#uploadprogresswrapper .stop').fadeOut(function() {
  33. self.$el.trigger(new $.Event('resized'));
  34. });
  35. },
  36. showProgressBar: function(showCancelButton) {
  37. if (showCancelButton) {
  38. showCancelButton = true;
  39. }
  40. $('#uploadprogressbar').progressbar({value: 0});
  41. if(showCancelButton) {
  42. $('#uploadprogresswrapper .stop').show();
  43. } else {
  44. $('#uploadprogresswrapper .stop').hide();
  45. }
  46. $('#uploadprogresswrapper .label').show();
  47. $('#uploadprogressbar').fadeIn();
  48. this.$el.trigger(new $.Event('resized'));
  49. },
  50. setProgressBarValue: function(value) {
  51. $('#uploadprogressbar').progressbar({value: value});
  52. },
  53. setProgressBarText: function(textDesktop, textMobile, title) {
  54. var labelHtml = OCA.Files.Templates['operationprogressbarlabel']({textDesktop: textDesktop, textMobile: textMobile});
  55. $('#uploadprogressbar .ui-progressbar-value').html(labelHtml);
  56. $('#uploadprogressbar .ui-progressbar-value>em').addClass('inner');
  57. $('#uploadprogressbar>em').replaceWith(labelHtml);
  58. $('#uploadprogressbar>em').addClass('outer');
  59. $('#uploadprogressbar').tooltip({placement: 'bottom', container: '#uploadprogresswrapper'});
  60. if (title) {
  61. $('#uploadprogressbar').attr('data-original-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);