Blob Blame History Raw
From c2783b9b54ecae8299da0dc593c3813c2bd26fe2 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvoborni@redhat.com>
Date: Thu, 26 Jul 2012 11:17:28 +0200
Subject: [PATCH 67/79] Replace use of attr with prop for booleans

Recommened way of setting boolean HTML attributes is by $.prop(boolean) method not $.attr(boolean) because it sets DOM object property not an attribute. Latter works because of jquery's backward compatibility. This patch makes things clearer.

Some info about prop and attr: http://stackoverflow.com/a/5876747

https://fedorahosted.org/freeipa/ticket/2817
---
 install/ui/aci.js         |  2 +-
 install/ui/association.js |  4 ++--
 install/ui/dns.js         |  8 ++++----
 install/ui/hbactest.js    | 12 ++++++------
 install/ui/widget.js      | 48 ++++++++++++++++++++---------------------------
 5 files changed, 33 insertions(+), 41 deletions(-)

diff --git a/install/ui/aci.js b/install/ui/aci.js
index 63181efac5f335d28a4c23bfa1ae2da95b9a0e75..039e633234c0aa968dc6f2f81093507aa57f22f2 100644
--- a/install/ui/aci.js
+++ b/install/ui/aci.js
@@ -492,7 +492,7 @@ IPA.attributes_widget = function(spec) {
                 type: "checkbox",
                 click: function() {
                     $('.aci-attribute', that.table).
-                        attr('checked', $(this).attr('checked'));
+                        prop('checked', $(this).prop('checked'));
                     that.value_changed.notify([], that);
                 }
             })
diff --git a/install/ui/association.js b/install/ui/association.js
index 0594ea764e9b02742a983f127b865bc66bf7f3f3..be8b8459dded9b024e5d998311eab62c70e57756 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -1038,9 +1038,9 @@ IPA.association_facet = function (spec, no_init) {
     that.refresh = function() {
 
         if (that.association_type == 'direct') {
-            if (that.direct_radio) that.direct_radio.attr('checked', true);
+            if (that.direct_radio) that.direct_radio.prop('checked', true);
         } else {
-            if (that.indirect_radio) that.indirect_radio.attr('checked', true);
+            if (that.indirect_radio) that.indirect_radio.prop('checked', true);
         }
 
         var pkey = that.entity.get_primary_key();
diff --git a/install/ui/dns.js b/install/ui/dns.js
index 1f4ba8ccdb98cda3e67d9d006139d42f99a3399e..cd8cb8e195eb60a72489773083dd90b9e0a947a8 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -512,8 +512,8 @@ IPA.add_dns_zone_name_policy = function() {
         var name_from_ip_f = this.container.fields.get_field('name_from_ip');
 
         idnsname_w.radio_clicked.attach(function() {
-            idnsname_w.input.attr('disabled', false);
-            name_from_ip_w.input.attr('disabled', true);
+            idnsname_w.input.prop('disabled', false);
+            name_from_ip_w.input.prop('disabled', true);
 
             idnsname_f.set_required(true);
             name_from_ip_f.set_required(false);
@@ -522,8 +522,8 @@ IPA.add_dns_zone_name_policy = function() {
         });
 
         name_from_ip_w.radio_clicked.attach(function() {
-            idnsname_w.input.attr('disabled', true);
-            name_from_ip_w.input.attr('disabled', false);
+            idnsname_w.input.prop('disabled', true);
+            name_from_ip_w.input.prop('disabled', false);
 
             idnsname_f.set_required(false);
             name_from_ip_f.set_required(true);
diff --git a/install/ui/hbactest.js b/install/ui/hbactest.js
index 373ff39b0c32424eeb2a6548074ec8ad008aa895..4b666ef29306d10cebc37014de444f1797f52103 100644
--- a/install/ui/hbactest.js
+++ b/install/ui/hbactest.js
@@ -279,7 +279,7 @@ IPA.hbac.test_select_facet = function(spec) {
 
         that.table.set_values = function(values) {
             if (values && values.length && values[0] === '__external__') {
-                if (that.external_radio) that.external_radio.attr('checked', true);
+                if (that.external_radio) that.external_radio.prop('checked', true);
             } else {
                 that.table.table_set_values(values);
             }
@@ -393,7 +393,7 @@ IPA.hbac.test_select_facet = function(spec) {
 
     that.reset = function() {
         delete that.selected_values;
-        if (that.external_radio) that.external_radio.attr('checked', false);
+        if (that.external_radio) that.external_radio.prop('checked', false);
         if (that.external_text) that.external_text.val('');
     };
 
@@ -482,8 +482,8 @@ IPA.hbac.test_rules_facet = function(spec) {
 
     that.reset = function() {
         delete that.selected_values;
-        if (that.enabled) that.enabled.attr('checked', false);
-        if (that.disabled) that.disabled.attr('checked', false);
+        if (that.enabled) that.enabled.prop('checked', false);
+        if (that.disabled) that.disabled.prop('checked', false);
     };
 
     that.save = function(record) {
@@ -655,8 +655,8 @@ IPA.hbac.test_run_facet = function(spec) {
         delete that.data;
         that.show_matched = true;
         that.show_unmatched = true;
-        if (that.matched_checkbox) that.matched_checkbox.attr('checked', true);
-        if (that.unmatched_checkbox) that.unmatched_checkbox.attr('checked', true);
+        if (that.matched_checkbox) that.matched_checkbox.prop('checked', true);
+        if (that.unmatched_checkbox) that.unmatched_checkbox.prop('checked', true);
         that.refresh();
     };
 
diff --git a/install/ui/widget.js b/install/ui/widget.js
index ed7fcf76c3d5eca6c652c31b0053f60c52bddf27..9b15f2f1b236c1dd4dae027272664c7178218d97 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -297,11 +297,7 @@ IPA.text_widget = function(spec) {
 
     that.set_enabled = function(value) {
 
-        if(value) {
-            that.input.removeAttr('disabled');
-        } else {
-            that.input.attr('disabled', 'disabled');
-        }
+        that.input.prop('disabled', !value);
     };
 
     that.clear = function() {
@@ -669,11 +665,11 @@ IPA.checkbox_widget = function (spec) {
             value = that.checked;
         }
 
-        that.input.attr('checked', value);
+        that.input.prop('checked', value);
     };
 
     that.clear = function() {
-        that.input.attr('checked', false);
+        that.input.prop('checked', false);
     };
 
     that.checkbox_save = that.save;
@@ -741,18 +737,18 @@ IPA.checkboxes_widget = function (spec) {
 
     that.update = function(values) {
         var inputs = $('input[name="'+that.name+'"]', that.container);
-        inputs.attr('checked', false);
+        inputs.prop('checked', false);
 
         for (var j=0; values && j<values.length; j++) {
             var value = values[j];
             var input = $('input[name="'+that.name+'"][value="'+value+'"]', that.container);
             if (!input.length) continue;
-            input.attr('checked', true);
+            input.prop('checked', true);
         }
     };
 
     that.clear = function() {
-        $('input[name="'+that.name+'"]').attr('checked', false);
+        $('input[name="'+that.name+'"]').prop('checked', false);
     };
 
     that.add_option = function(option) {
@@ -829,21 +825,21 @@ IPA.radio_widget = function(spec) {
         var value = values && values.length ? values[0] : '';
         var input = $(that.selector+'[value="'+value+'"]', that.container);
         if (input.length) {
-            input.attr('checked', true);
+            input.prop('checked', true);
         } else if (that.default_value) {
             input = $(that.selector+'[value="'+that.default_value+'"]', that.container);
-            input.attr('checked', true);
+            input.prop('checked', true);
         }
 
         that.value_changed.notify([that.save()], that);
     };
 
     that.clear = function() {
-        $(that.selector, that.container).attr('checked', false);
+        $(that.selector, that.container).prop('checked', false);
 
         if (that.default_value) {
             var input = $(that.selector+'[value="'+that.default_value+'"]', that.container);
-            input.attr('checked', true);
+            input.prop('checked', true);
         }
     };
 
@@ -915,7 +911,7 @@ IPA.select_widget = function(spec) {
         var value = values[0];
         var option = $('option[value="'+value+'"]', that.select);
         if (!option.length) return;
-        option.attr('selected', 'selected');
+        option.prop('selected', true);
     };
 
     that.empty = function() {
@@ -923,7 +919,7 @@ IPA.select_widget = function(spec) {
     };
 
     that.clear = function() {
-        $('option', that.select).attr('selected', '');
+        $('option', that.select).prop('selected', false);
     };
 
     that.set_options_enabled = function(enabled, options) {
@@ -1521,24 +1517,24 @@ IPA.table_widget = function (spec) {
     };
 
     that.select_all = function() {
-        $('input[name="'+that.name+'"]', that.thead).attr('checked', true).
+        $('input[name="'+that.name+'"]', that.thead).prop('checked', true).
             attr('title', IPA.messages.search.unselect_all);
-        $('input[name="'+that.name+'"]', that.tbody).attr('checked', true);
+        $('input[name="'+that.name+'"]', that.tbody).prop('checked', true);
         that.select_changed();
     };
 
     that.unselect_all = function() {
-        $('input[name="'+that.name+'"]', that.thead).attr('checked', false).
+        $('input[name="'+that.name+'"]', that.thead).prop('checked', false).
             attr('title', IPA.messages.search.select_all);
-        $('input[name="'+that.name+'"]', that.tbody).attr('checked', false);
+        $('input[name="'+that.name+'"]', that.tbody).prop('checked', false);
         that.select_changed();
     };
 
     that.set_values = function(values) {
-        $('input[name="'+that.name+'"]', that.tbody).attr('checked', false);
+        $('input[name="'+that.name+'"]', that.tbody).prop('checked', false);
         for (var i=0; values && i<values.length; i++) {
             var value = values[i];
-            $('input[name="'+that.name+'"][value="'+value+'"]', that.tbody).attr('checked', true);
+            $('input[name="'+that.name+'"][value="'+value+'"]', that.tbody).prop('checked', true);
         }
         that.select_changed();
     };
@@ -1697,11 +1693,7 @@ IPA.table_widget = function (spec) {
     };
 
     that.set_enabled = function(enabled) {
-        if (enabled) {
-            $('input[name="'+that.name+'"]', that.table).attr('disabled', false);
-        } else {
-            $('input[name="'+that.name+'"]', that.table).attr('disabled', true);
-        }
+        $('input[name="'+that.name+'"]', that.table).prop('disabled', !enabled);
     };
 
     that.clear = function() {
@@ -2316,7 +2308,7 @@ IPA.combobox_widget = function(spec) {
         // if no option found, skip
         if (!option.length) return;
 
-        option.attr('selected', 'selected');
+        option.prop('selected', true);
 
         that.set_value(option.val());
         that.value_changed.notify([], that);
-- 
1.7.11.2