[Suiviobsmer-commits] r1004 - in trunk: wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/resources/i18n wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/java/fr/ifremer/wao/ui/services wao-ui/src/main/resources/i18n wao-ui/src/main/webapp
Author: bleny Date: 2011-02-11 15:13:05 +0000 (Fri, 11 Feb 2011) New Revision: 1004 Log: add form to edit contact state motives Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties trunk/wao-ui/src/main/webapp/Administration.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2011-02-10 14:20:14 UTC (rev 1003) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2011-02-11 15:13:05 UTC (rev 1004) @@ -385,18 +385,25 @@ return result; } + /** + * + * @param contactState if null, return motifs for all contact states + */ @Override protected List<ContactStateMotif> executeGetAllContactStateMotifs(TopiaContext transaction, ContactState contactState) throws Exception { ContactStateMotifDAO contactStateMotifDAO = WaoDAOHelper.getContactStateMotifDAO(transaction); - ContactState substituteState = ContactState.getSubstituteForMotif(contactState); - - List<ContactStateMotif> notTranslatedResult = contactStateMotifDAO.findAllByContactStateOrdinal(substituteState.ordinal()); - + List<ContactStateMotif> notTranslatedResult; + if (contactState == null) { + notTranslatedResult = contactStateMotifDAO.findAll(); + } else { + ContactState substituteState = ContactState.getSubstituteForMotif(contactState); + notTranslatedResult = contactStateMotifDAO.findAllByContactStateOrdinal(substituteState.ordinal()); + } List<ContactStateMotif> result = translateEntities(transaction, notTranslatedResult); if (log.isDebugEnabled()) { - log.debug(result.size() + " motifs found for state " + contactState.toString()); + log.debug(result.size() + " motifs found for state " + contactState); } return result; @@ -406,9 +413,14 @@ protected void executeUpdateAllContactStatesMotifs(TopiaContext transaction, List<ContactStateMotif> motifs) throws Exception { ContactStateMotifDAO contactStateMotifDAO = WaoDAOHelper.getContactStateMotifDAO(transaction); for (ContactStateMotif motif : motifs) { - contactStateMotifDAO.update(motif); + if (motif.getTopiaId() == null) { + contactStateMotifDAO.create(motif); + } else { + contactStateMotifDAO.update(motif); + } } updateTranslations(transaction, motifs); + transaction.commitTransaction(); } @Override @@ -456,6 +468,13 @@ } } + + /** For a given list of entities, make all known translations available + * in the entity. + * + * This method will look in database to find all translations for a given + * entity and push them in the object. + */ protected <E extends TranslatableEntity> List<E> translateEntities(TopiaContext transaction, List<E> entities) throws TopiaException { List<E> result = new ArrayList<E>(entities); TranslationDAO translationDAO = WaoDAOHelper.getTranslationDAO(transaction); @@ -474,6 +493,9 @@ TranslationDAO translationDAO = WaoDAOHelper.getTranslationDAO(transaction); + int translationAdded = 0; + int translationUpdated = 0; + for (TranslatableEntity entity : entities) { Map<Locale, String> translations = entity.getTranslations(); String id = entity.getTopiaId(); @@ -490,11 +512,22 @@ translationDAO.create(Translation.PROPERTY_ID, id, Translation.PROPERTY_LOCALE, locale.toString(), Translation.PROPERTY_TEXT, value); + translationAdded += 1; } else { + if (log.isDebugEnabled()) { + log.debug("will change translation from '" + translationEntity.getText() + + "' to '" + value + "'"); + } translationEntity.setText(value); translationDAO.update(translationEntity); + translationUpdated += 1; } } } + + if (log.isDebugEnabled()) { + log.debug(translationAdded + " translation added, " + + translationUpdated + " translations updated"); + } } } Modified: trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties 2011-02-10 14:20:14 UTC (rev 1003) +++ trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties 2011-02-11 15:13:05 UTC (rev 1004) @@ -55,6 +55,7 @@ fr.ifremer.wao.entity.FishingGearDCF.GND=Driftnets fr.ifremer.wao.entity.FishingGearDCF.GNF=Fixed gillnets fr.ifremer.wao.entity.FishingGearDCF.GNS=Set gillnets (anchored) +fr.ifremer.wao.entity.FishingGearDCF.GT=Gillnetters fr.ifremer.wao.entity.FishingGearDCF.GTN=Combined gillnets-trammel nets fr.ifremer.wao.entity.FishingGearDCF.GTR=Trammel nets fr.ifremer.wao.entity.FishingGearDCF.HAR=Harpoons Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2011-02-10 14:20:14 UTC (rev 1003) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2011-02-11 15:13:05 UTC (rev 1004) @@ -29,11 +29,14 @@ import fr.ifremer.wao.WaoException; import fr.ifremer.wao.WaoProperty; import fr.ifremer.wao.bean.ConnectedUser; +import fr.ifremer.wao.bean.ContactState; import fr.ifremer.wao.bean.GlobalIndicatorValue; import fr.ifremer.wao.bean.GlobalSynthesisParameters; import fr.ifremer.wao.bean.UserRole; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.CompanyImpl; +import fr.ifremer.wao.entity.ContactStateMotif; +import fr.ifremer.wao.entity.ContactStateMotifImpl; import fr.ifremer.wao.entity.Indicator; import fr.ifremer.wao.entity.IndicatorLevel; import fr.ifremer.wao.entity.UserProfile; @@ -82,6 +85,7 @@ import java.io.FileNotFoundException; import java.io.InputStream; +import java.util.ArrayList; import java.util.List; /** @@ -742,13 +746,60 @@ return GlobalIndicatorValue.valueOf(indicatorLevel.getLevel()); } + /************************ Contact states motifs **************************/ + + @InjectComponent + private Form contactStateMotifsForm; + + @Property + @Persist + private String contactStateMotifId; + + @Property + private String translation; + + private GenericSelectModel<ContactStateMotif> contactStateMotifSelectModel; + + @Log + public GenericSelectModel<ContactStateMotif> getContactStateMotifSelectModel() { + if (contactStateMotifSelectModel == null) { + List<ContactStateMotif> motifs = serviceReferential.getAllContactStateMotifs(null); + if (motifs.size() != 0) { + contactStateMotifSelectModel = new GenericSelectModel<ContactStateMotif>( + motifs, ContactStateMotif.class, "translation", ContactStateMotif.TOPIA_ID, propertyAccess); + } + } + return contactStateMotifSelectModel; + } +// +// @Log +// public Object onValueChangedFromContactStateMotif(String contactStateMotifId) { +// this.contactStateMotifId = contactStateMotifId; +// ContactStateMotif motif = getContactStateMotifSelectModel().findObject(contactStateMotifId); +// translation = motif.getTranslation(); +// return contactStateMotifsForm; +// } + + @Log + public Form onSuccessFromContactStateMotifsForm() { + ContactStateMotif motif; + if (StringUtils.isEmpty(contactStateMotifId)) { + motif = new ContactStateMotifImpl(ContactState.CONTACT_REFUSED); + } else { + motif = getContactStateMotifSelectModel().findObject(contactStateMotifId); + } + motif.setTranslation(manager.getCurrentLocale(), translation); + List<ContactStateMotif> motifs = new ArrayList<ContactStateMotif>(); + motifs.add(motif); + serviceReferential.updateAllContactStatesMotifs(motifs); + // refresh + translation = null; + contactStateMotifSelectModel = null; + return contactStateMotifsForm; + } + /*************************************** I18N ****************************/ @Inject private Messages messages; - - public String getLabelForEnum(Enum value) { - return messages.get(value.getDeclaringClass().getSimpleName() + "." + value.name()); - } - } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2011-02-10 14:20:14 UTC (rev 1003) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2011-02-11 15:13:05 UTC (rev 1004) @@ -289,7 +289,7 @@ } public void changeLocale() { - Locale currentLocale = localeService.get(); + Locale currentLocale = getCurrentLocale(); Locale newLocale; if (Locale.ENGLISH.equals(currentLocale)) { newLocale = Locale.FRENCH; @@ -299,4 +299,12 @@ localeService.set(newLocale); context.setLocale(newLocale); } + + public Locale getCurrentLocale() { + Locale currentLocale = localeService.get(); + if (currentLocale == null) { + currentLocale = Locale.FRENCH; + } + return currentLocale; + } } Modified: trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties =================================================================== --- trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties 2011-02-10 14:20:14 UTC (rev 1003) +++ trunk/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties 2011-02-11 15:13:05 UTC (rev 1004) @@ -79,6 +79,7 @@ wao.ui.field.Contact.completeSampling=Complete sampling wao.ui.field.Contact.contactState=Contact state wao.ui.field.Contact.contactStateMotif=Refusal motif +wao.ui.field.Contact.contactStateMotifs=Refusal motives wao.ui.field.Contact.creationDate=Contact creation date wao.ui.field.Contact.dataInputDate=Allegro data input wao.ui.field.Contact.dataReliability=Data reliability Modified: trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties =================================================================== --- trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties 2011-02-10 14:20:14 UTC (rev 1003) +++ trunk/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties 2011-02-11 15:13:05 UTC (rev 1004) @@ -79,6 +79,7 @@ wao.ui.field.Contact.completeSampling=\u00C9chantillonnage complet wao.ui.field.Contact.contactState=\u00C9tat du contact wao.ui.field.Contact.contactStateMotif=Motif du refus +wao.ui.field.Contact.contactStateMotifs=Motifs de refus wao.ui.field.Contact.creationDate=Date de cr\u00E9ation du contact wao.ui.field.Contact.dataInputDate=Saisie des donn\u00E9es dans Allegro wao.ui.field.Contact.dataReliability=Qualit\u00E9 des donn\u00E9es Modified: trunk/wao-ui/src/main/webapp/Administration.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Administration.tml 2011-02-10 14:20:14 UTC (rev 1003) +++ trunk/wao-ui/src/main/webapp/Administration.tml 2011-02-11 15:13:05 UTC (rev 1004) @@ -208,7 +208,7 @@ <table class="indicatorLevels"> <tr> <td t:type="loop" t:source="globalSynthesisParameters.globalIndicator.indicatorLevel" t:value="indicatorLevel" t:volatile="true"> - ${getLabelForEnum(globalIndicatorValue)} + ${globalIndicatorValue} </td> </tr> <tr> @@ -259,4 +259,21 @@ </t:if> + <t:if t:test="currentUser.admin"> + <t:if t:test="currentUser.obsMer"> + <h2>${message:wao.ui.field.Contact.contactStateMotifs}</h2> + + <t:zone t:id="contactStateMotifsFormZone" t:update="show" class="acenter"> + <form t:type="form" t:zone="contactStateMotifsFormZone" t:id="contactStateMotifsForm"> + <input t:type="select" + t:id="contactStateMotif" + t:value="contactStateMotifId" + t:model="contactStateMotifSelectModel" /> + <input t:type="textfield" t:value="translation" /> + <input t:type="submit" class="ico save" value="${message:wao.ui.action.save}" /> + </form> + </t:zone> + </t:if> + </t:if> + </t:layout>
participants (1)
-
bleny@users.labs.libre-entreprise.org