Improve JavaScript coding style

To comitted code now passes the Airbnb pattern using jscs
This commit is contained in:
Francis Lachapelle 2014-09-18 20:46:52 -04:00
parent 17ee62f4de
commit 3e2173db7a
6 changed files with 545 additions and 525 deletions

View file

@ -112,12 +112,12 @@
<!-- dropdown menu for new card split button --> <!-- dropdown menu for new card split button -->
<ul id="newListDrop" class="f-dropdown"> <ul id="newListDrop" class="f-dropdown">
<li><a class="tiny" data-ui-sref="addressbook.new({addressbook_id: addressbook.id, contact_type: 'list'})"><var:string label:value="New List"/></a></li> <li><a class="tiny" data-ui-sref="addressbook.new({addressbookId: addressbook.id, contactType: 'list'})"><var:string label:value="New List"/></a></li>
</ul> </ul>
<div id="addressbooksList" class="folders-list"> <div id="addressbooksList" class="folders-list">
<div class="newItemsToolbar"> <div class="newItemsToolbar">
<a class="button tiny radius split" data-ui-sref="addressbook.new({addressbook_id: addressbook.id, contact_type: 'card'})"><var:string label:value="New Card"/><span data-dropdown-toggle="#newListDrop"></span></a><br/> <a class="button tiny radius split" data-ui-sref="addressbook.new({addressbookId: addressbook.id, contactType: 'card'})"><var:string label:value="New Card"/><span data-dropdown-toggle="#newListDrop"></span></a><br/>
</div> </div>
<ul id="contactFolders"> <ul id="contactFolders">
<li data-ng-repeat="folder in addressbooks" <li data-ng-repeat="folder in addressbooks"
@ -125,7 +125,7 @@
data-ng-dblclick="edit($index)"> data-ng-dblclick="edit($index)">
<i class="icon" data-ng-class="{'icon-earth': folder.isRemote, 'icon-address-book': folder.isEditable}"><!-- icon --></i> <i class="icon" data-ng-class="{'icon-earth': folder.isRemote, 'icon-address-book': folder.isEditable}"><!-- icon --></i>
<form data-ng-submit="save($index)"> <form data-ng-submit="save($index)">
<a data-ui-sref="addressbook({addressbook_id: folder.id})" <a data-ui-sref="addressbook({addressbookId: folder.id})"
data-ng-click="select($index)" data-ng-click="select($index)"
data-ng-show="editMode!=folder.id" data-ng-show="editMode!=folder.id"
data-ng-cloak="ng-cloak">{{folder.name}}</a> data-ng-cloak="ng-cloak">{{folder.name}}</a>
@ -180,7 +180,7 @@
<li data-ng-repeat="card in addressbook.cards" <li data-ng-repeat="card in addressbook.cards"
data-ng-class="{_selected: addressbook.card.id == card.id}"> data-ng-class="{_selected: addressbook.card.id == card.id}">
<!-- <input type="checkbox" class="card-picture left"/> --> <!-- <input type="checkbox" class="card-picture left"/> -->
<a data-ui-sref="addressbook.card({addressbook_id: addressbook.id, card_id: card.id})"> <a data-ui-sref="addressbook.card({addressbookId: addressbook.id, cardId: card.id})">
<span class="card-picture" data-ng-switch="card.tag"> <span class="card-picture" data-ng-switch="card.tag">
<i data-ng-switch-when="vcard" class="icon-ion-ios7-person"><!-- card --></i> <i data-ng-switch-when="vcard" class="icon-ion-ios7-person"><!-- card --></i>
<i data-ng-switch-when="vlist" class="icon-ion-ios7-people"><!-- list --></i> <i data-ng-switch-when="vlist" class="icon-ion-ios7-people"><!-- list --></i>
@ -208,7 +208,7 @@
</div> </div>
<div class="buttonsToolbar"> <div class="buttonsToolbar">
<span data-ng-show="addressbook.isEditable"> <span data-ng-show="addressbook.isEditable">
<a class="button tiny radius" data-ui-sref="addressbook.editor({addressbook_id: addressbook.id, card_id: addressbook.card.id})"><i class="icon-pencil"><!-- edit --></i></a> <a class="button tiny radius" data-ui-sref="addressbook.editor({addressbookId: addressbook.id, cardId: addressbook.card.id})"><i class="icon-pencil"><!-- edit --></i></a>
<span class="button tiny radius alert" data-ng-click="confirmDelete(addressbook.card)"><i class="icon-trash"><!-- delete --></i></span> <span class="button tiny radius alert" data-ng-click="confirmDelete(addressbook.card)"><i class="icon-trash"><!-- delete --></i></span>
</span> </span>
</div> </div>

View file

@ -55,7 +55,7 @@
<ion-content class="has-header"> <ion-content class="has-header">
<ion-list> <ion-list>
<ion-item ng-repeat="addressbook in addressbooks" option-buttons="buttons" <ion-item ng-repeat="addressbook in addressbooks" option-buttons="buttons"
ui-sref="app.addressbook({addressbook_id: addressbook.id})" ui-sref="app.addressbook({addressbookId: addressbook.id})"
class="item-icon-left item-icon-right"> class="item-icon-left item-icon-right">
<i class="icon" ng-class="{'ion-earth': addressbook.isRemote}"><!-- public addressbook --></i> <i class="icon" ng-class="{'ion-earth': addressbook.isRemote}"><!-- public addressbook --></i>
{{addressbook.name}} {{addressbook.name}}
@ -71,7 +71,7 @@
<script type="text/ng-template" id="addressbook.html"> <script type="text/ng-template" id="addressbook.html">
<ion-view title="{{addressbook.name}}"> <ion-view title="{{addressbook.name}}">
<ion-nav-buttons side="right"> <ion-nav-buttons side="right">
<a class="button button-clear button-positive button-icon icon ion-ios7-plus-empty" ui-sref="app.newCard({ addressbook_id: addressbook.id, contact_type: 'card' })"><!-- new --></a> <a class="button button-clear button-positive button-icon icon ion-ios7-plus-empty" ui-sref="app.newCard({ addressbookId: addressbook.id, contactType: 'card' })"><!-- new --></a>
</ion-nav-buttons> </ion-nav-buttons>
<ion-content class="has-header"> <ion-content class="has-header">
<ion-list> <ion-list>
@ -86,7 +86,7 @@
<ion-list> <ion-list>
<ion-item class="item-icon-right" option-buttons="buttons" <ion-item class="item-icon-right" option-buttons="buttons"
data-ng-repeat="card in addressbook.cards" data-ng-repeat="card in addressbook.cards"
data-ui-sref="app.card({addressbook_id: addressbook.id, card_id: card.c_name})"> data-ui-sref="app.card({addressbookId: addressbook.id, cardId: card.c_name})">
{{card.c_cn || card.c_mail}} {{card.c_cn || card.c_mail}}
<i class="icon ion-ios7-arrow-right"><!-- right arrow icon --></i> <i class="icon ion-ios7-arrow-right"><!-- right arrow icon --></i>
</ion-item> </ion-item>

View file

@ -1,213 +1,216 @@
(function() { /* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
'use strict';
/** (function() {
* @name AddressBook 'use strict';
* @constructor
* @param {object} futureAddressBookData /**
*/ * @name AddressBook
function AddressBook(futureAddressBookData) { * @constructor
// Data is immediately available * @param {object} futureAddressBookData
if (typeof futureAddressBookData.then !== 'function') { */
angular.extend(this, futureAddressBookData); function AddressBook(futureAddressBookData) {
if (this.name && !this.id) { // Data is immediately available
// Create a new addressbook on the server if (typeof futureAddressBookData.then !== 'function') {
var newAddressBookData = AddressBook.$$resource.create('createFolder', this.name); angular.extend(this, futureAddressBookData);
this.$unwrap(newAddressBookData); if (this.name && !this.id) {
} // Create a new addressbook on the server
} var newAddressBookData = AddressBook.$$resource.create('createFolder', this.name);
else { this.$unwrap(newAddressBookData);
// The promise will be unwrapped first }
this.$unwrap(futureAddressBookData); }
} else {
// The promise will be unwrapped first
this.$unwrap(futureAddressBookData);
}
}
/* The factory we'll use to register with Angular */
AddressBook.$factory = ['$q', '$timeout', 'sgSettings', 'sgResource', 'sgCard', function($q, $timeout, Settings, Resource, Card) {
angular.extend(AddressBook, {
$q: $q,
$timeout: $timeout,
$$resource: new Resource(Settings.baseURL),
$Card: Card
});
return AddressBook; // return constructor
}];
/* 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;
};
/**
* @memberof AddressBook
* @desc Add a new addressbook to the static list of addressbooks
* @param {AddressBook} addressbook - an Addressbook object instance
*/
AddressBook.$add = function(addressbook) {
// Insert new addressbook at proper index
var sibling = _.find(this.$addressbooks, function(o) {
return (o.isRemote || (o.id != 'personal' && o.name.localeCompare(addressbook.name) === 1));
});
var i = sibling? _.indexOf(_.pluck(this.$addressbooks, 'id'), sibling.id) : 1;
this.$addressbooks.splice(i, 0, addressbook);
};
/* Fetch list of cards and return an AddressBook instance */
AddressBook.$find = function(addressbook_id) {
var futureAddressBookData = AddressBook.$$resource.find(addressbook_id);
return new AddressBook(futureAddressBookData);
};
/* Instance methods */
AddressBook.prototype.$id = function() {
return this.$futureAddressBookData.then(function(data) {
return data.id;
});
};
/**
* @function $filter
* @memberof AddressBook.prototype
* @desc Search for cards matching some criterias
* @param {string} search - the search string to match
* @param {hash} [options] - additional options to the query
* @returns a collection of Cards instances
*/
AddressBook.prototype.$filter = function(search, options) {
var self = this;
var params = { 'search': 'name_or_address',
'value': search,
'sort': 'c_cn',
'asc': 'true' };
if (options && options.excludeLists) {
params.excludeLists = true;
} }
/* The factory we'll use to register with Angular */ return this.$id().then(function(addressbook_id) {
AddressBook.$factory = ['$q', '$timeout', 'sgSettings', 'sgResource', 'sgCard', function($q, $timeout, Settings, Resource, Card) { var futureAddressBookData = AddressBook.$$resource.filter(addressbook_id, params);
angular.extend(AddressBook, { return futureAddressBookData.then(function(data) {
$q: $q, var cards;
$timeout: $timeout, if (options && options.dry) {
$$resource: new Resource(Settings.baseURL), // Don't keep a copy of the resulting cards.
$Card: Card // This is usefull when doing autocompletion.
}); cards = data.cards;
return AddressBook; // return constructor
}];
/* 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; else {
}; self.cards = data.cards;
cards = self.cards;
/**
* @memberof AddressBook
* @desc Add a new addressbook to the static list of addressbooks
* @param {AddressBook} addressbook - an Addressbook object instance
*/
AddressBook.$add = function(addressbook) {
// Insert new addressbook at proper index
var sibling = _.find(this.$addressbooks, function(o) {
return (o.isRemote || (o.id != 'personal' && o.name.localeCompare(addressbook.name) === 1));
});
var i = sibling? _.indexOf(_.pluck(this.$addressbooks, 'id'), sibling.id) : 1;
this.$addressbooks.splice(i, 0, addressbook);
};
/* Fetch list of cards and return an AddressBook instance */
AddressBook.$find = function(addressbook_id) {
var futureAddressBookData = AddressBook.$$resource.find(addressbook_id);
return new AddressBook(futureAddressBookData);
};
/* Instance methods */
AddressBook.prototype.$id = function() {
return this.$futureAddressBookData.then(function(data) {
return data.id;
});
};
/**
* @function $filter
* @memberof AddressBook.prototype
* @desc Search for cards matching some criterias
* @param {string} search - the search string to match
* @param {hash} [options] - additional options to the query
* @returns a collection of Cards instances
*/
AddressBook.prototype.$filter = function(search, options) {
var self = this;
var params = { 'search': 'name_or_address',
'value': search,
'sort': 'c_cn',
'asc': 'true' };
if (options && options.excludeLists) {
params.excludeLists = true;
} }
// Instanciate Card objects
return this.$id().then(function(addressbook_id) { angular.forEach(cards, function(o, i) {
var futureAddressBookData = AddressBook.$$resource.filter(addressbook_id, params); cards[i] = new AddressBook.$Card(o);
return futureAddressBookData.then(function(data) {
var cards;
if (options && options.dry) {
// Don't keep a copy of the resulting cards.
// This is usefull when doing autocompletion.
cards = data.cards;
}
else {
self.cards = data.cards;
cards = self.cards;
}
// Instanciate Card objects
angular.forEach(cards, function(o, i) {
cards[i] = new AddressBook.$Card(o);
});
return cards;
});
}); });
}; return cards;
});
});
};
/** /**
* @function $rename * @function $rename
* @memberof AddressBook.prototype * @memberof AddressBook.prototype
* @desc Rename the addressbook * @desc Rename the addressbook
* @param {string} name - the new name * @param {string} name - the new name
* @returns a promise of the HTTP operation * @returns a promise of the HTTP operation
*/ */
AddressBook.prototype.$rename = function(name) { AddressBook.prototype.$rename = function(name) {
var i = _.indexOf(_.pluck(AddressBook.$addressbooks, 'id'), this.id); var i = _.indexOf(_.pluck(AddressBook.$addressbooks, 'id'), this.id);
this.name = name; this.name = name;
AddressBook.$addressbooks.splice(i, 1);
AddressBook.$add(this);
return this.$save();
};
AddressBook.prototype.$delete = function() {
var self = this;
var d = AddressBook.$q.defer();
AddressBook.$$resource.remove(this.id)
.then(function() {
var i = _.indexOf(_.pluck(AddressBook.$addressbooks, 'id'), self.id);
AddressBook.$addressbooks.splice(i, 1); AddressBook.$addressbooks.splice(i, 1);
AddressBook.$add(this); d.resolve(true);
return this.$save(); }, function(data, status) {
}; d.reject(data);
});
return d.promise;
};
AddressBook.prototype.$delete = function() { AddressBook.prototype.$save = function() {
var self = this; return AddressBook.$$resource.save(this.id, this.$omit()).then(function (data) {
var d = AddressBook.$q.defer(); return data;
AddressBook.$$resource.remove(this.id) });
.then(function() { };
var i = _.indexOf(_.pluck(AddressBook.$addressbooks, 'id'), self.id);
AddressBook.$addressbooks.splice(i, 1);
d.resolve(true);
}, function(data, status) {
d.reject(data);
});
return d.promise;
};
AddressBook.prototype.$save = function() { AddressBook.prototype.$getCard = function(card_id) {
return AddressBook.$$resource.save(this.id, this.$omit()).then(function (data) { var self = this;
return data; return this.$id().then(function(addressbook_id) {
self.card = AddressBook.$Card.$find(addressbook_id, card_id);
return self.card;
});
};
AddressBook.prototype.$resetCard = function() {
this.$getCard(this.card.id);
};
// Unwrap a promise
AddressBook.prototype.$unwrap = function(futureAddressBookData) {
var self = this;
this.$futureAddressBookData = futureAddressBookData;
this.$futureAddressBookData.then(function(data) {
AddressBook.$timeout(function() {
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) {
if (o.id == self.id) {
angular.extend(self, o);
}
}); });
}; // Instanciate Card objects
angular.forEach(self.cards, function(o, i) {
AddressBook.prototype.$getCard = function(card_id) { self.cards[i] = new AddressBook.$Card(o);
var self = this;
return this.$id().then(function(addressbook_id) {
self.card = AddressBook.$Card.$find(addressbook_id, card_id);
return self.card;
}); });
}; });
}, function(data) {
angular.extend(self, data);
self.isError = true;
});
};
AddressBook.prototype.$resetCard = function() { // $omit returns a sanitized object used to send to the server
this.$getCard(this.card.id); AddressBook.prototype.$omit = function() {
}; var addressbook = {};
angular.forEach(this, function(value, key) {
// Unwrap a promise if (key != 'constructor' &&
AddressBook.prototype.$unwrap = function(futureAddressBookData) { key != 'card' &&
var self = this; key != 'cards' &&
key[0] != '$') {
this.$futureAddressBookData = futureAddressBookData; addressbook[key] = value;
this.$futureAddressBookData.then(function(data) { }
AddressBook.$timeout(function() { });
angular.extend(self, data); return addressbook;
// Also extend AddressBook instance from data of addressbooks list. };
// Will inherit attributes such as isEditable and isRemote.
angular.forEach(AddressBook.$all(), function(o, i) {
if (o.id == self.id) {
angular.extend(self, o);
}
});
// Instanciate Card objects
angular.forEach(self.cards, function(o, i) {
self.cards[i] = new AddressBook.$Card(o);
});
});
}, function(data) {
angular.extend(self, data);
self.isError = true;
});
};
// $omit returns a sanitized object used to send to the server
AddressBook.prototype.$omit = function() {
var addressbook = {};
angular.forEach(this, function(value, key) {
if (key != 'constructor' &&
key != 'card' &&
key != 'cards' &&
key[0] != '$') {
addressbook[key] = value;
}
});
return addressbook;
};
})(); })();

View file

@ -24,10 +24,10 @@
} }
} }
Card.$tel_types = ['work', 'home', 'cell', 'fax', 'pager']; Card.$TEL_TYPES = ['work', 'home', 'cell', 'fax', 'pager'];
Card.$email_types = ['work', 'home', 'pref']; Card.$EMAIL_TYPES = ['work', 'home', 'pref'];
Card.$url_types = ['work', 'home', 'pref']; Card.$URL_TYPES = ['work', 'home', 'pref'];
Card.$address_types = ['work', 'home']; Card.$ADDRESS_TYPES = ['work', 'home'];
/* The factory we'll use to register with Angular */ /* The factory we'll use to register with Angular */
Card.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) { Card.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) {
@ -39,11 +39,18 @@
return Card; // return constructor return Card; // return constructor
}]; }];
/* Factory registration in Angular module */ /**
* @module SOGo.ContactsUI
* @desc Factory registration of Card in Angular module
*/
angular.module('SOGo.ContactsUI') angular.module('SOGo.ContactsUI')
.factory('sgCard', Card.$factory) .factory('sgCard', Card.$factory)
// Directive to format a postal address /**
* @name sgAddress
* @memberof ContactsUI
* @desc Directive to format a postal address
*/
.directive('sgAddress', function() { .directive('sgAddress', function() {
return { return {
restrict: 'A', restrict: 'A',

View file

@ -15,7 +15,7 @@
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { .config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider $stateProvider
.state('addressbook', { .state('addressbook', {
url: '/:addressbook_id', url: '/:addressbookId',
views: { views: {
addressbooks: { addressbooks: {
templateUrl: 'addressbooks.html', templateUrl: 'addressbooks.html',
@ -27,12 +27,12 @@
return AddressBook.$all(contactFolders); return AddressBook.$all(contactFolders);
}], }],
stateAddressbook: ['$stateParams', 'sgAddressBook', function($stateParams, AddressBook) { stateAddressbook: ['$stateParams', 'sgAddressBook', function($stateParams, AddressBook) {
return AddressBook.$find($stateParams.addressbook_id); return AddressBook.$find($stateParams.addressbookId);
}] }]
} }
}) })
.state('addressbook.card', { .state('addressbook.card', {
url: '/:card_id', url: '/:cardId',
views: { views: {
card: { card: {
templateUrl: 'card.html', templateUrl: 'card.html',
@ -41,12 +41,12 @@
}, },
resolve: { resolve: {
stateCard: ['$stateParams', 'stateAddressbook', function($stateParams, stateAddressbook) { stateCard: ['$stateParams', 'stateAddressbook', function($stateParams, stateAddressbook) {
return stateAddressbook.$getCard($stateParams.card_id); return stateAddressbook.$getCard($stateParams.cardId);
}] }]
} }
}) })
.state('addressbook.new', { .state('addressbook.new', {
url: '/:contact_type/new', url: '/:contactType/new',
views: { views: {
card: { card: {
templateUrl: 'cardEditor.html', templateUrl: 'cardEditor.html',
@ -55,14 +55,14 @@
}, },
resolve: { resolve: {
stateCard: ['$stateParams', 'stateAddressbook', 'sgCard', function($stateParams, stateAddressbook, Card) { stateCard: ['$stateParams', 'stateAddressbook', 'sgCard', function($stateParams, stateAddressbook, Card) {
var tag = 'v' + $stateParams.contact_type; var tag = 'v' + $stateParams.contactType;
stateAddressbook.card = new Card({ pid: $stateParams.addressbook_id, tag: tag }); stateAddressbook.card = new Card({ pid: $stateParams.addressbookId, tag: tag });
return stateAddressbook.card; return stateAddressbook.card;
}] }]
} }
}) })
.state('addressbook.editor', { .state('addressbook.editor', {
url: '/:card_id/edit', url: '/:cardId/edit',
views: { views: {
card: { card: {
templateUrl: 'cardEditor.html', templateUrl: 'cardEditor.html',
@ -71,7 +71,7 @@
}, },
resolve: { resolve: {
stateCard: ['$stateParams', 'stateAddressbook', function($stateParams, stateAddressbook) { stateCard: ['$stateParams', 'stateAddressbook', function($stateParams, stateAddressbook) {
return stateAddressbook.$getCard($stateParams.card_id); return stateAddressbook.$getCard($stateParams.cardId);
}] }]
} }
}); });
@ -100,19 +100,20 @@
}]) }])
.controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$modal', 'sgFocus', 'sgCard', 'sgAddressBook', 'sgDialog', 'stateAddressbooks', 'stateAddressbook', function($state, $scope, $rootScope, $stateParams, $timeout, $modal, focus, Card, AddressBook, Dialog, stateAddressbooks, stateAddressbook) { .controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$modal', 'sgFocus', 'sgCard', 'sgAddressBook', 'sgDialog', 'stateAddressbooks', 'stateAddressbook', function($state, $scope, $rootScope, $stateParams, $timeout, $modal, focus, Card, AddressBook, Dialog, stateAddressbooks, stateAddressbook) {
var addressbookEntry; var currentAddressbook;
// $scope objects // Resolve objects
$scope.search = { status: null, filter: null, last_filter: null }; $scope.addressbooks = stateAddressbooks;
$rootScope.addressbooks = stateAddressbooks;
$rootScope.addressbook = stateAddressbook; $rootScope.addressbook = stateAddressbook;
// $scope objects
$scope.search = { status: null, filter: null, lastFilter: null };
// Adjust search status depending on addressbook type // Adjust search status depending on addressbook type
var o = _.find($rootScope.addressbooks, function(o) { currentAddressbook = _.find($scope.addressbooks, function(o) {
return o.id == $stateParams.addressbook_id; return o.id == $stateParams.addressbookId;
}); });
$scope.search.status = (o && o.isRemote)? 'remote-addressbook' : ''; $scope.search.status = (currentAddressbook && currentAddressbook.isRemote)? 'remote-addressbook' : '';
// $scope functions // $scope functions
$scope.select = function(rowIndex) { $scope.select = function(rowIndex) {
@ -138,14 +139,14 @@
$scope.edit = function(i) { $scope.edit = function(i) {
if (!$rootScope.addressbook.isRemote) { if (!$rootScope.addressbook.isRemote) {
if (angular.isUndefined(i)) { if (angular.isUndefined(i)) {
i = _.indexOf(_.pluck($rootScope.addressbooks, 'id'), $rootScope.addressbook.id); i = _.indexOf(_.pluck($scope.addressbooks, 'id'), $rootScope.addressbook.id);
} }
$scope.editMode = $rootScope.addressbook.id; $scope.editMode = $rootScope.addressbook.id;
focus('addressBookName_' + i); focus('addressBookName_' + i);
} }
}; };
$scope.save = function(i) { $scope.save = function(i) {
var name = $rootScope.addressbooks[i].name; var name = $scope.addressbooks[i].name;
if (name && name.length > 0) { if (name && name.length > 0) {
$scope.addressbook.$rename(name) $scope.addressbook.$rename(name)
.then(function(data) { .then(function(data) {
@ -184,7 +185,7 @@
}); });
}; };
$scope.doSearch = function(keyEvent) { $scope.doSearch = function(keyEvent) {
if ($scope.search.filter != $scope.search.last_filter) { if ($scope.search.filter != $scope.search.lastFilter) {
if ($scope.search.filter.length > 2) { if ($scope.search.filter.length > 2) {
$rootScope.addressbook.$filter($scope.search.filter).then(function(data) { $rootScope.addressbook.$filter($scope.search.filter).then(function(data) {
if (data.length == 0) if (data.length == 0)
@ -194,10 +195,10 @@
}); });
} }
else if ($scope.search.filter.length == 0) { else if ($scope.search.filter.length == 0) {
$rootScope.addressbook = AddressBook.$find($stateParams.addressbook_id); $rootScope.addressbook = AddressBook.$find($stateParams.addressbookId);
// Extend resulting model instance with parameters from addressbooks listing // Extend resulting model instance with parameters from addressbooks listing
var o = _.find($rootScope.addressbooks, function(o) { var o = _.find($scope.addressbooks, function(o) {
return o.id == $stateParams.addressbook_id; return o.id == $stateParams.addressbookId;
}); });
$scope.search.status = (o.isRemote)? 'remote-addressbook' : ''; $scope.search.status = (o.isRemote)? 'remote-addressbook' : '';
} }
@ -206,32 +207,32 @@
$rootScope.addressbook.cards = []; $rootScope.addressbook.cards = [];
} }
} }
$scope.search.last_filter = $scope.search.filter; $scope.search.lastFilter = $scope.search.filter;
}; };
}]) }])
.controller('CardCtrl', ['$scope', '$rootScope', 'sgAddressBook', 'sgCard', 'sgDialog', 'sgFocus', '$state', '$stateParams', function($scope, $rootScope, AddressBook, Card, Dialog, focus, $state, $stateParams) { .controller('CardCtrl', ['$scope', '$rootScope', 'sgAddressBook', 'sgCard', 'sgDialog', 'sgFocus', '$state', '$stateParams', function($scope, $rootScope, AddressBook, Card, Dialog, focus, $state, $stateParams) {
$scope.allEmailTypes = Card.$email_types; $scope.allEmailTypes = Card.$EMAIL_TYPES;
$scope.allTelTypes = Card.$tel_types; $scope.allTelTypes = Card.$TEL_TYPES;
$scope.allUrlTypes = Card.$url_types; $scope.allUrlTypes = Card.$URL_TYPES;
$scope.allAddressTypes = Card.$address_types; $scope.allAddressTypes = Card.$ADDRESS_TYPES;
$rootScope.master_card = angular.copy($rootScope.addressbook.card); $rootScope.masterCard = angular.copy($rootScope.addressbook.card);
$scope.addOrgUnit = function() { $scope.addOrgUnit = function() {
var i = $rootScope.addressbook.card.$addOrgUnit(''); var i = $rootScope.addressbook.card.$addOrgUnit('');
focus('orgUnit_' + i); focus('orgUnit_' + i);
}; };
$scope.addCategory = function() { $scope.addCategory = function() {
var i = $rootScope.addressbook.card.$addCategory($scope.new_category); var i = $rootScope.addressbook.card.$addCategory('');
focus('category_' + i); focus('category_' + i);
}; };
$scope.addEmail = function() { $scope.addEmail = function() {
var i = $rootScope.addressbook.card.$addEmail($scope.new_email_type); var i = $rootScope.addressbook.card.$addEmail('');
focus('email_' + i); focus('email_' + i);
}; };
$scope.addPhone = function() { $scope.addPhone = function() {
var i = $rootScope.addressbook.card.$addPhone($scope.new_phone_type); var i = $rootScope.addressbook.card.$addPhone('');
focus('phone_' + i); focus('phone_' + i);
}; };
$scope.addUrl = function() { $scope.addUrl = function() {
@ -267,19 +268,19 @@
}; };
$scope.cancel = function() { $scope.cancel = function() {
$scope.reset(); $scope.reset();
delete $rootScope.master_card; delete $rootScope.masterCard;
if ($scope.addressbook.card.id) { if ($scope.addressbook.card.id) {
// Cancelling the edition of an existing card // Cancelling the edition of an existing card
$state.go('addressbook.card', { card_id: $scope.addressbook.card.id }); $state.go('addressbook.card', { cardId: $scope.addressbook.card.id });
} }
else { else {
// Cancelling the creation of a card // Cancelling the creation of a card
delete $rootScope.addressbook.card; delete $rootScope.addressbook.card;
$state.go('addressbook', { addressbook_id: $scope.addressbook.id }); $state.go('addressbook', { addressbookId: $scope.addressbook.id });
} }
}; };
$scope.reset = function() { $scope.reset = function() {
$rootScope.addressbook.card = angular.copy($rootScope.master_card); $rootScope.addressbook.card = angular.copy($rootScope.masterCard);
}; };
$scope.confirmDelete = function(card) { $scope.confirmDelete = function(card) {
Dialog.confirm(l('Warning'), Dialog.confirm(l('Warning'),

View file

@ -1,318 +1,327 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* JavaScript for SOGoContacts (mobile) */ /* JavaScript for SOGoContacts (mobile) */
(function() { (function() {
'use strict'; 'use strict';
angular.module('SOGo.Common', []); angular.module('SOGo.Common', []);
angular.module('SOGo.ContactsUI', ['ionic', 'SOGo.Common', 'SOGo.UIMobile']) angular.module('SOGo.ContactsUI', ['ionic', 'SOGo.Common', 'SOGo.UIMobile'])
.constant('sgSettings', { .constant('sgSettings', {
'baseURL': ApplicationBaseURL baseURL: ApplicationBaseURL
}) })
.run(function($ionicPlatform) { .run(function($ionicPlatform) {
$ionicPlatform.ready(function() { $ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs) // for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) { if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
} }
if (window.StatusBar) { if (window.StatusBar) {
// org.apache.cordova.statusbar required // org.apache.cordova.statusbar required
StatusBar.styleDefault(); StatusBar.styleDefault();
} }
}); });
}) })
.config(function($stateProvider, $urlRouterProvider) { .config(function($stateProvider, $urlRouterProvider) {
$stateProvider $stateProvider
.state('app', { .state('app', {
url: "/app", url: '/app',
abstract: true, abstract: true,
templateUrl: "menu.html", templateUrl: 'menu.html',
controller: 'AppCtrl' controller: 'AppCtrl'
}) })
.state('app.addressbooks', { .state('app.addressbooks', {
url: "/addressbooks", url: '/addressbooks',
views: { views: {
'menuContent': { menuContent: {
templateUrl: "addressbooks.html", templateUrl: 'addressbooks.html',
controller: 'AddressBooksCtrl' controller: 'AddressBooksCtrl'
} }
}
})
.state('app.addressbook', {
url: '/addressbook/:addressbookId',
views: {
menuContent: {
templateUrl: 'addressbook.html',
controller: 'AddressBookCtrl',
resolve: {
stateAddressbook: function($stateParams, sgAddressBook) {
return sgAddressBook.$find($stateParams.addressbookId);
} }
}) }
}
}
})
.state('app.addressbook', { .state('app.newCard', {
url: "/addressbook/:addressbook_id", url: '/addressbook/:addressbookId/:contactType/new',
views: { views: {
'menuContent': { menuContent: {
templateUrl: "addressbook.html", templateUrl: 'card.html',
controller: 'AddressBookCtrl', controller: 'CardCtrl',
resolve: { resolve: {
stateAddressbook: function($stateParams, sgAddressBook) { stateCard: ['$rootScope', '$stateParams', 'sgAddressBook', 'sgCard', function($rootScope, $stateParams, sgAddressBook, Card) {
return sgAddressBook.$find($stateParams.addressbook_id); var tag = 'v' + $stateParams.contactType;
} if (!$rootScope.addressbook) {
} $rootScope.addressbook = sgAddressBook.$find($stateParams.addressbookId);
}
return new Card(
{
pid: $stateParams.addressbookId,
tag: tag,
isNew: true
} }
} );
}) }]
}
}
}
})
.state('app.newCard', { .state('app.card', {
url: "/addressbook/:addressbook_id/:contact_type/new", url: '/addressbook/:addressbookId/:cardId',
views: { views: {
'menuContent': { menuContent: {
templateUrl: "card.html", templateUrl: 'card.html',
controller: 'CardCtrl', controller: 'CardCtrl',
resolve: { resolve: {
stateCard: function($rootScope, $stateParams, sgAddressBook, sgCard) { stateCard: function($rootScope, $stateParams, sgAddressBook) {
var tag = 'v' + $stateParams.contact_type; if (!$rootScope.addressbook) {
if (!$rootScope.addressbook) { $rootScope.addressbook = sgAddressBook.$find($stateParams.addressbookId);
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbook_id); }
} return $rootScope.addressbook.$getCard($stateParams.cardId);
return new sgCard({ 'pid': $stateParams.addressbook_id,
'tag': tag,
'isNew': true });
}
}
}
} }
}) }
}
}
});
.state('app.card', { // if none of the above states are matched, use this as the fallback
url: "/addressbook/:addressbook_id/:card_id", $urlRouterProvider.otherwise('/app/addressbooks');
views: {
'menuContent': {
templateUrl: "card.html",
controller: 'CardCtrl',
resolve: {
stateCard: function($rootScope, $stateParams, sgAddressBook) {
if (!$rootScope.addressbook) {
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbook_id);
}
return $rootScope.addressbook.$getCard($stateParams.card_id);
}
}
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/addressbooks');
}) })
.controller('AppCtrl', ['$scope', '$http', function($scope, $http) { .controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
$scope.UserLogin = UserLogin; $scope.UserLogin = UserLogin;
$scope.UserFolderURL = UserFolderURL; $scope.UserFolderURL = UserFolderURL;
$scope.ApplicationBaseURL = ApplicationBaseURL; $scope.ApplicationBaseURL = ApplicationBaseURL;
// $scope.logout = function(url) { // $scope.logout = function(url) {
// $http.get(url) // $http.get(url)
// .success(function(data, status, headers) { // .success(function(data, status, headers) {
// console.debug(headers); // console.debug(headers);
// }); // });
// }; // };
}]) }])
.controller('AddressBooksCtrl', ['$scope', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', function($scope, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook) { .controller('AddressBooksCtrl', ['$scope', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', function($scope, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook) {
// Initialize with data from template // Initialize with data from template
$scope.addressbooks = AddressBook.$all(contactFolders); $scope.addressbooks = AddressBook.$all(contactFolders);
$scope.newAddressbook = function() { $scope.newAddressbook = function() {
Dialog.prompt(l('Create addressbook'), Dialog.prompt(l('Create addressbook'),
l('Name of new addressbook')) l('Name of new addressbook'))
.then(function(res) { .then(function(res) {
if (res && res.length > 0) { if (res && res.length > 0) {
var addressbook = new AddressBook({ 'name': res, var addressbook = new AddressBook(
'isEditable': true, {
'isRemote': false }); name: res,
AddressBook.$add(addressbook); isEditable: true,
isRemote: false
}
);
AddressBook.$add(addressbook);
} }
}); });
}; };
$scope.edit = function(addressbook) { $scope.edit = function(addressbook) {
$ionicActionSheet.show({ $ionicActionSheet.show({
titleText: l('Modify your addressbook %{0}', addressbook.name), titleText: l('Modify your addressbook %{0}', addressbook.name),
buttons: [ buttons: [
{ text: l('Rename') } { text: l('Rename') }
], ],
destructiveText: l('Delete'), destructiveText: l('Delete'),
cancelText: l('Cancel'), cancelText: l('Cancel'),
buttonClicked: function(index) { buttonClicked: function(index) {
// Rename addressbook // Rename addressbook
Dialog.prompt(l('Rename addressbook'), Dialog.prompt(l('Rename addressbook'),
addressbook.name) addressbook.name)
.then(function(name) { .then(function(name) {
if (name && name.length > 0) { if (name && name.length > 0) {
addressbook.$rename(name); addressbook.$rename(name);
} }
}); });
return true; return true;
}, },
destructiveButtonClicked: function() { destructiveButtonClicked: function() {
// Delete addressbook // Delete addressbook
addressbook.$delete() addressbook.$delete()
.then(function() { .then(function() {
addressbook = null; addressbook = null;
}, function(data) { }, function(data) {
Dialog.alert(l('An error occured while deleting the addressbook "%{0}".', Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',
addressbook.name), addressbook.name),
l(data.error)); l(data.error));
}); });
return true; return true;
}, }
// cancel: function() { // cancel: function() {
// }, // },
}); });
$ionicListDelegate.closeOptionButtons(); $ionicListDelegate.closeOptionButtons();
}; };
}]) }])
.controller('AddressBookCtrl', ['$scope', '$rootScope', '$stateParams', '$state', 'sgAddressBook', 'sgCard', 'stateAddressbook', function($scope, $rootScope, $stateParams, $state, AddressBook, Card, stateAddressbook) { .controller('AddressBookCtrl', ['$scope', '$rootScope', '$stateParams', '$state', 'sgAddressBook', 'sgCard', 'stateAddressbook', function($scope, $rootScope, $stateParams, $state, AddressBook, Card, stateAddressbook) {
$rootScope.addressbook = stateAddressbook; $rootScope.addressbook = stateAddressbook;
$scope.search = { 'status': null, 'filter': null, 'last_filter': null }; $scope.search = { status: null, filter: null, lastFilter: null };
$scope.doSearch = function(keyEvent) { $scope.doSearch = function(keyEvent) {
if ($scope.search.last_filter != $scope.search.filter) { if ($scope.search.lastFilter != $scope.search.filter) {
if ($scope.search.filter.length > 2) { if ($scope.search.filter.length > 2) {
$rootScope.addressbook.$filter($scope.search.filter).then(function(data) { $rootScope.addressbook.$filter($scope.search.filter).then(function(data) {
if (data.length == 0) if (data.length == 0)
$scope.search.status = 'no-result'; $scope.search.status = 'no-result';
else else
$scope.search.status = ''; $scope.search.status = '';
}); });
} }
else if ($scope.search.filter.length == 0) { else if ($scope.search.filter.length == 0) {
$scope.searchStatus = ''; $scope.searchStatus = '';
$rootScope.addressbook = AddressBook.$find($rootScope.addressbook.id); $rootScope.addressbook = AddressBook.$find($rootScope.addressbook.id);
} }
else { else {
$scope.search.status = 'min-char'; $scope.search.status = 'min-char';
$rootScope.addressbook.cards = []; $rootScope.addressbook.cards = [];
} }
} }
$scope.search.last_filter = $scope.search.filter; $scope.search.lastFilter = $scope.search.filter;
}; };
}]) }])
.controller('CardCtrl', ['$scope', '$rootScope', '$state', '$stateParams', '$ionicModal', 'sgDialog', 'sgAddressBook', 'sgCard', 'stateCard', function($scope, $rootScope, $state, $stateParams, $ionicModal, Dialog, AddressBook, Card, stateCard) { .controller('CardCtrl', ['$scope', '$rootScope', '$state', '$stateParams', '$ionicModal', 'sgDialog', 'sgAddressBook', 'sgCard', 'stateCard', function($scope, $rootScope, $state, $stateParams, $ionicModal, Dialog, AddressBook, Card, stateCard) {
$rootScope.addressbook.card = stateCard; $rootScope.addressbook.card = stateCard;
$scope.UserFolderURL = UserFolderURL; $scope.UserFolderURL = UserFolderURL;
$scope.allEmailTypes = Card.$email_types; $scope.allEmailTypes = Card.$EMAIL_TYPES;
$scope.allTelTypes = Card.$tel_types; $scope.allTelTypes = Card.$TEL_TYPES;
$scope.allUrlTypes = Card.$url_types; $scope.allUrlTypes = Card.$URL_TYPES;
$scope.allAddressTypes = Card.$address_types; $scope.allAddressTypes = Card.$ADDRESS_TYPES;
$scope.edit = function() { $scope.edit = function() {
// Copy card to be able to cancel changes later // Copy card to be able to cancel changes later
$scope.master_card = angular.copy($rootScope.addressbook.card); $scope.masterCard = angular.copy($rootScope.addressbook.card);
// Build modal editor // Build modal editor
$ionicModal.fromTemplateUrl('cardEditor.html', { $ionicModal.fromTemplateUrl('cardEditor.html', {
scope: $scope, scope: $scope,
focusFirstInput: false focusFirstInput: false
}).then(function(modal) { }).then(function(modal) {
if ($scope.$cardEditorModal) { if ($scope.$cardEditorModal) {
// Delete previous modal // Delete previous modal
$scope.$cardEditorModal.remove(); $scope.$cardEditorModal.remove();
} }
$scope.$cardEditorModal = modal; $scope.$cardEditorModal = modal;
// Show modal // Show modal
$scope.$cardEditorModal.show(); $scope.$cardEditorModal.show();
}); });
}; };
$scope.cancel = function() { $scope.cancel = function() {
if ($rootScope.addressbook.card.isNew) { if ($rootScope.addressbook.card.isNew) {
$scope.$cardEditorModal.hide().then(function() { $scope.$cardEditorModal.hide().then(function() {
// Go back to addressbook // Go back to addressbook
$state.go('app.addressbook', { addressbook_id: $rootScope.addressbook.id }); $state.go('app.addressbook', { addressbookId: $rootScope.addressbook.id });
}); });
}
else {
$rootScope.addressbook.card = angular.copy($scope.master_card);
$scope.$cardEditorModal.hide()
}
};
$scope.addOrgUnit = function() {
var i = $rootScope.addressbook.card.$addOrgUnit('');
focus('orgUnit_' + i);
};
$scope.addCategory = function() {
var i = $rootScope.addressbook.card.$addCategory($scope.new_category);
focus('category_' + i);
};
$scope.addEmail = function() {
var i = $rootScope.addressbook.card.$addEmail($scope.new_email_type);
focus('email_' + i);
};
$scope.addPhone = function() {
var i = $rootScope.addressbook.card.$addPhone($scope.new_phone_type);
focus('phone_' + i);
};
$scope.addUrl = function() {
var i = $rootScope.addressbook.card.$addUrl('', '');
focus('url_' + i);
};
$scope.addAddress = function() {
var i = $rootScope.addressbook.card.$addAddress('', '', '', '', '', '', '', '');
focus('address_' + i);
};
$scope.addMember = function() {
var i = $rootScope.addressbook.card.$addMember('');
focus('ref_' + i);
};
$scope.save = function(form) {
if (form.$valid) {
$rootScope.addressbook.card.$save()
.then(function(data) {
delete $rootScope.addressbook.card.isNew;
var i = _.indexOf(_.pluck($rootScope.addressbook.cards, 'id'), $rootScope.addressbook.card.id);
if (i < 0) {
// New card
// Reload contacts list and show addressbook in which the card has been created
var card = angular.copy($rootScope.addressbook.card);
$rootScope.addressbook = AddressBook.$find(data.pid);
$rootScope.addressbook.card = card;
}
else {
// Update contacts list with new version of the Card object
$rootScope.addressbook.cards[i] = angular.copy($rootScope.addressbook.card);
}
// Close editor
$scope.$cardEditorModal.hide();
});
}
};
$scope.confirmDelete = function(card) {
Dialog.confirm(l('Warning'),
l('Are you sure you want to delete the card of <b>%{0}</b>?', card.$fullname()))
.then(function(res) {
if (res) {
// User has confirmed deletion
card.$delete()
.then(function() {
// Delete card from list of addressbook
$rootScope.addressbook.cards = _.reject($rootScope.addressbook.cards, function(o) {
return o.id == card.id;
});
// Delete card object
delete $rootScope.addressbook.card;
// Delete modal editor
$scope.$cardEditorModal.remove();
// Go back to addressbook
$state.go('app.addressbook', { addressbook_id: $rootScope.addressbook.id });
}, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
card.$fullname()));
});
}
});
};
if ($scope.addressbook.card && $scope.addressbook.card.isNew) {
// New contact
$scope.edit();
} }
else {
$rootScope.addressbook.card = angular.copy($scope.masterCard);
$scope.$cardEditorModal.hide()
}
};
$scope.addOrgUnit = function() {
var i = $rootScope.addressbook.card.$addOrgUnit('');
focus('orgUnit_' + i);
};
$scope.addCategory = function() {
var i = $rootScope.addressbook.card.$addCategory('');
focus('category_' + i);
};
$scope.addEmail = function() {
var i = $rootScope.addressbook.card.$addEmail('');
focus('email_' + i);
};
$scope.addPhone = function() {
var i = $rootScope.addressbook.card.$addPhone('');
focus('phone_' + i);
};
$scope.addUrl = function() {
var i = $rootScope.addressbook.card.$addUrl('', '');
focus('url_' + i);
};
$scope.addAddress = function() {
var i = $rootScope.addressbook.card.$addAddress('', '', '', '', '', '', '', '');
focus('address_' + i);
};
$scope.addMember = function() {
var i = $rootScope.addressbook.card.$addMember('');
focus('ref_' + i);
};
$scope.save = function(form) {
if (form.$valid) {
$rootScope.addressbook.card.$save()
.then(function(data) {
var i, card;
delete $rootScope.addressbook.card.isNew;
i = _.indexOf(_.pluck($rootScope.addressbook.cards, 'id'), $rootScope.addressbook.card.id);
if (i < 0) {
// New card
// Reload contacts list and show addressbook in which the card has been created
card = angular.copy($rootScope.addressbook.card);
$rootScope.addressbook = AddressBook.$find(data.pid);
$rootScope.addressbook.card = card;
}
else {
// Update contacts list with new version of the Card object
$rootScope.addressbook.cards[i] = angular.copy($rootScope.addressbook.card);
}
// Close editor
$scope.$cardEditorModal.hide();
});
}
};
$scope.confirmDelete = function(card) {
Dialog.confirm(l('Warning'),
l('Are you sure you want to delete the card of <b>%{0}</b>?', card.$fullname()))
.then(function(res) {
if (res) {
// User has confirmed deletion
card.$delete()
.then(function() {
// Delete card from list of addressbook
$rootScope.addressbook.cards = _.reject($rootScope.addressbook.cards, function(o) {
return o.id == card.id;
});
// Delete card object
delete $rootScope.addressbook.card;
// Delete modal editor
$scope.$cardEditorModal.remove();
// Go back to addressbook
$state.go('app.addressbook', { addressbookId: $rootScope.addressbook.id });
}, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
card.$fullname()));
});
}
});
};
if ($scope.addressbook.card && $scope.addressbook.card.isNew) {
// New contact
$scope.edit();
}
}]); }]);
})(); })();