← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8480: mobile: very basic first rendering of entry forms

 

------------------------------------------------------------
revno: 8480
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-10-11 12:16:00 +0200
message:
  mobile: very basic first rendering of entry forms
modified:
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.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/data-entry.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm	2012-10-10 17:14:33 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm	2012-10-11 10:16:00 +0000
@@ -1,17 +1,26 @@
 
 <script>
-    function selectOrganisationUnit(e, data) {
-        var $this = $(this);
-        console.log($this.data('id'));
+    var Selected = {};
+
+    function selectOrganisationUnit( e ) {
+        var $this = $(this);
+        Selected.orgUnit = $this.data('id');
+        console.log(Selected);
+    }
+
+    function selectDataSet( e ) {
+        var $this = $(this);
+        Selected.dataSet = $this.data('id');
+        console.log(Selected);
     }
 
     function loadOrganisationUnitsPage() {
         jQuery.ajax({
             url   : '$baseUrl/../api/currentUser/organisationUnits',
+            dataType: 'json',
             data: {
               'withChildren': true
-            },
-            dataType: 'json'
+            }
         }).success(function ( data ) {
             var tmpl = jQuery('#organisation-units-template').html();
 
@@ -19,20 +28,66 @@
                 _.template( tmpl, { 'organisationUnits': data } )
             );
 
-            console.log(data);
             jQuery('#organisation-unit-list').listview()
+            jQuery('#organisation-unit-list li a').bind('click', selectOrganisationUnit);
         }).error(function () {
             console.log('error fetching orgUnits')
         });
-
+    }
+
+    function loadDataSetsPage() {
+        if(Selected.orgUnit === undefined)
+        {
+            $.mobile.changePage('#organisation-units-page');
+            return;
+        }
+
+        jQuery.ajax({
+            url   : '$baseUrl/../api/currentUser/organisationUnits/' + Selected.orgUnit + '/dataSets',
+            dataType: 'json'
+        }).success(function ( data ) {
+            var tmpl = jQuery('#data-sets-template').html();
+
+            jQuery('#data-sets-page section[data-role="content"]').html(
+                _.template( tmpl, { 'dataSets': data } )
+            );
+
+            jQuery('#data-set-list').listview()
+            jQuery('#data-set-list li a').bind('click', selectDataSet);
+        }).error(function () {
+            console.log('error fetching dataSets')
+        });
     }
 
     function loadDataEntryPage() {
-
-    }
-
-    function loadDataSetsPage() {
-
+        if(Selected.dataSet === undefined)
+        {
+            if(Selected.orgUnit === undefined) {
+                $.mobile.changePage('#organisation-units-page');
+            } else {
+                $.mobile.changePage('#data-sets-page');
+            }
+
+            return;
+        }
+
+        jQuery.ajax({
+            url   : '$baseUrl/../api/dataSets/' + Selected.dataSet + '/form',
+            dataType: 'json'
+        }).success(function ( data ) {
+            console.log(data);
+
+            var tmpl = jQuery('#data-entry-template').html();
+
+            jQuery('#data-entry-page section[data-role="content"]').html(
+                _.template( tmpl, data )
+            );
+
+            jQuery('#data-entry-page').trigger('create')
+            jQuery('#data-entry-list').listview('refresh');
+        }).error(function () {
+            console.log('error fetching form')
+        });
     }
 
     jQuery(document).bind('pagechange', function (event, data) {
@@ -47,10 +102,6 @@
             loadDataEntryPage();
         }
     });
-
-    jQuery(document).bind('pageinit', function() {
-        $('#organisation-unit-list li a').bind('click', selectOrganisationUnit);
-    });
 </script>
 
 <script id="organisation-units-template" type="text/template">
@@ -69,6 +120,25 @@
     </ul>
 </script>
 
+<script id="data-entry-template" type="text/template">
+    <h1><%= label %></h1>
+    <form id='data-entry-form'>
+    <ul id="data-entry-list" data-role="listview" data-inset="true">
+        <% _( groups ).each( function(group, idx) { %>
+            <li data-role="list-divider"><%= group.label %></li>
+
+            <% _( group.fields ).each( function(field, idx) { %>
+                <li>
+                    <label for='<%= field.dataElement %>-<%= field.categoryOptionCombo %>'><%= field.label %></label>
+                    <input type="text" id='<%= field.dataElement %>-<%= field.categoryOptionCombo %>' />
+                </li>
+            <% }); %>
+
+        <% }); %>
+    </ul>
+    </form>
+</script>
+
 <section data-role="page" id="organisation-units-page" data-theme="c">
 
 	<header data-role="header" data-theme="b">