summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--install/ui/src/freeipa/widget.js107
-rw-r--r--ipatests/test_webui/ui_driver.py7
2 files changed, 58 insertions, 56 deletions
diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js
index 3891bf9b1..0fcf61827 100644
--- a/install/ui/src/freeipa/widget.js
+++ b/install/ui/src/freeipa/widget.js
@@ -3449,7 +3449,7 @@ IPA.link_widget = function(spec) {
};
/**
- * Create link which behaves as button
+ * Create button
*
* @method
* @member IPA
@@ -3469,38 +3469,13 @@ IPA.link_widget = function(spec) {
*/
IPA.action_button = function(spec) {
- spec = spec || {};
-
- var button = $('<a/>', {
- id: spec.id,
- name: spec.name,
- href: spec.href || '#' + (spec.name || 'button'),
- title: text.get(spec.title || spec.label),
- 'class': 'button action-button',
- style: spec.style,
- click: spec.click,
- blur: spec.blur
- });
-
- if (spec.focusable === false) {
- button.attr('tabindex', '-1');
- }
+ spec = $.extend({}, spec);
- if (spec['class']) button.addClass(spec['class']);
-
- if (spec.icon) {
- $('<span/>', {
- 'class': 'icon '+spec.icon
- }).appendTo(button);
- }
-
- if (spec.label) {
- $('<span/>', {
- 'class': 'button-label',
- html: text.get(spec.label)
- }).appendTo(button);
- }
+ spec.element = spec.element || '<a/>';
+ spec.button_class = spec.button_class || 'button action-button';
+ var button = IPA.button(spec);
+ button.prop('href', spec.href || '#');
return button;
};
@@ -3518,30 +3493,53 @@ IPA.action_button = function(spec) {
* @param {string} [spec.title=label] button title
* @param {string} [spec.icon] icon name (class)
* @param {string} [spec.id]
- * @param {string} [spec.href]
* @param {string} [spec.style] css style
* @param {string} [spec.class]
+ * @param {string} [spec.button_class]
+ * @param {string} [spec.element]
+ * @param {string} [spec.type]
* @param {Function} [spec.click] click handler
+ * @param {boolean} [spec.focusable] button is focusable
+ * @param {Function} [spec.blur] blur handler
*/
IPA.button = function(spec) {
spec = spec || {};
- var button = $('<a/>', {
+ var el = spec.element || '<button/>';
+ var button_class = spec.button_class || 'btn';
+
+ var button = $(el, {
id: spec.id,
name: spec.name,
- href: spec.href || '#' + (spec.name || 'button')
+ title: text.get(spec.title || spec.label),
+ 'class': button_class,
+ style: spec.style,
+ click: spec.click,
+ type: spec.type || 'button',
+ blur: spec.blur
});
- var icons = { primary: spec.icon };
- var label = text.get(spec.label);
+ if (spec.focusable === false) {
+ button.attr('tabindex', '-1');
+ }
- button.button({
- icons: icons,
- label: label
- });
+ if (spec['class']) button.addClass(spec['class']);
+
+ if (spec.type) button.addClass(spec.type);
- button.click(spec.click);
+ if (spec.icon) {
+ $('<span/>', {
+ 'class': 'icon '+spec.icon
+ }).appendTo(button);
+ }
+
+ if (spec.label) {
+ $('<span/>', {
+ 'class': 'button-label',
+ html: text.get(spec.label)
+ }).appendTo(button);
+ }
return button;
};
@@ -3558,16 +3556,22 @@ IPA.button_widget = function(spec) {
var that = IPA.widget(spec);
- /** Displayed link */
- that.href = spec.href;
- /** CSS style */
+ /**
+ * Additional CSS style
+ * @property
+ */
that.style = spec.style;
- /** Click handler */
+ /**
+ * Click handler
+ * @property {Function}
+ */
that.click = spec.click;
- /** CSS class */
+
+ /**
+ * Additional CSS class(es)
+ * @property {String}
+ */
that['class'] = spec['class'];
- /** CSS class for disabled button */
- that.disabled_class = 'button-disabled';
/**
* Widget click handler.
@@ -3587,7 +3591,6 @@ IPA.button_widget = function(spec) {
that.button = IPA.button({
id: that.id,
name: that.name,
- href: that.href,
title: that.tooltip,
label: that.label,
'class': that['class'],
@@ -3603,11 +3606,7 @@ IPA.button_widget = function(spec) {
that.widget_set_enabled(enabled);
if (that.button) {
- if (enabled) {
- that.button.removeClass(that.disabled_class);
- } else {
- that.button.addClass(that.disabled_class);
- }
+ that.button.prop('disabled', !enabled);
}
};
diff --git a/ipatests/test_webui/ui_driver.py b/ipatests/test_webui/ui_driver.py
index dabe4a7db..65d14f9ae 100644
--- a/ipatests/test_webui/ui_driver.py
+++ b/ipatests/test_webui/ui_driver.py
@@ -583,12 +583,15 @@ class UI_driver(object):
if not parent:
parent = self.get_form()
- s = "a[name='%s'].ui-button" % name
+ s = "[name='%s'].btn" % name
self._button_click(s, parent, name)
def _button_click(self, selector, parent, name=''):
btn = self.find(selector, By.CSS_SELECTOR, parent, strict=True)
- disabled = 'ui-state-disabled' in btn.get_attribute("class").split()
+
+ disabled = 'ui-state-disabled' in btn.get_attribute("class").split() or \
+ btn.get_attribute("disabled")
+
assert btn.is_displayed(), 'Button is not displayed: %s' % name
assert not disabled, 'Invalid button state: disabled. Button: %s' % name
btn.click()