dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19555
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8574: mobile: now works as a online data entry client
------------------------------------------------------------
revno: 8574
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-10-18 10:27:37 +0200
message:
mobile: now works as a online data entry client
modified:
dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm
dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm
dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm
dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/settings.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm 2012-10-15 12:37:39 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/base.vm 2012-10-18 08:27:37 +0000
@@ -1,5 +1,6 @@
<!DOCTYPE html>
-<html manifest="../dhis-web-mobile-resources/manifest.appcache">
+<!-- <html manifest="../dhis-web-mobile-resources/manifest.appcache"> -->
+<html>
<head>
<title>DHIS2</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm 2012-10-15 12:37:39 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm 2012-10-18 08:27:37 +0000
@@ -133,17 +133,78 @@
$.mobile.showPageLoadingMsg();
- var form = fm.form(Selected.dataSet);
-
- var tmpl = jQuery('#data-entry-template').html();
-
- jQuery('#data-entry-page section[data-role="content"]').html(
- _.template( tmpl, form )
- );
-
- jQuery('#data-entry-page').trigger('pagecreate')
- jQuery('#data-entry-list').listview('refresh');
- $.mobile.hidePageLoadingMsg();
+ function renderFormTemplate(form) {
+
+ var tmpl = jQuery('#data-entry-template').html();
+
+ jQuery('#data-entry-page section[data-role="content"]').html(
+ _.template( tmpl, form )
+ );
+
+ jQuery('#data-entry-page').trigger('pagecreate')
+ jQuery('#data-entry-list').listview('refresh');
+ jQuery('#send_button').bind('click', saveValues);
+ }
+
+ $.ajax({
+ url: '../api/dataSets/' + Selected.dataSet + '/form',
+ data: {
+ ou: Selected.orgUnit,
+ pe: Selected.period
+ },
+ dataType: 'json'
+ }).success(function(form) {
+ console.log("rendering fresh form");
+ console.log(form);
+ renderFormTemplate(form);
+ $.mobile.hidePageLoadingMsg();
+ }).error(function() {
+ var form = fm.form(Selected.dataSet);
+ renderFormTemplate(form);
+ $.mobile.hidePageLoadingMsg();
+ });
+ }
+
+ function saveValues() {
+ $.mobile.showPageLoadingMsg();
+
+ var fields = $('#data-entry-form :input[name]');
+
+ var dataValueSet = {
+ dataSet: Selected.dataSet,
+ orgUnit: Selected.orgUnit,
+ period: Selected.period.toString()
+ };
+
+ var dataValues = [];
+
+ _.each(fields, function(field) {
+ var field = $(field);
+
+ var dataValue = {
+ dataElement: field.data('dataelement'),
+ categoryOptionCombo: field.data('categoryoptioncombo'),
+ value: field.val()
+ };
+
+ dataValues.push(dataValue);
+ });
+
+ dataValueSet.dataValues = dataValues;
+
+ console.log(dataValueSet);
+
+ $.ajax({
+ url: '../api/dataValueSets',
+ type: 'POST',
+ contentType: 'application/json',
+ data: JSON.stringify(dataValueSet)
+ }).success(function() {
+ $.mobile.hidePageLoadingMsg();
+ }).error(function() {
+ console.log("error when saving datavalues")
+ $.mobile.hidePageLoadingMsg();
+ });
}
jQuery(document).bind('pagechange', function (event, data) {
@@ -185,7 +246,7 @@
</div>
<ul id="period-list" data-role="listview" data-inset="true">
<% _( periods ).each( function(period, idx) { %>
- <li><a href="#data-entry-page" data-id="<%= period.id %>"><%= period.name %></a></li>
+ <li><a href="#data-entry-page" data-id="<%= period.iso %>"><%= period.name %></a></li>
<% }); %>
</ul>
</script>
@@ -198,27 +259,29 @@
<li data-role="list-divider"><%= group.label %></li>
<% _( group.fields ).each( function(field, idx) { %>
+ <% var fieldId = _.uniqueId('field'); %>
+ <% var value = field.value === undefined ? '' : field.value; %>
<li>
- <label for='<%= field.dataElement %>-<%= field.categoryOptionCombo %>'><%= field.label %></label>
+ <label for='<%= fieldId %>'><%= field.label %></label>
<% if( field.type == 'TEXT' ) { %>
- <input type="text" id='<%= field.dataElement %>-<%= field.categoryOptionCombo %>' maxlength="255" />
+ <input type="text" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255" value="<%= value %>" />
<% } else if( field.type == 'DATE' ) { %>
- <input type="date" id='<%= field.dataElement %>-<%= field.categoryOptionCombo %>' maxlength="255" />
+ <input type="date" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255" value="<%= value %>" />
<% } else if( field.type == 'BOOLEAN' ) { %>
- <select type="" id='<%= field.dataElement %>-<%= field.categoryOptionCombo %>' maxlength="255">
- <option value="">None selected</option>
- <option value="yes">Yes</option>
- <option value="no">No</option>
+ <select type="" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255">
+ <option value="">[ None selected ]</option>
+ <option value="true" <% if( value == "true" ) { %> selected="selected" <% } %>>Yes</option>
+ <option value="false" <% if( value == "false" ) { %> selected="selected" <% } %>>No</option>
</select>
<% } else if( field.type == 'INTEGER' ) { %>
- <input type="number" id='<%= field.dataElement %>-<%= field.categoryOptionCombo %>' maxlength="255" />
+ <input type="number" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255" value="<%= value %>" />
<% } else if( field.type == 'INTEGER_POSITIVE' ) { %>
- <input type="number" id='<%= field.dataElement %>-<%= field.categoryOptionCombo %>' maxlength="255" />
+ <input type="number" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255" value="<%= value %>" />
<% } else if( field.type == 'INTEGER_NEGATIVE' ) { %>
- <input type="number" id='<%= field.dataElement %>-<%= field.categoryOptionCombo %>' maxlength="255" />
+ <input type="number" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255" value="<%= value %>" />
<% } else if( field.type == 'NUMBER' ) { %>
- <input type="number" id='<%= field.dataElement %>-<%= field.categoryOptionCombo %>' maxlength="255" />
+ <input type="number" id='<%= fieldId %>' name='<%= fieldId %>' data-dataElement='<%= field.dataElement %>' data-categoryOptionCombo='<%= field.categoryOptionCombo %>' maxlength="255" value="<%= value %>" />
<% } %>
</li>
<% }); %>
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm 2012-10-15 12:37:39 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm 2012-10-18 08:27:37 +0000
@@ -27,7 +27,7 @@
<ul data-role="listview" data-inset="true">
<li id="data-entry"><a href="data-entry">Aggregate Reporting</a></li>
<li id="messages"><a href="messages">Messages</a></li>
- <li id="settings"><a href="settings">Settings</a></li>
+ <li id="settings"><a href="settings">User Account</a></li>
</ul>
</section>
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/settings.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/settings.vm 2012-10-10 17:15:59 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/settings.vm 2012-10-18 08:27:37 +0000
@@ -46,19 +46,19 @@
<section data-role="content">
<form id="settings-form" method="POST">
- <label for="firstNameInput">First Name</label>
+ <label for="firstNameInput">First Name:</label>
<input id="firstNameInput" name="firstName" type="text" placeholder="Enter first name.." />
- <label for="surnameInput">Surname</label>
+ <label for="surnameInput">Surname:</label>
<input id="surnameInput" name="surname" type="text" placeholder="Enter surname.." />
- <label for="emailInput">E-mail</label>
+ <label for="emailInput">E-mail:</label>
<input id="emailInput" name="email" type="text" placeholder="Enter e-mail.." />
- <label for="phoneNumberInput">Phone Number</label>
+ <label for="phoneNumberInput">Phone Number:</label>
<input id="phoneNumberInput" name="phoneNumber" type="text" placeholder="Enter phone number.." />
- <input type="submit" value="Save settings" />
+ <input type="submit" value="Save" />
</form>
</section>