[Suiviobsmer-commits] r592 - in trunk: . wao-business/src/main/filters wao-business/src/main/java/fr/ifremer/wao wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/resources/i18n wao-business/src/main/xmi wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/webapp wao-ui/src/main/webapp/js
Author: fdesbois Date: 2010-07-07 17:49:30 +0000 (Wed, 07 Jul 2010) New Revision: 592 Log: Evo #2351 : Add script confirm to send email after BOARDING_DONE contact. Added: trunk/wao-ui/src/main/webapp/js/contacts.js Removed: trunk/wao-ui/src/main/webapp/js/ContactComment.js Modified: trunk/changelog.txt trunk/wao-business/src/main/filters/Wao.properties trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoBusinessException.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoProperty.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 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/java/fr/ifremer/wao/ui/pages/Contacts.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactsKmlLoader.java trunk/wao-ui/src/main/webapp/Contacts.tml Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/changelog.txt 2010-07-07 17:49:30 UTC (rev 592) @@ -9,6 +9,8 @@ Evolutions ++++++++++ +- [fdesbois] Evo #2361 : Mail automatique suite à un embarquement réalisé. + Mise à jour librairies ++++++++++++++++++++++ Modified: trunk/wao-business/src/main/filters/Wao.properties =================================================================== --- trunk/wao-business/src/main/filters/Wao.properties 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/filters/Wao.properties 2010-07-07 17:49:30 UTC (rev 592) @@ -43,6 +43,7 @@ wao.email.host=smtp wao.email.port=25 wao.email.from=admin at wao.org +wao.contactDone.email=admin at wao.org ## Server path for link in mails (must be override) wao.server.path=localhost:8080/wao Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-07-07 17:49:30 UTC (rev 592) @@ -222,10 +222,6 @@ // FIXME-fdesbois-2010-06-29 : Seems dangerous to use class, maybe it's better to use full qualified name 'fr.ifremer.wao.entity.BoatDistrict' String districtId = TopiaId.create(BoatDistrict.class); String createDate = dateFormat.format(new Date()); -// queries.add(String.format( -// "INSERT INTO BoatDistrict VALUES ('%s', %d, '%s', '%s', null, null, null);", -// districtId, 0, createDate, code) -// ); query.append(separator).append(String.format( "('%s', %d, '%s', '%s', null, null, null)", districtId, 0, createDate, code) @@ -259,4 +255,12 @@ queries.add("ALTER TABLE Boat DROP COLUMN districtCode;"); } + + @Override + protected void createContactEmailSentColumn_1_5e(List<String> queries) { + // Evo #2361 : detect and send email when boarding is done + queries.add("ALTER TABLE Contact ADD emailSent BOOLEAN;"); + queries.add("UPDATE Contact SET emailSent = FALSE WHERE dataInputDate IS NULL;"); + queries.add("UPDATE Contact SET emailSent = TRUE WHERE dataInputDate IS NOT NULL;"); + } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoBusinessException.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoBusinessException.java 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoBusinessException.java 2010-07-07 17:49:30 UTC (rev 592) @@ -40,6 +40,14 @@ protected Class<?> serviceClass; + public WaoBusinessException(String message) { + super(message); + } + + public WaoBusinessException(String message, Throwable cause) { + super(message, cause); + } + public WaoBusinessException(Type type, Class<?> serviceClass, String msg) { super(msg); this.type = type; Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java 2010-07-07 17:49:30 UTC (rev 592) @@ -28,6 +28,7 @@ import java.nio.charset.Charset; import java.util.Date; import org.apache.commons.mail.EmailException; +import org.apache.commons.mail.SimpleEmail; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; @@ -128,6 +129,9 @@ */ void sendEmail(String to, String subject, String msg) throws EmailException; + SimpleEmail prepareEmail(String to, String subject, String msg) + throws EmailException; + /** * getCurrentDate : * @return Date Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-07-07 17:49:30 UTC (rev 592) @@ -448,6 +448,14 @@ if (log.isInfoEnabled()) { log.info("Send an email to " + to + " : " + subject); } + SimpleEmail email = prepareEmail(to, subject, msg); + email.send(); + } + + @Override + public SimpleEmail prepareEmail(String to, String subject, String msg) + throws EmailException { + SimpleEmail email = new SimpleEmail(); email.setHostName(WaoProperty.EMAIL_HOST.getValue()); email.setSmtpPort(Integer.parseInt(WaoProperty.EMAIL_PORT.getValue())); @@ -456,6 +464,6 @@ email.setSubject(subject); email.setMsg(msg); email.setCharset("UTF-8"); - email.send(); + return email; } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-07-07 17:49:30 UTC (rev 592) @@ -27,7 +27,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hibernate.SQLQuery; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.migration.TopiaMigrationCallback; @@ -78,6 +77,8 @@ protected abstract void updateBoatWithBoatDistrict_1_5d(List<String> queries, Map<String, String> boats); + protected abstract void createContactEmailSentColumn_1_5e(List<String> queries); + protected static final Version[] VERSIONS = new Version[] { VersionUtil.valueOf("1.0"), VersionUtil.valueOf("1.1"), @@ -210,8 +211,11 @@ // Update the Boat table with id of district (create column as foreign key) updateBoatWithBoatDistrict_1_5d(queries, boats); + createContactEmailSentColumn_1_5e(queries); + + String[] strings = queries.toArray(new String[queries.size()]); - executeSQL(tx, false, false, strings); + executeSQL(tx, showSql, showProgression, strings); } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoProperty.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoProperty.java 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoProperty.java 2010-07-07 17:49:30 UTC (rev 592) @@ -50,7 +50,9 @@ /** Server path */ SERVER_PATH("wao.server.path"), /** Path for Eastwood */ - CHART_SERVER_PATH("chart.server.path"); + CHART_SERVER_PATH("chart.server.path"), + /** Email address to use when contact is done */ + CONTACT_DONE_EMAIL("wao.contactDone.email"); private String key; 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-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-07-07 17:49:30 UTC (rev 592) @@ -25,17 +25,6 @@ package fr.ifremer.wao.service; -import java.io.IOException; -import java.io.InputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Map; import com.csvreader.CsvReader; import com.csvreader.CsvWriter; import fr.ifremer.wao.WaoBinderHelper; @@ -43,9 +32,14 @@ import fr.ifremer.wao.WaoContext; import fr.ifremer.wao.WaoDAOHelper; import fr.ifremer.wao.WaoException; +import fr.ifremer.wao.WaoProperty; import fr.ifremer.wao.WaoQueryBuilder; import fr.ifremer.wao.WaoQueryHelper; import fr.ifremer.wao.bean.ConnectedUser; +import fr.ifremer.wao.bean.ContactFilter; +import fr.ifremer.wao.bean.ContactState; +import fr.ifremer.wao.bean.ContactStatus; +import fr.ifremer.wao.bean.ContactStatus.NullSampleMonthException; import fr.ifremer.wao.bean.UserRole; import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Company; @@ -61,24 +55,38 @@ import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.io.ContactInput; import fr.ifremer.wao.io.ImportRefusedException; +import fr.ifremer.wao.io.ImportResults; +import fr.ifremer.wao.io.ImportResultsImpl; import fr.ifremer.wao.io.csv.ExportHelper; import fr.ifremer.wao.io.csv.ImportHelper; import fr.ifremer.wao.io.csv.WaoCsvHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import fr.ifremer.wao.io.csv.WaoCsvHeader.BOAT; +import fr.ifremer.wao.io.csv.WaoCsvHeader.CONTACT; +import fr.ifremer.wao.io.csv.WaoCsvHeader.ContactHeader; +import fr.ifremer.wao.io.csv.WaoCsvHeader.FISHING_ZONE; +import fr.ifremer.wao.io.csv.WaoCsvHeader.SAMPLING; +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.mail.EmailException; +import org.apache.commons.mail.SimpleEmail; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.framework.TopiaQuery; -import fr.ifremer.wao.bean.ContactStatus; -import fr.ifremer.wao.bean.ContactStatus.NullSampleMonthException; -import fr.ifremer.wao.bean.ContactFilter; -import fr.ifremer.wao.bean.ContactState; -import fr.ifremer.wao.io.ImportResults; -import fr.ifremer.wao.io.ImportResultsImpl; -import fr.ifremer.wao.io.csv.WaoCsvHeader.*; -import org.apache.commons.lang.BooleanUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Map; + /** * ServiceContactImpl * @@ -872,4 +880,67 @@ elligible.setCompanyActive(Boolean.TRUE); } + @Override + public boolean executeSendContactDoneEmail(TopiaContext transaction, Contact contact) + throws WaoBusinessException, TopiaException { + + // Do nothing in this case + if (!contact.getContactState().equals(ContactState.BOARDING_DONE) || + contact.getEmailSent()) { + return false; + } + + ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); + + // Retrieve existing contact + Contact contactToUpdate = dao.findByTopiaId(contact.getTopiaId()); + + WaoUser observer = contactToUpdate.getObserver(); + String observerEmail = observer.getLogin(); + int boatImmatriculation = contactToUpdate.getBoat().getImmatriculation(); + + String subject = String.format( + "Obsmer : ajout navire \"%d\" sur portefeuille ALLEGRO de %s", + boatImmatriculation, + observerEmail + ); + + String content = String.format( + "Bonjour,\n\n" + + "Merci d'ajouter le navire \"%d\" au portefeuille ALLEGRO de " + + "l'observateur %s %s %s.\n\n" + + "Cordialement,\n" + + "L'équipe Obsmer", + boatImmatriculation, + observer.getFullName(), + observer.getCompany().getName(), + observerEmail + ); + + try { + // Send the email + SimpleEmail email = context.prepareEmail( + WaoProperty.CONTACT_DONE_EMAIL.getValue(), + subject, + content + ); + + email.addTo(observerEmail); + email.send(); + + // Update the contact + contactToUpdate.setEmailSent(true); + dao.update(contactToUpdate); + + transaction.commitTransaction(); + + return true; + + } catch (EmailException eee) { + throw new WaoBusinessException("Aucun email n'a pu être envoyé." + + " Vérifiez le serveur smtp et l'adresse email de l'observateur.", + eee); + } + } + } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-07-07 17:49:30 UTC (rev 592) @@ -383,7 +383,7 @@ UserRole.getMatchCodes(UserRole.OBSERVER, UserRole.COORDINATOR); TopiaQuery query = dao.createQuery(). - addEquals(WaoUser.ROLE, (Integer[])matchCodes). + addEquals(WaoUser.ROLE, (Object[])matchCodes). addOrder(WaoUser.FIRST_NAME, WaoUser.LAST_NAME); if (company != null) { 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 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-07-07 17:49:30 UTC (rev 592) @@ -36,6 +36,7 @@ wao.error.serviceContact.importContactCsv= wao.error.serviceContact.saveComment= wao.error.serviceContact.saveContact= +wao.error.serviceContact.sendContactDoneEmail= wao.error.serviceContact.updateSampleMonthTidesValue= wao.error.serviceNews.getNewNews= wao.error.serviceNews.getNews= 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-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-07-07 17:49:30 UTC (rev 592) @@ -35,6 +35,7 @@ wao.error.serviceContact.importContactCsv=Impossible d'importer les contacts wao.error.serviceContact.saveComment= wao.error.serviceContact.saveContact=Impossible de sauvegarder le contact +wao.error.serviceContact.sendContactDoneEmail= wao.error.serviceContact.updateSampleMonthTidesValue= wao.error.serviceNews.getNewNews= wao.error.serviceNews.getNews=Impossible de r\u00E9cup\u00E9rer l'ensemble des news Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-07-07 17:49:30 UTC (rev 592) @@ -31,32 +31,27 @@ import fr.ifremer.wao.bean.ContactFilter; import fr.ifremer.wao.bean.ContactFilterImpl; import fr.ifremer.wao.bean.ContactState; -import fr.ifremer.wao.io.ImportResults; import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.bean.UserRole; import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.WaoUser; +import fr.ifremer.wao.io.ImportResults; import fr.ifremer.wao.service.ServiceContact; import fr.ifremer.wao.service.ServiceUser; import fr.ifremer.wao.ui.base.AbstractFilteredPage; -import fr.ifremer.wao.ui.data.*; +import fr.ifremer.wao.ui.components.Layout; +import fr.ifremer.wao.ui.data.ContactDataSource; +import fr.ifremer.wao.ui.data.ExportStreamResponse; import fr.ifremer.wao.ui.data.GenericSelectModel; -import fr.ifremer.wao.ui.components.Layout; +import fr.ifremer.wao.ui.data.RequiresAuthentication; import fr.ifremer.wao.ui.services.ContactModelFactory; import fr.ifremer.wao.ui.services.WaoManager; -import java.io.IOException; -import java.io.InputStream; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.apache.tapestry5.ComponentResources; import org.apache.tapestry5.Field; -import org.apache.tapestry5.Link; import org.apache.tapestry5.PersistenceConstants; import org.apache.tapestry5.RenderSupport; import org.apache.tapestry5.StreamResponse; @@ -76,11 +71,17 @@ import org.apache.tapestry5.ioc.services.PropertyAccess; import org.apache.tapestry5.json.JSONObject; import org.apache.tapestry5.services.BeanModelSource; -import org.apache.tapestry5.services.Request; import org.apache.tapestry5.upload.services.UploadedFile; import org.nuiton.util.DateUtils; import org.slf4j.Logger; +import java.io.IOException; +import java.io.InputStream; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + /** * Contacts * @@ -90,11 +91,11 @@ */ @RequiresAuthentication({UserRole.ADMIN, UserRole.COORDINATOR, UserRole.OBSERVER}) @IncludeStylesheet("context:css/contacts.css") - at IncludeJavaScriptLibrary("context:js/ContactComment.js") + at IncludeJavaScriptLibrary("context:js/contacts.js") public class Contacts extends AbstractFilteredPage { @Inject - private Logger log; + private Logger logger; @InjectComponent private Layout layout; @@ -106,11 +107,14 @@ @Inject private ServiceContact serviceContact; + @Environmental + private RenderSupport renderSupport; + @Log void setupRender() throws WaoException { - if (log.isDebugEnabled()) { - log.debug("RESET DATA"); - log.debug("User : " + user.getFullName()); + if (logger.isDebugEnabled()) { + logger.debug("RESET DATA"); + logger.debug("User : " + user.getFullName()); } contacts = null; contactsForm.clearErrors(); @@ -126,6 +130,15 @@ initCompanyFilter(); } + /** + * Add script to renderSupport + */ + @Log + void afterRender() { + addCommentScript(); + addSendEmailScript(); + } + /**************************** CONTACT FILTERS *****************************/ @Persist @@ -144,8 +157,8 @@ public ContactFilter getContactFilter() throws WaoException { if (contactFilter == null) { - if (log.isDebugEnabled()) { - log.debug("Init contactFilter"); + if (logger.isDebugEnabled()) { + logger.debug("Init contactFilter"); } contactFilter = new ContactFilterImpl(); // Initialized to 12 months before the current day @@ -309,8 +322,8 @@ public ContactDataSource getContacts() throws WaoException { if (contacts == null) { - if (log.isDebugEnabled()) { - log.debug("Create DataSource"); + if (logger.isDebugEnabled()) { + logger.debug("Create DataSource"); } contacts = new ContactDataSource(getContactFilter(), serviceContact); } @@ -336,8 +349,8 @@ if (userSelectModel == null) { List<WaoUser> users = serviceUser.getObservers( user.getCompany(), true); - if (log.isDebugEnabled()) { - log.debug("Nb users : " + users.size()); + if (logger.isDebugEnabled()) { + logger.debug("Nb users : " + users.size()); } userSelectModel = new GenericSelectModel<WaoUser>(users, WaoUser.class, "fullName", "id", propertyAccess); @@ -465,8 +478,8 @@ } void onSelectedFromAcceptContact(String contactId) throws WaoException { - if (log.isDebugEnabled()) { - log.debug("Accept contact : " + contactId); + if (logger.isDebugEnabled()) { + logger.debug("Accept contact : " + contactId); } contactEdited = getContacts().get(contactId); if (user.isAdmin()) { @@ -479,8 +492,8 @@ } void onSelectedFromRefuseContact(String contactId) throws WaoException { - if (log.isDebugEnabled()) { - log.debug("Refuse contact : " + contactId); + if (logger.isDebugEnabled()) { + logger.debug("Refuse contact : " + contactId); } contactEdited = getContacts().get(contactId); if (user.isAdmin()) { @@ -493,8 +506,8 @@ } void onSelectedFromUnvalidateContact(String contactId) throws WaoException { - if (log.isDebugEnabled()) { - log.debug("Unvalidate contact : " + contactId); + if (logger.isDebugEnabled()) { + logger.debug("Unvalidate contact : " + contactId); } contactEdited = getContacts().get(contactId); if (user.isAdmin()) { @@ -515,10 +528,10 @@ @Log void onSelectedFromEditContact(String contactId) throws WaoException { - if (log.isDebugEnabled()) { - log.debug("Edit contact : " + contactId); - log.debug("Contact : " + getContacts().get(contactId)); - log.debug("Set observerId : " + getContacts().get(contactId).getObserver()); + if (logger.isDebugEnabled()) { + logger.debug("Edit contact : " + contactId); + logger.debug("Contact : " + getContacts().get(contactId)); + logger.debug("Set observerId : " + getContacts().get(contactId).getObserver()); } contactEdited = getContacts().get(contactId); //prepareContactEdited(contactId); contactUserId = contactEdited.getObserver().getId(); @@ -530,8 +543,8 @@ @Log void onSelectedFromDeleteContact(String contactId) throws WaoException { - if (log.isDebugEnabled()) { - log.debug("Delete contact : " + contactId); + if (logger.isDebugEnabled()) { + logger.debug("Delete contact : " + contactId); } contactEdited = getContacts().get(contactId); deleted = true; @@ -539,17 +552,17 @@ @Log void onSelectedFromSaveContact(String contactId) throws WaoException { - if (log.isDebugEnabled()) { - log.debug("Save contact : " + contactId); - log.debug("Observer Id : " + contactUserId); + if (logger.isDebugEnabled()) { + logger.debug("Save contact : " + contactId); + logger.debug("Observer Id : " + contactUserId); } // ContactEdited is in session, previously set by Edit action // contactEdited.setState(contactState.toString()); WaoUser contactUser = getUserSelectModel().findObject(contactUserId); contactEdited.setObserver(contactUser); - if (log.isDebugEnabled()) { - log.debug("Comment : " + contactEdited.getComment()); + if (logger.isDebugEnabled()) { + logger.debug("Comment : " + contactEdited.getComment()); } } @@ -590,6 +603,21 @@ @Inject private Messages messages; + @Property + private boolean sendEmail; + + protected void addSendEmailScript() { + // Ask user to send an email if not already sent + if (contactEdited != null && !contactEdited.getEmailSent()) { + renderSupport.addScript("new ContactSendEmail('%s', '%s');", + "Souhaitez vous envoyer un email de demande d\\'ajout " + + "du navire à votre portefeuille Allegro afin de pouvoir " + + "saisir les données ?", + // Check state BOARDING_DONE + ContactState.BOARDING_DONE.name()); + } + } + @Log void onValidateFormFromContactsForm() { contactsForm.clearErrors(); @@ -597,8 +625,8 @@ // form) if (!edited && contactEdited != null) { ContactState contactState = contactEdited.getContactState(); - if (log.isDebugEnabled()) { - log.debug("For state : " + contactState); + if (logger.isDebugEnabled()) { + logger.debug("For state : " + contactState); } Date begin = contactEdited.getTideBeginDate(); @@ -678,27 +706,32 @@ @Log Object onSuccessFromContactsForm() { if (!edited && contactEdited != null) { + if (logger.isDebugEnabled()) { + logger.debug("Contact save : " + contactEdited); + logger.debug("Contact sendEmail : " + sendEmail); + } + serviceContact.saveContact(contactEdited, deleted); + try { - if (log.isDebugEnabled()) { - log.debug("Contact save : " + contactEdited); + if (sendEmail && serviceContact.sendContactDoneEmail(contactEdited)) { + layout.addInfo("Un email a été envoyé pour l'ajout du navire au portefeuille ALLEGRO."); } - serviceContact.saveContact(contactEdited, deleted); - contactSelectedId = contactEdited.getTopiaId(); - oldComment = null; - contactEdited = null; - } catch (WaoException eee) { - for (String msg : manager.getErrorMessages(eee, messages, log)) { - layout.addError(msg); - } + } catch (WaoBusinessException eee) { + String message = manager.getErrorMessage(eee, messages, logger); + layout.addError(message); } + + contactSelectedId = contactEdited.getTopiaId(); + oldComment = null; + contactEdited = null; } return this; } @Log Object onFailureFromContactsForm() { - if (log.isDebugEnabled()) { - log.debug("Contact can't be saved with errors"); + if (logger.isDebugEnabled()) { + logger.debug("Contact can't be saved with errors"); } // The contact is not saved, the contact must be editable to show form // and correct errors @@ -726,15 +759,8 @@ @Property private String extraComment; - @Environmental - private RenderSupport renderSupport; - - /** - * Instantiate the commentController javascript. - */ - @Log - void afterRender() { - renderSupport.addScript("commentController = new ContactComment();"); + protected void addCommentScript() { + renderSupport.addScript("commentController = new ContactComment();"); } /** Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactsKmlLoader.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactsKmlLoader.java 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ContactsKmlLoader.java 2010-07-07 17:49:30 UTC (rev 592) @@ -1,20 +1,15 @@ package fr.ifremer.wao.ui.pages; -import fr.ifremer.wao.WaoDAOHelper; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.service.ServiceCartography; import fr.ifremer.wao.service.ServiceUser; -import fr.ifremer.wao.ui.data.KmlStreamResponse; import fr.ifremer.wao.ui.data.RequiresAuthentication; import fr.ifremer.wao.ui.services.WaoManager; import org.apache.commons.lang.StringUtils; import org.apache.tapestry5.EventContext; import org.apache.tapestry5.StreamResponse; import org.apache.tapestry5.ioc.annotations.Inject; -import org.apache.tapestry5.ioc.internal.util.TapestryException; import org.apache.tapestry5.services.Response; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import java.io.IOException; import java.io.InputStream; Modified: trunk/wao-ui/src/main/webapp/Contacts.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Contacts.tml 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-ui/src/main/webapp/Contacts.tml 2010-07-07 17:49:30 UTC (rev 592) @@ -177,6 +177,7 @@ <t:zone t:id="gridZone"> <form t:type="form" t:id="contactsForm" t:zone="gridZone"> <t:errors id="so-contact-form-errors" t:banner="message:contactsForm-errors-banner"/> + <input t:type="hidden" t:id="hiddenSendEmail" t:value="sendEmail" /> <div t:type="grid" t:source="contacts" t:row="contact" class="t-data-grid ${gridClass}" t:model="contactModel" t:rowClass="prop:rowClass" t:rowsPerPage="20"> <p:createdByCell> Deleted: trunk/wao-ui/src/main/webapp/js/ContactComment.js =================================================================== --- trunk/wao-ui/src/main/webapp/js/ContactComment.js 2010-07-07 13:45:46 UTC (rev 591) +++ trunk/wao-ui/src/main/webapp/js/ContactComment.js 2010-07-07 17:49:30 UTC (rev 592) @@ -1,106 +0,0 @@ -/* - * #%L - * Wao :: Web Interface - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -/** - * This class is used to manage comment window for contacts. Two possible cases : - * - comment from current edition - * - direct comment for coordinator or admin - * The differences are in saveComment method. The openWindow method is used - * in template using a JSONObject from Java that contains comment data. - */ -ContactComment = Class.create({ - initialize: function() { - this.commentForm = $('commentForm'); - this.contactForm = $('contactsForm'); - - this.image = $('commentImage'); - this.invalidImage = $('commentInvalidImage'); - this.validImage = $('commentValidImage'); - - this.window = commentWindow; - }, - /** - * Open the commentWindow :: - * Use JSON to initialize data from template : - * - contact.edited : if a contact is currently in edition - * - contact.comment : comment value to initialize - * - contact.unfinished : if contact is in unfinished state - * - contact.id : id of the contact (used to save directly the comment) - */ - openWindow: function(contact) { - this.editionMode = contact.edited; - this.oldComment = contact.comment; - this.contactUnfinished = contact.unfinished; - - this.commentForm.editComment.setValue(this.oldComment); - this.commentForm.hiddenContactId.setValue(contact.id); - - this.window.showCenter(true); - }, - /** - * Save the comment :: - * If form is in edition, the comment will be push in existing input 'comment' - * otherwise the commentForm will be submitted to save the comment - */ - saveComment: function() { - - if (!this.editionMode) { - // Execute commentForm to save directly the comment - this.commentForm.submit(); - } else { - // Refresh edition form with comment - this.newComment = $F(this.commentForm.editComment); - this.refreshCommentImage(); - this.contactForm.comment.setValue(this.newComment); - } - - this.window.close(); - }, - /** - * Refresh the comment image (only in edition mode) :: - * Depends on contactUnfinished value to know if errors can occurs on comment - */ - refreshCommentImage: function() { - if (this.contactUnfinished && (!this.newComment || this.oldComment == this.newComment)) { - this.showImage(this.invalidImage); - this.hideImage(this.validImage); - this.hideImage(this.image); - } else if (this.oldComment != this.newComment) { - this.showImage(this.validImage); - this.hideImage(this.invalidImage); - this.hideImage(this.image); - } else { - this.showImage(this.image); - this.hideImage(this.validImage); - this.hideImage(this.invalidImage); - } - }, - showImage: function(image) { - if (image.hasClassName('hidden')) { - image.removeClassName('hidden'); - } - }, - hideImage: function(image) { - if (!image.hasClassName('hidden')) { - image.addClassName('hidden'); - } - } -}); \ No newline at end of file Copied: trunk/wao-ui/src/main/webapp/js/contacts.js (from rev 588, trunk/wao-ui/src/main/webapp/js/ContactComment.js) =================================================================== --- trunk/wao-ui/src/main/webapp/js/contacts.js (rev 0) +++ trunk/wao-ui/src/main/webapp/js/contacts.js 2010-07-07 17:49:30 UTC (rev 592) @@ -0,0 +1,120 @@ +/* + * #%L + * Wao :: Web Interface + * %% + * Copyright (C) 2009 - 2010 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +/** + * This class is used to manage comment window for contacts. Two possible cases : + * - comment from current edition + * - direct comment for coordinator or admin + * The differences are in saveComment method. The openWindow method is used + * in template using a JSONObject from Java that contains comment data. + */ +ContactComment = Class.create({ + initialize: function() { + this.commentForm = $('commentForm'); + this.contactForm = $('contactsForm'); + + this.image = $('commentImage'); + this.invalidImage = $('commentInvalidImage'); + this.validImage = $('commentValidImage'); + + this.window = commentWindow; + }, + /** + * Open the commentWindow :: + * Use JSON to initialize data from template : + * - contact.edited : if a contact is currently in edition + * - contact.comment : comment value to initialize + * - contact.unfinished : if contact is in unfinished state + * - contact.id : id of the contact (used to save directly the comment) + */ + openWindow: function(contact) { + this.editionMode = contact.edited; + this.oldComment = contact.comment; + this.contactUnfinished = contact.unfinished; + + this.commentForm.editComment.setValue(this.oldComment); + this.commentForm.hiddenContactId.setValue(contact.id); + + this.window.showCenter(true); + }, + /** + * Save the comment :: + * If form is in edition, the comment will be push in existing input 'comment' + * otherwise the commentForm will be submitted to save the comment + */ + saveComment: function() { + + if (!this.editionMode) { + // Execute commentForm to save directly the comment + this.commentForm.submit(); + } else { + // Refresh edition form with comment + this.newComment = $F(this.commentForm.editComment); + this.refreshCommentImage(); + this.contactForm.comment.setValue(this.newComment); + } + + this.window.close(); + }, + /** + * Refresh the comment image (only in edition mode) :: + * Depends on contactUnfinished value to know if errors can occurs on comment + */ + refreshCommentImage: function() { + if (this.contactUnfinished && (!this.newComment || this.oldComment == this.newComment)) { + this.showImage(this.invalidImage); + this.hideImage(this.validImage); + this.hideImage(this.image); + } else if (this.oldComment != this.newComment) { + this.showImage(this.validImage); + this.hideImage(this.invalidImage); + this.hideImage(this.image); + } else { + this.showImage(this.image); + this.hideImage(this.validImage); + this.hideImage(this.invalidImage); + } + }, + showImage: function(image) { + if (image.hasClassName('hidden')) { + image.removeClassName('hidden'); + } + }, + hideImage: function(image) { + if (!image.hasClassName('hidden')) { + image.addClassName('hidden'); + } + } +}); + +ContactSendEmail = Class.create({ + initialize: function(message, contactState) { + this.contactForm = $('contactsForm'); + this.contactState = contactState; + this.message = message; + this.contactForm.saveContact.observe('click', this.doConfirm.bind(this)); + }, + doConfirm: function(event) { + if (confirm(this.message) && $F(this.contactForm.contactState) == this.contactState) { + this.contactForm.hiddenSendEmail.setValue(true); + } + } +}); \ No newline at end of file
participants (1)
-
fdesbois@users.labs.libre-entreprise.org