[Suiviobsmer-commits] r653 - in trunk/wao-ui/src/main: java/fr/ifremer/wao/ui/pages webapp/js
Author: fdesbois Date: 2010-10-03 16:15:23 +0000 (Sun, 03 Oct 2010) New Revision: 653 Log: Ano #2440 : Improve restriction on comment needed for unfinished state Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java trunk/wao-ui/src/main/webapp/js/contacts.js 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-10-03 15:59:15 UTC (rev 652) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-10-03 16:15:23 UTC (rev 653) @@ -87,7 +87,9 @@ * Created: 9 nov. 2009 * * @author fdesbois <fdesbois at codelutin.com> + * @version $Id$ */ + at SuppressWarnings({"UnusedDeclaration"}) @RequiresAuthentication({UserRole.ADMIN, UserRole.COORDINATOR, UserRole.OBSERVER}) @IncludeStylesheet("context:css/contacts.css") @IncludeJavaScriptLibrary("context:js/contacts.js") @@ -259,7 +261,7 @@ @Override public InputStream getStream() throws IOException { - InputStream result = null; + InputStream result; try { result = serviceContact.exportContactCsv( getContactFilter()); @@ -428,6 +430,9 @@ @Persist private String oldComment; + @Persist + private ContactState oldState; + public boolean hasActions() { return !user.isAdmin() && contact.getValidationCompany() == null && !user.isReadOnly(); @@ -541,6 +546,7 @@ //contactEditedId = contactId; contactSelectedId = contactId; oldComment = contactEdited.getComment(); + oldState = contactEdited.getContactState(); edited = true; } @@ -681,8 +687,14 @@ // Non abouti, Refus ou Refus Définitif if (contactState.isUnfinishedState()) { String newComment = contactEdited.getComment(); - if (StringUtils.isNotEmpty(newComment) && - !newComment.equals(oldComment)) { + + boolean commentChanged = + StringUtils.isNotEmpty(newComment) && + !newComment.equals(oldComment); + + // Ano #2440 : no restriction if previous state is unfinished + if (oldState.isUnfinishedState() || commentChanged) { + // RAZ des champs contactEdited.setTideBeginDate(null); contactEdited.setTideEndDate(null); Modified: trunk/wao-ui/src/main/webapp/js/contacts.js =================================================================== --- trunk/wao-ui/src/main/webapp/js/contacts.js 2010-10-03 15:59:15 UTC (rev 652) +++ trunk/wao-ui/src/main/webapp/js/contacts.js 2010-10-03 16:15:23 UTC (rev 653) @@ -46,10 +46,10 @@ */ openWindow: function(contact) { this.editionMode = contact.edited; - this.oldComment = contact.comment; - this.contactUnfinished = contact.unfinished; + this.oldContact = contact; - this.commentForm.editComment.setValue(this.oldComment); + // Edit current comment from contactForm + this.commentForm.editComment.setValue($F(this.contactForm.comment)); this.commentForm.hiddenContactId.setValue(contact.id); this.window.showCenter(true); @@ -66,31 +66,54 @@ this.commentForm.submit(); } else { // Refresh edition form with comment - this.newComment = $F(this.commentForm.editComment); - this.refreshCommentImage(); - this.contactForm.comment.setValue(this.newComment); + var newComment = $F(this.commentForm.editComment); + this.refreshCommentImage(newComment && this.oldContact.comment != newComment); + this.contactForm.comment.setValue(newComment); } this.window.close(); }, /** + * Return true if current state has changed and becomes unfinished + */ + isCommentMandatory: function() { + + var previouslyUnfinished = this.oldContact.unfinished; + var currentState = $F(this.contactForm.contactState); + + var becomesUnfinished = currentState == 'BOAT_UNAVAILABLE' || + currentState == 'BOAT_REFUSED' || + currentState == 'BOAT_DEFINITIVE_REFUSED'; + + return becomesUnfinished && !previouslyUnfinished; + }, + /** * Refresh the comment image (only in edition mode) :: * Depends on contactUnfinished value to know if errors can occurs on comment + * provides by return value of isCommentMandatory() function. + * - param : commentChanged boolean, true if comment has changed */ - refreshCommentImage: function() { - if (this.contactUnfinished && (!this.newComment || this.oldComment == this.newComment)) { + refreshCommentImage: function(commentChanged) { + + // VALID + if (commentChanged) { + this.showImage(this.validImage); + this.hideImage(this.invalidImage); + this.hideImage(this.image); + + // INVALID + } else if (this.isCommentMandatory()) { 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); + + // NO_CHANGE } else { this.showImage(this.image); + this.hideImage(this.invalidImage); this.hideImage(this.validImage); - this.hideImage(this.invalidImage); } + }, showImage: function(image) { if (image.hasClassName('hidden')) {
participants (1)
-
fdesbois@users.labs.libre-entreprise.org