Author: bleny Date: 2010-12-20 16:35:01 +0000 (Mon, 20 Dec 2010) New Revision: 839 Log: move contact edition form to a separated page ; useless code remains until validation by user Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactForm.java trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/pages/ContactForm.properties trunk/wao-ui/src/main/webapp/ContactForm.tml trunk/wao-ui/src/main/webapp/js/contactForm.js Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ConnectedUserImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ContactState.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/UserProfileImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-ui/src/main/webapp/Contacts.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ConnectedUserImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ConnectedUserImpl.java 2010-12-15 18:16:56 UTC (rev 838) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ConnectedUserImpl.java 2010-12-20 16:35:01 UTC (rev 839) @@ -43,6 +43,11 @@ } @Override + public boolean isCoordinatorOrObserver() { + return getProfile().isCoordinatorOrObserver(); + } + + @Override public boolean isObserver() { return getProfile().isObserver(); } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ContactState.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ContactState.java 2010-12-15 18:16:56 UTC (rev 838) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ContactState.java 2010-12-20 16:35:01 UTC (rev 839) @@ -122,4 +122,8 @@ return results; } + public String getLabel() { + return libelle; + } + } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/UserProfileImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/UserProfileImpl.java 2010-12-15 18:16:56 UTC (rev 838) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/UserProfileImpl.java 2010-12-20 16:35:01 UTC (rev 839) @@ -44,6 +44,11 @@ } @Override + public boolean isCoordinatorOrObserver() { + return isCoordinator() || isObserver(); + } + + @Override public boolean isObserver() { return getUserRole() == UserRole.OBSERVER; } 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 2010-12-15 18:16:56 UTC (rev 838) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-12-20 16:35:01 UTC (rev 839) @@ -124,6 +124,19 @@ } @Override + protected Contact executeGetContact(TopiaContext transaction, String contactId) throws Exception { + ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); + Contact contact = dao.findByTopiaId(contactId); + + // force load + contact.getMainObserver(); + contact.sizeSecondaryObservers(); + contact.getSampleRow().sizeSampleMonth(); + contact.getBoat().getName(); + return contact; + } + + @Override public Map<String, Contact> executeGetContacts(TopiaContext transaction, ContactFilter filter) throws TopiaException { Modified: trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-12-15 18:16:56 UTC (rev 838) +++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-12-20 16:35:01 UTC (rev 839) @@ -144,7 +144,7 @@ wao.error.serviceReferential.getFishingZones=Impossible de charger la liste des secteurs de p\u00EAche wao.error.serviceReferential.getProfessions=Impossible de charger la liste des m\u00E9tiers wao.error.serviceReferential.getSectors=Impossible de charger la liste des zones de p\u00EAche -wao.error.serviceReferential.importDCFcodes=Impossible de créer le référentiel des codes DCF +wao.error.serviceReferential.importDCFcodes=Impossible de cr\u00E9er le r\u00E9f\u00E9rentiel des codes DCF wao.error.serviceReferential.importFishingZoneCsv=Probl\u00E8me d'import du fichier CSV. V\u00E9rifiez l'en-t\u00EAte du fichier \: [ PECHE_DIVISION,PECHE_ZONE,PECHE_FACADE ]. Voir documentation pour plus de d\u00E9tails. wao.error.serviceSampling.createSampleRowLog= wao.error.serviceSampling.createUpdateSampleRow=Impossible de sauvegarder la ligne d'\u00E9chantillon Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactForm.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactForm.java (rev 0) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactForm.java 2010-12-20 16:35:01 UTC (rev 839) @@ -0,0 +1,486 @@ +package fr.ifremer.wao.ui.pages; + +import fr.ifremer.wao.WaoBusinessException; +import fr.ifremer.wao.WaoException; +import fr.ifremer.wao.bean.ConnectedUser; +import fr.ifremer.wao.bean.ContactState; +import fr.ifremer.wao.bean.DataReliability; +import fr.ifremer.wao.bean.UserRole; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.WaoUser; +import fr.ifremer.wao.service.ServiceContact; +import fr.ifremer.wao.service.ServiceUser; +import fr.ifremer.wao.ui.components.Layout; +import fr.ifremer.wao.ui.data.GenericSelectModel; +import fr.ifremer.wao.ui.data.RequiresAuthentication; +import fr.ifremer.wao.ui.services.WaoManager; +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.tapestry5.Block; +import org.apache.tapestry5.EventContext; +import org.apache.tapestry5.RenderSupport; +import org.apache.tapestry5.annotations.Environmental; +import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary; +import org.apache.tapestry5.annotations.IncludeStylesheet; +import org.apache.tapestry5.annotations.InjectComponent; +import org.apache.tapestry5.annotations.Log; +import org.apache.tapestry5.annotations.Persist; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.annotations.SessionState; +import org.apache.tapestry5.corelib.components.Form; +import org.apache.tapestry5.corelib.components.Zone; +import org.apache.tapestry5.ioc.Messages; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.ioc.services.PropertyAccess; +import org.slf4j.Logger; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + +/** + * In this page, user will be able to edit a contact. Fields depends on right + * level and validations. + * + * + */ + at RequiresAuthentication(value = {UserRole.ADMIN, UserRole.COORDINATOR, UserRole.OBSERVER}, readOnlyAllowed = false) + at IncludeStylesheet("context:css/common.css") + at IncludeJavaScriptLibrary("context:js/contactForm.js") +public class ContactForm { + + @Inject + private PropertyAccess propertyAccess; + + @Inject + private Logger logger; + + @InjectComponent + private Layout layout; + + @SessionState + @Property + private ConnectedUser connectedUser; + + @Inject + private WaoManager manager; + + @Inject + private ServiceContact serviceContact; + + @Inject + private ServiceUser serviceUser; + + @Environmental + private RenderSupport renderSupport; + + @InjectComponent + private Zone globalZone; + + public DateFormat getDateFormat() { + return new SimpleDateFormat("dd/MM/yyyy"); + } + + public DateFormat getMonthYearFormat() { + return new SimpleDateFormat("MM/yyyy"); + } + + void onActivate(EventContext eventContext) { + if (eventContext.getCount() > 0) { + contactId = eventContext.get(String.class, 0); + } + } + + String onPassivate() { + return contactId; + } + + void setupRender() throws WaoException { + contact = null; // reset + getContact(); + } + + @Log + void afterRender() { + addSendEmailScript(); + } + + protected void addSendEmailScript() { + // Ask user to send an email if not already sent + if ( ! getContact().getEmailSent()) { + + String confirmMessage = + "Souhaitez vous envoyer un email de demande d\\'ajout " + + "du navire à votre portefeuille Allegro afin de pouvoir " + + "saisir les données ?"; + + // TODO-fdesbois-2010-07-27 : manage array of states in JavaScript + renderSupport.addScript("new ContactSendEmail('%s', '%s');", + confirmMessage, + // Check state BOARDING_DONE + ContactState.BOARDING_DONE.name()); + + renderSupport.addScript("new ContactSendEmail('%s', '%s');", + confirmMessage, + // Check state BOARDING_EXPECTED + ContactState.BOARDING_EXPECTED.name()); + } + } + + @Persist + private String contactId; + + @Persist + private Contact oldContact; + + @Persist + private Contact contact; + + @Log + public Contact getContact() { + if (contact == null) { + if (StringUtils.isEmpty(contactId)) { + // contact = serviceContact.getNewContact() + } else { + oldContact = serviceContact.getContact(contactId); + contact = serviceContact.getContact(contactId); + + mainObserverId = contact.getMainObserver().getTopiaId(); + if (oldContact == contact) { + throw new IllegalStateException("il faut deux instances différentes"); + } + } + if (logger.isDebugEnabled()) { + logger.debug("contact : " + contact.getTopiaCreateDate() + + contact.getId() + contact.getSampleRow().getCode()); + } + } + return contact; + } + + @InjectComponent + private Form contactForm; + + /****************************** INFORMATIONS ******************************/ + + public String getBoatDescription() { + return manager.getTooltipBoat(contact.getBoat()); + } + + /****************************** OBSERVERS *********************************/ + + @Property + private boolean refreshObserversForm; + + @Inject + private Block viewObservers; + + @Inject + private Block editObservers; + + public Block getViewOrEditObservers() { + Block result = viewObservers; + if (connectedUser.isCoordinatorOrObserver() && contact.getValidationCompany() == null) { + result = editObservers; + } + return result; + } + + @Property + private String mainObserverId; + + @InjectComponent + private Zone observersFormZone; + + @Persist + private List<WaoUser> secondaryObservers; + + @Persist + @Property + private String selectedSecondaryObserverId; + + @Property + private int secondaryObserverIndex; + + @Property + private WaoUser observer; // for loop + + private GenericSelectModel<WaoUser> observerSelectModel; + + public GenericSelectModel<WaoUser> getObserverSelectModel() throws WaoException { + if (observerSelectModel == null) { + List<WaoUser> observers = + serviceUser.getObservers(connectedUser.getCompany(), true); + observerSelectModel = new GenericSelectModel<WaoUser>(observers,WaoUser.class, + "fullName", "topiaId", propertyAccess); + } + return observerSelectModel; + } + + public List<WaoUser> getSecondaryObservers() { + if (secondaryObservers == null) { + secondaryObservers = new ArrayList<WaoUser>(getContact().getSecondaryObservers()); + } + return secondaryObservers; + } + + @Log + public void onChangeFromSecondaryObserver(String value) { + if (StringUtils.isEmpty(value)) { + selectedSecondaryObserverId = null; + } else { + selectedSecondaryObserverId = value; + } + if (logger.isDebugEnabled()) { + logger.debug("selected observer changed to " + selectedSecondaryObserverId); + } + } + + @Log + public Zone onActionFromAddSecondaryObserver() { + if (selectedSecondaryObserverId != null) { + WaoUser observerToAdd = getObserverSelectModel().findObject(selectedSecondaryObserverId); + + if (observerToAdd == null) { + logger.error("observerToAdd is null, id is " + selectedSecondaryObserverId); + } else if ( ! getSecondaryObservers().contains(observerToAdd)) { + getSecondaryObservers().add(observerToAdd); + } + } + + refreshObserversForm = true; + return observersFormZone; + } + + @Log + public Zone onActionFromRemoveSecondaryObserver(int secondaryObserverIndex) { + getSecondaryObservers().remove(secondaryObserverIndex); + + refreshObserversForm = true; + return observersFormZone; + } + + /************************ OBSERVATION REPORT ******************************/ + + @Inject + private Block viewObservationReport; + + @Inject + private Block editObservationReport; + + public Block getViewOrEditObservationReport() { + Block result = viewObservationReport; + if (connectedUser.isCoordinatorOrObserver() && contact.getValidationCompany() == null) { + result = editObservationReport; + } + return result; + } + + + /************************ ADMIN FIELDS ************************************/ + + + public boolean canEditDataReliability() { + boolean result = connectedUser.isAdmin() // coordinator can see the value + && BooleanUtils.isTrue(getContact().getValidationCompany()) + && getContact().getValidationProgram() == null; + return result; + } + + + /************** VALIDATION AND SUBMISSION *********************************/ + + @Persist + private boolean saveContact; // true if user selected save button, false if revert + + @Log + public void onSelectedFromRevertContact() { + saveContact = false; + } + + @Log + public void onSelectedFromSaveContact() { + saveContact = true; + } + + @Log + void onValidateFormFromContactForm() { + + contactForm.clearErrors(); + + if ( ! saveContact) { + return; + } + + if (mainObserverId == null) { + contactForm.recordError("Il faut au moins un observateur"); + } else { + WaoUser mainObserver = getObserverSelectModel().findObject(mainObserverId); + if (logger.isDebugEnabled()) { + logger.debug("main observer is " + mainObserver); + } + contact.setMainObserver(mainObserver); + contact.setSecondaryObservers(getSecondaryObservers()); + } + + // Validation for saving contact depends on contactState (only edition + // form) + ContactState contactState = contact.getContactState(); + if (logger.isDebugEnabled()) { + logger.debug("For state : " + contactState); + } + + Date begin = contact.getTideBeginDate(); + Date end = contact.getTideEndDate(); + Date input = contact.getDataInputDate(); + SampleRow row = contact.getSampleRow(); + + if (logger.isDebugEnabled()) { + logger.debug(String.format("begin = %s, end = %s, input = %s", begin, end, input)); + } + + if (begin != null && !row.isValid(begin)) { + contactForm.recordError( + "La date de début de la marée doit correspondre à un " + + "mois valide (non vide) de la ligne " + row.getCode()); + } + + if (begin != null && end != null && end.before(begin)) { + contactForm.recordError("La date de fin de la marée" + + " ne peut pas être antérieure à celle de début"); + } + + Date current = manager.getCurrentDate(); + + if (end != null && end.after(current)) { + contactForm.recordError("La date de fin de la marée" + + " ne peut pas être postérieure à la date du jour"); + } + + if (end != null && input != null && end.after(input)) { + contactForm.recordError("La date de saisie des" + + " données ne peut pas être antérieure à la date de" + + " fin de la marée"); + } + + if (input != null && input.after(current)) { + contactForm.recordError("La date de saisie des" + + " données ne peut pas être postérieure à la date" + + " du jour"); + } + + // Non abouti, Refus ou Refus Définitif + if (contactState.isUnfinishedState()) { + String newComment = contact.getComment(); + + boolean commentDefined = StringUtils.isNotEmpty(newComment); + boolean commentChanged = commentDefined && + !newComment.equals(oldContact.getComment()); + + // Ano #2540 : NPE on oldState, extract boolean for + // previous unfinishedState case + boolean previousUnfinishedState = commentDefined && + oldContact.getContactState() != null && oldContact.getContactState().isUnfinishedState(); + + // Ano #2440 : no restriction if previous state is unfinished + if (previousUnfinishedState || commentChanged) { + + // RAZ des champs + contact.setTideBeginDate(null); + contact.setTideEndDate(null); + contact.setNbObservants(0); + contact.setMammalsCapture(false); + contact.setMammalsObservation(false); + contact.setDataInputDate(null); + + } else { + contactForm.recordError("Vous devez ajouter" + + " un commentaire pour l'état" + + " '" + contactState.libelle() + "'"); + } + // Embarquement Réalisé + } else if (contactState.equals(ContactState.BOARDING_DONE)) { + + if (begin == null) { + contactForm.recordError("La date de début de" + + " marée est obligatoire pour l'état" + + " '" + contactState.libelle() + "'"); + } + if (end == null) { + contactForm.recordError("La date de fin de" + + " marée est obligatoire pour l'état" + + " '" + contactState.libelle() + "'"); + } + if (contact.getNbObservants() == 0) { + contactForm.recordError("Il ne peut y" + + " avoir aucun observateur pour l'état" + + " '" + contactState.libelle() + "'"); + } + + if (logger.isDebugEnabled()) { + logger.debug("ValidationProgram = " + contact.isValidationProgram()); + } + + if (BooleanUtils.isTrue(contact.isValidationProgram())) { + + // it's an admin validation, data-reliability field must be filled + if (logger.isDebugEnabled()) { + logger.debug("field data reliability is " + + contact.getDataReliability()); + } + + if (contact.getDataReliability() == null || + contact.getDataReliability() == DataReliability.UNKNOWN) { + contactForm.recordError("Il faut préciser la qualité des données avant de valider"); + } + } + } + } + + @Log + Object onFailureFromContactForm() { + // refresh zone to show errors + return globalZone; + } + + @Inject + private Messages messages; + + @Property + private boolean sendEmail; + + @Log + Object onSuccessFromContactForm() { + + if (saveContact) { + + if (logger.isDebugEnabled()) { + logger.debug("Contact save : " + contact); + // logger.debug("Contact sendEmail : " + sendEmail); + } + serviceContact.saveContact(contact, false); + + try { + if (sendEmail && serviceContact.sendContactDoneEmail(contact)) { + layout.addInfo("Un email a été envoyé pour l'ajout du navire au portefeuille ALLEGRO."); + } + } catch (WaoBusinessException eee) { + String message = manager.getErrorMessage(eee, messages, logger); + layout.addError(message); + } + } + + // reset + contact = null; + mainObserverId = null; + secondaryObservers = null; + + // reload page + return this; + } + +} Added: trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/pages/ContactForm.properties =================================================================== --- trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/pages/ContactForm.properties (rev 0) +++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/pages/ContactForm.properties 2010-12-20 16:35:01 UTC (rev 839) @@ -0,0 +1,13 @@ +# form labels +mainObserver-label: Observateur r\u00e9f\u00e9rant +secondaryObserver-label: Observateur +contactState-label: \u00c9tat du contact +beginDate-label: D\u00e9but de la mar\u00e9e +endDate-label: Fin de la mar\u00e9e +mammalsObservation-label: Observations de mammif\u00e8res +mammalsCapture-label: Capture accidentelle de mammif\u00e8res +inputDate-label: Date de saisie des donn\u00e9es dans Allegro +observerComment-label: Commentaire observateur +coordinatorComment-label: Commentaire soci\u00e9t\u00e9 +adminComment-label: Commentaire administrateur +dataReliability-label: Qualit\u00e9 de la donn\u00e9e \ No newline at end of file Added: trunk/wao-ui/src/main/webapp/ContactForm.tml =================================================================== --- trunk/wao-ui/src/main/webapp/ContactForm.tml (rev 0) +++ trunk/wao-ui/src/main/webapp/ContactForm.tml 2010-12-20 16:35:01 UTC (rev 839) @@ -0,0 +1,240 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<t:layout t:pageTitle="Modification d'un contact" t:contentId="so-contact-form" + xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> + <h1 class="acenter"> + Modification d'un contact + </h1> + + <div class="mtop30" /> + <t:zone t:id="globalZone" t:update="show"> + <form t:type="form" t:id="contactForm" t:zone="globalZone"> + + <t:errors /> + + <input t:type="hidden" t:id="hiddenSendEmail" t:value="sendEmail" /> + + <fieldset class="user-form clearfix"> + <legend>Informations</legend> + <div class="t-beaneditor"> + <div class="fright" style="border-left: solid 1px; padding-left: 10px;"> + <strong> + Navire<br /> + ${contact.boat.name} + </strong> + <ul style="list-style-type: none;"> + <li>Immatriculation : ${contact.boat.immatriculation}</li> + <li>Quartier : ${contact.boat.districtCode}</li> + <li>Longueur : ${contact.boat.boatLength} m</li> + <li>Année de contruction : ${contact.boat.buildYear}</li> + </ul> + </div> + <div class="t-beaneditor-row"> + <strong>Ligne du plan d'échantillonage</strong> + <br /> + <ul style="list-style-type: none;"> + <li>Code : ${contact.sampleRow.code}</li> + <li>Métier : ${contact.sampleRow.professionDescription}</li> + <li>Programme : ${contact.sampleRow.programName} (du + <t:output value="contact.sampleRow.periodBegin" format="monthYearFormat" /> + au + <t:output value="contact.sampleRow.periodEnd" format="monthYearFormat" />) + </li> + </ul> + </div> + <div class="t-beaneditor-row"> + Date de création du contact : <t:output value="contact.topiaCreateDate" format="dateFormat" /> + </div> + </div> + </fieldset> + + <fieldset class="user-form clearfix"> + <legend>Observateurs</legend> + <div class="t-beaneditor"> + <t:delegate to="viewOrEditObservers" /> + </div> + </fieldset> + + <t:block id="viewObservers"> + <div class="t-beaneditor-row"> + <t:label t:for="mainObserver" /> + <t:if test="contact.mainObserver"> + ${contact.mainObserver.fullName} + </t:if> + </div> + <div class="t-beaneditor-row" style="position: relative; left: 250px;"> + <ul> + <li t:type="loop" t:source="secondaryObservers" t:value="observer"> + ${observer.fullName} + </li> + </ul> + </div> + </t:block> + + <t:block id="editObservers"> + <div class="t-beaneditor-row"> + <t:label t:for="mainObserver" /> + <input t:type="select" t:id="mainObserver" t:model="observerSelectModel" t:validate="required" t:value="mainObserverId" /> + </div> + <t:zone t:id="observersFormZone" t:visible="true" t:update="show"> + <t:nuiton.subForm t:visible="refreshObserversForm"> + <div class="t-beaneditor-row"> + <t:label t:for="secondaryObserver" /> + <input t:type="select" t:id="secondaryObserver" t:model="observerSelectModel" t:value="selectedSecondaryObserverId" t:mixins="ck/onEvent" t:event="change" /> + <a t:type="actionlink" t:id="addSecondaryObserver" title="Ajouter un observateur" t:zone="observersFormZone"> + <img src="${asset:context:img/add-16px.png}" /> + </a> + <div class="t-beaneditor-row" style="position: relative; left: 250px;"> + <ul> + <li t:type="loop" t:source="secondaryObservers" t:value="observer" t:index="secondaryObserverIndex" t:volatile="true"> + ${observer.fullName} + <a t:type="actionlink" t:id="removeSecondaryObserver" t:context="secondaryObserverIndex" title="Supprimer cet observateur" t:zone="observersFormZone"> + <img src="${asset:context:img/remove-22px.png}" /> + </a> + </li> + </ul> + </div> + </div> + </t:nuiton.subForm> + </t:zone> + </t:block> + + <fieldset class="user-form clearfix"> + <legend>Compte-rendu de l'observation</legend> + <div class="t-beaneditor"> + <t:delegate to="viewOrEditObservationReport" /> + </div> + </fieldset> + + <t:block id="viewObservationReport"> + <div class="t-beaneditor-row"> + <t:label t:for="contactState" /> + ${contact.contactState.label} + </div> + <div class="t-beaneditor-row"> + <t:label t:for="beginDate" /> + <t:output value="contact.tideBeginDate" format="dateFormat" /> + </div> + <div class="t-beaneditor-row"> + <t:label t:for="endDate" /> + <t:output value="contact.tideEndDate" format="dateFormat" /> + </div> + <div class="t-beaneditor-row"> + <img src="${asset:context:img/eye-22px.png}" alt="Observations" title="Observations" /> + <t:label t:for="mammalsObservation" /> + <t:booleanImage t:value="contact.mammalsObservation" /> + </div> + <div class="t-beaneditor-row"> + <img src="${asset:context:img/fishing-net-22px.png}" alt="Captures" title="Captures" /> + <t:label t:for="mammalsCapture" /> + <t:booleanImage t:value="contact.mammalsCapture" /> + </div> + <div class="t-beaneditor-row"> + <t:label t:for="inputDate" /> + <t:output value="contact.dataInputDate" format="dateFormat" /> + </div> + + <div class="t-beaneditor-row"> + <t:label t:for="observerComment" /> + <t:if t:test="contact.comment"> + ${contact.comment} + <p:else> + <em>aucun commentaire</em> + </p:else> + </t:if> + </div> + + <t:unless test="connectedUser.observer"> + <div class="t-beaneditor-row"> + <t:label t:for="coordinatorComment" /> + <t:if t:test="contact.commentCoordinator"> + ${contact.commentCoordinator} + <p:else> + <em>aucun commentaire</em> + </p:else> + </t:if> + </div> + </t:unless> + </t:block> + + <t:block id="editObservationReport"> + <div class="t-beaneditor-row"> + <t:label t:for="contactState" /> + <input t:type="select" t:id="contactState" t:value="contact.contactState" t:validate="required"/> + </div> + <div class="t-beaneditor-row"> + <t:label t:for="beginDate" /> + <input t:type="datefield" t:id="beginDate" class="date" value="contact.tideBeginDate" /> + </div> + <div class="t-beaneditor-row"> + <t:label t:for="endDate" /> + <input t:type="datefield" t:id="endDate" class="date" value="contact.tideEndDate" /> + </div> + <div class="t-beaneditor-row"> + <img src="${asset:context:img/eye-22px.png}" alt="Observations" title="Observations" /> + <t:label t:for="mammalsObservation" /> + <input t:type="checkbox" t:id="mammalsObservation" value="contact.mammalsObservation"/> + </div> + <div class="t-beaneditor-row"> + <img src="${asset:context:img/fishing-net-22px.png}" alt="Captures" title="Captures" /> + <t:label t:for="mammalsCapture" /> + <input t:type="checkbox" t:id="mammalsCapture" value="contact.mammalsCapture" /> + </div> + <div class="t-beaneditor-row"> + <t:label t:for="observerComment" /> + <input t:type="textarea" t:id="observerComment" value="contact.comment" /> + </div> + <div class="t-beaneditor-row"> + <t:label t:for="inputDate" /> + <input t:type="datefield" t:id="inputDate" class="date" value="contact.dataInputDate" /> + </div> + + + <t:unless test="connectedUser.observer"> + <div class="t-beaneditor-row"> + <t:label t:for="coordinatorComment" /> + <input t:type="textarea" t:id="coordinatorComment" value="contact.commentCoordinator" /> + </div> + </t:unless> + </t:block> + + <t:unless test="connectedUser.observer"> + <fieldset class="user-form clearfix"> + <legend>Évaluation programme</legend> + <div class="t-beaneditor"> + <div class="t-beaneditor-row"> + <t:label t:for="dataReliability" /> + <t:if t:test="canEditDataReliability()"> + <input t:type="select" t:id="dataReliability" value="contact.dataReliability" /> + <p:else> + ${contact.dataReliability.label} + </p:else> + </t:if> + </div> + <div class="t-beaneditor-row"> + <t:label t:for="adminComment" /> + <t:if t:test="connectedUser.admin"> + <input t:type="textarea" t:id="adminComment" value="contact.commentAdmin" /> + <p:else> + <t:if t:test="contact.commentAdmin"> + ${contact.commentAdmin} + <p:else> + <em>aucun commentaire</em> + </p:else> + </t:if> + </p:else> + </t:if> + </div> + </div> + </fieldset> + </t:unless> + + <div class="fright"> + <input t:type="submit" t:id="saveContact" class="ico save" value="Save" title="Enregistrer les modifications" /> + <input t:type="submit" t:id="revertContact" class="ico undo" value="Undo" title="Annuler les modifications" /> + </div> + + </form> + </t:zone> + +</t:layout> Modified: trunk/wao-ui/src/main/webapp/Contacts.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Contacts.tml 2010-12-15 18:16:56 UTC (rev 838) +++ trunk/wao-ui/src/main/webapp/Contacts.tml 2010-12-20 16:35:01 UTC (rev 839) @@ -138,8 +138,10 @@ <t:label t:for="programUndefined"> <img src="${asset:context:img/help-22px.png}" title="Non validé par le programme" /> </t:label> - <t:label t:for="reliabilityFilter" />: - <select t:type="select" t:id="reliabilityFilter" value="contactFilter.dataReliability"/> + <t:unless t:test="user.observer"> + <t:label t:for="reliabilityFilter" />: + <select t:type="select" t:id="reliabilityFilter" value="contactFilter.dataReliability"/> + </t:unless> <span>Commentaires : </span> <input t:type="checkbox" t:id="commentFilter" value="contactFilter.comment" /> <label for="commentFilter">observateur</label> @@ -194,9 +196,9 @@ t:rowsPerPage="20"> <p:createdByCell> ${contact.mainObserver.fullName} - <t:if t:test="editionMode"> + <!--t:if t:test="editionMode"> <a t:type="actionlink" t:id="showObserversForm" t:zone="observersFormZone" context="${contact.topiaId}" class="display-form" title="Modifier les observateurs associés à ce contact">...</a> - </t:if> + </t:if--> </p:createdByCell> <p:sampleRowCell> <span t:type="ck/Tooltip" title="Infos" t:value="prop:sampleRowDescription" t:effect="appear"> @@ -298,11 +300,11 @@ <t:if t:test="contact.validationCompany"> <t:if test="contact.validationProgram"> ${contact.dataReliability.label} - <p:else> + <!--p:else> <t:if test="canUpdateDataReliability()"> <input t:type="select" t:id="dataReliability" t:value="contact.dataReliability" validate="required" /> </t:if> - </p:else> + </p:else--> </t:if> </t:if> </t:if> @@ -318,6 +320,14 @@ </span> </p:commentAdminCell> <p:actionsCell> + <t:unless t:test="contact.validationProgram"> + <a t:type="pagelink" t:page="contactForm" t:context="contact.topiaId"> + <img src="${asset:context:}/img/edit.png" alt="Modifier" title="Modifier le contact"/> + </a> + <p:else> + <img src="${asset:context:img/edit-unavailable-22px.png}" alt="Edit unavailable" title="Modification du contact indisponible"/> + </p:else> + </t:unless> <t:if t:test="hasActions()"> <t:if t:test="editionMode"> <input t:type="submit" t:id="cancelEditContact" class="ico22px undo22px" value="Undo" @@ -325,8 +335,8 @@ <input t:type="submitContext" t:id="saveContact" class="ico22px save22px" value="Save" t:context="contact.topiaId" title="Enregistrer le contact" /> <p:else> - <input t:type="submitContext" t:id="editContact" class="ico edit" value="Edit" - t:context="contact.topiaId" title="Modifier le contact" /> + <!--input t:type="submitContext" t:id="editContact" class="ico edit" value="Edit" + t:context="contact.topiaId" title="Modifier le contact" /--> <input t:type="submitContext" t:id="deleteContact" class="ico22px delete" value="Delete" t:context="contact.topiaId" title="Supprimer le contact" t:mixins="nuiton/confirm" t:message="literal:Etes-vous sûr de vouloir supprimer définitivement ce contact ?" /> @@ -334,7 +344,7 @@ </t:if> <p:else> <t:unless t:test="user.admin"> - <img src="${asset:context:img/edit-unavailable-22px.png}" alt="Edit unavailable" title="Edition du contact indisponible"/> + <!--img src="${asset:context:img/edit-unavailable-22px.png}" alt="Edit unavailable" title="Edition du contact indisponible"/--> <img src="${asset:context:img/delete-unavailable-22px.png}" alt="Delete unavailable" title="Suppression du contact indisponible"/> </t:unless> </p:else> @@ -356,14 +366,14 @@ <input t:type="submitContext" t:id="unvalidateContact" class="ico22px unvalidate" value="Unvalidate" t:context="contact.topiaId" title="Enlever la validation du contact" /> </t:if> - <t:if t:test="editionMode"> + <!--t:if t:test="editionMode"> <img src="${asset:context:img/comment-unavailable-22px.png}" alt="Add comment" /> <p:else> <a class="link" onclick="commentController.openWindow(${commentData});"> <img src="${asset:context:img/comment-22px.png}" alt="Add comment" /> </a> </p:else> - </t:if> + </t:if--> </t:if> </p:actionsCell> </div> Added: trunk/wao-ui/src/main/webapp/js/contactForm.js =================================================================== --- trunk/wao-ui/src/main/webapp/js/contactForm.js (rev 0) +++ trunk/wao-ui/src/main/webapp/js/contactForm.js 2010-12-20 16:35:01 UTC (rev 839) @@ -0,0 +1,16 @@ +ContactSendEmail = Class.create({ + initialize: function(message, contactState) { + this.contactState = contactState; + this.message = message; + + $('saveContact').observe('click', this.doConfirm.bind(this)); + }, + doConfirm: function(event) { + + var contactForm = event.element().form; + + if ($F(contactForm.contactState) == this.contactState && confirm(this.message)) { + contactForm.hiddenSendEmail.setValue(true); + } + } +}); \ No newline at end of file