From 651cbe042fda1c81b7dc3fa255f1be20539372c7 Mon Sep 17 00:00:00 2001
From: Bruno Nocera Zanette <brunonzanette@gmail.com>
Date: Tue, 23 Sep 2014 23:25:09 -0300
Subject: [PATCH] Fix Localizacoes-Ocorrencias dropdown menu options

Fix Localizacoes-Ocorrencias dropdown menu options
---
 .../tags/form/fields/select_multlabel.tagx    | 117 ++++++++++++++++++
 .../WEB-INF/views/localizacoes/create.jspx    |   2 +-
 2 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 src/main/webapp/WEB-INF/tags/form/fields/select_multlabel.tagx

diff --git a/src/main/webapp/WEB-INF/tags/form/fields/select_multlabel.tagx b/src/main/webapp/WEB-INF/tags/form/fields/select_multlabel.tagx
new file mode 100644
index 0000000..5673809
--- /dev/null
+++ b/src/main/webapp/WEB-INF/tags/form/fields/select_multlabel.tagx
@@ -0,0 +1,117 @@
+<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:spring="http://www.springframework.org/tags" xmlns:form="http://www.springframework.org/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
+  <jsp:output omit-xml-declaration="yes" />
+
+  <jsp:directive.attribute name="id" type="java.lang.String" required="true" rtexprvalue="true" description="The identifier for this tag (do not change!)" />
+  <jsp:directive.attribute name="field" type="java.lang.String" required="true" rtexprvalue="true" description="The field exposed from the form backing object" />
+  <jsp:directive.attribute name="path" type="java.lang.String" required="true" rtexprvalue="true" description="The relative path to the referenced resource" />
+  <jsp:directive.attribute name="items" type="java.util.Collection" required="true" rtexprvalue="true" description="The name of the collection displayed in the select box" />
+  <jsp:directive.attribute name="label" type="java.lang.String" required="false" rtexprvalue="true" description="The label used for this field, will default to a message bundle if not supplied" />
+  <jsp:directive.attribute name="itemLabel" type="java.lang.String" required="false" rtexprvalue="true" description="Name of the property mapped to the inner text of the 'option' tag (will override the configured converter)" />
+  <jsp:directive.attribute name="itemValue" type="java.lang.String" required="false" rtexprvalue="true" description="The identifier used as value in the select box (defaults to 'id' for non enum types)" />
+  <jsp:directive.attribute name="required" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicates if this field is required (default false)" />
+  <jsp:directive.attribute name="disabled" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Specify if this field should be enabled" />
+  <jsp:directive.attribute name="multiple" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Specify if the select box should allow multiple selections" />
+  <jsp:directive.attribute name="disableFormBinding" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Set to true to disable Spring form binding" />
+  <jsp:directive.attribute name="render" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if the contents of this tag and all enclosed tags should be rendered (default 'true')" />
+  <jsp:directive.attribute name="z" type="java.lang.String" required="false" description="Used for checking if element has been modified (to recalculate simply provide empty string value)" />
+  
+  <jsp:directive.attribute name="hintValue" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the code for a diferent hint to be displayed." />
+  <jsp:directive.attribute name="comboboxform" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicates if the select can serve as well as an input and it has a warning message for repeated values. (default false)." />
+  <jsp:directive.attribute name="widthcss" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the width of the input. This will overwrite the default from the css file." />
+  
+  <c:if test="${empty render or render}">
+    
+    <c:if test="${empty comboboxform}">
+      <c:set value="false" var="comboboxform" />
+    </c:if>
+    
+    <c:if test="${empty defaultmultiple}">
+      <c:set value="false" var="defaultmultiple" />
+    </c:if>
+    
+    <spring:message code="global_warning" var="warning" htmlEscape="false" />
+
+    <c:if test="${empty disabled}">
+      <c:set value="false" var="disabled" />
+    </c:if>
+
+    <c:if test="${empty label}">
+      <spring:message code="label_${fn:toLowerCase(fn:substringAfter(id,'_'))}" var="label" htmlEscape="false" />
+    </c:if>
+
+    <c:if test="${empty required}">
+      <c:set value="false" var="required" />
+    </c:if>
+
+    <c:if test="${empty multiple}">
+      <c:set value="false" var="multiple" />
+    </c:if>
+    
+    <c:if test="${empty widthcss}">
+      <c:if test="${multiple == false}">
+        <c:set value="400px" var="widthcss" />
+      </c:if>
+      <c:if test="${multiple == true}">
+        <c:set value="438px" var="widthcss" />
+      </c:if>
+    </c:if>
+    
+    <c:set var="sec_field">
+      <spring:escapeBody javaScriptEscape="true" >${field}</spring:escapeBody>
+    </c:set>
+
+    <c:set var="sec_itemLabel">
+      <spring:escapeBody htmlEscape="true" >${itemLabel}</spring:escapeBody>
+    </c:set>
+    
+    <c:choose>
+    	<c:when test="${empty hintValue}">
+    		<spring:message argumentSeparator="," arguments="${label}, " code="field_simple_validation" var="sec_field_validation" htmlEscape="false" />
+    	</c:when>
+    	<c:otherwise>
+    		<spring:message code="${hintValue}" var="sec_field_validation" htmlEscape="false" />
+    	</c:otherwise>
+    </c:choose>
+
+    <div id="_${fn:escapeXml(id)}_id" onmouseover="dijit.Tooltip.defaultPosition=['after']" style="width:calc(220px + ${widthcss})" onclick="forceSelection('_${sec_field}_id', '${multiple}', '${disabled}');">
+      <label for="_${sec_field}_id"><c:out value="${fn:escapeXml(label)}" />:</label>
+        <select id="_${sec_field}_id" name="${sec_field}">
+          <c:forEach items="${items}" var="item">
+            <option value="${item[fn:escapeXml(itemValue)]}">
+              <c:choose>
+                <c:when test="${fn:contains(sec_itemLabel,'#')}">
+                  <c:forEach items="${fn:split(sec_itemLabel,'#')}" var="l" varStatus="loopLabel">
+                    <spring:eval expression="item[l]"/>
+                    <c:if test="${!loopLabel.last}"> : </c:if>
+                  </c:forEach>
+                </c:when>
+                <c:otherwise>
+                  <spring:eval expression="item[sec_itemLabel]"/>
+                </c:otherwise>
+              </c:choose>
+            </option>
+          </c:forEach>
+        </select>
+
+	  <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id', widgetType: 'dijit.form.FilteringSelect', widgetAttrs : {hasDownArrow : true, style:"width:${widthcss}"}})); </script>
+      
+      <script type="text/javascript">
+      	new dijit.Tooltip({
+  			connectId: ["_${fn:escapeXml(id)}_id"],
+  			label: "${sec_field_validation}",
+		});
+      	
+      	function forceSelection(id, multiple, disabled) {
+      		if (multiple == "true") {
+      			if (disabled == "false") {
+					var lisopt = dojo.byId(id).options;
+ 					for (var x = 0 ; x &lt; lisopt.length ; x++)
+     					lisopt[x].selected = true;
+ 				}
+      		}
+      	}
+      </script>
+    </div>
+    <br />
+  </c:if>
+</jsp:root>
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/views/localizacoes/create.jspx b/src/main/webapp/WEB-INF/views/localizacoes/create.jspx
index e9a7f2c..f2375e6 100644
--- a/src/main/webapp/WEB-INF/views/localizacoes/create.jspx
+++ b/src/main/webapp/WEB-INF/views/localizacoes/create.jspx
@@ -3,7 +3,7 @@
     <jsp:directive.page contentType="text/html;charset=UTF-8"/>
     <jsp:output omit-xml-declaration="yes"/>
     <form:create id="fc_br_ufpr_c3sl_estacaojuventude_Localizacao" modelAttribute="localizacao" path="/localizacoes" render="${empty dependencies}" z="roB49ZfPLXumP8eGL4QtNZnO5mw=">
-        <field:select field="ocorrencia" id="c_br_ufpr_c3sl_estacaojuventude_Localizacao_ocorrencia" itemValue="id" items="${ocorrenciamunicipais}" path="/ocorrenciamunicipais" z="user-managed"/>
+        <field:select_multlabel field="ocorrencia" id="c_br_ufpr_c3sl_estacaojuventude_Localizacao_ocorrencia" itemValue="id" items="${ocorrenciamunicipais}" itemLabel="programaVinculado#municipios" path="/ocorrenciamunicipais" z="user-managed"/>
         <field:input field="local" hintValue="hint_local" id="c_br_ufpr_c3sl_estacaojuventude_Localizacao_local" z="user-managed"/>
         <field:input field="logradouro" id="c_br_ufpr_c3sl_estacaojuventude_Localizacao_logradouro" z="R8VF4nPgbPp/k1CvGN5ciGIcG9o="/>
         <field:input field="bairro" id="c_br_ufpr_c3sl_estacaojuventude_Localizacao_bairro" z="K2LLo5fbTkJS/fDtHvy8wH1k9zM="/>
-- 
GitLab