Commit 22d15411 authored by nakavaram-nisum-com's avatar nakavaram-nisum-com Committed by tdutta-nisum-com

restricting api calls in update (#120)

parent 67879601
...@@ -266,83 +266,89 @@ myApp.controller("domainController", ...@@ -266,83 +266,89 @@ myApp.controller("domainController",
return "Please select account"; return "Please select account";
} }
}; };
isDataUpdated = function () {
if (dataToPass.action == "Update") {
$scope.previousData = {
domainId: dataToPass.domainId,
accountinfo: dataToPass.AccountName,
domainname: dataToPass.domainName
}
$scope.currentdata = {
domainId: $scope.domainId,
accountinfo: $scope.AccountInfo.accountName,
domainname: $scope.domainName
}
$scope.cancel = function() { var predata = JSON.stringify($scope.previousData);
var showConfirmDialog = false; var curdata = JSON.stringify($scope.currentdata);
if(dataToPass.action=="Update"){
console.log(dataToPass.deliveryManagers+' response')
console.log($scope.employeeModel)
$scope.previousData={
domainId :dataToPass.domainId,
accountinfo:dataToPass.AccountName,
domainname:dataToPass.domainName
}
$scope.currentdata={
domainId :$scope.domainId,
accountinfo:$scope.AccountInfo.accountName,
domainname:$scope.domainName
}
var predata=JSON.stringify($scope.previousData);
var curdata=JSON.stringify($scope.currentdata);
var exsistingMangersList = dataToPass.deliveryManagers; var exsistingMangersList = dataToPass.deliveryManagers;
var currentMangersList = $scope.employeeModel; var currentMangersList = $scope.employeeModel;
var managerCheck = false; var managerCheck = false;
if(exsistingMangersList.length === currentMangersList.length){ if (exsistingMangersList.length === currentMangersList.length) {
var temp1 = []; var temp1 = [];
var temp2 = []; var temp2 = [];
for (var i in exsistingMangersList){ for (var i in exsistingMangersList) {
temp1.push(exsistingMangersList[i].employeeId); temp1.push(exsistingMangersList[i].employeeId);
} }
for (var j in currentMangersList){ for (var j in currentMangersList) {
temp2.push(currentMangersList[j].employeeId); temp2.push(currentMangersList[j].employeeId);
} }
for(var k=0;k<exsistingMangersList.length;k++){ for (var k = 0; k < exsistingMangersList.length; k++) {
if(temp2.indexOf(temp1[k]) > -1){ if (temp2.indexOf(temp1[k]) > -1) {
managerCheck = true; managerCheck = true;
}else{ } else {
managerCheck = false; managerCheck = false;
} }
} }
}else{ } else {
managerCheck = false; managerCheck = false;
} }
if(predata === curdata && managerCheck){ if (predata === curdata && managerCheck) {
//$mdDialog.hide('Cancelled');
return false;
}
return true;
}
}
$scope.cancel = function () {
var showConfirmDialog = false;
if (dataToPass.action == "Update") {
if (isDataUpdated() != true) {
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
} }
else{ else {
$mdDialog.show($mdDialog.confirm({ $mdDialog.show($mdDialog.confirm({
skipHide: true, skipHide: true,
textContent: 'Are you sure you want to cancel this?', textContent: 'Are you sure you want to cancel this?',
ok: 'ok', ok: 'ok',
cancel:'cancel' cancel: 'cancel'
})).then(function(){ })).then(function () {
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
}) })
} }
} }
if(dataToPass.action=="Add"){ if (dataToPass.action == "Add") {
var totalFields = $scope.myForm.$$controls; var totalFields = $scope.myForm.$$controls;
for (key in totalFields) { for (key in totalFields) {
console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue) console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue)
if(totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined && totalFields[key].$modelValue.length !== 0) { if (totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined && totalFields[key].$modelValue.length !== 0) {
console.log("Came here!");
showConfirmDialog = true; showConfirmDialog = true;
} }
} }
if(showConfirmDialog){ if (showConfirmDialog) {
$mdDialog.show($mdDialog.confirm({ $mdDialog.show($mdDialog.confirm({
skipHide: true, skipHide: true,
textContent: 'Are you sure you want to cancel this?', textContent: 'Are you sure you want to cancel this?',
ok: 'ok', ok: 'ok',
cancel:'cancel' cancel: 'cancel'
})).then(function(){ })).then(function () {
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
}) })
} }
else{ else {
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
} }
} }
...@@ -477,11 +483,19 @@ myApp.controller("domainController", ...@@ -477,11 +483,19 @@ myApp.controller("domainController",
"id" : $scope.id, "id" : $scope.id,
"domainId" : dataToPass.domainId "domainId" : dataToPass.domainId
}; };
$scope.addOrUpdateDomain(record,action); if (isDataUpdated() != true) {
$mdDialog.show($mdDialog.alert({
skipHide: true,
title: 'Attention',
textContent: 'There is no data change to Update',
ok: 'ok'
}))
}
else {
$scope.addOrUpdateDomain(record, action);
}
} }
} }
}; };
} }
......
...@@ -171,7 +171,6 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo ...@@ -171,7 +171,6 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo
url : appConfig.appUri + "/projectTeam/getEmployeesToTeam" url : appConfig.appUri + "/projectTeam/getEmployeesToTeam"
}).then(function mySuccess(response) { }).then(function mySuccess(response) {
$scope.managerDetails=response.data; $scope.managerDetails=response.data;
console.log("response",response)
}, function myError(response) { }, function myError(response) {
showAlert("Something went wrong while fetching data!!!"); showAlert("Something went wrong while fetching data!!!");
$scope.gridOptions.data = []; $scope.gridOptions.data = [];
...@@ -181,86 +180,92 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo ...@@ -181,86 +180,92 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo
$scope.closeSelectBox = function () { $scope.closeSelectBox = function () {
$mdSelect.hide(); $mdSelect.hide();
} }
$scope.cancel = function(){ isDataUpdated = function () {
var showConfirmDialog = false; if (dataToPass.action == "Update") {
if(dataToPass.action=="Update"){ $scope.previousData = {
console.log(dataToPass); AccountID: dataToPass.accountId,
$scope.previousData={ AccountName: dataToPass.accountName,
AccountID:dataToPass.accountId, IndustryType: dataToPass.industryType,
AccountName:dataToPass.accountName, ClientAddress: dataToPass.clientAddress,
IndustryType:dataToPass.industryType, }
ClientAddress:dataToPass.clientAddress, $scope.currentData = {
} AccountID: $scope.accountId,
$scope.currentData={ AccountName: $scope.accountName,
AccountID:$scope.accountId, IndustryType: $scope.industryType,
AccountName:$scope.accountName, ClientAddress: $scope.clientAddress
IndustryType:$scope.industryType,
ClientAddress:$scope.clientAddress
} }
var predata=JSON.stringify($scope.previousData); var predata = JSON.stringify($scope.previousData);
var curdata=JSON.stringify($scope.currentData); var curdata = JSON.stringify($scope.currentData);
var exsistingMangersList = dataToPass.deliveryManagers; var exsistingMangersList = dataToPass.deliveryManagers;
var currentMangersList = $scope.managersSelectedList; var currentMangersList = $scope.managersSelectedList;
console.log($scope.managersSelectedList);
var managerCheck = false; var managerCheck = false;
if(exsistingMangersList.length === currentMangersList.length){ if (exsistingMangersList.length === currentMangersList.length) {
var temp1 = []; var temp1 = [];
var temp2 = []; var temp2 = [];
for (var i in exsistingMangersList){ for (var i in exsistingMangersList) {
temp1.push(exsistingMangersList[i].employeeId); temp1.push(exsistingMangersList[i].employeeId);
} }
for (var j in currentMangersList){ for (var j in currentMangersList) {
temp2.push(currentMangersList[j].employeeId); temp2.push(currentMangersList[j].employeeId);
} }
for(var k=0;k<exsistingMangersList.length;k++){ for (var k = 0; k < exsistingMangersList.length; k++) {
if(temp2.indexOf(temp1[k]) > -1){ if (temp2.indexOf(temp1[k]) > -1) {
managerCheck = true; managerCheck = true;
}else{ } else {
managerCheck = false; managerCheck = false;
} }
} }
} }
else{ else {
managerCheck = false; managerCheck = false;
} }
if(predata === curdata && managerCheck){ if (predata === curdata && managerCheck) {
//$mdDialog.hide('Cancelled');
return false;
}
return true;
}
}
$scope.cancel = function () {
var showConfirmDialog = false;
if (dataToPass.action == "Update") {
if (isDataUpdated() != true) {
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
} }
else{ else {
$mdDialog.show($mdDialog.confirm({ $mdDialog.show($mdDialog.confirm({
skipHide: true, skipHide: true,
textContent: 'Are you sure you want to cancel this?', textContent: 'Are you sure you want to cancel this?',
ok: 'ok', ok: 'ok',
cancel:'cancel' cancel: 'cancel'
})).then(function(){ })).then(function () {
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
}) })
} }
} }
if(dataToPass.action=="Add"){ if (dataToPass.action == "Add") {
var totalFields = $scope.myForm.$$controls; var totalFields = $scope.myForm.$$controls;
for (key in totalFields) { for (key in totalFields) {
console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue) // console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue)
if(totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined && totalFields[key].$modelValue.length !== 0) { if (totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined && totalFields[key].$modelValue.length !== 0) {
console.log("Came here!");
showConfirmDialog = true; showConfirmDialog = true;
} }
} }
if(showConfirmDialog){ if (showConfirmDialog) {
$mdDialog.show($mdDialog.confirm({ $mdDialog.show($mdDialog.confirm({
skipHide: true, skipHide: true,
textContent: 'Are you sure you want to cancel this?', textContent: 'Are you sure you want to cancel this?',
ok: 'ok', ok: 'ok',
cancel:'cancel' cancel: 'cancel'
})).then(function(){ })).then(function () {
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
}) })
} }
else{ else {
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
} }
} }
...@@ -364,10 +369,19 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo ...@@ -364,10 +369,19 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo
else{ else{
$scope.alertMsg = ""; $scope.alertMsg = "";
var record = {"accountId":$scope.accountId, "accountName":$scope.accountName,"industryType":$scope.industryType,"clientAddress":$scope.clientAddress,"deliveryManagers":$scope.accountManagers()}; var record = {"accountId":$scope.accountId, "accountName":$scope.accountName,"industryType":$scope.industryType,"clientAddress":$scope.clientAddress,"deliveryManagers":$scope.accountManagers()};
record.id = $scope.parentData.id; record.id = $scope.parentData.id;
addOrUpdateAccount(record,$scope.templateTitle,"U"); if (isDataUpdated() != true) {
$timeout(function(){updateGrid($scope.templateTitle, record)},200); $mdDialog.show($mdDialog.alert({
skipHide: true,
title: 'Attention',
textContent: 'There is no data change to Update',
ok: 'ok'
}))
}
else {
addOrUpdateAccount(record, $scope.templateTitle, "U");
$timeout(function () { updateGrid($scope.templateTitle, record) }, 200);
}
} }
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment