bahmniapps-commons
Version:
Common Modules carved out from bahmniapps.
1,494 lines (1,292 loc) • 67.4 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 61);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */,
/* 1 */,
/* 2 */,
/* 3 */,
/* 4 */,
/* 5 */,
/* 6 */,
/* 7 */,
/* 8 */,
/* 9 */,
/* 10 */,
/* 11 */,
/* 12 */,
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').controller('MessageController', ['$scope', 'messagingService', function ($scope, messagingService) {
$scope.messages = messagingService.messages;
$scope.getMessageText = function (level) {
var string = "";
$scope.messages[level].forEach(function (message) {
string = string.concat(message.value);
});
return string;
};
$scope.hideMessage = function (level) {
messagingService.hideMessages(level);
};
$scope.isErrorMessagePresent = function () {
return $scope.messages.error.length > 0;
};
$scope.isInfoMessagePresent = function () {
return $scope.messages.info.length > 0;
};
}]);
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('nonBlank', function () {
return function ($scope, element, attrs) {
var addNonBlankAttrs = function () {
element.attr({ 'required': 'required' });
};
var removeNonBlankAttrs = function () {
element.removeAttr('required');
};
if (!attrs.nonBlank) {
return addNonBlankAttrs(element);
}
$scope.$watch(attrs.nonBlank, function (value) {
return value ? addNonBlankAttrs() : removeNonBlankAttrs();
});
};
}).directive('datepicker', function () {
var link = function ($scope, element, attrs, ngModel) {
var maxDate = attrs.maxDate;
var minDate = attrs.minDate || "-120y";
var format = attrs.dateFormat || 'dd-mm-yy';
element.datepicker({
changeYear: true,
changeMonth: true,
maxDate: maxDate,
minDate: minDate,
yearRange: 'c-120:c+120',
dateFormat: format,
onSelect: function (dateText) {
$scope.$apply(function () {
ngModel.$setViewValue(dateText);
});
}
});
};
return {
require: 'ngModel',
link: link
};
}).directive('myAutocomplete', ['$parse', function ($parse) {
var link = function (scope, element, attrs, ngModelCtrl) {
var ngModel = $parse(attrs.ngModel);
var source = scope.source();
var responseMap = scope.responseMap();
var onSelect = scope.onSelect();
element.autocomplete({
autofocus: true,
minLength: 2,
source: function (request, response) {
source(attrs.id, request.term, attrs.itemType).then(function (data) {
var results = responseMap ? responseMap(data.data) : data.data;
response(results);
});
},
select: function (event, ui) {
scope.$apply(function (scope) {
ngModelCtrl.$setViewValue(ui.item.value);
scope.$eval(attrs.ngChange);
if (onSelect != null) {
onSelect(ui.item);
}
});
return true;
},
search: function (event) {
var searchTerm = $.trim(element.val());
if (searchTerm.length < 2) {
event.preventDefault();
}
}
});
};
return {
link: link,
require: 'ngModel',
scope: {
source: '&',
responseMap: '&',
onSelect: '&'
}
};
}]).directive('bmForm', ['$timeout', function ($timeout) {
var link = function (scope, elem, attrs) {
$timeout(function () {
$(elem).unbind('submit').submit(function (e) {
var formScope = scope.$parent;
var formName = attrs.name;
e.preventDefault();
if (scope.autofillable) {
$(elem).find('input').trigger('change');
}
if (formScope[formName].$valid) {
formScope.$apply(attrs.ngSubmit);
$(elem).removeClass('submitted-with-error');
} else {
$(elem).addClass('submitted-with-error');
}
});
}, 0);
};
return {
link: link,
require: 'form',
scope: {
autofillable: "="
}
};
}]).directive('patternValidate', ['$timeout', function ($timeout) {
return function ($scope, element, attrs) {
var addPatternToElement = function () {
if ($scope.fieldValidation && $scope.fieldValidation[attrs.id]) {
element.attr({ "pattern": $scope.fieldValidation[attrs.id].pattern, "title": $scope.fieldValidation[attrs.id].errorMessage, "type": "text" });
}
};
$timeout(addPatternToElement);
};
}]).directive('validateOn', function () {
var link = function (scope, element, attrs, ngModelCtrl) {
var validationMessage = attrs.validationMessage || 'Please enter a valid detail';
var setValidity = function (value) {
var valid = value ? true : false;
ngModelCtrl.$setValidity('blank', valid);
element[0].setCustomValidity(!valid ? validationMessage : '');
};
scope.$watch(attrs.validateOn, setValidity, true);
};
return {
link: link,
require: 'ngModel'
};
});
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('assignHeight', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var height;
scope.$watch(function () {
height = element[0].offsetHeight;
if (attrs.key) {
scope[attrs.key] = {
height: height
};
}
});
}
};
});
/***/ }),
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('autoScroll', ['$location', '$anchorScroll', '$timeout', function ($location, $anchorScroll, $timeout) {
var heightOfNavigationBar = 55;
return {
scope: {
autoScrollEnabled: "="
},
link: function (scope, element, attrs) {
$timeout(function () {
if (scope.autoScrollEnabled) {
$('body').animate({
scrollTop: $("#" + attrs.autoScroll).offset().top - heightOfNavigationBar
}, 500);
}
});
scope.$on('$destroy', function () {
$timeout.cancel();
$('body').animate({
scrollTop: -1 * heightOfNavigationBar
}, 0);
});
}
};
}]);
/***/ }),
/* 17 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('bmBackLinks', function () {
return {
template: '<ul>' + '<li ng-repeat="backLink in backLinks">' + '<a class="back-btn" ng-if="backLink.action" accesskey="{{backLink.accessKey}}" ng-click="closeAllDialogs();backLink.action()" id="{{backLink.id}}"> <span ng-bind-html="backLink.label"></span> </a>' + '<a class="back-btn" ng-class="{\'dashboard-link\':backLink.image}" ng-if="backLink.url" accesskey="{{backLink.accessKey}}" ng-href="{{backLink.url}}" ng-click="closeAllDialogs()" id="{{backLink.id}}" title="{{backLink.title}}"> ' + '<img ng-if="backLink.image" ng-src="{{backLink.image}}" onerror="this.onerror=null; this.src=\'../images/blank-user.gif\'"/>' + '<i ng-if="backLink.icon && !backLink.image" class="fa {{backLink.icon}}"></i></a>' + '<a class="back-btn" ng-if="backLink.state && !backLink.text" accesskey="{{backLink.accessKey}}" ui-sref="{{backLink.state}}" ng-click="closeAllDialogs()" id="{{backLink.id}}">' + '<i ng-if="backLink.icon" class="fa {{backLink.icon}}"></i></a>' + '<a ng-if="backLink.text && backLink.requiredPrivilege" show-if-privilege="{{backLink.requiredPrivilege}}" accesskey="{{backLink.accessKey}}" ui-sref="{{backLink.state}}" id="{{backLink.id}}" class="back-btn-noIcon" ui-sref-active="active">' + '<span>{{backLink.text | translate}}</span>' + ' </a>' + '<a ng-if="backLink.text && !backLink.requiredPrivilege" accesskey="{{backLink.accessKey}}" ui-sref="{{backLink.state}}" id="{{backLink.id}}" class="back-btn-noIcon" ui-sref-active="active">' + '<span>{{backLink.text | translate}}</span>' + ' </a>' + '</li>' + '</ul>',
controller: function ($scope, backlinkService) {
$scope.backLinks = backlinkService.getAllUrls();
$scope.$on('$stateChangeSuccess', function (event, state) {
if (state.data && state.data.backLinks) {
backlinkService.setUrls(state.data.backLinks);
$scope.backLinks = backlinkService.getAllUrls();
}
});
$scope.$on("$destroy", function () {
window.onbeforeunload = undefined;
});
},
restrict: 'E'
};
});
/***/ }),
/* 18 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('bahmniAutocomplete', ['$translate', function ($translate) {
var link = function (scope, element, attrs, ngModelCtrl) {
var source = scope.source();
var responseMap = scope.responseMap && scope.responseMap();
var onSelect = scope.onSelect();
var onEdit = scope.onEdit && scope.onEdit();
var minLength = scope.minLength || 2;
var formElement = element[0];
var validationMessage = scope.validationMessage || $translate.instant("SELECT_VALUE_FROM_AUTOCOMPLETE_DEFAULT_MESSAGE");
var validateIfNeeded = function (value) {
if (!scope.strictSelect) {
return;
}
scope.isInvalid = value !== scope.selectedValue;
if (_.isEmpty(value)) {
scope.isInvalid = false;
}
};
scope.$watch('initialValue', function () {
if (scope.initialValue) {
scope.selectedValue = scope.initialValue;
scope.isInvalid = false;
}
});
element.autocomplete({
autofocus: true,
minLength: minLength,
source: function (request, response) {
source({ elementId: attrs.id, term: request.term, elementType: attrs.type }).then(function (data) {
var results = responseMap ? responseMap(data) : data;
response(results);
});
},
select: function (event, ui) {
scope.selectedValue = ui.item.value;
ngModelCtrl.$setViewValue(ui.item.value);
if (onSelect != null) {
onSelect(ui.item);
}
validateIfNeeded(ui.item.value);
if (scope.blurOnSelect) {
element.blur();
}
scope.$apply();
scope.$eval(attrs.ngDisabled);
scope.$apply();
return true;
},
search: function (event, ui) {
if (onEdit != null) {
onEdit(ui.item);
}
var searchTerm = $.trim(element.val());
validateIfNeeded(searchTerm);
if (searchTerm.length < minLength) {
event.preventDefault();
}
}
});
var changeHanlder = function (e) {
validateIfNeeded(element.val());
};
var keyUpHandler = function (e) {
validateIfNeeded(element.val());
scope.$apply();
};
element.on('change', changeHanlder);
element.on('keyup', keyUpHandler);
scope.$watch('isInvalid', function () {
ngModelCtrl.$setValidity('selection', !scope.isInvalid);
formElement.setCustomValidity(scope.isInvalid ? validationMessage : '');
});
scope.$on("$destroy", function () {
element.off('change', changeHanlder);
element.off('keyup', keyUpHandler);
});
};
return {
link: link,
require: 'ngModel',
scope: {
source: '&',
responseMap: '&?',
onSelect: '&',
onEdit: '&?',
minLength: '=?',
blurOnSelect: '=?',
strictSelect: '=?',
validationMessage: '@',
isInvalid: "=?",
initialValue: "=?"
}
};
}]);
/***/ }),
/* 19 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('bmShow', ['$rootScope', function ($rootScope) {
var link = function ($scope, element) {
$scope.$watch('bmShow', function () {
if ($rootScope.isBeingPrinted || $scope.bmShow) {
element.removeClass('ng-hide');
} else {
element.addClass('ng-hide');
}
});
};
return {
scope: {
bmShow: "="
},
link: link
};
}]);
/***/ }),
/* 20 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('compileHtml', ['$compile', function ($compile) {
return function (scope, element, attrs) {
scope.$watch(function (scope) {
return scope.$eval(attrs.compileHtml);
}, function (value) {
element.html(value);
$compile(element.contents())(scope);
});
};
}]);
/***/ }),
/* 21 */
/***/ (function(module, exports) {
(function () {
'use strict';
var constructSearchResult = function (concept, searchString) {
var matchingName = null;
var conceptName = concept.name;
if (!_.includes(_.toLower(conceptName), _.toLower(searchString))) {
var synonyms = _.map(concept.names, 'name');
matchingName = _.find(synonyms, function (name) {
return name !== conceptName && name.search(new RegExp(searchString, "i")) !== -1;
});
}
return {
label: matchingName ? matchingName + " => " + conceptName : conceptName,
value: conceptName,
concept: concept,
uuid: concept.uuid,
name: conceptName
};
};
var searchWithDefaultConcept = function (searchMethod, request, response) {
var searchTerm = _.toLower(request.term.trim());
var isMatching = function (answer) {
var conceptNameFound = _.find(answer.names, function (name) {
return _.includes(_.toLower(name.name), searchTerm);
});
var conceptDrugNameFound = _.includes(_.toLower(answer.name), searchTerm);
return conceptNameFound || conceptDrugNameFound;
};
var responseMap = _.partial(constructSearchResult, _, searchTerm);
searchMethod().then(_.partial(_.filter, _, isMatching)) // == .then(function(value){return _.filter(value,isMatching);})
.then(_.partial(_.map, _, responseMap)).then(response);
};
var searchWithGivenConcept = function (searchMethod, request, response) {
var searchTerm = request.term.trim();
var responseMap = _.partial(constructSearchResult, _, searchTerm);
searchMethod().then(_.partial(_.map, _, responseMap)).then(response);
};
var toBeInjected = ['$parse', '$http', 'conceptService'];
var conceptAutocomplete = function ($parse, $http, conceptService) {
var link = function (scope, element, attrs, ngModelCtrl) {
var minLength = scope.minLength || 2;
var previousValue = scope.previousValue;
var validator = function (searchTerm) {
if (!scope.strictSelect) {
return;
}
if (!scope.illegalValue && (_.isEmpty(searchTerm) || searchTerm === previousValue)) {
element.removeClass('illegalValue');
return;
}
element.addClass('illegalValue');
};
element.autocomplete({
autofocus: true,
minLength: minLength,
source: function (request, response) {
var searchMethod;
if (!scope.answersConceptName && scope.defaultConcept) {
searchMethod = _.partial(conceptService.getAnswers, scope.defaultConcept);
searchWithDefaultConcept(searchMethod, request, response);
} else {
searchMethod = _.partial(conceptService.getAnswersForConceptName, {
term: request.term,
answersConceptName: scope.answersConceptName
});
searchWithGivenConcept(searchMethod, request, response);
}
},
select: function (event, ui) {
scope.$apply(function (scope) {
ngModelCtrl.$setViewValue(ui.item);
if (scope.blurOnSelect) {
element.blur();
}
previousValue = ui.item.value;
validator(previousValue);
scope.$eval(attrs.ngChange);
});
return true;
},
search: function (event) {
var searchTerm = $.trim(element.val());
if (searchTerm.length < minLength) {
event.preventDefault();
}
previousValue = null;
}
});
var blurHandler = function () {
var searchTerm = $.trim(element.val());
validator(searchTerm);
};
element.on('blur', blurHandler);
scope.$on("$destroy", function () {
element.off('blur', blurHandler);
});
};
return {
link: link,
require: 'ngModel',
scope: {
illegalValue: '=',
defaultConcept: '=',
answersConceptName: '=',
minLength: '=',
blurOnSelect: '=',
strictSelect: '=?',
previousValue: '='
}
};
};
conceptAutocomplete.$inject = toBeInjected;
angular.module('bahmni.common.uiHelper').directive('conceptAutocomplete', conceptAutocomplete);
})();
/***/ }),
/* 22 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('confirmOnExit', ['$translate', function ($translate) {
return {
link: function ($scope) {
var cleanUpListenerPageUnload = $scope.$on("event:pageUnload", function () {
window.onbeforeunload = function () {
return $translate.instant("BROWSER_CLOSE_DIALOG_MESSAGE_KEY");
};
});
$scope.$on("$destroy", cleanUpListenerPageUnload);
}
};
}]);
/***/ }),
/* 23 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('dateConverter', [function () {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModelController) {
var DateUtil = Bahmni.Common.Util.DateUtil;
ngModelController.$parsers.push(function (date) {
return DateUtil.parse(date);
});
ngModelController.$formatters.push(function (date) {
return DateUtil.parse(DateUtil.getDateWithoutTime(date));
});
}
};
}]);
/***/ }),
/* 24 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('datetimepicker', function () {
var link = function ($scope) {
if (!$scope.allowFutureDates) {
$scope.maxDate = Bahmni.Common.Util.DateTimeFormatter.getDateWithoutTime();
}
var getSelectedDateStr = function () {
return $scope.selectedDate != null ? moment($scope.selectedDate).format("YYYY-MM-DD") : "";
};
var getSelectedTimeStr = function () {
return $scope.selectedTime != null ? moment($scope.selectedTime).format("HH:mm") : "";
};
var valueNotFilled = function () {
return $scope.selectedDate == null && $scope.selectedTime == null;
};
var valueCompletelyFilled = function () {
return $scope.selectedDate != null && $scope.selectedTime != null;
};
$scope.updateModel = function () {
if (valueCompletelyFilled()) {
$scope.model = getSelectedDateStr() + " " + getSelectedTimeStr();
} else if (!$scope.isValid()) {
$scope.model = "Invalid Datetime";
} else {
$scope.model = "";
}
};
$scope.isValid = function () {
return valueNotFilled() || valueCompletelyFilled();
};
if ($scope.model) {
var date = moment($scope.model).toDate();
$scope.selectedDate = date;
$scope.selectedTime = date;
$scope.updateModel();
}
};
return {
restrict: 'E',
link: link,
scope: {
model: '=',
observation: "=",
showTime: '=',
illegalValue: '=',
allowFutureDates: '='
},
template: "<div>" + "<input type='date' ng-change='updateModel()' ng-class=\"{'illegalValue': illegalValue}\" ng-attr-max='{{maxDate || undefined}}' ng-model='selectedDate' ng-disabled='observation.disabled' />" + "</div>" + "<div>" + "<input type='time' ng-change='updateModel()' ng-class= \"{'illegalValue': !isValid()}\" ng-model='selectedTime' ng-disabled='observation.disabled' />" + "</div>"
};
});
/***/ }),
/* 25 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.patient').directive('fallbackSrc', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
if (_.isEmpty(attrs.ngSrc)) {
element.attr('src', attrs.fallbackSrc);
}
element.bind('error', function () {
element.attr('src', attrs.fallbackSrc);
});
}
};
});
/***/ }),
/* 26 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive("fixedFirstColumn", ["$interval", function ($interval) {
return {
restrict: "A",
template: "<div class='table-responsive'><div ng-transclude class='table-responsive-fixedColumn' ></div></div>",
transclude: true,
link: function ($scope, $element) {
var checkIfTableLoaded = $interval(function () {
if ($element.find("table").length > 0) {
var tr = $element.find("tr");
angular.forEach(tr, function (i) {
var columns = angular.element(i).children();
if (columns.length < 1) {
// Row with no columns? Ignore it.
return;
}
var column0 = columns[0];
var column1 = columns[1];
// Calculate heights of each <td>.
var height0 = column0.offsetHeight;
var height1 = column1 ? column1.offsetHeight : 0;
// Calculate final height.
var height = Math.max(height0, height1);
// Set heights of <td> and <tr>.
columns[0].style.height = height + "px";
i.style.height = height + "px";
if (column1) {
column1.style.height = height + "px";
}
// If <td> heights have stabilized.
if (height0 !== 0 && height0 === height1) {
clearInterval(checkIfTableLoaded);
}
});
clearInterval(checkIfTableLoaded);
}
}, 100, 1);
}
};
}]);
/***/ }),
/* 27 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('focusMe', ['$timeout', '$parse', function ($timeout, $parse) {
return {
link: function (scope, element, attrs) {
var model = $parse(attrs.focusMe);
scope.$watch(model, function (value) {
if (value === true) {
$timeout(function () {
element[0].focus();
});
}
});
}
};
}]);
/***/ }),
/* 28 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('focusOn', ['$timeout', function ($timeout) {
return function (scope, elem, attrs) {
if (Modernizr.ios) {
return;
}
scope.$watch(attrs.focusOn, function (value) {
if (value) {
$timeout(function () {
$(elem).focus();
});
}
});
};
}]);
/***/ }),
/* 29 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('focusOnInputErrors', ['$timeout', function ($timeout) {
return function (scope) {
var cleanUpListenerErrorsOnForm = scope.$on("event:errorsOnForm", function () {
$timeout(function () {
$('.illegalValue:first button').focus();
$('.illegalValue:first').focus();
}, 10, false);
});
scope.$on("$destroy", cleanUpListenerErrorsOnForm);
};
}]);
/***/ }),
/* 30 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('bmGallery', ['$location', '$rootScope', '$compile', function ($location, $rootScope, $compile) {
var controller = function ($scope) {
$scope.albums = [];
$scope.imagePosition = {
tag: undefined,
index: 0
};
this.image = function (record) {
var provider = record.provider;
return {
src: Bahmni.Common.Constants.documentsPath + '/' + record.imageObservation.value,
title: record.concept.name,
commentOnUpload: record.comment || record.imageObservation.comment,
date: record.imageObservation.observationDateTime,
uuid: record.imageObservation.uuid,
providerName: provider ? provider.name : null
};
};
this.addImageObservation = function (record, tag) {
return this.addImage(this.image(record), tag);
};
this.addImage = function (image, tag, tagOrder) {
var matchedAlbum = getMatchingAlbum(tag);
if (!matchedAlbum) {
var newAlbum = {};
newAlbum.tag = tag;
newAlbum.images = [image];
$scope.albums.splice(tagOrder, 0, newAlbum);
} else {
var index = image.imageIndex ? image.imageIndex : matchedAlbum.images.length;
matchedAlbum.images.splice(index, 0, image);
}
return $scope.albums[0].images.length - 1;
};
var getMatchingAlbum = function (tag) {
return _.find($scope.albums, function (album) {
return album.tag == tag;
});
};
this.removeImage = function (image, tag, index) {
var matchedAlbum = getMatchingAlbum(tag);
if (matchedAlbum) {
if (matchedAlbum.images) {
matchedAlbum.images.splice(index, 1);
}
}
};
this.setIndex = function (tag, index) {
$scope.imagePosition.tag = tag;
$scope.imagePosition.index = index;
};
this.open = function () {
$compile("<div bm-gallery-pane id='gallery-pane'></div>")($scope);
};
};
return {
controller: controller,
scope: {
patient: "=",
accessImpression: "=?"
}
};
}]).directive('bmGalleryItem', function () {
var link = function ($scope, element, attrs, imageGalleryController) {
var image = {
src: $scope.image.encodedValue,
title: $scope.image.concept ? $scope.image.concept.name : "",
date: $scope.image.obsDatetime,
uuid: $scope.image.obsUuid,
providerName: $scope.image.provider ? $scope.image.provider.name : "",
imageIndex: $scope.image.imageIndex,
commentOnUpload: $scope.image.comment
};
imageGalleryController.addImage(image, $scope.visitUuid, $scope.visitOrder);
element.click(function (e) {
e.stopPropagation();
imageGalleryController.setIndex($scope.visitUuid, $scope.index);
imageGalleryController.open();
});
element.on('$destroy', function () {
imageGalleryController.removeImage(image, $scope.visitUuid, $scope.index);
});
};
return {
link: link,
scope: {
image: '=',
index: "@",
visitUuid: "=",
visitOrder: "@"
},
require: '^bmGallery'
};
}).directive('bmImageObservationGalleryItem', function () {
var link = function (scope, element, attrs, imageGalleryController) {
scope.imageIndex = imageGalleryController.addImageObservation(scope.observation, 'defaultTag');
element.click(function (e) {
e.stopPropagation();
imageGalleryController.setIndex('defaultTag', scope.imageIndex);
imageGalleryController.open();
});
};
return {
link: link,
scope: {
observation: '='
},
require: '^bmGallery'
};
}).directive('bmObservationGalleryItem', function () {
var link = function (scope, element, attrs, imageGalleryController) {
scope.imageObservation = new Bahmni.Common.Obs.ImageObservation(scope.observation, scope.observation.concept, scope.observation.provider);
scope.imageIndex = imageGalleryController.addImageObservation(scope.imageObservation, 'defaultTag');
element.click(function (e) {
e.stopPropagation();
imageGalleryController.setIndex('defaultTag', scope.imageIndex);
imageGalleryController.open();
});
};
return {
link: link,
scope: {
observation: '='
},
require: '^bmGallery'
};
}).directive("bmImageObservationGalleryItems", function () {
var link = function (scope, elem, attrs, imageGalleryController) {
angular.forEach(scope.list, function (record) {
imageGalleryController.addImageObservation(record, 'defaultTag');
});
$(elem).click(function () {
imageGalleryController.open();
});
};
return {
link: link,
scope: {
list: "="
},
require: '^bmGallery'
};
}).directive("bmLazyImageObservationGalleryItems", function () {
var link = function (scope, elem, attrs, imageGalleryController) {
scope.promise.then(function (response) {
angular.forEach(response, function (record) {
var index = imageGalleryController.addImageObservation(record, 'defaultTag');
if (scope.currentObservation && scope.currentObservation.imageObservation.uuid == record.imageObservation.uuid) {
imageGalleryController.setIndex('defaultTag', index);
}
});
$(elem).click(function () {
imageGalleryController.open();
});
});
};
return {
link: link,
scope: {
promise: "=",
currentObservation: "=?index"
},
require: '^bmGallery'
};
});
/***/ }),
/* 31 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('monthyearpicker', ['$translate', function ($translate) {
var link = function ($scope) {
var monthNames = $translate.instant('MONTHS');
$scope.monthNames = monthNames.split(",");
var getYearList = function () {
var minYear = $scope.minYear ? $scope.minYear : moment().toDate().getFullYear() - 15;
var maxYear = $scope.maxYear ? $scope.maxYear : moment().toDate().getFullYear() + 5;
var yearList = [];
for (var i = maxYear; i >= minYear; i--) {
yearList.push(i);
}
return yearList;
};
$scope.years = getYearList();
var valueCompletelyFilled = function () {
return $scope.selectedMonth != null && $scope.selectedYear != null;
};
var valueNotFilled = function () {
return $scope.selectedMonth == null && $scope.selectedYear == null;
};
var getCompleteDate = function () {
var month = $scope.selectedMonth + 1;
return $scope.selectedYear + "-" + month + "-01";
};
$scope.updateModel = function () {
if (valueCompletelyFilled()) {
$scope.model = getCompleteDate();
} else if (!$scope.isValid()) {
$scope.model = "Invalid Date";
} else {
$scope.model = "";
}
};
$scope.isValid = function () {
return valueNotFilled() || valueCompletelyFilled();
};
$scope.illegalMonth = function () {
return ($scope.selectedMonth === undefined || $scope.selectedMonth === null) && $scope.selectedYear !== null && $scope.selectedYear !== undefined;
};
$scope.illegalYear = function () {
return $scope.selectedMonth !== null && $scope.selectedMonth !== undefined && ($scope.selectedYear === undefined || $scope.selectedYear === null);
};
if ($scope.model) {
var date = moment($scope.model).toDate();
$scope.selectedMonth = date.getMonth();
$scope.selectedYear = date.getFullYear();
}
};
return {
restrict: 'E',
link: link,
scope: {
observation: "=",
minYear: "=",
maxYear: "=",
illegalValue: '=',
model: "="
},
template: '<span><select ng-model=\'selectedMonth\' ng-class=\"{\'illegalValue\': illegalMonth() || illegalValue}\" ng-change="updateModel()" ng-options="monthNames.indexOf(month) as month for month in monthNames" ><option value="">{{\'CHOOSE_MONTH_KEY\' | translate}}</option>>' + '</select></span>' + '<span><select ng-model=\'selectedYear\' ng-class=\"{\'illegalValue\': illegalYear() || illegalValue}\" ng-change="updateModel()" ng-options="year as year for year in years"><option value="">{{\'CHOOSE_YEAR_KEY\' | translate}}</option>>' + '</select></span>'
};
}]);
/***/ }),
/* 32 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('ngConfirmClick', function () {
var link = function (scope, element, attr) {
var msg = attr.confirmMessage || "Are you sure?";
var clickAction = attr.ngConfirmClick;
element.bind('click', function () {
if (window.confirm(msg)) {
scope.$apply(clickAction);
}
});
};
return {
restrict: 'A',
link: link
};
});
/***/ }),
/* 33 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('bmPopOver', function () {
var controller = function ($scope) {
$scope.targetElements = [];
var hideTargetElements = function () {
$scope.targetElements.forEach(function (el) {
el.hide();
});
};
var showTargetElements = function () {
$scope.targetElements.forEach(function (el) {
el.show();
});
};
this.registerTriggerElement = function (triggerElement) {
$scope.triggerElement = triggerElement;
var docClickHandler = function () {
if (!$scope.autoclose) {
return;
}
hideTargetElements();
$scope.isTargetOpen = false;
$(document).off('click', docClickHandler);
};
$scope.triggerElement.on('click', function (event) {
if ($scope.isTargetOpen) {
$scope.isTargetOpen = false;
hideTargetElements(0);
$(document).off('click', docClickHandler);
} else {
$scope.isTargetOpen = true;
showTargetElements();
$(document).on('click', docClickHandler);
event.stopImmediatePropagation();
}
});
$scope.$on('$destroy', function () {
$(document).off('click', docClickHandler);
});
};
this.registerTargetElement = function (targetElement) {
targetElement.hide();
$scope.targetElements.push(targetElement);
};
var hideOrShowTargetElements = function () {
if ($scope.isTargetOpen) {
$scope.isTargetOpen = false;
hideTargetElements(0);
}
};
$(document).on('click', '.reg-wrapper', hideOrShowTargetElements);
$scope.$on('$destroy', function () {
$(document).off('click', '.reg-wrapper', hideOrShowTargetElements);
});
};
return {
restrict: 'A',
controller: controller,
scope: {
autoclose: "="
}
};
}).directive('bmPopOverTarget', function () {
var link = function ($scope, element, attrs, popOverController) {
popOverController.registerTargetElement(element);
};
return {
restrict: 'A',
require: '^bmPopOver',
link: link
};
}).directive('bmPopOverTrigger', function () {
var link = function ($scope, element, attrs, popOverController) {
popOverController.registerTriggerElement(element);
};
return {
restrict: 'A',
require: '^bmPopOver',
link: link
};
});
/***/ }),
/* 34 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('providerDirective', function () {
var template = '<span>' + '<span ng-if=":: creatorName && providerName && (creatorName != providerName)">{{::creatorName}} {{"ON_BEHALF_OF_TRANSLATION_KEY"|translate}} </span>' + '{{::providerName}} <span ng-if=":: providerDate"> {{::providerDate | bahmniTime}} </span>' + '</span>';
return {
restrict: 'EA',
replace: true,
scope: {
creatorName: "@",
providerName: "@",
providerDate: "=?"
},
template: template
};
});
/***/ }),
/* 35 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('scrollToObsElement', function () {
return function (scope, elem, attrs) {
if (attrs.scrollToObsElement && scope.observation.scrollToElement) {
$(elem).focus();
var scrollPosition = $(elem).offset().top - window.innerHeight / 2;
if ($('#scrollOnEdit')[0]) {
var container = $('#scrollOnEdit');
var scrollTo = elem;
scrollPosition = scrollTo.offset().top + container.scrollTop() - (container.offset().top + container.offset().top / 2);
container.animate({ scrollTop: scrollPosition }, 900);
} else {
$(window).animate({ scrollTop: scrollPosition }, 900);
}
scope.observation.scrollToElement = false;
}
};
});
/***/ }),
/* 36 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('singleClick', function () {
var ignoreClick = false;
var link = function (scope, element) {
var clickHandler = function () {
if (ignoreClick) {
return;
}
ignoreClick = true;
scope.singleClick().finally(function () {
ignoreClick = false;
});
};
element.on('click', clickHandler);
scope.$on("$destroy", function () {
element.off('click', clickHandler);
});
};
return {
scope: {
singleClick: '&'
},
restrict: 'A',
link: link
};
});
/***/ }),
/* 37 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('singleSubmit', function () {
var ignoreSubmit = false;
var link = function (scope, element) {
var submitHandler = function () {
if (ignoreSubmit) {
return;
}
ignoreSubmit = true;
scope.singleSubmit().finally(function () {
ignoreSubmit = false;
});
};
element.on('submit', submitHandler);
scope.$on("$destroy", function () {
element.off('submit', submitHandler);
});
};
return {
scope: {
singleSubmit: '&'
},
restrict: 'A',
link: link
};
});
/***/ }),
/* 38 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('splitButton', ['$timeout', function ($timeout) {
var controller = function ($scope) {
$scope.primaryOption = $scope.primaryOption || $scope.options[0];
$scope.secondaryOptions = _.without($scope.options, $scope.primaryOption);
$scope.hasMultipleOptions = function () {
return $scope.secondaryOptions.length > 0;
};
};
var link = function (scope, element) {
var shouldScroll = function (elementPosition, elementHeight) {
var windowHeight = window.innerHeight + $(window).scrollTop();
return windowHeight < elementHeight + elementPosition;
};
scope.scrollToBottom = function () {
var timeout = $timeout(function () {
var scrollHeight = $(element)[0].scrollHeight;
if (shouldScroll(element.position().top, scrollHeight)) {
window.scrollBy(0, scrollHeight);
$timeout.cancel(timeout);
}
});
};
};
return {
restrict: 'A',
template: '<div class="split-button" bm-pop-over>' + '<button bm-pop-over-trigger class="toggle-button fa fa-caret-down" ng-show="::hasMultipleOptions()" ng-click="scrollToBottom()" ng-disabled="optionDisabled" type="button"></button>' + '<ul class="options">' + '<li class="primaryOption">' + '<button class="buttonClass" ng-click="optionClick()(primaryOption)" accesskey="{{::primaryOption.shortcutKey}}" ng-disabled="optionDisabled" ng-bind-html="::optionText()(primaryOption,\'primary\') | translate "></button>' + '</li>' + '<ul class="hidden-options">' + '<li bm-pop-over-target ng-repeat="option in ::secondaryOptions" class="secondaryOption">' + '<button class="buttonClass" ng-click="optionClick()(option)" accesskey="{{::option.shortcutKey}}" ng-disabled="optionDisabled" ng-bind-html="::optionText()(option) | translate"></button>' + '</li>' + '</ul>' + '</ul>' + '</div>',
controller: controller,
link: link,
scope: {
options: '=',
primaryOption: '=',
optionText: '&',
optionClick: '&',
optionDisabled: '='
}
};
}]);
/***/ }),
/* 39 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').directive('toggle', function () {
var link = function ($scope, element) {
$scope.toggle = $scope.toggle === undefined ? false : $scope.toggle;
$(element).click(function () {
$scope.$apply(function () {
$scope.toggle = !$scope.toggle;
});
});
$scope.$watch('toggle', function () {
$(element).toggleClass('active', $scope.toggle);
});
$scope.$on("$destroy", function () {
element.off('click');
});
};
return {
scope: {
toggle: "="
},
link: link
};
});
/***/ }),
/* 40 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
angular.module('bahmni.common.uiHelper').filter('days', function () {
return function (startDate, endDate) {
return Bahmni.Common.Util.DateUtil.diffInDays(startDate, endDate);
};
}).filter('bahmniDateTime', function () {
return function (date) {
return Bahmni.Common.Util.DateUtil.formatDateWithTime(date);
};
}).filter('bahmniDate', function () {
return function (date) {
return Bahmni.Common.Util.DateUtil.formatDateWithoutTime(date);
};
}).filter('bahmniTime', function () {
return function (date) {
return Bahmni.Common.Util.DateUtil.formatTime(date);
};
}).filter('bahmniDateInStrictMode', function () {
return function (date) {
return Bahmni.Common.Util.DateUtil.formatDateInStrictMode(date);
};
});
/***/ }),
/* 4