Anonymous avatar Anonymous committed 9a5e77b

..Added support for custom return data.
..Made it so that final values can be verified by ID

Comments (0)

Files changed (6)

TestWebsite/Controllers/hAutoCompleteController.cs

                                             new HAutoCompleteReturnData.ListItem() {id = "06", label = "universal soldier"}
                                         };
 
-            var returnModel = new HAutoCompleteReturnData();
+            var returnModel = new HautoCompleteCustomReturnData()
+                                  {
+                                      ControlID = postData.controlId,
+                                      searchTerm = postData.term,
+                                      ct = postData.TypeOfCall.ToString()
+                                  };
 
 
-            //Return everything if empty search term is detected
-            if (string.IsNullOrEmpty(postData.term))
+            if (postData.TypeOfCall == HAutoCompletePostData.typeOfCall.filtering)
             {
-                returnModel.resultList = fakedDatabaseData;
+                //Return everything if empty search term is detected
+                returnModel.resultList = string.IsNullOrEmpty(postData.term)
+                                             ? fakedDatabaseData
+                                             : (from str in fakedDatabaseData
+                                                where str.label.Contains(postData.term)
+                                                select str).ToList();
             } else
             {
+                //For verifying by ID
                 returnModel.resultList =
-                    (from str in fakedDatabaseData where str.label.Contains(postData.term) select str).ToList();
+                    (from str in fakedDatabaseData where str.id.ToLower() == postData.term.ToLower() select str).ToList();
             }
-            
-            
+
+
             // ReSharper disable Asp.NotResolved
             return View(returnModel);
             // ReSharper restore Asp.NotResolved

TestWebsite/Models/hAutoComplete/HAutoCompletePostData.cs

         /// </summary>
         public string term { get; set; }
         public string controlId { get; set; }
+        public typeOfCall TypeOfCall { get; set; }
+
+        public enum typeOfCall
+        {
+            /// <summary>
+            /// To know when to do a search
+            /// </summary>
+            filtering, 
+            /// <summary>
+            /// To know when to search by ID to verify that a particular selection is a valid one.
+            /// </summary>
+            verifying 
+        }
     }
 }

TestWebsite/Models/hAutoComplete/HautoCompleteCustomReturnData.cs

+namespace TestWebsite.Models.hAutoComplete
+{
+    public class HautoCompleteCustomReturnData : HAutoCompleteReturnData
+    {
+        public string ct { get; set; }
+        public string searchTerm { get; set; }
+        public string ControlID { get; set; }
+    }
+}

TestWebsite/Scripts/hAutoComplete/hAutoComplete.js

     };
 
 
+    /*
+    
+    Options:
+    
+    options.additionalDataRecievedCallback = function(data)   -> For registering a callback function that retrieves additional data every time a filtering call to the server completes.
+    
+    options.extraParameters =  -> For sending additional paramters to the server each time a search operation is performed.  Things like work order number, loging name, etc...
+    {
+    additionalProperty1: 'This can be an additional property. It can be named anything as long as the server can de-serialize it.',
+    additionalProperty2: 'This can be an additional property. It can be named anything as long as the server can de-serialize it.',
+    .
+    .
+    .
+    }
+
+    options.source = 'http...' -> For specifying the URL to where the filtering AJAX call will be called out to.  An object will be serialized into JSON and posted to this URL.  The object
+    that is posted looks like this:
+    {
+    term: 'search term',   //Mandatory, will always exist
+    controlId: 'ID of the control where the search is coming from', //Mandatory, will always exist
+        
+    additionalProperty1: 'This comes from options.extraParameters',
+    additionalProperty2: 'This comes from options.extraParameters',
+    .
+    .
+    .
+    */
     $.fn.hAutoComplete = function(options, setValue) {
         if (options === 'set') {
             $.fn.hAutoComplete.prototype.val.call(this, { term: setValue });
         $(document).undelegate('*', 'click', otherElementFocus);
         $(document).delegate('*', 'click', otherElementFocus);
 
-        getFilterResultsFromServer = function(searchObject, response, surpressErrors) {
+        getFilterResultsFromServer = function(searchObject, response, surpressErrors, callType) {
             //Spawn an ajax request here to the filter controller
             //Make sure some kind of loading screen appears.
             if ((surpressErrors === null) || (surpressErrors === undefined)) {
                 surpressErrors = true;
             }
+            if ((callType === null) || (callType === undefined)) {
+                callType = 'filtering';
+            }
+
 
             $.AjaxManager.POSTJson({
                 name: that.attr('name'),
                 dataFunc: function() {
                     var dataPackage = {
                         term: searchObject.term,
-                        controlId: that.attr('id')
+                        controlId: that.attr('id'),
+                        TypeOfCall: callType
                     };
                     $.extend(dataPackage, options.extraParameters);
                     return dataPackage;
                 },
                 success: function(json) {
+                    if (typeof (options.additionalDataRecievedCallback) === 'function') {
+                        options.additionalDataRecievedCallback(json);
+                    }
                     response(json.resultList);
                 }
             });
                 } else {
                     thisElement.val(thisElement.data("uiItem"));
                 }
-            }, false);
+            }, false, 'verifying');
         };
 
         hideToolTip = function(event) {

TestWebsite/TestWebsite.csproj

     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
+    <Compile Include="Models\hAutoComplete\HautoCompleteCustomReturnData.cs" />
     <Compile Include="Models\hAutoComplete\HAutoCompletePostData.cs" />
     <Compile Include="Models\hAutoComplete\HAutoCompleteReturnData.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

TestWebsite/Views/hAutoComplete/Index.aspx

     
 	<script type="text/javascript">
 	    $(function() {
-	        
+
 	        $(document).ready(function() {
 	            //Remote example is here: http://jqueryui.com/demos/autocomplete/remote.html
-	        //$("#selector").hAutoComplete({ source: '<%=Url.Action("Search","hAutoComplete") %>' });
-	        //$("#selector").hAutoComplete({ source: '<%=Url.Action("Search2","hAutoComplete") %>' });
-	        $("#selector").hAutoComplete({ source: '<%=Url.Action("Search","hAutoComplete") %>' });
-	        $("#testing2").hAutoComplete({ source: '<%=Url.Action("Search","hAutoComplete") %>' });
-	        $('#testing2').hAutoComplete('set','arnold');
+	            //$("#selector").hAutoComplete({ source: '<%=Url.Action("Search","hAutoComplete") %>' });
+	            //$("#selector").hAutoComplete({ source: '<%=Url.Action("Search2","hAutoComplete") %>' });
+	            $("#selector").hAutoComplete({ source: '<%=Url.Action("Search","hAutoComplete") %>', additionalDataRecievedCallback: function(data) { console.log('selector finished'); } });
+	            $("#testing2").hAutoComplete({ source: '<%=Url.Action("Search","hAutoComplete") %>', additionalDataRecievedCallback: function(data) { console.log('testing2 finished'); } });
+	            $('#testing2').hAutoComplete('set', 'arnold');
 	        });
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.