Author: bleny Date: 2011-01-21 11:31:20 +0000 (Fri, 21 Jan 2011) New Revision: 932 Log: fix AJAX bugs Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java trunk/wao-ui/src/main/webapp/ContactForm.tml trunk/wao-ui/src/main/webapp/SampleRowForm.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2011-01-20 14:54:07 UTC (rev 931) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2011-01-21 11:31:20 UTC (rev 932) @@ -77,6 +77,8 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.DateUtil; +import org.nuiton.util.DateUtils; import org.nuiton.util.StringUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,6 +92,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -209,8 +212,8 @@ } @Override - public Contact executeGetNewContact(WaoUser user, SampleRow row, Boat boat) throws WaoBusinessException { - + protected Contact executeGetNewContact(TopiaContext transaction, WaoUser user, + SampleRow row, Boat boat) throws Exception { ObsProgram obsProgram = row.getObsProgram(); if (obsProgram.equals(ObsProgram.OBSMER)) { @@ -228,6 +231,27 @@ newContact.setMainObserver(user); newContact.setSampleRow(row); newContact.setContactState(ContactState.CONTACT_START); + + if (newContact.getObsProgram() == ObsProgram.OBSVENTE) { + // try to pre-fill some field for user-experience + ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); + + // let's try to find a similar contact + Map<String, Object> properties = new HashMap<String, Object>(); + properties.put(Contact.PROPERTY_OBS_PROGRAM_ORDINAL, ObsProgram.OBSVENTE.ordinal()); + properties.put(Contact.PROPERTY_SAMPLE_ROW, row); + properties.put(Contact.PROPERTY_MAIN_OBSERVER, user); + + Contact similarContact = dao.findByProperties(properties); + if (similarContact != null) { + newContact.setObservationBeginDate(similarContact.getObservationBeginDate()); + newContact.setObservationEndDate(similarContact.getObservationEndDate()); + newContact.setTerrestrialLocation(similarContact.getTerrestrialLocation()); + newContact.clearSecondaryObservers(); + newContact.addAllSecondaryObservers(similarContact.getSecondaryObservers()); + } + } + saveContact(newContact, Boolean.FALSE); return newContact; } Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2011-01-20 14:54:07 UTC (rev 931) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2011-01-21 11:31:20 UTC (rev 932) @@ -53,6 +53,7 @@ import fr.ifremer.wao.ui.data.WaoPropertyChangeListener; import fr.ifremer.wao.ui.services.WaoManager; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.iterators.ArrayListIterator; import org.apache.commons.lang.StringUtils; import org.apache.tapestry5.ComponentResources; import org.apache.tapestry5.EventContext; @@ -341,7 +342,11 @@ if (log.isDebugEnabled()) { log.debug("Remove fishingZone at position : " + index); } - getFishingZones().remove(index); + // getFishingZones().remove(index); throw a ConcurrentModificationException, + // a copy to prevent it : + List<FishingZone> fishingZones = new ArrayList<FishingZone>(getSampleRow().getFishingZone()); + fishingZones.remove(index); + getSampleRow().setFishingZone(fishingZones); edited = true; } @@ -526,9 +531,15 @@ @Log void onSelectedFromDeleteMonth(int index) throws WaoException { - SampleMonth month = getSampleMonths().remove(index); - month.removePropertyChangeListener( + // SampleMonth month = getSampleMonths().remove(index); + List<SampleMonth> sampleMonths = new ArrayList<SampleMonth>(getSampleMonths()); + SampleMonth removedMonth = sampleMonths.get(index); + sampleMonths.remove(removedMonth); + removedMonth.removePropertyChangeListener( SampleMonth.PROPERTY_EXPECTED_TIDES_VALUE, propertyChange); +// month.removePropertyChangeListener( +// SampleMonth.PROPERTY_EXPECTED_TIDES_VALUE, propertyChange); + this.sampleMonths = sampleMonths; edited = true; } @@ -572,7 +583,7 @@ for (SampleMonth month : sampleRow.getSampleMonth()) { month.addPropertyChangeListener( SampleMonth.PROPERTY_EXPECTED_TIDES_VALUE, propertyChange); - } + } } else { sampleRow = serviceSampling.getNewSampleRow(); sampleRow.setObsProgram(user.getProfile().getObsProgram()); Modified: trunk/wao-ui/src/main/webapp/ContactForm.tml =================================================================== --- trunk/wao-ui/src/main/webapp/ContactForm.tml 2011-01-20 14:54:07 UTC (rev 931) +++ trunk/wao-ui/src/main/webapp/ContactForm.tml 2011-01-21 11:31:20 UTC (rev 932) @@ -7,7 +7,7 @@ </h1> <div class="mtop30" /> - <t:zone t:id="globalZone" t:update="show"> + <t:zone t:id="globalZone" id="globalZone" t:update="show"> <form t:type="form" t:id="contactForm" t:zone="globalZone"> <t:errors /> Modified: trunk/wao-ui/src/main/webapp/SampleRowForm.tml =================================================================== --- trunk/wao-ui/src/main/webapp/SampleRowForm.tml 2011-01-20 14:54:07 UTC (rev 931) +++ trunk/wao-ui/src/main/webapp/SampleRowForm.tml 2011-01-21 11:31:20 UTC (rev 932) @@ -93,8 +93,7 @@ <div class="clearfix fishingzone-row" t:type="loop" volatile="true" t:source="fishingZones" t:value="fishingZone" t:index="indexFishingZone"> <div class="fleft width50"> - <input t:type="submitContext" class="ico remove" t:context="indexFishingZone" - t:id="removeFishingZone" t:defer="false" value="${message:wao.ui.action.remove}" /> + <input t:type="submit" class="ico remove" t:context="indexFishingZone" t:id="removeFishingZone" t:defer="false" value="${message:wao.ui.action.remove}" /> </div> <div class="fleft"> ${fishingZone.code} @@ -154,8 +153,8 @@ <td t:type="loop" class="acenter" volatile="true" t:source="sampleMonths" t:value="sampleMonth" t:index="monthIndex"> <t:output value="sampleMonth.periodDate" format="dateFormat" /> <t:unless t:test="sampleMonth.realTidesValue"> - <input t:type="submitContext" class="ico16px suppr" t:defer="false" t:id="deleteMonth" value="${message:wao.ui.action.delete}" t:context="monthIndex" - title="${message:wao.ui.action.delete}"/> + <!--input t:type="submitContext" class="ico16px suppr" t:defer="false" t:id="deleteMonth" value="${message:wao.ui.action.delete}" t:context="monthIndex" /--> + <input t:type="submit" class="ico16px suppr" t:defer="false" t:id="deleteMonth" value="${message:wao.ui.action.delete}" t:context="monthIndex" /> <p:else> <img src="${asset:context:}/img/suppr-unavailable-16px.png" alt="${message:wao.ui.unavailableOperation}" /> </p:else>