blob: 39336e3a3a9f6ddd741367009063e8a1eded7345 [file] [log] [blame]
Max Chu886c89f2017-08-24 15:44:27 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
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
12 * distributed under the License is distributed on an "AS IS" BASIS,
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
18import {IXosConfirmConfig} from './confirm';
19
20export interface IXosConfirm {
Max Chuf9261192017-08-25 15:51:18 -070021 modalInstance: any;
Max Chu886c89f2017-08-24 15:44:27 -070022 open(config: IXosConfirmConfig) : void;
Max Chuf9261192017-08-25 15:51:18 -070023 close(cb: any) : void;
Max Chu886c89f2017-08-24 15:44:27 -070024 dismiss() : void;
25}
26
27export class XosConfirm implements IXosConfirm {
28
Max Chuf9261192017-08-25 15:51:18 -070029 static $inject = ['$uibModal', '$log'];
Max Chu886c89f2017-08-24 15:44:27 -070030 public modalInstance;
31
32 constructor(
33 private $uibModal : any,
Max Chuf9261192017-08-25 15:51:18 -070034 private $log: ng.ILogService,
Max Chu886c89f2017-08-24 15:44:27 -070035 ) {
36
37 }
38
39 public open(config: IXosConfirmConfig) {
Max Chuf9261192017-08-25 15:51:18 -070040 this.$log.debug('[XosConfirm] called open');
Max Chu886c89f2017-08-24 15:44:27 -070041 this.modalInstance = this.$uibModal.open({
Max Chuf9261192017-08-25 15:51:18 -070042 keyboard: true,
Max Chu886c89f2017-08-24 15:44:27 -070043 component: 'xosConfirm',
44 backdrop: 'static',
45 resolve: {
46 config: () => config
47 }
48 });
Max Chuf9261192017-08-25 15:51:18 -070049
Max Chu886c89f2017-08-24 15:44:27 -070050 return this.modalInstance;
51 }
52
Max Chuf9261192017-08-25 15:51:18 -070053 public close(cb: any) {
54 // check if model instance exists
55 if (angular.isUndefined(this.modalInstance)) {
56 this.$log.debug('[XosConfirm] called close without a modalInstance');
57 return;
58 }
Max Chu886c89f2017-08-24 15:44:27 -070059 cb()
60 .then(() => {
61 this.modalInstance.close();
62 })
63 .catch((err) => {
64 this.modalInstance.dismiss(err);
65 });
66 }
67
68 public dismiss() {
69 this.modalInstance.dismiss();
70 }
71
72}
73