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 {IAppConfigurtaion, Component, AsdcComment} from "app/models";
23 import {ValidationUtils} from "app/utils";
25 export interface IEmailModalModel_Email {
31 export interface IEmailModalModel_Data {
36 export interface IEmailModalModel {
38 email:IEmailModalModel_Email;
39 data:IEmailModalModel_Data;
42 interface IEmailModalViewModelScope {
43 modalInstanceEmail:ng.ui.bootstrap.IModalServiceInstance;
44 emailModalModel:IEmailModalModel;
45 submitInProgress:boolean;
46 commentValidationPattern:RegExp;
50 validateField(field:any):boolean;
53 export class EmailModalViewModel {
55 static '$inject' = ['$scope', '$filter', 'sdcConfig', '$uibModalInstance', 'emailModalModel', 'ValidationUtils', 'CommentValidationPattern'];
57 constructor(private $scope:IEmailModalViewModelScope,
58 private $filter:ng.IFilterService,
59 private sdcConfig:IAppConfigurtaion,
60 private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
61 private emailModalModel:IEmailModalModel,
62 private ValidationUtils:ValidationUtils,
63 private CommentValidationPattern:RegExp) {
65 this.initScope(emailModalModel);
68 private initScope = (emailModalModel:IEmailModalModel):void => {
69 this.$scope.emailModalModel = emailModalModel;
70 this.$scope.submitInProgress = false;
71 this.$scope.commentValidationPattern = this.CommentValidationPattern;
72 this.$scope.modalInstanceEmail = this.$uibModalInstance;
74 this.$scope.submit = ():any => {
76 let onSuccess = (component:Component) => {
77 this.$scope.isLoading = false;
78 this.$scope.submitInProgress = false;
79 // showing the outlook modal according to the config json
80 if (this.sdcConfig.showOutlook) {
81 let link:string = encodeURI(this.sdcConfig.api.baseUrl + "?folder=Ready_For_Testing");
82 let outlook:string = this.$filter('translate')("EMAIL_OUTLOOK_MESSAGE", "{'to': '" + emailModalModel.email.to + "','subject': '" + emailModalModel.email.subject + "','message': '" + emailModalModel.email.message + "', 'entityNameAndVersion': '" + emailModalModel.email.subject + "','link': '" + link + "'}");
83 window.location.href = outlook; // Open outlook with the email to send
85 this.$uibModalInstance.close(component); // Close the dialog
89 this.$scope.isLoading = false;
90 this.$scope.submitInProgress = false;
91 this.$uibModalInstance.close(); // Close the dialog
95 // Prevent from user pressing multiple times on submit.
96 if (this.$scope.submitInProgress === false) {
97 this.$scope.isLoading = true;
98 this.$scope.submitInProgress = true;
99 let comment:AsdcComment = new AsdcComment();
100 comment.userRemarks = emailModalModel.email.message;
101 emailModalModel.data.component.changeLifecycleState(emailModalModel.data.stateUrl, comment).then(onSuccess, onError);
105 this.$scope.cancel = ():void => {
106 this.$uibModalInstance.dismiss();
109 this.$scope.validateField = (field:any):boolean => {
110 if (field && field.$dirty && field.$invalid) {