Created
June 2, 2015 13:54
-
-
Save yesh0907/561f870cd77aa6696522 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.addContact = function(contact) { | |
$ionicPopup.show({ | |
template: '<input type="text" ng-model="data.contact" placeholder="Username">', | |
title: "Username of Contact that you wish to add: ", | |
scope: $scope, | |
buttons: [ | |
{ text: "Cancel" }, | |
{ | |
text: '<b>Save</b>', | |
type: 'button-positive', | |
onTap: function(e) { | |
if (!$scope.data.contact) { | |
e.preventDefault(); | |
} | |
else { | |
$scope.userNames = []; | |
var contacts = []; | |
for (var i = 1; i < 7; i++) { | |
//console.log($scope.users["simplelogin:"+i]); | |
$scope.userNames.push($scope.users["simplelogin:"+i].userData[0].name); | |
//contacts.push($scope.data.contacts[i-1].name); | |
//console.log($scope.data.contacts[i-1].name); | |
} | |
var match = false; | |
var counter = 0; | |
//console.log($scope.userNames); | |
for (var j = 0; j <= $scope.userNames.length; j++) { | |
//Contact Already Exsists... | |
//console.log(contacts[j-1]); | |
if ($scope.data.contact === contacts[j-1]) { | |
$ionicPopup.alert({ | |
title: "Contact Already Exsits" | |
}); | |
} | |
//Found A Match and Saved | |
else if ($scope.data.contact === $scope.userNames[j] && !match) { | |
match = true; | |
if ($scope.data.hasOwnProperty("contacts") !== true) { | |
$scope.data.contacts = []; | |
} | |
$scope.data.contacts.push({ | |
name: $scope.data.contact | |
}) | |
$scope.data.contact = ""; | |
} | |
//Could Not Find a Match | |
else if (counter >= $scope.userNames.length) { | |
$ionicPopup.alert({ | |
title: "No Match Found" | |
}); | |
$scope.data.contact = ""; | |
} | |
//Didn't find a match but still looking | |
else if ($scope.data.contact !== $scope.userNames[j] && !match) { | |
counter++; | |
//console.log("Counter: " + counter); | |
} | |
else if (match) { | |
console.log("Matched"); | |
$scope.data.contact = ""; | |
break; | |
} | |
// console.log(j); | |
// console.log($scope.userNames.length); | |
} | |
} | |
} | |
} | |
] | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment