!function WP$ChartSync$ChartSyncController$definition(){var n=$$WP.Common.Model,t=$$WP.Common.ModelCollection,e=$$WP.ChartSync.Synchronization,o=1,r=function WP$ChartSync$ChartSyncController$s_onConfiguredPollingIntervalLoaded(n){var t=this.callback;$$WP.ChartSync.ChartSyncController.ConfiguredPollingInterval=n,t&&"function"==typeof t&&t(n)},i=function WP$ChartSync$ChartSyncController(n,t){this.WP$Controllers$Controller();var o=$$WP.ChartSync.ChartSyncController;this.proxify("_onConfiguredPollingIntervalLoaded","_generateNewEstimatedTimeLeftString","_onTimerElapsedToDecrementEstimatedTimeLeft","_onSynchronizationAdded","_updateSynchronizationProgress","_onSynchronizationDisplayChanged","_onCancelButtonClicked","_onSynchronizationErrorChanged","_onSynchronizationStatusChanged"),this._lightboxTemplate=t&&"function"==typeof t?t:$$WP.Templates.ChartSync.ChartSyncLightboxContent,this._hasUiComponent=!1!==n,this._synchronizations=e.createSynchronizationCollection(),this._intervalTimerIdsToDecrementEstimatedTimeLeft={},this._synchronizationListeners={},this._hasUiComponent&&(this._viewBinder=new o.CountdownTimerViewBinder("EstimatedTimeLeft",this._generateNewEstimatedTimeLeftString)),o.ConfiguredPollingInterval?this._pollingInterval=o.ConfiguredPollingInterval:o.LoadConfiguredPollingInterval(this._onConfiguredPollingIntervalLoaded),this._addPropertyListeners()},a={_pollingInterval:null,_lightboxTemplate:null,_hasUiComponent:!1,_viewBinder:null,_synchronizations:null,_intervalTimerIdsToDecrementEstimatedTimeLeft:null,_synchronizationListeners:null,_addPropertyListeners:function WP$ChartSync$ChartSyncController$_addPropertyListeners(){this._synchronizations.addCollectionEventListener(t.AddEvent,this._onSynchronizationAdded),this._synchronizations.addPropertyListener("IsDisplayed",this._onSynchronizationDisplayChanged),this._synchronizations.addPropertyListener("Error",this._onSynchronizationErrorChanged),this._synchronizations.addPropertyListener("Status",this._onSynchronizationStatusChanged)},syncPatient:function WP$ChartSync$ChartSyncController$syncPatient(n,t,r,i,a,s,h,c){var l,y;return l=new e(n,t,r,i,a,s),this._setUpTimerToDecrementEstimatedTimeLeft(l.ModelId),y=o++,this._addListenerForSynchronization(l,y,c,h),this._synchronizations.add(l),y},_setUpTimerToDecrementEstimatedTimeLeft:function WP$ChartSync$ChartSyncController$_setUpTimerToDecrementEstimatedTimeLeft(n){var t=window.setInterval(this._onTimerElapsedToDecrementEstimatedTimeLeft,1e3,n);this._addTimerToDecrementEstimatedTimeLeft(n,t)},_onTimerElapsedToDecrementEstimatedTimeLeft:function WP$ChartSync$ChartSyncController$_onTimerElapsedToDecrementEstimatedTimeLeft(t){var e=n.getInstance(t);!e||this._isSynchronizationComplete(e)?this._clearTimerToDecrementEstimatedTimeLeft(t):this._decrementEstimatedTimeLeft(e)},_decrementEstimatedTimeLeft:function WP$ChartSync$ChartSyncController$_decrementEstimatedTimeLeft(n){var t;n.EstimatedTimeLeft>0&&(t=n.EstimatedTimeLeft-1,n.setProperty("EstimatedTimeLeft",t))},_onSynchronizationAdded:function WP$ChartSync$ChartSyncController$_onSynchronizationAdded(){this._pollingInterval&&this._startSynchronizationsThatNeedToBeRequested()},_startSynchronizationsThatNeedToBeRequested:function WP$ChartSync$ChartSyncController$_startSynchronizationsThatNeedToBeRequested(){var n,t;for(n=this._getSynchronizationsToRequest(),t=0;t<n.length;t++)this._startSynchronization(n[t])},_getSynchronizationsToRequest:function WP$ChartSync$ChartSyncController$_getSynchronizationsToRequest(){var t,o,r;for(o in t=[],this._synchronizations.getFromIndex("Status",e.SyncStatusEnum.NotRequested))(r=n.getInstance(o))&&$$WPUtil.IsNullOrEmpty(r.Error)&&t.push(r);return t},_startSynchronization:function WP$ChartSync$ChartSyncController$_startSynchronization(n){this._hasUiComponent&&!this._isCurrentlyDisplayingSynchronization()&&this._showSynchronization(n),this._updateSynchronizationProgress(n.ModelId)},_showSynchronization:function WP$ChartSync$ChartSyncController$_showSynchronization(n){n&&!n.IsDisplayed&&this._hasUiComponent&&n.setProperty("IsDisplayed",!0)},_hideSynchronization:function WP$ChartSync$ChartSyncController$_hideSynchronization(n){n&&n.IsDisplayed&&this._hasUiComponent&&n.setProperty("IsDisplayed",!1)},_onSynchronizationDisplayChanged:function WP$ChartSync$ChartSyncController$_onSynchronizationDisplayChanged(n){var t,e;for(t in n)e=n[t].model,!0===n[t].to?this._showSynchronizationInLightbox(e):this._removeSynchronizationLightbox(e)},_showSynchronizationInLightbox:function WP$ChartSync$ChartSyncController$_showSynchronizationInLightbox(n){var t,e,o;resetLightbox(),e=this._getViewModel(n),t=$afe.renderTemplate(this._lightboxTemplate,e),showLightBox(t[0].outerHTML),this._viewBinder.bindModel(n),$afe.select("#lightbox_overlay").prop("onclick",null),o='[data-view-binder-id="'+this._viewBinder.ViewBinderId+'"]',o+='[data-model-id="'+n.ModelId+'"]',$afe.select(o).on("click",".button.cancelworkflow",n.ModelId,this._onCancelButtonClicked)},_getViewModel:function WP$ChartSync$ChartSyncController$_getViewModel(n){return{ViewBinderId:this._viewBinder.ViewBinderId,Synchronization:n}},_onCancelButtonClicked:function WP$ChartSync$ChartSyncController$_onCancelButtonClicked(t){var o,r;o=t.data,(r=n.getInstance(o))&&!this._isSynchronizationComplete(r)&&r.setProperty("Status",e.SyncStatusEnum.Canceled)},_removeSynchronizationLightbox:function WP$ChartSync$ChartSyncController$_hideSynchronizationInLightbox(n){hideLightbox(),resetLightbox()},_updateSynchronizationProgress:function WP$ChartSync$ChartSyncController$_updateSynchronizationProgress(t){var e=n.getInstance(t);this._shouldRequestNewSynchronizationProgress(e)&&this._sendRequestForNewSynchronizationProgress(e)},_shouldRequestNewSynchronizationProgress:function WP$ChartSync$ChartSyncController$_shouldRequestNewSynchronizationProgress(n){return n&&!this._isSynchronizationComplete(n)},_sendRequestForNewSynchronizationProgress:function WP$ChartSync$ChartSyncController$_sendRequestForNewSynchronizationProgress(n){var t,e,o;t=this._getPatientChartUpToDateRequestObject(n),e=JSON.stringify(t),o={ChartSyncController:this,SynchronizationId:n.ModelId},this._shouldHideDefaultAjaxSpinner()&&this._hideDefaultAjaxSpinner(),$.ajax({url:makeLink("ChartSync/GetPatientChartUpToDate"),type:"POST",contentType:"application/json",success:$.proxy(this._onNewSynchronizationProgress,o),data:e})},_getPatientChartUpToDateRequestObject:function WP$ChartSync$ChartSyncController$_getPatientChartUpToDateRequestObject(n){return{PatientCid:n.PatientCid,UserCid:n.UserCid,ApplicationId:n.ApplicationId,homeDeploymentInternalId:n.HomeDeploymentInternalId,Priority:n.Priority,SyncType:n.SyncType}},_onNewSynchronizationProgress:function WP$ChartSync$ChartSyncController$_onNewSynchronizationProgress(t){var e,o,r,i;e=this.ChartSyncController,o=this.SynchronizationId,r=n.getInstance(o),e._shouldHideDefaultAjaxSpinner()&&e._unhideDefaultAjaxSpinner(),r&&!e._isSynchronizationComplete(r)&&(e._synchronizations.openChangeBatch(),r.setProperty("Status",t.Status),r.setProperty("Error",t.Error),e._updateEstimatedTimeLeft(r,t.EstimatedTimeLeft),e._synchronizations.closeChangeBatch(),i=1e3*e._pollingInterval,window.setTimeout(e._updateSynchronizationProgress,i,o))},_updateEstimatedTimeLeft:function WP$ChartSync$chartSyncController(n,t){var e,o;e=n.EstimatedTimeLeft,o=Math.abs(e-t),(null===e||o>10)&&n.setProperty("EstimatedTimeLeft",t)},_onSynchronizationErrorChanged:function WP$ChartSync$ChartSyncController$_onSynchronizationErrorChanged(n){this._onSynchronizationStatusChanged(n)},_onSynchronizationStatusChanged:function WP$ChartSync$ChartSyncController$_onSynchronizationStatusChanged(n){var t,e;for(t in n)e=n[t].model||$$WP.Common.Model.getInstance(t),this._isSynchronizationComplete(e)&&this._onSynchronizationComplete(e)},_onSynchronizationComplete:function WP$ChartSync$ChartSyncController$_onSynchronizationComplete(n){var t,e,o,r,i;t=this._getListenerIdForSynchronization(n),e=this._getContextDataForSynchronization(n),o=this._getCallbackForSynchronization(n),r=n.Status,i=n.Error,this._removeSynchronization(n),o&&"function"==typeof o&&o(t,r,i,e)},_removeSynchronization:function WP$ChartSync$ChartSyncController$_removeSynchronization(n){this._hideSynchronization(n),this._removeListenerForSynchronization(n),this._synchronizations.remove(n),n.dispose()},_generateNewEstimatedTimeLeftString:function WP$ChartSync$ChartSyncController$_generateNewEstimatedTimeLeftString(n){var t;return n<=60?t=$$WP.Strings.get("EstimatedTimeLeftUnderAMinute","ChartSync.ChartSyncLightBox"):($$WP.Strings.addMnemonic("@MYCHART@COUNTDOWN@",n),t=$$WP.Strings.get("EstimatedTimeLeftInSeconds","ChartSync.ChartSyncLightBox"),$$WP.Strings.removeMnemonic("@MYCHART@COUNTDOWN@")),t},_onConfiguredPollingIntervalLoaded:function WP$ChartSync$ChartSyncController$_onConfiguredPollingIntervalLoaded(n){this._pollingInterval=n,this._startSynchronizationsThatNeedToBeRequested()},_isCurrentlyDisplayingSynchronization:function WP$ChartSync$ChartSyncController$_isCurrentlyDisplayingSynchronization(){return null!==this._synchronizations.getFromIndex("IsDisplayed",!0)},_isSynchronizationComplete:function WP$ChartSync$ChartSyncController$_isSynchronizationComplete(n){return n.Status===e.SyncStatusEnum.UpToDate||n.Status===e.SyncStatusEnum.Canceled||n.Status===e.SyncStatusEnum.UnknownError||!$$WPUtil.IsNullOrEmpty(n.Error)},_addListenerForSynchronization:function WP$ChartSync$ChartSyncController$_addListenerForSynchronization(n,t,e,o){var r={listenerId:t,contextData:e,callback:o};this._synchronizationListeners[n.ModelId]=r},_getListenerIdForSynchronization:function WP$ChartSync$ChartSyncController$_getListenerIdForSynchronization(n){return this._synchronizationListeners[n.ModelId].listenerId},_getContextDataForSynchronization:function WP$ChartSync$ChartSyncController$_getContextDataForSynchronization(n){return this._synchronizationListeners[n.ModelId].contextData},_getCallbackForSynchronization:function WP$ChartSync$ChartSyncController$_getCallbackForSynchronization(n){return this._synchronizationListeners[n.ModelId].callback},_removeListenerForSynchronization:function WP$ChartSync$ChartSyncController$_removeListenerForSynchronization(n){delete this._synchronizationListeners[n.ModelId]},_addTimerToDecrementEstimatedTimeLeft:function WP$ChartSync$ChartSyncController$_addTimerToDecrementEstimatedTimeLeft(n,t){this._intervalTimerIdsToDecrementEstimatedTimeLeft[n]=t},_clearTimerToDecrementEstimatedTimeLeft:function WP$ChartSync$ChartSyncController$_clearTimerToDecrementEstimatedTimeLeft(n){var t=this._intervalTimerIdsToDecrementEstimatedTimeLeft[n];window.clearInterval(t),delete this._intervalTimerIdsToDecrementEstimatedTimeLeft[n]},_shouldHideDefaultAjaxSpinner:function WP$ChartSync$ChartSyncController$_shouldHideDefaultAjaxSpinner(){return this._isPrelogin()&&this._hasUiComponent},_isPrelogin:function WP$ChartSync$ChartSyncController$_isPrelogin(){return $afe.select("body").hasClass("isPrelogin")},_hideDefaultAjaxSpinner:function WP$ChartSync$ChartSyncController$_hideDefaultAjaxSpinner(){$afe.select(".ajaxspinner").addClass("jqHidden")},_unhideDefaultAjaxSpinner:function WP$ChartSync$ChartSyncController$_unhideDefaultAjaxSpinner(){$afe.select(".ajaxspinner").removeClass("jqHidden")}},s=function WP$ChartSync$CountdownTimerViewBinder(n,t){this.WP$Common$ViewBinder(null,[n]),t&&"function"==typeof t||$$WP.Debug.logError("StringGenerationFunction needs to be a function"),this._stringGenerationFunction=t};s.prototype={_stringGenerationFunction:null,_onPropertyChanged:function(n,t){var e,o,r;e=this.getBoundElements(n),o=t.to,r=this._stringGenerationFunction(o),e.find(".countdown").text(r)}},i.prototype=a,i.extend($$WP.Controllers.Controller,"WP$ChartSync$ChartSyncController"),s.extend($$WP.Common.ViewBinder,"WP$ChartSync$CountdownTimerViewBinder"),$$WP.ChartSync=$$WP.ChartSync||{},$$WP.ChartSync.ChartSyncController=i,$$WP.ChartSync.ChartSyncController.ConfiguredPollingInterval=null,$$WP.ChartSync.ChartSyncController.LoadConfiguredPollingInterval=function WP$ChartSync$ChartSyncController$LoadConfiguredPollingInterval(n){var t={callback:n};$$WP.ChartSync.ChartSyncController.ConfiguredPollingInterval&&n&&"function"==typeof n?n($$WP.ChartSync.ChartSyncController.ConfiguredPollingInterval):$.ajax({url:makeLink("ChartSync/GetConfiguredPollingInterval"),type:"POST",contentType:"application/json",success:$.proxy(r,t)})},$$WP.ChartSync.ChartSyncController.CountdownTimerViewBinder=s}();