|
| 1 | +// Copyright 2015 Google Inc. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/** |
| 16 | + * Controller for the resource card delete menu item component. It deletes card's resource. |
| 17 | + * @final |
| 18 | + */ |
| 19 | +export class ResourceCardDeleteMenuItemController { |
| 20 | + /** |
| 21 | + * @param {!./../../resource/verber_service.VerberService} kdResourceVerberService |
| 22 | + * @param {!ui.router.$state} $state |
| 23 | + * @param {!md.$dialog} $mdDialog |
| 24 | + * @ngInject |
| 25 | + */ |
| 26 | + constructor(kdResourceVerberService, $state, $mdDialog) { |
| 27 | + /** |
| 28 | + * Initialized from require just before $onInit is called. |
| 29 | + * @export {!./resourcecard_component.ResourceCardController} |
| 30 | + */ |
| 31 | + this.resourceCardCtrl; |
| 32 | + |
| 33 | + /** @export {string} Initialized from a binding.*/ |
| 34 | + this.resourceKindName; |
| 35 | + |
| 36 | + /** @private {!./../../resource/verber_service.VerberService} */ |
| 37 | + this.kdResourceVerberService_ = kdResourceVerberService; |
| 38 | + |
| 39 | + /** @private {!ui.router.$state}} */ |
| 40 | + this.state_ = $state; |
| 41 | + |
| 42 | + /** @private {!md.$dialog} */ |
| 43 | + this.mdDialog_ = $mdDialog; |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * @export |
| 48 | + */ |
| 49 | + remove() { |
| 50 | + this.kdResourceVerberService_ |
| 51 | + .showDeleteDialog( |
| 52 | + this.resourceKindName, this.resourceCardCtrl.typeMeta, this.resourceCardCtrl.objectMeta) |
| 53 | + .then( |
| 54 | + () => { |
| 55 | + // For now just reload the state. Later we can remove the item in place. |
| 56 | + this.state_.reload(); |
| 57 | + }, |
| 58 | + (/** angular.$http.Response|null */ err) => { |
| 59 | + if (err) { |
| 60 | + // Show dialog if there was an error, not user canceling dialog. |
| 61 | + this.mdDialog_.show(this.mdDialog_.alert() |
| 62 | + .ok('Ok') |
| 63 | + .title(err.statusText || 'Internal server error') |
| 64 | + .textContent(err.data || 'Could not delete the resource')); |
| 65 | + } |
| 66 | + }); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +/** |
| 71 | + * @type {!angular.Component} |
| 72 | + */ |
| 73 | +export const resourceCardDeleteMenuItemComponent = { |
| 74 | + templateUrl: 'common/components/resourcecard/resourcecarddeletemenuitem.html', |
| 75 | + bindings: { |
| 76 | + 'resourceKindName': '@', |
| 77 | + }, |
| 78 | + bindToController: true, |
| 79 | + require: { |
| 80 | + 'resourceCardCtrl': '^kdResourceCard', |
| 81 | + }, |
| 82 | + controller: ResourceCardDeleteMenuItemController, |
| 83 | +}; |
0 commit comments