Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement initial integration with enketo-core to display complex emb… #563

Closed
wants to merge 9 commits into from
10 changes: 9 additions & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com http://nominatim.openstreetmap.org https://e-mission.eecs.berkeley.edu https://api.ionic.io/push/tokens emission: 'unsafe-eval'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: http://*.tile.openstreetmap.org http://tile.stamen.com https://*.tile.stamen.com http://*.tile.stamen.com 'unsafe-inline'">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com http://nominatim.openstreetmap.org https://e-mission.eecs.berkeley.edu https://api.ionic.io/push/tokens emission: 'unsafe-eval'; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: http://*.tile.openstreetmap.org https://*.tile.openstreetmap.org http://tile.stamen.com https://*.tile.stamen.com http://*.tile.stamen.com 'unsafe-inline'">
<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
Expand All @@ -21,6 +21,12 @@
<link href="common/img/sprites/spritesmith/quests/bosses/quest.bosses.css" rel="stylesheet">
<link rel="stylesheet" href="lib/ng-walkthrough/css/ng-walkthrough.css">
<link href="lib/angularjs-slider/dist/rzslider.css" rel="stylesheet">
<link href="manual_lib/enketo/css/formhub.css" media="all" rel="stylesheet">
<!--<link type="text/css" href="manual_lib/enketo/css/plain.css" media="all" rel="stylesheet" />-->
<!--<link type="text/css" href="manual_lib/enketo/css/grid.css" media="all" rel="stylesheet" />-->
<link href="manual_lib/enketo/css/formhub-print.css" media="print" rel="stylesheet">
<!--<link type="text/css" href="manual_lib/enketo/css/plain-print.css" media="print" rel="stylesheet" />-->
<!--<link type="text/css" href="manual_lib/enketo/css/grid-print.css" media="print" rel="stylesheet" />-->

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
Expand Down Expand Up @@ -53,6 +59,7 @@
<script src="lib/angularLocalStorage/dist/angularLocalStorage.min.js"></script>
<script src="manual_lib/leaflet-plugins/leaflet.textpath.js"></script>
<script src="lib/angularjs-slider/dist/rzslider.min.js"></script>
<script src="manual_lib/enketo/enketo-bundle.js"></script>
<!-- Manually installed javascript for libraries that are not published through bower -->
<!-- cordova script (this will be a 404 in the browser) -->
<script type="text/javascript" src="cordova.js"></script>
Expand Down Expand Up @@ -88,6 +95,7 @@
<script src="js/common/place-detail.js"></script>
<script src="js/common/services.js"></script>
<script src="js/survey/launch.js"></script>
<script src="js/survey/enketo_launch.js"></script>
<script src="js/heatmap.js"></script>
<script src="js/metrics.js"></script>
<script src="js/goals.js"></script>
Expand Down
12 changes: 12 additions & 0 deletions www/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ angular.module('emission.main', ['emission.main.recent',
'emission.main.common',
'emission.main.heatmap',
'emission.main.metrics',
'emission.survey.enketo.launch',
'emission.tripconfirm.posttrip.map',
'emission.services'])

Expand Down Expand Up @@ -61,6 +62,17 @@ angular.module('emission.main', ['emission.main.recent',
}
})

.state('root.main.enketosurvey', {
// if we have this the param here, we don't need the params in the definition
url: '/enketosurvey/:form_location',
views: {
'main-metrics': {
templateUrl: 'templates/survey/enketo-survey.html',
controller: 'EnketoSurveyCtrl'
}
},
})

.state('root.main.goals', {
url: '/goals',
views: {
Expand Down
70 changes: 70 additions & 0 deletions www/js/survey/enketo_launch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict';

// import { Form } from 'enketo-core';

angular.module('emission.survey.enketo.launch', ['emission.services',
'emission.plugin.logger'])

.controller('EnketoSurveyCtrl', function($window, $scope, $rootScope, $state,
$stateParams, $http, $ionicPopup, Logger, $cordovaInAppBrowser) {

console.log("EnketoSurveyCtrl called with params = "+JSON.stringify($stateParams));

$scope.loadForm = function(form_location) {
// var invokeUrl = "templates/survey/enketo-survey-iab.html?xform="+form_location;
// var invokeUrl = "https://odk.enke.to/preview?form=https://xlsform.opendatakit.org/downloads/ngzcr5fw/rkunsw-survey1.xml";
// $cordovaInAppBrowser.open(invokeUrl, '_blank')
$http.get(form_location)
.then(function(form_json) {
console.log(form_json);
$scope.loaded_form = form_json.data.form;
$scope.loaded_model = form_json.data.model;
$( '.form-header' ).after( $scope.loaded_form );
var formSelector = 'form.or:eq(0)';
var data = {
// required string of the default instance defined in the XForm
modelStr: $scope.loaded_model,
// optional string of an existing instance to be edited
instanceStr: null,
// optional boolean whether this instance has ever been submitted before
submitted: false,
// optional array of external data objects containing:
// {id: 'someInstanceId', xml: XMLDocument}
external: [],
// optional object of session properties
// 'deviceid', 'username', 'email', 'phonenumber', 'simserial', 'subscriberid'
session: {}
};
$scope.form = new $window.FormModule( formSelector, data, {});
var loadErrors = $scope.form.init();
if (loadErrors.length > 0) {
$ionicPopup.alert({template: "loadErrors: " + loadErrors.join(",")});
}
});
};

/*
* Initialize all the scope variables based on the paramters
*/
if (!angular.isDefined($stateParams.form_location)) {
$ionicPopup.alert("No form location defined, going back to metrics")
.then(function() {
$state.go("root.main.metrics")
});
} else {
$scope.loadForm($stateParams.form_location);
}

$scope.validateForm = function() {
$scope.form.validate()
.then(function (valid){
if ( !valid ) {
$ionicPopup.alert({template: 'Form contains errors. Please see fields marked in red.'});
} else {
// Record is valid!
$ionicPopup.alert({template: 'Form is valid! (see XML record in the console)'});
console.log($scope.form.getDataStr());
}
});
}
});
1 change: 1 addition & 0 deletions www/json/enketo-survey-sample-full.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions www/json/enketo-survey-sample.json

Large diffs are not rendered by default.

Loading