Contacts JS models: improve documentation

pull/91/head
Francis Lachapelle 2014-11-25 16:13:53 -05:00
parent 2f17e94fef
commit 0ee725b945
2 changed files with 39 additions and 11 deletions

View File

@ -6,7 +6,7 @@
/**
* @name AddressBook
* @constructor
* @param {object} futureAddressBookData
* @param {object} futureAddressBookData - either an object literal or a promise
*/
function AddressBook(futureAddressBookData) {
// Data is immediately available
@ -106,8 +106,8 @@
/**
* @memberOf AddressBook
* @desc Subscribe to another user's addressbook and add it to the list of addressbooks.
* @param {String} uid - user id
* @param {String} path - path of folder for specified user
* @param {string} uid - user id
* @param {string} path - path of folder for specified user
* @returns a promise of the HTTP query result
*/
AddressBook.$subscribe = function(uid, path) {
@ -193,6 +193,12 @@
return this.$save();
};
/**
* @function $delete
* @memberof AddressBook.prototype
* @desc Delete the addressbook from the server and the static list of addressbooks.
* @returns a promise of the HTTP operation
*/
AddressBook.prototype.$delete = function() {
var _this = this,
d = AddressBook.$q.defer(),
@ -213,19 +219,36 @@
return d.promise;
};
/**
* @function $save
* @memberof AddressBook.prototype
* @desc Save the addressbook to the server. This currently can only affect the name of the addressbook.
* @returns a promise of the HTTP operation
*/
AddressBook.prototype.$save = function() {
return AddressBook.$$resource.save(this.id, this.$omit()).then(function(data) {
return data;
});
};
/**
* @function $getCard
* @memberof AddressBook.prototype
* @desc Fetch the card attributes from the server.
* @returns a promise of the HTTP operation
*/
AddressBook.prototype.$getCard = function(cardId) {
return this.$id().then(function(addressbookId) {
return AddressBook.$Card.$find(addressbookId, cardId);
});
};
// Unwrap a promise
/**
* @function $unwrap
* @memberof AddressBook.prototype
* @desc Unwrap a promise and instanciate new Card objects using received data.
* @param {promise} futureAddressBookData - a promise of the AddressBook's data
*/
AddressBook.prototype.$unwrap = function(futureAddressBookData) {
var _this = this;
@ -257,7 +280,12 @@
});
};
// $omit returns a sanitized object used to send to the server
/**
* @function $omit
* @memberof AddressBook.prototype
* @desc Return a sanitized object used to send to the server.
* @return an object literal copy of the Addressbook instance
*/
AddressBook.prototype.$omit = function() {
var addressbook = {};
angular.forEach(this, function(value, key) {

View File

@ -39,7 +39,7 @@
*/
Card.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) {
angular.extend(Card, {
$$resource: new Resource(Settings.baseURL),
$$resource: new Resource(Settings.baseURL, Settings.activeUser),
$timeout: $timeout
});
@ -411,10 +411,10 @@
*/
Card.prototype.$unwrap = function(futureCardData) {
var _this = this;
if (futureCardData) {
// Expose the promise
this.$futureCardData = futureCardData;
}
// Expose the promise
this.$futureCardData = futureCardData;
// Resolve the promise
this.$futureCardData.then(function(data) {
// Calling $timeout will force Angular to refresh the view
@ -435,7 +435,7 @@
* @function $omit
* @memberof Card.prototype
* @desc Return a sanitized object used to send to the server.
* @param {boolean} deep - make a deep copy if true
* @param {Boolean} [deep] - make a deep copy if true
* @return an object literal copy of the Card instance
*/
Card.prototype.$omit = function(deep) {