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,3 +1,5 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() { (function() {
'use strict'; 'use strict';
@ -35,7 +37,8 @@
}]; }];
/* Factory registration in Angular module */ /* Factory registration in Angular module */
angular.module('SOGo.ContactsUI').factory('sgAddressBook', AddressBook.$factory); angular.module('SOGo.ContactsUI')
.factory('sgAddressBook', AddressBook.$factory)
/** /**
* @memberof AddressBook * @memberof 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,4 +1,4 @@
/* -*- 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() {
@ -9,7 +9,7 @@
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) {
@ -29,31 +29,31 @@
.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', { .state('app.addressbook', {
url: "/addressbook/:addressbook_id", url: '/addressbook/:addressbookId',
views: { views: {
'menuContent': { menuContent: {
templateUrl: "addressbook.html", templateUrl: 'addressbook.html',
controller: 'AddressBookCtrl', controller: 'AddressBookCtrl',
resolve: { resolve: {
stateAddressbook: function($stateParams, sgAddressBook) { stateAddressbook: function($stateParams, sgAddressBook) {
return sgAddressBook.$find($stateParams.addressbook_id); return sgAddressBook.$find($stateParams.addressbookId);
} }
} }
} }
@ -61,38 +61,42 @@
}) })
.state('app.newCard', { .state('app.newCard', {
url: "/addressbook/:addressbook_id/:contact_type/new", url: '/addressbook/:addressbookId/:contactType/new',
views: { views: {
'menuContent': { menuContent: {
templateUrl: "card.html", templateUrl: 'card.html',
controller: 'CardCtrl', controller: 'CardCtrl',
resolve: { resolve: {
stateCard: function($rootScope, $stateParams, sgAddressBook, sgCard) { stateCard: ['$rootScope', '$stateParams', 'sgAddressBook', 'sgCard', function($rootScope, $stateParams, sgAddressBook, Card) {
var tag = 'v' + $stateParams.contact_type; var tag = 'v' + $stateParams.contactType;
if (!$rootScope.addressbook) { if (!$rootScope.addressbook) {
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbook_id); $rootScope.addressbook = sgAddressBook.$find($stateParams.addressbookId);
} }
return new sgCard({ 'pid': $stateParams.addressbook_id, return new Card(
'tag': tag, {
'isNew': true }); pid: $stateParams.addressbookId,
tag: tag,
isNew: true
} }
);
}]
} }
} }
} }
}) })
.state('app.card', { .state('app.card', {
url: "/addressbook/:addressbook_id/:card_id", 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) { stateCard: function($rootScope, $stateParams, sgAddressBook) {
if (!$rootScope.addressbook) { if (!$rootScope.addressbook) {
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbook_id); $rootScope.addressbook = sgAddressBook.$find($stateParams.addressbookId);
} }
return $rootScope.addressbook.$getCard($stateParams.card_id); return $rootScope.addressbook.$getCard($stateParams.cardId);
} }
} }
} }
@ -123,9 +127,13 @@
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,
isEditable: true,
isRemote: false
}
);
AddressBook.$add(addressbook); AddressBook.$add(addressbook);
} }
}); });
@ -160,7 +168,7 @@
l(data.error)); l(data.error));
}); });
return true; return true;
}, }
// cancel: function() { // cancel: function() {
// }, // },
}); });
@ -171,9 +179,9 @@
.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)
@ -191,7 +199,7 @@
$rootScope.addressbook.cards = []; $rootScope.addressbook.cards = [];
} }
} }
$scope.search.last_filter = $scope.search.filter; $scope.search.lastFilter = $scope.search.filter;
}; };
}]) }])
@ -199,14 +207,14 @@
$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,
@ -225,11 +233,11 @@
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 { else {
$rootScope.addressbook.card = angular.copy($scope.master_card); $rootScope.addressbook.card = angular.copy($scope.masterCard);
$scope.$cardEditorModal.hide() $scope.$cardEditorModal.hide()
} }
}; };
@ -238,15 +246,15 @@
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() {
@ -265,12 +273,13 @@
if (form.$valid) { if (form.$valid) {
$rootScope.addressbook.card.$save() $rootScope.addressbook.card.$save()
.then(function(data) { .then(function(data) {
var i, card;
delete $rootScope.addressbook.card.isNew; delete $rootScope.addressbook.card.isNew;
var i = _.indexOf(_.pluck($rootScope.addressbook.cards, 'id'), $rootScope.addressbook.card.id); i = _.indexOf(_.pluck($rootScope.addressbook.cards, 'id'), $rootScope.addressbook.card.id);
if (i < 0) { if (i < 0) {
// New card // New card
// Reload contacts list and show addressbook in which the card has been created // Reload contacts list and show addressbook in which the card has been created
var card = angular.copy($rootScope.addressbook.card); card = angular.copy($rootScope.addressbook.card);
$rootScope.addressbook = AddressBook.$find(data.pid); $rootScope.addressbook = AddressBook.$find(data.pid);
$rootScope.addressbook.card = card; $rootScope.addressbook.card = card;
} }
@ -300,7 +309,7 @@
// Delete modal editor // Delete modal editor
$scope.$cardEditorModal.remove(); $scope.$cardEditorModal.remove();
// 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 });
}, function(data, status) { }, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".', Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
card.$fullname())); card.$fullname()));