On 10/19/2010 4:28 PM, Endi Sukma Dewata wrote:
https://fedorahosted.org/reviewboard/r/95/

The ipa_cmd() has been modified to identity the type of the error
it has received and display the error using the right dialog box.
The dialog box can be customized further to display the appropriate
amount of information for each type of error.

I've rebased this patch on top of my patch #24. Thanks!

--
Endi S. Dewata
From 9f3336e1892dd26a3d8b861a4fa843b987162698 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Thu, 28 Oct 2010 09:50:34 -0500
Subject: [PATCH] Dialog boxes for AJAX, HTTP, and IPA errors.

The ipa_cmd() has been modified to identity the type of the error
it has received and display the error using the right dialog box.
The dialog box can be customized further to display the appropriate
amount of information for each type of error.
---
 install/static/associate.js |    2 +-
 install/static/details.js   |    2 +-
 install/static/ipa.js       |   88 ++++++++++++++++++++++++++++---------------
 install/static/search.js    |    2 +-
 install/static/webui.js     |    2 +-
 5 files changed, 61 insertions(+), 35 deletions(-)

diff --git a/install/static/associate.js b/install/static/associate.js
index a99fd907b264aceddd6e24a9442ca990308f1edf..7daa0cffb380a44d09c0b60a7c79140f30b20b9b 100644
--- a/install/static/associate.js
+++ b/install/static/associate.js
@@ -321,7 +321,7 @@ function ipa_association_facet(spec) {
         function refresh_on_error(xhr, text_status, error_thrown) {
             var search_results = $('.search-results', container).empty();
             search_results.append('<p>Error: '+error_thrown.name+'</p>');
-            search_results.append('<p>URL: '+this.url+'</p>');
+            search_results.append('<p>'+error_thrown.title+'</p>');
             search_results.append('<p>'+error_thrown.message+'</p>');
         }
 
diff --git a/install/static/details.js b/install/static/details.js
index d4593d82ee6f50cf4b025d92b8034a0e8d9c2bbc..e4cbec77e571e620b1c3f29aaa6f053c7a5c90aa 100644
--- a/install/static/details.js
+++ b/install/static/details.js
@@ -335,7 +335,7 @@ function ipa_details_load(container, pkey, on_win, on_fail)
 
         var details = $('.details', container).empty();
         details.append('<p>Error: '+error_thrown.name+'</p>');
-        details.append('<p>URL: '+this.url+'</p>');
+        details.append('<p>'+error_thrown.title+'</p>');
         details.append('<p>'+error_thrown.message+'</p>');
     }
 
diff --git a/install/static/ipa.js b/install/static/ipa.js
index 9da693051ecc14b556831a07d681e90135e849b3..d1558ee7c1d806df066cf5ae1fa53ab95523a80d 100644
--- a/install/static/ipa.js
+++ b/install/static/ipa.js
@@ -109,35 +109,7 @@ var IPA = function() {
  *   objname - name of an IPA object (optional) */
 function ipa_cmd(name, args, options, win_callback, fail_callback, objname)
 {
-    function ipa_success_handler(data, text_status, xhr) {
-        if (!data) {
-            var error_thrown = {
-                name: 'HTTP Error '+xhr.status,
-                message: data ? xhr.statusText : "No response"
-            };
-            ipa_error_handler.call(this, xhr, text_status, error_thrown);
-
-        } else if (data.error) {
-            var error_thrown = {
-                name: 'IPA Error '+data.error.code,
-                message: data.error.message
-            };
-            ipa_error_handler.call(this, xhr, text_status, error_thrown);
-
-        } else if (win_callback) {
-            win_callback.call(this, data, text_status, xhr);
-        }
-    }
-
-    function ipa_error_handler(xhr, text_status, error_thrown) {
-        IPA.error_dialog.empty();
-        IPA.error_dialog.attr('title', 'Error: '+error_thrown.name);
-
-        IPA.error_dialog.append('<p>URL: '+this.url+'</p>');
-        if (error_thrown.message) {
-            IPA.error_dialog.append('<p>'+error_thrown.message+'</p>');
-        }
-
+    function dialog_open(xhr, text_status, error_thrown) {
         var that = this;
 
         IPA.error_dialog.dialog({
@@ -156,6 +128,60 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname)
         });
     }
 
+    function success_handler(data, text_status, xhr) {
+        if (!data) {
+            var error_thrown = {
+                title: 'HTTP Error '+xhr.status,
+                message: data ? xhr.statusText : "No response"
+            };
+            http_error_handler.call(this, xhr, text_status, error_thrown);
+
+        } else if (data.error) {
+            var error_thrown = {
+                title: 'IPA Error '+data.error.code,
+                message: data.error.message
+            };
+            ipa_error_handler.call(this, xhr, text_status, error_thrown);
+
+        } else if (win_callback) {
+            win_callback.call(this, data, text_status, xhr);
+        }
+    }
+
+    function error_handler(xhr, text_status, error_thrown) {
+        error_thrown.title = 'AJAX Error: '+error_thrown.name;
+        ajax_error_handler.call(this, xhr, text_status, error_thrown);
+    }
+
+    function ajax_error_handler(xhr, text_status, error_thrown) {
+        IPA.error_dialog.empty();
+        IPA.error_dialog.attr('title', error_thrown.title);
+
+        IPA.error_dialog.append('<p>URL: '+this.url+'</p>');
+        IPA.error_dialog.append('<p>'+error_thrown.message+'</p>');
+
+        dialog_open.call(this, xhr, text_status, error_thrown);
+    }
+
+    function http_error_handler(xhr, text_status, error_thrown) {
+        IPA.error_dialog.empty();
+        IPA.error_dialog.attr('title', error_thrown.title);
+
+        IPA.error_dialog.append('<p>URL: '+this.url+'</p>');
+        IPA.error_dialog.append('<p>'+error_thrown.message+'</p>');
+
+        dialog_open.call(this, xhr, text_status, error_thrown);
+    }
+
+    function ipa_error_handler(xhr, text_status, error_thrown) {
+        IPA.error_dialog.empty();
+        IPA.error_dialog.attr('title', error_thrown.title);
+
+        IPA.error_dialog.append('<p>'+error_thrown.message+'</p>');
+
+        dialog_open.call(this, xhr, text_status, error_thrown);
+    }
+
     var id = ipa_jsonrpc_id++;
 
     var method_name = name;
@@ -180,8 +206,8 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname)
     var request = {
         url: url,
         data: JSON.stringify(data),
-        success: ipa_success_handler,
-        error: ipa_error_handler
+        success: success_handler,
+        error: error_handler
     };
 
     $.ajax(request);
diff --git a/install/static/search.js b/install/static/search.js
index fd123c0940360c331ad7d12acbf460079ed34ac7..62fffbe99b45f9832175eb15fbbebe5dce98df72 100644
--- a/install/static/search.js
+++ b/install/static/search.js
@@ -296,7 +296,7 @@ function search_load(container, criteria, on_win, on_fail)
 
         var search_results = $('.search-results', container);
         search_results.append('<p>Error: '+error_thrown.name+'</p>');
-        search_results.append('<p>URL: '+this.url+'</p>');
+        search_results.append('<p>'+error_thrown.title+'</p>');
         search_results.append('<p>'+error_thrown.message+'</p>');
     }
 
diff --git a/install/static/webui.js b/install/static/webui.js
index 42c559dce494f9fceb84e4e348e01f13a3e59bf9..804f06f8633fbe70d497ec4edc09a3d18ef23a9f 100644
--- a/install/static/webui.js
+++ b/install/static/webui.js
@@ -94,7 +94,7 @@ $(function() {
     function init_on_error(xhr, text_status, error_thrown) {
         var navigation = $('#navigation').empty();
         navigation.append('<p>Error: '+error_thrown.name+'</p>');
-        navigation.append('<p>URL: '+this.url+'</p>');
+        navigation.append('<p>'+error_thrown.title+'</p>');
         navigation.append('<p>'+error_thrown.message+'</p>');
     }
 
-- 
1.6.6.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to