Don't allow duplicate GCS folder names

This commit is contained in:
Francis Lachapelle
2018-08-30 22:09:17 -04:00
parent 18df3bafb5
commit 3bdd90e2be
7 changed files with 75 additions and 33 deletions
@@ -581,15 +581,16 @@
* @returns a promise of the HTTP operation
*/
AddressBook.prototype.$rename = function(name) {
var i, list;
var _this = this, i, list;
list = this.isSubscription? AddressBook.$subscriptions : AddressBook.$addressbooks;
i = _.indexOf(_.map(list, 'id'), this.id);
this.name = name;
list.splice(i, 1);
AddressBook.$add(this);
return this.$save();
return this.$save().then(function() {
list.splice(i, 1);
_this.name = name;
AddressBook.$add(_this);
});
};
/**
@@ -17,6 +17,7 @@
vm.edit = edit;
vm.revertEditing = revertEditing;
vm.save = save;
vm.saving = false;
vm.confirmDelete = confirmDelete;
vm.importCards = importCards;
vm.showLinks = showLinks;
@@ -98,13 +99,18 @@
function save(folder) {
var name = folder.name;
if (name && name.length > 0) {
if (!vm.saving && name && name.length > 0) {
if (name != vm.originalAddressbook.name) {
vm.saving = true;
folder.$rename(name)
.then(function(data) {
vm.editMode = false;
}, function(data, status) {
Dialog.alert(l('Warning'), data);
}, function() {
revertEditing(folder);
vm.editMode = folder.id;
})
.finally(function() {
vm.saving = false;
});
}
else {