@aappddeevv/dynamics-client-ui
Version:
## What is it? A library to help you create great dynamics applications.
48 lines • 1.54 kB
JavaScript
;
/**
* Manages state and actions for Dynamics notifications at the form
* level (not attribute level). Hence, these are for user presentation
* so the text message should be relevant to a user.
*/
Object.defineProperty(exports, "__esModule", { value: true });
/** Module wide counter */
let counter = 0;
const getAndIncrement = () => {
const tmp = counter;
counter = counter + 1;
return tmp;
};
class NotificationManager {
constructor(getXrm) {
this.notifications = [];
this.add = (msg) => {
const xrm = this.getXrm();
if (xrm) {
const nt = msg.level;
const id = getAndIncrement().toString();
const worked = xrm.Page.ui.setFormNotification(msg.message, nt, id);
if (worked) {
if (msg.removeAfter && msg.removeAfter > 0) {
setTimeout(() => this.remove(id), msg.removeAfter * 1000);
}
return id;
}
return null;
}
return null;
};
this.remove = (id) => {
const xrm = this.getXrm();
if (xrm) {
return xrm.Page.ui.clearFormNotification(id);
}
return false;
};
this.clearAll = () => {
};
this.getXrm = getXrm;
}
}
exports.NotificationManager = NotificationManager;
exports.default = NotificationManager;
//# sourceMappingURL=NotificationManager.js.map