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 app.controller('serviceDictGridController', function ($scope, PolicyAppService, modalService, $modal){
 
  21         $( "#dialog" ).hide();
 
  23         PolicyAppService.getData('getDictionary/get_ClosedLoopServicesData').then(function (data) {
 
  25                 $scope.data = JSON.parse(j.data);
 
  26                 console.log($scope.data);
 
  27                 $scope.closedLoopServiceDictionaryDatas = JSON.parse($scope.data.closedLoopServiceDictionaryDatas);
 
  28                 console.log($scope.closedLoopServiceDictionaryDatas);
 
  30                 console.log("failed");
 
  33         PolicyAppService.getData('get_LockDownData').then(function(data){
 
  35                 $scope.data = JSON.parse(j.data);
 
  36                 $scope.lockdowndata = JSON.parse($scope.data.lockdowndata);
 
  37                 if($scope.lockdowndata[0].lockdown == true){
 
  38                         $scope.serviceDictionaryGrid.columnDefs[0].visible = false;
 
  39                         $scope.gridApi.grid.refresh();
 
  41                         $scope.serviceDictionaryGrid.columnDefs[0].visible = true;
 
  42                         $scope.gridApi.grid.refresh();
 
  45                 console.log("failed");
 
  48         $scope.serviceDictionaryGrid = {
 
  49                         data : 'closedLoopServiceDictionaryDatas',
 
  50                         enableFiltering: true,
 
  52                                 field: 'id', enableFiltering: false, headerCellTemplate: '' +
 
  53                                 '<button id=\'New\' ng-click="grid.appScope.createNewServiceDictWindow()" class="btn btn-success">' + 'Create</button>',
 
  55                                         '<button  type="button"  class="btn btn-primary"  ng-click="grid.appScope.editServiceDictWindow(row.entity)"><i class="fa fa-pencil-square-o"></i></button> ' +
 
  56                                         '<button  type="button"  class="btn btn-danger"  ng-click="grid.appScope.deleteServiceDict(row.entity)" ><i class="fa fa-trash-o"></i></button> ',  width: '8%'
 
  58                         { field: 'serviceName', displayName : 'Service Name', sort: { direction: 'asc', priority: 0 }},
 
  59                         { field: 'description'},
 
  60                         {field: 'userCreatedBy.userName', displayName : 'Created By'},
 
  61                         {field: 'userModifiedBy.userName', displayName : 'Modified By'},
 
  62                         {field: 'createdDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' },
 
  63                         {field: 'modifiedDate',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }
 
  67         $scope.editCLService = null;
 
  68         $scope.createNewServiceDictWindow = function(){
 
  69                 $scope.editCLService = null;
 
  70                 var modalInstance = $modal.open({
 
  71                         backdrop: 'static', keyboard: false,
 
  72                         templateUrl : 'add_CLService_popup.html',
 
  73                         controller: 'editCLServiceController',
 
  75                                 message: function () {
 
  77                                                         closedLoopServiceDictionaryDatas: $scope.editCLService
 
  83                 modalInstance.result.then(function(response){
 
  84                         console.log('response', response);
 
  85                         $scope.closedLoopServiceDictionaryDatas=response.closedLoopServiceDictionaryDatas;
 
  89         $scope.editServiceDictWindow = function(closedLoopServiceDictionaryData) {
 
  90                 $scope.editCLService = closedLoopServiceDictionaryData;
 
  91                 var modalInstance = $modal.open({
 
  92                         backdrop: 'static', keyboard: false,
 
  93                         templateUrl : 'add_CLService_popup.html',
 
  94                         controller: 'editCLServiceController',
 
  96                                 message: function () {
 
  98                                                         closedLoopServiceDictionaryData: $scope.editCLService
 
 104                 modalInstance.result.then(function(response){
 
 105                         console.log('response', response);
 
 106                         $scope.closedLoopServiceDictionaryDatas = response.closedLoopServiceDictionaryDatas;
 
 110         $scope.deleteServiceDict = function(data) {
 
 111                 var uuu = "searchDictionary";
 
 112                 var postData={data: data, type: "clService"};
 
 113                 var searchString = "\n";
 
 118                         contentType: 'application/json',
 
 119                         data: JSON.stringify(postData),
 
 120                         success : function(resultList){
 
 121                                 $scope.$apply(function(){
 
 122                                         $scope.list =resultList.result;});
 
 123                                 $scope.searchData = JSON.stringify(resultList.result);
 
 124                                 $scope.searchDatas = JSON.parse($scope.searchData);        
 
 125                                 $scope.success = true;
 
 127                                 if($scope.searchDatas.length > 0){
 
 128                                         for(i = 0 ; i < $scope.searchDatas.length; i++){
 
 129                                                 searchString += $scope.searchDatas[i].name + "\n";
 
 132                                         searchString += "No Policies is Using this Value"
 
 135                                 console.log($scope.list);
 
 137                                         modalService.popupConfirmWin("Confirm","You are about to delete the Service Dictionary  "+data.serviceName+". \n "+searchString+" \n  Do you want to continue?",
 
 139                                                 var uuu = "deleteDictionary/cl_dictionary/remove_Service";
 
 140                                                 var postData={data: data};
 
 145                                                         contentType: 'application/json',
 
 146                                                         data: JSON.stringify(postData),
 
 147                                                         success : function(data){
 
 148                                                                 $scope.$apply(function(){$scope.closedLoopServiceDictionaryDatas=data.closedLoopServiceDictionaryDatas;});
 
 150                                                         error : function(data){
 
 152                                                                 modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
 
 158                         error : function(data){
 
 159                                 alert("Error while Searching.");