← Back to team overview

dhis2-devs team mailing list archive

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

 

------------------------------------------------------------
revno: 21049
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-11-13 20:46:32 +0100
message:
  PT noext.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app2.js
  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/app2.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app2.js	2015-11-12 15:59:35 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app2.js	2015-11-13 19:46:32 +0000
@@ -3,7 +3,7 @@
 
     // initialize
     (function() {
-        var metaDataManager = N.MetaDataManager,
+        var appManager = N.AppManager,
             calendarManager = N.CalendarManager,
             requestManager = new N.Api.RequestManager(),
             manifestReq = $.getJSON('manifest.webapp'),
@@ -12,137 +12,158 @@
             userAccountReq = $.getJSON('/api/me/user-account.json');
 
         manifestReq.done(function(manifest) {
-            metaDataManager.manifest = manifest;
+            appManager.manifest = manifest;
 
         systemInfoReq.done(function(systemInfo) {
-            metaDataManager.systemInfo = systemInfo;
-            metaDataManager.path = systemInfo.contextPath;
+            appManager.systemInfo = systemInfo;
+            appManager.path = systemInfo.contextPath;
 
         systemSettingsReq.done(function(systemSettings) {
-            metaDataManager.systemSettings = systemSettings;
+            appManager.systemSettings = systemSettings;
 
         userAccountReq.done(function(userAccount) {
-            metaDataManager.userAccount = userAccount;
-
-            calendarManager.setBaseUrl(metaDataManager.getPath());
-            calendarManager.setDateFormat(metaDataManager.getDateFormat());
-            calendarManager.generate(metaDataManager.systemSettings.keyCalendar);
-
-        // i18n
-        requestManager.add(new N.Api.Request({
-            baseUrl: 'i18n/i18n_app.properties',
-            type: 'ajax',
-            fn: function(r) {
-                var t = this;
-
-                N.I18nManager.add(dhis2.util.parseJavaProperties(r));
-
-                if (metaDataManager.isUiLocaleDefault()) {
-                    requestManager.ok(t);
-                }
-                else {
+            appManager.userAccount = userAccount;
+
+            calendarManager.setBaseUrl(appManager.getPath());
+            calendarManager.setDateFormat(appManager.getDateFormat());
+            calendarManager.generate(appManager.systemSettings.keyCalendar);
+
+        // requests
+        (function() {
+            var uiLocale = appManager.getUiLocale(),
+                displayProperty = appManager.getDisplayProperty(),
+                path = appManager.getPath();
+
+            // i18n
+            requestManager.add(new N.Api.Request({
+                baseUrl: 'i18n/i18n_app.properties',
+                type: 'ajax',
+                success: function(r) {
+                    var t = this;
+
+                    N.I18nManager.add(dhis2.util.parseJavaProperties(r));
+
+                    if (appManager.isUiLocaleDefault()) {
+                        requestManager.ok(t);
+                    }
+                    else {
+                        $.ajax({
+                            url: 'i18n/i18n_app_' + uiLocale + '.properties',
+                            success: function(r) {
+                                N.I18nManager.add(dhis2.util.parseJavaProperties(r));
+                            },
+                            error: function() {
+                                console.log('(i18n) No translations found for system locale (' + uiLocale + ')');
+                            },
+                            complete: function() {
+                                requestManager.ok(t);
+                            }
+                        });
+                    }
+                },
+                error: function() {
                     $.ajax({
-                        url: 'i18n/i18n_app_' + metaDataManager.getUiLocale() + '.properties',
+                        url: 'i18n/i18n_app_' + uiLocale + '.properties',
                         success: function(r) {
                             N.I18nManager.add(dhis2.util.parseJavaProperties(r));
                         },
-                        error: function() {
-                            console.log('(i18n) No translations found for system locale (' + metaDataManager.getUiLocale() + ')');
+                        error: function() {
+                            alert('(i18n) No translations found for system locale (' + uiLocale + ') or default locale (' + appManager.defaultUiLocale + ')');
                         },
-                        complete: function() {
-                            requestManager.ok(t);
+                        completed: function() {
+                            requestManager.ok(this);
                         }
                     });
                 }
-            }
-        }));
-
-        // authorization
-        requestManager.add(new N.Api.Request({
-            baseUrl: metaDataManager.getPath() + '/api/me/authorization/F_VIEW_UNAPPROVED_DATA',
-            fn: function(r) {
-                metaDataManager.viewUnapprovedData = r;
-                requestManager.ok(this);
-            }
-        }));
-
-        // root nodes
-        requestManager.add(new N.Api.Request({
-            baseUrl: metaDataManager.getPath() + '/api/organisationUnits.json',
-            params: [
-                'userDataViewFallback=true',
-                'fields=id,' + metaDataManager.getDisplayProperty() + ',children[id,' + metaDataManager.getDisplayProperty() + ']',
-                'paging=false'
-            ],
-            fn: function(r) {
-                metaDataManager.rootNodes = r.organisationUnits;
-                requestManager.ok(this);
-            }
-        }));
-
-        // organisation unit levels
-        requestManager.add(new N.Api.Request({
-            baseUrl: metaDataManager.getPath() + '/api/organisationUnitLevels.json',
-            params: [
-                'fields=id,' + metaDataManager.getDisplayProperty() + 'level',
-                'paging=false'
-            ],
-            fn: function(r) {
-                metaDataManager.organisationUnitLevels = r.organisationUnitLevels;
-
-                if (!r.organisationUnitLevels.length) {
-                    alert('No organisation unit levels found');
-                }
-
-                requestManager.ok(this);
-            }
-        }));
+            }));
+
+            // authorization
+            requestManager.add(new N.Api.Request({
+                baseUrl: path + '/api/me/authorization/F_VIEW_UNAPPROVED_DATA',
+                success: function(r) {
+                    appManager.viewUnapprovedData = r;
+                    requestManager.ok(this);
+                }
+            }));
+
+            // root nodes
+            requestManager.add(new N.Api.Request({
+                baseUrl: path + '/api/organisationUnits.json',
+                params: [
+                    'userDataViewFallback=true',
+                    'fields=id,' + displayProperty + ',children[id,' + displayProperty + ']',
+                    'paging=false'
+                ],
+                success: function(r) {
+                    appManager.rootNodes = r.organisationUnits;
+                    requestManager.ok(this);
+                }
+            }));
+
+            // organisation unit levels
+            requestManager.add(new N.Api.Request({
+                baseUrl: path + '/api/organisationUnitLevels.json',
+                params: [
+                    'fields=id,' + displayProperty + 'level',
+                    'paging=false'
+                ],
+                fn: function(r) {
+                    appManager.organisationUnitLevels = r.organisationUnitLevels;
+
+                    if (!r.organisationUnitLevels.length) {
+                        alert('No organisation unit levels found');
+                    }
+
+                    requestManager.ok(this);
+                }
+            }));
+
+            // legend sets
+            requestManager.add(new N.Api.Request({
+                baseUrl: path + '/api/legendSets.json',
+                params: [
+                    'fields=id,' + displayProperty + ',legends[id,' + displayProperty + ',startValue,endValue,color]',
+                    'paging=false'
+                ],
+                fn: function(r) {
+                    appManager.legendSets = r.legendSets;
+                    requestManager.ok(this);
+                }
+            }));
+
+            // dimensions
+            requestManager.add(new N.Api.Request({
+                baseUrl: path + '/api/dimensions.json',
+                params: [
+                    'fields=id,' + displayProperty,
+                    'paging=false'
+                ],
+                success: function(r) {
+                    appManager.dimensions = r.dimensions;
+                    requestManager.ok(this);
+                }
+            }));
+
+            // approval levels
+            requestManager.add(new N.Api.Request({
+                baseUrl: path + '/api/dataApprovalLevels.json',
+                params: [
+                    'order=level:asc',
+                    'fields=id,' + displayProperty,
+                    'paging=false'
+                ],
+                success: function(r) {
+                    appManager.dataApprovalLevels = r.dataApprovalLevels;
+                    requestManager.ok(this);
+                }
+            }));
+        })();
+
+        //requestManager.set(function() {
 
 
         requestManager.run();
 
-
-                                        //requests.push({
-                                            //url: 'i18n/i18n_app.properties',
-                                            //success: function(r) {
-                                                //NS.i18n = dhis2.util.parseJavaProperties(r.responseText);
-
-                                                //if (keyUiLocale === defaultKeyUiLocale) {
-                                                    //fn();
-                                                //}
-                                                //else {
-                                                    //Ext.Ajax.request({
-                                                        //url: 'i18n/i18n_app_' + keyUiLocale + '.properties',
-                                                        //success: function(r) {
-                                                            //Ext.apply(NS.i18n, dhis2.util.parseJavaProperties(r.responseText));
-                                                        //},
-                                                        //failure: function() {
-                                                            //console.log('No translations found for system locale (' + keyUiLocale + ')');
-                                                        //},
-                                                        //callback: function() {
-                                                            //fn();
-                                                        //}
-                                                    //});
-                                                //}
-                                            //},
-                                            //failure: function() {
-                                                //Ext.Ajax.request({
-                                                    //url: 'i18n/i18n_app_' + keyUiLocale + '.properties',
-                                                    //success: function(r) {
-                                                        //NS.i18n = dhis2.util.parseJavaProperties(r.responseText);
-                                                    //},
-                                                    //failure: function() {
-                                                        //alert('No translations found for system locale (' + keyUiLocale + ') or default locale (' + defaultKeyUiLocale + ').');
-                                                    //},
-                                                    //callback: fn
-                                                //});
-                                            //}
-                                        //});
-
-
-
-
-
         });
         });
         });

=== 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-12 15:59:35 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core2.js	2015-11-13 19:46:32 +0000
@@ -393,9 +393,9 @@
         N.DateManager = new DateManager();
     })();
 
-    // MetaDataManager
+    // AppManager
     (function() {
-        var MetaDataManager = function() {
+        var AppManager = function() {
             var t = this;
 
             // constants
@@ -463,23 +463,23 @@
             t.analysisFields;
         };
 
-        MetaDataManager.prototype.getPath = function() {
+        AppManager.prototype.getPath = function() {
             return this.path ? this.path : (this.path = this.manifest.activities.dhis.href);
         };
 
-        MetaDataManager.prototype.getDateFormat = function() {
+        AppManager.prototype.getDateFormat = function() {
             return this.dateFormat ? this.dateFormat : (this.dateFormat = N.isString(this.systemSettings.keyDateFormat) ? this.systemSettings.keyDateFormat.toLowerCase() : 'yyyy-mm-dd');
         };
 
-        MetaDataManager.prototype.getRelativePeriod = function() {
+        AppManager.prototype.getRelativePeriod = function() {
             return this.relativePeriod ? this.relativePeriod : (this.relativePeriod = this.systemSettings.keyAnalysisRelativePeriod || 'LAST_12_MONTHS');
         };
 
-        MetaDataManager.prototype.getUiLocale = function() {
+        AppManager.prototype.getUiLocale = function() {
             return this.uiLocale ? this.uiLocale : (this.uiLocale = this.userAccount.settings.keyUiLocale || this.defaultUiLocale);
         };
 
-        MetaDataManager.prototype.getDisplayProperty = function() {
+        AppManager.prototype.getDisplayProperty = function() {
             if (this.displayProperty) {
                 return this.displayProperty;
             }
@@ -489,21 +489,21 @@
             return this.displayProperty = (key === 'name') ? key : (key + '|rename(name)');
         };
 
-        MetaDataManager.prototype.getValueTypesByType = function(type) {
+        AppManager.prototype.getValueTypesByType = function(type) {
             return this.valueTypes[type];
         };
 
         // dep 1
 
-        MetaDataManager.prototype.isUiLocaleDefault = function() {
+        AppManager.prototype.isUiLocaleDefault = function() {
             return this.getUiLocale() === this.defaultUiLocale;
         };
 
-        MetaDataManager.prototype.getAnalysisFields = function() {
+        AppManager.prototype.getAnalysisFields = function() {
             return this.analysisFields ? this.analysisFields : (this.analysisFields = (this.defaultAnalysisFields.join(',').replaceAll('$', this.getDisplayProperty())));
         };
 
-        N.MetaDataManager = new MetaDataManager();
+        N.AppManager = new AppManager();
     })();
 
     // CalendarManager
@@ -739,6 +739,39 @@
         N.DimConf = new DimensionConfig();
     })();
 
+    // RootNodeManager
+    (function() {
+        var RootNodeManager = function() {
+            var t = this;
+
+            // constants
+            t.rootId = 'root';
+
+            // uninitialized
+            t.nodes;
+        };
+
+        RootNodeManager.prototype.add = function(param) {
+            var t = this,
+                nodes = N.arrayFrom(param);
+
+            nodes.forEach(function(node) {
+                node.expanded = true;
+                node.path = '/' + t.rootId + '/' + node.id;
+            });
+        };
+
+        RootNodeManager.prototype.getRootNode = function() {
+            return this.nodes[0];
+        };
+
+        RootNodeManager.prototype.getRootNodes = function() {
+            return this.nodes;
+        };
+
+        N.RootNodeManager = new RootNodeManager();
+    })();
+
     // PeriodConfig
     (function() {
         var PeriodConfig = function() {
@@ -1501,13 +1534,6 @@
                     metaData: $.getJSON(metaDataRequest.url('skipData=true')),
                     data: $.getJSON(dataRequest.url('skipMeta=true'))
                 };
-
-                //return $.getJSON(metaDataRequest.url(), function(metaData) {
-                    //return $.getJSON(dataRequest.url());
-                //});
-
-
-                //$.getJSON('/api/analytics.json' + request.url());
             };
         })();
 
@@ -1523,16 +1549,21 @@
                 t.params = N.arrayFrom(config.params);
                 t.manager = config.manager || null;
                 t.type = N.isString(config.type) ? config.type : 'json';
-                t.fn = N.isFunction(config.fn) ? config.fn : function() { t.defaultFn(); };
+                t.success = N.isFunction(config.success) ? config.success : function() { t.defaultSuccess(); };
+                t.error = N.isFunction(config.error) ? config.error : function() { t.defaultError(); };
+                t.completed = N.isFunction(config.completed) ? config.completed : function() { t.defaultCompleted(); };
 
-                // default fn
-                t.defaultFn = function() {
+                // defaults
+                t.defaultSuccess = function() {
                     var t = this;
 
                     if (t.manager) {
                         t.manager.ok(t);
                     }
                 };
+
+                t.defaultError = function() {};
+                t.defaultCompleted = function() {};
             };
 
             Request.prototype.log = function(text, noError) {
@@ -1598,9 +1629,9 @@
                 }
             };
 
-            Request.prototype.setFn = function(fn) {
+            Request.prototype.setSuccess = function(fn) {
                 if (N.isFunction(fn)) {
-                    this.fn = fn;
+                    this.success = fn;
                 }
             };
 
@@ -1622,15 +1653,21 @@
 
             // dep 1
 
-            Request.prototype.run = function(fn) {
+            Request.prototype.run = function(config) {
                 var t = this;
-                this.setFn(fn);
+
+                config = N.isObject(config) ? config : {};
 
                 if (this.type === 'ajax') {
-                    return $.ajax({url: this.url(), success: t.fn});
+                    return $.ajax({
+                        url: this.url(),
+                        success: config.success || t.success,
+                        error: config.error || t.error,
+                        completed: config.completed || t.completed
+                    });
                 }
                 else {
-                    return $.getJSON(this.url(), t.fn);
+                    return $.getJSON(this.url(), config.success || t.success).error(config.error || t.error).completed(config.completed || t.completed);
                 }
             };
         })();