delete-modal.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import Ember from 'ember';
  19. import OperationModal from '../mixins/operation-modal';
  20. export default Ember.Component.extend(OperationModal, {
  21. fileSelectionService: Ember.inject.service('files-selection'),
  22. fileOperationService: Ember.inject.service('file-operation'),
  23. logger: Ember.inject.service('alert-messages'),
  24. closeOnEscape: true,
  25. deletePermanently: false,
  26. deletePermanentlyAlways: false,
  27. showDeletePermanentCheckbox: true,
  28. selectedFiles: Ember.computed.alias('fileSelectionService.files'),
  29. filesCount: Ember.computed.oneWay('fileSelectionService.filesCount'),
  30. folderCount: Ember.computed.oneWay('fileSelectionService.folderCount'),
  31. hasFiles: Ember.computed('filesCount', function() {
  32. return this.get('filesCount') > 0;
  33. }),
  34. hasFolders: Ember.computed('folderCount', function() {
  35. return this.get('folderCount') > 0;
  36. }),
  37. hasError: false,
  38. shouldRetry: false,
  39. currentFailedPath: '',
  40. currentUnprocessedPaths: [],
  41. currentFailureMessage: '',
  42. currentServerFailureMessage: '',
  43. isDeleting: false,
  44. setTrashSettings: Ember.on('init', Ember.observer('currentPathIsTrash', function() {
  45. if(this.get('currentPathIsTrash')) {
  46. this.set('deletePermanentlyAlways', true);
  47. this.set('showDeletePermanentCheckbox', false);
  48. } else {
  49. this.set('deletePermanentlyAlways', false);
  50. this.set('showDeletePermanentCheckbox', true);
  51. }
  52. })),
  53. disableCloseOnEscape: Ember.observer('isDeleting', function() {
  54. if (this.get('isDeleting') === true) {
  55. this.set('closeOnEscape', false);
  56. } else {
  57. this.set('closeOnEscape', true);
  58. }
  59. }),
  60. deletePaths: function(paths) {
  61. this.set('isDeleting', true);
  62. let deletePermanently = this.get('deletePermanently');
  63. if(this.get('deletePermanentlyAlways')) {
  64. deletePermanently = true;
  65. }
  66. this.get('fileOperationService').deletePaths(paths, deletePermanently).then(
  67. (response) => {
  68. this.set('isDeleting', false);
  69. this.send('close');
  70. this.sendAction('refreshAction');
  71. }, (error) => {
  72. this.set('isDeleting', false);
  73. if (error.unprocessable === true) {
  74. this.set('hasError', true);
  75. this.set('currentFailedPath', error.failed);
  76. this.set('currentServerFailureMessage', error.message);
  77. this.set('currentFailureMessage', `Failed to delete <strong>${error.failed}</strong>.`);
  78. this.set('shouldRetry', error.retry);
  79. this.set('currentUnprocessedPaths', error.unprocessed);
  80. } else {
  81. this.set('isDeleting', false);
  82. this.get('logger').danger("Failed to delete files and folders.", error);
  83. this.send('close');
  84. }
  85. });
  86. },
  87. reset: function() {
  88. this.set('deletePermanently', false);
  89. this.set('hasError', false);
  90. this.set('shouldRetry', false);
  91. this.set('isDeleting', false);
  92. this.set('currentFailedPath', '');
  93. this.set('currentFailureMessage', '');
  94. this.set('currentUnprocessedPaths', '');
  95. },
  96. actions: {
  97. didOpenModal: function() {
  98. this.reset();
  99. console.log("Delete modal opened");
  100. },
  101. didCloseModal: function() {
  102. console.log("Delete Modal closed");
  103. },
  104. delete: function() {
  105. var currentPathsToDelete = this.get('selectedFiles').map((entry) => { return entry.get('path');});
  106. this.deletePaths(currentPathsToDelete);
  107. },
  108. retryError: function() {
  109. var newPaths = [this.get('currentFailedPath')];
  110. if (Ember.isArray(this.get('currentUnprocessedPaths'))) {
  111. newPaths.pushObjects(this.get('currentUnprocessedPaths'));
  112. }
  113. this.deletePaths(newPaths);
  114. },
  115. skipAndRetry: function() {
  116. this.deletePaths(this.get('currentUnprocessedPaths'));
  117. },
  118. skipAll: function() {
  119. this.send('close');
  120. this.sendAction('refreshAction');
  121. }
  122. }
  123. });