Hide the Add Contact button if we've got an invalid contact

This commit is contained in:
skjnldsv 2016-04-07 08:01:22 +02:00 committed by Thomas Müller
parent 7a77692a6d
commit 6498f49ab9
3 changed files with 20 additions and 6 deletions

View File

@ -318,7 +318,10 @@ li.addressBook-share-item span.shareeIdentifier {
/* Contacts List */
#new-contact-button {
margin: 14px auto; /* to have the same height than a contact*/
}

View File

@ -7,6 +7,7 @@ angular.module('contactsApp')
ctrl.contactList = [];
ctrl.searchTerm = '';
ctrl.show = true;
ctrl.invalid = false;
ctrl.t = {
addContact : t('contacts', 'Add contact'),
@ -149,6 +150,15 @@ angular.module('contactsApp')
}
});
// Watch if we have an invalid contact
$scope.$watch('ctrl.contactList[0].fullName()', function(fullName) {
if(fullName === '') {
ctrl.invalid = true;
} else {
ctrl.invalid = false;
}
});
ctrl.createContact = function() {
ContactService.create().then(function(contact) {
['tel', 'adr', 'email'].forEach(function(field) {

View File

@ -1,10 +1,11 @@
<div style="height: 90%" class="contacts-list" ng-class="{loading: ctrl.loading, 'mobile-show': ctrl.show}">
<button ng-show="!ctrl.loading" class="app-content-list-button" type="button" name="button" ng-click="ctrl.createContact()">{{ctrl.t.addContact}}</button>
<button ng-show="!ctrl.loading && !ctrl.invalid" class="app-content-list-button" id="new-contact-button"
type="button" name="button" ng-click="ctrl.createContact()">{{ctrl.t.addContact}}</button>
<div class="app-content-list-item"
ng-repeat="contact in ctrl.contactList = (ctrl.contacts | contactGroupFilter:ctrl.routeParams.gid | orderBy:'fullName()' | filter:query) track by contact.uid()"
contact data="contact"
ng-click="setSelected(contact.uid())"
ng-class="{active: contact.uid() === ctrl.getSelectedId()}">
ng-repeat="contact in ctrl.contactList = (ctrl.contacts | contactGroupFilter:ctrl.routeParams.gid | orderBy:'fullName()' | filter:query) track by contact.uid()"
contact data="contact"
ng-click="setSelected(contact.uid())"
ng-class="{active: contact.uid() === ctrl.getSelectedId()}">
</div>
<div ng-show="!ctrl.contactList.length && !ctrl.loading && ctrl.searchTerm !== ''">
<div id="emptycontent" class="emptycontent-search">