|
@@ -408,3 +408,146 @@ function initPatientPresenceIndicator() {
|
|
|
}, 15000); // once in 15 seconds
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// not really the place for this!
|
|
|
+// find a better place to put this
|
|
|
+window.saveVisitForm = function(_trigger, _silent = false, _close = false) {
|
|
|
+ let form = $(_trigger).closest('form');
|
|
|
+
|
|
|
+ if (!_silent && !form[0].checkValidity()) {
|
|
|
+ form[0].reportValidity();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // add [data-name] values to payload
|
|
|
+ let dataField = form.find('[name="data"]').first();
|
|
|
+ let parsed = null;
|
|
|
+ if(dataField.val()) {
|
|
|
+ parsed = JSON.parse(dataField.val());
|
|
|
+ }
|
|
|
+ form.find('[data-name]').each(function() {
|
|
|
+ if(!parsed) parsed = {};
|
|
|
+
|
|
|
+ let keys = $(this).attr('data-name').split('->');
|
|
|
+ let currentNode = parsed;
|
|
|
+ for (let i = 0; i < keys.length; i++) {
|
|
|
+ if(i !== keys.length - 1) {
|
|
|
+ if(typeof currentNode[keys[i]] === 'undefined') {
|
|
|
+ currentNode[keys[i]] = {};
|
|
|
+ }
|
|
|
+ currentNode = currentNode[keys[i]];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if($(this).is(':checkbox')) {
|
|
|
+ currentNode[keys[i]] = $(this).prop('checked');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ currentNode[keys[i]] = $(this).val();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ if(parsed) {
|
|
|
+ dataField.val(JSON.stringify(parsed));
|
|
|
+ }
|
|
|
+
|
|
|
+ let closeOnSave = false, noteSection = form.closest('.note-section');
|
|
|
+ if($(_trigger).closest('[visit-moe]').is('[close-on-save]')) {
|
|
|
+ closeOnSave = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // disallow-if-value-same-as
|
|
|
+ let compareWith = false;
|
|
|
+ if(form.find('.disallow-if-value-same-as')) {
|
|
|
+ compareWith = $.trim(form.find('.disallow-if-value-same-as').text());
|
|
|
+ if(compareWith && parsed) {
|
|
|
+ if(!parsed.value) {
|
|
|
+ alert('Value cannot be empty!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ let newValue = $('<div/>').html(parsed.value).text().replace(/[^a-zA-Z0-9]/g, '');
|
|
|
+ if(newValue === '') {
|
|
|
+ alert('Value cannot be empty!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if(newValue === compareWith) {
|
|
|
+ alert('New value should be different from the previous value!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!_silent) showMask();
|
|
|
+
|
|
|
+ $.post(form.attr('url'), form.serialize(), _data => {
|
|
|
+ if(!hasResponseError(_data)) {
|
|
|
+ if(!_silent) {
|
|
|
+ hideMask();
|
|
|
+ if(typeof updateAllSegmentsInResponse !== 'undefined' && noteSection.length) {
|
|
|
+ updateAllSegmentsInResponse(_data);
|
|
|
+ if (closeOnSave) {
|
|
|
+ noteSection.removeClass('edit');
|
|
|
+ let segmentUid = form.find('[name="segmentUid"]').first();
|
|
|
+ segmentUid = segmentUid.length ? segmentUid.val() : false;
|
|
|
+ if (segmentUid) {
|
|
|
+ window.setTimeout(() => {
|
|
|
+ $('.note-tree-node>a[data-segment-uid="' + segmentUid + '"]').trigger('click');
|
|
|
+ }, 250);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($(_trigger).closest('[visit-moe]').closest('.stag-popup').length) {
|
|
|
+ refreshDynamicStagPopup();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(_close) {
|
|
|
+ closeStagPopup();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 'json');
|
|
|
+ return false;
|
|
|
+};
|
|
|
+window.initSegmentMoes = function(_parent) {
|
|
|
+
|
|
|
+ $('body')
|
|
|
+ .off('mousedown.visit-moe-outside-click')
|
|
|
+ .on('mousedown.visit-moe-outside-click', function (e) {
|
|
|
+ if ($(e.target).closest('[visit-moe]').length ||
|
|
|
+ $(e.target).closest('#create-shortcut-form').length ||
|
|
|
+ $(e.target).is('#create-shortcut-form') ||
|
|
|
+ $(e.target).is('.stag-shortcuts .sc') ||
|
|
|
+ $(e.target).closest('.ui-datepicker').length) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $('[visit-moe] [url]:not([show])').hide();
|
|
|
+ });
|
|
|
+
|
|
|
+ _parent.find('[visit-moe] [submit]')
|
|
|
+ .off('click.visit-moe-submit')
|
|
|
+ .on('click.visit-moe-submit', function() {
|
|
|
+ saveVisitForm(this);
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
+ _parent.find('[visit-moe]>a[start]')
|
|
|
+ .off('click.visit-moe-show')
|
|
|
+ .on('click.visit-moe-show', function () {
|
|
|
+ $('[visit-moe] [url]:not([show])').hide();
|
|
|
+ $(this)
|
|
|
+ .closest('[visit-moe]')
|
|
|
+ .find('form[url]')
|
|
|
+ .show();
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
+ _parent.find('[visit-moe] [cancel]')
|
|
|
+ .off('click.visit-moe-cancel')
|
|
|
+ .on('click.visit-moe-cancel', function() {
|
|
|
+ $(this).closest('[visit-moe]').find('[url]:not([show])').hide();
|
|
|
+ if($(this).closest('[visit-moe]').is('[close-on-cancel]')) {
|
|
|
+ $(this).closest('.note-section').removeClass('edit');
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+};
|