403b09
From a5918fbd136d1b597e30629f66a3d69d567737f3 Mon Sep 17 00:00:00 2001
403b09
From: Pavel Vomacka <pvomacka@redhat.com>
403b09
Date: Fri, 26 Aug 2016 12:50:00 +0200
403b09
Subject: [PATCH] Add support for additional options taken from table facet
403b09
403b09
Sometimes the entity_show command must be called with options which are gathered
403b09
from result of entity_find command. These options needs to be passed as
403b09
arguments in URL which points to details page.
403b09
403b09
This functionality is implemented to table facet. There is new property
403b09
'additional_navigation_arguments' which is prepared for array of attributes
403b09
which will be passed to URL.
403b09
403b09
Part of: https://fedorahosted.org/freeipa/ticket/6238
403b09
403b09
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
403b09
---
403b09
 install/ui/src/freeipa/facet.js | 49 ++++++++++++++++++++++++++++++++++++++++-
403b09
 1 file changed, 48 insertions(+), 1 deletion(-)
403b09
403b09
diff --git a/install/ui/src/freeipa/facet.js b/install/ui/src/freeipa/facet.js
403b09
index 4553c5c65e6c334ed451e9c2f1a89ddc455d71c3..06eca189fa2c7b125fdfbd964e6192ddf709b2c8 100644
403b09
--- a/install/ui/src/freeipa/facet.js
403b09
+++ b/install/ui/src/freeipa/facet.js
403b09
@@ -1819,6 +1819,15 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
403b09
     var that = IPA.facet(spec, no_init);
403b09
 
403b09
     /**
403b09
+     * Names of additional row attributes which will be send to another facet
403b09
+     * during navigation as URL parameters.
403b09
+     *
403b09
+     * @property {Array<string>}
403b09
+     */
403b09
+    that.additional_navigation_arguments = spec.additional_navigation_arguments;
403b09
+
403b09
+
403b09
+    /**
403b09
      * Entity of data displayed in the table
403b09
      * @property {entity.entity}
403b09
      */
403b09
@@ -2268,6 +2277,38 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
403b09
 
403b09
 
403b09
     /**
403b09
+     * Extract data from command response and return them.
403b09
+     *
403b09
+     * @param pkey {string} primary key of row which is chosen
403b09
+     * @param attrs {Array} names of attributes which will be extracted
403b09
+     */
403b09
+    that.get_row_attribute_values = function(key, attrs) {
403b09
+        var result = that.data.result.result;
403b09
+        var options = {};
403b09
+        var row;
403b09
+
403b09
+        if (result) {
403b09
+            for (var i=0, l=result.length; i
403b09
+                row = result[i];
403b09
+
403b09
+                var pkey = row[that.table.name];
403b09
+                if (pkey == key) break;
403b09
+            }
403b09
+
403b09
+            if (row) {
403b09
+                for (var j=0, le=attrs.length; j
403b09
+                    var attr = attrs[j];
403b09
+                    var new_attr = {};
403b09
+                    new_attr[attr] = row[attr];
403b09
+                    $.extend(options, new_attr);
403b09
+                }
403b09
+            }
403b09
+        }
403b09
+
403b09
+        return options;
403b09
+    };
403b09
+
403b09
+    /**
403b09
      *
403b09
      * Method which will be called after clicking on pkey in table.
403b09
      *
403b09
@@ -2279,6 +2320,12 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
403b09
      */
403b09
     that.on_column_link_click = function(value, entity) {
403b09
         var pkeys = [value];
403b09
+        var args;
403b09
+
403b09
+        var attributes = that.additional_navigation_arguments;
403b09
+        if (lang.isArray(attributes)) {
403b09
+            args = that.get_row_attribute_values(value, attributes);
403b09
+        }
403b09
 
403b09
         // for nested entities
403b09
         var containing_entity = entity.get_containing_entity();
403b09
@@ -2287,7 +2334,7 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
403b09
             pkeys.push(value);
403b09
         }
403b09
 
403b09
-        navigation.show_entity(entity.name, that.details_facet_name, pkeys);
403b09
+        navigation.show_entity(entity.name, that.details_facet_name, pkeys, args);
403b09
         return false;
403b09
     };
403b09
 
403b09
-- 
403b09
2.7.4
403b09