Skip to content

Commit

Permalink
add blockless version. closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Mar 25, 2015
1 parent 46b7850 commit a283762
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 1 deletion.
41 changes: 41 additions & 0 deletions addon/components/x-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,47 @@ export default Ember.Component.extend({
*/
tabindex: 1,

/**
* Auxiliary computed property that replaces `content.`
* in `optionLabelPath`.
*
* @private
* @property _labelPath
*/
_labelPath: Ember.computed('optionLabelPath', function() {
return this.get('optionLabelPath').replace(/^content\.?/, '');
}),

/**
* Alias to `value`.
* This way we accept `value` or `selection` properties.
*
* @property selection
*/
selection: Ember.computed.alias('value'),

/**
* Alias to `prompt`.
* This way we accept `prompt` or `placeholder` properties.
*
* @property placeholder
*/
placeholder: Ember.computed.alias('prompt'),

/**
* Auxiliary computed array that holds `content` array
* values and their labels. Used only in the blockless version.
*
* @private
* @property _optionValues
*/
_optionValues: Ember.computed.map('content', function(obj) {
return {
value: obj,
label: Ember.get(obj, this.get('_labelPath'))
};
}),

/**
* The collection of options for this select box. When options are
* inserted into the dom, they will register themselves with their
Expand Down
10 changes: 10 additions & 0 deletions app/templates/components/x-select.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{#if template}}
{{yield}}
{{else}}
{{#if placeholder}}
<option>{{placeholder}}</option>
{{/if}}
{{#each option in _optionValues}}
{{#x-option value=option.value}}{{option.label}}{{/x-option}}
{{/each}}
{{/if}}
11 changes: 11 additions & 0 deletions tests/dummy/app/controllers/blockless-multiple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Ember from 'ember';
import Folks from 'dummy/mixins/folks';

export default Ember.ObjectController.extend(Folks, {
isDisabled: false,
actions: {
tagYouAreIt: function(object) {
this.tagged = object;
}
}
});
11 changes: 11 additions & 0 deletions tests/dummy/app/controllers/blockless-single.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Ember from 'ember';
import Folks from 'dummy/mixins/folks';

export default Ember.ObjectController.extend(Folks, {
isDisabled: false,
actions: {
tagYouAreIt: function(object) {
this.tagged = object;
}
}
});
2 changes: 2 additions & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var Router = Ember.Router.extend({
Router.map(function() {
this.route('single');
this.route('multiple');
this.route('blockless-single');
this.route('blockless-multiple');
});

export default Router;
13 changes: 13 additions & 0 deletions tests/dummy/app/routes/blockless-multiple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ember from 'ember';
import Folks from 'dummy/mixins/folks';

export default Ember.Route.extend(Folks, {
model: function() {
return Ember.A([this.get('bastion')]);
},
setupController: function(controller, model) {
this._super.apply(this, arguments);
controller.set('it', model);
controller.set('folks', Ember.A([this.get('bastion'), this.get('stanley'), this.get('charles')]));
}
});
13 changes: 13 additions & 0 deletions tests/dummy/app/routes/blockless-single.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ember from 'ember';
import Folks from 'dummy/mixins/folks';

export default Ember.Route.extend(Folks, {
model: function() {
return this.get('bastion');
},
setupController: function(controller, model) {
this._super.apply(this, arguments);
controller.set('it', model);
controller.set('folks', Ember.A([this.get('bastion'), this.get('stanley'), this.get('charles')]));
}
});
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1> XSelect </h1>

{{#link-to 'single'}}Single{{/link-to}} | {{#link-to 'multiple'}}Multiple{{/link-to}}
{{#link-to 'single'}}Single{{/link-to}} | {{#link-to 'multiple'}}Multiple{{/link-to}} | {{#link-to 'blockless-single'}}Blockless Single{{/link-to}} | {{#link-to 'blockless-multiple'}}Blockless Multiple{{/link-to}}

<div>
{{outlet}}
Expand Down
15 changes: 15 additions & 0 deletions tests/dummy/app/templates/blockless-multiple.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p>
{{x-select action="tagYouAreIt" disabled=isDisabled
multiple=true
content=folks
selection=it
optionLabelPath="content.name"}}
</p>
<p>Selected:</p>
<ul>
{{#each selection in model}}
<li>{{selection.name}}</li>
{{else}}
<li>(None)</li>
{{/each}}
</ul>
8 changes: 8 additions & 0 deletions tests/dummy/app/templates/blockless-single.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>
{{x-select action="tagYouAreIt" disabled=isDisabled
content=folks
selection=it
optionLabelPath="content.name"
prompt="choose one"}}
</p>
<p>Selected: {{it.name}}</p>

0 comments on commit a283762

Please sign in to comment.