2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 import {ValidationUtils, ModalType} from "app/utils";
24 export interface IConfirmationModalModel {
31 interface IConfirmationModalViewModelScope {
32 modalInstanceConfirmation:ng.ui.bootstrap.IModalServiceInstance;
33 confirmationModalModel:IConfirmationModalModel;
35 commentValidationPattern:RegExp;
36 editForm:ng.IFormController;
38 hideCancelButton:boolean;
43 export class ConfirmationModalViewModel {
45 static '$inject' = ['$scope', '$uibModalInstance', 'confirmationModalModel', 'CommentValidationPattern', 'ValidationUtils'];
47 constructor(private $scope:IConfirmationModalViewModelScope,
48 private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
49 confirmationModalModel:IConfirmationModalModel,
50 private CommentValidationPattern:RegExp,
51 private ValidationUtils:ValidationUtils) {
53 this.initScope(confirmationModalModel);
56 private initScope = (confirmationModalModel:IConfirmationModalModel):void => {
58 this.$scope.hideCancelButton = false;
59 this.$scope.modalInstanceConfirmation = this.$uibModalInstance;
60 this.$scope.confirmationModalModel = confirmationModalModel;
61 this.$scope.comment = {"text": ''};
62 this.$scope.commentValidationPattern = this.CommentValidationPattern;
64 this.$scope.ok = ():any => {
65 self.$uibModalInstance.close(this.ValidationUtils.stripAndSanitize(self.$scope.comment.text));
68 this.$scope.cancel = ():void => {
69 console.info('Cancel pressed on: ' + this.$scope.confirmationModalModel.title);
70 self.$uibModalInstance.dismiss();
73 // Set the OK button color according to modal type (standard, error, alert)
74 let _okButtonColor = 'blue'; // Default
75 switch (confirmationModalModel.type) {
76 case ModalType.STANDARD:
77 _okButtonColor = 'blue';
80 _okButtonColor = 'red';
83 this.$scope.hideCancelButton = true;
84 _okButtonColor = 'grey';
87 _okButtonColor = 'blue';
90 this.$scope.okButtonColor = _okButtonColor;