Added custom function for cancel and update , refactored Manage accounts

parent f4ecd677
......@@ -183,96 +183,42 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo
$scope.closeSelectBox = function () {
$mdSelect.hide();
}
isDataUpdated = function () {
if (dataToPass.action == "Update") {
$scope.previousData = {
AccountID: dataToPass.accountId,
AccountName: dataToPass.accountName,
IndustryType: dataToPass.industryType,
ClientAddress: dataToPass.clientAddress,
}
$scope.currentData = {
AccountID: $scope.accountId,
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;
}
var confirmationMsg = function(){
$mdDialog.show($mdDialog.confirm({
skipHide: true,
textContent: 'Are you sure you want to cancel this?',
ok: 'ok',
cancel: 'cancel'
})).then(function () {
$mdDialog.hide('Cancelled');
})
}
$scope.cancel = function () {
var showConfirmDialog = false;
if (dataToPass.action == "Update") {
if (isDataUpdated() != true) {
if (dataToPass.action == "Add") {
var accountForm = myFactory.addFormDataCheck($scope.myForm);
if(Object.keys(accountForm).length == 0){
$mdDialog.hide('Cancelled');
}
else {
$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{
confirmationMsg();
}
}
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{
var record = {"accountName":$scope.accountName,"industryType":$scope.industryType,"clientAddress":$scope.clientAddress,"deliveryManagers":$scope.managersSelectedList};
var isFormUpated = myFactory.updateFormDataCheck($scope.myForm,record);
if(isFormUpated == true){
confirmationMsg();
}
else {
else{
$mdDialog.hide('Cancelled');
}
}
}
$scope.updateSearch = function (e) {
e.stopPropagation();
$scope.getSelectedLead();
......@@ -379,19 +325,23 @@ myApp.controller("assignAccountsController",function($scope, myFactory, $mdDialo
else{
$scope.alertMsg = "";
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) {
$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);
}
record.deliveryManagers = managersSelectedList;
var isFormUpated = myFactory.updateFormDataCheck($scope.myForm,record);
if(isFormUpated == true){
record.deliveryManagers = $scope.accountManagers();
addOrUpdateAccount(record, $scope.templateTitle, "U");
$timeout(function () { updateGrid($scope.templateTitle, record) }, 200);
}
else{
$mdDialog.show($mdDialog.alert({
skipHide: true,
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() {
function getProfileUrl() {
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 {
setEmpId : setEmpId,
getEmpId : getEmpId,
......@@ -197,7 +223,10 @@ myApp.factory('myFactory', function() {
setTemplateUrl : setTemplateUrl,
getTemplateUrl : getTemplateUrl,
setProfileUrl : setProfileUrl,
getProfileUrl : getProfileUrl
getProfileUrl : getProfileUrl,
isPagination : isPagination,
addFormDataCheck : addFormDataCheck,
updateFormDataCheck : updateFormDataCheck
}
});
......
......@@ -30,7 +30,7 @@
<b >Industry Type</b></td>
<td colspan="8">
<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
ng-value="industryType" ng-repeat="industryType in industryTypesList">{{industryType}}</md-option>
</md-optgroup> </md-select>
......@@ -41,7 +41,7 @@
<b >Client Address</b></td>
<td colspan="8">
<!-- <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> -->
</td>
</tr>
......@@ -55,7 +55,7 @@
</div>
</div>
<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">
<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>
......
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