Skip to content

Instantly share code, notes, and snippets.

@christopherthielen
Last active February 6, 2016 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopherthielen/9ce238841d28e4be395c to your computer and use it in GitHub Desktop.
Save christopherthielen/9ce238841d28e4be395c to your computer and use it in GitHub Desktop.
// contact is a RevertableModel which is injected from the state's resolve data.
export class EditContactController{
constructor($state, dialogService, Contacts, contact) {
this.$state = $state;
this.dialogService = dialogService;
this.Contacts = Contacts;
this.contact = contact.editableModel;
this.clearDirty = () => contact.clearDirty();
}
/** Ask for confirmation, then delete the contact, then go to the grandparent state ('contacts') */
remove(contact) {
this.dialogService.confirm(`Delete contact: ${contact.name.first} ${contact.name.last}`)
.then(() => this.Contacts.remove(contact))
.then(this.clearDirty)
.then(() => this.$state.go("^.^"));
}
/** Save the contact, then go to the grandparent state ('contacts') */
save(contact) {
this.Contacts.save(contact)
.then(this.clearDirty)
.then(() => this.$state.go("^", null, { reload: true }));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment