Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #109 from sunpietro/add-button-disabled-state
Browse files Browse the repository at this point in the history
EZP-23347 - As a developer I would like to handle disabled/enabled state of a button
  • Loading branch information
sunpietro committed Sep 16, 2014
2 parents c0b88d2 + 23ad00c commit 7d5252e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Resources/public/css/theme/views/actions/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
font-size: 60%;
}

.ez-view-buttonactionview .is-disabled .action-icon,
.ez-view-buttonactionview .is-disabled .action-label,
.ez-view-buttonactionview .is-disabled .action-hint {
.ez-view-buttonactionview [disabled] .action-icon,
.ez-view-buttonactionview [disabled] .action-label,
.ez-view-buttonactionview [disabled] .action-hint {
color: #808080;
}

Expand Down
6 changes: 3 additions & 3 deletions Resources/public/css/theme/views/buttonaction.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
font-size: 60%;
}

.ez-view-buttonactionview .is-disabled .action-icon,
.ez-view-buttonactionview .is-disabled .action-label,
.ez-view-buttonactionview .is-disabled .action-hint {
.ez-view-buttonactionview [disabled] .action-icon,
.ez-view-buttonactionview [disabled] .action-label,
.ez-view-buttonactionview [disabled] .action-hint {
color: #808080;
}

Expand Down
2 changes: 1 addition & 1 deletion Resources/public/css/views/bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
z-index: 1015;
}

.ez-view-barview .ez-actions-list .ez-action.is-disabled {
.ez-view-barview .ez-actions-list .ez-action[disabled] {
cursor: default;
}

Expand Down
19 changes: 18 additions & 1 deletion Resources/public/js/views/actions/ez-buttonactionview.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ YUI.add('ez-buttonactionview', function (Y) {
}
},

initializer: function () {
this.on('disabledChange', this._handleToggleButtonState);
},

/**
* Renders the action
*
Expand Down Expand Up @@ -82,8 +86,21 @@ YUI.add('ez-buttonactionview', function (Y) {
this.fire(this.get('actionId') + ACTION_SUFFIX, {
content: this.get('content')
});
}
},

/**
* Handles *:disabledChange event
*
* @method _handleToggleButtonState
* @param event {Object} event facade
* @protected
*/
_handleToggleButtonState: function (event) {
var buttons = this.get('container').all('.action-trigger'),
buttonMethod = event.newVal ? 'setAttribute' : 'removeAttribute';

buttons[buttonMethod]('disabled', event.newVal);
}
}, {
ATTRS: {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% verbatim %}
<button class="ez-action {{#if disabled}}is-disabled {{else}}{{#if actionId}}action-trigger {{/if}}{{/if}}{{#if hint}}with-hint{{/if}}" data-action="{{ actionId }}">
<button class="ez-action {{#if actionId}}action-trigger{{/if}}{{#if hint}} with-hint{{/if}}" data-action="{{ actionId }}" {{#if disabled}}disabled{{/if}}>
<div class="font-icon action-icon">
<p class="action-label">{{ label }}</p>
{{#if hint}}
Expand Down
18 changes: 18 additions & 0 deletions Tests/js/views/actions/assets/genericbuttonactionview-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ YUI.add('ez-genericbuttonactionview-tests', function (Y) {
});
});
this.wait();
},

'Should disable the button': function () {
var view = this.view;

view.render();
view.set('disabled', true);

Y.Assert.isTrue(view.get('container').one('.action-trigger').hasAttribute('disabled'), 'The button should be disabled');
},

'Should enable the button': function () {
var view = this.view;

view.render();
view.set('disabled', true);
view.set('disabled', false);
Y.Assert.isFalse(view.get('container').one('.action-trigger').hasAttribute('disabled'), 'The button should be enabled');
}
};
}, '', {requires: ['test', 'node-event-simulate']});
17 changes: 9 additions & 8 deletions Tests/js/views/actions/ez-buttonactionview.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>eZ Button Action view tests</title>
</head>
<body>

<div class="container"></div>

<script type="text/x-handlebars-template" id="buttonactionview-ez-template">
<button class="action {{#if disabled}}is-disabled{{else}}{{#if actionId}}action-trigger{{/if}}{{/if}}" data-action="{{ actionId }}">
<div class="font-icon action-icon">
<p class="action-label {{#if hint}}with-hint{{/if}}">{{ label }}</p>
{{#if hint}}
<p class="action-hint">{{ hint }}</p>
{{/if}}
</div>
</button>
<button class="ez-action {{#if actionId}}action-trigger{{/if}}{{#if hint}} with-hint{{/if}}" data-action="{{ actionId }}" {{#if disabled}}disabled{{/if}}>
<div class="font-icon action-icon">
<p class="action-label">{{ label }}</p>
{{#if hint}}
<p class="action-hint">{{ hint }}</p>
{{/if}}
</div>
</button>
</script>

<script type="text/javascript" src="../../../../node_modules/yui/yui/yui.js"></script>
Expand Down

0 comments on commit 7d5252e

Please sign in to comment.