← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20939: PT noext.

 

------------------------------------------------------------
revno: 20939
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-11-04 00:45:37 +0100
message:
  PT noext.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core2.js


--
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-apps/src/main/webapp/dhis-web-pivot/scripts/core2.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core2.js	2015-11-03 23:08:41 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core2.js	2015-11-03 23:45:37 +0000
@@ -877,9 +877,11 @@
                 return request.url();
             };
 
-
-            //Layout.prototype.data = function() {
-
+            // dep 3
+
+            Layout.prototype.data = function() {
+                return $.getJSON('/api/analytics.json' + this.url());
+            };
 
         })();
 
@@ -888,14 +890,13 @@
             var Request = NS.Api.Request = function(config) {
                 var t = this;
 
+                config = NS.isObject(config) ? config : {};
+                config.baseUrl = NS.isString(config.baseUrl) ? config.baseUrl : '';
+                config.params = NS.arrayFrom(config.params);
+
                 // constructor
-                t.params = [];
-
-                (function() {
-                    if (NS.isArray(config) && config.length) {
-                        t.params = config;
-                    }
-                })();
+                t.baseUrl = config.baseUrl;
+                t.params = config.params;
             };
 
             Request.prototype.add = function(param) {
@@ -905,13 +906,13 @@
             };
 
             Request.prototype.url = function() {
-                return '?' + this.params.join('&').replace(/#/g, '.');
+                return this.baseUrl + '?' + this.params.join('&');
             };
         })();
 
         // Header
         (function() {
-            var Header = NS.Api.Header = function(config) {
+            var ResponseHeader = NS.Api.ResponseHeader = function(config) {
                 var t = this;
 
                 config = NS.isObject(config) ? config : {};
@@ -923,7 +924,7 @@
                 t.index;
             };
 
-            Header.prototype.setIndex = function(index) {
+            ResponseHeader.prototype.setIndex = function(index) {
                 if (NS.isNumeric(index)) {
                     this.index = parseInt(index);
                 }
@@ -937,15 +938,20 @@
 
                 config = NS.isObject(config) ? config : {};
 
-                t.headers = config.headers;
+                // constructor
+                t.headers = (config.headers || []).map(function(header, index) {
+                    return new NS.Api.ResponseHeader(header);
+                });
                 t.metaData = config.metaData;
                 t.rows = config.rows;
 
                 // transient
                 t.nameHeaderMap = function() {
-                    for (var i = 0, map = {}; i < t.headers.length; i++) {
-                        map[t.headers[i].name] = t.headers[i];
-                    }
+                    var map = {};
+
+                    t.headers.forEach(function(header) {
+                        map[header.name] = header;
+                    });
 
                     return map;
                 }();
@@ -953,12 +959,10 @@
                 // uninitialized
                 t.idValueMap = {};
 
-                // Header: index
-                (function() {
-                    for (var i = 0, header; i < t.headers.length; i++) {
-                        t.headers[i].setIndex(i);
-                    }
-                })();
+                // ResponseHeader: index
+                t.headers.forEach(function(header, index) {
+                    header.setIndex(index);
+                });
             };
 
             Response.prototype.getHeaderByName = function(name) {