angular.module("stp.core.charts",[]);angular.module("stp.core.dataServices",["ngCookies","restangular","ngFileUpload"]);angular.module("stp.core.exception",[]);angular.module("stp.core.forms",["ui.bootstrap","ui.mask","ui.router.tabs","ui.select","formly","formlyBootstrap","localytics.directives","ngFileUpload","froala"]);angular.module("stp.core.charts").config([function(){$("body").on("click",function(n){$("[data-original-title]").each(function(){$(this).is(n.target)||$(this).has(n.target).length!==0||$(".popover").has(n.target).length!==0||$(this).popover("hide")})})}]);angular.module("stp.core.charts").controller("TimelineController",["$scope","$timeout","$window","$element","$q",function(n,t,i,r){function p(){if(!i.vis)throw"VisJS not referenced or loaded.";w();n.$watchCollection(function(){return u.dataItems},b);n.$watch(function(){return u.startDate},h);n.$watch(function(){return u.endDate},h)}function w(){e=new i.vis.DataSet;o=new i.vis.Timeline(r[0],e,{stack:!1,margin:{axis:5},moveable:!1,selectable:!0});c()}function h(){u.startDate&&u.endDate&&(a(),o.setOptions({start:u.startDate,end:u.endDate}),v())}function b(n){n&&c()}function c(){var n,t;a();e.clear();n=[];f=[];_.forEach(u.dataItems,function(t){var i=l(t.group);f[i]||(f[i]={name:t.group,items:[]},n.push(t.group));f[i].items.push(t.summary);e.add({group:i,subgroup:i,content:t.caption,start:t.fromDate,end:t.toDate,style:"background-color: "+t.colour+"; border-color: white;"})});t=new vis.DataSet;_.each(n,function(n){var i=l(n);t.add({id:i,content:n,className:"vis-timeline-group "+s+i})});o.setGroups(t);v()}function l(n){return n.replace(" ","_")}function a(){$(r[0]).find(".vis-item").popover("destroy")}function v(){$(r[0]).find(".vis-group").popover({placement:"bottom",container:$(r[0]),trigger:"click",viewport:{selector:$(r[0]),padding:50},html:!0,title:function(){var n=y(this);return n.name},content:function(){var n=y(this);return n.items.join("<br/>")}})}function y(n){var t=_.find($(n).attr("class").split(" "),function(n){return n.indexOf(s)===0}),i=t.substr(s.length);return f[i]}var u=this,e,o,f=[],s="stp-med-group-key-";p()}]);angular.module("stp.core.charts").directive("stpTimeline",function(){return{restict:"E",scope:{dataItems:"=items",startDate:"=",endDate:"="},template:'<div class="vis-timeline vis-timeline-container"><\/div>',controller:"TimelineController",controllerAs:"ctrl",bindToController:!0,replace:!0}}),function(){function n(n){this.page=1;this.pageSize=10;this.data=n;this.pageData=n.slice(0,this.pageSize);this.total=n.length;this.firstPage=this.page===1;this.lastPage=this.page*this.pageSize>=this.total;this.dataResponse={total:this.data.length};this.totalPages=this.total/this.pageSize;this.singlePage=this.total<=this.pageSize}angular.module("stp.core.dataServices").service("arrayDataSourceFactory",[function(){return function(t,i){return new n(t,i)}}]);n.prototype.nextPage=function(){var t=this.page*this.pageSize,n;this.page++;n=this.page*this.pageSize;this.pageData=this.data.slice(t,n);this.lastPage=this.page*this.pageSize>=this.data.length;this.firstPage=this.page===1};n.prototype.previousPage=function(){var t=(this.page-1)*this.pageSize,n;this.page--;n=(this.page-1)*this.pageSize;this.pageData=this.data.slice(n,t);this.firstPage=this.page===1;this.lastPage=this.page*this.pageSize>=this.total}}(),function(){function n(n,t,i,r,u){this.page=1;this.pageSize=10;this.dataResponse=null;this.firstPage=!0;this.lastPage=!0;this.searchTerm=null;this.sortParams=[];this.loading=!1;this._filterObj={logic:"and",filters:[]};var f={transformElement:function(n){return n}};this.config=_.defaults({},n,f);this.restangular=i;this.$q=t;this.rootRestangular=r;this.filterService=u}angular.module("stp.core.dataServices").service("dataSourceFactory",["$q","Restangular","filterService",function(t,i,r){return function(u,f){return new n(f,t,i,u,r)}}]);n.prototype.search=function(){var n=this,t={pageSize:this.pageSize,page:this.page,searchTerm:this.searchTerm||"",filter:this.filterService.render(this._filterObj),sort:this.sortParams.join(",")||""};return n.loading=!0,n.rootRestangular.customGET("search",t).then(function(t){return n.dataResponse=t,n.restangular.restangularizeCollection(n.rootRestangular,n.dataResponse.data,""),_.each(n.dataResponse.data,function(t){t.fromServer=!0;t.computedFields={};t=n.config.transformElement(t)}),n.firstPage=n.page===1,n.lastPage=n.page*n.pageSize>=t.total,n.singlePage=t.total<=n.pageSize,n}).finally(function(){n.loading=!1})};n.prototype.download=function(n,t,i){var r=this,u={pageSize:1e6,page:1,searchTerm:n||"",filter:this.filterService.render(this._filterObj),sort:this.sortParams.join(",")||""};return r.loading=!0,r.rootRestangular.customGET("download",u).then(function(n){var u=new Blob([n],{type:'"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"'}),f=URL.createObjectURL(u),r=document.createElement("a");r.href=f;r.target="_blank";r.download=(t||(new Date).toISOString()+"-Download")+"."+(i||"csv");document.body.appendChild(r);r.click()}).finally(function(){r.loading=!1})};n.prototype.clearSearch=function(){return this._filterObj.filters.length=0,this.sortParams.length=0,this.page=1,this};n.prototype.setFilter=function(n){return this._filterObj=n,this};n.prototype.filter=function(n,t,i){return this._filterObj.filters.push({field:n,operator:i||"equals",value:t}),this};n.prototype.subFilter=function(n){var t=_filterObj={logic:n||"and",filters:[]};return this._filterObj.filters.push(t),{filter:function(n,i,r){return t.filters.push({field:n,operator:r||"equals",value:i}),this}}};n.prototype.sortBy=function(n,t){this.sortParams.add(n+"-"+t)};n.prototype.searchOnTerm=function(n){return this.searchTerm=n,this.page=1,this.search()};n.prototype.totalPages=function(){return this.dataResponse.total===0||this.pageSize===0?0:this.dataResponse.total/this.pageSize};n.prototype.refresh=function(){return this.search()};n.prototype.nextPage=function(){return this.page<this.totalPages()?(this.page++,this.search()):this.$q.when()};n.prototype.previousPage=function(){return this.page>0?(this.page--,this.search()):this.$q.when()}}();angular.module("stp.core.dataServices").factory("filterService",[function(){function t(n,t){var i={logic:"and",filters:[]},r=n.split(" ");return _.each(r,function(n){var r=[];_.each(t,function(t){r.push({field:t,operator:"contains",value:n})});i.filters.push({logic:"or",filters:r})}),i}function i(n,t,i){return{field:n,operator:i||"equals",value:t}}function r(n){return{logic:"and",filters:n}}function u(n){return{logic:"or",filters:n}}function n(n){if(!n)return"";if(n.hasOwnProperty("sets"))return o(n);if(n.hasOwnProperty("filters"))return e(n);if(n.hasOwnProperty("field"))return f(n);throw"Expected object with either logic or field on it";}function f(n){return n.field+"~"+n.operator+"~"+n.value}function e(t){if(t.filters&&t.filters.length>0){var i=t.logic,r=_.map(t.filters,n);return"("+r.join("~"+i+"~")+")"}return""}function o(t){if(t.sets&&t.sets.length>0){var i=t.logic,r=_.map(t.sets,n);return r.join("~"+i+"~")}return""}return{render:n,search:t,filter:i,and:r,or:u}}]);angular.module("stp.core.dataServices").service("lookupService",["$q","$cacheFactory","lookupMetaDataService","dataSourceFactory",function(n,t,i,r){function o(t){var u=n.defer(),f=[],r={};return r.$promise=u.promise,_.forEach(t,function(n){r[n]=[]}),i.getLookupMetadata().then(function(){_.forEach(t,function(n){f.push(h(r,n))});n.all(f).then(function(){u.resolve(r)})}),r}function s(n){return i.getLookupMetadata().then(function(){var t=i.getLookupMetadataByName(n);if(!t)throw"Unknown lookup: "+n;return r(t.all("items"))})}function h(n,t){var r=i.getLookupMetadataByName(t);if(!r)throw"Unknown lookup: "+t;return r.all("items").withHttpConfig({cache:!0}).getList().then(function(i){n[t]=i})}function c(n,t){return i.getLookupMetadata().then(function(){var f=i.getLookupMetadataByName(n),u;if(!f)throw"Unknown lookup: "+n;return u=r(f.all("items")),u.filter("id",t,"equals"),u.search().then(function(i){if(i.dataResponse.data.length===0)throw"Lookup item not found for "+n+" with id "+t;return i.dataResponse.data[0]})})}function l(n,t){return n.all("items").post(t).then(function(n){return e(n),n})}function a(n){return n.save().then(function(n){return e(n),n})}function v(n){var t=i.getLookupMetadataByName(n),r=t.all("items").getRestangularUrl();f.remove(r)}function e(n){var t=n.getRestangularUrl();t=t.replace(/\/\d+$/,"");f.remove(t)}var u=this,f;u.getLookups=o;u.getLookupDataSourceAsync=s;u.getLookupValueAsync=c;u.addLookupItem=l;u.saveLookupItem=a;u.clearLookupCache=v;f=t.get("$http")}]);angular.module("stp.core.dataServices").value("lookupKnownIds",{roles:{doctor:1,nurse:2,clerical:3,systemAdmin:4,helpAdmin:5,medicalCentreAdmin:6},smokingStatus:{never:1,current:2,exSmoker:3},diagnosis:{CD:1,UC:2},radiologyType:{mrcp:4,mrPelvis:7},gender:{male:1,female:2},radiologyBehaviour:{stricture:2},investigationType:{endoscopy:1,radiology:2},medicationIndicationForStopping:{adverseReaction:5},histologyProcedure:{endoscopy:1,surgery:2,other:3},repeatInterval:{weekly:1,monthly:2},medicationFrequency:{singleDose:1},educationType:{coreEducation:1},taskType:{patientReview:1},taskItemType:{histologyReview:1,surgeryReview:2},inflammation:{noAbnormality:1,quiescent:2},endoscopyComplication:{normal:1},medicationGrouping:{oralSteroid:2}});angular.module("stp.core.dataServices").service("lookupMetaDataService",["Restangular",function(n){function f(){return r}function e(n){return _.find(t,function(t){return u(t.name)===u(n)})}function u(n){return n.remove(/\s/g).toLowerCase()}var i=this,t,r;i.getLookupMetadata=f;i.getLookupMetadataByName=e;r=n.all("lookups").withHttpConfig({cache:!0}).getList().then(function(n){return t=n})}]),function(){function n(n,t){this.rootRestangular=t;this.uploadService=n}angular.module("stp.core.dataServices").factory("restangularAdapterFactory",["Upload",function(t){return function(i){return new n(t,i)}}]);n.prototype.post=function(n,t){var i=this;return this.rootRestangular.post(n).then(function(n){return i._processUploadFiles(n,t)})};n.prototype.save=function(n){var t=this;return this.rootRestangular.save().then(function(i){return angular.extend(t.rootRestangular,i.plain()),t._processUploadFiles(t.rootRestangular,n)})};n.prototype.customPOST=function(n,t,i,r){var u=this;return u.rootRestangular.customPOST(n,t,i,r).then(function(n){return angular.extend(u.rootRestangular,n.plain()),u.rootRestangular})};n.prototype._processUploadFiles=function(n,t){return!t||t.length===0?n:this.uploadService.upload({url:n.all("attachments").getRestangularUrl(),data:{files:t}}).then(function(){return delete t,n.get()})}}();angular.module("stp.core.exception").provider("stpErrorService",[function(){var n=this;n.unhandledExceptionMessage="An unexpected error has occured. If problems persist, please contact your system admin.";n.$get=["$rootScope",function(t){var i=[];return{addUnhandledErrorHandler:function(n){i.push(n)},notify:function(r){var f=t.$broadcast("stpError",r),u;f.defaultPrevented||(u={message:n.unhandledExceptionMessage},t.$broadcast("stpUnhandledError",r,u),_.each(i,function(n){n(r,u)}))}}}]}]).config(["$httpProvider",function(n){n.interceptors.push(["$q","$log","stpErrorService","httpUtilityService","messageBoxService",function(n,t,i,r,u){return{responseError:function(f){return r.isConflict(f)?u.alert(f.data.message):r.isOfflineOrCancelled(f)?t.warn("Network connection cannot be made or request cancelled."):!f||angular.isString(f)||r.isNotAuthorisedError(f)||r.isNotFoundError(f)||i.notify(f),n.reject(f)}}}])}]).run(["$rootScope","stpErrorService","httpUtilityService",function(n,t,i){function r(n){return angular.isDefined(n)&&angular.isDefined(n.startsWith)&&angular.isFunction(n.startsWith)&&n.startsWith("adal:")}n.$on("$stateChangeError",function(n,u,f,e,o,s){n.defaultPrevented||i.isHttpError(s)||r(s)||(n.preventDefault(),t.notify({message:"$stateChangeError",toState:u,toParams:f,fromState:e,fromParams:o,error:s}))})}]).run(["$window","stpErrorService",function(n,t){n.onerror=function(n,i,r,u,f){t.notify({error:f,message:n,url:i,lineNumber:r,columnNumber:u})}}]).factory("$exceptionHandler",["$injector",function(n){var t,i;return function(r){t=t||n.get("stpErrorService");i=i||n.get("$location");r.url=i.url();t.notify(r)}}]).provider("stpUnhandledErrorLogger",[function(){var n=this;return n.enabled=!0,n.$get=["$rootScope","$log","stpErrorService",function(t,i,r){function u(t){n.enabled&&i.error(t)}return r.addUnhandledErrorHandler(u),{}}],n}]).run(["stpUnhandledErrorLogger",angular.noop]).provider("stpUnhandledErrorMessageBox",[function(){var n=this;return n.enabled=!0,n.$get=["$rootScope","messageBoxService","stpErrorService",function(t,i,r){function u(t,r){n.enabled&&i.alert(r.message)}return r.addUnhandledErrorHandler(u),{}}],n}]).run(["stpUnhandledErrorMessageBox",angular.noop]).provider("stpUnhandledErrorRaygun",[function(){var n=this;return n.enabled=!0,n.$get=["$rootScope","stpRaygunService","stpErrorService",function(t,i,r){function u(t){n.enabled&&i.log(t)}return r.addUnhandledErrorHandler(u),{}}],n}]).run(["stpUnhandledErrorRaygun",angular.noop]).provider("stpRaygunService",[function(){var n=this,t=!1;return n.init=function(n){Raygun.init(n,{ignore3rdPartyErrors:!0}).attach();t=!0},n.$get=["$log",function(n){return{log:function(i){if(t)try{Raygun.send(i,i)}catch(r){n.error(r)}}}}],n}]);angular.module("stp.core.exception").config(["$stateProvider",function(n){n.state("throw",{url:"/exception",controller:function(){throw"Raygun test exception";}})}]);angular.module("stp.core.exception").service("httpUtilityService",[function(){function t(n){return angular.isDefined(n)&&(angular.isDefined(n.status)||i(n))}function r(n){return t(n)&&n.status===404}function u(n){return t(n)&&(n.status===401||n.status===403||f(n))}function f(n){return t(n)&&n.status===400&&n.data.error==="invalid_grant"}function e(n){return t(n)&&n.status===409}function i(n){return n&&angular.isString(n)&&n==="stp:offlineOrRequestCancelled"}var n=this;n.isHttpError=t;n.isNotFoundError=r;n.isNotAuthorisedError=u;n.isConflict=e;n.isOfflineOrCancelled=i}]);angular.module("stp.core.forms").run(["formlyConfig","fieldsService",function(n,t){function i(t){var t=n.getType(t),i;t=angular.copy(t);i=t.wrapper.indexOf("label");i>=0&&(t.wrapper.splice(i,1),t.name=t.name+"-noLabel",n.setType(t))}function r(t){var t=n.getType(t),i;t=angular.copy(t);i=t.wrapper.indexOf("formGroup");i>=0&&(t.wrapper.splice(i,1),t.wrapper.push("formGroupMultiField"),t.name=t.name+"MultiField",n.setType(t))}n.templateManipulators.preWrapper.push(function(n,i,r){function u(){var n=f(r.options.formControl)||{$submitted:!1};return n.$submitted}function f(n){return n&&n.$$parentForm&&angular.isDefined(n.$$parentForm.$submitted)?f(n.$$parentForm):n}return n=angular.element(n),r.defaultLabel=t.getDefaultLabel(i.key),r.hasError=function(){var n=!1;return angular.isDefined(r.options.formControl)&&(n=angular.isArray(r.options.formControl)?_.some(r.options.formControl,{$invalid:!0}):r.options.formControl.$invalid),n&&u()},r.getError=function(){return angular.isDefined(r.options.formControl)&&angular.isArray(r.options.formControl)?r.options.formControl[0].$error:r.options.formControl.$error},r.isSubmitted=u,n});n.templateManipulators.postWrapper.push(function(n,t,i){return n=angular.element(n),i.to.focus&&_.each(n.find("[formly-focus]"),function(n){n.removeAttribute("formly-focus");n.setAttribute("stp-auto-focus","")}),n});n.setWrapper({name:"formGroup",template:'<div class="form-group" ng-class="{\'has-error\': hasError() }">  \t\t\t\t\t\t\t<formly-transclude><\/formly-transclude>\t\t\t\t\t\t\t<div ng-messages="getError()" ng-if="isSubmitted()" role="alert">\t\t\t\t\t\t\t\t    <small ng-message="required" class="help-block">{{ to.requiredValidationMessage || \'Please enter a value\'}}<\/small>\t\t\t\t\t\t\t\t    <small ng-message="uiSelectRequired" class="help-block">Please enter a value<\/small>\t\t\t\t\t\t\t\t    <small ng-message="parse" class="help-block">Invalid date<\/small>\t\t\t\t\t\t\t\t    <small ng-message="date" class="help-block">Invalid date<\/small>\t\t\t\t\t\t\t\t    <small ng-message="endDate" class="help-block">End Date must be later then Start Date<\/small>\t\t\t\t\t\t\t\t    <small ng-message="minDate" class="help-block">Please enter a later date<\/small>\t\t\t\t\t\t\t\t    <small ng-message="maxDate" class="help-block">Please enter an earlier date<\/small>\t\t\t\t\t\t\t\t    <small ng-message="integer" class="help-block">Invalid number<\/small>                                    <small ng-message="number" class="help-block">Invalid number<\/small>                                    <small ng-message="unique" class="help-block">This value is already used in the system<\/small>                                    <small ng-message="max" class="help-block">{{to.maxValidationMessage || \'Please enter a smaller number\'}}<\/small>                                    <small ng-message="maxlength" class="help-block">Please enter a smaller value<\/small>                                    <small ng-message="min" class="help-block">{{to.minValidationMessage || \'Please enter a larger number\'}}<\/small>                                    <small ng-message="minlength" class="help-block">Please enter a larger value<\/small>                                    <small ng-message="mediaListMaxSize" class="help-block">Maximum upload size exceeded<\/small>                                    <small ng-message="pattern" class="help-block">{{to.patternValidationMessage}}<\/small>                                    <small ng-message="confirm" class="help-block">{{to.confirmValidationMessage}}<\/small>                                    <small ng-message="custom" class="help-block">{{to.customValidationMessage}}<\/small>\t\t\t\t\t\t\t<\/div>\t\t\t\t\t   <\/div>'});n.setWrapper({name:"formGroupMultiField",template:'<div class="form-group" ng-class="{\'has-warning\': hasError() }">  \t\t\t\t\t\t\t<formly-transclude><\/formly-transclude>\t\t\t\t\t\t\t<div ng-messages="getError()" ng-if="isSubmitted()" role="alert">\t\t\t\t\t\t\t\t    <small ng-message="required" class="help-block">Please fill at least one of the following<\/small>\t\t\t\t\t\t\t\t    <small ng-message="uiSelectRequired" class="help-block">Please fill at least one of the following<\/small>\t\t\t\t\t\t\t<\/div>\t\t\t\t\t   <\/div>'});n.setWrapper({name:"label",template:'<div> \t\t\t\t\t   <label class="fg-label control-label">                            <span ng-if="!to.siteTextKey">{{to.label || defaultLabel}}<\/span>                             <span ng-if="to.siteTextKey"><metrocard-site-text site-text-key="to.siteTextKey"><\/metrocard-site-text><\/span> \t\t\t\t\t   \t    <span class="required-indicator" ng-if="to.required"><i class="zmdi zmdi-flare"><\/i><\/span>\t\t\t\t\t   <\/label> \t\t\t\t\t\t    <formly-transclude><\/formly-transclude> \t\t\t\t\t   <\/div>',overwriteOk:!0,apiCheck:function(n){return{templateOptions:{label:n.string.optional,required:n.bool.optional,siteTextKey:n.bool.optional}}}});n.setType({name:"text",template:'<stp-text ng-model="model[options.key]" />',wrapper:["label","formGroup"],overwriteOk:!0});i("text");n.setType({name:"password",template:'<stp-password ng-model="model[options.key]" />',wrapper:["label","formGroup"],overwriteOk:!0});i("password");r("text");i("textMultiField");n.setType({name:"integer",template:'<stp-integer ng-model="model[options.key]" />',wrapper:["label","formGroup"],overwriteOk:!0});i("integer");n.setType({name:"date",template:'<stp-date class="form-control fg-input" ng-model="model[options.key]" mindate="{{to.minDate}}" maxdate="{{to.maxDate}}"/>',wrapper:["label","formGroup"],overwriteOk:!0,controller:["$scope",function(n){function i(){angular.isDefined(n.to.defaultValue)&&(n.model[n.options.key]=angular.isFunction(n.to.defaultValue)?n.to.defaultValue():n.to.defaultValue)}var t=n.$watch("model[options.key]",function(n,r){n===r&&(n||i(),t())})}]});i("date");n.setType({name:"textarea",template:'<textarea class="form-control fg-input" rows="{{to.rows || 6}}" ng-model="model[options.key]" />',wrapper:["label","formGroup"],overwriteOk:!0,apiCheck:function(n){return{templateOptions:{rows:n.number.optional}}}});i("textarea");n.setType({name:"markupTextarea",template:'<textarea froala="froalaOptions" class="form-control fg-input" rows="{{to.rows || 6}}" ng-model="model[options.key]" />',wrapper:["label","formGroup"],overwriteOk:!0,controller:["$scope",function(n){n.froalaOptions={toolbarButtons:["bold","italic","underline","formatOL","formatUL","outdent","indent","fontSize","insertLink","undo","redo"],toolbarSticky:!1};n.to.heightMin&&(n.froalaOptions.heightMin=n.to.heightMin)}],apiCheck:function(n){return{templateOptions:{rows:n.number.optional}}}});i("markupTextarea");n.setType({name:"checkbox",template:'<div class="checkbox">                        <label>                            <input class="checkbox" type="checkbox" ng-model="model[options.key]" ng-true-value="true" ng-false-value="false" />                            <i class="input-helper"><\/i>                            <span ng-if="!(to.siteTextKey || to.labelIsHtml)">{{to.label || defaultLabel}}<\/span>                             <span ng-if="to.labelIsHtml" ng-bind-html="to.label"><\/span>                             <span ng-if="to.siteTextKey"><metrocard-site-text site-text-key="to.siteTextKey"><\/metrocard-site-text><\/span>                     <\/label>                <\/div>',wrapper:["formGroup"],overwriteOk:!0,apiCheck:function(n){return{templateOptions:{label:n.string.optional,labelIsHtml:n.bool.optional,required:n.bool.optional,siteTextKey:n.string.optional}}}});r("checkbox");n.setType({name:"optionalInteger",template:'<div class="row">                        <div ng-class="model[to.hasValueKey] ? \'col-md-6\' : \'col-md-12\'">                           <div class="select">                            <ui-select class="form-control" ng-model="model[to.hasValueKey]" theme="bootstrap">                                <ui-select-choices repeat="opt.value as opt in to.options | filter: $select.search">                                    {{opt.name}}                                <\/ui-select-choices>                                <ui-select-match allow-clear="true">                                    <span ng-bind="$select.selected.name"><\/span>                                <\/ui-select-match>                            <\/ui-select>                           <\/div>                        <\/div>                        <div class="col-md-6" ng-if="model[to.hasValueKey]" ng-class="{\'has-error\': model[options.key].$invalid && isSubmitted()}">                            <div>                                <stp-integer placeholder="{{to.placeholderLabel}}" ng-model="model[options.key]" />\t\t\t\t\t\t\t<\/div>                            <div ng-messages="options.formControl[options.formControl.length - 1].$error" ng-if="form.$$parentForm.$submitted" role="alert">\t\t\t\t\t            <small ng-message="min" class="help-block">Enter nothing or a positive value<\/small>\t\t\t\t\t\t\t<\/div>                       <\/div>                    <\/div>',wrapper:["label","formGroup"],overwriteOk:!0,controller:["$scope",function(n){n.to.options=[{name:"No",value:!1},{name:"Yes",value:!0}];var t=n.$watch("model[options.key]",function(i,r){i===r&&(n.model[n.options.key]=i,t())});n.$watch("model[to.hasValueKey]",function(t,i){i===t||t||(n.model[n.options.key]=null)})}],apiCheck:function(n){return{templateOptions:{hasValueKey:n.string}}}});i("optionalInteger");n.setType({name:"lookup",template:'<stp-lookup ng-model="model[options.key]" lookup-name="to.lookupName" multiple="to.multiple" other-option-value="model[to.otherOptionKey]" other-option-field-name="to.otherOptionKey"><\/stp-lookup>',wrapper:["label","formGroup"],overwriteOk:!0,controller:["$scope","lookupService",function(n){n.to.lookupName||(n.to.lookupName=t.getDefaultLookupName(n.options.key))}],apiCheck:function(n){return{templateOptions:{lookupName:n.string.optional}}}});i("lookup");n.setType({name:"select",template:'<div class="select">                            <ui-select ui-select-required="{{to.required}}" class="form-control" ng-model="model[options.key]" theme="bootstrap">                                <ui-select-choices repeat="option.id as option in to.options | filter: $select.search">                                    {{option.name}}                                <\/ui-select-choices>                                <ui-select-match allow-clear="true">                                    <span ng-bind="$select.selected.name"><\/span>                                <\/ui-select-match>                            <\/ui-select>                        <\/div>',wrapper:["label","formGroup"],overwriteOk:!0});i("select");n.setType({name:"multiSelect",template:'<div class="select">                            <ui-select ui-select-required="{{to.required}}" multiple ng-model="model[options.key]" class="form-control" theme="bootstrap">                                <ui-select-choices repeat="option.id as option in to.options | filter: $select.search">                                    {{option.name}}                                <\/ui-select-choices>                                <ui-select-match allow-clear="true">                                    {{$item.name}}                                <\/ui-select-match>                            <\/ui-select>                        <\/div>',wrapper:["label","formGroup"],overwriteOk:!0});i("multiSelect");n.setType({name:"selectTable",controller:["$scope","$parse",function(n,t){n.list=t(n.to.list)(n)}],template:'<stp-select-table-control list="model[options.key]" lookup-id-field="{{to.lookupIdField}}" on-new-item="to.onNewItem(id)" table-template-url="{{to.tableTemplateUrl}}" controller-extensions="to.controllerExtensions" />',wrapper:["formGroup"],overwriteOk:!0,apiCheck:function(n){return{templateOptions:{lookupIdField:n.string,tableTemplateUrl:n.string}}}});i("selectTable");n.setType({name:"yesNoLookup",template:'<stp-yes-no ng-model="model[options.key]" />',wrapper:["label","formGroup"],overwriteOk:!0});i("yesNoLookup");n.setType({name:"roleLookup",template:'<div class="select">                            <ui-select multiple ui-select-required="{{to.required}}" ng-model="model[options.key]" class="form-control" theme="bootstrap">                                <ui-select-choices group-by="\'group\'" repeat="option.id as option in to.roles | filter: $select.search">                                    {{option.displayName}}                                <\/ui-select-choices>                                <ui-select-match allow-clear="true">                                    {{$item.displayName}}                                <\/ui-select-match>                            <\/ui-select>                        <\/div>',wrapper:["label","formGroup"],overwriteOk:!0,controller:["$scope","roleService",function(n,t){t.getRoles().then(function(t){n.to.roles=t})}]});i("roleLookup");n.setType({name:"keepDeleteBool",template:'<div class="select">                        <ui-select ng-model="model[options.key]" class="form-control" theme="bootstrap">                            <ui-select-choices repeat="option.value as option in ddOptions | filter: $select.search">                                {{option.name}}                            <\/ui-select-choices>                            <ui-select-match allow-clear="true">                                <span ng-bind="$select.selected.name"><\/span>                            <\/ui-select-match>                        <\/ui-select>                      <div>',wrapper:["label","formGroup"],overwriteOk:!0,controller:["$scope",function(n){n.ddOptions=[{value:!1,name:"Delete"},{value:!0,name:"Keep"}]}]});i("keepDeleteBool");n.setType({name:"currency",template:'<stp-currency ng-model="model[options.key]" />',wrapper:["label","formGroup"],overwriteOk:!0});i("currency")}]);angular.module("stp.core.forms").run(["$templateCache",function(n){n.put("template/tabs/tabset.html",'<div class="clearfix"><ul class="tab-nav" ng-class="{\'tn-vertical\': vertical, \'tn-justified\': justified, \'tab-nav-right\': right}" ng-transclude><\/ul><div class="tab-content"><div class="tab-pane" ng-repeat="tab in tabs" ng-class="{active: tab.active}" uib-tab-content-transclude="tab"><\/div><\/div><\/div>')}]);angular.module("stp.core.forms").directive("stpAutoFocus",[function(){return{restrict:"A",link:function(n,t){var i=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);i||window.setTimeout(function(){var n=t.find(".ui-select-focusser");n&&n.length>0?n.get(0).focus():t.get(0).focus()},300)}}}]);angular.module("stp.core.forms").controller("ButtonSelectController",["$scope","lookupService",function(n,t){function u(){var t=n.$watch("ctrl.model",function(n,i){n===i&&(r=n,t())})}function f(n){return!n.archived||r&&r===n.id}var i=this,r;i.lookupOptions=t.getLookups([i.lookupName]);i.activeLookupsOnly=f;u()}]);angular.module("stp.core.forms").directive("stpButtonSelect",[function(){return{restrict:"E",scope:{model:"=ngModel",lookupName:"="},templateUrl:"/libs/stp-core-app/forms/directives/buttonselect.html",controller:"ButtonSelectController",controllerAs:"ctrl",bindToController:!0}}]);angular.module("stp.core.forms").directive("stpCard",function(){return{restrict:"E",templateUrl:"/libs/stp-core-app/forms/directives/card.html",replace:!0,transclude:!0,scope:{heading:"@",subHeading:"@",options:"=?"},bindToController:!0,controllerAs:"cardCtrl",controller:[function(){this.options=angular.extend({padding:!0},this.options||{})}],link:function(n,t,i){i.$observe("subHeading",function(t){n.cardCtrl.subHeading=t})}}});angular.module("stp.core.forms").directive("stpCardForm",function(){return{restrict:"E",templateUrl:"/libs/stp-core-app/forms/directives/cardform.html",replace:!0,transclude:!0,scope:{heading:"@",originalModel:"=formlyModel",formlyFieldsPromiseOrArray:"=formlyFields",onSaveCallback:"&onSave",onCompleteCallback:"&onComplete",onCancelCallback:"&?onCancel",submitButtonText:"@?"},bindToController:!0,controllerAs:"cardCtrl",controller:["$scope","$q","fieldsService",function(n,t,i){function e(){r.originalModel||(r.originalModel={});r.formlyModel=i.cloneObject(r.originalModel);r.submitButtonText||(r.submitButtonText="Save");t.when(r.formlyFieldsPromiseOrArray).then(function(n){r.formlyFields=angular.copy(n);r.isLoaded=!0})}function o(){r.onCancelCallback?r.onCancelCallback():f(!1)}function s(n){n.$valid&&(r.showSpinner=!0,h(n).then(function(){r.onSaveCallback||f(!0,r.formlyModel);t.when(r.onSaveCallback({model:r.formlyModel,uploadFiles:n.uploadFiles})).then(function(n){f(!0,n)}).finally(function(){r.showSpinner=!1})}))}function h(n){var i=[];return _.forEach(u,function(t){i.push(t.call(null,n,r.formlyModel))}),t.all(i)}function f(n,t){if(n?r.originalModel=angular.extend(r.originalModel,i.getPlainObject(t)):r.formlyModel=i.cloneObject(r.originalModel),r.onCompleteCallback)r.onCompleteCallback({model:t})}function c(n){u.push(n)}var r=this,u;r.onSave=s;r.onCancel=o;r.showSpinner=!1;r.isLoaded=!1;r.registerSaveCallback=c;e();u=[]}]}});angular.module("stp.core.forms").directive("stpCurrency",function(){return{restrict:"E",require:"ngModel",replace:!0,template:'<input type="text" class="form-control fg-input" ng-currency step="0.1"><\/input>'}});angular.module("stp.core.forms").directive("stpDataTable",[function(){return{restrict:"E",templateUrl:"/libs/stp-core-app/forms/directives/dataTable.html",scope:{entityService:"="},controllerAs:"ctrl",bindToController:!0,controller:["fieldsService",function(n){function i(n){if(!angular.isObject(n)||!n.hasOwnProperty("id"))throw"Expected entity object with id field";t.entityService.view(n.id)}function r(n){if(!angular.isObject(n)||!n.hasOwnProperty("id"))throw"Expected entity object with id field";t.entityService.remove(n)}var t=this;if(t.viewEntity=i,t.removeEntity=r,!t.entityService.tableFields)throw"Expected table fields";t.tableFields=n.annotateTableFields(t.entityService.tableFields)}]}}]);angular.module("stp.core.forms").directive("stpDataTableField",["$compile",function(n){return{restrict:"E",scope:{field:"=",entity:"="},controllerAs:"ctrl",bindToController:!0,controller:[function(){var n=this;n.value=n.entity[n.field.key]}],link:function(t,i){t.$watch("ctrl.field",function(r){var u;if(!r)throw"Expected a value for "+this.field.Key;return u=r.valueTemplate?r.valueTemplate:r.type==="date"?"{{ctrl.value | date:'mediumDate'}}":r.type==="lookup"?'<stp-display-lookup field="ctrl.value" lookup="{{ctrl.field.lookupName}}" other-option-field="ctrl.entity[ctrl.field.otherOptionField]" options="{showLabel: false}"><\/stp-display-lookup>':r.type==="yesNoLookup"?"{{ctrl.value | yesNo}}":"{{ctrl.value}}",i.html(u),n(i.contents())(t)})}}}]);angular.module("stp.core.forms").directive("stpDate",function(){return{restrict:"E",require:"ngModel",replace:!0,template:'<input type="text" ui-mask="99/99/9999" ui-mask-placeholder><\/input>',scope:{},link:function(n,t,i,r){function e(n){if(!n)return null;var t=moment(n,["DDMMYYYY","DDMMYY"],!0);return t.isValid()?t.toDate():undefined}var u,f;i.$observe("mindate",function(n){u=!n!=""||angular.isUndefined(n)?undefined:moment(n.replace(/\"/g,""))});i.$observe("maxdate",function(n){f=!n!=""||angular.isUndefined(n)?undefined:moment(n.replace(/\"/g,""))});i.$observe("disabled",function(n){i.uiMask=n?"":"99/99/9999"});r.$parsers.push(function(n){return e(n)});r.$formatters.push(function(n){return n?moment(n).format("DD/MM/YYYY"):null});r.$validators.date=function(n){return!n||angular.isString(n)?!0:n.getFullYear()<=1900?!1:!0};r.$validators.minDate=function(n){return!n||angular.isUndefined(u)||moment(n).diff(u)>=0?!0:!1};r.$validators.maxDate=function(n){return!n||angular.isUndefined(f)||moment(n).diff(f)<=0?!0:!1}}}});angular.module("stp.core.forms").directive("stpDecimal",function(){return{restrict:"E",require:"ngModel",replace:!0,template:'<input type="number" class="form-control fg-input" step="0.1"><\/input>'}});angular.module("stp.core.forms").directive("stpDisplayBadge",[function(){return{restrict:"E",transclude:!0,replace:!0,template:'<dl class="dl-horizontal"><dt>{{ctrl.labelText}}<\/dt>  \t\t\t\t                <dd><span class="badge">{{ctrl.display | stpIfNull}}<\/span><\/dd>                             <\/dl>',scope:{display:"=field",fieldName:"@field",label:"@"},bindToController:!0,controllerAs:"ctrl",controller:["fieldsService",function(n){this.labelText=this.label||n.getDefaultLabel(this.fieldName)}]}}]);angular.module("stp.core.forms").directive("stpDisplayBoolean",[function(){return{restrict:"E",transclude:!0,replace:!0,template:'<dl class="dl-horizontal"><dt>{{ctrl.labelText}}<\/dt>  \t\t\t\t                <dd>{{ctrl.display | yesNo | stpIfNull}}<\/dd>                             <\/dl>',scope:{display:"=field",fieldName:"@field",label:"@"},bindToController:!0,controllerAs:"ctrl",controller:["fieldsService",function(n){this.labelText=this.label||n.getDefaultLabel(this.fieldName)}]}}]);angular.module("stp.core.forms").directive("stpDisplayCurrency",[function(){return{restrict:"E",transclude:!0,replace:!0,template:'<dl class="dl-horizontal"><dt>{{ctrl.labelText}}<\/dt>  \t\t\t\t                <dd>{{ctrl.display | currency | stpIfNull}}<\/dd>                             <\/dl>',scope:{display:"=field",fieldName:"@field",label:"@"},bindToController:!0,controllerAs:"ctrl",controller:["fieldsService",function(n){this.labelText=this.label||n.getDefaultLabel(this.fieldName)}]}}]);angular.module("stp.core.forms").directive("stpDisplayDate",[function(){return{restrict:"E",transclude:!0,replace:!0,template:'<dl class="dl-horizontal"><dt>{{ctrl.labelText}}<\/dt>  \t\t\t\t                <dd>{{ctrl.display | date}}<\/dd>                             <\/dl>',scope:{display:"=field",fieldName:"@field",label:"@"},bindToController:!0,controllerAs:"ctrl",controller:["fieldsService",function(n){this.labelText=this.label||n.getDefaultLabel(this.fieldName)}]}}]);angular.module("stp.core.forms").directive("stpDisplayField",["$compile",function(n){return{restrict:"E",transclude:!0,replace:!0,scope:{display:"=field",fieldName:"@field",label:"@",postfix:"@",options:"=?"},link:function(t,i){var r="<span ng-bind=\"ctrl.textToShow | stpPostfix:ctrl.postfix | stpIfNull\"><\/span>                     <span ng-if='ctrl.truncated'><br/><a ng-click='ctrl.showMore()' href=\"#\">Show More<\/a><\/span>                     <span ng-if='ctrl.showAll'><br/><a ng-click='ctrl.showLess()' href=\"#\">Show Less<\/a><\/span>";t.ctrl.options&&t.ctrl.options.showLabel===!1||(r='<dl class="dl-horizontal"><dt ng-if="ctrl.options.showLabel">{{ctrl.labelText}}<\/dt><dd>'+r+"<\/dd><\/dl>");r='<span ng-if="ctrl.showControl">'+r+"<\/span>";i.html(r);n(i.contents())(t)},bindToController:!0,controllerAs:"ctrl",controller:["fieldsService","$scope",function(n,t){function u(){i.labelText=i.label||n.getDefaultLabel(i.fieldName);t.$watch("ctrl.display",function(){i.textToShow=r();i.showControl=!i.options.hideIfNull||i.textToShow})}function r(){return i.display&&angular.isString(i.display)?i.showAll||i.options.doNotTruncate?(i.truncated=!1,i.display):i.display.length<150?(i.truncated=!1,i.display):(i.truncated=!0,i.display.substring(0,150)+"..."):i.display}var i=this;i.truncated=!1;i.showAll=!1;i.textToShow=null;i.showControl=!1;i.options=i.options||{showLabel:!0};u();i.showMore=function(){i.showAll=!0;i.textToShow=r()};i.showLess=function(){i.showAll=!1;i.textToShow=r()}}]}}]);angular.module("stp.core.forms").directive("stpDisplayHtml",["$compile",function(n){return{restrict:"E",transclude:!0,replace:!0,scope:{display:"=field",fieldName:"@field",label:"@",postfix:"@",options:"=?"},link:function(t,i){var r='<span ng-bind-html="ctrl.display | stpPostfix:ctrl.postfix | stpIfNull"><\/span>';t.ctrl.options.showLabel&&(r='<dl class="dl-horizontal"><dt ng-if="ctrl.options.showLabel">{{ctrl.labelText}}<\/dt><dd>'+r+"<\/dd><\/dl>");r='<span ng-if="ctrl.showControl">'+r+"<\/span>";i.html(r);n(i.contents())(t)},bindToController:!0,controllerAs:"ctrl",controller:["fieldsService","$scope",function(n,t){function r(){i.labelText=i.label||n.getDefaultLabel(i.fieldName);t.$watch("ctrl.display",function(){i.showControl=!i.options.hideIfNull||i.display})}var i=this;i.showControl=!1;i.options=i.options||{showLabel:!0};r()}]}}]);angular.module("stp.core.forms").directive("stpDisplayLookup",["$compile",function(n){return{restrict:"E",scope:{display:"=field",lookup:"@?",lookupField:"@field",otherOptionField:"=?",label:"@",options:"=?"},link:function(t,i){var r='<span ng-if="showControl && !displayOptions.showLabel">{{lookupText}}<\/span>                             <dl ng-if="showControl && displayOptions.showLabel" ng-show="display || displayOptions.showDefaultValue" class="dl-horizontal" ><dt>{{labelText}}<\/dt>  \t\t\t\t                <dd ng-bind="lookupText"> \t\t\t\t            <\/dd><\/dl>';t.options&&t.options.showLabel===!1&&(r="<span ng-bind='lookupText'><\/span>");i.html(r);n(i.contents())(t)},controller:["$scope","$filter","lookupService","fieldsService",function(n,t,i,r){function o(t){n.displayOptions.useLookupDataSource?h(t):s(t)}function s(t){e.$promise.then(function(){var r,i;n.display&&e[f]||u(null);t&&angular.isArray(t)?(r=_.map(t,function(n){return _.find(e[f],{id:n}).name}).join(", "),u(r)):(i=_.find(e[f],{id:t}),i&&(i.isOtherOption?u(n.otherOptionField):u(i.name||t)));n.showControl=!n.displayOptions.hideIfNull||n.lookupText})}function h(t){i.getLookupValueAsync(f,t).then(function(i){i.isOtherOption?u(n.otherOptionField):u(i.name||t);n.showControl=!n.displayOptions.hideIfNull||n.lookupText})}function u(i){n.lookupText=n.displayOptions.hideIfNull?i:t("stpIfNull")(i)}var f=r.getDefaultLookupName(n.lookup||n.lookupField),e=i.getLookups([f]);n.labelText=n.label||r.getDefaultLabel(n.lookup||n.lookupField);n.displayOptions=angular.extend({showLabel:!0,showDefaultValue:!0,hideIfNull:!1,useLookupDataSource:!1},n.options||{});n.showControl=!1;n.$watch("display",function(n,t){n!==t&&o(n)});n.$watch("otherOptionField",function(t,i){t!==i&&o(n.display)});o(n.display)}]}}]);angular.module("stp.core.forms").directive("stpDisplayOptionalInteger",[function(){return{restrict:"E",transclude:!0,replace:!0,template:'<dl class="dl-horizontal"><dt>{{ctrl.labelText}}<\/dt> \t\t\t\t                <dd>{{ctrl.hasValueField | yesNo | stpIfNull}} {{ctrl.display | surroundWithBrackets}}<\/dd>                             <\/dl>',scope:{display:"=field",fieldName:"@field",hasValueField:"=",label:"@"},bindToController:!0,controllerAs:"ctrl",controller:["fieldsService",function(n){this.labelText=this.label||n.getDefaultLabel(this.fieldName)}]}}]);angular.module("stp.core.forms").directive("stpDisplayRoles",[function(){return{restrict:"E",template:'<dl ng-class="{\'dl-horizontal\': ctrl.displayOptions.showLabel}"><dt ng-show="ctrl.displayOptions.showLabel">{{ctrl.labelText}}<\/dt>                                     <dd ng-bind="ctrl.roleText | stpIfNull">                             <\/dl>',scope:{display:"=field",fieldName:"@field",label:"@",options:"=?"},bindToController:!0,controllerAs:"ctrl",controller:["$scope","roleService","fieldsService",function(n,t,i){function e(){f=t.getRoles();n.$watch("ctrl.display",function(n,t){r.roleText&&n===t||o(n)})}function o(n){f.then(function(t){if(!angular.isArray(n))throw"Expected array of Role Ids";r.roleText=_.chain(n).map(function(n){return _.find(t,{id:n})}).pluck("displayName").value().join(", ")})}var r=this,u,f;r.labelText=r.label||i.getDefaultLabel(r.fieldName);r.displayOptions=null;e();u={showLabel:!0};r.displayOptions=angular.extend(u,r.options||{})}]}}]);angular.module("stp.core.forms").directive("stpEditTable",["messageBoxService","$filter",function(n,t){return{restrict:"E",templateUrl:"/libs/stp-core-app/forms/directives/edittable.html",scope:{headerTemplate:"@",detailTemplate:"@",editTemplate:"@",footerTemplate:"@",noDataTemplate:"@",items:"=",orderBy:"=",filterBy:"=",onNew:"&?",onClick:"=",onDelete:"&?",onActionClick:"&?",isActionEnabledCallback:"&?isActionEnabled",beforeEdit:"=",onSave:"&",editScope:"=",validate:"=",canEdit:"&",canEditItem:"=",canDelete:"&",canInsert:"&",addButtonCaption:"@"},controller:["$scope","$q",function(i){function f(n){i.editItem=n;i.editScope.item=n}var r=this,u=!1;i.addCaption=i.addButtonCaption||"New";i.editScope=i.editScope||{};i.editScope.originalItem=null;i.showSpinner=!1;i.canEdit()===undefined&&(i.canEdit=function(){return!0});i.canDelete()===undefined&&(i.canDelete=function(){return!0});i.canInsert()===undefined&&(i.canInsert=function(){return!0});i.formHolder={};r.beforeEdit=function(n){i.beforeEdit&&i.beforeEdit(n)};r.canEditItem=function(n){return i.canEditItem?i.canEditItem(n):!0};r.onSave=function(n){if(!i.onSave)throw"No Save handler";return i.onSave({item:n})};r.validate=function(n){return i.validate?i.validate(n):!0};r.afterSave=function(){r.applyFilters()};r.applyFilters=function(){var n=i.items;i.orderBy&&(n=t("orderBy")(n,i.orderBy));i.filterBy&&(n=t("filter")(n,i.filterBy,!1));i.filteredItems=n};i.$watchCollection("items",r.applyFilters,!1);i.$watchCollection("filterBy",r.applyFilters);i.newItem=function(){u=!0;var n={};i.onNew&&(n=i.onNew());r.beforeEdit(n);f(n);i.editScope.originalItem=null};i.click=function(n){if(i.onClick)i.onClick(n);else i.edit(n)};i.actionClick=function(n,t){if(i.onActionClick){i.onActionClick({action:n,item:t});r.applyFilters()}};i.isActionEnabled=function(n,t){return i.isActionEnabledCallback?i.isActionEnabledCallback({action:n,item:t}):!0};i.edit=function(n){i.canEdit()&&!i.editingIsTakingPlace()&&r.canEditItem(n)&&(i.editScope.originalItem=angular.copy(n),r.beforeEdit(n),f(n))};i.inserting=function(){return u};i.itemBeingEdited=function(n){return i.editScope.item===n};i.doCancel=function(){angular.copy(i.editScope.originalItem,i.editScope.item);f(null);u=!1};i.editingIsTakingPlace=function(){return i.editScope.item!=null};i.hideNew=function(){return i.editScope.item!=null};i.delete=function(t){function r(){_.remove(i.items,t);f(null)}n.confirm("Are you sure you want to delete this item?")&&(i.onDelete?(i.showSpinner=!0,i.onDelete({item:t}).then(function(){r()}).finally(function(){i.showSpinner=!1})):angular.isDefined(i.editScope.item.$delete)&&angular.isFunction(i.editScope.item.$delete)?t.$delete({id:t.id},function(){r()}):r())};i.doSave=function(){i.formHolder.form.$valid&&i.save()};i.formIsValid=function(){return i.formHolder.form.$valid};i.save=function(){r.validate(i.editScope.item)&&(i.showSpinner=!0,r.onSave(i.editScope.item).then(function(n){i.editScope.item=n;i.onSaveSuccess();r.afterSave(i.editScope.item)}).finally(function(){i.showSpinner=!1}))};i.invoke=function(n,t){n(t).call(t,i.onSaveSuccess,i.onSaveFailure)};i.processSavedItem=function(){u&&i.items.push(i.editScope.item);f(null);u=!1};i.onSaveSuccess=function(){i.processSavedItem()};i.onSaveFailure=function(){n.alert("Save failed");u=!1};i.getFooterTemplate=function(){return!u&&i.items&&i.items.length===0?i.noDataTemplate:i.footerTemplate};i.isNew=function(){return i.editScope.item.id===0||i.editScope.item.id===undefined};i.isDirty=function(){return!angular.equals(i.editScope.item,i.editScope.originalItem)};i.canSave=function(){return i.isDirty()||i.isNew()};i.canCancel=function(){return!0}}]}}]);angular.module("stp.core.forms").directive("stpEnvironment",[function(){return{restrict:"E",template:'<div class="environment-name environment-{{ctrl.environment}}">{{ ctrl.environment | uppercase }} SITE<\/div>',bindToController:!0,controllerAs:"ctrl",controller:["applicationConfiguration",function(n){this.environment=n.environment}]}}]);angular.module("stp.core.forms").directive("stpExpander",[function(){return{restrict:"E",transclude:!0,replace:!0,templateUrl:"/libs/stp-core-app/forms/directives/expander.html",scope:{},bindToController:!0,controllerAs:"exanderController",controller:[function(){function t(){n.expanded=!n.expanded}var n=this;n.expanded=!1;n.toggle=t}]}}]);angular.module("stp.core.forms").directive("stpFocusTag",["$timeout",function(n){return function(t,i,r){t.$on("focusService:setFocus",function(t,u){var f,e;u===r.stpFocusTag&&(i.is("input,select,textarea")?f=i:(e=i.find("input:visible,select:visible,textarea:visible"),e&&e.length>0&&(f=e[0])),f&&n(function(){f.focus()},0))})}}]);angular.module("stp.core.forms").directive("stpInteger",function(){return{restrict:"E",require:"ngModel",replace:!0,template:'<input type="number" class="form-control fg-input"><\/input>',link:function(n,t,i,r){r.$validators.integer=function(n,t){return r.$isEmpty(n)?!0:/^\-?\d+$/g.test(t)?!0:!1}}}});angular.module("stp.core.forms").controller("lookupDirectiveController",["$scope","lookupService",function(n,t){function f(){var t=n.$watch("ctrl.model",function(n,i){n===i&&(r=n,h(),t())})}function e(){for(var n=i.form,t=n.$submitted;n&&!t;)n=n.$$parentForm,t=n&&n.$submitted;return t}function o(n){return n?_.find(i.lookupOptions[i.lookupName],{id:n}):null}function u(n){if(!i.otherOptionFieldName)return!1;var t=o(n);return t?t.isOtherOption:!1}function s(n){return!n.archived||r&&r===n.id}function h(){i.lookupOptions.$promise.then(function(){n.$watch("ctrl.model",function(n,t){n&&!u(n)&&i.otherOptionValue&&(i.otherOptionValue=null);n!==t&&i.onChange&&i.onChange()})})}var i=this,r;i.activeLookupsOnly=s;i.lookupOptions=t.getLookups([i.lookupName]);i.isOtherOptionSelected=u;i.showOtherFieldError=e;r=null;f()}]);angular.module("stp.core.forms").directive("stpLookup",function(){return{restrict:"E",require:["^?form","ngModel"],scope:{model:"=ngModel",lookupName:"=",multiple:"=?",otherOptionValue:"=?",otherOptionFieldName:"=?",onChange:"&?ngChange",placeholder:"=?"},templateUrl:"/libs/stp-core-app/forms/directives/lookup.html",controller:"lookupDirectiveController",controllerAs:"ctrl",bindToController:!0,link:function(n,t,i,r){n.ctrl.form=r[0];var u=r[1];n.ctrl.multiple&&u.$validators.required&&(u.$validators.required=function(n){return n&&n.length>0?!0:!1})}}});angular.module("stp.core.forms").directive("stpNotes",function(){return{restrict:"E",replace:!0,template:'<textarea class="form-control fg-textarea"><\/textarea>'}});angular.module("stp.core.forms").directive("onClickAway",["$document",function(n){return{link:function(t,i,r){var u=!1,f=function(n){if(u){u=!1;return}var f=$(i).has(n.target).length>0,e=i[0]===n.target,o=f||e;o||t.$apply(r.onClickAway)};t.$watch(r.onClickAwayActive,function(t,i){if(t===!0){u=!0;n.on("click",f)}else t!==i&&t===!1&&n.unbind("click",f)});t.$on("$destroy",function(){n.off("click",f)})}}}]);angular.module("stp.core.forms").directive("stpPager",function(){return{restrict:"E",replace:!0,templateUrl:"/libs/stp-core-app/forms/directives/pager.html",scope:{dataSource:"=datasource"},bindToController:!0,controllerAs:"ctrl",controller:function(){}}});angular.module("stp.core.forms").directive("stpPassword",function(){return{restrict:"E",replace:!0,template:'<input type="password" class="form-control fg-input"><\/input>'}});angular.module("stp.core.forms").directive("stpRouteTabs",[function(){return{restrict:"E",template:'<div class="route-tabs">                                 <tabs data="data" type="tabs" justified="true" />                                 <div class="route-tabs-content">                                     <ui-view/>                                 <\/div>                            <\/div>',scope:{data:"=tabs"}}}]);angular.module("stp.core.forms").directive("stpScrollToTop",[function(){return{restict:"A",link:function(n){n.$on("$stateChangeSuccess",function(){$("html, body").animate({scrollTop:"0"},200)})}}}]);angular.module("stp.core.forms").controller("SearchBarController",[function(){function t(){}function i(){n.onSearch({searchTerm:n.searchTerm})}var n=this;n.search=i;t()}]);angular.module("stp.core.forms").directive("stpSearchBar",[function(){return{restrict:"E",templateUrl:"/libs/stp-core-app/forms/directives/searchbar.html",scope:{placeholder:"@",onSearch:"&"},bindToController:!0,controllerAs:"ctrl",controller:"SearchBarController"}}]);angular.module("stp.core.forms").controller("SelectTableController",["$scope",function(n){function i(){var i=n.$watch(function(){return t.list},function(n,t){n===t&&(r(),i())})}function r(){t.list=t.list||[];t.listIds=_.map(t.list,t.lookupIdField);u()}function u(){n.$watchCollection(function(){return t.listIds},f)}function f(n,i){if(n!==i){var r=_.map(t.list,t.lookupIdField),u=_.difference(n,r),f=_.difference(r,n);_.remove(t.list,function(n){return _.contains(f,n[t.lookupIdField])});_.forEach(u,function(n){var i=t.onNewItem({id:n});t.list.push(i)})}}var t=this;t.listIds=[];i()}]);angular.module("stp.core.forms").directive("stpSelectTableControl",[function(){return{restrict:"E",scope:{list:"=",lookupIdField:"@",tableTemplateUrl:"@",controllerExtensions:"=",onNewItem:"&"},templateUrl:"/libs/stp-core-app/forms/directives/selecttablecontrol.html",controller:"SelectTableController",controllerAs:"ctrl",bindToController:!0}}]);angular.module("stp.core.forms").directive("stpSpinner",function(){return{restrict:"E",templateUrl:"/libs/stp-core-app/forms/directives/spinner.html",replace:!0,transclude:!0,scope:{show:"="},bindToController:!0,controllerAs:"spinnerCtrl",controller:[function(){}]}});angular.module("stp.core.forms").directive("stpText",function(){return{restrict:"E",replace:!0,template:'<input type="text" class="form-control fg-input"><\/input>'}});angular.module("stp.core.forms").directive("uiSelectRequired",[function(){return{restrict:"A",require:"ngModel",link:function(n,t,i,r){var u=!1,e,f=!1,o=n.$watch(function(){return r.$modelValue},function(n,t){n===t&&(e=n,f=!0,o())});i.$observe("uiSelectRequired",function(n){u=n=="true"||n===!0});r.$validators.uiSelectRequired=function(n){return!f||!u?!0:angular.isArray(n)?n.length>0:angular.isDefined(n)}}}}]);angular.module("stp.core.forms").directive("stpUnique",function(){return{restrict:"A",require:"ngModel",scope:{uniqueCheckPromise:"&",id:"=?"},link:function(n,t,i,r){t.bind("blur",function(){if(r&&t.val()){var i=t.val();n.uniqueCheckPromise(i,n.id).then(function(n){i==t.val()&&r.$setValidity("unique",n)},function(){r.$setValidity("unique",!0)})}})}}});angular.module("stp.core.forms").directive("validateUnique",["$parse",function(n){return{restrict:"A",require:"ngModel",link:function(t,i,r,u){function h(n){return f!==n}var e=n(r.validateUnique)(t),f,o=!1,s=t.$watch(function(){return u.$modelValue},function(n,t){n===t&&(f=n,o=!0,s())});u.$validators.validateUnique=function(n){var t,i;return o?h(n)?!n||n===f?!0:(t={},t[e.propertyName]=n,i=_.find(e.list,t),i)?!1:!0:!0:!0}}}}]);angular.module("stp.core.forms").directive("stpWizard",function(){return{restrict:"E",templateUrl:"/libs/stp-core-app/forms/directives/wizard.html",replace:!0,transclude:!0,scope:{title:"@",pages:"=",onComplete:"&"},bindToController:!0,controllerAs:"ctrl",controller:["$q","$state","fieldsService",function(n,t){function s(){var n=_.findIndex(i.pages,function(n){return n.state==t.current.name}),r=n!==-1?n:0;f(r)}function h(){r&&r.onBack?n.when(r.onBack()).then(function(n){n&&e()}):e()}function e(){f(u-1)}function c(){r&&r.onNext?n.when(r.onNext()).then(function(n){n&&o()}):o()}function o(){u+1===i.pages.length?i.onComplete&&i.onComplete():f(u+1)}function f(n){r=null;t.go(i.pages[n].state,t.params).then(function(){u=n;i.canGoBack=u>0;i.canGoNext=!0;i.nextText=u+1===i.pages.length?"Finish":"Next";i.currentPageNo=u+1})}function l(n){r=n;i.currentPageTitle=n.title}var u=0,r=null,i=this;i.canGoBack=!1;i.canGoNext=!0;i.backText="Back";i.nextText="Next";i.currentPageTitle="";i.currentPageNo=1;i.totalPages=i.pages.length;i.moveBack=h;i.moveNext=c;i.registerCurrentPage=l;s()}]}});angular.module("stp.core.forms").directive("stpWizardBackNext",function(){return{restrict:"E",templateUrl:"/libs/stp-core-app/forms/directives/wizardbacknext.html",replace:!0,scope:{wizard:"=",allowBack:"&?",allowNext:"&?",enableBack:"&?",enableNext:"&?"},bindToController:!0,controllerAs:"ctrl",controller:["$q",function(n){function i(){return t.enableBack?t.enableBack():t.wizard.canGoBack}function r(){return t.enableNext?t.enableNext():t.wizard.canGoNext}function u(){t.allowBack?n.when(t.allowBack()).then(function(n){n&&t.wizard.moveBack()}):t.wizard.moveBack()}function f(){t.allowNext?n.when(t.allowNext()).then(function(n){n&&t.wizard.moveNext()}):t.wizard.moveNext()}var t=this;t.canGoBack=i;t.canGoNext=r;t.moveBack=u;t.moveNext=f}]}});angular.module("stp.core.forms").directive("stpWizardForm",function(){return{restrict:"E",templateUrl:"/libs/stp-core-app/forms/directives/wizardform.html",replace:!0,transclude:!0,scope:{heading:"@",originalModel:"=formlyModel",formlyFields:"=",onSaveCallback:"&onSave",onCompleteCallback:"&onComplete",onCancelCallback:"&?onCancel",wizard:"=",introduction:"="},bindToController:!0,controllerAs:"wizardFormCtrl",controller:["$q","fieldsService",function(n,t){function u(){i.originalModel||(i.originalModel={});i.formlyModel=t.cloneObject(i.originalModel)}function f(){i.onCancelCallback?i.onCancelCallback():r(!1)}function e(t){t.$valid&&(i.onSaveCallback||r(!0,i.formlyModel),n.when(i.onSaveCallback({model:i.formlyModel,uploadFiles:t.uploadFiles})).then(function(n){r(!0,n)}))}function r(n,r){if(n?i.originalModel=angular.extend(i.originalModel,t.getPlainObject(r)):i.formlyModel=t.cloneObject(i.originalModel),i.onCompleteCallback)i.onCompleteCallback({model:r});n&&i.wizard.moveNext()}var i=this;i.onSave=e;i.onCancel=f;u()}]}});angular.module("stp.core.forms").directive("stpWizardFormPage",function(){return{restrict:"E",transclude:!0,templateUrl:"/libs/stp-core-app/forms/directives/wizardformpage.html",require:"^stpWizard",scope:{title:"@",onBack:"&?",onNext:"&?"},bindToController:!0,controllerAs:"ctrl",controller:["$q",function(n){function i(){return t.onBack?n.when(t.onBack()):n.when(!0)}function r(){return(t.form.$setSubmitted(),!t.form.$valid)?n.when(!1):t.onNext?n.when(t.onNext()):n.when(!0)}var t=this;t.internalOnNext=r;t.internalOnBack=i}]}});angular.module("stp.core.forms").directive("stpWizardPage",function(){return{restrict:"E",transclude:!0,template:"<ng-transclude><\/ng-transclude>",require:"^stpWizard",scope:{title:"@",onNext:"&?",onBack:"&?"},bindToController:!0,controllerAs:"ctrl",controller:["$element",function(n){var t=this;n.controller("stpWizard").registerCurrentPage({title:t.title,onNext:t.onNext,onBack:t.onBack})}]}});angular.module("stp.core.forms").directive("stpYesNo",function(){return{restrict:"E",template:'<div class="select">\t                    <ui-select class="form-control" ng-model="ctrl.model" theme="bootstrap">                            <ui-select-choices repeat="opt.value as opt in ctrl.ddOptions | filter: $select.search">                                {{opt.name}}                            <\/ui-select-choices>                            <ui-select-match allow-clear="true">                                <span ng-bind="$select.selected.name"><\/span>                            <\/ui-select-match>                        <\/ui-select>                      <div>',scope:{model:"=ngModel"},controllerAs:"ctrl",bindToController:!0,controller:["$scope",function(){var n=this;n.ddOptions=[{value:!1,name:"No"},{value:!0,name:"Yes"}]}]}});angular.module("stp.core.forms").filter("ageFilter",function(){return function(n){return moment().diff(moment(n),"years")+" years old"}});angular.module("stp.core.forms").filter("enabledDisabled",function(){return function(n){return!angular.isDefined(n)||n==null?n:n?"Enabled":"Disabled"}});angular.module("stp.core.forms").filter("fromNow",function(){function n(n,t){return n==1?n+" "+t:n+" "+t+"s"}return function(t){var f=moment(),e=moment(t),r=f.diff(e,"months"),i,u;return r<=12?moment(t).fromNow():(i=r%12,u=(r-i)/12,i==0?n(u," year")+" ago":n(u," year")+" "+n(i," month")+" ago")}});angular.module("stp.core.forms").filter("stpIfNull",function(){return function(n,t){return n===0?n:!n||/^(\s+)|(null\s*)$/.test(n)?t||"-":n}});angular.module("stp.core.forms").filter("OrFilter",[function(){return function(n,t){var i=[],r;return angular.isArray(n)?(r=Object.keys(t),n.forEach(function(n){for(var f,o,e=!1,u=0;u<r.length;u++)if(f=r[u],o=t[f].toLowerCase(),n[f].toString().toLowerCase().indexOf(o)!==-1){e=!0;break}e&&i.push(n)})):i=n,i}}]);angular.module("stp.core.forms").filter("stpPostfix",function(){return function(n,t){return t&&(n||n===0)?n+" "+t:n}});angular.module("stp.core.forms").filter("stpPrefix",function(){return function(n,t){return t&&(n||n===0)?t+" "+n:n}});angular.module("stp.core.forms").filter("surroundWithBrackets",function(){return function(n){if(n)return"("+n+")"}});angular.module("stp.core.forms").filter("yesNo",function(){return function(n){return!angular.isDefined(n)||n==null?n:n?"Yes":"No"}});angular.module("stp.core.forms").service("dialogStateService",["$modal","$state",function(n,t){function u(r,u){u=angular.extend({},i,u);var f=n.open(u);f.result.finally(function(){t.go("^")});r.$on("$stateChangeStart",function(){f.close()})}var r=this,i;r.open=u;i={size:"lg"}}]);angular.module("stp.core.forms").service("fieldsService",[function(){function e(n){return _.each(n,function(n){f(n);n.type==="lookup"&&(n.lookupName=n.lookupName||r(n.key));n.columnTitle||(n.columnTitle=t(n.key));n.key!="notes"||n.cssClass||(n.cssClass="notes")}),n}function t(n){return!n||!angular.isString(n)?"":(n=i(n),n=n.titleize(),n.endsWith(" Id")?n=n.substr(0,n.length-3):n.endsWith(" Type Ids")?n=n.substr(0,n.length-9)+"s":n.endsWith(" Ids")&&(n=n.substr(0,n.length-4)+"s"),n)}function i(n){if(!n)return"";var t=n.lastIndexOf(".");return t>=0&&t<n.length-1&&(n=n.substr(t+1)),n}function r(n){if(!n)return null;var t=n.split("."),i;return i=t.length>0?t[t.length-1]:t,i.replace(/Id$/gi,"")}function o(n){return n?angular.isDefined(n.plain)&&angular.isFunction(n.plain)?n.plain():n:n}function s(n){return n?angular.isDefined(n.clone)&&angular.isFunction(n.clone)?n.clone():angular.copy(n):n}function h(n,t){for(var n=angular.copy(n),e=[],r=t||[4],i=0,f,o;n.length>0;)f=r[i],o=u(n.splice(0,f),f),e.push(o),i++,i>=r.length&&(i=r.length-1);return e}function u(n,t){_.forEach(n,f);var t=t||n.length,i={className:"row",fieldGroup:n},r=12/t;return _.forEach(i.fieldGroup,function(n){n.className||(n.className="col-md-"+r)}),i}function f(n){return angular.isUndefined(n.type)&&angular.isUndefined(n.template)&&angular.isUndefined(n.templateUrl)&&(n.type=/^date($|[A-Z])|(Date($|[A-Z]))/g.test(n.key)?"date":/Id$/g.test(n.key)?"lookup":/[Pp]assword/g.test(n.key)?"password":"text"),n}var n=this;n.getDefaultLabel=t;n.getDefaultLookupName=r;n.getPlainObject=o;n.getPlainName=i;n.cloneObject=s;n.createRows=h;n.createRow=u;n.annotateTableFields=e}]);angular.module("stp.core.forms").service("focusService",["$rootScope","$timeout",function(n,t){function r(i,r){t(function(){n.$broadcast("focusService:setFocus",i)},r||0)}var i=this;i.setFocus=r}]);angular.module("stp.core.forms").service("messageBoxService",["$window",function(n){this.confirm=function(t){return n.confirm(t)};this.alert=function(t){return n.alert(t)}}]);angular.module("stp.core.forms").factory("usernameFormatter",["$interpolate",function(n){return n("{{firstName}} {{surname | uppercase}} ")}]);angular.module("stp.core.forms").service("wizardService",["$state",function(n){function t(t,i){return function(){function s(){var t=_.findIndex(f,function(t){return t.state==n.current.name}),i=t!==-1?t:0;o(i)}function h(n){e=n}function c(){o(r-1)}function l(){r+1===f.length?e&&e():o(r+1)}function o(t){n.go(f[t].state,n.params).then(function(){r=t;u.started=!0;u.canGoBack=r>0;u.canGoNext=!0;u.nextText=r+1===f.length?"Finish":"Next";u.currentPage=r+1;u.currentPageTitle=f[r].title})}var f=i,r=0,e,u={canGoBack:!1,canGoNext:!0,started:!1,backText:"Back",nextText:"Next",currentPageTitle:"",currentPage:1,totalPages:f.length,title:t,start:s,after:h,moveBack:c,moveNext:l};return u}()}this.newWizard=t}]);angular.module("stp.core.forms").provider("entityConfiguration",[function(){function i(t,i){n[t]||(n[t]={});n[t]=angular.extend({},n[t],i)}var t=this,n={};t.configEntity=i;t.$get=["$injector","$interpolate","fieldsService",function(i,r,u){function e(t,i){var u=o(t),e=n[t]||{},r=angular.extend({},u,e);return r.dataService=f(r,"dataService",i),r.dataSource=f(r,"dataSource",i),r.fieldService=f(r,"fieldService",i),r.fields=f(r,"fields",i),r.tableFields=f(r,"tableFields",i),r.add=f(r,"add",i),r}function o(n){return{editTemplateUrl:"/libs/stp-core-app/forms/services/entityservice/popupdialog.html",entityName:u.getDefaultLabel(n),dataService:s(n),fieldService:h(n),fields:c(),tableFields:l(),viewTemplateUrl:"/app/patientdetails/"+n+"s/view"+n+".html",modalSize:"lg"}}function s(n){var t=n+"Service";return function(){if(!i.has(t))throw r("Default data service '{{dataServiceName}}' not found. Specify entity configuration manually.")({dataServiceName:t});return i.get(t)}}function h(n){var t=n+"FieldsService";return function(){if(!i.has(t))throw r("Default field service '{{fieldServiceName}}' not found. Specify entity configuration manually.")({fieldServiceName:t});return i.get(t)}}function c(){return["fieldService",function(n){if(!n.hasOwnProperty("getFields")||!angular.isFunction(n.getFields))throw"Default field service  does not have function 'getFields()'. Specify entity configuration manually.";return n.getFields()}]}function l(){return["fieldService",function(n){if(!n.hasOwnProperty("getTableFields")||!angular.isFunction(n.getTableFields))throw"Default field service  does not have function 'getTableFields()'. Specify entity configuration manually.";return n.getTableFields()}]}function f(n,u,f){if(!n.hasOwnProperty(u)||!n[u])return undefined;var e=angular.extend({},f,n),o=n[u],s=i.annotate(o);return _.forEach(s,function(n){if(!i.has(n)&&!e.hasOwnProperty(n))throw r("Configuration '{{name}}' expects dependency '{{dependency}}' which cannot be found. Register as angular service or specify in 'params' argument.")({name:u,dependency:n});}),i.invoke(o,t,e)}return{getEntityConfig:e}}]}]),function(){function n(n,t,i,r,u,f,e){function c(){s=r.getEntityConfig(f,e);h=u(s);o.dataSource=s.dataSource;o.fields=s.fields;o.fieldService=s.fieldService;o.dataService=s.dataService;o.tableFields=s.tableFields}function l(t){if(!t)throw"Expected entityId parameter";return n.open({templateUrl:"/libs/stp-core-app/forms/services/entityservice/viewdialog.html",resolve:{config:s,entityId:t},controller:"ViewDialogController",controllerAs:"ctrl",size:s.modalSize}).result.then(function(){s.dataSource.refresh()})}function a(){h.addEntity()}function v(n){if(!angular.isObject(n)||!n.hasOwnProperty("id"))throw"Expected entity object with id field";h.removeEntity(n)}function y(){return o.dataSource.loading}var o=this,s,h;o.isBusy=y;o.view=l;o.add=a;o.remove=v;o.dataSource=null;o.fields=null;o.tableFields=null;o.fieldService=null;o.dataService=null;c()}angular.module("stp.core.forms").factory("entityServiceFactory",["$modal","$injector","fieldsService","entityConfiguration","dataSourceListServiceFactory",function(t,i,r,u,f){return function(e,o){return new n(t,i,r,u,f,e,o)}}])}();angular.module("stp.core.forms").controller("ViewDialogController",["$modalInstance","$q","config","entityId",function(n,t,i,r){function e(){u.showSpinner=!0;i.dataService.getById(r).then(function(n){u.model=n;u.showSpinner=!1})}function o(){u.editMode=!0}function s(){u.editMode=!1}function h(n,r){return angular.isDefined(i.save)&&angular.isFunction(i.save)?t.when(i.save(n)).then(f):i.dataService.save(n,r).then(f).finally(function(){u.showSpinner=!1})}function f(n){return c(i.afterEdit,n),n}function c(n){var t=_.slice(arguments,1);angular.isDefined(n)&&angular.isFunction(n)&&n.apply(undefined,t)}var u=this;u.config=i;u.fields=i.fields;u.entityName=i.entityName;u.viewTemplateUrl=i.viewTemplateUrl;u.model=null;u.showSpinner=!0;u.editMode=!1;u.edit=o;u.onSave=h;u.onCancel=s;e()}]);angular.module("stp.core.forms").factory("arrayListServiceFactory",["listServiceFactory",function(n){return function(t){return n(t,{afterRemove:function(n){t.dataSource&&_.remove(t.dataSource,n)},afterAdd:function(n){t.dataSource&&t.dataSource.push(n)}})}}]);angular.module("stp.core.forms").factory("dataSourceListServiceFactory",["listServiceFactory",function(n){return function(t){return n(t,{afterEdit:function(){t.dataSource&&t.dataSource.refresh()},afterRemove:function(){t.dataSource&&t.dataSource.refresh()},afterAdd:function(){t.dataSource&&t.dataSource.refresh()}})}}]),function(){function n(n,t,i,r,u){function c(n){n=h(n);t.open({templateUrl:function(){return r.editTemplateUrl?r.editTemplateUrl:"/libs/stp-core-app/forms/services/listservice/listservice.edit.html"},controller:["$q","entity","config",function(n,t,i){function o(t,r){return angular.isDefined(i.save)&&angular.isFunction(i.save)?n.when(i.save(t)).then(f):i.dataService.save(t,r).then(f)}function f(n){return e(u.afterEdit,n),e(i.afterEdit,n),n}var r=this;r.config=i;r.entity=t;r.onSave=o}],controllerAs:"ctrl",resolve:{entity:n,config:r},size:r.modalSize})}function l(){var n=t.open({templateUrl:function(){return r.addTemplateUrl?r.addTemplateUrl:"/libs/stp-core-app/forms/services/listservice/listservice.add.html"},controller:["$q","config",function(t,i){function o(n,r){return angular.isDefined(i.add)&&angular.isFunction(i.add)?t.when(i.add(n,r)).then(f):i.dataService.add(n,r).then(f)}function s(t){n.close(t)}function f(n){return e(u.afterAdd,n),e(i.afterAdd,n),n}var r=this;r.config=i;r.onSave=o;r.onComplete=s}],controllerAs:"ctrl",size:r.modalSize,resolve:{config:r}})}function a(n){n=h(n);i.confirm(s(n))&&(f.busy=!0,r.dataService.remove(n).then(function(){e(u.afterRemove,n);e(r.afterRemove,n)}).finally(function(){f.busy=!1}))}function e(n){var t=_.slice(arguments,1);angular.isDefined(n)&&angular.isFunction(n)&&n.apply(undefined,t)}function h(n){if(!r.mapEntity)return n;var t=r.mapEntity(n);return t?t:n}var f=this,o,s;f.editEntity=c;f.addEntity=l;f.removeEntity=a;f.behaviour=u||{};f.busy=!1;o={modalSize:"lg",removeMessage:"Are you sure you wish to delete this record?"};r=angular.extend({},o,r);s=n(r.removeMessage)}angular.module("stp.core.forms").factory("listServiceFactory",["$interpolate","$modal","messageBoxService",function(t,i,r){return function(u,f){return new n(t,i,r,u,f)}}])}()