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"/>
21 module Sdc.ViewModels {
24 interface IAddCategoryModalViewModelScope extends ng.IScope {
25 category:Sdc.Services.ICategoryResource;
27 footerButtons: Array<any>;
34 export class AddCategoryModalViewModel {
38 'Sdc.Services.CategoryResourceService',
45 private $scope:IAddCategoryModalViewModelScope,
46 private categoryResourceService:Sdc.Services.ICategoryResourceClass,
47 private $modalInstance:ng.ui.bootstrap.IModalServiceInstance,
48 private parentCategory:Sdc.Services.ICategoryResource,
54 private initScope = ():void => {
55 this.$scope.forms = {};
56 this.$scope.modelType = this.parentCategory ? 'sub category' : 'category';
57 this.$scope.category = new this.categoryResourceService();
59 this.$scope.close = ():void => {
60 this.$modalInstance.dismiss();
63 this.$scope.save = ():void => {
65 let onOk = (newCategory :Sdc.Services.ICategoryResource):void => {
66 this.$modalInstance.close(newCategory);
69 let onCancel = ():void => {
73 if(!this.parentCategory) {
74 this.$scope.category.$save({types: this.type+"s"}, onOk, onCancel);
76 this.$scope.category.$saveSubCategory({types: this.type+"s", categoryId: this.parentCategory.uniqueId}, onOk, onCancel);
81 this.$scope.footerButtons = [
82 {'name': 'OK', 'css': 'blue', 'callback': this.$scope.save, 'disabled': true},
83 {'name': 'Cancel', 'css': 'grey', 'callback': this.$scope.close}
86 this.$scope.$watch("forms.editForm.$invalid", (newVal, oldVal) => {
87 this.$scope.footerButtons[0].disabled = this.$scope.forms.editForm.$invalid;