Hi,

Please review the attached patch. Thanks!

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.

--
Endi S. Dewata
From 38922bc54eb26a87d3edff54d5a3c1c9fb445d74 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Tue, 19 Oct 2010 15:41:04 -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 |    3 +-
 install/static/details.js   |    3 +-
 install/static/ipa.js       |   78 ++++++++++++++++++++++++++++--------------
 install/static/search.js    |    3 +-
 install/static/webui.js     |    3 +-
 5 files changed, 56 insertions(+), 34 deletions(-)

diff --git a/install/static/associate.js b/install/static/associate.js
index 49f2fd5..9d6d4e8 100644
--- a/install/static/associate.js
+++ b/install/static/associate.js
@@ -243,8 +243,7 @@ function AssociationList(obj, pkey, manyObj, associationColumns, jobj, associati
 
         function refresh_on_error(xhr, text_status, error_thrown) {
             var search_results = $('.search-results', jobj).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 cb4aab1..aadc69b 100644
--- a/install/static/details.js
+++ b/install/static/details.js
@@ -245,8 +245,7 @@ function ipa_details_load(container, pkey, on_win, on_fail)
             on_fail(xhr, text_status, error_thrown);
 
         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 b436ba9..5196723 100644
--- a/install/static/ipa.js
+++ b/install/static/ipa.js
@@ -76,17 +76,36 @@ function ipa_init(url, use_static_files, on_win, on_error)
  *   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) {
+    function dialog_open(xhr, text_status, error_thrown) {
+        var that = this;
+
+        ipa_dialog.dialog({
+            modal: true,
+            width: 400,
+            buttons: {
+                'Retry': function() {
+                    ipa_dialog.dialog('close');
+                    ipa_cmd(name, args, options, win_callback, fail_callback, objname);
+                },
+                'Cancel': function() {
+                    ipa_dialog.dialog('close');
+                    fail_callback.call(that, xhr, text_status, error_thrown);
+                }
+            }
+        });
+    }
+
+    function success_handler(data, text_status, xhr) {
         if (!data) {
             var error_thrown = {
-                name: 'HTTP Error '+xhr.status,
+                title: 'HTTP Error: '+xhr.status,
                 message: data ? xhr.statusText : "No response"
             };
-            ipa_error_handler.call(this, xhr, text_status, error_thrown);
+            http_error_handler.call(this, xhr, text_status, error_thrown);
 
         } else if (data.error) {
             var error_thrown = {
-                name: 'IPA Error '+data.error.code,
+                title: 'IPA Error: '+data.error.code,
                 message: data.error.message
             };
             ipa_error_handler.call(this, xhr, text_status, error_thrown);
@@ -96,31 +115,38 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname)
         }
     }
 
-    function ipa_error_handler(xhr, text_status, error_thrown) {
+    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_dialog.empty();
-        ipa_dialog.attr('title', 'Error: '+error_thrown.name);
+        ipa_dialog.attr('title', error_thrown.title);
 
         ipa_dialog.append('<p>URL: '+this.url+'</p>');
-        if (error_thrown.message) {
-            ipa_dialog.append('<p>'+error_thrown.message+'</p>');
-        }
+        ipa_dialog.append('<p>'+error_thrown.message+'</p>');
 
-        var that = this;
+        dialog_open.call(this, xhr, text_status, error_thrown);
+    }
 
-        ipa_dialog.dialog({
-            modal: true,
-            width: 400,
-            buttons: {
-                'Retry': function() {
-                    ipa_dialog.dialog('close');
-                    ipa_cmd(name, args, options, win_callback, fail_callback, objname);
-                },
-                'Cancel': function() {
-                    ipa_dialog.dialog('close');
-                    fail_callback.call(that, xhr, text_status, error_thrown);
-                }
-            }
-        });
+    function http_error_handler(xhr, text_status, error_thrown) {
+        ipa_dialog.empty();
+        ipa_dialog.attr('title', error_thrown.title);
+
+        ipa_dialog.append('<p>URL: '+this.url+'</p>');
+        ipa_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_dialog.empty();
+        ipa_dialog.attr('title', error_thrown.title);
+
+        ipa_dialog.append('<p>'+error_thrown.message+'</p>');
+
+        dialog_open.call(this, xhr, text_status, error_thrown);
     }
 
     var id = ipa_jsonrpc_id++;
@@ -148,8 +174,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 91ee1bd..c369305 100644
--- a/install/static/search.js
+++ b/install/static/search.js
@@ -191,8 +191,7 @@ function search_load(jobj, criteria, on_win, on_fail)
             on_fail(xhr, text_status, error_thrown);
 
         var search_results = $('.search-results', jobj);
-        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 a53824b..bc00cb5 100644
--- a/install/static/webui.js
+++ b/install/static/webui.js
@@ -94,8 +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