You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/08/16 03:08:56 UTC

svn commit: r1158076 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5: default.css t5-ajax.js t5-dom.js t5-prototype.js t5-spi.js tapestry.js

Author: hlship
Date: Tue Aug 16 01:08:55 2011
New Revision: 1158076

URL: http://svn.apache.org/viewvc?rev=1158076&view=rev
Log:
TAP5-1308: Initial progress on making Ajax exceptions display in a pop-up iframe

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-ajax.js
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-dom.js
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-prototype.js
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-spi.js
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css?rev=1158076&r1=1158075&r2=1158076&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/default.css Tue Aug 16 01:08:55 2011
@@ -481,15 +481,43 @@ DIV.t-page-loading-banner {
     border-bottom: 2px solid black;
 }
 
-SPAN.t-render-object-error
-{
-  font-weight: bold;
-  font: italic;
-  color: red;
+SPAN.t-render-object-error {
+    font-weight: bold;
+    font: italic;
+    color: red;
 }
 
-DIV.t-available-values UL LI
-{
-  list-style-type : disc;
-  margin-left: 0px;
+DIV.t-available-values UL LI {
+    list-style-type: disc;
+    margin-left: 0px;
+}
+
+DIV.t-exception-container {
+    background: white;
+    border: 1px solid black;
+    position: fixed;
+    width: 80%;
+    top: 30px;
+    left: 10%;
+    -moz-box-shadow: 6px 6px 3px #888;
+    -webkit-box-shadow: 6px 6px 3px #888;
+    box-shadow: 6px 6px 3px #888;
+
+}
+
+DIV.t-exception-frame {
+}
+
+DIV.t-exception-container .t-exception-close {
+    display: block;
+    float: right;
+    margin-left: 3px;
+    margin-bottom: 3px;
+    cursor: pointer;
+    width: 16px;
+    height: 16px;
+    background: url("silk/delete.png");
+    border-radius: 5px;
+    -moz-border-radius: 5px;
+    -webkit-border-radius: 5px;
 }
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-ajax.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-ajax.js?rev=1158076&r1=1158075&r2=1158076&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-ajax.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-ajax.js Tue Aug 16 01:08:55 2011
@@ -21,56 +21,111 @@
  */
 T5.define("ajax", function() {
 
-	var $ = T5.$;
-	var spi = T5.spi;
+    var $ = T5.$;
+    var spi = T5.spi;
 
-    function noop() { }
+    var exceptionContainer, iframe, iframeDocument;
 
-	function defaultFailure(transport) {
-	}
-	
-	function defaultException(exception) {
-	}
-	
-	/**
-	 * Performs an AJAX request. The options object is used to identify
-	 * additional parameters to be encoded into the request, and to identify the
-	 * handlers for success and failure.
-	 * <p>
-	 * Option keys:
-	 * <dl>
-	 * <dt>parameters
-	 * <dd>object with string keys and string values, defines additional query
-	 * parameters
-	 * <dt>failure
-	 * <dd>A function invoked if the Ajax request fails; the function is passed
-	 * the transport
-	 * <dt>exception
-	 * <dd>A function invoked if there's an exception processing the Ajax
-	 * request, the function is passed the exception
-	 * <dt>success
-	 * <dd>A function invoked when the Ajax response is returned successfully.
-	 * The function is passed the transport object.
-	 * <dt>method
-	 * <dd>The type of request, 'get' or 'post'. 'post' is the default.
-	 * </dl>
-	 * 
-	 * @param url
-	 *            the URL for the request
-	 * @param options
-	 *            an optional object that provides additional options.
-	 * @return not defined
-	 * 
-	 */
-	function request(url, options) {
-		
-  throw "not yet implemented";
-	}
-
-	return {
-		defaultFailure : defaultFailure,
-		defaultException : defaultException,
-		defaultSuccess : noop,
-		request : request
-	};
+    function noop() {
+    }
+
+    function writeToErrorIFrame(content) {
+        // Clear current content.
+        iframeDocument.open();
+        // Write in the new content.
+        iframeDocument.write(content);
+        iframeDocument.close();
+
+    }
+
+    /**
+     * When there's a server-side failure, Tapestry sends back the exception report page as HTML.
+     * This function creates and displays a dialog that presents that content to the user using
+     * a created iframe element.
+     * @param exceptionContext HTML markup for the exception report
+     */
+    function showExceptionDialog(exceptionContent) {
+
+        if (!exceptionContainer) {
+            var markup = [ "<div class='t-exception-container'>",
+                "<iframe class='t-exception-frame' width='100%'></iframe>",
+                "<div class='t-exception-controls'>",
+                "<span class='t-exception-close'>Close</span>",
+                "</div>",
+                "</div>"].join("");
+
+            exceptionContainer = T5.dom.find(T5.dom.appendMarkup(document.body, markup), 'div.t-exception-container');
+
+            iframe = T5.dom.find(exceptionContainer, "iframe");
+
+            // See http://xkr.us/articles/dom/iframe-document/
+
+            iframeDocument = (iframe.contentWindow || iframe.contentDocument);
+            if (iframeDocument.document) {
+                iframeDocument = iframeDocument.document;
+            }
+
+            var closeButton = T5.dom.find(exceptionContainer, ".t-exception-close");
+
+            T5.dom.observe(closeButton, "click", function(event) {
+                event.stop();
+                writeToErrorIFrame("");
+                T5.dom.hide(exceptionContainer);
+            });
+        }
+
+
+        writeToErrorIFrame(exceptionContent);
+
+        exceptionContainer.show();
+    }
+
+    function defaultFailure(transport) {
+    }
+
+    function defaultException(exception) {
+    }
+
+    /**
+     * Performs an AJAX request. The options object is used to identify
+     * additional parameters to be encoded into the request, and to identify the
+     * handlers for success and failure.
+     * <p>
+     * Option keys:
+     * <dl>
+     * <dt>parameters
+     * <dd>object with string keys and string values, defines additional query
+     * parameters
+     * <dt>failure
+     * <dd>A function invoked if the Ajax request fails; the function is passed
+     * the transport
+     * <dt>exception
+     * <dd>A function invoked if there's an exception processing the Ajax
+     * request, the function is passed the exception
+     * <dt>success
+     * <dd>A function invoked when the Ajax response is returned successfully.
+     * The function is passed the transport object.
+     * <dt>method
+     * <dd>The type of request, 'get' or 'post'. 'post' is the default.
+     * </dl>
+     *
+     * @param url
+     *            the URL for the request
+     * @param options
+     *            an optional object that provides additional options.
+     * @return not defined
+     *
+     */
+    function request(url, options) {
+
+        throw "not yet implemented";
+    }
+
+    return {
+        defaultFailure : defaultFailure,
+        defaultException : defaultException,
+        defaultSuccess : noop,
+        showExceptionDialog: showExceptionDialog,
+        request : request
+    };
 });
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-dom.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-dom.js?rev=1158076&r1=1158075&r2=1158076&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-dom.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-dom.js Tue Aug 16 01:08:55 2011
@@ -140,6 +140,7 @@ T5.define("dom", function() {
         find : T5.spi.find,
         hide : T5.spi.hide,
         show : T5.spi.show,
+        appendMarkup : T5.spi.appendMarkup,
         publishEvent : publishEvent
     };
 });

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-prototype.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-prototype.js?rev=1158076&r1=1158075&r2=1158076&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-prototype.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-prototype.js Tue Aug 16 01:08:55 2011
@@ -40,11 +40,20 @@ T5.extend(T5.spi, function() {
         );
     });
 
+    function appendMarkup(element, markup) {
+        var element = $(element);
+
+        element.insert({ bottom: markup });
+
+        return element;
+    }
+
     return {
         observe : observe,
         find : Element.down,
         show : Element.show,
-        hide : Element.hide
+        hide : Element.hide,
+        appendMarkup : appendMarkup
     };
 });
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-spi.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-spi.js?rev=1158076&r1=1158075&r2=1158076&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-spi.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-spi.js Tue Aug 16 01:08:55 2011
@@ -41,6 +41,7 @@ T5.define("spi", {
      *
      * @param element DOM element or element id
      * @param selector CSS selector to locate
+     * @return the element, or undefined if not found
      */
     find : undefined,
 
@@ -56,6 +57,15 @@ T5.define("spi", {
     show : undefined,
 
     /**
+     * Appends new markup to an existing element's body.
+     *
+     * @param element DOM element or element id
+     * @param markup new content as markup string
+     * @return element
+     */
+    appendMarkup: undefined,
+
+    /**
      * Performs an ajax request, as per T5.ajax.request(). Supplied by the SPI
      * implementation.
      *

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js?rev=1158076&r1=1158075&r2=1158076&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js Tue Aug 16 01:08:55 2011
@@ -390,6 +390,10 @@ var Tapestry = {
         Tapestry.error(Tapestry.Messages.communicationFailed + message);
 
         Tapestry.debug(Tapestry.Messages.ajaxFailure + message, response);
+
+        // Assuming here that it is text/html. Should we check?
+
+        T5.ajax.showExceptionDialog(response.responseText)
     },
 
     /**