Commits

Pedro Lima committed ed98a70

Support for different results field for different search helps in the collective SH scenario

Comments (0)

Files changed (2)

docs/search_help_widget.rst

   <script src="http://cogni.bitbucket.org/mobiweaver/jquery.mobile-1.0.mobiweaver.js"></script>
   <script src="http://cogni.bitbucket.org/mobiweaver/jquery.mobiweaver.searchhelp-0.1.js"></script>
 
-- FIXME: check final names
-
-
 In order to set the search help widget in a form element, the following setup is needed:
 
 - add the data-role="searchhelp" in the form element
 - set a data-options element with keys:
 
     - *searchHelp*  - a search help in the SAP server 
-    - *type* (optional) - set to "C" in case of a collective search help. Can be ommited otherwise.
+    - *type* (optional) - set to "C" in case of a collective search help. Can be omitted otherwise.
     - *resultField* - the field name that will transfer the value to the html form field
-    - *resultTableFields* (optional) - a list of visible columns in the search results table; defaults to showing all the columns.
+    - *resultTableFields* (optional) - this field has information for restricting the results display to a subset of fields in the search help; it can be either a list of fields to display, and in this case it applies to all search helps inside a collective search help, or it can be an object with keys the search help names and values the corresponding lists of fields to display; defaults to showing all the columns.
     - *baseUrl* (optional): the url where the search.do and fields.do scripts reside. defaults to "/sap/bc/bsp/sap/ymwsearchhelp/"
     - *transition* (optional): jQueryMobile transition used when opening/closing the dialogs (defaults to "pop").
     - *searchHelpTheme* (optional): the jQueryMobile theme for the Search Help dialog (defaults to "a").
 Example::
 
   <input type="text" name="tknum" data-role="searchhelp" 
-       data-options='{"searchHelp": "sh_tknum", "resultField": "tknum"}'>
+       data-options='{"searchHelp": "sh_tknum", "resultField": "tknum", "resultTableFields":["tknum", "shtyp","tplst"] }'>
 
 Example of a collective search help::
 
-  <input type="text" name="..." data-role="searchhelp" 
-       data-options='{"searchHelp": "admc", "type": "C", "resultField": "..."}'>
+  <input type="text" name="carriers" data-role="searchhelp" 
+     data-options='{"searchHelp": "F4_CARRIERS", "type": "C", "resultField": "LIFNR", "resultTableFields": {"KREDA":["LIFNR","PSTLZ"], "F4_LFA1_ACCT":["LIFNR","NAME1","LAND1"]} }'>
+
 
 
 Minified 
 --------
 
 To reduce the size of both Javascript files and reduce their loading time, you can create minified versions.
-The included Makefile performs this task using [REF TO FINAL MINIFIER].
+The included Makefile performs this task using yuicompressor.
 
 The minified files are also available from::
 

mobiweaver/javascript/jquery.mobiweaver.searchhelp.js

             var thisTheme = $.mobile.getInheritedTheme(inputElement, opts.searchHelpTheme);
             opts.overlayTheme = opts.overlayTheme || thisTheme;
             opts.resultField = opts.resultField.toUpperCase(); // in SAP the field name is always in UPPER CASE.
+            // field names are always in uppercase in SAP, the result fields are converted
             if ($.isArray(opts.resultTableFields)) {
                 for (var i=0; i<opts.resultTableFields.length; i++) {
-                    // field names are always in uppercase in SAP
                     opts.resultTableFields[i] = opts.resultTableFields[i].toUpperCase();
                 }
-            } else {
+            } else if ($.type(opts.resultTableFields) === 'object') {
+                $.each(opts.resultTableFields, function(key, value) {
+                  if ($.isArray(value)) {
+                    for (var i=0; i<value.length; i++) {
+                      value[i] = value[i].toUpperCase();
+                    }
+                  }
+                });
+            } else {                
                 opts.resultTableFields = undefined;
             }
             var thisPage = inputElement.closest('.ui-page');
             }
         },
 
-        _isFieldVisible: function(field) {
+        _isFieldVisible: function(field, searchHelp) {
+            var resFields;
             var fieldName = $(field).attr('name');
-            return (this.options.resultTableFields==undefined ||
-                ($.inArray(fieldName, this.options.resultTableFields)>-1));
+            var resultTableFieldsType = $.type(this.options.resultTableFields);
+            if (resultTableFieldsType === 'array') {
+              // if resultTableFields is a list the output fields will be the same for all SH 
+              // inside the collective SH
+              resFields = this.options.resultTableFields;
+            } else if (resultTableFieldsType === 'object') {
+              // if resultTableFields is an object it is expected an entry
+              // with the output fields for each SH inside the collective SH
+              resFields = this.options.resultTableFields[searchHelp];
+            }
+            return (resFields==undefined || ($.inArray(fieldName, resFields)>-1))
         },
 
         search: function(value) {
                     self._showErrorMessage();
                 },
                 success: function(data){
-                    var xmldoc;
+                    var xmldoc, searchHelpName;
                     var resultTable = $('<table class="ui-mobiweaver-searchhelp"></table>');
                     var resultsExist = false;
                     xmldoc = $(data);
                     // header row
                     xmldoc.find('searchhelp entry').each( function(index) {
+                        searchHelpName = $(this).parent().attr('name');
                         if (index === 0) {
                             resultsExist = true;
                             var header = $('<thead></thead>');
                             var headerRow = $('<tr></tr>');
                             $(this).children().each( function() {
-                                if (self._isFieldVisible(this)) {
+                                if (self._isFieldVisible(this, searchHelpName)) {
                                     var th = $('<th></th>').text($(this).attr('title'));
                                     headerRow.append(th);
                                 }
                         // data
                         var tblBody = $('<tbody></tbody>');
                         xmldoc.find('searchhelp entry').each( function(index) {
+                            searchHelpName = $(this).parent().attr('name');
                             var resultText = $(this).find("field[name='"+self.options.resultField+"']").text();
                             // TODO exception if not found
                             var resRow = $('<tr></tr>',  {'class': 'ui-btn ui-btn-up-' + self.options.searchHelpTheme, 'data-result': resultText, 'data-theme': self.options.searchHelpTheme});
                             $(this).children().each( function() {
-                                if (self._isFieldVisible(this)) {
+                                if (self._isFieldVisible(this, searchHelpName)) {
                                     var resData = $('<td></td>').text($(this).text());
                                     resRow.append(resData);
                                 }