← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12482: (PT, DV) Several minor bug fixes.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 12482 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-10-07 18:31:28 +0200
message:
  (PT, DV) Several minor bug fixes.
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/login.css
  dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js
  dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/styles/style.css
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.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-commons-resources/src/main/webapp/dhis-web-commons/css/login.css'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/login.css	2013-10-07 13:27:04 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/login.css	2013-10-07 15:45:20 +0000
@@ -27,7 +27,7 @@
 input[type=text],input[type=password]
 {
   border: 1px solid #888;
-  padding: 4px 7px;
+  padding: 4px 6px;
 }
 
 #flagArea
@@ -95,7 +95,7 @@
 
 #loginField input[type=text],input[type=password]
 {
-  width: 264px;
+  width: 266px;
   height: 20px;
 }
 

=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js	2013-10-07 12:39:55 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js	2013-10-07 16:18:43 +0000
@@ -232,9 +232,10 @@
 					pt.viewport.westRegion.hasScrollbar = true;
 				}
 
+                // Expand first panel
 				cmp.dimension.panels[0].expand();
 
-				// Load favorite from url
+                // Look for url params
 				var id = util.url.getUrlParam('id'),
 					session = util.url.getUrlParam('s'),
 					layout;
@@ -2217,7 +2218,9 @@
 	};
 
 	createViewport = function() {
-		var indicatorAvailable,
+        var dimConf = pt.conf.finals.dimension,
+        
+			indicatorAvailable,
 			indicatorSelected,
 			indicator,
 			dataElementAvailable,
@@ -4440,9 +4443,8 @@
 			}
 		});
 
-		setGui = function(layout, updateGui, isFavorite) {
-			var dimConf = pt.conf.finals.dimension,
-				dimensions = [].concat(layout.columns || [], layout.rows || [], layout.filters || []),
+		setGui = function(layout, xLayout, updateGui, isFavorite) {
+			var dimensions = [].concat(layout.columns || [], layout.rows || [], layout.filters || []),
 				dimMap = pt.service.layout.getObjectNameDimensionMap(dimensions),
 				recMap = pt.service.layout.getObjectNameDimensionItemsMap(dimensions),
 				graphMap = layout.parentGraphMap,

=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js	2013-10-07 12:10:11 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/core.js	2013-10-07 16:28:57 +0000
@@ -723,7 +723,7 @@
 					}
 
 					// Get object names and user orgunits
-					for (var i = 0, dim, dims = [].concat(config.columns, config.rows, config.filters); i < dims.length; i++) {
+					for (var i = 0, dim, dims = [].concat(config.columns || [], config.rows || [], config.filters || []); i < dims.length; i++) {
 						dim = dims[i];
 
 						if (dim) {
@@ -1167,6 +1167,10 @@
 						paramString += '&filter=' + dim.dimensionName + ':' + dim.ids.join(';');
 					}
 				}
+				
+				if (xLayout.showHierarchy) {
+					paramString += '&hierarchyMeta=true';
+				}
 
 				return paramString;
 			};
@@ -1185,6 +1189,7 @@
 
 			engine.createTable = function(layout, pt, updateGui, isFavorite) {
 				var legendSet = layout.legendSet ? pt.init.idLegendSetMap[layout.legendSet.id] : null,
+					isHierarchy,
 					getItemName,
 					getSyncronizedXLayout,
 					getExtendedResponse,
@@ -1198,11 +1203,15 @@
 					uuidDimUuidsMap = {},
 					uuidObjectMap = {};
 
+				isHierarchy = function(id, response) {					
+					return layout.showHierarchy && Ext.isObject(response.metaData.ouHierarchy) && response.metaData.ouHierarchy.hasOwnProperty(id);
+				};						
+					
 				getItemName = function(id, response, isHtml) {
 					var metaData = response.metaData,
 						name = '';
 					
-					if (layout.showHierarchy && Ext.isObject(metaData.ouHierarchy) && metaData.ouHierarchy.hasOwnProperty(id)) {
+					if (isHierarchy(id, response)) {
 						var a = Ext.clean(metaData.ouHierarchy[id].split('/'));
 						
 						for (var i = 0; i < a.length; i++) {
@@ -1218,7 +1227,7 @@
 				getSyncronizedXLayout = function(xLayout, response) {
 					var removeDimensionFromXLayout,
 						getHeaderNames,
-						dimensions = [].concat(xLayout.columns, xLayout.rows, xLayout.filters);
+						dimensions = [].concat(xLayout.columns || [], xLayout.rows || [], xLayout.filters || []);
 
 					removeDimensionFromXLayout = function(objectName) {
 						var getUpdatedAxis;
@@ -1330,8 +1339,8 @@
 
 										userOugc = [];
 										
-										for (var i = 0, id; i < responseOu.length; i++) {
-											id = responseOu[i];
+										for (var j = 0, id; j < responseOu.length; j++) {
+											id = responseOu[j];
 											
 											if (!Ext.Array.contains(userOuOuc, id)) {
 												userOugc.push({
@@ -1347,8 +1356,8 @@
 									dim.items = [].concat(userOu || [], userOuc || [], userOugc || []);
 								}
 								else if (isLevel || isGroup) {
-									for (var i = 0, responseOu = response.metaData[ou], id; i < responseOu.length; i++) {
-										id = responseOu[i];
+									for (var j = 0, responseOu = response.metaData[ou], id; j < responseOu.length; j++) {
+										id = responseOu[j];
 										
 										dim.items.push({
 											id: id,
@@ -1364,7 +1373,7 @@
 							}
 							else {
 								// Items: get ids from metadata -> items
-								if (metaDataDim) {
+								if (Ext.isArray(metaDataDim) && metaDataDim.length) {
 									var ids = Ext.clone(response.metaData[dim.dimensionName]);
 									for (var j = 0; j < ids.length; j++) {
 										dim.items.push({
@@ -1408,7 +1417,7 @@
 								}
 							}
 
-							return pt.engine.getExtendedLayout(layout);
+							return engine.getExtendedLayout(layout);
 						}
 
 						return null;
@@ -1992,7 +2001,7 @@
 								for (var j = 0, obj, newObj; j < xRowAxis.dims; j++) {
 									obj = xRowAxis.objects.all[j][i];
 									obj.type = 'dimension';
-									obj.cls = 'pivot-dim td-nobreak';
+									obj.cls = 'pivot-dim td-nobreak' + (isHierarchy(obj.id, xResponse) ? ' align-left' : '');
 									obj.noBreak = true;
 									obj.hidden = !(obj.rowSpan || obj.colSpan);
 									obj.htmlValue = getItemName(obj.id, xResponse, true);
@@ -2447,7 +2456,7 @@
 						}
 						
 						if (updateGui) {
-							pt.viewport.setGui(layout, updateGui, isFavorite);
+							pt.viewport.setGui(layout, xLayout, updateGui, isFavorite);
 						}
 					}
 
@@ -2481,7 +2490,7 @@
 
 					// Param string
 					pt.paramString = engine.getParamString(xLayout, true);
-					url = pt.init.contextPath + '/api/analytics.json' + pt.paramString + '&hierarchyMeta=true';
+					url = pt.init.contextPath + '/api/analytics.json' + pt.paramString;
 
 					// Validate request size
 					if (!validateUrl(url)) {

=== modified file 'dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/styles/style.css'
--- dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/styles/style.css	2013-10-07 12:39:55 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/styles/style.css	2013-10-07 15:45:20 +0000
@@ -147,6 +147,10 @@
 	color: #303038;
 }
 
+.align-left {
+	text-align: left !important;
+}
+
 /*----------------------------------------------------------------------------
  * Pivot
  *--------------------------------------------------------------------------*/

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js	2013-10-04 12:38:58 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js	2013-10-07 16:18:43 +0000
@@ -393,13 +393,13 @@
                     layout;
 
                 if (id) {
-                    engine.loadChart(id, dv);
+                    engine.loadChart(id, dv, true, true);
                 }
                 else if (Ext.isString(session) && DV.isSessionStorage && Ext.isObject(JSON.parse(sessionStorage.getItem('dhis2'))) && session in JSON.parse(sessionStorage.getItem('dhis2'))) {
                     layout = api.layout.Layout(engine.analytical2layout(JSON.parse(sessionStorage.getItem('dhis2'))[session]));
 
                     if (layout) {
-                        dv.viewport.setFavorite(layout);
+						dv.engine.createChart(layout, dv, true);
                     }
                 }
 
@@ -1427,7 +1427,7 @@
 								element.addClsOnOver('link');
 								element.load = function() {
 									favoriteWindow.hide();
-									dv.engine.loadChart(record.data.id, dv);
+									dv.engine.loadChart(record.data.id, dv, true, true);
 								};
 								element.dom.setAttribute('onclick', 'Ext.get(this).load();');
 							}
@@ -2123,7 +2123,7 @@
             westRegion,
             centerRegion,
 
-            setFavorite,
+            setGui,
 
             viewport,
             addListeners;
@@ -4584,34 +4584,31 @@
             }
         });
 
-        setFavorite = function(layout) {
-            var xLayout,
-                dimMap,
-                recMap,
-                graphMap,
+        setGui = function(layout, xLayout, updateGui, isFavorite) {
+			var dimensions = [].concat(layout.columns || [], layout.rows || [], layout.filters || []),
+				dimMap = dv.service.layout.getObjectNameDimensionMap(dimensions),
+				recMap = dv.service.layout.getObjectNameDimensionItemsMap(dimensions),
+				graphMap = layout.parentGraphMap,
                 objectName,
                 periodRecords,
                 fixedPeriodRecords = [],
-                isOu = false,
-                isOuc = false,
+				dimNames = [],
+				isOu = false,
+				isOuc = false,
 				isOugc = false,
-                isLevel = false,
 				levels = [],
-				groups = [];
-
-            // State
-            dv.viewport.interpretationButton.enable();
-
-            // Create chart
-            dv.engine.createChart(layout, dv);
+				groups = [],
+				orgunits = [];
+
+			// State
+			downloadButton.enable();
+			
+			if (isFavorite) {
+				interpretationButton.enable();
+			}
 
             // Set gui
 
-            xLayout = dv.engine.getExtendedLayout(layout);
-            dimMap = xLayout.objectNameDimensionsMap;
-            recMap = xLayout.objectNameItemsMap;
-            graphMap = layout.parentGraphMap;
-
             // Indicators
             dv.store.indicatorSelected.removeAll();
             objectName = dimConf.indicator.objectName;
@@ -4680,7 +4677,7 @@
             }
 
             // Layout
-            dv.viewport.chartType.setChartType(xLayout.type);
+            dv.viewport.chartType.setChartType(layout.type);
 
             dv.viewport.series.setValue(xLayout.columnDimensionNames[0]);
             dv.viewport.series.filterNext();
@@ -4695,26 +4692,29 @@
                 dv.viewport.optionsWindow.setOptions(layout);
             }
 
-            // Organisation units
-            if (recMap[dimConf.organisationUnit.objectName]) {
-                for (var i = 0, ouRecords = recMap[dimConf.organisationUnit.objectName]; i < ouRecords.length; i++) {
-                    if (ouRecords[i].id === 'USER_ORGUNIT') {
-                        isOu = true;
-                    }
-                    if (ouRecords[i].id === 'USER_ORGUNIT_CHILDREN') {
-                        isOuc = true;
-                    }
-					if (ouRecords[i].id === 'USER_ORGUNIT_GRANDCHILDREN') {
+			// Organisation units
+			if (recMap[dimConf.organisationUnit.objectName]) {
+				for (var i = 0, ouRecords = recMap[dimConf.organisationUnit.objectName]; i < ouRecords.length; i++) {
+					if (ouRecords[i].id === 'USER_ORGUNIT') {
+						isOu = true;
+					}
+					else if (ouRecords[i].id === 'USER_ORGUNIT_CHILDREN') {
+						isOuc = true;
+					}
+					else if (ouRecords[i].id === 'USER_ORGUNIT_GRANDCHILDREN') {
 						isOugc = true;
 					}
-                    if (ouRecords[i].id.substr(0,5) === 'LEVEL') {
-                        isLevel = true;
-                    }
-					if (ouRecords[i].id.substr(0,8) === 'OU_GROUP') {
+					else if (ouRecords[i].id.substr(0,5) === 'LEVEL') {
+						levels.push(parseInt(ouRecords[i].id.split('-')[1]));
+					}
+					else if (ouRecords[i].id.substr(0,8) === 'OU_GROUP') {
 						groups.push(parseInt(ouRecords[i].id.split('-')[1]));
 					}
-                }
-            }
+					else {
+						orgunits.push(ouRecords[i].id);
+					}
+				}
+			}
 
 			if (levels.length) {
 				toolMenu.clickHandler('level');
@@ -4730,20 +4730,23 @@
 				userOrganisationUnitChildren.setValue(isOuc);
 				userOrganisationUnitGrandChildren.setValue(isOugc);
 			}
-
-            // If fav has organisation units, wait for tree callback before update
-            if (recMap[dimConf.organisationUnit.objectName] && Ext.isObject(graphMap)) {
-                treePanel.numberOfRecords = dv.util.object.getLength(graphMap);
-
-                for (var i = 0, a = xLayout.objectNameItemsMap[dimConf.organisationUnit.objectName]; i < a.length; i++) {
-                    if (graphMap.hasOwnProperty(a[i].id)) {
-                        treePanel.multipleExpand(a[i].id, graphMap[a[i].id], false);
-                    }
-                }
-            }
-            else {
-                treePanel.reset();
-            }
+			
+			if (!(isOu || isOuc || isOugc)) {
+
+				// If fav has organisation units, wait for tree callback before update
+				if (Ext.isObject(graphMap)) {
+					treePanel.numberOfRecords = dv.util.object.getLength(graphMap);
+
+					for (var key in graphMap) {						
+						if (graphMap.hasOwnProperty(key)) {
+							treePanel.multipleExpand(key, graphMap[key], false);
+						}
+					}
+				}
+			}
+			else {
+				treePanel.reset();
+			}
         };
 
         viewport = Ext.create('Ext.container.Viewport', {
@@ -4764,7 +4767,7 @@
             userOrganisationUnit: userOrganisationUnit,
             userOrganisationUnitChildren: userOrganisationUnitChildren,
             dataElementDetailLevel: dataElementDetailLevel,
-            setFavorite: setFavorite,
+            setGui: setGui,
             items: [
                 westRegion,
                 centerRegion
@@ -4800,8 +4803,6 @@
         return viewport;
     };
 
-	
-	
 	initialize = function(r) {
 
 		// ext configuration

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js	2013-10-04 12:38:58 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/core.js	2013-10-07 16:28:57 +0000
@@ -3,7 +3,7 @@
 	// ext config
 	Ext.Ajax.method = 'GET';
 	
-	// pt	
+	// dv	
 	DV = {
 		core: {
 			instances: []
@@ -17,6 +17,7 @@
         var conf = {},
             util = {},
             api = {},
+            service = {},
             engine = {},
             dimConf;
 
@@ -772,6 +773,45 @@
                 }();
             };
         }());
+		
+		// service
+		(function() {
+			service.layout = {};
+			
+			service.layout.getObjectNameDimensionMap = function(dimensionArray) {
+				var map = {};
+				
+				if (Ext.isArray(dimensionArray) && dimensionArray.length) {					
+					for (var i = 0, dim; i < dimensionArray.length; i++) {
+						dim = api.layout.Dimension(dimensionArray[i]);
+						
+						if (dim) {
+							map[dim.dimension] = dim;
+						}
+					}
+				}
+				
+				return map;
+			};				
+			
+			service.layout.getObjectNameDimensionItemsMap = function(dimensionArray) {
+				var map = {};
+				
+				if (Ext.isArray(dimensionArray) && dimensionArray.length) {					
+					for (var i = 0, dim; i < dimensionArray.length; i++) {
+						dim = api.layout.Dimension(dimensionArray[i]);
+						
+						if (dim) {
+							map[dim.dimension] = dim.items;
+						}
+					}
+				}
+				
+				return map;
+			};
+							
+			service.response = {};
+		}());
 
         // engine
         (function() {
@@ -1045,9 +1085,11 @@
                 }
             };
 
-            engine.createChart = function(layout, dv) {
+            engine.createChart = function(layout, dv, updateGui, isFavorite) {
                 var getSyncronizedXLayout,
                     getExtendedResponse,
+                    validateUrl,
+                    
                     getDefaultStore,
                     getDefaultNumericAxis,
                     getDefaultCategoryAxis,
@@ -1057,10 +1099,15 @@
                     getDefaultTargetLine,
                     getDefaultBaseLine,
                     getDefaultTips,
+                    setDefaultTheme,
+                    getDefaultLegend,                    
                     getDefaultChartTitle,
+                    getDefaultChartSizeHandler,
+                    getDefaultChartTitlePositionHandler,
                     getDefaultChart,
-                    validateUrl,
+                    
                     generator = {},
+                    afterLoad,
                     initialize;
 
                 getSyncronizedXLayout = function(xLayout, response) {
@@ -1126,71 +1173,58 @@
                                     userOuc = dv.util.array.sortObjectsByString(userOuc);
                                 }
                                 if (isUserOrgunitGrandChildren) {
-										var userOuOuc = [].concat(dv.init.user.ou, dv.init.user.ouc),
-											responseOu = response.metaData[ou];
+									var userOuOuc = [].concat(dv.init.user.ou, dv.init.user.ouc),
+										responseOu = response.metaData[ou];
 
-										userOugc = [];
+									userOugc = [];
+									
+									for (var j = 0, id; j < responseOu.length; j++) {
+										id = responseOu[j];
 										
-										for (var key in responseOu) {
-											if (responseOu.hasOwnProperty(key) && !Ext.Array.contains(userOuOuc, key)) {
-												userOugc.push({
-													id: key,
-													name: response.metaData.names[key]
-												});
-											}
+										if (!Ext.Array.contains(userOuOuc, id)) {
+											userOugc.push({
+												id: id,
+												name: response.metaData.names[id]
+											});
 										}
-
-										userOugc = dv.util.array.sortObjectsByString(userOugc);
 									}
 
+									userOugc = dv.util.array.sortObjectsByString(userOugc);
+								}
+
                                 dim.items = [].concat(userOu || [], userOuc || [], userOugc || []);
                             }
                             else if (isLevel || isGroup) {
-									var responseOu = response.metaData[ou];
-
-									for (var key in responseOu) {
-										if (responseOu.hasOwnProperty(key)) {
-											dim.items.push({
-												id: key,
-												name: response.metaData.names[key]
-											});
-										}
-									}
-
-									dim.items = dv.util.array.sortObjectsByString(dim.items);
+								for (var j = 0, responseOu = response.metaData[ou], id; j < responseOu.length; j++) {
+									id = responseOu[j];
+									
+									dim.items.push({
+										id: id,
+										name: response.metaData.names[id]
+									});
 								}
-                            else {
-                                dim.items = Ext.clone(xLayout.dimensionNameItemsMap[dim.dimensionName]);
-                            }
+
+								dim.items = pt.util.array.sortObjectsByString(dim.items);
+							}
+							else {
+								dim.items = Ext.clone(xLayout.dimensionNameItemsMap[dim.dimensionName]);
+							}
                         }
                         else {
                             // Items: get ids from metadata -> items
-                            if (metaDataDim) {
-									var ids = Ext.clone(response.metaData[dim.dimensionName]);
-									
-									if (dim.dimensionName === ou) {
-										for (var key in ids) {
-											if (ids.hasOwnProperty(key)) {
-												dim.items.push({
-													id: key,
-													name: response.metaData.names[key]
-												});
-											}
-										}
-									}
-									else {
-										for (var j = 0; j < ids.length; j++) {
-											dim.items.push({
-												id: ids[j],
-												name: response.metaData.names[ids[j]]
-											});
-										}
-									}
+                            if (Ext.isArray(metaDataDim) && metaDataDim.length) {
+								var ids = Ext.clone(response.metaData[dim.dimensionName]);
+								for (var j = 0; j < ids.length; j++) {
+									dim.items.push({
+										id: ids[j],
+										name: response.metaData.names[ids[j]]
+									});
 								}
-                            // Items: get items from xLayout
-                            else {
-                                dim.items = Ext.clone(xLayout.objectNameItemsMap[dim.objectName]);
-                            }
+							}
+							// Items: get items from xLayout
+							else {
+								dim.items = Ext.clone(xLayout.objectNameItemsMap[dim.objectName]);
+							}
                         }
                     }
 
@@ -1198,7 +1232,7 @@
                     layout = dv.api.layout.Layout(xLayout);
 
                     if (layout) {
-                        dimensions = [].concat(layout.columns, layout.rows, layout.filters);
+                        dimensions = [].concat(layout.columns || [], layout.rows || [], layout.filters || []);
 
                         for (var i = 0, idNameMap = response.metaData.names, dimItems; i < dimensions.length; i++) {
                             dimItems = dimensions[i].items;
@@ -1220,32 +1254,6 @@
                     return null;
                 };
 
-                validateResponse = function(response) {
-                    if (!(response && Ext.isObject(response))) {
-                        alert('Data response invalid');
-                        return false;
-                    }
-
-                    if (!(response.headers && Ext.isArray(response.headers) && response.headers.length)) {
-                        alert('Data response invalid');
-                        return false;
-                    }
-
-                    if (!(Ext.isNumber(response.width) && response.width > 0 &&
-                          Ext.isNumber(response.height) && response.height > 0 &&
-                          Ext.isArray(response.rows) && response.rows.length > 0)) {
-                        alert('No values found');
-                        return false;
-                    }
-
-                    if (response.headers.length !== response.rows[0].length) {
-                        alert('Data response invalid');
-                        return false;
-                    }
-
-                    return true;
-                };
-
                 getExtendedResponse = function(response, xLayout) {
                     response.nameHeaderMap = {};
                     response.idValueMap = {};
@@ -2196,21 +2204,54 @@
                     return chart;
                 };
 
+				afterLoad = function(layout, xLayout, xResponse) {
+					
+					if (dv.isPlugin) {
+						
+					}
+					else {
+						if (DV.isSessionStorage) {
+							engine.setSessionStorage(layout, 'chart');
+						}
+						
+						if (updateGui) {
+							dv.viewport.setGui(layout, xLayout, updateGui, isFavorite);
+						}
+					}
+
+					// Hide mask
+					util.mask.hideMask(dv.viewport.centerRegion);
+
+					// Add objects to instance
+					dv.layout = layout;
+					dv.xLayout = xLayout;
+					dv.xResponse = xResponse;
+
+					if (DV.isDebug) {
+						console.log("xResponse", xResponse);
+						console.log("xLayout", xLayout);
+						console.log("layout", layout);
+					}
+				};
+
                 initialize = function() {
                     var url,
                         xLayout,
                         xResponse,
                         chart;
 
+					// Extended layout
                     xLayout = engine.getExtendedLayout(layout);
 
                     dv.paramString = engine.getParamString(xLayout, true);
                     url = init.contextPath + '/api/analytics.json' + dv.paramString;
 
+					// Validate request size
                     if (!validateUrl(url)) {
                         return;
                     }
 
+					// Show load mask
                     util.mask.showMask(dv.viewport.centerRegion);
 
                     Ext.Ajax.request({
@@ -2229,56 +2270,39 @@
                         },
                         success: function(r) {
                             var html,
-                                response = Ext.decode(r.responseText);
-
-                            if (!validateResponse(response)) {
-                                util.mask.hideMask(dv.viewport.centerRegion);
-                                return;
-                            }
-
+								response = dv.api.response.Response(Ext.decode(r.responseText));
+
+							if (!response) {
+								dv.util.mask.hideMask(dv.viewport.centerRegion);
+								return;
+							}
+
+							// Synchronize xLayout
                             xLayout = getSyncronizedXLayout(xLayout, response);
 
                             if (!xLayout) {
-                                util.mask.hideMask(dv.viewport.centerRegion);
+                                dv.util.mask.hideMask(dv.viewport.centerRegion);
                                 return;
                             }
 
+							// Extended response
                             xResponse = getExtendedResponse(response, xLayout);
 
+							// Create chart
                             chart = generator[xLayout.type](xResponse, xLayout);
 
+							// Update viewport
                             dv.viewport.centerRegion.removeAll(true);
                             dv.viewport.centerRegion.add(chart);
-
-                            // After table success
-                            util.mask.hideMask(dv.viewport.centerRegion);
-
-                            if (dv.viewport.downloadButton) {
-                                dv.viewport.downloadButton.enable();
-                            }
-
-                            // Set session storage
-                            if (DV.isSessionStorage) {
-                                engine.setSessionStorage(layout, 'chart');
-                            }
-
-                            dv.chart = chart;
-                            dv.layout = layout;
-                            dv.xLayout = xLayout;
-                            dv.xResponse = xResponse;
-
-                            if (DV.isDebug) {
-                                console.log("xResponse", xResponse);
-                                console.log("xLayout", xLayout);
-                                console.log("layout", layout);
-                            }
+                            
+                            afterLoad(layout, xLayout, xResponse);
                         }
                     });
 
                 }();
             };
 
-            engine.loadChart = function(id, dv) {
+            engine.loadChart = function(id, dv, updateGui, isFavorite) {
                 var url = init.contextPath + '/api/charts/' + id,
                     params = '?viewClass=dimensional&links=false',
                     method = 'GET',
@@ -2298,7 +2322,7 @@
                         dv.favorite.id = layoutConfig.id;
                         dv.favorite.name = layoutConfig.name;
 
-                        dv.viewport.setFavorite(layout);
+						engine.createChart(layout, dv, updateGui, isFavorite);
                     }
                 };
 
@@ -2405,6 +2429,7 @@
             util: util,
             init: init,
             api: api,
+            service: service,
             engine: engine
         });