(js) Improve addressbook renaming

The AddressBook instance to list the cards is now the same as the one
from the list of addressbooks. Therefore, when renaming an addressbook,
the addressbook name in the list is automatically updated.
pull/101/head^2
Francis Lachapelle 2015-11-09 14:46:30 -05:00
parent dc3e42fd62
commit cc5cc30c24
4 changed files with 23 additions and 14 deletions

View File

@ -6,7 +6,7 @@
xmlns:const="http://www.skyrix.com/od/constant"
xmlns:label="OGo:label"
>
<md-dialog flex-sm="100">
<md-dialog flex="40" flex-md="60" flex-sm="90">
<md-toolbar>
<div class="md-toolbar-tools">
@ -33,10 +33,10 @@
</md-checkbox>
</md-dialog-content>
<div class="md-actions">
<md-dialog-actions>
<md-button type="button" ng-click="properties.close()"><var:string label:value="Cancel"/></md-button>
<md-button ng-click="properties.saveProperties()"><var:string label:value="Save"/></md-button>
</div>
</md-dialog-actions>
</md-dialog>
</container>

View File

@ -215,10 +215,12 @@
* @desc Extend instance with new data and compute additional attributes.
* @param {object} data - attributes of addressbook
*/
AddressBook.prototype.init = function(data) {
this.$isLoading = true;
this.$cards = [];
this.cards = [];
AddressBook.prototype.init = function(data, options) {
if (!this.$cards) {
this.$isLoading = true;
this.$cards = [];
this.cards = [];
}
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;

View File

@ -249,10 +249,13 @@
vm.close = close;
function saveProperties() {
vm.addressbook.$save();
// Refresh list instance
srcAddressBook.init(vm.addressbook.$omit());
$mdDialog.hide();
vm.addressbook.$save().then(function() {
// Refresh list instance
srcAddressBook.init(vm.addressbook.$omit());
$mdDialog.hide();
}, function() {
// TODO handle error
});
}
function close() {

View File

@ -102,9 +102,13 @@
/**
* @ngInject
*/
stateAddressbook.$inject = ['$stateParams', 'AddressBook'];
function stateAddressbook($stateParams, AddressBook) {
return AddressBook.$find($stateParams.addressbookId).$futureAddressBookData;
stateAddressbook.$inject = ['$stateParams', 'stateAddressbooks', 'AddressBook'];
function stateAddressbook($stateParams, stateAddressbooks, AddressBook) {
var addressbook = _.find(stateAddressbooks, function(addressbook) {
return addressbook.id == $stateParams.addressbookId;
});
addressbook.$reload();
return addressbook;
}
/**