Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
Max Chu | 2de11f8 | 2017-09-06 08:49:21 -0700 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the 'License'); |
Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
Max Chu | 2de11f8 | 2017-09-06 08:49:21 -0700 | [diff] [blame] | 12 | * distributed under the License is distributed on an 'AS IS' BASIS, |
Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | let self; |
| 20 | |
| 21 | class ElineSide { |
| 22 | |
Max Chu | 2de11f8 | 2017-09-06 08:49:21 -0700 | [diff] [blame] | 23 | static $inject = ['XosSidePanel', 'XosModelStore', '$http', '$log', 'toastr', 'XosConfirm']; |
Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 24 | |
| 25 | constructor( |
| 26 | private XosSidePanel: any, |
| 27 | private XosModelStore: any, |
| 28 | private $http: any, |
| 29 | private $log: any, |
| 30 | private toastr: any, |
Max Chu | 2de11f8 | 2017-09-06 08:49:21 -0700 | [diff] [blame] | 31 | private XosConfirm: any, |
Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 32 | ) { |
| 33 | self = this; |
| 34 | } |
| 35 | |
| 36 | public saveEline(item: any) { |
| 37 | let path = item.path; |
| 38 | delete item.path; |
| 39 | item.$save().then((res) => { |
| 40 | item.path = path; |
| 41 | this.toastr.success(`${item.name} successfully saved!`); |
| 42 | }) |
| 43 | .catch((error) => { |
| 44 | this.toastr.error(`Error while saving ${item.name}: ${error.specific_error}`); |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | public deleteEline(item: any) { |
| 49 | let name = item.name; |
Max Chu | 2de11f8 | 2017-09-06 08:49:21 -0700 | [diff] [blame] | 50 | this.XosConfirm.open({ |
| 51 | header: 'Confirm deletion', |
| 52 | text: 'Are you sure you want to delete this? This action cannot be undone.', |
| 53 | actions: [{ |
| 54 | label: 'Delete', |
| 55 | class: 'btn-danger', |
| 56 | cb: () => { |
| 57 | item.$delete().then((res) => { |
| 58 | this.toastr.success(`${name} successfully deleted!`); |
| 59 | }) |
| 60 | .catch((error) => { |
| 61 | this.toastr.error(`Error while deleting ${name}: ${error.specific_error}`); |
| 62 | }); |
| 63 | } |
| 64 | }] |
| 65 | }); |
| 66 | |
Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
| 70 | } |
| 71 | |
| 72 | export const elineSide: angular.IComponentOptions = { |
| 73 | template: require('./eline-side.component.html'), |
| 74 | controllerAs: 'vm', |
| 75 | controller: ElineSide, |
| 76 | bindings: { |
Max Chu | 2de11f8 | 2017-09-06 08:49:21 -0700 | [diff] [blame] | 77 | vng: '=' |
Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 78 | } |
| 79 | }; |