From aa29a8a769c62b07cc4e6d82fc79846505cc9fa3 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 26 May 2011 17:57:39 -0500 Subject: Added Update and Reset buttons into Dirty dialog. The Dirty dialogs have been combined into IPA.dirty_dialog. It provides the Update and Reset buttons with customizable callback. Previously the widget's dirty status is computed by comparing the old values with the new values. This method is sometimes inaccurate, so the is_dirty() method has been modified to simply return a flag which is set to true if the widget is changed. Ticket #896. --- install/ui/widget.js | 134 ++++++++++++++++++++------------------------------- 1 file changed, 51 insertions(+), 83 deletions(-) (limited to 'install/ui/widget.js') diff --git a/install/ui/widget.js b/install/ui/widget.js index 6b211d6f..66dedbdf 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -51,17 +51,11 @@ IPA.widget = function(spec) { that.undo = typeof spec.undo == 'undefined' ? true : spec.undo; that.join = spec.join; - that.init = spec.init || init; - that.create = spec.create || create; - that.setup = spec.setup || setup; - that.load = spec.load || load; - that.save = spec.save || save; - that.update = spec.update || update; - that.param_info = spec.param_info; that.metadata = spec.metadata; that.values = []; + that.dirty = false; that.valid = true; that.__defineGetter__("entity_name", function(){ @@ -128,7 +122,7 @@ IPA.widget = function(spec) { } }; - function init() { + that.init = function() { if (that.entity_name) { that.param_info = IPA.get_entity_param(that.entity_name, that.name); @@ -143,20 +137,20 @@ IPA.widget = function(spec) { } } } - } + }; - function create(container) { - } + that.create = function(container) { + }; - function setup(container) { + that.setup = function(container) { that.container = container; - } + }; /** * This function stores the entire record and the values * of the field, then invoke reset() to update the UI. */ - function load(record) { + that.load = function(record) { that.record = record; var value = record[that.name]; @@ -186,24 +180,24 @@ IPA.widget = function(spec) { } that.reset(); - } + }; that.reset = function() { - that.hide_undo(); + that.set_dirty(false); that.update(); }; - function update() { - } + that.update = function() { + }; /** * This function saves the values entered in the UI. * It returns the values in an array, or null if * the field should not be saved. */ - function save() { + that.save = function() { return that.values; - } + }; /** * This function compares the original values and the @@ -211,45 +205,7 @@ IPA.widget = function(spec) { * it will return true. */ that.is_dirty = function() { - - if (that.read_only) { - return false; - } - - var values = that.save(); - - if (!values) { // ignore null values - return false; - } - - if (!that.values) { - - if (values instanceof Array) { - - if ((values.length === 0) || - (values.length === 1) && - (values[0] === '')) { - return false; - } - } - - return true; - } - - if (values.length != that.values.length) { - return true; - } - - values.sort(); - that.values.sort(); - - for (var i=0; i= that.values.length) { // show undo/remove link for new value + that.set_dirty(true, index); if (that.undo) { - that.show_undo(index); - that.show_undo(); remove_link.css('display', 'none'); } else { remove_link.css('display', 'inline'); @@ -563,9 +539,8 @@ IPA.multivalued_text_widget = function(spec) { var index = that.row_index(row); // uncross removed value input.removeClass('strikethrough'); + that.set_dirty(true, index); if (that.undo) { - that.show_undo(index); - that.show_undo(); if (index < that.values.length) { remove_link.css('display', 'inline'); } @@ -579,10 +554,7 @@ IPA.multivalued_text_widget = function(spec) { // restore old value then cross it out that.update(index); input.addClass('strikethrough'); - if (that.undo) { - that.show_undo(index); - that.show_undo(); - } + that.set_dirty(true, index); remove_link.css('display', 'none'); } else { // remove new value @@ -623,7 +595,7 @@ IPA.multivalued_text_widget = function(spec) { }; that.reset = function(index) { - that.hide_undo(index); + that.set_dirty(false, index); that.update(index); }; @@ -685,7 +657,7 @@ IPA.checkbox_widget = function (spec) { var input = $('input[name="'+that.name+'"]', that.container); input.change(function() { - that.show_undo(); + that.set_dirty(true); }); var undo = that.get_undo(); @@ -759,7 +731,7 @@ IPA.checkboxes_widget = function (spec) { var input = $('input[name="'+that.name+'"]', that.container); input.change(function() { - that.show_undo(); + that.set_dirty(true); }); var undo = that.get_undo(); @@ -837,7 +809,7 @@ IPA.radio_widget = function(spec) { var input = $('input[name="'+that.name+'"]', that.container); input.change(function() { - that.show_undo(); + that.set_dirty(true); }); var undo = that.get_undo(); @@ -913,7 +885,7 @@ IPA.select_widget = function(spec) { that.select = $('select[name="'+that.name+'"]', that.container); that.select.change(function() { - that.show_undo(); + that.set_dirty(true); }); var undo = that.get_undo(); @@ -994,7 +966,7 @@ IPA.textarea_widget = function (spec) { var input = $('textarea[name="'+that.name+'"]', that.container); input.keyup(function() { - that.show_undo(); + that.set_dirty(true); that.validate(); }); @@ -1439,7 +1411,7 @@ IPA.entity_select_widget = function(spec) { that.entity_select = $('