From b36df6e9b9c1104d37fe14782a7e21e57097a7c0 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Mon, 25 Jul 2011 12:15:14 -0400 Subject: removing setters setup and init change widget and widget unit tests to hold on to entity, not entity name. Replacing entity_name with entity.name in most places. The one exception is columns for table_widget. Widgets that refer to other entities have to have late resolution of the entity object, due to circular dependencies. cleanup entity assignment. removed template and layout, merged setup into create adder dialogs adjust height for external removed init from widget, isection, association, facet, host and service Make unit tests use factory. fix functional tests to click find link correctly. tweak to activation test, but still broken. moved initialization code to the end use --all for hbacrule find, so the type shows up now fixed dns exception code and exception handling for get_entity replace metadata look up with value from entity. fixed author lines removed duplicate columns in managed by facets. tweak to nav fix in order to initialize tab. more defensive code update metadata for true false one line init for entity_name in widget move init code to end of constructor functions moved constants to start of function for adder_dialog external fields for dialogs initialized at dialog creation sudo sections: move add fields and columns to widget definition. The parameter validation in IPA.column ...This is precondition checking. Note that it merely throws an exception if the entity_name is not set. I want this stuff at the top of the function so that it is obvious to people looking to use them what is required. I added a comment to make this clear, but I'd like to keep precondition checking at the top of the function. decreased the scope of the pkey_name and moved the initiailzation fof columns into the setup_column function for association_tables return false at the end of click handler removed blank labels in sudo command section fix radio buttons for sudo category fixed table side for adder dialogs with external fields comments for future direction with add_columns https://fedorahosted.org/freeipa/ticket/1451 https://fedorahosted.org/freeipa/ticket/1462 https://fedorahosted.org/freeipa/ticket/1493 https://fedorahosted.org/freeipa/ticket/1497 https://fedorahosted.org/freeipa/ticket/1532 https://fedorahosted.org/freeipa/ticket/1534 --- install/ui/widget.js | 197 ++++++++++++++++++++++++--------------------------- 1 file changed, 93 insertions(+), 104 deletions(-) (limited to 'install/ui/widget.js') diff --git a/install/ui/widget.js b/install/ui/widget.js index 1932bee7..b60b2a61 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -31,6 +31,8 @@ IPA.widget = function(spec) { var that = {}; + + that.entity = spec.entity; that.id = spec.id; that.name = spec.name; that.label = spec.label; @@ -41,14 +43,12 @@ IPA.widget = function(spec) { that.conditional = spec.conditional; that.optional = spec.optional || false; - // read_only is set during initialization + // read_only is set when widget is created that.read_only = spec.read_only; // writable is set during load that.writable = true; - that._entity_name = spec.entity_name; - that.width = spec.width; that.height = spec.height; @@ -62,13 +62,21 @@ IPA.widget = function(spec) { that.dirty = false; that.valid = true; - that.__defineGetter__("entity_name", function(){ - return that._entity_name; - }); - that.__defineSetter__("entity_name", function(entity_name){ - that._entity_name = entity_name; - }); + function set_param_info(){ + if (!that.param_info && that.entity){ + that.param_info = + IPA.get_entity_param(that.entity.name, that.name); + } + if (that.param_info) { + if (that.label === undefined) { + that.label = that.param_info.label; + } + if (that.tooltip === undefined) { + that.tooltip = that.param_info.doc; + } + } + } function meta_validate(meta, value){ @@ -159,25 +167,6 @@ IPA.widget = function(spec) { } }; - that.init = function() { - if (that.entity_name) { - that.entity = IPA.get_entity(that.entity_name); - if (!that.param_info){ - that.param_info = - IPA.get_entity_param(that.entity_name, that.name); - } - if (that.param_info) { - - if (that.label === undefined) { - that.label = that.param_info.label; - } - - if (that.tooltip === undefined) { - that.tooltip = that.param_info.doc; - } - } - } - }; /** * This function compares the original values and the @@ -231,10 +220,6 @@ IPA.widget = function(spec) { that.container = 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. @@ -352,10 +337,12 @@ IPA.widget = function(spec) { that.refresh = function() { }; + + /*widget initialization*/ + set_param_info(); + // methods that should be invoked by subclasses - that.widget_init = that.init; that.widget_create = that.create; - that.widget_setup = that.setup; that.widget_load = that.load; that.widget_reset = that.reset; that.widget_save = that.save; @@ -419,11 +406,6 @@ IPA.text_widget = function(spec) { } that.create_error_link(container); - }; - - that.setup = function(container) { - - that.widget_setup(container); var input = $('input[name="'+that.name+'"]', that.container); input.keyup(function() { @@ -587,11 +569,6 @@ IPA.multivalued_text_widget = function(spec) { 'class': 'ui-state-highlight ui-corner-all undo', html: 'undo all' }).appendTo(container); - }; - - that.setup = function(container) { - - that.widget_setup(container); that.template = $('div[name=value]', that.container); that.template.detach(); @@ -789,11 +766,6 @@ IPA.checkbox_widget = function (spec) { if (that.undo) { that.create_undo(container); } - }; - - that.setup = function(container) { - - that.widget_setup(container); var input = $('input[name="'+that.name+'"]', that.container); input.change(function() { @@ -874,11 +846,6 @@ IPA.checkboxes_widget = function (spec) { if (that.undo) { that.create_undo(container); } - }; - - that.setup = function(container) { - - that.widget_setup(container); var input = $('input[name="'+that.name+'"]', that.container); input.change(function() { @@ -891,6 +858,7 @@ IPA.checkboxes_widget = function (spec) { }); }; + that.load = function(record) { that.values = record[that.name] || []; that.reset(); @@ -956,11 +924,6 @@ IPA.radio_widget = function(spec) { if (that.undo) { that.create_undo(container); } - }; - - that.setup = function(container) { - - that.widget_setup(container); var input = $('input[name="'+that.name+'"]', that.container); input.change(function() { @@ -1038,10 +1001,6 @@ IPA.select_widget = function(spec) { container.append(' '); that.create_undo(container); } - }; - - that.setup = function(container) { - that.widget_setup(container); that.select = $('select[name="'+that.name+'"]', that.container); that.select.change(function() { @@ -1118,12 +1077,6 @@ IPA.textarea_widget = function (spec) { that.create_error_link(container); - }; - - that.setup = function(container) { - - that.widget_setup(container); - var input = $('textarea[name="'+that.name+'"]', that.container); input.keyup(function() { that.set_dirty(that.test_dirty()); @@ -1160,7 +1113,9 @@ IPA.textarea_widget = function (spec) { return that; }; - +/* + The entity name must be set in the spec either directly or via entity.name +*/ IPA.column = function (spec) { spec = spec || {}; @@ -1170,26 +1125,22 @@ IPA.column = function (spec) { that.name = spec.name; that.label = spec.label; that.width = spec.width; - - that.entity_name = spec.entity_name; + that.entity_name = spec.entity ? spec.entity.name : spec.entity_name; that.primary_key = spec.primary_key; that.link = spec.link; - that.format = spec.format; - that.init = function() { - if (that.entity_name && !that.label) { - var param_info = IPA.get_entity_param(that.entity_name, that.name); - if (param_info) { - that.label = param_info.label; - } else { - alert('Cannot find label for ' + that.entity_name + ' ' + - that.name); - } - } - }; + if (!that.entity_name){ + var except = { + expected: false, + message:'Column created without an entity_name.' + }; + throw except; + } function setup(container, record) { + + container.empty(); var value = record[that.name]; @@ -1218,6 +1169,16 @@ IPA.column = function (spec) { return false; }; + + /*column initialization*/ + if (that.entity_name && !that.label) { + var param_info = IPA.get_entity_param(that.entity_name, that.name); + if (param_info) { + that.label = param_info.label; + } + } + + return that; }; @@ -1267,15 +1228,6 @@ IPA.table_widget = function (spec) { return column; }; - that.init = function() { - that.widget_init(); - - var columns = that.columns.values; - for (var i=0; i', { + id: spec.id, + name: spec.name, + href: spec.href || '#' + (spec.name || 'button'), + title: spec.title || spec.label, + 'class': 'ui-state-default ui-corner-all input_link', + style: spec.style, + click: spec.click, + blur: spec.blur + }); + + if (spec['class']) button.addClass(spec['class']); + + if (spec.icon) { + $('', { + 'class': 'icon '+spec.icon + }).appendTo(button); + } + + if (spec.label) { + $('', { + 'class': 'button-label', + html: spec.label + }).appendTo(button); + } + + return button; +}; + -- cgit