(js) Add caching of cards
This commit is contained in:
parent
1667f8879d
commit
c9d9f7b47a
|
@ -471,8 +471,25 @@
|
||||||
* @returns a promise of the HTTP operation
|
* @returns a promise of the HTTP operation
|
||||||
*/
|
*/
|
||||||
AddressBook.prototype.$getCard = function(cardId) {
|
AddressBook.prototype.$getCard = function(cardId) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
return this.$id().then(function(addressbookId) {
|
return this.$id().then(function(addressbookId) {
|
||||||
return AddressBook.$Card.$find(addressbookId, cardId);
|
var fullCard,
|
||||||
|
cachedCard = _.find(_this.cards, function(data) {
|
||||||
|
return cardId == data.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (cachedCard && cachedCard.$futureCardData)
|
||||||
|
// Full card is available
|
||||||
|
return cachedCard;
|
||||||
|
|
||||||
|
fullCard = AddressBook.$Card.$find(addressbookId, cardId);
|
||||||
|
fullCard.$id().then(function(cardId) {
|
||||||
|
// Extend the Card object of the addressbook list with the full card description
|
||||||
|
if (cachedCard)
|
||||||
|
angular.extend(cachedCard, fullCard);
|
||||||
|
});
|
||||||
|
return fullCard;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -447,26 +447,20 @@
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
// Expose the promise
|
// Expose the promise
|
||||||
this.$futureCardData = futureCardData;
|
this.$futureCardData = futureCardData.then(function(data) {
|
||||||
|
_this.init(data);
|
||||||
// Resolve the promise
|
// Instanciate Card objects for list members
|
||||||
this.$futureCardData.then(function(data) {
|
angular.forEach(_this.refs, function(o, i) {
|
||||||
// Calling $timeout will force Angular to refresh the view
|
if (o.email) o.emails = [{value: o.email}];
|
||||||
return Card.$timeout(function() {
|
o.id = o.reference;
|
||||||
_this.init(data);
|
_this.refs[i] = new Card(o);
|
||||||
// Instanciate Card objects for list members
|
|
||||||
angular.forEach(_this.refs, function(o, i) {
|
|
||||||
if (o.email) o.emails = [{value: o.email}];
|
|
||||||
o.id = o.reference;
|
|
||||||
_this.refs[i] = new Card(o);
|
|
||||||
});
|
|
||||||
if (_this.birthday) {
|
|
||||||
_this.birthday = new Date(_this.birthday * 1000);
|
|
||||||
}
|
|
||||||
// Make a copy of the data for an eventual reset
|
|
||||||
_this.$shadowData = _this.$omit(true);
|
|
||||||
return _this;
|
|
||||||
});
|
});
|
||||||
|
if (_this.birthday) {
|
||||||
|
_this.birthday = new Date(_this.birthday * 1000);
|
||||||
|
}
|
||||||
|
// Make a copy of the data for an eventual reset
|
||||||
|
_this.$shadowData = _this.$omit(true);
|
||||||
|
return _this;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue