Răsfoiți Sursa

HUE-57. Add support for shift selecting multiple checkboxes

Aaron Newton 15 ani în urmă
părinte
comite
69d5feae7b

+ 36 - 0
apps/jframegallery/src/jframegallery/templates/multi-checks.html

@@ -0,0 +1,36 @@
+{% comment %}
+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.
+{% endcomment %}
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<html>
+	<head>
+		<title>Multi Checks</title>
+	</head>
+	<body>
+		<div class="jframe_padded" data-filters="MultiChecks">
+			<p>You should be able to hold down shift to select ranges of checkboxes below. Select one checkbox, then hold shift and click another. The boxes between the two should fill in. It shouldn't matter if you go up or down.</p>
+			<input type="checkbox"/><br/>
+			<input type="checkbox"/><br/>
+			<input type="checkbox"/><br/>
+			<input type="checkbox"/><br/>
+			<input type="checkbox"/><br/>
+			<input type="checkbox"/><br/>
+			<input type="checkbox"/><br/>
+			<input type="checkbox"/><br/>
+		</div>
+	</body>
+</html>

+ 50 - 0
desktop/core/static/js/Source/BehaviorFilters/Behavior.MultiChecks.js

@@ -0,0 +1,50 @@
+/*
+---
+description: Allows users to hold down shift to select multiple check boxes.
+provides: [Behavior.MultiChecks]
+requires: [Widgets/Behavior]
+script: Behavior.MultiChecks.js
+...
+*/
+(function(){
+	var checkInput = function(input, checked) {
+		input.set('checked', checked).fireEvent('change');
+	};
+	
+	Behavior.addGlobalFilters({
+
+		MultiChecks: function(element, events) {
+			var prev;
+			//this method handles clicks to our checkboxes
+			var clickHandler = function(e, input){
+				//if there's a previously clicked input and the shift button is held
+				if (prev && e.shift) {
+					var active, check;
+					//get the state of the input, if it's checked, we're selecting things
+					//otherwise we're deselecting them
+					check = input.get('checked');
+					//get all the checkboxes in the element
+					element.getElements('input[type=checkbox]').each(function(el){
+						//if it's the element we checked, or it's the previous one checked
+						if (el == input || el == prev) {
+							//then check it and toggle our start state
+							checkInput(el, check);
+							active = !active;
+							return;
+						}
+						//if we're active, check the input
+						if (active) checkInput(el, check);
+					});
+				}
+				//store the clicked element as the new one.
+				prev = input;
+			};
+			element.addEvent('click:relay(input[type=checkbox])', clickHandler);
+			this.markForCleanup(element, function(){
+				element.removeEvent('click:relay(input[type=checkbox])', clickHandler);
+			});
+		}
+
+	});
+
+})();

+ 1 - 0
desktop/core/static/js/Source/CCS/CCS.JFrame.js

@@ -36,6 +36,7 @@ requires:
  - Widgets/Behavior.ArtButton
  - /Behavior.SideBySideSelect
  - /Behavior.FitText
+ - /Behavior.MultiChecks
  - /CCS
  - /CCS.ContextMenu
 script: CCS.JFrame.js

+ 1 - 0
desktop/core/static/js/package.yml

@@ -64,6 +64,7 @@ sources: [
   Source/CCS/CCS.PostEditor.Simple.js,
   Source/UI/ART.SideBySideSelect.js,
   Source/BehaviorFilters/Behavior.FitText.js,
+  Source/BehaviorFilters/Behavior.MultiChecks.js,
   Source/BehaviorFilters/Behavior.SideBySideSelect.js,
 ]
 version: Unknown