From 4bab6b7e5d4f6454e5293c3b403fded397f93610 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Tue, 22 Nov 2011 15:41:33 +0100 Subject: Splitting basic widgets into visual widgets and fields https://fedorahosted.org/freeipa/ticket/2040 --- install/ui/widget.js | 620 +++++++++++++++++++++++---------------------------- 1 file changed, 274 insertions(+), 346 deletions(-) (limited to 'install/ui/widget.js') diff --git a/install/ui/widget.js b/install/ui/widget.js index 59a4091d..710b6c25 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -61,8 +61,9 @@ IPA.input_widget = function(spec) { that.height = spec.height; that.undo = spec.undo === undefined ? true : spec.undo; - that.writable = spec.writable; + that.writable = spec.writable === undefined ? true : spec.writable; that.read_only = spec.read_only; + that.hidden = spec.hidden; //events //each widget can contain several events @@ -168,8 +169,6 @@ IPA.input_widget = function(spec) { that.focus_input = function() {}; that.set_deleted = function() {}; - - // methods that should be invoked by subclasses that.widget_hide_error = that.hide_error; that.widget_show_error = that.show_error; @@ -196,7 +195,7 @@ IPA.text_widget = function(spec) { spec = spec || {}; - var that = IPA.widget(spec); + var that = IPA.input_widget(spec); that.size = spec.size || 30; that.type = spec.type || 'text'; @@ -223,8 +222,7 @@ IPA.text_widget = function(spec) { size: that.size, title: that.tooltip, keyup: function() { - that.set_dirty(that.test_dirty()); - that.validate(); + that.value_changed.notify([], that); } }).appendTo(container); @@ -235,8 +233,8 @@ IPA.text_widget = function(spec) { that.create_error_link(container); }; - that.update = function() { - var value = that.values && that.values.length ? that.values[0] : ''; + that.update = function(values) { + var value = values && values.length ? values[0] : ''; if (that.read_only || !that.writable) { that.display_control.text(value); @@ -274,299 +272,274 @@ IPA.text_widget = function(spec) { that.display_control.text(''); }; + that.focus_input = function() { + that.input.focus(); + }; + + that.set_deleted = function(deleted) { + if(deleted) { + that.input.addClass('strikethrough'); + } else { + that.input.removeClass('strikethrough'); + } + }; + // methods that should be invoked by subclasses that.text_load = that.load; return that; }; +IPA.password_widget = function(spec) { + + spec = spec || {}; + spec.type = 'password'; + + var that = IPA.text_widget(spec); + return that; +}; + IPA.multivalued_text_widget = function(spec) { spec = spec || {}; - var that = IPA.widget(spec); + var that = IPA.input_widget(spec); + that.widget_factory = spec.widget_factory || IPA.text_widget; that.size = spec.size || 30; + that.undo_control; + that.initialized = false; - that.get_undo = function(index) { - if (index === undefined) { - return $('span[name="undo_all"]', that.container); + that.rows = []; - } else { - var row = that.get_row(index); - return $('span[name="undo"]', row); + that.on_child_value_changed = function(row) { + if(that.test_dirty_row(row)) { + row.widget.show_undo(); + row.remove_link.hide(); } + + that.value_changed.notify([], that); }; - that.test_dirty = function(index) { - if (index === undefined) { - return that.widget_test_dirty(); + that.on_child_undo_clicked = function(row) { + if (row.is_new) { + that.remove_row(row); + } else { + //reset + row.widget.update(row.original_values); + row.widget.set_deleted(false); + row.deleted = false; + row.remove_link.show(); } - var row = that.get_row(index); - var input = $('input[name="'+that.name+'"]', row); + row.widget.hide_undo(); + that.value_changed.notify([], that); + }; - if (input.is('.strikethrough')) { - return true; - } + that.hide_undo = function() { - var value = input.val(); - if (value !== that.values[index]) { - return true; + $(that.undo_span).css('display', 'none'); + for(var i=0; i', { name: 'value'}); - that.template = $('
', { - name: 'value' + row.widget = that.widget_factory({ + name: that.name+'-'+row_index, + undo: that.undo, + read_only: that.read_only, + writable: that.writable }); - $('', { - type: 'text', - name: that.name, - disabled: that.disabled, - size: that.size, - title: that.tooltip - }).appendTo(that.template); + row.widget.create(row.container); - that.template.append(' '); + row.original_values = values; + row.widget.update(values); - $('', { + row.widget.value_changed.attach(function() { + that.on_child_value_changed(row); + }); + row.widget.undo_clicked.attach(function() { + that.on_child_undo_clicked(row); + }); + + row.remove_link = $('', { name: 'remove', href: 'jslink', title: IPA.messages.buttons.remove, - html: IPA.messages.buttons.remove - }).appendTo(that.template); + html: IPA.messages.buttons.remove, + click: function () { + that.remove_row(row); + that.value_changed.notify([], that); + return false; + } + }).appendTo(row.container); - if (that.undo) { - that.create_undo(that.template, false /* no callback */); + if(row.is_new) { + row.remove_link.hide(); + row.widget.show_undo(); + that.value_changed.notify([], that); } + row.container.insertBefore(that.add_link); + }; + + that.create = function(container) { + + container.addClass('multivalued-text-widget'); + + that.widget_create(container); + that.create_error_link(container); - $('', { + that.add_link = $('', { name: 'add', href: 'jslink', title: IPA.messages.buttons.add, html: IPA.messages.buttons.add, click: function() { that.add_row(''); - var input = $('input[name="'+that.name+'"]:last', that.container); - input.focus(); + that.focus_last(); return false; } }).appendTo(container); - //create other container.append(' '); - $('', { + that.undo_span = $('', { name: 'undo_all', style: 'display: none;', 'class': 'ui-state-highlight ui-corner-all undo', html: IPA.messages.widget.undo_all, click: function() { - that.reset(); + that.undo_clicked.notify([], that); } }).appendTo(container); }; - that.save = function() { - var values = []; - if (that.read_only || !that.writable) { - $('label[name="'+that.name+'"]', that.container).each(function() { - var input = $(this); - var value = input.html(); - values.push(value); - }); - + that.remove_row = function(row) { + if (row.is_new) { + row.container.remove(); + that.rows.splice(that.rows.indexOf(row), 1); //not supported by IE<9 } else { - $('input[name="'+that.name+'"]', that.container).each(function() { - var input = $(this); - if (input.is('.strikethrough')) return; - - var value = input.val(); - values.push(value); - }); + row.deleted = true; + row.widget.set_deleted(true); + row.remove_link.hide(); + row.widget.show_undo(); } - return values; }; - that.add_row = function(value) { - - var add_link = $('a[name=add]', that.container); + that.remove_rows = function() { + for(var i=0; i < that.rows.length; i++) { + that.rows[i].container.remove(); + } + that.rows = []; + }; - var row = that.template.clone(); - row.insertBefore(add_link); + that.clear = function() { + that.remove_rows(); + }; - var input = $('input[name="'+that.name+'"]', row); - var remove_link = $('a[name=remove]', row); - var undo_link = $('span[name=undo]', row); + that.test_dirty_row = function(row) { - if (that.read_only || !that.writable) { - var label = $('