Split AddressBooks list by type

The list of addressbook books is now splitted by type: personal
addressbooks, other's addressbooks (subscriptions) and global
addressbooks (from sogo.conf, per domain).

The main ui-view has been splitted and therefore an additional
controller has been created.

The constructor of the AddressBook model has been improved.
pull/91/head
Francis Lachapelle 2015-04-24 08:45:39 -04:00
parent 19c12add73
commit 96ebc32d8a
3 changed files with 332 additions and 241 deletions

View File

@ -11,7 +11,7 @@
title="name"
var:popup="isPopup">
<script type="text/javascript">
var contactFolders =<var:string value="contactFolders" const:escapeHTML="NO" />;
var contactFolders = <var:string value="contactFolders" const:escapeHTML="NO" />;
</script>
<!--
@ -148,137 +148,204 @@
<md-sidenav id="left-sidenav" class="md-sidenav-left md-whiteframe-z1" md-component-id="left" md-is-locked-open="isGtMedium" layout="column">
<var:component className="UIxSidenavToolbarTemplate" />
<md-content md-scroll-y="md-scroll-y" class="md-flex">
<md-list>
<md-list-item ng-repeat="folder in addressbooks track by folder.id"
ui-sref-active="sg-active"
ng-dblclick="edit($index)">
<i ng-class="{'md-icon-public': folder.isRemote, 'md-icon-contacts': folder.isEditable}"><!-- icon --></i>
<button class="md-button md-flex sg-item-name"
ng-show="editMode!=folder.id"
ng-click="select($index)"
ng-cloak="ng-cloak"
ui-sref="addressbook({addressbookId: folder.id})">{{folder.name}}</button>
<md-input-container
class="md-flex md-tile-content"
ng-show="editMode==folder.id">
<input class="folder-name" type="text"
ng-model="folder.name"
ng-cloak="ng-cloak"
ng-blur="save($index)"
sg-focus-on="addressBookName_{{$index}}"
sg-enter="save($index)"
sg-escape="revertEditing($index)"/>
</md-input-container>
<i class="md-icon-more-vert"
ng-show="currentFolderIsConfigurable(folder)"><!-- options --></i>
</md-list-item>
</md-list>
<md-toolbar class="md-medium-tall">
<div class="md-toolbar-tools md-toolbar-tools-bottom">
<md-button
class="iconButton sg-button-navicon"
label:aria-label="Subscribe to an Addressbook..."
sg-subscribe="contact"
sg-subscribe-on-select="subscribeToFolder(folderData)">
<i class="md-icon-folder-shared"><!-- icon --></i>
</md-button>
<md-button ng-click="newAddressbook()">
<i class="md-icon-add-circle"><!-- icon --></i>
</md-button>
</div>
</md-toolbar>
<!-- User's addressbooks -->
<section>
<md-subheader class="sg-md-subheader">
<div layout="row" layout-align="space-between center">
<span><var:string label:value="AddressBooks"/></span>
<md-button
class="iconButton"
label:aria-label="New Addressbook..."
ng-click="newAddressbook()">
<i class="md-icon-add-circle-outline"><!-- add --></i>
</md-button>
</div>
</md-subheader>
<md-list>
<md-list-item ng-repeat="folder in service.$addressbooks track by folder.id"
ui-sref-active="sg-active"
ng-dblclick="edit($index, folder)">
<i ng-class="{'md-icon-public': folder.isRemote, 'md-icon-contacts': folder.isEditable}"><!-- icon --></i>
<button class="md-button md-flex sg-item-name"
ng-show="editMode!=folder.id"
ng-click="select(folder)"
ng-cloak="ng-cloak"
ui-sref="app.addressbook({addressbookId: folder.id})">{{folder.name}}</button>
<md-input-container
class="md-flex md-tile-content"
ng-show="editMode==folder.id">
<input class="folder-name" type="text"
ng-model="folder.name"
ng-cloak="ng-cloak"
ng-blur="save($index, folder)"
sg-focus-on="addressBookName_{{folder.id}}"
sg-enter="save(folder)"
sg-escape="revertEditing(folder)"/>
</md-input-container>
<md-button class="iconButton" label:aria-label="Options"
ng-show="currentFolder.id==folder.id">
<i class="md-icon-more-vert"><!-- options --></i>
</md-button>
</md-list-item>
</md-list>
</section>
<!-- Subscriptions -->
<section>
<md-subheader class="sg-md-subheader">
<div layout="row" layout-align="space-between center">
<span><var:string label:value="Subscriptions"/></span>
<md-button
class="iconButton"
label:aria-label="Subscribe to an Addressbook..."
sg-subscribe="contact"
sg-subscribe-on-select="subscribeToFolder(folderData)">
<i class="md-icon-add-circle-outline"><!-- add --></i>
</md-button>
</div>
</md-subheader>
<md-list>
<md-list-item ng-repeat="folder in service.$subscriptions track by folder.id"
ui-sref-active="sg-active"
ng-dblclick="edit($index, folder)">
<i ng-class="{'md-icon-public': folder.isRemote, 'md-icon-contacts': folder.isEditable}"><!-- icon --></i>
<button class="md-button md-flex sg-item-name"
ng-show="editMode!=folder.id"
ng-click="select(folder)"
ng-cloak="ng-cloak"
ui-sref="app.addressbook({addressbookId: folder.id})">{{folder.name}}</button>
<md-input-container
class="md-flex md-tile-content"
ng-show="editMode==folder.id">
<input class="folder-name" type="text"
ng-model="folder.name"
ng-cloak="ng-cloak"
ng-blur="save($index, folder)"
sg-focus-on="addressBookName_{{folder.id}}"
sg-enter="save(folder)"
sg-escape="revertEditing(folder)"/>
</md-input-container>
<md-button class="iconButton" label:aria-label="Options"
ng-show="currentFolder.id==folder.id">
<i class="md-icon-more-vert"><!-- options --></i>
</md-button>
</md-list-item>
</md-list>
</section>
<!-- Remote/domain addressbooks -->
<section>
<md-subheader class="sg-md-subheader md-padding">
<var:string label:value="Global Addressbooks"/>
</md-subheader>
<md-list>
<md-list-item ng-repeat="folder in service.$remotes track by folder.id"
ui-sref-active="sg-active">
<i ng-class="{'md-icon-public': folder.isRemote, 'md-icon-contacts': folder.isEditable}"><!-- icon --></i>
<button class="md-button md-flex sg-item-name"
ng-click="select(folder)"
ng-cloak="ng-cloak"
ui-sref="app.addressbook({addressbookId: folder.id})">{{folder.name}}</button>
</md-list-item>
</md-list>
</section>
</md-content>
</md-sidenav>
<section layout="column" class="sg-app-content md-layout-fill">
<md-toolbar layout="column" layout-align="space-between start" class="md-tall toolbar-main">
<div class="md-toolbar-tools md-toolbar-tools-top sg-padded" layout="row" layout-align="space-between start">
<var:component className="UIxTopnavToolbarTemplate" />
</div>
<div class="md-toolbar-tools md-toolbar-tools-bottom" layout="row" layout-align="space-between center">
<div class="view-list cols-6 sg-padded" layout="row" layout-align="space-between center"
sg-search="addressbook.$filter(searchText, { search: searchField })">
<md-input-container class="sg-search-field-container">
<label style="color: white"><i class="md-icon-search"><!--icon--></i><var:string label:value="Search"/></label>
<input name="folderSearch" type="search" style="color: white"/>
</md-input-container>
<section layout="column" class="sg-app-content md-layout-fill" ui-view="addressbook"><!-- contacts list --></section>
</script>
<div class="sg-toolbar-group">
<md-select class="sg-toolbar-sort md-contrast-light">
<md-option value="name_or_address"><var:string label:value="Name or Email"/></md-option>
<md-option value="category"><var:string label:value="Category"/></md-option>
<md-option value="organization"><var:string label:value="Organization"/></md-option>
</md-select>
</div>
<script type="text/ng-template" id="addressbook">
<md-toolbar layout="column" layout-align="space-between start" class="md-tall toolbar-main">
<div class="md-toolbar-tools md-toolbar-tools-top sg-padded" layout="row" layout-align="space-between start">
<var:component className="UIxTopnavToolbarTemplate" />
</div>
<div class="md-toolbar-tools md-toolbar-tools-bottom" layout="row" layout-align="space-between center">
<div class="view-list cols-6 sg-padded" layout="row" layout-align="space-between center"
sg-search="addressbook.$filter(searchText, { search: searchField })">
<md-input-container class="sg-search-field-container">
<label style="color: white"><i class="md-icon-search"><!--icon--></i><var:string label:value="Search"/></label>
<input name="folderSearch" type="search" style="color: white"/>
</md-input-container>
<div class="sg-toolbar-group">
<md-select class="sg-toolbar-sort md-contrast-light">
<md-option value="name_or_address"><var:string label:value="Name or Email"/></md-option>
<md-option value="category"><var:string label:value="Category"/></md-option>
<md-option value="organization"><var:string label:value="Organization"/></md-option>
</md-select>
</div>
</div>
</md-toolbar>
<div layout="row" class="md-flex" layout-align="space-between">
<md-content class="view-list" id="contactsList">
<header class="sg-md-subheader">
<h2 class="sg-md-subhead-solo fg-sogoBlue-700">Contacts</h2>
</header>
<!-- Search field & special results
<input type="text" placeholder="Search" ng-model="search.filter" ng-keyup="doSearch($event)" />
<div ng-switch="search.status">
<div ng-switch-when="min-char" class="alert-bg">
<i class="icon-warning"></i><var:string label:value="Please enter at least three characters"/>
</div>
<div ng-switch-when="no-result" class="alert-bg">
<i class="icon-ion-search"></i><var:string label:value="No matching card"/>
</div>
<div ng-switch-when="remote-addressbook" ng-show="addressbook.cards.length == 0" class="alert-bg">
<i class="icon-ion-search"></i><var:string label:value="Initiate a search"/>
</div>
</div>
-->
<md-list vs-repeat="72" vs-scroll-parent="#contactsList">
<md-list-item ng-repeat="currentCard in addressbook.cards track by currentCard.id">
<div
ng-class="{_selected: card.id == currentCard.id}"
ng-click="select($index); toggleDetailView()"
layout="row"
flex="true">
<div class="sg-avatar" ng-show="currentCard.tag == 'vcard'">
<!--card avatar-->
</div>
<div class="sg-list-avatar" ng-show="currentCard.tag == 'vlist'">
<!--list avatar-->
</div>
<div class="sg-tile-content">
<a ui-sref="addressbook.card.view({addressbookId: addressbook.id, cardId: currentCard.id})">
<div class="sg-md-body-multi contact-name" ng-bind-html="currentCard.$fullname()"><!-- cn --></div>
<div class="sg-md-subhead-multi contact-email">{{currentCard.$preferredEmail()}}</div>
</a>
</div>
</div>
</md-toolbar>
<div layout="row" class="md-flex" layout-align="space-between">
<md-content class="view-list" id="contactsList">
<header class="sg-md-subheader sg-md-subheader--fixed">
<h2 class="sg-md-subhead-solo fg-sogoBlue-700">Contacts</h2>
</header>
<!-- Search field & special results
<input type="text" placeholder="Search" ng-model="search.filter" ng-keyup="doSearch($event)" />
<div ng-switch="search.status">
<div ng-switch-when="min-char" class="alert-bg">
<i class="icon-warning"></i><var:string label:value="Please enter at least three characters"/>
</div>
<div ng-switch-when="no-result" class="alert-bg">
<i class="icon-ion-search"></i><var:string label:value="No matching card"/>
</div>
<div ng-switch-when="remote-addressbook" ng-show="addressbook.cards.length == 0" class="alert-bg">
<i class="icon-ion-search"></i><var:string label:value="Initiate a search"/>
</div>
</div>
-->
<md-list vs-repeat="72" vs-scroll-parent="#contactsList">
<md-list-item ng-repeat="currentCard in addressbook.cards track by currentCard.id">
<div
ng-class="{_selected: card.id == currentCard.id}"
ng-click="select($index); toggleDetailView()"
layout="row"
flex="true">
<div class="sg-avatar" ng-show="currentCard.tag == 'vcard'">
<!--card avatar-->
</div>
</md-list-item>
</md-list>
</md-content>
<md-button class="iconButton md-fab md-fab--bottom md-accent
hide-sm" label:aria-label="New Contact" ng-click="newComponent()"><i class="md-icon-add"><!--icon--></i></md-button>
<!-- This extra container is used to animate views transitions
double quotes in ng-animate is not a typo -->
<div id="detailView" class="view-detail" layout="column">
<md-card class="viewer" ui-view="card"><!-- card view --></md-card>
</div>
<div class="sg-list-avatar" ng-show="currentCard.tag == 'vlist'">
<!--list avatar-->
</div>
<div class="sg-tile-content">
<a ui-sref="app.addressbook.card.view({addressbookId: addressbook.id, cardId: currentCard.id})">
<div class="sg-md-body-multi contact-name" ng-bind-html="currentCard.$fullname()"><!-- cn --></div>
<div class="sg-md-subhead-multi contact-email">{{currentCard.$preferredEmail()}}</div>
</a>
</div>
</div>
</md-list-item>
</md-list>
</md-content>
<md-button class="iconButton md-fab md-accent show-sm"
label:aria-label="New Contact" ng-click="newComponent()"><i class="md-icon-add"><!--icon--></i></md-button>
<md-button class="iconButton md-fab md-fab--bottom md-accent hide-sm"
label:aria-label="New Contact"
ng-click="newComponent()">
<i class="md-icon-add"><!--icon--></i>
</md-button>
<!-- This extra container is used to animate views transitions
double quotes in ng-animate is not a typo -->
<div id="detailView" class="view-detail" layout="column">
<md-card class="viewer" ui-view="card"><!-- card view --></md-card>
</div>
</section>
<md-button class="iconButton md-fab md-accent show-sm"
label:aria-label="New Contact"
ng-click="newComponent()">
<i class="md-icon-add"><!--icon--></i>
</md-button>
</div>
</script>
<!-- modal for addressbook sharing options -->
<script type="text/ng-template" id="UIxUserRightsEditor">
<var:component className="UIxContactsUserRightsEditor" />
</script>
<script type="text/ng-template" id="UIxContactViewTemplate">
<var:component className="UIxContactViewTemplate" />
</script>
<!-- modal for addressbook sharing options -->
<script type="text/ng-template" id="UIxUserRightsEditor">
<var:component className="UIxContactsUserRightsEditor" />
</script>
<script type="text/ng-template" id="UIxContactViewTemplate">
<var:component className="UIxContactViewTemplate" />
</script>

View File

@ -11,7 +11,7 @@
function AddressBook(futureAddressBookData) {
// Data is immediately available
if (typeof futureAddressBookData.then !== 'function') {
angular.extend(this, futureAddressBookData);
this.init(futureAddressBookData);
if (this.name && !this.id) {
// Create a new addressbook on the server
var newAddressBookData = AddressBook.$$resource.create('createFolder', this.name);
@ -78,19 +78,16 @@
*/
AddressBook.$add = function(addressbook) {
// Insert new addressbook at proper index
var sibling, i;
var list, sibling, i;
addressbook.isOwned = this.activeUser.isSuperUser || addressbook.owner == this.activeUser.login;
addressbook.isSubscription = addressbook.owner != this.activeUser.login;
sibling = _.find(this.$addressbooks, function(o) {
return (o.isRemote
|| (!addressbook.isSubscription && o.isSubscription)
list = addressbook.isSubscription? this.$subscriptions : this.$addressbooks;
sibling = _.find(list, function(o) {
return (addressbook.id == 'personal'
|| (o.id != 'personal'
&& o.isSubscription === addressbook.isSubscription
&& o.name.localeCompare(addressbook.name) === 1));
});
i = sibling ? _.indexOf(_.pluck(this.$addressbooks, 'id'), sibling.id) : 1;
this.$addressbooks.splice(i, 0, addressbook);
i = sibling ? _.indexOf(_.pluck(list, 'id'), sibling.id) : 1;
list.splice(i, 0, addressbook);
};
/**
@ -102,14 +99,18 @@
AddressBook.$findAll = function(data) {
var _this = this;
if (data) {
this.$addressbooks = data;
this.$addressbooks = [];
this.$subscriptions = [];
this.$remotes = [];
// Instanciate AddressBook objects
angular.forEach(this.$addressbooks, function(o, i) {
_this.$addressbooks[i] = new AddressBook(o);
// Add 'isOwned' and 'isSubscription' attributes based on active user (TODO: add it server-side?)
_this.$addressbooks[i].isSubscription = _this.$addressbooks[i].owner != _this.activeUser.login;
_this.$addressbooks[i].isOwned = _this.activeUser.isSuperUser
|| _this.$addressbooks[i].owner == _this.activeUser.login;
angular.forEach(data, function(o, i) {
var addressbook = new AddressBook(o);
if (addressbook.isRemote)
_this.$remotes.push(addressbook);
else if (addressbook.isSubscription)
_this.$subscriptions.push(addressbook);
else
_this.$addressbooks.push(addressbook);
});
}
return this.$addressbooks;
@ -138,15 +139,29 @@
var _this = this;
return AddressBook.$$resource.userResource(uid).fetch(path, 'subscribe').then(function(addressbookData) {
var addressbook = new AddressBook(addressbookData);
if (!_.find(_this.$addressbooks, function(o) {
if (!_.find(_this.$subscriptions, function(o) {
return o.id == addressbookData.id;
})) {
// Not already subscribed
AddressBook.$add(addressbook);
}
return addressbook;
});
};
/**
* @function init
* @memberof AddressBook.prototype
* @desc Extend instance with new data and compute additional attributes.
* @param {object} data - attributes of addressbook
*/
AddressBook.prototype.init = function(data) {
angular.extend(this, data);
// Add 'isOwned' and 'isSubscription' attributes based on active user (TODO: add it server-side?)
this.isOwned = AddressBook.activeUser.isSuperUser || this.owner == AddressBook.activeUser.login;
this.isSubscription = !this.isRemote && this.owner != AddressBook.activeUser.login;
};
/**
* @function $id
* @memberof AddressBook.prototype
@ -225,17 +240,22 @@
AddressBook.prototype.$delete = function() {
var _this = this,
d = AddressBook.$q.defer(),
list,
promise;
if (this.isSubscription)
if (this.isSubscription) {
promise = AddressBook.$$resource.fetch(this.id, 'unsubscribe');
else
list = AddressBook.$subscriptions;
}
else {
promise = AddressBook.$$resource.remove(this.id);
list = AddressBook.$addressbooks;
}
promise.then(function() {
var i = _.indexOf(_.pluck(AddressBook.$addressbooks, 'id'), _this.id);
AddressBook.$addressbooks.splice(i, 1);
d.resolve(true);
var i = _.indexOf(_.pluck(list, 'id'), _this.id);
list.splice(i, 1);
d.resolve();
}, function(data, status) {
d.reject(data);
});
@ -280,7 +300,7 @@
// Resolve the promise
this.$futureAddressBookData.then(function(data) {
AddressBook.$timeout(function() {
angular.extend(_this, data);
_this.init(data);
// Also extend AddressBook instance from data of addressbooks list.
// Will inherit attributes such as isEditable and isRemote.
angular.forEach(AddressBook.$findAll(), function(o, i) {

View File

@ -21,24 +21,36 @@
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('addressbook', {
url: '/:addressbookId',
.state('app', {
url: '/addressbooks',
abstract: true,
views: {
addressbooks: {
templateUrl: 'UIxContactFoldersView', // UI/Templates/Contacts/UIxContactFoldersView.wox
controller: 'AddressBookCtrl'
controller: 'AddressBooksCtrl'
}
},
resolve: {
stateAddressbooks: ['sgAddressBook', function(AddressBook) {
return AddressBook.$findAll(contactFolders);
}],
}]
}
})
.state('app.addressbook', {
url: '/:addressbookId',
views: {
addressbook: {
templateUrl: 'addressbook',
controller: 'AddressBookCtrl'
}
},
resolve: {
stateAddressbook: ['$stateParams', 'sgAddressBook', function($stateParams, AddressBook) {
return AddressBook.$find($stateParams.addressbookId);
}]
}
})
.state('addressbook.new', {
.state('app.addressbook.new', {
url: '/:contactType/new',
views: {
card: {
@ -54,7 +66,7 @@
}]
}
})
.state('addressbook.card', {
.state('app.addressbook.card', {
url: '/:cardId',
abstract: true,
views: {
@ -68,19 +80,19 @@
}]
}
})
.state('addressbook.card.view', {
.state('app.addressbook.card.view', {
url: '/view',
views: {
'card@addressbook': {
'card@app.addressbook': {
templateUrl: 'UIxContactViewTemplate', // UI/Templates/Contacts/UIxContactViewTemplate.wox
controller: 'CardCtrl'
}
}
})
.state('addressbook.card.editor', {
.state('app.addressbook.card.editor', {
url: '/edit',
views: {
'card@addressbook': {
'card@app.addressbook': {
templateUrl: 'UIxContactEditorTemplate', // UI/Templates/Contacts/UIxContactEditorTemplate.wox
controller: 'CardCtrl'
}
@ -88,26 +100,17 @@
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/personal');
$urlRouterProvider.otherwise('/addressbooks/personal');
}])
.controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$mdDialog', 'sgFocus', 'sgCard', 'sgAddressBook', 'sgDialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook', function($state, $scope, $rootScope, $stateParams, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) {
var currentAddressbook;
.controller('AddressBooksCtrl', ['$scope', '$rootScope', '$state', '$stateParams', '$timeout', '$mdDialog', 'sgFocus', 'sgCard', 'sgAddressBook', 'sgDialog', 'sgSettings', 'stateAddressbooks', function($scope, $rootScope, $state, $stateParams, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks) {
$scope.activeUser = Settings.activeUser;
// Resolved objects
$scope.addressbooks = stateAddressbooks;
$rootScope.addressbook = stateAddressbook;
// Adjust search status depending on addressbook type
currentAddressbook = _.find($scope.addressbooks, function(o) {
return o.id == $stateParams.addressbookId;
});
$scope.service = AddressBook;
// $scope functions
$scope.select = function(rowIndex) {
$scope.select = function(folder) {
$scope.editMode = false;
//$rootScope.currentFolder = folder;
};
$scope.newAddressbook = function(ev) {
$scope.editMode = false;
@ -154,62 +157,21 @@
}
}
};
$scope.newComponent = function(ev) {
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: true,
escapeToClose: true,
template:
'<md-dialog aria-label="Create component">' +
' <md-content>' +
' <div layout="column">' +
' <md-button ng-click="createContact()">' +
' Contact' +
' </md-button>' +
' <md-button ng-click="createList()">' +
' List' +
' </md-button>' +
' </div>' +
' </md-content>' +
'</md-dialog>',
locals: {
state: $state
},
controller: ComponentDialogController
});
function ComponentDialogController(scope, $mdDialog, state) {
scope.createContact = function() {
state.go('addressbook.new', { addressbookId: $scope.addressbook.id, contactType: 'card' });
$mdDialog.hide();
}
scope.createList = function() {
state.go('addressbook.new', { addressbookId: $scope.addressbook.id, contactType: 'list' });
$mdDialog.hide();
}
$scope.edit = function(index, folder) {
if (!folder.isRemote) {
$scope.editMode = folder.id;
$scope.originalAddressbook = angular.extend({}, folder.$omit());
focus('addressBookName_' + folder.id);
}
};
$scope.currentFolderIsConfigurable = function(folder) {
return ($scope.addressbook && $scope.addressbook.id == folder.id && !folder.isRemote);
};
$scope.edit = function(i) {
if (!$rootScope.addressbook.isRemote) {
if (angular.isUndefined(i)) {
i = _.indexOf(_.pluck($scope.addressbooks, 'id'), $rootScope.addressbook.id);
}
$scope.editMode = $rootScope.addressbook.id;
$scope.originalAddressbook = angular.extend({}, $scope.addressbook.$omit());
focus('addressBookName_' + i);
}
};
$scope.revertEditing = function(i) {
$scope.addressbooks[i].name = $scope.originalAddressbook.name;
$scope.revertEditing = function(folder) {
folder.name = $scope.originalAddressbook.name;
$scope.editMode = false;
};
$scope.save = function(i) {
var name = $scope.addressbooks[i].name;
if (name && name.length > 0) {
$scope.addressbook.$rename(name)
$scope.save = function(folder) {
var name = folder.name;
if (name && name.length > 0 && name != $scope.originalAddressbook.name) {
folder.$rename(name)
.then(function(data) {
$scope.editMode = false;
}, function(data, status) {
@ -218,31 +180,30 @@
}
};
$scope.confirmDelete = function() {
if ($scope.addressbook.isSubscription) {
if ($scope.currentFolder.isSubscription) {
// Unsubscribe without confirmation
$rootScope.addressbook.$delete()
$rootScope.currentFolder.$delete()
.then(function() {
$rootScope.addressbook = null;
$rootScope.currentFolder = null;
$state.go('app.addressbook', { addressbookId: 'personal' });
}, function(data, status) {
Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',
$rootScope.addressbook.name),
$rootScope.currentFolder.name),
l(data.error));
});
}
else {
Dialog.confirm(l('Warning'), l('Are you sure you want to delete the addressbook <em>%{0}</em>?',
$scope.addressbook.name))
.then(function(res) {
if (res) {
$rootScope.addressbook.$delete()
.then(function() {
$rootScope.addressbook = null;
}, function(data, status) {
Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',
$rootScope.addressbook.name),
l(data.error));
});
}
$scope.currentFolder.name))
.then(function() {
$rootScope.currentFolder.$delete()
.then(function() {
$rootScope.currentFolder = null;
}, function(data, status) {
Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',
$rootScope.currentFolder.name),
l(data.error));
});
});
}
};
@ -320,6 +281,49 @@
};
}])
.controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$mdDialog', 'sgFocus', 'sgCard', 'sgAddressBook', 'sgDialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook', function($state, $scope, $rootScope, $stateParams, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) {
var currentAddressbook;
$rootScope.currentFolder = stateAddressbook;
$scope.addressbook = stateAddressbook;
$scope.newComponent = function(ev) {
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: true,
escapeToClose: true,
template:
'<md-dialog aria-label="Create component">' +
' <md-content>' +
' <div layout="column">' +
' <md-button ng-click="createContact()">' +
' Contact' +
' </md-button>' +
' <md-button ng-click="createList()">' +
' List' +
' </md-button>' +
' </div>' +
' </md-content>' +
'</md-dialog>',
locals: {
state: $state
},
controller: ComponentDialogController
});
function ComponentDialogController(scope, $mdDialog, state) {
scope.createContact = function() {
state.go('app.addressbook.new', { addressbookId: $scope.addressbook.id, contactType: 'card' });
$mdDialog.hide();
}
scope.createList = function() {
state.go('app.addressbook.new', { addressbookId: $scope.addressbook.id, contactType: 'list' });
$mdDialog.hide();
}
}
};
}])
/**
* Controller to view and edit a card
*/
@ -372,7 +376,7 @@
// Update contacts list with new version of the Card object
$rootScope.addressbook.cards[i] = angular.copy($scope.card);
}
$state.go('addressbook.card.view', { cardId: $scope.card.id });
$state.go('app.addressbook.card.view', { cardId: $scope.card.id });
}, function(data, status) {
console.debug('failed');
});
@ -386,11 +390,11 @@
if ($scope.card.isNew) {
// Cancelling the creation of a card
$scope.card = null;
$state.go('addressbook', { addressbookId: $scope.addressbook.id });
$state.go('app.addressbook', { addressbookId: $scope.addressbook.id });
}
else {
// Cancelling the edition of an existing card
$state.go('addressbook.card.view', { cardId: $scope.card.id });
$state.go('app.addressbook.card.view', { cardId: $scope.card.id });
}
};
$scope.confirmDelete = function(card) {
@ -406,7 +410,7 @@
});
// Remove card object from scope
$scope.card = null;
$state.go('addressbook', { addressbookId: $scope.addressbook.id });
$state.go('app.addressbook', { addressbookId: $scope.addressbook.id });
}, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
card.$fullname()));