On 06/20/2011 09:46 AM, Adam Young wrote:
https://fedorahosted.org/freeipa/ticket/1043


_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

From 70139d51f9b1071281ad248e01aa369cf4f5db5b Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Sat, 18 Jun 2011 23:22:48 -0400
Subject: [PATCH] editable entity_select

jsl fixes

https://fedorahosted.org/freeipa/ticket/1043
---
 install/ui/host.js   |   14 ++++++++++++-
 install/ui/widget.js |   52 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/install/ui/host.js b/install/ui/host.js
index fe35e0f1fe60928eb5af01752722d3315482ec72..bd149178e452bf8c77eecedec7f0d899154b3a67 100644
--- a/install/ui/host.js
+++ b/install/ui/host.js
@@ -87,7 +87,19 @@ IPA.entity_factories.host = function () {
         }).
         standard_association_facets().
         adder_dialog({
-            fields: ['fqdn', {factory:IPA.force_host_add_checkbox_widget}]
+            width:500,
+            fields:[
+                {
+                    factory:IPA.entity_select_widget,
+                    name: 'fqdn',
+                    field_name:'idnsname',
+                    entity: 'dnszone',
+                    label: IPA.messages.objects.service.host,
+                    editable: true,
+                    undo: false
+                },
+                {factory:IPA.force_host_add_checkbox_widget}
+            ] 
         }).
         build();
 };
diff --git a/install/ui/widget.js b/install/ui/widget.js
index 9f013a0a75168200ac338f79a2943e8781eb6dcc..bd6d2037b218ed2829565ff838b82f56bb9aeec7 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -324,6 +324,20 @@ IPA.widget = function(spec) {
     return that;
 };
 
+/*uses a browser specific technique to select a range.*/
+IPA.select_range = function(input,start, end) {
+    if (input[0].setSelectionRange) {
+        input.focus();
+        input[0].setSelectionRange(start, end);
+    } else if (input[0].createTextRange) {
+        var range = input[0].createTextRange();
+        range.collapse(true);
+        range.moveEnd('character', end);
+        range.moveStart('character', start);
+        range.select();
+    }
+};
+
 
 IPA.text_widget = function(spec) {
 
@@ -334,6 +348,10 @@ IPA.text_widget = function(spec) {
     that.size = spec.size || 30;
     that.type = spec.type || 'text';
 
+    that.select_range = function(start, end){
+        IPA.select_range(that.input, start, end);
+    };
+
     that.create = function(container) {
 
         $('<label/>', {
@@ -1545,6 +1563,7 @@ IPA.entity_select_widget = function(spec) {
     var that = IPA.widget(spec);
     var entity = spec.entity || 'group';
     var field_name = spec.field_name || 'cn';
+    var editable = spec.editable || false;
 
     function populate_select(value) {
         function find_success(result) {
@@ -1588,9 +1607,25 @@ IPA.entity_select_widget = function(spec) {
 
     that.create = function(container) {
 
+        if (editable){
+            that.edit_box = $('<input />',{
+                type: 'text'
+            });
+
+            $('<div style:"display=block;" />').
+                append(that.edit_box).
+                appendTo(container);
+        }
+
         that.entity_select = $('<select/>', {
             id: that.name + '-entity-select',
             change: function(){
+                if (editable){
+                    that.edit_box.val(
+                        $('option:selected', that.entity_select).val());
+                    that.edit_box.focus();
+                    IPA.select_range(that.edit_box,0,0);
+                }
                 that.set_dirty(that.test_dirty());
             }
         }).appendTo(container);
@@ -1601,7 +1636,7 @@ IPA.entity_select_widget = function(spec) {
             id: 'entity_filter',
             style: 'display: none;',
             keyup: function(){
-                populate_select($('option:selected', that.entity_select).val());
+                populate_select(current_value());
             }
         }).appendTo(container);
 
@@ -1630,6 +1665,9 @@ IPA.entity_select_widget = function(spec) {
         that.entity_filter.val(that.values[0]);
         that.set_dirty(false);
         populate_select(that.values[0]);
+        if (editable){
+            that.edit_box.val(that.values[0]);
+        }
     };
 
     that.load = function(record) {
@@ -1642,8 +1680,18 @@ IPA.entity_select_widget = function(spec) {
         that.reset();
     };
 
+    function current_value(){
+        var value;
+        if (editable){
+            value = that.edit_box.val();
+        }else{
+            value = $('option:selected', that.entity_select).val();
+        }
+        return value;
+    }
+
     that.save = function() {
-        var value = $('option:selected', that.entity_select).val();
+        var value = current_value();
         return [value];
     };
 
-- 
1.7.5.2

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to