Author: pyaschenko
Date: 2010-05-19 12:19:06 -0400 (Wed, 19 May 2010)
New Revision: 17129
Modified:
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
root/core/trunk/impl/src/test/resources/javascript/richfaces-client-api.html
root/core/trunk/impl/src/test/resources/javascript/richfaces-jsf-ajax-qunit.js
root/core/trunk/impl/src/test/resources/javascript/richfaces-queue-qunit-request.js
Log:
https://jira.jboss.org/browse/RF-8258
broken tests fix
Modified:
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
===================================================================
---
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-05-19
14:51:23 UTC (rev 17128)
+++
root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-05-19
16:19:06 UTC (rev 17129)
@@ -142,6 +142,16 @@
* */
getEventElement: function() {
return this.id;
+ },
+
+ /**
+ * Destroy method. Will be called before remove component from the page
+ *
+ * @function
+ * @name RichFaces.BaseComponent#destroy
+ *
+ * */
+ destroy: function() {
}
};
})(params));
Modified: root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-05-19
14:51:23 UTC (rev 17128)
+++ root/core/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2010-05-19
16:19:06 UTC (rev 17129)
@@ -9,7 +9,7 @@
* */
window.RichFaces = {};
-(function(richfaces, jQuery) {
+(function(jQuery, richfaces) {
// get DOM element by id or DOM element or jQuery object
richfaces.getDomElement = function (source) {
@@ -40,6 +40,30 @@
}
}
+ // find component and call his method
+ richfaces.invokeMethod = function(source, method) {
+ var c = richfaces.$(source);
+ if (c) {
+ var f = c[method];
+ if (typeof f == "function") {
+ return f.apply(c, Array.prototype.slice.call(arguments, 2));
+ }
+ }
+ }
+
+ //dom cleaner
+ richfaces.cleanDom = function(id) {
+ var e = document.getElementById(id);
+ var elements = e.getElementsByTagName("*");
+ jQuery.cleanData(elements);
+ jQuery.cleanData([e]);
+ jQuery.each(elements, function(index) {
+ richfaces.invokeMethod(this, "destroy");
+ });
+ richfaces.invokeMethod(e, "destroy");
+
+ }
+
//form.js
richfaces.submitForm = function(form, parameters, target) {
if (typeof form === "string") { form = jQuery(form) };
@@ -705,6 +729,24 @@
}
};
}()));
+
+ richfaces.ajax.onComplete = function (data) {
+ var type = data.type;
+ var responseXML = data.responseXML;
-}(RichFaces, jQuery));
+ if (type == 'complete' && responseXML) {
+ var partialResponse = jQuery(responseXML).children("partial-response");
+ if (partialResponse && partialResponse.length) {
+ var elements = partialResponse.children('changes').children('update,
delete');
+ jQuery.each(elements, function () {
+ richfaces.cleanDom(this.id);
+ });
+ }
+ }
+ };
+ // move this code to somewhere
+ if (typeof jsf != 'undefined') {
+ jsf.ajax.addOnEvent(richfaces.ajax.onComplete);
+ }
+}(jQuery, RichFaces));
Modified: root/core/trunk/impl/src/test/resources/javascript/richfaces-client-api.html
===================================================================
---
root/core/trunk/impl/src/test/resources/javascript/richfaces-client-api.html 2010-05-19
14:51:23 UTC (rev 17128)
+++
root/core/trunk/impl/src/test/resources/javascript/richfaces-client-api.html 2010-05-19
16:19:06 UTC (rev 17129)
@@ -8,10 +8,21 @@
<script type="text/javascript"
src="../../classes/META-INF/resources/jquery.js"></script>
<script type="text/javascript"
src="qunit/qunit.js"></script>
<script type="text/javascript"
src="timer-simulation.js"></script>
+ <script type="text/javascript"
src="richfaces-jsf-ajax-qunit.js"></script>
<script type="text/javascript"
src="../../classes/META-INF/resources/richfaces.js"></script>
- <script type="text/javascript"
src="richfaces-jsf-ajax-qunit.js"></script>
<script type="text/javascript"
src="../../classes/META-INF/resources/jquery.position.js"></script>
+ <script type="text/javascript">
+ // save handlers counter
+ jsf.ajax.__data = {};
+ jsf.ajax.__data.beforeEventHandlers = jsf.ajax.eventHandlerCounter;
+ jsf.ajax.__data.beforeErrorHandlers = jsf.ajax.errorHandlerCounter;
+ </script>
<script type="text/javascript"
src="../../classes/META-INF/resources/richfaces-queue.js"></script>
+ <script type="text/javascript">
+ // save handlers counter
+ jsf.ajax.__data.afterEventHandlers = jsf.ajax.eventHandlerCounter;
+ jsf.ajax.__data.afterErrorHandlers = jsf.ajax.errorHandlerCounter;
+ </script>
<script type="text/javascript"
src="../../classes/META-INF/resources/richfaces-base-component.js"></script>
<script type="text/javascript"
src="../../classes/META-INF/resources/richfaces-event.js"></script>
<script type="text/javascript"
src="richfaces-qunit.js"></script>
Modified: root/core/trunk/impl/src/test/resources/javascript/richfaces-jsf-ajax-qunit.js
===================================================================
---
root/core/trunk/impl/src/test/resources/javascript/richfaces-jsf-ajax-qunit.js 2010-05-19
14:51:23 UTC (rev 17128)
+++
root/core/trunk/impl/src/test/resources/javascript/richfaces-jsf-ajax-qunit.js 2010-05-19
16:19:06 UTC (rev 17129)
@@ -3,6 +3,8 @@
return {
eventHandlers:[],
errorHandlers:[],
+ eventHandlerCounter:0,
+ errorHandlerCounter:0,
request:function (source, event, options) {
for (var i=0; i<jsf.ajax.eventHandlers.length;i++) {
jsf.ajax.eventHandlers[i]({type:"event", status:"success"});
@@ -10,9 +12,11 @@
},
addOnEvent: function (handler) {
jsf.ajax.eventHandlers.push(handler);
+ this.eventHandlerCounter++;
},
addOnError: function (handler) {
jsf.ajax.errorHandlers.push(handler);
+ this.errorHandlerCounter++;
}
}
})();
Modified:
root/core/trunk/impl/src/test/resources/javascript/richfaces-queue-qunit-request.js
===================================================================
---
root/core/trunk/impl/src/test/resources/javascript/richfaces-queue-qunit-request.js 2010-05-19
14:51:23 UTC (rev 17128)
+++
root/core/trunk/impl/src/test/resources/javascript/richfaces-queue-qunit-request.js 2010-05-19
16:19:06 UTC (rev 17129)
@@ -56,10 +56,10 @@
// queue handlers
test("queue event and error handlers", function() {
expect(4);
- equals(jsf.ajax.eventHandlers.length, 1, "one event handler");
- equals(typeof jsf.ajax.eventHandlers[0], "function", "event handler is
function");
- equals(jsf.ajax.errorHandlers.length, 1, "one error handler");
- equals(typeof jsf.ajax.errorHandlers[0], "function", "error handler is
function");
+ equals(jsf.ajax.__data.afterEventHandlers - jsf.ajax.__data.beforeEventHandlers, 1,
"one event handler");
+ equals(typeof jsf.ajax.eventHandlers[jsf.ajax.__data.beforeEventHandlers],
"function", "event handler is function");
+ equals(jsf.ajax.__data.afterErrorHandlers - jsf.ajax.__data.beforeErrorHandlers, 1,
"one error handler");
+ equals(typeof jsf.ajax.errorHandlers[jsf.ajax.__data.beforeErrorHandlers],
"function", "error handler is function");
});
//jsf.ajax.request - parameters test