Browse Source

HUE-1929 [core] Create jHueDelayedInput plugin

Created new plugin and refactored most of the old calls
Removed usued alert and validation plugins
Enrico Berti 11 years ago
parent
commit
fbf25a6

+ 7 - 11
apps/beeswax/src/beeswax/templates/execute.mako

@@ -777,17 +777,13 @@ $(document).ready(function () {
     show: false
     show: false
   });
   });
 
 
-  var navigatorSearchTimeout = -1;
-  $("#navigatorSearch").on("keyup", function () {
-    window.clearTimeout(navigatorSearchTimeout);
-    navigatorSearchTimeout = window.setTimeout(function () {
-      $("#navigatorTables li").removeClass("hide");
-      $("#navigatorTables li").each(function () {
-        if ($(this).text().toLowerCase().indexOf($("#navigatorSearch").val().toLowerCase()) == -1) {
-          $(this).addClass("hide");
-        }
-      });
-    }, 300);
+  $("#navigatorSearch").jHueDelayedInput(function(){
+    $("#navigatorTables li").removeClass("hide");
+    $("#navigatorTables li").each(function () {
+      if ($(this).text().toLowerCase().indexOf($("#navigatorSearch").val().toLowerCase()) == -1) {
+        $(this).addClass("hide");
+      }
+    });
   });
   });
 
 
   resetNavigator = function () {
   resetNavigator = function () {

+ 6 - 10
apps/beeswax/src/beeswax/templates/list_history.mako

@@ -190,16 +190,12 @@ ${ layout.menubar(section='history') }
       "bStateSave": true
       "bStateSave": true
     });
     });
 
 
-    var filterTimeout = -1;
-    $(".search-query").keyup(function () {
-      window.clearTimeout(filterTimeout);
-      filterTimeout = window.setTimeout(function () {
-        $("#spinner").show();
-        $(".datatables").hide();
-        $(".pagination").hide();
-        location.href = '?${ filter_params.get(prefix + 'user') and (prefix + 'user=' + filter_params.get(prefix + 'user') + '&') or '' }${ prefix }search='+$(".search-query").val();
-      }, 500);
-    });
+    $(".search-query").jHueDelayedInput(function(){
+      $("#spinner").show();
+      $(".datatables").hide();
+      $(".pagination").hide();
+      location.href = '?${ filter_params.get(prefix + 'user') and (prefix + 'user=' + filter_params.get(prefix + 'user') + '&') or '' }${ prefix }search='+$(".search-query").val();
+    }, 500);
 
 
     var _val = $(".search-query").val();
     var _val = $(".search-query").val();
     $(".search-query").focus().val("").val(_val);
     $(".search-query").focus().val("").val(_val);

+ 4 - 8
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -750,14 +750,10 @@ from django.utils.translation import ugettext as _
       }
       }
       viewModel.retrieveData();
       viewModel.retrieveData();
 
 
-      var filterTimeout = -1;
-      $(".search-query").keyup(function () {
-        window.clearTimeout(filterTimeout);
-        filterTimeout = window.setTimeout(function () {
-          viewModel.searchQuery($(".search-query").val());
-          viewModel.filter();
-        }, 500);
-      });
+      $(".search-query").jHueDelayedInput(function(){
+        viewModel.searchQuery($(".search-query").val());
+        viewModel.filter();
+      }, 500);
 
 
       $("#editBreadcrumb").click(function () {
       $("#editBreadcrumb").click(function () {
         $(this).hide();
         $(this).hide();

+ 3 - 7
apps/jobbrowser/src/jobbrowser/templates/jobs.mako

@@ -306,13 +306,9 @@ ${ components.menubar() }
       $.getJSON(_url, callback);
       $.getJSON(_url, callback);
     }
     }
 
 
-    var _filterTimeout = -1;
-    $(".search-query").on("keyup", function () {
-      window.clearTimeout(_filterTimeout);
-      _filterTimeout = window.setTimeout(function () {
-        $("#loading").removeClass("hide");
-        callJsonData(populateTable);
-      }, 300);
+    $(".search-query").jHueDelayedInput(function(){
+      $("#loading").removeClass("hide");
+      callJsonData(populateTable);
     });
     });
 
 
     $("#showRetired").change(function () {
     $("#showRetired").change(function () {

+ 11 - 19
apps/pig/src/pig/templates/app.mako

@@ -824,18 +824,14 @@ ${ commonheader(None, "pig", user) | n,unicode }
       codeMirror.focus();
       codeMirror.focus();
     });
     });
 
 
-    var navigatorSearchTimeout = -1;
-    $("#navigatorSearch").on("keyup", function () {
-      window.clearTimeout(navigatorSearchTimeout);
-      navigatorSearchTimeout = window.setTimeout(function () {
-        $(".navigatorFunctionCategoryContent").removeClass("hide");
-        $(".navigatorFunctionCategoryContent li").removeClass("hide");
-        $(".navigatorFunctionCategoryContent li").each(function () {
-          if ($(this).text().toLowerCase().indexOf($("#navigatorSearch").val().toLowerCase()) == -1) {
-            $(this).addClass("hide");
-          }
-        });
-      }, 300);
+    $("#navigatorSearch").jHueDelayedInput(function(){
+      $(".navigatorFunctionCategoryContent").removeClass("hide");
+      $(".navigatorFunctionCategoryContent li").removeClass("hide");
+      $(".navigatorFunctionCategoryContent li").each(function () {
+        if ($(this).text().toLowerCase().indexOf($("#navigatorSearch").val().toLowerCase()) == -1) {
+          $(this).addClass("hide");
+        }
+      });
     });
     });
 
 
     $("#navigatorFunctions").css("max-height", ($(window).height() - 370) + "px").css("overflow-y", "auto");
     $("#navigatorFunctions").css("max-height", ($(window).height() - 370) + "px").css("overflow-y", "auto");
@@ -1141,13 +1137,9 @@ ${ commonheader(None, "pig", user) | n,unicode }
       }, 100);
       }, 100);
     });
     });
 
 
-    var _filterTimeout = -1;
-    $("#filter").on("keyup", function () {
-      window.clearTimeout(_filterTimeout);
-      _filterTimeout = window.setTimeout(function () {
-        viewModel.filterScripts($("#filter").val());
-      }, 350);
-    });
+    $("#filter").jHueDelayedInput(function(){
+      viewModel.filterScripts($("#filter").val());
+    }, 350);
 
 
     viewModel.filterScripts("");
     viewModel.filterScripts("");
 
 

+ 7 - 11
apps/rdbms/src/rdbms/templates/execute.mako

@@ -336,17 +336,13 @@ ${ commonheader(_('Query'), app_name, user) | n,unicode }
       placement: 'bottom'
       placement: 'bottom'
     });
     });
 
 
-    var navigatorSearchTimeout = -1;
-    $("#navigatorSearch").on("keyup", function () {
-      window.clearTimeout(navigatorSearchTimeout);
-      navigatorSearchTimeout = window.setTimeout(function () {
-        $("#navigatorTables li").removeClass("hide");
-        $("#navigatorTables li").each(function () {
-          if ($(this).text().toLowerCase().indexOf($("#navigatorSearch").val().toLowerCase()) == -1) {
-            $(this).addClass("hide");
-          }
-        });
-      }, 300);
+    $("#navigatorSearch").jHueDelayedInput(function(){
+      $("#navigatorTables li").removeClass("hide");
+      $("#navigatorTables li").each(function () {
+        if ($(this).text().toLowerCase().indexOf($("#navigatorSearch").val().toLowerCase()) == -1) {
+          $(this).addClass("hide");
+        }
+      });
     });
     });
 
 
     $("#navigatorTables").css("max-height", ($(window).height() - 340) + "px").css("overflow-y", "auto");
     $("#navigatorTables").css("max-height", ($(window).height() - 340) + "px").css("overflow-y", "auto");

+ 11 - 15
apps/search/src/search/templates/search.mako

@@ -531,22 +531,18 @@ ${ commonheader(_('Search'), "search", user, "90px") | n,unicode }
     % if hue_collection.autocomplete:
     % if hue_collection.autocomplete:
     $("#id_query").attr("autocomplete", "off");
     $("#id_query").attr("autocomplete", "off");
 
 
-    var autocompleteTimeout = -1;
-    $("#id_query").on("keyup", function () {
-      window.clearTimeout(autocompleteTimeout);
-      autocompleteTimeout = window.setTimeout(function() {
-        var query = $("#id_query").val();
-        if (query) {
-          $.ajax("${ url('search:query_suggest', collection_id=hue_collection.id) }" + query, {
-            type: 'GET',
-            success: function (data) {
-              if (data.message.spellcheck && ! jQuery.isEmptyObject(data.message.spellcheck.suggestions)) {
-                $('#id_query').typeahead({source: data.message.spellcheck.suggestions[1].suggestion});
-              }
+    $("#id_query").jHueDelayedInput(function(){
+      var query = $("#id_query").val();
+      if (query) {
+        $.ajax("${ url('search:query_suggest', collection_id=hue_collection.id) }" + query, {
+          type: 'GET',
+          success: function (data) {
+            if (data.message.spellcheck && ! jQuery.isEmptyObject(data.message.spellcheck.suggestions)) {
+              $('#id_query').typeahead({source: data.message.spellcheck.suggestions[1].suggestion});
             }
             }
-          });
-        }
-      }, 300);
+          }
+        });
+      }
     });
     });
     % endif
     % endif
 
 

+ 1 - 1
desktop/core/src/desktop/templates/common_header.mako

@@ -122,7 +122,7 @@ from django.utils.translation import ugettext as _
   <script src="/static/js/jquery.migration.js"></script>
   <script src="/static/js/jquery.migration.js"></script>
   <script src="/static/js/jquery.filechooser.js"></script>
   <script src="/static/js/jquery.filechooser.js"></script>
   <script src="/static/js/jquery.selector.js"></script>
   <script src="/static/js/jquery.selector.js"></script>
-  <script src="/static/js/jquery.alert.js"></script>
+  <script src="/static/js/jquery.delayedinput.js"></script>
   <script src="/static/js/jquery.rowselector.js"></script>
   <script src="/static/js/jquery.rowselector.js"></script>
   <script src="/static/js/jquery.notify.js"></script>
   <script src="/static/js/jquery.notify.js"></script>
   <script src="/static/js/jquery.titleupdater.js"></script>
   <script src="/static/js/jquery.titleupdater.js"></script>

+ 3 - 7
desktop/core/src/desktop/templates/logs.mako

@@ -98,13 +98,9 @@ ${layout.menubar(section='log_view')}
       }, 200);
       }, 200);
     });
     });
 
 
-    var filterTimeout = -1;
-    $(".search-query").keyup(function () {
-      window.clearTimeout(filterTimeout);
-      filterTimeout = window.setTimeout(function () {
-        filterLogs($(".search-query").val());
-      }, 500);
-    });
+    $(".search-query").jHueDelayedInput(function(){
+      filterLogs($(".search-query").val());
+    }, 500);
 
 
     if ("${query}" != "") {
     if ("${query}" != "") {
       filterLogs("${query}");
       filterLogs("${query}");

+ 0 - 33
desktop/core/static/js/jquery.alert.js

@@ -1,33 +0,0 @@
-// Licensed to Cloudera, Inc. under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  Cloudera, Inc. licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-/*
-* jHue alert plugin
-*/
-var jHueAlert = function(message){
-
-		if ($("#jHueAlertDialog").length==0){
-			var mainDialog = $("<div>").attr("id", "jHueAlertDialog").addClass("modal").addClass("hide").addClass("fade");
-			mainDialog.html('<div class="modal-header"><a href="#" class="close">&times;</a></div><div class="modal-body"></div>');
-			mainDialog.appendTo("body");
-			mainDialog.modal({
-				backdrop: "static",
-				keyboard: true
-			});
-		}
-		var alertDialog= $("#jHueAlertDialog");
-		alertDialog.find(".modal-body").text(message);
-		alertDialog.modal("show");
-};

+ 68 - 0
desktop/core/static/js/jquery.delayedinput.js

@@ -0,0 +1,68 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+/*
+* jHue Delayed Input plugin
+* use it with
+* $("#element").jHueDelayedInput( __FUNCTION_YOU_WANT_TO_CALL__, __TIMEOUT_IN_MS__ [optional])
+*/
+;
+(function ($, window, document, undefined) {
+
+  var pluginName = "jHueDelayedInput",
+      defaults = {
+        fn: null,
+        timeout: 300
+      };
+
+  function Plugin(element, options) {
+    this.element = element;
+    this.options = $.extend({}, defaults, options);
+    this._defaults = defaults;
+    this._name = pluginName;
+    this.init();
+  }
+
+  Plugin.prototype.setOptions = function (options) {
+    this.options = $.extend({}, defaults, options);
+  };
+
+  Plugin.prototype.init = function () {
+    var _this = this;
+    var _timeout = -1;
+    if (_this.options.fn != null) {
+      $(_this.element).on("keyup", function () {
+        window.clearTimeout(_timeout);
+        _timeout = window.setTimeout(_this.options.fn, _this.options.timeout);
+      });
+    }
+  };
+
+  $.fn[pluginName] = function (fn, timeout) {
+    var _options = {
+      fn: fn,
+      timeout: timeout
+    }
+    return this.each(function () {
+      if (!$.data(this, 'plugin_' + pluginName)) {
+        $.data(this, 'plugin_' + pluginName, new Plugin(this, _options));
+      }
+      else {
+        $.data(this, 'plugin_' + pluginName).setOptions(_options);
+      }
+    });
+  }
+
+})(jQuery, window, document);

+ 0 - 52
desktop/core/static/js/jquery.validation.js

@@ -1,52 +0,0 @@
-// Licensed to Cloudera, Inc. under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  Cloudera, Inc. licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-/*
-* jHue validation plugin
-*/
-;(function ($, window, document, undefined) {
-
-	var pluginName = "jHueValidation",
-	defaults = {
-	};
-
-	function Plugin(element, options) {
-		this.element = element;
-		this.options = $.extend({}, defaults, options) ;
-		this._defaults = defaults;
-		this._name = pluginName;
-		this.init();
-	}
-	
-	Plugin.prototype.setOptions = function(options) {
-		this.options = $.extend({}, defaults, options) ;
-	};
-
-	Plugin.prototype.init = function () {
-		var _this = this;		
-	};
-
-	$.fn[pluginName] = function (options) {
-		return this.each(function () {
-			if (!$.data(this, 'plugin_' + pluginName)) {
-				$.data(this, 'plugin_' + pluginName, new Plugin( this, options));
-			}
-			else {
-				$.data(this, 'plugin_' + pluginName).setOptions(options);
-			}
-		});
-	}
-
-})(jQuery, window, document);