Author: alexsmirnov
Date: 2011-01-26 19:14:48 -0500 (Wed, 26 Jan 2011)
New Revision: 21254
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/ClearMessageTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/DocumentReadyTest.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/MessageTestBase.java
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/SendMessageTest.java
Log:
CODING IN PROGRESS - issue RF-10064: Finish rich:message HTML design
https://issues.jboss.org/browse/RF-10064
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js 2011-01-27
00:14:17 UTC (rev 21253)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/message.js 2011-01-27
00:14:48 UTC (rev 21254)
@@ -44,28 +44,53 @@
var $super = rf.ui.Message.$super;
var defaultOptions = {
-
+ showSummary:true,
+ level:0
};
+ var
severetyClasses=["rf-msg-inf","rf-msg-wrn","rf-msg-err","rf-msg-ftl"];
var componentHash = {};
var componentIndex = 0;
var onMessage = function (event, element, data) {
+ var content = $(rf.getDomElement(this.id));
if (!this.options.forComponentId) {
var index = componentHash[data.sourceId];
if (typeof index != undefined) {
$(rf.getDomElement(this.id+index)).remove();
}
- var content = content = $(rf.getDomElement(this.id));
-
componentIndex ++;
- if (data.message) content.append('<li
id="'+this.id+componentIndex+'">'+data.message.summary+'</li>');
+ renderMessage.call(this,componentIndex,data.message);
componentHash[data.sourceId] = componentIndex;
} else if (this.options.forComponentId==data.sourceId) {
- rf.getDomElement(this.id).innerHTML = data.message ?
'<li>'+data.message.summary+'</li>' : '';
+ content.empty();
+ renderMessage.call(this,0,data.message);
}
}
+
+ var renderMessage = function(index,message){
+ if(message && message.severity >= this.options.level){
+ var content = $(rf.getDomElement(this.id));
+ var msgContent = "<span
class='"+severetyClasses[message.severity]+"'
id='"+this.id+index+"'";
+ if(message.summary){
+ if(this.options.tooltip){
+ msgContent = msgContent+"
title='"+message.summary+"'>";
+ } else if(this.options.showSummary ){
+ msgContent = msgContent + "><span
class='rf-msg-sum'>"+message.summary+"</span>";
+ } else {
+ msgContent = msgContent+">";
+ }
+ } else {
+ msgContent = msgContent+">";
+ }
+ if(this.options.showDetail && message.detail){
+ msgContent = msgContent + "<span
class='rf-msg-dtl'>"+message.detail+"</span>";
+ }
+ msgContent = msgContent+"</span>"
+ content.append(msgContent);
+ }
+ }
$.extend(rf.ui.Message.prototype, {
name: "Message",
Modified:
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-27
00:14:17 UTC (rev 21253)
+++
trunk/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-27
00:14:48 UTC (rev 21254)
@@ -53,15 +53,18 @@
$.extend(_messages, messagesObject);
},
getMessage: function(customMessage, messageId, values) {
- var message = customMessage ? customMessage : _messages[messageId] ||
{detail:"",summary:""};
- return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values)};
+ var message = customMessage ? customMessage : _messages[messageId] ||
{detail:"",summary:"",severity:0};
+ return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values),severity:message.severity};
},
interpolateMessage: function(message,values){
- return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values)};
+ return
{detail:__interpolateMessage(message.detail,values),summary:__interpolateMessage(message.summary,values),severity:message.severity};
},
sendMessage: function (componentId, message) {
rf.Event.fire(window.document, rf.Event.MESSAGE_EVENT_TYPE,
{'sourceId':componentId, 'message':message});
},
+ clearMessage: function(componentId){
+ rf.Event.fire(window.document, rf.Event.MESSAGE_EVENT_TYPE,
{'sourceId':componentId });
+ },
validate: function (event, id, element, params) {
var value = __getValue(element || id);
var convertedValue;
@@ -71,6 +74,7 @@
if (converter.f)
convertedValue = converter.f(value,id,converter.p,converter.m);
} catch (e){
+ e.severity=2;
rf.csv.sendMessage(id, e);
return false;
}
@@ -88,6 +92,7 @@
}
}
} catch (e) {
+ e.severity=2;
rf.csv.sendMessage(id, e);
return false;
}
@@ -95,7 +100,7 @@
if(!params.da && params.a){
params.a.call(element,event,id);
} else {
- rf.csv.sendMessage(id, "");
+ rf.csv.clearMessage(id);
}
return true;
},
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/ClearMessageTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/ClearMessageTest.java 2011-01-27
00:14:17 UTC (rev 21253)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/ClearMessageTest.java 2011-01-27
00:14:48 UTC (rev 21254)
@@ -50,7 +50,7 @@
@Override
protected String getMessageContent() {
- return "<li>Error</li>";
+ return "<span class='rf-msg-err'><span
class='rf-msg-sum'>"+ERROR_MESSAGE+"</span><span>";
}
@Override
protected String getJavaScriptFunctionName() {
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/DocumentReadyTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/DocumentReadyTest.java 2011-01-27
00:14:17 UTC (rev 21253)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/DocumentReadyTest.java 2011-01-27
00:14:48 UTC (rev 21254)
@@ -23,12 +23,9 @@
package org.richfaces.javascript.client.message;
-import static org.junit.Assert.*;
-
import org.jboss.test.qunit.Qunit.Builder;
import org.junit.Test;
-import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.javascript.host.Event;
/**
@@ -40,15 +37,12 @@
@Override
protected Builder createQunitPage() {
- return
super.createQunitPage().loadContent("$(document).ready(function(){"+MESSAGE_INIT+"});");
+ return
super.createQunitPage().loadContent("$(document).ready(function(){"+getMessageInit("")+"});");
}
@Test
public void testSend() throws Exception {
sendMessage();
- HtmlElement htmlElement = getMessageContentElement();
- String text = htmlElement.asText();
- assertTrue(text.contains(getErrorMessage().getSummary()));
}
@Test
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/MessageTestBase.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/MessageTestBase.java 2011-01-27
00:14:17 UTC (rev 21253)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/MessageTestBase.java 2011-01-27
00:14:48 UTC (rev 21254)
@@ -18,7 +18,6 @@
public static final String MY_MESSAGE = "form:uiMessage";
- public static final String MESSAGE_INIT = "new
RichFaces.ui.Message(\"" + MY_MESSAGE + "\",
{forComponentId:\"" + COMPONENT + "\"})";
@Rule
public final Qunit qunit;
@@ -28,19 +27,25 @@
}
public void setUpMessage(){
- qunit.runScript(MESSAGE_INIT);
+ setUpMessage("");
}
+ public void setUpMessage(String messageOptions){
+ qunit.runScript(getMessageInit(messageOptions));
+ }
+
protected Builder createQunitPage() {
return
Qunit.builder().emulate(BrowserVersion.FIREFOX_3_6).loadJsfResource("jquery.js").loadJsfResource("richfaces.js")
-
.loadJsfResource("richfaces-event.js").loadJsfResource("richfaces-base-component.js").
- loadJsfResource("csv.js",
"org.richfaces").loadJsfResource("message.js",
"org.richfaces").content("<form id=\"form\"
name=\"form\" method=\"post\" action=\"/client-test.jsf\"
enctype=\"application/x-www-form-urlencoded\">\n" +
+
.loadJsfResource("richfaces-event.js").loadJsfResource("richfaces-base-component.js")
+ .loadJsfResource("richfaces-csv.js",
"org.richfaces").loadJsfResource("message.js",
"org.richfaces")
+ .content("<form id=\"form\" name=\"form\"
method=\"post\" action=\"/client-test.jsf\"
enctype=\"application/x-www-form-urlencoded\">\n" +
" <input type=\"hidden\" name=\"form\"
value=\"form\"/>\n" +
" <input id=\"form:text\" type=\"text\"
name=\"form:text\" value=\"fooValue\"
onblur=\"form_3Atext_3Av("form:text",this,event)\"/>\n"
+
" <span id=\"form:out\">\n" +
" fooValue\n" +
- " </span><div id=\"foo\" ><ul
id=\"" + MY_MESSAGE +
"\">"+getMessageContent()+"</ul></div><input
type=\"hidden\" name=\"javax.faces.ViewState\"
id=\"javax.faces.ViewState\"
value=\"4262028796446907996:-2607792463910755035\"
autocomplete=\"off\"/>\n"
- + " </form>");
+ " </span><span id=\"" + MY_MESSAGE +
"\">"+getMessageContent()+"</span>"+
+ " <input type=\"hidden\"
name=\"javax.faces.ViewState\" id=\"javax.faces.ViewState\"
value=\"4262028796446907996:-2607792463910755035\"
autocomplete=\"off\"/>\n"+
+ " </form>");
}
@@ -58,7 +63,7 @@
}
protected Message getErrorMessage() {
- return new Message(2,"error","script error");
+ return new Message(2,"error summary","error description");
}
protected HtmlElement getMessageContentElement() {
@@ -68,4 +73,13 @@
return htmlElement;
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param messageOptions TODO
+ * @return the messageInit
+ */
+ public String getMessageInit(String messageOptions) {
+ return "new RichFaces.ui.Message(\"" + MY_MESSAGE + "\",
{forComponentId:\"" + COMPONENT +
"\""+messageOptions+"})";
+ }
+
}
Modified:
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/SendMessageTest.java
===================================================================
---
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/SendMessageTest.java 2011-01-27
00:14:17 UTC (rev 21253)
+++
trunk/ui/validator/ui/src/test/java/org/richfaces/javascript/client/message/SendMessageTest.java 2011-01-27
00:14:48 UTC (rev 21254)
@@ -38,11 +38,15 @@
@Test
public void testSend() throws Exception {
- setUpMessage();
+ setUpMessage(",showSummary:true");
sendMessage();
+ checkMessageContent(getErrorMessage().getSummary());
+ }
+
+ protected void checkMessageContent(String summary) {
HtmlElement htmlElement = getMessageContentElement();
String text = htmlElement.asText();
- assertTrue(text.contains(getErrorMessage().getSummary()));
+ assertTrue(text.contains(summary));
}
}