changeset 4514:155f281be5f8

javascript: use jQuery for ypjax and rename to asynchtml The container id is replaced with a $target jQuery array.
author Mads Kiilerich <madski@unity3d.com>
date Mon, 08 Sep 2014 13:38:56 +0200
parents 0253b8e7d76c
children f3fa50c89783
files kallithea/public/js/base.js kallithea/templates/admin/admin_log.html kallithea/templates/admin/notifications/notifications.html kallithea/templates/admin/settings/settings_system.html kallithea/templates/base/base.html kallithea/templates/changelog/changelog_summary_data.html kallithea/templates/files/files.html kallithea/templates/followers/followers_data.html kallithea/templates/forks/forks_data.html kallithea/templates/journal/journal.html kallithea/templates/journal/journal_data.html kallithea/templates/pullrequests/pullrequest.html kallithea/templates/pullrequests/pullrequest_show_my.html
diffstat 13 files changed, 35 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/public/js/base.js	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/public/js/base.js	Mon Sep 08 13:38:56 2014 +0200
@@ -353,51 +353,33 @@
 };
 
 /**
- * Partial Ajax Implementation
+ * Load HTML into DOM using Ajax
  *
- * @param url: defines url to make partial request
- * @param container: defines id of container to input partial result
- * @param s_call: success callback function that takes o as arg
- *  o.tId
- *  o.status
- *  o.statusText
- *  o.getResponseHeader[ ]
- *  o.getAllResponseHeaders
- *  o.responseText
- *  o.responseXML
- *  o.argument
- * @param args arguments
+ * @param $target: load html async and place it (or an error message) here
+ * @param success: success callback function
+ * @param args: query parameters to pass to url
  */
-function ypjax(url, container, s_call, args){
-    var method='GET';
+function asynchtml(url, $target, success, args){
     if(args===undefined){
         args=null;
     }
-    var $target = $('#' + container);
     $target.html(_TM['Loading ...']).css('opacity','0.3');
 
-    // Set special header for partial ajax == HTTP_X_PARTIAL_XHR
-    YUC.initHeader('X-PARTIAL-XHR',true);
-
-    // wrapper of passed callback
-    var s_wrapper = (function(o){
-        return function(o){
-            $target.html(o.responseText).css('opacity','1.0');
-            //execute the given original callback
-            if (s_call !== undefined && s_call){
-                s_call();
-            }
-        }
-    })()
-    YUC.asyncRequest(method, url, {
-        success: s_wrapper,
-        failure: function(o){
-            console.log('ypjax failure: '+o);
-            $target.html('<span class="error_red">ERROR: {0}</span>'.format(o.status)).css('opacity','1.0');
-        },
-        cache:false
-    },args);
-
+    $.ajax({url: url, data: args, headers: {'X-PARTIAL-XHR': '1'}, cache: false, dataType: 'html'})
+        .done(function(html) {
+                $target.html(html);
+                $target.css('opacity','1.0');
+                //execute the given original callback
+                if (success !== undefined && success) {
+                    success();
+                }
+            })
+        .fail(function(jqXHR, textStatus, errorThrown) {
+                console.log('Ajax failure: ' + textStatus);
+                $target.html('<span class="error_red">ERROR: {0}</span>'.format(textStatus));
+                $target.css('opacity','1.0');
+            })
+        ;
 };
 
 var ajaxGET = function(url,success) {
--- a/kallithea/templates/admin/admin_log.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/admin/admin_log.html	Mon Sep 08 13:38:56 2014 +0200
@@ -41,14 +41,14 @@
   $(document).ready(function(){
     var $user_log = $('#user_log');
     $user_log.on('click','.pager_link',function(e){
-      ypjax(e.target.href,"user_log",function(){
+      asynchtml(e.target.href, $user_log, function(){
         show_more_event();
         tooltip_activate();
         show_changeset_tooltip();
       });
       e.preventDefault();
     });
-    $('#user_log').on('click','.show_more',function(e){
+    $user_log.on('click','.show_more',function(e){
       var el = e.target;
       $('#'+el.id.substring(1)).show();
       $(el.parentNode).hide();
--- a/kallithea/templates/admin/notifications/notifications.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/admin/notifications/notifications.html	Mon Sep 08 13:38:56 2014 +0200
@@ -52,7 +52,7 @@
 run();
 $('#mark_all_read').click(function(){
     var url = "${h.url('notifications_mark_all_read', **request.GET.mixed())}";
-    ypjax(url,'notification_data',function(){run()});
+    asynchtml(url, $('#notification_data'), function(){run();});
 });
 
 var current_filter = "${c.current_filter}";
--- a/kallithea/templates/admin/settings/settings_system.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/admin/settings/settings_system.html	Mon Sep 08 13:38:56 2014 +0200
@@ -38,7 +38,6 @@
     $('#check_for_update').click(function(e){
         var $update_notice = $('#update_notice');
         $update_notice.show();
-        ypjax("${h.url('admin_settings_system_update')}",
-              "update_notice");
-    })
+        asynchtml("${h.url('admin_settings_system_update')}", $update_notice);
+    });
 </script>
--- a/kallithea/templates/base/base.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/base/base.html	Mon Sep 08 13:38:56 2014 +0200
@@ -212,7 +212,7 @@
          var loaded = $branch_tag_switcher_2.hasClass('loaded');
          if(!loaded){
              $branch_tag_switcher_2.addClass('loaded');
-             ypjax("${h.url('branch_tag_switcher',repo_name=c.repo_name)}",'switch_to_list_2');
+             asynchtml("${h.url('branch_tag_switcher',repo_name=c.repo_name)}", $('#switch_to_list_2'));
          }
          return false;
       });
--- a/kallithea/templates/changelog/changelog_summary_data.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/changelog/changelog_summary_data.html	Mon Sep 08 13:38:56 2014 +0200
@@ -72,7 +72,7 @@
   $(document).ready(function(){
     var $shortlog_data = $('#shortlog_data');
     $shortlog_data.on('click','.pager_link',function(e){
-      ypjax(e.target.href,"shortlog_data",function(){tooltip_activate();});
+      asynchtml(e.target.href, $shortlog_data, function(){tooltip_activate();});
       e.preventDefault();
     });
   });
--- a/kallithea/templates/files/files.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/files/files.html	Mon Sep 08 13:38:56 2014 +0200
@@ -214,7 +214,7 @@
             callbacks(State);
         }
         else{
-            ypjax(State.url, container, function(){
+            asynchtml(State.url, $files_data, function(){
                     callbacks(State);
                     var expire_on = new Date().getTime() + CACHE_EXPIRE;
                     CACHE[cache_key] = [expire_on, $files_data.html()];
--- a/kallithea/templates/followers/followers_data.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/followers/followers_data.html	Mon Sep 08 13:38:56 2014 +0200
@@ -20,7 +20,7 @@
 $(document).ready(function(){
     var $followers = $('#followers');
     $followers.on('click','.pager_link',function(e){
-        ypjax(e.target.href,"followers",function(){
+        asynchtml(e.target.href, $followers, function(){
             show_more_event();
             tooltip_activate();
             show_changeset_tooltip();
--- a/kallithea/templates/forks/forks_data.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/forks/forks_data.html	Mon Sep 08 13:38:56 2014 +0200
@@ -28,7 +28,7 @@
   $(document).ready(function(){
       var $forks = $('#forks');
       $forks.on('click','.pager_link',function(e){
-          ypjax(e.target.href,"forks",function(){
+          asynchtml(e.target.href, $forks, function(){
               show_more_event();
               tooltip_activate();
               show_changeset_tooltip();
--- a/kallithea/templates/journal/journal.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/journal/journal.html	Mon Sep 08 13:38:56 2014 +0200
@@ -93,7 +93,7 @@
     fix_j_filter_width($('#j_filter').val().length);
 
     $('#refresh').click(function(e){
-        ypjax("${h.url.current(filter=c.search_term)}","journal",function(){
+        asynchtml("${h.url.current(filter=c.search_term)}", $("#journal"), function(){
             show_more_event();
             tooltip_activate();
             show_changeset_tooltip();
--- a/kallithea/templates/journal/journal_data.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/journal/journal_data.html	Mon Sep 08 13:38:56 2014 +0200
@@ -42,7 +42,7 @@
     $(document).ready(function(){
         var $journal = $('#journal');
         $journal.on('click','.pager_link',function(e){
-            ypjax(e.target.href,"journal",function(){
+            asynchtml(e.target.href, $journal, function(){
                 show_more_event();
                 tooltip_activate();
                 show_changeset_tooltip();
--- a/kallithea/templates/pullrequests/pullrequest.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/pullrequests/pullrequest.html	Mon Sep 08 13:38:56 2014 +0200
@@ -217,8 +217,8 @@
           url = url.replace(k,rev_data[k]);
       }
 
-      ypjax(url,'pull_request_overview', function(o){
-          var jsdata = eval('('+YUD.get('jsdata').innerHTML+')');
+      asynchtml(url, $('#pull_request_overview'), function(o){
+          var jsdata = eval('('+YUD.get('jsdata').innerHTML+')'); // TODO: just get json
           var r = new BranchRenderer('graph_canvas', 'graph_content_pr');
           r.render(jsdata,100);
       });
--- a/kallithea/templates/pullrequests/pullrequest_show_my.html	Mon Sep 08 13:38:56 2014 +0200
+++ b/kallithea/templates/pullrequests/pullrequest_show_my.html	Mon Sep 08 13:38:56 2014 +0200
@@ -34,7 +34,7 @@
     if ($('#show_closed').prop('checked')) {
         var url = pyroutes.url('my_pullrequests_data', {'pr_show_closed': '1'});
     }
-    ypjax(url, 'pullrequests_container', function(){
+    asynchtml(url, $('#pullrequests_container'), function(){
         // new #show_closed has just been loaded
         $('#show_closed').change(function (e) {
             show_pullrequests(e);