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=========================================================
20 /// <reference path="../../../references"/>
22 module Sdc.ViewModels {
25 interface IResourceInstanceViewModelScope extends ng.IScope {
27 componentInstanceModel: Sdc.Models.ComponentsInstances.ComponentInstance;
28 validationPattern: RegExp;
30 isAlreadyPressed:boolean;
31 footerButtons: Array<any>;
33 modalInstanceName:ng.ui.bootstrap.IModalServiceInstance;
39 export class ResourceInstanceNameViewModel {
45 'ComponentInstanceFactory',
50 constructor(private $scope:IResourceInstanceViewModelScope,
51 private ValidationPattern:RegExp,
52 private $modalInstance:ng.ui.bootstrap.IModalServiceInstance,
53 private ComponentInstanceFactory:Utils.ComponentInstanceFactory,
54 private component:Models.Components.Component) {
60 private initScope = ():void => {
61 this.$scope.forms = {};
62 this.$scope.validationPattern = this.ValidationPattern;
63 this.$scope.componentInstanceModel = Utils.ComponentInstanceFactory.createComponentInstance(this.component.selectedInstance);
64 this.$scope.oldName = this.component.selectedInstance.name;
65 this.$scope.modalInstanceName = this.$modalInstance;
67 this.$scope.isAlreadyPressed = false;
70 this.$scope.close = ():void => {
71 this.$modalInstance.dismiss();
74 this.$scope.save = ():void => {
76 let onFailed = () => {
77 this.$scope.isAlreadyPressed = true;
80 let onSuccess = (componentInstance:Models.ComponentsInstances.ComponentInstance) => {
81 this.$modalInstance.close();
82 this.$scope.isAlreadyPressed = false;
83 this.$scope.componentInstanceModel = componentInstance;
84 //this.component.name = componentInstance.name;//DE219124
85 this.component.selectedInstance.name = componentInstance.name;
89 this.$scope.isAlreadyPressed = true;
90 if (this.$scope.oldName != this.$scope.componentInstanceModel.name) {
91 this.component.updateComponentInstance(this.$scope.componentInstanceModel).then(onSuccess, onFailed);
95 this.$scope.footerButtons = [
96 {'name': 'OK', 'css': 'blue', 'callback': this.$scope.save, 'disabled': (!this.$scope.componentInstanceModel.name || this.$scope.componentInstanceModel.name === this.$scope.oldName) || this.$scope.isAlreadyPressed},
97 {'name': 'Cancel', 'css': 'grey', 'callback': this.$scope.close}
100 this.$scope.$watch("forms.editNameForm.$invalid", (newVal, oldVal) => {
101 this.$scope.footerButtons[0].disabled = this.$scope.forms.editNameForm.$invalid;