dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11542
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3314: Implemented method SelectionTreeManager.setCurrentUserOrganisationUnitAsSelected
------------------------------------------------------------
revno: 3314
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-04-07 14:42:11 +0200
message:
Implemented method SelectionTreeManager.setCurrentUserOrganisationUnitAsSelected
modified:
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/SelectionTreeManager.java
dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml
labs/dhis-web-light/src/main/java/org/hisp/dhis/light/action/GetReportParamsAction.java
labs/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml
labs/dhis-web-light/src/main/webapp/dhis-web-light/inputReportParamsForm.vm
labs/dhis-web-light/src/main/webapp/dhis-web-light/javascript/dhis-web-light.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/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java 2011-02-22 23:17:50 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java 2011-04-07 12:42:11 +0000
@@ -35,6 +35,8 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
import com.opensymphony.xwork2.ActionContext;
@@ -60,6 +62,13 @@
{
this.organisationUnitService = organisationUnitService;
}
+
+ private CurrentUserService currentUserService;
+
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
// -------------------------------------------------------------------------
// SelectionTreeManager implementation
@@ -199,6 +208,19 @@
setSelectedOrganisationUnits( set );
}
+ public boolean setCurrentUserOrganisationUnitAsSelected()
+ {
+ User user = currentUserService.getCurrentUser();
+
+ if ( user != null && user.getOrganisationUnit() != null )
+ {
+ setSelectedOrganisationUnit( user.getOrganisationUnit() );
+ return true;
+ }
+
+ return false;
+ }
+
// -------------------------------------------------------------------------
// Session methods
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/SelectionTreeManager.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/SelectionTreeManager.java 2010-08-31 11:40:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/SelectionTreeManager.java 2011-04-07 12:42:11 +0000
@@ -148,4 +148,14 @@
* if the argument is null
*/
void setSelectedOrganisationUnit( OrganisationUnit unit );
+
+ /**
+ * Sets the current user's organisation unit as selected. If the user is
+ * associated with more than one organisation unit, it is undefined which one
+ * is selected.
+ *
+ * @return true if the operation was successful, ie. if a current users exists
+ * and if the current user is associated with one or more organisation units.
+ */
+ boolean setCurrentUserOrganisationUnitAsSelected();
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml 2011-04-06 11:39:06 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml 2011-04-07 12:42:11 +0000
@@ -180,13 +180,11 @@
</property>
</bean>
-
<!-- Organisation Unit Selection Tree -->
<bean id="org.hisp.dhis.oust.manager.SelectionTreeManager" class="org.hisp.dhis.oust.manager.DefaultSelectionTreeManager">
- <property name="organisationUnitService">
- <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService" />
- </property>
+ <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+ <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService"/>
</bean>
<bean id="org.hisp.dhis.oust.action.ExpandSubtreeAction" class="org.hisp.dhis.oust.action.ExpandSubtreeAction" scope="prototype">
=== modified file 'labs/dhis-web-light/src/main/java/org/hisp/dhis/light/action/GetReportParamsAction.java'
--- labs/dhis-web-light/src/main/java/org/hisp/dhis/light/action/GetReportParamsAction.java 2011-04-07 11:55:24 +0000
+++ labs/dhis-web-light/src/main/java/org/hisp/dhis/light/action/GetReportParamsAction.java 2011-04-07 12:42:11 +0000
@@ -32,6 +32,7 @@
import java.util.TreeMap;
import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
import org.hisp.dhis.period.MonthlyPeriodType;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
@@ -60,6 +61,13 @@
{
this.reportTableService = reportTableService;
}
+
+ private SelectionTreeManager selectionTreeManager;
+
+ public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
+ {
+ this.selectionTreeManager = selectionTreeManager;
+ }
private I18nFormat format;
@@ -115,6 +123,8 @@
public String execute()
{
+ selectionTreeManager.setCurrentUserOrganisationUnitAsSelected();
+
if ( id != null )
{
ReportTable reportTable = reportTableService.getReportTable( id, ReportTableService.MODE_REPORT_TABLE );
=== modified file 'labs/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml'
--- labs/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2011-04-07 11:55:24 +0000
+++ labs/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2011-04-07 12:42:11 +0000
@@ -24,6 +24,7 @@
<bean id="org.hisp.dhis.light.action.GetReportParamsAction"
class="org.hisp.dhis.light.action.GetReportParamsAction" scope="prototype">
<property name="reportTableService" ref="org.hisp.dhis.reporttable.ReportTableService"/>
+ <property name="selectionTreeManager" ref="org.hisp.dhis.oust.manager.SelectionTreeManager"/>
</bean>
</beans>
\ No newline at end of file
=== modified file 'labs/dhis-web-light/src/main/webapp/dhis-web-light/inputReportParamsForm.vm'
--- labs/dhis-web-light/src/main/webapp/dhis-web-light/inputReportParamsForm.vm 2011-04-07 11:55:24 +0000
+++ labs/dhis-web-light/src/main/webapp/dhis-web-light/inputReportParamsForm.vm 2011-04-07 12:42:11 +0000
@@ -40,8 +40,6 @@
<div class="pageDiv" id="selectionTree" style="width:300px; height:200px"></div>
<script type="text/javascript">
selectionTreeSelection.setMultipleSelectionAllowed( false );
- selectionTreeSelection.setListenerFunction( paramOrganisationUnitSet );
- selectionTree.clearSelectedOrganisationUnits();
selectionTree.buildSelectionTree();
</script>
=== modified file 'labs/dhis-web-light/src/main/webapp/dhis-web-light/javascript/dhis-web-light.js'
--- labs/dhis-web-light/src/main/webapp/dhis-web-light/javascript/dhis-web-light.js 2011-04-07 11:55:24 +0000
+++ labs/dhis-web-light/src/main/webapp/dhis-web-light/javascript/dhis-web-light.js 2011-04-07 12:42:11 +0000
@@ -8,16 +8,9 @@
window.location.href = "getReportParams.action?id=" + id;
}
-var paramOrganisationUnit = null;
-
-function paramOrganisationUnitSet( id )
-{
- paramOrganisationUnit = id;
-}
-
function validationError()
{
- if ( $( "#selectionTree" ).length && paramOrganisationUnit == null )
+ if ( $( "#selectionTree" ).length && selectionTreeSelection.getSelected().length == 0 )
{
setMessage( i18n_please_select_unit );
return true;
@@ -40,9 +33,9 @@
url += "&reportingPeriod=" + $( "#reportingPeriod" ).val();
}
- if ( paramOrganisationUnit != null )
+ if ( $( "#selectionTree" ).length )
{
- url += "&organisationUnitId=" + paramOrganisationUnit;
+ url += "&organisationUnitId=" + selectionTreeSelection.getSelected()[0];
}
window.location.href = "getReport.action?" + url;