From 1a904708cc68f742a19036224b267d92644968fc Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Mon, 7 Jul 2014 15:38:01 +0200 Subject: webui: reflect readonly state Separate update of read-only state from update of value. It should be possible to switch from read-only UI to editable UI without value change. https://fedorahosted.org/freeipa/ticket/4254 Reviewed-By: Endi Sukma Dewata --- install/ui/src/freeipa/widget.js | 137 +++++++++++++++++++++++++++++++-------- 1 file changed, 110 insertions(+), 27 deletions(-) (limited to 'install/ui/src/freeipa/widget.js') diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js index c12115592..302b466b5 100644 --- a/install/ui/src/freeipa/widget.js +++ b/install/ui/src/freeipa/widget.js @@ -569,6 +569,7 @@ IPA.input_widget = function(spec) { var changed = writable !== that.writable; that.writable = writable; + that.update_read_only(); if (changed) { that.emit('writable-change', { source: that, writable: writable }); @@ -585,12 +586,25 @@ IPA.input_widget = function(spec) { var changed = read_only !== that.read_only; that.read_only = read_only; + that.update_read_only(); if (changed) { that.emit('readonly-change', { source: that, read_only: read_only }); } }; + /** + * Update widget's HTML based on `read_only` and `writable` properties + * @protected + */ + that.update_read_only = function() { + var input = that.get_input(); + if (input) { + var ro = that.is_writable(); + input.prop('readOnly', !ro); + } + }; + /** * Focus input element * @abstract @@ -636,6 +650,8 @@ IPA.input_widget = function(spec) { that.widget_set_valid = that.set_valid; that.widget_hide_undo = that.hide_undo; that.widget_show_undo = that.show_undo; + that.widget_set_writable = that.set_writable; + that.widget_set_read_only = that.set_read_only; return that; }; @@ -737,6 +753,7 @@ IPA.text_widget = function(spec) { that.create_error_link(container); that.set_enabled(that.enabled); + that.update_read_only(); that.update_input_group_state(); }; @@ -745,18 +762,23 @@ IPA.text_widget = function(spec) { */ that.update = function(values) { var value = values && values.length ? values[0] : ''; + that.display_control.text(value); + that.input.val(value); + that.on_value_changed(); + }; + /** + * @inheritDoc + */ + that.update_read_only = function() { + if (!that.input) return; if (!that.is_writable()) { - that.display_control.text(value); that.display_control.css('display', ''); that.input_group.css('display', 'none'); } else { - that.input.val(value); that.display_control.css('display', 'none'); that.input_group.css('display', ''); } - - that.on_value_changed(); }; /** @@ -1183,7 +1205,13 @@ IPA.multivalued_widget = function(spec) { that.on_value_changed(); }; + /** @inheritDoc */ + that.update_read_only = function() { + that.update_add_link_visibility(); + }; + that.update_add_link_visibility = function() { + if (!that.add_link) return; var visible = that.is_writable() && that.enabled; if (visible) { that.add_link.css('display', ''); @@ -1192,6 +1220,40 @@ IPA.multivalued_widget = function(spec) { } }; + that.update_row_buttons = function(row) { + + var w = that.is_writable(); + if (!that.enabled || !w) { + row.widget.hide_undo(); + that.toggle_remove_link(row, false); + } else { + if (row.is_new || that.test_dirty_row(row)) { + row.widget.show_undo(); + that.toggle_remove_link(row, false); + } else { + that.toggle_remove_link(row, w); + } + } + }; + + that.set_writable = function(writable) { + that.widget_set_writable(writable); + for (var i=0,l=that.rows.length; i', { + name: that.name, + 'class': 'form-control-static', + style: 'display: none;' + }).appendTo(container); + that.select = $('