From 7eadb02ebdc3199a21770071998279d856ec51f8 Mon Sep 17 00:00:00 2001 From: Mark Polak Date: Mon, 7 Nov 2016 15:04:36 +0100 Subject: [PATCH] Add data entry events to approvals app --- package.json | 1 + src/main/datasets/datasetview-directive.js | 36 ++++++++++++++++++++++ src/main/manifest.webapp | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 445f8ac..3b5d4d0 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "sinon": "^1.14.1" }, "scripts": { + "build": "gulp build-prod", "test": "gulp test", "validate": "gulp git:pre-commit" }, diff --git a/src/main/datasets/datasetview-directive.js b/src/main/datasets/datasetview-directive.js index 00d8814..49b367e 100644 --- a/src/main/datasets/datasetview-directive.js +++ b/src/main/datasets/datasetview-directive.js @@ -2,6 +2,40 @@ function datasetViewDirective(AppManifest, $translate, dataSetGroupService, $log) { var dataSetReportWrapSelector = '.dataset-report-wrap'; + /** + * Creates the events as they exist in data entry so they can be subscribed to. + * This is needed so that subscriptions to these events in custom forms do not cause the + * form to behave differently between reports and approvals. + */ + (function createDataEntryEvents() { + window.dhis2 = window.dhis2 || {}; + dhis2.de = dhis2.de || {}; + + dhis2.de.event = { + // Fired + formLoaded : "dhis2.de.event.formLoaded", + dataValuesLoaded : "dhis2.de.event.dataValuesLoaded", + formReady : "dhis2.de.event.formReady", + // Never fired in approvals (but can be subscribed to in custom form) + dataValueSaved : "dhis2.de.event.dataValueSaved", + completed : "dhis2.de.event.completed", + uncompleted : "dhis2.de.event.uncompleted", + validationSucces : "dhis2.de.event.validationSuccess", + validationError : "dhis2.de.event.validationError" + }; + }()); + + /** + * Fire a subset of the data entry events, just like in Data Set Report. + */ + function fireDataEntryEvents() { + var $document = $(document); + + $document.trigger(dhis2.de.event.formLoaded); + $document.trigger(dhis2.de.event.dataValuesLoaded); + $document.trigger(dhis2.de.event.formReady); + } + function loadDataSetReport(details, ds, element, scope) { var dataSetReportUrl = AppManifest.activities.dhis.href + '/dhis-web-reporting/generateDataSetReport.action'; var params = { @@ -254,6 +288,8 @@ function datasetViewDirective(AppManifest, $translate, dataSetGroupService, $log } else { element.find(dataSetReportWrapSelector).append(scope.reportView[$item.id].content); } + + fireDataEntryEvents(); } } catch (e) { if (window.console && window.console.error) { diff --git a/src/main/manifest.webapp b/src/main/manifest.webapp index b823a41..30cf669 100644 --- a/src/main/manifest.webapp +++ b/src/main/manifest.webapp @@ -1 +1 @@ -{"version":"0.4.10","name":"Data Approval","description":"Approvals app for PEPFAR","icons":{"48":"img/icons/dataapproval.png"},"developer":{"url":"http://www.dhis2.org","name":"Mark Polak","company":"DHIS2 Core Team","email":"markpo@ifi.uio.no"},"launch_path":"index.html?v=0.4.10","default_locale":"en","activities":{"dhis":{"href":"*"}}} \ No newline at end of file +{"version":"0.5.0","name":"Data Approval","description":"Approvals app for PEPFAR","icons":{"48":"img/icons/dataapproval.png"},"developer":{"url":"http://www.dhis2.org","name":"Mark Polak","company":"DHIS2 Core Team","email":"markpo@ifi.uio.no"},"launch_path":"index.html?v=0.5.0","default_locale":"en","activities":{"dhis":{"href":"*"}}} \ No newline at end of file