dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31093
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15813: PT dimension/layout gui sync.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 15813 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-06-23 15:22:40 +0200
message:
PT dimension/layout gui sync.
modified:
dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.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-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 2014-06-23 08:00:48 +0000
+++ dhis-2/dhis-web/dhis-web-pivot/src/main/webapp/dhis-web-pivot/app/scripts/app.js 2014-06-23 13:21:30 +0000
@@ -46,11 +46,15 @@
filterStore,
value,
- getData,
getStore,
getStoreKeys,
- getCmpHeight,
- getSetup,
+ addDimension,
+ removeDimension,
+ hasDimension,
+ saveState,
+ resetData,
+ reset,
+ dimensionStoreMap = {},
dimensionPanel,
selectPanel,
@@ -58,25 +62,7 @@
margin = 1,
defaultWidth = 160,
- defaultHeight = 158,
- maxHeight = (ns.app.viewport.getHeight() - 100) / 2;
-
- getData = function(all) {
- var data = [];
-
- if (all) {
- data.push({id: dimConf.data.dimensionName, name: dimConf.data.name});
- }
-
- data.push({id: dimConf.category.dimensionName, name: dimConf.category.name});
-
- if (all) {
- data.push({id: dimConf.period.dimensionName, name: dimConf.period.name});
- data.push({id: dimConf.organisationUnit.dimensionName, name: dimConf.organisationUnit.name});
- }
-
- return data.concat(Ext.clone(ns.core.init.dimensions));
- };
+ defaultHeight = 200;
getStore = function(data) {
var config = {};
@@ -113,45 +99,22 @@
return keys;
};
- dimensionStore = getStore(getData());
- dimensionStore.reset = function(all) {
- dimensionStore.removeAll();
- dimensionStore.add(getData(all));
- };
- ns.app.stores.dimension = dimensionStore;
+ dimensionStore = getStore();
+ ns.app.stores.dimension = dimensionStore;
+
+ colStore = getStore();
+ ns.app.stores.col = colStore;
rowStore = getStore();
- ns.app.stores.row = rowStore;
- rowStore.add({id: dimConf.period.dimensionName, name: dimConf.period.name});
-
- colStore = getStore();
- ns.app.stores.col = colStore;
- colStore.add({id: dimConf.data.dimensionName, name: dimConf.data.name});
-
- filterStore = getStore();
- ns.app.stores.filter = filterStore;
- filterStore.add({id: dimConf.organisationUnit.dimensionName, name: dimConf.organisationUnit.name});
-
- getCmpHeight = function() {
- var size = dimensionStore.totalCount,
- expansion = 10,
- height = defaultHeight,
- diff;
-
- if (size > 10) {
- diff = size - 10;
- height += (diff * expansion);
- }
-
- height = height > maxHeight ? maxHeight : height;
-
- return height;
- };
+ ns.app.stores.row = rowStore;
+
+ filterStore = getStore();
+ ns.app.stores.filter = filterStore;
dimension = Ext.create('Ext.ux.form.MultiSelect', {
cls: 'ns-toolbar-multiselect-leftright',
width: defaultWidth,
- height: (getCmpHeight() * 2) + margin,
+ height: (defaultHeight * 2) + margin,
style: 'margin-right:' + margin + 'px; margin-bottom:0px',
valueField: 'id',
displayField: 'name',
@@ -178,10 +141,44 @@
}
});
+ col = Ext.create('Ext.ux.form.MultiSelect', {
+ cls: 'ns-toolbar-multiselect-leftright',
+ width: defaultWidth,
+ height: defaultHeight,
+ style: 'margin-bottom:' + margin + 'px',
+ valueField: 'id',
+ displayField: 'name',
+ dragGroup: 'layoutDD',
+ dropGroup: 'layoutDD',
+ store: colStore,
+ tbar: {
+ height: 25,
+ items: {
+ xtype: 'label',
+ text: NS.i18n.column,
+ cls: 'ns-toolbar-multiselect-leftright-label'
+ }
+ },
+ listeners: {
+ afterrender: function(ms) {
+ ms.boundList.on('itemdblclick', function(view, record) {
+ ms.store.remove(record);
+ dimensionStore.add(record);
+ });
+
+ ms.store.on('add', function() {
+ Ext.defer( function() {
+ ms.boundList.getSelectionModel().deselectAll();
+ }, 10);
+ });
+ }
+ }
+ });
+
row = Ext.create('Ext.ux.form.MultiSelect', {
cls: 'ns-toolbar-multiselect-leftright',
width: defaultWidth,
- height: getCmpHeight(),
+ height: defaultHeight,
style: 'margin-bottom:0px',
valueField: 'id',
displayField: 'name',
@@ -212,44 +209,10 @@
}
});
- col = Ext.create('Ext.ux.form.MultiSelect', {
- cls: 'ns-toolbar-multiselect-leftright',
- width: defaultWidth,
- height: getCmpHeight(),
- style: 'margin-bottom:' + margin + 'px',
- valueField: 'id',
- displayField: 'name',
- dragGroup: 'layoutDD',
- dropGroup: 'layoutDD',
- store: colStore,
- tbar: {
- height: 25,
- items: {
- xtype: 'label',
- text: NS.i18n.column,
- cls: 'ns-toolbar-multiselect-leftright-label'
- }
- },
- listeners: {
- afterrender: function(ms) {
- ms.boundList.on('itemdblclick', function(view, record) {
- ms.store.remove(record);
- dimensionStore.add(record);
- });
-
- ms.store.on('add', function() {
- Ext.defer( function() {
- ms.boundList.getSelectionModel().deselectAll();
- }, 10);
- });
- }
- }
- });
-
filter = Ext.create('Ext.ux.form.MultiSelect', {
cls: 'ns-toolbar-multiselect-leftright',
width: defaultWidth,
- height: getCmpHeight(),
+ height: defaultHeight,
style: 'margin-right:' + margin + 'px; margin-bottom:' + margin + 'px',
valueField: 'id',
displayField: 'name',
@@ -301,6 +264,84 @@
]
});
+ addDimension = function(record, store) {
+ var store = dimensionStoreMap[record.id] || store || colStore;
+
+ if (!hasDimension(record.id)) {
+ store.add(record);
+ }
+ };
+
+ removeDimension = function(dataElementId) {
+ var stores = [colStore, rowStore, filterStore];
+
+ for (var i = 0, store, index; i < stores.length; i++) {
+ store = stores[i];
+ index = store.findExact('id', dataElementId);
+
+ if (index != -1) {
+ store.remove(store.getAt(index));
+ dimensionStoreMap[dataElementId] = store;
+ }
+ }
+ };
+
+ hasDimension = function(id) {
+ var stores = [colStore, rowStore, filterStore];
+
+ for (var i = 0, store, index; i < stores.length; i++) {
+ store = stores[i];
+ index = store.findExact('id', id);
+
+ if (index != -1) {
+ return true;
+ }
+ }
+
+ return false;
+ };
+
+ saveState = function(map) {
+ map = map || dimensionStoreMap;
+
+ colStore.each(function(record) {
+ map[record.data.id] = colStore;
+ });
+
+ rowStore.each(function(record) {
+ map[record.data.id] = rowStore;
+ });
+
+ filterStore.each(function(record) {
+ map[record.data.id] = filterStore;
+ });
+
+ return map;
+ };
+
+ resetData = function() {
+ var map = saveState({}),
+ keys = ['dx', 'ou', 'pe', 'dates'];
+
+ for (var key in map) {
+ if (map.hasOwnProperty(key) && !Ext.Array.contains(keys, key)) {
+ removeDimension(key);
+ }
+ }
+ };
+
+ reset = function(isAll) {
+ colStore.removeAll();
+ rowStore.removeAll();
+ filterStore.removeAll();
+
+ if (!isAll) {
+ colStore.add({id: dimConf.data.dimensionName, name: dimConf.data.name});
+ rowStore.add({id: dimConf.period.dimensionName, name: dimConf.period.name});
+ filterStore.add({id: dimConf.organisationUnit.dimensionName, name: dimConf.organisationUnit.name});
+ }
+ };
+
getSetup = function() {
return {
col: getStoreKeys(colStore),
@@ -321,6 +362,9 @@
rowStore: rowStore,
colStore: colStore,
filterStore: filterStore,
+ addDimension: addDimension,
+ removeDimension: removeDimension,
+ hasDimension: hasDimension,
hideOnBlur: true,
items: {
layout: 'column',
@@ -371,7 +415,10 @@
ns.core.web.window.addHideOnBlurHandler(w);
}
}
- }
+ },
+ render: function() {
+ reset();
+ }
}
});
@@ -4728,7 +4775,8 @@
// dimensions
getDimensionPanel = function(dimension, iconCls) {
- var availableStore,
+ var onSelect,
+ availableStore,
selectedStore,
available,
selected,
@@ -4737,6 +4785,17 @@
createPanel,
getPanels;
+ onSelect = function() {
+ var win = ns.app.layoutWindow;
+console.log(selectedStore.getRange().length, win.hasDimension(dimension.id));
+ if (selectedStore.getRange().length) {
+ win.addDimension({id: dimension.id, name: dimension.name});
+ }
+ else if (!selectedStore.getRange().length && win.hasDimension(dimension.id)) {
+ win.removeDimension(dimension.id);
+ }
+ };
+
availableStore = Ext.create('Ext.data.Store', {
fields: ['id', 'name'],
lastPage: null,
@@ -4806,7 +4865,15 @@
selectedStore = Ext.create('Ext.data.Store', {
fields: ['id', 'name'],
- data: []
+ data: [],
+ listeners: {
+ add: function() {
+ onSelect();
+ },
+ remove: function() {
+ onSelect();
+ }
+ }
});
available = Ext.create('Ext.ux.form.MultiSelect', {
@@ -5700,7 +5767,7 @@
}
// Layout
- ns.app.stores.dimension.reset(true);
+ ns.app.stores.dimension.removeAll();
ns.app.stores.col.removeAll();
ns.app.stores.row.removeAll();
ns.app.stores.filter.removeAll();
@@ -5829,10 +5896,11 @@
render: function() {
ns.app.viewport = this;
- ns.app.layoutWindow = LayoutWindow();
- ns.app.layoutWindow.hide();
- ns.app.optionsWindow = OptionsWindow();
- ns.app.optionsWindow.hide();
+ ns.app.layoutWindow = LayoutWindow();
+ ns.app.layoutWindow.hide();
+
+ ns.app.optionsWindow = OptionsWindow();
+ ns.app.optionsWindow.hide();
},
afterrender: function() {