Browse Source

HUE-132. Create SelectWithOther Behavior Filter and propagate across Hue

Marcus McLaughlin 15 years ago
parent
commit
da23ccf301

+ 1 - 1
apps/beeswax/src/beeswax/templates/choose_delimiter.mako

@@ -54,7 +54,7 @@ ${wrappers.head('Choose a Delimiter')}
                     </div>
                   % endif
                   <div class="bw-select_delim" class="ccs-hidden">
-                    ${comps.field(delim_form["delimiter"], render_default=True, help=r'Enter the column delimiter.  Must be a single character.  Use syntax like "\001" or "\t" for special characters.', klass="ccs-select-with-other")}
+                    ${comps.field(delim_form["delimiter"], render_default=True, help=r'Enter the column delimiter.  Must be a single character.  Use syntax like "\001" or "\t" for special characters.', dd_attrs=dict(data_filters='SelectWithOther'))}
 
                     <input class="ccs-hidden" type="submit" value="Preview" name="submit_preview"/>
                     <input class="ccs-hidden" type="submit" value="Select this Delimiter" name="submit_delim"/>

+ 3 - 3
apps/beeswax/src/beeswax/templates/create_table_manually.mako

@@ -108,9 +108,9 @@ ${wrappers.head('Create a Table', toolbar=has_tables, section='new table')}
               <p class="ccs-hidden">If your records are delimited, please configure these fields:</p>
               Hive only supports single-character delimiters.
               <dl>
-                ${comps.field(table_form["field_terminator"], render_default=True, help=r'Enter the column delimiter.  Must be a single character.  Use syntax like "\001" or "\t" for special characters.', klass="ccs-select-with-other")}
-                ${comps.field(table_form["collection_terminator"], render_default=True, help="Use for array types.", klass="ccs-select-with-other")}
-                ${comps.field(table_form["map_key_terminator"], render_default=True, help="Use for map types.", klass="ccs-select-with-other")}
+                ${comps.field(table_form["field_terminator"], render_default=True, help=r'Enter the column delimiter.  Must be a single character.  Use syntax like "\001" or "\t" for special characters.', dd_attrs=dict(data_filters="SelectWithOther"))}
+                ${comps.field(table_form["collection_terminator"], render_default=True, help="Use for array types.", dd_attrs=dict(data_filters="SelectWithOther"))}
+                ${comps.field(table_form["map_key_terminator"], render_default=True, help="Use for map types.", dd_attrs=dict(data_filters="SelectWithOther"))}
               </dl>
             </li>
             <li class="bw-serde-options">

+ 3 - 3
apps/filebrowser/src/filebrowser/templates/chown.mako

@@ -20,7 +20,7 @@ ${comps.header('Change Owner / Group: ' + path.split('/')[-1])}
 
 <%
   is_superuser = extra_params['current_user'].username == extra_params['superuser']
-  select_class = is_superuser and 'ccs-select-with-other' or ''
+  select_filter = is_superuser and 'SelectWithOther' or ''
 %>
 
 ## Puts together a selection list with an "other" field as well.
@@ -64,7 +64,7 @@ ${comps.header('Change Owner / Group: ' + path.split('/')[-1])}
     ${edit.render_field(form["path"], hidden=True)}
 
     <dt><label>User</label></dt>
-    <dd class="${select_class}">
+    <dd data-filters="${select_filter}">
       % if is_superuser:
         ${ selection("user", form.all_users, extract_field_data(form["user"]), "user_other") }
       % else:
@@ -72,7 +72,7 @@ ${comps.header('Change Owner / Group: ' + path.split('/')[-1])}
       % endif
     </dd>
     <dt><label>Group</label></dt>
-    <dd class="${select_class}">
+    <dd data-filters="${select_filter}">
       % if is_superuser:
         ${ selection("group", form.all_groups, extract_field_data(form["group"]), "group_other") }
       % else:

+ 1 - 1
apps/jframegallery/src/jframegallery/templates/select_with_other.mako

@@ -20,7 +20,7 @@
 	</head>
 	<body>
 		<div class="jframe_padded">
-                        <div class="ccs-select-with-other">
+                        <div data-filters="SelectWithOther">
                                 <select>
                                 <option>A</option>
                                 <option>B</option>

+ 51 - 0
desktop/core/static/js/Source/BehaviorFilters/Behavior.SelectWithOther.js

@@ -0,0 +1,51 @@
+// 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.
+/*
+---
+description: Displays an input field when the user chooses "other" in a select input in an element with "SelectWithOther" in its data-filters property.
+provides: [Behavior.SelectWithOther]
+requires: [Widgets/Behavior,More/Fx.Reveal,More/OverText]
+script: Behavior.SelectWithOther.js
+...
+*/
+
+Behavior.addGlobalFilters({
+	SelectWithOther: function(element, methods) {
+                //get the 'other' input
+                var other = element.getElement('input').set('alt', 'Enter a custom value').addClass('required').addDataFilter('OverText').hide();
+                //create hint text
+                var ot = new OverText(other);
+                //get the select input
+                var sel = element.getElement('select');
+                //when the select changes, if the user chooses "other"
+                //reveal the input, enable the overtext
+                sel.addEvent('change', function() {
+                        if (sel.getSelected()[0].get('value') == '__other__') {
+                                other.removeClass('ignoreValidation').reveal().get('reveal').chain(function(){
+                                        ot.enable();
+                                });
+                        //else hide and disable the input
+                        } else {
+                                other.addClass('ignoreValidation').dissolve().get('reveal').chain(function(){
+                                        ot.disable();
+                                });
+                        }
+                });
+                this.markForCleanup(element, function(){
+                        ot.destroy();
+                });
+	}
+});

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

@@ -45,6 +45,7 @@ requires:
  - /Behavior.HtmlTableKeyboard
  - /Behavior.HtmlTableMultiSelectMenu
  - /Behavior.MultiChecks
+ - /Behavior.SelectWithOther
  - /Behavior.SideBySideSelect
  - /Behavior.SizeTo
  - /Behavior.SplitViewPostFold

+ 10 - 2
desktop/core/static/js/Source/JFrameFilters/CCS.JFrame.Deprecated.js

@@ -28,6 +28,7 @@ provides: [
  CCS.JFrame.HtmlTable,
  CCS.JFrame.Input,
  CCS.JFrame.OverText,
+ CCS.JFrame.SelectWithOther,
  CCS.JFrame.SizeTo,
  CCS.JFrame.SplitView,
  CCS.JFrame.SubmitOnChange,
@@ -190,8 +191,15 @@ script: CCS.JFrame.ArtButtons.js
 					element.addDataFilter('InfoTip');
 				}
 			});
-		}
+		},
 
+                select_with_other: function(container) {
+                        if (!container.get('html').contains('ccs-select-with-other')) return;
+                        container.getElements('.ccs-select-with-other').each(function(el) {
+                                dbug.warn('you are using a deprecated JFrame filter (ccs-select-with-other) on %o, use the SelectWithOther data-fitler instead.', el);
+                                el.addDataFilter('SelectWithOther');
+                        });
+                }
 	});
 
-})();
+})();

+ 0 - 49
desktop/core/static/js/Source/JFrameFilters/CCS.JFrame.SelectWithOther.js

@@ -1,49 +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.
-/*
----
-description: Displays an input field when the user chooses "other" in a select input.
-provides: [CCS.JFrame.SelectWithOther]
-requires: [/CCS.JFrame,More/Fx.Reveal,More/OverText]
-script: CCS.JFrame.SelectWithOther.js
-...
-*/
-
-CCS.JFrame.addGlobalFilters({
-	select_with_other: function(container) {
-		if (!container.get('html').contains('ccs-select-with-other')) return;
-		container.getElements('.ccs-select-with-other').each(function(el) {
-			//get the 'other' input
-			var other = el.getElement('input').set('alt', 'Enter a custom value').addClass('overtext required');
-			//create hint text
-			var ot = new OverText(other);
-			//get the select input
-			var sel = el.getElement('select');
-			//when the select changes, if the user chooses "other"
-			//reveal the input, enable the overtext
-			sel.addEvent('change', function() {
-				if (sel.getSelected()[0].get('value') == '__other__') {
-					other.removeClass('ignoreValidation').reveal().get('reveal').chain(function(){
-						ot.enable();
-					});
-				//else hide and disable the input
-				} else {
-					ot.disable();
-				}
-			});
-		});
-	},
-});

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

@@ -10,7 +10,6 @@ sources: [
   Source/JFrameFilters/CCS.JFrame.Collapsible.js,
   Source/JFrameFilters/CCS.JFrame.ToggleHistory.js,
   Source/JFrameFilters/CCS.JFrame.DataGroupToggle.js,
-  Source/JFrameFilters/CCS.JFrame.SelectWithOther.js,
   Source/JFrameFilters/CCS.JFrame.Deprecated.js,
   Source/Fx/Fx.Shake.js,
   Source/JFrameRenderers/CCS.JFrame.Alert.js,
@@ -59,6 +58,7 @@ sources: [
   Source/BehaviorFilters/Behavior.HtmlTableKeyboard.js,
   Source/BehaviorFilters/Behavior.HtmlTableMultiSelectMenu.js,
   Source/BehaviorFilters/Behavior.MultiChecks.js,
+  Source/BehaviorFilters/Behavior.SelectWithOther.js,
   Source/BehaviorFilters/Behavior.SideBySideSelect.js,
   Source/BehaviorFilters/Behavior.SizeTo.js,
   Source/BehaviorFilters/Behavior.SplitViewPostFold.js,