(feat) added date picker in contact editor + now handle correctly birthday

This commit is contained in:
Ludovic Marcotte
2015-08-20 10:29:47 -04:00
parent da81f7bc58
commit 65525dd33b
6 changed files with 48 additions and 14 deletions

View File

@@ -367,6 +367,8 @@ static Class SOGoContactGCSEntryK = Nil;
day = [date dayOfMonth];
[card setBday: [NSString stringWithFormat: @"%.4d%.2d%.2d", year, month, day]];
}
else
[card setBday: nil];
if ([[attributes objectForKey: @"addresses"] isKindOfClass: [NSArray class]])
{

View File

@@ -838,11 +838,10 @@
o = [card birthday];
if (o)
{
NSNumber *time = [NSNumber numberWithInt: [o timeIntervalSince1970]];
[data setObject: time forKey: @"birthday"];
[data setObject: [NSNumber numberWithInt: [o timeIntervalSince1970]]
forKey: @"birthday"];
}
// o = [card source];
// if (o) [data setObject: o forKey: @"source"];
o = [card tz];
if (o) [data setObject: o forKey: @"tz"];

View File

@@ -115,7 +115,6 @@
<md-icon>remove_circle</md-icon>
</md-button>
</div>
</div>
<div class="md-layout-margin" layout="row" layout-align="start center">
<md-button class="sg-icon-button" type="button" ng-click="editor.addEmail()">
@@ -128,12 +127,25 @@
</div>
<!-- birthday -->
<md-input-container>
<label>
<var:string label:value="Birthday"/>
</label>
<input type="date" ng-model="editor.card.birthday"/>
</md-input-container>
<div class="section">
<div layout="row" layout-align="space-between end" ng-show="editor.card.birthday">
<label>
<var:string label:value="Birthday"/>
</label>
<md-datepicker ng-model="editor.card.birthday"><!-- birthday --></md-datepicker>
<md-button class="sg-icon-button" type="button" ng-click="editor.card.$delete('birthday', -1)">
<md-icon>remove_circle</md-icon>
</md-button>
</div>
<div class="md-layout-margin" layout="row" layout-align="start center" ng-hide="editor.card.birthday">
<md-button class="sg-icon-button" type="button" ng-click="editor.addBirthday()">
<md-icon>add_circle</md-icon>
</md-button>
<label class="button-label">
<var:string label:value="Add Birthday"/>
</label>
</div>
</div>
<!-- phones -->
<div class="section">

View File

@@ -65,14 +65,14 @@
</header>
<section class="msg-body">
<div class="pseudo-input-container" ng-show="editor.card.birthday">
<div class="pseudo-input-container" ng-show="editor.card.$birthday().length">
<div class="key">
<label class="pseudo-input-label">
<var:string label:value="Birthday"/>
</label>
</div>
<div class="pseudo-input-field">
<span>{{editor.card.$birthday() | date}}</span>
<span>{{editor.card.$birthday()}}</span>
</div>
</div>

View File

@@ -176,6 +176,8 @@
if (index > -1 && this[attribute].length > index) {
this[attribute].splice(index, 1);
}
else
delete this[attribute];
}
else {
// No arguments -- delete card
@@ -274,8 +276,16 @@
return fullname;
};
/**
* @function $birthday
* @memberof Card.prototype
* @returns the formatted birthday object
*/
Card.prototype.$birthday = function() {
return new Date(this.birthday * 1000);
if (this.birthday) {
return [this.birthday.getFullYear(), this.birthday.getMonth() + 1, this.birthday.getDate()].join('/');
}
return '';
};
Card.prototype.$isCard = function() {
@@ -481,6 +491,13 @@
card[key] = value;
}
});
// We convert back our birthday object
if (card.birthday)
card.birthday = card.birthday.getTime()/1000;
else
card.birthday = 0;
return card;
};

View File

@@ -21,6 +21,7 @@
vm.categories = {};
vm.userFilterResults = [];
vm.addOrgUnit = addOrgUnit;
vm.addBirthday = addBirthday;
vm.addEmail = addEmail;
vm.addPhone = addPhone;
vm.addUrl = addUrl;
@@ -37,6 +38,9 @@
var i = vm.card.$addOrgUnit('');
focus('orgUnit_' + i);
}
function addBirthday() {
vm.card.birthday = new Date();
}
function addEmail() {
var i = vm.card.$addEmail('');
focus('email_' + i);