AddressBook JS model: rename $all to $findAll
This commit is contained in:
parent
629bb43ca8
commit
61539892c0
|
@ -24,7 +24,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
/* The factory we'll use to register with Angular */
|
||||
/**
|
||||
* @memberof AddressBook
|
||||
* @desc The factory we'll use to register with Angular
|
||||
* @returns the AddressBook constructor
|
||||
*/
|
||||
AddressBook.$factory = ['$q', '$timeout', 'sgSettings', 'sgResource', 'sgCard', function($q, $timeout, Settings, Resource, Card) {
|
||||
angular.extend(AddressBook, {
|
||||
$q: $q,
|
||||
|
@ -38,25 +42,7 @@
|
|||
|
||||
/* Factory registration in Angular module */
|
||||
angular.module('SOGo.ContactsUI')
|
||||
.factory('sgAddressBook', AddressBook.$factory)
|
||||
|
||||
/**
|
||||
* @memberof AddressBook
|
||||
* @desc Set or get the list of addressbooks. Will instanciate a new AddressBook object for each item.
|
||||
* @param {array} [data] - the metadata of the addressbooks
|
||||
* @returns the list of addressbooks
|
||||
*/
|
||||
AddressBook.$all = function(data) {
|
||||
var self = this;
|
||||
if (data) {
|
||||
this.$addressbooks = data;
|
||||
// Instanciate AddressBook objects
|
||||
angular.forEach(this.$addressbooks, function(o, i) {
|
||||
self.$addressbooks[i] = new AddressBook(o);
|
||||
});
|
||||
}
|
||||
return this.$addressbooks;
|
||||
};
|
||||
.factory('sgAddressBook', AddressBook.$factory);
|
||||
|
||||
/**
|
||||
* @memberof AddressBook
|
||||
|
@ -72,7 +58,30 @@
|
|||
this.$addressbooks.splice(i, 0, addressbook);
|
||||
};
|
||||
|
||||
/* Fetch list of cards and return an AddressBook instance */
|
||||
/**
|
||||
* @memberof AddressBook
|
||||
* @desc Set or get the list of addressbooks. Will instanciate a new AddressBook object for each item.
|
||||
* @param {array} [data] - the metadata of the addressbooks
|
||||
* @returns the list of addressbooks
|
||||
*/
|
||||
AddressBook.$findAll = function(data) {
|
||||
var self = this;
|
||||
if (data) {
|
||||
this.$addressbooks = data;
|
||||
// Instanciate AddressBook objects
|
||||
angular.forEach(this.$addressbooks, function(o, i) {
|
||||
self.$addressbooks[i] = new AddressBook(o);
|
||||
});
|
||||
}
|
||||
return this.$addressbooks;
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberOf AddressBook
|
||||
* @desc Fetch list of cards and return an AddressBook instance
|
||||
* @param {string} addressbook_id - the addressbook identifier
|
||||
* @returns an AddressBook object instance
|
||||
*/
|
||||
AddressBook.$find = function(addressbook_id) {
|
||||
var futureAddressBookData = AddressBook.$$resource.find(addressbook_id);
|
||||
|
||||
|
@ -184,7 +193,7 @@
|
|||
angular.extend(self, data);
|
||||
// Also extend AddressBook instance from data of addressbooks list.
|
||||
// Will inherit attributes such as isEditable and isRemote.
|
||||
angular.forEach(AddressBook.$all(), function(o, i) {
|
||||
angular.forEach(AddressBook.$findAll(), function(o, i) {
|
||||
if (o.id == self.id) {
|
||||
angular.extend(self, o);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,11 @@
|
|||
Card.$URL_TYPES = ['work', 'home', 'pref'];
|
||||
Card.$ADDRESS_TYPES = ['work', 'home'];
|
||||
|
||||
/* The factory we'll use to register with Angular */
|
||||
/**
|
||||
* @memberof Card
|
||||
* @desc The factory we'll use to register with Angular
|
||||
* @returns the Card constructor
|
||||
*/
|
||||
Card.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) {
|
||||
angular.extend(Card, {
|
||||
$$resource: new Resource(Settings.baseURL),
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
},
|
||||
resolve: {
|
||||
stateAddressbooks: ['sgAddressBook', function(AddressBook) {
|
||||
return AddressBook.$all(contactFolders);
|
||||
return AddressBook.$findAll(contactFolders);
|
||||
}],
|
||||
stateAddressbook: ['$stateParams', 'sgAddressBook', function($stateParams, AddressBook) {
|
||||
return AddressBook.$find($stateParams.addressbookId);
|
||||
|
|
|
@ -92,12 +92,12 @@
|
|||
templateUrl: 'card.html',
|
||||
controller: 'CardCtrl',
|
||||
resolve: {
|
||||
stateCard: function($rootScope, $stateParams, sgAddressBook) {
|
||||
stateCard: ['$rootScope', '$stateParams', 'sgAddressBook', function($rootScope, $stateParams, AddressBook) {
|
||||
if (!$rootScope.addressbook) {
|
||||
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbookId);
|
||||
$rootScope.addressbook = AddressBook.$find($stateParams.addressbookId);
|
||||
}
|
||||
return $rootScope.addressbook.$getCard($stateParams.cardId);
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@
|
|||
|
||||
.controller('AddressBooksCtrl', ['$scope', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', function($scope, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook) {
|
||||
// Initialize with data from template
|
||||
$scope.addressbooks = AddressBook.$all(contactFolders);
|
||||
$scope.addressbooks = AddressBook.$findAll(contactFolders);
|
||||
$scope.newAddressbook = function() {
|
||||
Dialog.prompt(l('Create addressbook'),
|
||||
l('Name of new addressbook'))
|
||||
|
|
Loading…
Reference in a new issue