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
...@@ -265,85 +265,91 @@ myApp.controller("domainController", ...@@ -265,85 +265,91 @@ myApp.controller("domainController",
else { else {
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'); //$mdDialog.hide('Cancelled');
return false;
}
return true;
}
}
$scope.cancel = function () {
var showConfirmDialog = false;
if (dataToPass.action == "Update") {
if (isDataUpdated() != true) {
$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"){
var totalFields = $scope.myForm.$$controls;
for (key in totalFields) {
console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue)
if(totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined && totalFields[key].$modelValue.length !== 0) {
console.log("Came here!");
showConfirmDialog = true;
}
} }
if(showConfirmDialog){ if (dataToPass.action == "Add") {
$mdDialog.show($mdDialog.confirm({ var totalFields = $scope.myForm.$$controls;
skipHide: true, for (key in totalFields) {
textContent: 'Are you sure you want to cancel this?', console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue)
ok: 'ok', if (totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined && totalFields[key].$modelValue.length !== 0) {
cancel:'cancel' showConfirmDialog = true;
})).then(function(){ }
$mdDialog.hide('Cancelled'); }
}) if (showConfirmDialog) {
$mdDialog.show($mdDialog.confirm({
skipHide: true,
textContent: 'Are you sure you want to cancel this?',
ok: 'ok',
cancel: 'cancel'
})).then(function () {
$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,87 +180,93 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo ...@@ -181,87 +180,93 @@ 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 curdata=JSON.stringify($scope.currentData);
var exsistingMangersList = dataToPass.deliveryManagers;
var currentMangersList = $scope.managersSelectedList;
console.log($scope.managersSelectedList);
var managerCheck = false;
if(exsistingMangersList.length === currentMangersList.length){ var predata = JSON.stringify($scope.previousData);
var temp1 = []; var curdata = JSON.stringify($scope.currentData);
var temp2 = []; var exsistingMangersList = dataToPass.deliveryManagers;
var currentMangersList = $scope.managersSelectedList;
var managerCheck = false;
for (var i in exsistingMangersList){ if (exsistingMangersList.length === currentMangersList.length) {
temp1.push(exsistingMangersList[i].employeeId); var temp1 = [];
} var temp2 = [];
for (var j in currentMangersList){
temp2.push(currentMangersList[j].employeeId); for (var i in exsistingMangersList) {
} temp1.push(exsistingMangersList[i].employeeId);
for(var k=0;k<exsistingMangersList.length;k++){
if(temp2.indexOf(temp1[k]) > -1){
managerCheck = true;
}else{
managerCheck = false;
}
}
}
else{
managerCheck = false;
} }
if(predata === curdata && managerCheck){ for (var j in currentMangersList) {
$mdDialog.hide('Cancelled'); temp2.push(currentMangersList[j].employeeId);
} }
else{ for (var k = 0; k < exsistingMangersList.length; k++) {
$mdDialog.show($mdDialog.confirm({ if (temp2.indexOf(temp1[k]) > -1) {
skipHide: true, managerCheck = true;
textContent: 'Are you sure you want to cancel this?', } else {
ok: 'ok', managerCheck = false;
cancel:'cancel' }
})).then(function(){
$mdDialog.hide('Cancelled');
})
}
} }
if(dataToPass.action=="Add"){
var totalFields = $scope.myForm.$$controls;
for (key in totalFields) {
console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue)
if(totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined && totalFields[key].$modelValue.length !== 0) {
console.log("Came here!");
showConfirmDialog = true;
} }
else {
managerCheck = false;
}
if (predata === curdata && managerCheck) {
//$mdDialog.hide('Cancelled');
return false;
}
return true;
} }
if(showConfirmDialog){ }
$mdDialog.show($mdDialog.confirm({ $scope.cancel = function () {
skipHide: true, var showConfirmDialog = false;
textContent: 'Are you sure you want to cancel this?', if (dataToPass.action == "Update") {
ok: 'ok', if (isDataUpdated() != true) {
cancel:'cancel' $mdDialog.hide('Cancelled');
})).then(function(){
$mdDialog.hide('Cancelled');
})
} }
else{ else {
$mdDialog.hide('Cancelled'); $mdDialog.show($mdDialog.confirm({
skipHide: true,
textContent: 'Are you sure you want to cancel this?',
ok: 'ok',
cancel: 'cancel'
})).then(function () {
$mdDialog.hide('Cancelled');
})
}
}
if (dataToPass.action == "Add") {
var totalFields = $scope.myForm.$$controls;
for (key in totalFields) {
// console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue)
if (totalFields[key].$modelValue !== '' && totalFields[key].$modelValue !== undefined && totalFields[key].$modelValue.length !== 0) {
showConfirmDialog = true;
}
}
if (showConfirmDialog) {
$mdDialog.show($mdDialog.confirm({
skipHide: true,
textContent: 'Are you sure you want to cancel this?',
ok: 'ok',
cancel: 'cancel'
})).then(function () {
$mdDialog.hide('Cancelled');
})
}
else {
$mdDialog.hide('Cancelled');
} }
} }
} }
...@@ -364,11 +369,20 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo ...@@ -364,11 +369,20 @@ 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; if (isDataUpdated() != true) {
addOrUpdateAccount(record,$scope.templateTitle,"U"); $mdDialog.show($mdDialog.alert({
$timeout(function(){updateGrid($scope.templateTitle, record)},200); 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);
}
}
} }
}; };
addOrUpdateAccount = function(record,action,flag){ addOrUpdateAccount = function(record,action,flag){
......
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