Adding loading state and error message when saving measurements

This commit is contained in:
Bruno Alves de Faria committed 2017-02-15 17:49:32 -02:00
1 parent 5d8c608e70
commit 6b17deabcb
11 files changed
+129 -32

No files matched your search

+42 -15
View File
@@ -1,6 +1,7 @@
import { Template } from 'meteor/templating';
import { Blaze } from 'meteor/blaze';
import { _ } from 'meteor/underscore';
import { $ } from 'meteor/jquery';
import { OHIF } from 'meteor/ohif:core';
OHIF.ui.showDialog = (templateName, dialogData) => {
@@ -13,25 +14,51 @@ OHIF.ui.showDialog = (templateName, dialogData) => {
};
}
// Create a new promise to control the modal and store its resolve and reject callbacks
let promiseResolve;
let promiseReject;
const promise = new Promise((resolve, reject) => {
promiseResolve = resolve;
promiseReject = reject;
});
let promise;
let templateData;
if (dialogData && dialogData.promise instanceof Promise) {
// Use the given promise to control the modal
promise = dialogData.promise;
templateData = dialogData;
} else {
// Create a new promise to control the modal and store its resolve and reject callbacks
let promiseResolve;
let promiseReject;
promise = new Promise((resolve, reject) => {
promiseResolve = resolve;
promiseReject = reject;
});
// Render the dialog with the given template passing the promise object and callbacks
templateData = _.extend({}, dialogData, {
promise,
promiseResolve,
promiseReject
});
}
// Render the dialog with the given template passing the promise object and callbacks
const templateData = _.extend({}, dialogData, {
promise,
promiseResolve,
promiseReject
});
const view = Blaze.renderWithData(template, templateData, document.body);
const node = view.firstNode();
const $node = node && $(node);
let $modal;
if ($node && $node.hasClass('modal')) {
$modal = $node;
} else if ($node && $node.has('.modal')) {
$modal = $node.find('.modal:first');
}
// Destroy the created dialog view when the promise is either resolved or rejected
const dismissModal = () => Blaze.remove(view);
promise.then(dismissModal, dismissModal);
const dismissModal = () => {
if (dialogData.promise && $modal) {
$modal.one('hidden.bs.modal', () => Blaze.remove(view)).modal('hide');
} else {
Blaze.remove(view);
}
};
promise.then(dismissModal).catch(dismissModal);
// Return the promise to allow callbacks stacking from outside
return promise;