Author: fdesbois Date: 2009-12-08 13:45:12 +0000 (Tue, 08 Dec 2009) New Revision: 114 Added: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/mixins/Confirm.java trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceContactMock.java trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml trunk/suiviobsmer-ui/src/main/webapp/css/common.css Log: Evol #1954 : Contact row can be suppress if not validated yet Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2009-12-08 13:08:53 UTC (rev 113) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2009-12-08 13:45:12 UTC (rev 114) @@ -115,7 +115,7 @@ } @Override - public void createUpdateContact(Contact contact) throws SuiviObsmerException { + public void saveContact(Contact contact, boolean delete) throws SuiviObsmerException { TopiaContext transaction = null; try { transaction = rootContext.beginTransaction(); @@ -123,13 +123,17 @@ ContactDAO dao = SuiviObsmerModelDAOHelper.getContactDAO(transaction); SuiviObsmerUtils.prepareTopiaId(Contact.class, contact); - dao.update(contact); + if (delete) { + dao.delete(contact); + } else { + dao.update(contact); + } transaction.commitTransaction(); transaction.closeContext(); } catch (Exception eee) { SuiviObsmerUtils.serviceException(transaction, - "Impossible de filtrer la liste des contacts", eee); + "Impossible de sauvegarder le contact", eee); } } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceContactMock.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceContactMock.java 2009-12-08 13:08:53 UTC (rev 113) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceContactMock.java 2009-12-08 13:45:12 UTC (rev 114) @@ -255,7 +255,7 @@ } @Override - public void createUpdateContact(Contact contact) throws SuiviObsmerException { + public void saveContact(Contact contact, boolean delete) throws SuiviObsmerException { throw new UnsupportedOperationException("Not supported yet."); } Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo =================================================================== (Binary files differ) Added: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/mixins/Confirm.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/mixins/Confirm.java (rev 0) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/mixins/Confirm.java 2009-12-08 13:45:12 UTC (rev 114) @@ -0,0 +1,65 @@ +/** + * *##% Ca$h Web Interface + * Copyright (C) 2009 CodeLutin + * + * 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 Lesser 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>. ##%* + */ + +package fr.ifremer.suiviobsmer.ui.mixins; + +import org.apache.tapestry5.BindingConstants; +import org.apache.tapestry5.ClientElement; +import org.apache.tapestry5.RenderSupport; +import org.apache.tapestry5.annotations.AfterRender; +import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary; +import org.apache.tapestry5.annotations.InjectContainer; +import org.apache.tapestry5.annotations.Parameter; +import org.apache.tapestry5.ioc.annotations.Inject; + +/** + * Confirm.java + * + * A simple mixin for attaching a javascript confirmation box to the onclick + * event of any component that implements ClientElement. + * + * @author fdesbois + * @version $Revision: 3 $ + * + * Last update: $Date: 2009-07-31 16:54:15 +0200 (ven. 31 juil. 2009) $ + * by : $Author: fdesbois $ + */ + at IncludeJavaScriptLibrary("context:js/dialog.js") +public class Confirm { + + @Parameter(value = "Are you sure?", defaultPrefix = BindingConstants.LITERAL) + private String message; + + @Inject + private RenderSupport renderSupport; + + @InjectContainer + private ClientElement element; + + @Parameter + private boolean wDisabled; + + @AfterRender + public void afterRender() { + if (!wDisabled) { + renderSupport.addScript(String.format("new Confirm('%s', '%s');",element.getClientId(), message)); + } + } + +} Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2009-12-08 13:08:53 UTC (rev 113) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2009-12-08 13:45:12 UTC (rev 114) @@ -108,13 +108,8 @@ void setupRender() throws SuiviObsmerException { contacts = null; getContacts(); - //editableContactId = null; } -// public User getUser() { -// return layout.getCurrentUser(); -// } - void onActivate(EventContext ec) { if (ec.getCount() > 0) { boatId = ec.get(String.class, 0); @@ -130,15 +125,6 @@ /**************************** NEW CONTACT *********************************/ -// @Inject -// private PropertyAccess propertyAccess; -// -// @Persist -// private GenericSelectModel<SampleRow> sampleRowSelectModel; - -// @Persist -// private GenericSelectModel<Boat> boatSelectModel; - private Contact newContact; private Boat boat; @@ -159,37 +145,9 @@ return sampleRow; } -// public GenericSelectModel<SampleRow> getSampleRowSelectModel() throws SuiviObsmerException { -// if (sampleRowSelectModel == null) { -// if (log.isInfoEnabled()) { -// log.info("BUSINESS REQUEST [getSampleRowsForUser]"); -// } -// List<SampleRow> sampleRows = serviceSampling.getSampleRowsForUser(getUser()); -// sampleRowSelectModel = new GenericSelectModel<SampleRow>(sampleRows, SampleRow.class, -// "code", "topiaId", propertyAccess); -// } -// return sampleRowSelectModel; -// } - - -// public GenericSelectModel<Boat> getBoatSelectModel() throws SuiviObsmerException { -// if (boatSelectModel == null) { -// if (log.isInfoEnabled()) { -// log.info("BUSINESS REQUEST [getBoatsForUser]"); -// } -// List<Boat> boats = serviceBoat.getBoatsForUser(getUser()); -// boatSelectModel = new GenericSelectModel<Boat>(boats, Boat.class, -// "name", "topiaId", propertyAccess); -// } -// return boatSelectModel; -// } - public Contact getNewContact() throws SuiviObsmerException { if (newContact == null) { - //Boat boat = getBoatSelectModel().findObject(boatId); - //SampleRow sampleRow = getSampleRowSelectModel().findObject(sampleRowId); newContact = serviceContact.getNewContact(user, getSampleRow(), getBoat()); - //editableContactId = ""; } return newContact; } @@ -283,6 +241,9 @@ } else if (BooleanUtils.isFalse(contact.getValidationProgram()) || (!user.getAdmin() && BooleanUtils.isFalse(contact.getValidationCompany()))) { return "refused"; + } else if (BooleanUtils.isTrue(contact.getValidationProgram()) || + (!user.getAdmin() && BooleanUtils.isTrue(contact.getValidationCompany()))) { + return "accepted"; } return even ? "even" : "odd"; } @@ -303,14 +264,14 @@ private boolean contactEdited; + private boolean contactDeleted; + public boolean hasActions() { // pour un non admin : affichage si aucune des deux validations ont été effectuées if (!user.getAdmin()) { return contact.getValidationCompany() == null && contact.getValidationProgram() == null; } - // OLD pour un admin : affichage si la compagnie n'a pas encore validé ou l'a fait positivement - // isNotFalse // pour un admin : affichage uniquement si la compagnie a validé la ligne return BooleanUtils.isTrue(contact.getValidationCompany()); } @@ -347,17 +308,21 @@ void onSelectedFromEditContact(String contactId) { editableContactId = contactId; - contactEdited = true; contactSelectedId = contactId; + contactEdited = true; } + void onSelectedFromDeleteContact(String contactId) throws SuiviObsmerException { + contact = getContacts().get(contactId); + contactDeleted = true; + } + void onSelectedFromSaveContact(String contactId) throws SuiviObsmerException { contact = getContacts().get(contactId); } void onSelectedFromCancelEditContact() throws SuiviObsmerException { contactEdited = true; - //editableContactId = null; } /**************************** CONTACT SAVE ********************************/ @@ -371,19 +336,17 @@ if (log.isDebugEnabled()) { log.debug("Contact save : " + contact); } - serviceContact.createUpdateContact(contact); - //layout.getFeedBack().addInfo("Contact sauvegardé !"); + serviceContact.saveContact(contact, contactDeleted); contactSelectedId = contact.getTopiaId(); } catch (SuiviObsmerException eee) { layout.getFeedBack().addError(eee.getMessage()); } - //editableContactId = null; } } public void createNewContact(Boat boat, SampleRow sampleRow) throws SuiviObsmerException { contact = serviceContact.getNewContact(user, sampleRow, boat); - serviceContact.createUpdateContact(contact); + serviceContact.saveContact(contact, Boolean.FALSE); contactSelectedId = contact.getTopiaId(); } } Modified: trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml 2009-12-08 13:08:53 UTC (rev 113) +++ trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml 2009-12-08 13:45:12 UTC (rev 114) @@ -94,6 +94,9 @@ <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="deleteContact" class="ico22px delete" value="Delete" + t:context="contact.topiaId" title="Supprimer le contact" + t:mixins="confirm" t:message="Etes-vous sûr de vouloir supprimer définitivement ce contact ?" /> </p:else> </t:if> </t:unless> Modified: trunk/suiviobsmer-ui/src/main/webapp/css/common.css =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/css/common.css 2009-12-08 13:08:53 UTC (rev 113) +++ trunk/suiviobsmer-ui/src/main/webapp/css/common.css 2009-12-08 13:45:12 UTC (rev 114) @@ -150,6 +150,10 @@ background: url(../img/edit.png) no-repeat center center; } +input.delete { + background: url(../img/delete2.png) no-repeat center center; +} + input.remove { width: 22px; height: 22px; @@ -237,6 +241,9 @@ background-color: #ffaaaa; } +table.t-data-grid tbody tr.accepted { + background-color: #8dff98; +} /** FILTERS COMPONENT **/ div.so-filters { width: 60%; Added: trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js (rev 0) +++ trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js 2009-12-08 13:45:12 UTC (rev 114) @@ -0,0 +1,19 @@ +/** + * Dialogue de confirmation + */ +var Confirm = Class.create({ + /** + * element : Element DOM depuis lequel le dialogue de confirmation va s'ouvrir + * message : Message à afficher dans la boîte de dialogue + */ + initialize: function(element, message) { + this.message = message; + Event.observe($(element), 'click', this.doConfirm.bindAsEventListener(this)); + }, + doConfirm: function(e) { + if(! confirm(this.message)) { + //Tapestry.debug('STOP ' + e); + Event.stop(e); + } + } +});