Преглед изворни кода

HUE-5843 [jobsub] Avoid multiple list calls and fix JS error when deleting all the jobs

Enrico Berti пре 9 година
родитељ
комит
c4edeba

+ 11 - 1
apps/jobsub/src/jobsub/static/jobsub/js/jobsub.ko.js

@@ -17,6 +17,7 @@
 /**
  * Design representation
  */
+var jobsubAjaxQueue = 0;
 var Design = (function($, ko, NodeFields) {
   var module = function(options) {
     var self = this;
@@ -154,7 +155,16 @@ var Design = (function($, ko, NodeFields) {
         dataType: 'json',
         type: 'GET',
         success: $.noop,
-        error: $.noop
+        error: $.noop,
+        beforeSend: function () {
+          jobsubAjaxQueue = jobsubAjaxQueue + 1;
+        },
+        complete: function () {
+          jobsubAjaxQueue = Math.max(jobsubAjaxQueue - 1, 0);
+          if (jobsubAjaxQueue == 0) {
+            $(document).trigger('reload.designs');
+          }
+        }
       }, options || {});
 
       $.ajax(request);

+ 7 - 6
apps/jobsub/src/jobsub/templates/designs.mako

@@ -791,11 +791,14 @@ function redraw() {
  * Knockout doesn't work without this.
  * Clearing the table is necessary so multiple rows will not be added.
  */
+
 function reload() {
   designs.isLoading(true);
   $(document).one('load.designs', function() {
-    designTable.fnClearTable();
-    designTable.fnDestroy();
+    if (designTable != null){
+      designTable.fnClearTable();
+      designTable.fnDestroy();
+    }
   });
   $(document).one('initialized.designs', function() {
     designTable = $('#designTable').dataTable( designTableOptions );
@@ -814,10 +817,8 @@ $(document).bind('loaded.designs', function() {
     }
   });
 });
-$(document).bind('saved.design', reload);
-$(document).bind('deleted.design', reload);
-$(document).bind('cloned.design', reload);
-$(document).bind('restored.design', reload);
+
+$(document).bind('reload.designs', reload);
 
 reload();