Added custom function for cancel and update , refactored Manage accounts

parent f4ecd677
...@@ -183,96 +183,42 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo ...@@ -183,96 +183,42 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo
$scope.closeSelectBox = function () { $scope.closeSelectBox = function () {
$mdSelect.hide(); $mdSelect.hide();
} }
isDataUpdated = function () {
if (dataToPass.action == "Update") { var confirmationMsg = function(){
$scope.previousData = {
AccountID: dataToPass.accountId, $mdDialog.show($mdDialog.confirm({
AccountName: dataToPass.accountName, skipHide: true,
IndustryType: dataToPass.industryType, textContent: 'Are you sure you want to cancel this?',
ClientAddress: dataToPass.clientAddress, ok: 'ok',
} cancel: 'cancel'
$scope.currentData = { })).then(function () {
AccountID: $scope.accountId, $mdDialog.hide('Cancelled');
AccountName: $scope.accountName, })
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;
var managerCheck = false;
if (exsistingMangersList.length === currentMangersList.length) {
var temp1 = [];
var temp2 = [];
for (var i in exsistingMangersList) {
temp1.push(exsistingMangersList[i].employeeId);
}
for (var j in currentMangersList) {
temp2.push(currentMangersList[j].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) {
//$mdDialog.hide('Cancelled');
return false;
}
return true;
}
} }
$scope.cancel = function () { $scope.cancel = function () {
var showConfirmDialog = false;
if (dataToPass.action == "Update") { if (dataToPass.action == "Add") {
if (isDataUpdated() != true) { var accountForm = myFactory.addFormDataCheck($scope.myForm);
if(Object.keys(accountForm).length == 0){
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
} }
else { else{
$mdDialog.show($mdDialog.confirm({ confirmationMsg();
skipHide: true,
textContent: 'Are you sure you want to cancel this?',
ok: 'ok',
cancel: 'cancel'
})).then(function () {
$mdDialog.hide('Cancelled');
})
} }
} }
else{
if (dataToPass.action == "Add") { var record = {"accountName":$scope.accountName,"industryType":$scope.industryType,"clientAddress":$scope.clientAddress,"deliveryManagers":$scope.managersSelectedList};
var totalFields = $scope.myForm.$$controls; var isFormUpated = myFactory.updateFormDataCheck($scope.myForm,record);
for (key in totalFields) { if(isFormUpated == true){
// console.log("Model value of" + key + " ==>" + totalFields[key].$modelValue) confirmationMsg();
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 { else{
$mdDialog.hide('Cancelled'); $mdDialog.hide('Cancelled');
} }
} }
} }
$scope.updateSearch = function (e) { $scope.updateSearch = function (e) {
e.stopPropagation(); e.stopPropagation();
$scope.getSelectedLead(); $scope.getSelectedLead();
...@@ -379,19 +325,23 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo ...@@ -379,19 +325,23 @@ 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;
if (isDataUpdated() != true) { record.deliveryManagers = managersSelectedList;
$mdDialog.show($mdDialog.alert({ var isFormUpated = myFactory.updateFormDataCheck($scope.myForm,record);
skipHide: true, if(isFormUpated == true){
title: 'Attention', record.deliveryManagers = $scope.accountManagers();
textContent: 'There is no data change to Update', addOrUpdateAccount(record, $scope.templateTitle, "U");
ok: 'ok' $timeout(function () { updateGrid($scope.templateTitle, record) }, 200);
})) }
} else{
else { $mdDialog.show($mdDialog.alert({
addOrUpdateAccount(record, $scope.templateTitle, "U"); skipHide: true,
$timeout(function () { updateGrid($scope.templateTitle, record) }, 200); title: 'Attention',
} textContent: 'There is no data change to Update',
ok: 'ok'
}))
}
record.id = $scope.parentData.id;
} }
} }
}; };
......
...@@ -162,7 +162,33 @@ myApp.factory('myFactory', function() { ...@@ -162,7 +162,33 @@ myApp.factory('myFactory', function() {
function getProfileUrl() { function getProfileUrl() {
return profileUrl; return profileUrl;
} }
function isPagination(records){
if(records.length > 10){
return true;
}
return false;
}
function addFormDataCheck(form){
var obj = {};
form.$$controls.forEach(function(field){
if(field.$name != "" && field.$name != undefined && field.$viewValue != "" && field.$viewValue != undefined){
obj[field.$name] = field.$viewValue ;
}
});
return obj;
}
function updateFormDataCheck(form,record){
var updatedForm = addFormDataCheck(form);
console.log(JSON.stringify(updatedForm) == JSON.stringify(record),JSON.stringify(updatedForm) , JSON.stringify(record));
if(JSON.stringify(updatedForm) == JSON.stringify(record)){
return false;
}
return true;
}
return { return {
setEmpId : setEmpId, setEmpId : setEmpId,
getEmpId : getEmpId, getEmpId : getEmpId,
...@@ -197,7 +223,10 @@ myApp.factory('myFactory', function() { ...@@ -197,7 +223,10 @@ myApp.factory('myFactory', function() {
setTemplateUrl : setTemplateUrl, setTemplateUrl : setTemplateUrl,
getTemplateUrl : getTemplateUrl, getTemplateUrl : getTemplateUrl,
setProfileUrl : setProfileUrl, setProfileUrl : setProfileUrl,
getProfileUrl : getProfileUrl getProfileUrl : getProfileUrl,
isPagination : isPagination,
addFormDataCheck : addFormDataCheck,
updateFormDataCheck : updateFormDataCheck
} }
}); });
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<b >Industry Type</b></td> <b >Industry Type</b></td>
<td colspan="8"> <td colspan="8">
<md-select ng-model="industryType" <md-select ng-model="industryType"
md-selected-text="getIndustryTypeSelected()" id="industryType"> md-selected-text="getIndustryTypeSelected()" id="industryType" name="industryType" >
<md-optgroup label="Industry Type"> <md-option <md-optgroup label="Industry Type"> <md-option
ng-value="industryType" ng-repeat="industryType in industryTypesList">{{industryType}}</md-option> ng-value="industryType" ng-repeat="industryType in industryTypesList">{{industryType}}</md-option>
</md-optgroup> </md-select> </md-optgroup> </md-select>
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
<b >Client Address</b></td> <b >Client Address</b></td>
<td colspan="8"> <td colspan="8">
<!-- <md-input-container class="md-block"> --> <!-- <md-input-container class="md-block"> -->
<textarea ng-model="clientAddress" id="clientAddress" placeholder = "Please enter the client address" style="width:100%" md-select-on-focus></textarea> <textarea ng-model="clientAddress" id="clientAddress" name="clientAddress" placeholder = "Please enter the client address" style="width:100%" md-select-on-focus></textarea>
<!-- </md-input-container> --> <!-- </md-input-container> -->
</td> </td>
</tr> </tr>
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
</div> </div>
</div> </div>
<div style="display: block; float: left; width: 100%;"> <div style="display: block; float: left; width: 100%;">
<md-select ng-model="managersSelectedList" data-md-container-class="selectHeader" id="selectManager" multiple="" md-selected-text="getSelectedLead()" ng-change="persistSelections()"> <md-select ng-model="managersSelectedList" data-md-container-class="selectHeader" name="deliveryManagers" id="selectManager" multiple="" md-selected-text="getSelectedLead()" ng-change="persistSelections()">
<md-select-header class="selectHeaderChild header-spacing" layout="column"> <md-select-header class="selectHeaderChild header-spacing" layout="column">
<input ng-model="searchTerm" type="search" id="search" ng-keydown="updateSearch($event)" ng-model-options="{debounce: {'default': 500, 'blur': 0}}" placeholder="Please Search for a manager" class="searchBoxHeader demo-header-searchbox md-text search-spacingleft" /> <input ng-model="searchTerm" type="search" id="search" ng-keydown="updateSearch($event)" ng-model-options="{debounce: {'default': 500, 'blur': 0}}" placeholder="Please Search for a manager" class="searchBoxHeader demo-header-searchbox md-text search-spacingleft" />
<span class="glyphicon glyphicon-remove close-mdselect" ng-click="closeSelectBox()"></span> <span class="glyphicon glyphicon-remove close-mdselect" ng-click="closeSelectBox()"></span>
......
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