Author: fdesbois Date: 2010-10-03 17:34:06 +0000 (Sun, 03 Oct 2010) New Revision: 654 Log: Ano #2440 : Improve restriction on comment needed for unfinished state : - didn't work if errors appears in form Modified: trunk/changelog.txt trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java trunk/wao-ui/src/main/webapp/js/contacts.js Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2010-10-03 16:15:23 UTC (rev 653) +++ trunk/changelog.txt 2010-10-03 17:34:06 UTC (rev 654) @@ -14,6 +14,9 @@ Anomalies +++++++++ +- [fdesbois] Ano #2440 : Commentaire obligatoire sur refus non abouti depuis + refus définitif. + Mise à jour librairies ++++++++++++++++++++++ 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 16:15:23 UTC (rev 653) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-10-03 17:34:06 UTC (rev 654) @@ -684,6 +684,18 @@ " du jour"); } + if (logger.isDebugEnabled()) { + logger.debug("IsUnfinished : " + contactState.isUnfinishedState()); + logger.debug("OldUnfinished : " + oldState.isUnfinishedState()); + + String newComment = contactEdited.getComment(); + boolean commentDefined = StringUtils.isNotEmpty(newComment); + boolean commentChanged = commentDefined && !newComment.equals(oldComment); + + logger.debug("commentDefined : " + commentDefined); + logger.debug("commentChanged : " + commentChanged); + } + // Non abouti, Refus ou Refus Définitif if (contactState.isUnfinishedState()) { String newComment = contactEdited.getComment(); @@ -693,7 +705,8 @@ !newComment.equals(oldComment); // Ano #2440 : no restriction if previous state is unfinished - if (oldState.isUnfinishedState() || commentChanged) { + if (oldState.isUnfinishedState() && + StringUtils.isNotEmpty(newComment) || commentChanged) { // RAZ des champs contactEdited.setTideBeginDate(null); @@ -785,7 +798,8 @@ private String extraComment; protected void addCommentScript() { - renderSupport.addScript("commentController = new ContactComment();"); + renderSupport.addScript("commentController = new ContactComment('" + + contactsForm.getClientId() + "');"); } /** @@ -818,6 +832,9 @@ */ public JSONObject getCommentData() { JSONObject json = new JSONObject(); + if (isEditionMode()) { + json.put("formId", contactsForm.getClientId()); + } json.put("id", contact.getId()); json.put("edited", isEditionMode()); json.put("unfinished", contact.getContactState().isUnfinishedState()); Modified: trunk/wao-ui/src/main/webapp/js/contacts.js =================================================================== --- trunk/wao-ui/src/main/webapp/js/contacts.js 2010-10-03 16:15:23 UTC (rev 653) +++ trunk/wao-ui/src/main/webapp/js/contacts.js 2010-10-03 17:34:06 UTC (rev 654) @@ -28,7 +28,6 @@ ContactComment = Class.create({ initialize: function() { this.commentForm = $('commentForm'); - this.contactForm = $('contactsForm'); this.image = $('commentImage'); this.invalidImage = $('commentInvalidImage'); @@ -39,19 +38,29 @@ /** * 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) + * - data.edited : if a contact is currently in edition + * - data.comment : comment value to initialize + * - data.unfinished : if contact is in unfinished state + * - data.id : id of the contact (used to save directly the comment) + * - data.formId : id of the contactsForm in edition mode (edited = true) */ - openWindow: function(contact) { - this.editionMode = contact.edited; - this.oldContact = contact; + openWindow: function(data) { + this.editionMode = data.edited; + this.oldUnfinished = data.unfinished; + this.oldComment = data.comment; - // Edit current comment from contactForm - this.commentForm.editComment.setValue($F(this.contactForm.comment)); - this.commentForm.hiddenContactId.setValue(contact.id); + // Init comment from argument + var comment = data.comment; + if (data.formId) { + // Init contactsForm + this.contactForm = $(data.formId); + comment = $F(this.contactForm.comment); + } + // Update commentForm + this.commentForm.editComment.setValue(comment); + this.commentForm.hiddenContactId.setValue(data.id); + this.window.showCenter(true); }, /** @@ -67,25 +76,27 @@ } else { // Refresh edition form with comment var newComment = $F(this.commentForm.editComment); - this.refreshCommentImage(newComment && this.oldContact.comment != newComment); + this.refreshCommentImage(newComment); this.contactForm.comment.setValue(newComment); } this.window.close(); }, /** - * Return true if current state has changed and becomes unfinished + * Return true if current state has changed and becomes unfinished. + * NewComment need to be defined. */ - isCommentMandatory: function() { + isCommentValid: function(newComment) { - var previouslyUnfinished = this.oldContact.unfinished; var currentState = $F(this.contactForm.contactState); - var becomesUnfinished = currentState == 'BOAT_UNAVAILABLE' || + var isUnfinished = currentState == 'BOAT_UNAVAILABLE' || currentState == 'BOAT_REFUSED' || currentState == 'BOAT_DEFINITIVE_REFUSED'; - return becomesUnfinished && !previouslyUnfinished; + var becomesUnfinished = isUnfinished && !this.oldUnfinished; + + return newComment && (isUnfinished || becomesUnfinished); }, /** * Refresh the comment image (only in edition mode) :: @@ -93,16 +104,16 @@ * provides by return value of isCommentMandatory() function. * - param : commentChanged boolean, true if comment has changed */ - refreshCommentImage: function(commentChanged) { + refreshCommentImage: function(newComment) { // VALID - if (commentChanged) { + if (newComment && this.oldComment != newComment) { this.showImage(this.validImage); this.hideImage(this.invalidImage); this.hideImage(this.image); // INVALID - } else if (this.isCommentMandatory()) { + } else if (!this.isCommentValid(newComment)) { this.showImage(this.invalidImage); this.hideImage(this.validImage); this.hideImage(this.image); @@ -129,14 +140,16 @@ 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)); + $('contactsForm').saveContact.observe('click', this.doConfirm.bind(this)); }, doConfirm: function(event) { - if ($F(this.contactForm.contactState) == this.contactState && confirm(this.message)) { - this.contactForm.hiddenSendEmail.setValue(true); + + var contactForm = event.element().form; + + if ($F(contactForm.contactState) == this.contactState && confirm(this.message)) { + contactForm.hiddenSendEmail.setValue(true); } } });