diff options
Diffstat (limited to 'install')
-rw-r--r-- | install/ui/details.js | 163 | ||||
-rw-r--r-- | install/ui/facet.js | 547 | ||||
-rwxr-xr-x | install/ui/jquery.ordered-map.js | 13 | ||||
-rw-r--r-- | install/ui/search.js | 90 | ||||
-rw-r--r-- | install/ui/widget.js | 60 |
5 files changed, 581 insertions, 292 deletions
diff --git a/install/ui/details.js b/install/ui/details.js index f1f13f0b4..1282912d5 100644 --- a/install/ui/details.js +++ b/install/ui/details.js @@ -231,57 +231,34 @@ IPA.details_facet = function(spec, no_init) { spec = spec || {}; spec.name = spec.name || 'details'; - spec.control_buttons = spec.control_buttons || {}; - var cb = spec.control_buttons; - cb.factory = cb.factory || IPA.control_buttons_widget; - cb.buttons = cb.buttons || []; - cb.state_listeners = cb.state_listeners || []; - cb.buttons.unshift( + spec.actions = spec.actions || []; + spec.actions.unshift( + IPA.refresh_action, + IPA.reset_action, + IPA.update_action); + + spec.control_buttons = spec.control_buttons || []; + spec.control_buttons.unshift( { name: 'refresh', label: IPA.messages.buttons.refresh, - icon: 'reset-icon', - action: { - handler: function(facet) { - facet.refresh(); - } - } + icon: 'reset-icon' }, { name: 'reset', label: IPA.messages.buttons.reset, - icon: 'reset-icon', - needs_confirm: true, - action: { - enable_cond: ['dirty'], - handler: function(facet) { - facet.reset(); - } - } + icon: 'reset-icon' }, { name: 'update', label: IPA.messages.buttons.update, - icon: 'update-icon', - action: { - enable_cond: ['dirty'], - handler: function(facet) { - if (!facet.validate()) { - facet.show_validation_error(); - return; - } + icon: 'update-icon' + }); - facet.update(); - } - } - } - ); - cb.state_listeners.push( - { - factory: IPA.dirty_state_listener - } - ); + spec.state = spec.state || {}; + spec.state.evaluators = spec.state.evaluators || []; + spec.state.evaluators.push(IPA.dirty_state_evaluator); var that = IPA.facet(spec, true); @@ -476,7 +453,7 @@ IPA.details_facet = function(spec, no_init) { field.load(data.result.result); } that.policies.post_load(data); - that.post_load.notify(); + that.post_load.notify([data], that); that.clear_expired_flag(); }; @@ -719,7 +696,8 @@ IPA.details_facet = function(spec, no_init) { var widget_builder = IPA.widget_builder({ widget_options: { - entity: that.entity + entity: that.entity, + facet: that } }); var field_builder = IPA.field_builder({ @@ -872,38 +850,107 @@ IPA.command_builder = function() { return that; }(); +IPA.select_action = function(spec) { + + spec = spec || {}; + spec.name = spec.name || 'select_action'; + spec.label = spec.label || '-- select action --'; + + var that = IPA.action(spec); + + that.execute_action = function(facet) { + }; + + return that; +}; + +IPA.refresh_action = function(spec) { + + spec = spec || {}; + spec.name = spec.name || 'refresh'; + spec.label = spec.label || IPA.messages.buttons.refresh; + + var that = IPA.action(spec); + + that.execute_action = function(facet) { + facet.refresh(); + }; + + return that; +}; + +IPA.reset_action = function(spec) { + + spec = spec || {}; + spec.name = spec.name || 'reset'; + spec.label = spec.label || IPA.messages.buttons.reset; + spec.enable_cond = spec.enable_cond || ['dirty']; + + var that = IPA.action(spec); + + that.execute_action = function(facet) { + facet.reset(); + }; + + return that; +}; + +IPA.update_action = function(spec) { + + spec = spec || {}; + spec.name = spec.name || 'update'; + spec.label = spec.label || IPA.messages.buttons.update; + spec.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : true; + spec.enable_cond = spec.enable_cond || ['dirty']; + + var that = IPA.action(spec); + + that.execute_action = function(facet) { + + if (!facet.validate()) { + facet.show_validation_error(); + return; + } + + facet.update(); + }; + + return that; +}; + IPA.boolean_state_evaluator = function(spec) { spec = spec || {}; + spec.event = spec.event || 'post_load'; + var that = IPA.state_evaluator(spec); + that.name = spec.name || 'boolean_state_evaluator'; that.field = spec.field; that.true_state = spec.true_state || that.field_name + '-true'; that.false_state = spec.false_state || that.field_name + '-false'; - that.true_desc = spec.true_desc || IPA.messages['true']; - that.false_desc = spec.false_desc || IPA.messages['false']; that.invert_value = spec.invert_value; that.parser = IPA.build({ factory: spec.parser || IPA.boolean_formatter, invert_value: that.invert_value }); - that.evaluate = function(record) { + that.on_event = function(data) { + var old_state = that.state; + var record = data.result.result; that.state = []; var value = that.parser.parse(record[that.field]); if (value === true) { that.state.push(that.true_state); - that.description = that.true_desc; } else { that.state.push(that.false_state); - that.description = that.false_desc; } - return that.state; + that.notify_on_change(old_state); }; return that; @@ -912,10 +959,9 @@ IPA.boolean_state_evaluator = function(spec) { IPA.enable_state_evaluator = function(spec) { spec = spec || {}; + spec.name = spec.name || 'enable_state_evaluator'; spec.true_state = spec.true_state || 'enabled'; spec.false_state = spec.false_state || 'disabled'; - spec.true_desc = spec.true_desc || IPA.messages.status.enabled; - spec.false_desc = spec.false_desc || IPA.messages.status.disabled; var that = IPA.boolean_state_evaluator(spec); @@ -931,7 +977,7 @@ IPA.object_action = function(spec) { that.method = spec.method; that.confirm_msg = spec.confirm_msg || IPA.messages.actions.confirm; - that.execute = function(facet, on_success, on_error) { + that.execute_action = function(facet, on_success, on_error) { var entity_name = facet.entity.name; var pkey = IPA.nav.get_state(entity_name+'-pkey'); @@ -1021,3 +1067,22 @@ IPA.delete_action = function(spec) { return that; }; + + +IPA.enabled_summary_cond = function() { + return { + pos: ['enabled'], + neg: [], + description: IPA.messages.status.enabled, + state: ['enabled'] + }; +}; + +IPA.disabled_summary_cond = function() { + return { + pos: [], + neg: ['enabled'], + description: IPA.messages.status.disabled, + state: ['disabled'] + }; +}; diff --git a/install/ui/facet.js b/install/ui/facet.js index 31a9df73c..ef8a06245 100644 --- a/install/ui/facet.js +++ b/install/ui/facet.js @@ -28,6 +28,8 @@ IPA.facet = function(spec, no_init) { spec = spec || {}; + spec.state = spec.state || {}; + $.extend(spec.state, { factory: IPA.state }); var that = {}; @@ -42,7 +44,10 @@ IPA.facet = function(spec, no_init) { that.disable_breadcrumb = spec.disable_breadcrumb; that.disable_facet_tabs = spec.disable_facet_tabs; - that.action_list = spec.action_list; + that.action_state = IPA.build(spec.state); + that.actions = IPA.build({ actions: spec.actions }, IPA.action_holder_builder); + + that.header_actions = spec.header_actions; that.header = spec.header || IPA.facet_header({ facet: that }); that._needs_update = spec.needs_update; @@ -299,16 +304,17 @@ IPA.facet = function(spec, no_init) { that.init_facet = function() { + that.action_state.init(that); + that.actions.init(that); + that.header.init(); + var buttons_spec = { factory: IPA.control_buttons_widget, name: 'control-buttons', - 'class': 'control-buttons' + 'class': 'control-buttons', + buttons: spec.control_buttons }; - if (spec.control_buttons) { - $.extend(buttons_spec, spec.control_buttons); - } - that.control_buttons = IPA.build(buttons_spec); that.control_buttons.init(that); }; @@ -335,9 +341,9 @@ IPA.facet_header = function(spec) { that.facet = spec.facet; - var init = function() { + that.init = function() { - if (that.facet.action_list) { + if (that.facet.header_actions) { var widget_builder = IPA.widget_builder({ widget_options: { @@ -345,10 +351,17 @@ IPA.facet_header = function(spec) { } }); - that.action_list = widget_builder.build_widget(that.facet.action_list); - that.action_list.init(); + var widget = { + factory: IPA.action_list_widget, + actions: that.facet.header_actions + }; + + that.action_list = widget_builder.build_widget(widget); + that.action_list.init(that.facet); } + that.facet.action_state.changed.attach(that.update_summary); + that.title_widget = IPA.facet_title(); }; @@ -587,17 +600,15 @@ IPA.facet_header = function(spec) { } } } + }; - if (that.action_list) { - that.action_list.update(result); - - var state = that.action_list.state; - var icon_tooltip = that.action_list.state_evaluator.get_description(); - if (state.length > 0) { - var css_class = state.join(' '); - that.title_widget.set_class(css_class); - that.title_widget.set_icon_tooltip(icon_tooltip); - } + that.update_summary = function() { + var summary = that.facet.action_state.summary(); + + if (summary.state.length > 0) { + var css_class = summary.state.join(' '); + that.title_widget.set_class(css_class); + that.title_widget.set_icon_tooltip(summary.description); } that.adjust_elements(); @@ -645,8 +656,6 @@ IPA.facet_header = function(spec) { that.load(); }; - init(); - return that; }; @@ -801,7 +810,7 @@ IPA.table_facet = function(spec, no_init) { that.table.pagination_control.css('visibility', 'visible'); - that.post_load.notify(); + that.post_load.notify([data], that); that.clear_expired_flag(); }; @@ -1245,19 +1254,79 @@ IPA.action = function(spec) { that.name = spec.name; that.label = spec.label; + + that.enabled = spec.enabled !== undefined ? spec.enabled : true; that.enable_cond = spec.enable_cond || []; that.disable_cond = spec.disable_cond || []; + that.enabled_changed = IPA.observer(); + + that.visible = spec.visible !== undefined ? spec.visible : true; + that.show_cond = spec.show_cond || []; + that.hide_cond = spec.hide_cond || []; + that.visible_changed = IPA.observer(); + that.handler = spec.handler; - that.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : true; + + that.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : false; that.confirm_msg = spec.confirm_msg || IPA.messages.actions.confirm; - that.execute = function(facet, on_success, on_error) { + + that.execute_action = function(facet, on_success, on_error) { if (that.handler) { that.handler(facet, on_success, on_error); } }; + that.execute = function(facet, on_success, on_error) { + + if (!that.enabled || !that.visible) return; + + if (that.needs_confirm) { + + var confirmed = false; + + if (that.confirm_dialog) { + + var dialog = IPA.build(that.confirm_dialog); + confirmed = dialog.confirm(that.facet); + } else { + var msg = that.get_confirm_message(); + confirmed = IPA.confirm(msg); + } + + if (!confirmed) return; + } + + that.execute_action(facet, on_success, on_error); + }; + + that.get_confirm_message = function() { + return that.confirm_msg; + }; + + that.set_enabled = function(enabled) { + + var old = that.enabled; + + that.enabled = enabled; + + if (old !== that.enabled) { + that.enabled_changed.notify([that.enabled], that); + } + }; + + that.set_visible = function(visible) { + + var old = that.visible; + + that.visible = visible; + + if (old !== that.visible) { + that.visible_changed.notify([that.visible], that); + } + }; + return that; }; @@ -1269,32 +1338,189 @@ IPA.action_builder = function(spec) { return that; }; -IPA.state_evaluator = function(spec) { + +IPA.action_holder = function(spec) { spec = spec || {}; var that = {}; - that.evaluate = function() { - that.state = []; - return that.state; + that.actions = $.ordered_map(); + + that.init = function(facet) { + + var i, action, actions; + + that.facet = facet; + actions = IPA.build(spec.actions, IPA.action_builder) || []; + + for (i=0; i<actions.length; i++) { + action = actions[i]; + that.actions.put(action.name, action); + } + + that.facet.action_state.changed.attach(that.state_changed); + that.facet.post_load.attach(that.on_load); }; - that.get_description = function() { - return that.description || ''; + that.state_changed = function(state) { + + var actions, action, i, enabled, visible; + + actions = that.actions.values; + + for (i=0; i<actions.length; i++) { + + action = actions[i]; + + enabled = IPA.eval_cond(action.enable_cond, action.disable_cond, state); + visible = IPA.eval_cond(action.show_cond, action.hide_cond, state); + action.set_enabled(enabled); + action.set_visible(visible); + } + }; + + that.get = function(name) { + return that.actions.get(name); + }; + + that.add = function(action) { + that.actions.put(action.name, action); + }; + + that.on_load = function() { + var state = that.facet.action_state.get(); + that.state_changed(state); }; return that; }; -IPA.state_listener = function(spec) { +IPA.action_holder_builder = function(spec) { spec = spec || {}; + spec.factory = spec.factory || IPA.action_holder; + var that = IPA.builder(spec); + return that; +}; + + +IPA.state = function(spec) { + + spec = spec || {}; + spec.summary_evaluator = spec.summary_evaluator || IPA.summary_evaluator; var that = {}; + that.state = $.ordered_map(); + + //when state changes. Params: state, Context: this + that.changed = IPA.observer(); + + that.evaluators = IPA.build(spec.evaluators, IPA.state_evaluator_builder) || []; + that.summary_evaluator = IPA.build(spec.summary_evaluator); + + that.summary_conditions = spec.summary_conditions || []; + + that.init = function(facet) { + + var i, evaluator; + + that.facet = facet; + + for (i=0; i<that.evaluators.length; i++) { + evaluator = that.evaluators[i]; + evaluator.init(facet); + evaluator.changed.attach(that.on_eval_changed); + } + }; + + that.on_eval_changed = function() { + + var evaluator = this; + + that.state.put(evaluator.name, evaluator.state); + + that.notify(); + }; + + that.get = function() { + + var state, i; + + state = []; + + var values = that.state.values; + + for (i=0; i<values.length; i++) { + $.merge(state, values[i]); + } + + return state; + }; + + that.summary = function() { + + var summary = that.summary_evaluator.evaluate(that); + return summary; + }; + + that.notify = function(state) { + + state = state || that.get(); + + that.changed.notify([state], that); + }; + + return that; +}; + +IPA.summary_evaluator = function(spec) { + + spec = spec || {}; + + var that = {}; + + that.evaluate = function(state) { + + var conds, cond, i, summary, state_a; + + conds = state.summary_conditions; + state_a = state.get(); + + for (i=0; i<conds.length; i++) { + cond = conds[i]; + if (IPA.eval_cond(cond.pos, cond.neg, state_a)) { + summary = { + state: cond.state, + description: cond.description + }; + break; + } + } + + summary = summary || { + state: state_a, + description: '' + }; + + return summary; + }; + + return that; +}; + +IPA.state_evaluator = function(spec) { + + spec = spec || {}; + + var that = {}; + + that.name = spec.name || 'state_evaluator'; that.event_name = spec.event; - that.state_changed = IPA.observer(); + + //when state changes. Params: state, Context: this + that.changed = IPA.observer(); that.state = []; that.init = function(facet) { @@ -1305,75 +1531,86 @@ IPA.state_listener = function(spec) { }; that.on_event = function() { - that.state_changed.notify(); }; - that.get_description = function() { - return that.description || ''; + that.notify_on_change = function(old_state) { + + if (IPA.array_diff(that.state, old_state)) { + that.changed.notify([that.state], that); + } }; return that; }; -IPA.state_listener_builder = function(spec) { +IPA.state_evaluator_builder = function(spec) { spec = spec || {}; - spec.factory = spec.factory || IPA.state_listener; + spec.factory = spec.factory || IPA.state_evaluator; var that = IPA.builder(spec); return that; }; -IPA.dirty_state_listener = function(spec) { +IPA.dirty_state_evaluator = function(spec) { spec = spec || {}; spec.event = spec.event || 'dirty_changed'; - var that = IPA.state_listener(spec); + var that = IPA.state_evaluator(spec); + that.name = spec.name || 'dirty_state_evaluator'; that.on_event = function(dirty) { + + var old_state = that.state; that.state = []; if (dirty) { that.state.push('dirty'); } - that.state_changed.notify(); + that.notify_on_change(old_state); }; return that; }; -IPA.selected_state_listener = function(spec) { +IPA.selected_state_evaluator = function(spec) { spec = spec || {}; spec.event = spec.event || 'select_changed'; - var that = IPA.state_listener(spec); + var that = IPA.state_evaluator(spec); + that.name = spec.name || 'selected_state_evaluator'; that.on_event = function(selected) { + + var old_state = that.state; that.state = []; if (selected && selected.length > 0) { that.state.push('item-selected'); } - that.state_changed.notify(); + that.notify_on_change(old_state); }; return that; }; -IPA.self_service_state_listener = function(spec) { +IPA.self_service_state_evaluator = function(spec) { spec = spec || {}; spec.event = spec.event || 'post_load'; - var that = IPA.state_listener(spec); + var that = IPA.state_evaluator(spec); + that.name = spec.name || 'self_service_state_evaluator'; that.on_event = function() { + + var old_state = that.state; that.state = []; var self_service = IPA.nav.name === 'self-service'; @@ -1382,7 +1619,7 @@ IPA.self_service_state_listener = function(spec) { that.state.push('self-service'); } - that.state_changed.notify(); + that.notify_on_change(old_state); }; return that; @@ -1400,17 +1637,22 @@ IPA.action_button_widget = function(spec) { that.href = spec.href || that.name; that.icon = spec.icon; - that.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : false; - that.confirm_msg = spec.confirm_msg || IPA.messages.actions.confirm; - that.confirm_dialog = spec.confirm_dialog; + that.action_name = spec.action || that.name; - that.action = IPA.build(spec.action, IPA.action_builder); that.enabled = spec.enabled !== undefined ? spec.enabled : true; that.visible = spec.visible !== undefined ? spec.visible : true; that.show_cond = spec.show_cond || []; that.hide_cond = spec.hide_cond || []; + that.init = function(facet) { + + that.facet = facet; + that.action = that.facet.actions.get(that.action_name); + that.action.enabled_changed.attach(that.set_enabled); + that.action.visible_changed.attach(that.set_visible); + }; + that.create = function(container) { that.widget_create(container); @@ -1426,42 +1668,15 @@ IPA.action_button_widget = function(spec) { } }).appendTo(container); - that.set_enabled(that.enabled); - that.set_visible(that.visible); + that.set_enabled(that.action.enabled); + that.set_visible(that.action.visible); }; that.on_click = function() { if (!that.enabled) return; - if (that.needs_confirm) { - - var confirmed = false; - - if (that.confirm_dialog) { - - var dialog = IPA.build(that.confirm_dialog); - confirmed = dialog.confirm(that.facet); - } else { - var msg = that.get_confirm_message(); - confirmed = IPA.confirm(msg); - } - - if (!confirmed) return; - } - - that.execute_action(); - }; - - that.get_confirm_message = function() { - return that.confirm_msg; - }; - - that.execute_action = function() { - - if (that.action) { - that.action.execute(that.facet); - } + that.action.execute(that.facet); }; that.set_enabled = function(enabled) { @@ -1508,27 +1723,16 @@ IPA.control_buttons_widget = function(spec) { var that = IPA.widget(spec); that.buttons = IPA.build(spec.buttons, IPA.action_button_widget_builder) || []; - that.state_listeners = IPA.build(spec.state_listeners, IPA.state_listener_builder) || []; - that.state = []; that.init = function(facet) { var i; - for (i=0; i<that.state_listeners.length; i++) { - - var listener = that.state_listeners[i]; - listener.init(facet); - listener.state_changed.attach(that.on_state_change); - } - for (i=0; i<that.buttons.length; i++) { var button = that.buttons[i]; - button.facet = facet; + button.init(facet); } - - that.on_state_change(); }; that.create = function(container) { @@ -1544,36 +1748,6 @@ IPA.control_buttons_widget = function(spec) { } }; - that.on_state_change = function() { - - that.get_state(); - that.reevaluate(); - }; - - that.get_state = function() { - - that.state = []; - - for (var i=0; i<that.state_listeners.length; i++) { - - var listener = that.state_listeners[i]; - that.state.push.apply(that.state, listener.state); - } - }; - - that.reevaluate = function() { - - for (var i=0; i<that.buttons.length; i++) { - - var button = that.buttons[i]; - var action = button.action; - var enabled = IPA.eval_cond(action.enable_cond, action.disable_cond, that.state); - var visible = IPA.eval_cond(button.show_cond, button.hide_cond, that.state); - button.set_enabled(enabled); - button.set_visible(visible); - } - }; - return that; }; @@ -1626,21 +1800,51 @@ IPA.action_list_widget = function(spec) { var that = IPA.composite_widget(spec); - that.actions = IPA.build(spec.actions, IPA.action_builder) || []; - that.state_evaluator = IPA.build(spec.state_evaluator); - that.state = []; + that.action_names = spec.actions || []; + that.actions = $.ordered_map(); + + that.init = function(facet) { + + var options, actions, action, name, i; + + that.facet = facet; - that.init = function() { that.action_select = that.widgets.get_widget('action'); that.apply_button = that.widgets.get_widget('apply'); that.action_select.value_changed.attach(that.on_action_change); that.apply_button.click = that.on_apply; - var options = []; + for (i=0; i<that.action_names.length; i++) { + name = that.action_names[i]; + action = that.facet.actions.get(name); + that.add_action(action, true); + } + + that.init_options(); + }; + + that.add_action = function(action, batch) { + that.actions.put(action.name, action); + action.enabled_changed.attach(that.action_enabled_changed); + action.visible_changed.attach(that.action_visible_changed); - for (var i=0; i< that.actions.length; i++) { - var action = that.actions[i]; + if(!batch) { + that.init_options(); + that.recreate_options(); + that.select_first_enabled(); + } + }; + + that.init_options = function() { + + var options, actions, action, i; + + options = []; + actions = that.actions.values; + + for (i=0; i< actions.length; i++) { + action = actions[i]; options.push({ label: action.label, value: action.name @@ -1650,71 +1854,62 @@ IPA.action_list_widget = function(spec) { that.action_select.options = options; }; + that.recreate_options = function() { + + that.action_select.create_options(); + }; + that.on_action_change = function() { - var selected = that.action_select.save()[0]; - var action = that.get_action(selected); - var enabled = that.action_enabled(action); - that.apply_button.set_enabled(enabled); + var action = that.get_selected(); + that.apply_button.set_enabled(action.enabled); }; that.on_apply = function() { - var selected = that.action_select.save()[0]; - var action = that.get_action(selected); - var enabled = that.action_enabled(action); - var facet = that.entity.get_facet(); - if (enabled) { - action.execute(facet, + var action = that.get_selected(); + + if (action.enabled) { + action.execute(that.facet, that.on_action_success, that.on_action_error); } }; that.on_action_success = function() { - var facet = that.entity.get_facet(); - facet.refresh(); - }; - that.on_action_error = function() { - var facet = that.entity.get_facet(); - facet.refresh(); + that.facet.refresh(); }; - that.update = function(result) { + that.on_action_error = function() { - that.get_state(result); - var disabled = that.get_disabled(); - that.action_select.enable_options(); - that.action_select.disable_options(disabled); - that.select_first_enabled(); + that.facet.refresh(); }; - that.get_state = function(result) { + that.action_enabled_changed = function(enabled) { + var action = this; + var selected_action = that.get_selected(); + that.action_select.set_options_enabled(action.enabled, [action.name]); - if (that.state_evaluator) { - that.state = that.state_evaluator.evaluate(result); + if (!action.enabled && action === selected_action) { + that.select_first_enabled(); } }; - that.get_action = function(name) { - - for (var i=0; i< that.actions.length; i++) { - var action = that.actions[i]; - if (action.name === name) { - return action; - } - } - return null; + that.get_selected = function() { + var selected = that.action_select.save()[0]; + var action = that.actions.get(selected); + return action; }; that.get_disabled = function() { var disabled = []; + var actions = that.action.values; - for (var i=0; i< that.actions.length; i++) { - var action = that.actions[i]; - if (!that.action_enabled(action)) { + for (var i=0; i< actions.length; i++) { + var action = actions[i]; + if (!that.action.enabled) { disabled.push(action.name); } } @@ -1722,21 +1917,15 @@ IPA.action_list_widget = function(spec) { return disabled; }; - that.action_enabled = function(action) { - - var enabled = IPA.eval_cond(action.enable_cond, - action.disable_cond, - that.state); - return enabled; - }; - that.select_first_enabled = function() { - var first = that.actions[0].name; + var actions = that.actions.values; + + var first = actions[0].name; - for (var i=0; i< that.actions.length; i++) { - var action = that.actions[i]; - if (that.action_enabled(action)) { + for (var i=0; i< actions.length; i++) { + var action = actions[i]; + if (action.enabled) { first = action.name; break; } diff --git a/install/ui/jquery.ordered-map.js b/install/ui/jquery.ordered-map.js index aa0d28143..7c0f3fadc 100755 --- a/install/ui/jquery.ordered-map.js +++ b/install/ui/jquery.ordered-map.js @@ -36,10 +36,17 @@ jQuery.ordered_map = jQuery.fn.ordered_map = function() { }; that.put = function(key, value) { - that.keys.push(key); - that.values.push(value); + + var i = that.get_key_index(key); + if (i >= 0) { + that.values[i] = value; + } else { + that.keys.push(key); + that.values.push(value); + that.length = that.keys.length; + } + that.map[key] = value; - that.length = that.keys.length; }; that.remove = function(key) { diff --git a/install/ui/search.js b/install/ui/search.js index 1b6cfab2a..845da57c1 100644 --- a/install/ui/search.js +++ b/install/ui/search.js @@ -37,58 +37,35 @@ IPA.search_facet = function(spec, no_init) { spec.disable_facet_tabs = spec.disable_facet_tabs === undefined ? true : spec.disable_facet_tabs; - spec.control_buttons = spec.control_buttons || {}; - - var cb = spec.control_buttons; - cb.factory = cb.factory || IPA.control_buttons_widget; - cb.buttons = cb.buttons || []; - cb.state_listeners = cb.state_listeners || []; - cb.buttons.unshift( + spec.actions = spec.actions || []; + spec.actions.unshift( + IPA.refresh_action, + IPA.batch_remove_action, + IPA.add_action); + + spec.control_buttons = spec.control_buttons || []; + spec.control_buttons.unshift( { name: 'refresh', label: IPA.messages.buttons.refresh, - icon: 'reset-icon', - action: { - handler: function(facet) { - facet.refresh(); - } - } + icon: 'reset-icon' }, { name: 'remove', label: IPA.messages.buttons.remove, - icon: 'remove-icon', - needs_confirm: true, - hide_cond: ['self-service'], - action: { - enable_cond: ['item-selected'], - handler: function(facet) { - facet.show_remove_dialog(); - } - } + icon: 'remove-icon' }, { name: 'add', label: IPA.messages.buttons.add, - icon: 'add-icon', - hide_cond: ['self-service'], - action: { - handler: function(facet) { - facet.show_add_dialog(); - } - } - } - ); - cb.state_listeners.push( - { - factory: IPA.selected_state_listener - }, - { - factory: IPA.self_service_state_listener - } - ); + icon: 'add-icon' + }); - //TODO: make buttons invisible on self-service. Currently regression. + spec.state = spec.state || {}; + spec.state.evaluators = spec.state.evaluators || []; + spec.state.evaluators.push( + IPA.selected_state_evaluator, + IPA.self_service_state_evaluator); var that = IPA.table_facet(spec, true); @@ -392,6 +369,39 @@ IPA.nested_search_facet = function(spec) { return that; }; +IPA.batch_remove_action = function(spec) { + + spec = spec || {}; + spec.name = spec.name || 'remove'; + spec.label = spec.label || IPA.messages.buttons.remove; + spec.enable_cond = spec.enable_cond || ['item-selected']; + spec.hide_cond = spec.hide_cond || ['self-service']; + + var that = IPA.action(spec); + + that.execute_action = function(facet) { + facet.show_remove_dialog(); + }; + + return that; +}; + +IPA.add_action = function(spec) { + + spec = spec || {}; + spec.name = spec.name || 'add'; + spec.label = spec.label || IPA.messages.buttons.add; + spec.hide_cond = spec.hide_cond || ['self-service']; + + var that = IPA.action(spec); + + that.execute_action = function(facet) { + facet.show_add_dialog(); + }; + + return that; +}; + /* * Calls entity's disable command for each selected item in a batch. * Usable in table facets. diff --git a/install/ui/widget.js b/install/ui/widget.js index d3efe499b..172e43a5c 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -839,29 +839,35 @@ IPA.select_widget = function(spec) { container.addClass('select-widget'); - var select = $('<select/>', { - name: that.name + that.select = $('<select/>', { + name: that.name, + change: function() { + that.value_changed.notify([], that); + return false; + } }).appendTo(container); + that.create_options(); + + if (that.undo) { + that.create_undo(container); + } + + that.create_error_link(container); + }; + + that.create_options = function() { + + that.select.empty(); + for (var i=0; i<that.options.length; i++) { var option = that.options[i]; $('<option/>', { text: option.label, value: option.value - }).appendTo(select); + }).appendTo(that.select); } - - if (that.undo) { - that.create_undo(container); - } - - that.select = $('select[name="'+that.name+'"]', that.container); - that.select.change(function() { - that.value_changed.notify([], that); - }); - - that.create_error_link(container); }; that.save = function() { @@ -891,17 +897,29 @@ IPA.select_widget = function(spec) { $('option', that.select).attr('selected', ''); }; - that.enable_options = function() { - $('option', that.select).attr('disabled', ''); + that.set_options_enabled = function(enabled, options) { + + var html_value = enabled ? '' : 'disabled'; + + if (!options) { + $('option', that.select).attr('disabled', html_value); + } else { + for (var i=0; i<options.length;i++) { + var value = options[i]; + var option = $('option[value="'+value+'"]', that.select); + option.attr('disabled', html_value); + } + } + }; + + that.enable_options = function(options) { + + that.set_options_enabled(true, options); }; that.disable_options = function(options) { - for (var i=0; i<options.length;i++) { - var value = options[i]; - var option = $('option[value="'+value+'"]', that.select); - option.attr('disabled', 'disabled'); - } + that.set_options_enabled(false, options); }; // methods that should be invoked by subclasses |