Merge branch 'master' into 2919-provenance-graph-cutoff
[arvados.git] / apps / workbench / app / assets / javascripts / pipeline_instances.js
index 27c2c7f5e760451992ab7b4b4dc13660896a8164..d23ced7fbc31335cd5d44217f4448bf5e1f2398b 100644 (file)
@@ -1,73 +1,74 @@
-(function() {
-    var run_pipeline_button_state = function() {
-        var a = $('a.editable.required.editable-empty');
-        if (a.length > 0) {
-            $("#run-pipeline-button").addClass("disabled");
+function run_pipeline_button_state() {
+    var a = $('a.editable.required.editable-empty');
+    if (a.length > 0) {
+        $(".run-pipeline-button").addClass("disabled");
+    }
+    else {
+        $(".run-pipeline-button").removeClass("disabled");
+    }
+}
+
+$(document).on('editable:success', function(event, tag, response, newValue) {
+    var $tag = $(tag);
+    if ($('.run-pipeline-button').length == 0)
+        return;
+    if ($tag.hasClass("required")) {
+        if (newValue && newValue.trim() != "") {
+            $tag.removeClass("editable-empty");
+            $tag.parent().css("background-color", "");
+            $tag.parent().prev().css("background-color", "");
         }
         else {
-            $("#run-pipeline-button").removeClass("disabled");
+            $tag.addClass("editable-empty");
+            $tag.parent().css("background-color", "#ffdddd");
+            $tag.parent().prev().css("background-color", "#ffdddd");
         }
     }
-
-    $.fn.editable.defaults.success = function (response, newValue) {
-        var tag = $(this);
-        if (tag.hasClass("required")) {
-            if (newValue && newValue.trim() != "") {
-                tag.removeClass("editable-empty");
-                tag.parent().css("background-color", "");
-                tag.parent().prev().css("background-color", "");
-            }
-            else {
-                tag.addClass("editable-empty");
-                tag.parent().css("background-color", "#ffdddd");
-                tag.parent().prev().css("background-color", "#ffdddd");
-            }
-        }
-        run_pipeline_button_state();
+    if ($tag.attr('data-name')) {
+        // Update other inputs representing the same piece of data
+        $('.editable[data-name="' + $tag.attr('data-name') + '"]').
+            editable('setValue', newValue);
     }
+    run_pipeline_button_state();
+});
 
-    $(window).on('load', function() {
-        var a = $('a.editable.required');
-        for (var i = 0; i < a.length; i++) {
-            var tag = $(a[i]);
-            if (tag.hasClass("editable-empty")) {
-                tag.parent().css("background-color", "#ffdddd");
-                tag.parent().prev().css("background-color", "#ffdddd");
-            }
-            else {
-                tag.parent().css("background-color", "");
-                tag.parent().prev().css("background-color", "");
-            }
+$(document).on('ready ajax:complete', function() {
+    $('a.editable.required').each(function() {
+        var $tag = $(this);
+        if ($tag.hasClass("editable-empty")) {
+            $tag.parent().css("background-color", "#ffdddd");
+            $tag.parent().prev().css("background-color", "#ffdddd");
+        }
+        else {
+            $tag.parent().css("background-color", "");
+            $tag.parent().prev().css("background-color", "");
         }
-        run_pipeline_button_state();
-    } );
+    });
+    run_pipeline_button_state();
+});
 
-    $(document).on('ajax:complete ready', function() {
-      var a = $('.event-listener');
-      if (a.length > 0) {
-        $('.event-listener').each(function() {
-          subscribeToEventLog(this.id);
-        });
-      }
+$(document).on('ajax:complete ready', function() {
+  var a = $('.arv-log-event-listener');
+  if (a.length > 0) {
+    $('.arv-log-event-listener').each(function() {
+      subscribeToEventLog(this.id);
     });
+  }
+});
 
-    $(document).on('arv-event', '.event-handler-append-logs', function(event, eventData){
-      parsedData = JSON.parse(eventData);
-      summary = parsedData.summary;
-      properties = parsedData.properties;
-      updatedProperties = null;
-      if (properties !== null) {
-        new_attributes = properties.new_attributes;
-        if (new_attributes !== null) {
-          updatedProperties = JSON.stringify(properties.new_attributes);
-        }
-      }
+$(document).on('arv-log-event', '.arv-log-event-handler-append-logs', function(event, eventData){
+  parsedData = JSON.parse(eventData);
 
-      if (updatedProperties !== null) {
-        $(this).append(updatedProperties + "<br/><br/>");
-      } else {
-        $(this).append(summary + "<br/><br/>");
-      }
-    });
+  propertyText = undefined
 
-})();
+  properties = parsedData.properties;
+    if (properties !== null) {
+      propertyText = properties.text;
+    }
+
+    if (propertyText !== undefined) {
+      $(this).append(propertyText + "<br/>");
+    } else {
+      $(this).append(parsedData.summary + "<br/>");
+    }
+});