-
-
Save tiagogm/dd97f1b991b9c0f0c4f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {logger} from 'shared/components/utilities/logger'; | |
export function withSpinner(target, key, descriptor) { | |
let ptr = descriptor.value; | |
descriptor.value = function(...args) { | |
if (this.spinner) { | |
this.spinner.setLoading(true); | |
} | |
return ptr.apply(this, args) | |
.then(() => { | |
if (this.spinner) { | |
this.spinner.setLoading(false); | |
} | |
}); | |
}; | |
return descriptor; | |
} | |
export function catchErrors(target, key, descriptor) { | |
let ptr = descriptor.value; | |
descriptor.value = function(...args) { | |
return ptr.apply(this, args) | |
.catch(e => { | |
if (logger) { | |
logger.error(e); | |
} | |
if (this.toastr) { | |
this.toastr.genericError(); | |
} | |
}); | |
}; | |
return descriptor; | |
} | |
export function callModal(modalClass, transformer) { | |
return function(target, key, descriptor) { | |
let ptr = descriptor.value; | |
descriptor.value = function(...args) { | |
let transformed; | |
if (transformer) { | |
transformed = transformer.apply(this, args); | |
} | |
return this.modalService.show(modalClass, transformed) | |
.then(response => { | |
if (!response.wasCancelled) { | |
return ptr.call(this, response.output); | |
} | |
}); | |
}; | |
return descriptor; | |
}; | |
} | |
export function withConfirmation(message = 'AreYouSure') { | |
return function(target, key, descriptor) { | |
let ptr = descriptor.value; | |
descriptor.value = function(...args) { | |
return this.sweetAlert.confirmDialog(message) | |
.then(response => { | |
if (!response.wasCancelled) { | |
return ptr.apply(this, args); | |
} | |
}); | |
}; | |
return descriptor; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment