diff --git a/addon/components/x-select.js b/addon/components/x-select.js index 87940b2..560013e 100644 --- a/addon/components/x-select.js +++ b/addon/components/x-select.js @@ -55,37 +55,6 @@ export default Ember.Component.extend({ */ tabindex: 0, - /** - * Auxiliary computed property that replaces `content.` - * in `optionValuePath`. - * - * @private - * @property _valuePath - */ - _valuePath: Ember.computed('optionValuePath', function() { - var optionValuePath = this.get('optionValuePath'); - if (optionValuePath) { - return optionValuePath.replace(/^content\.?/, ''); - } - return null; - }), - - /** - * Auxiliary computed property that replaces `content.` - * in `optionLabelPath`. - * - * @private - * @property _labelPath - */ - _labelPath: Ember.computed('optionLabelPath', function() { - var optionLabelPath = this.get('optionLabelPath'); - - if (optionLabelPath) { - return optionLabelPath.replace(/^content\.?/, ''); - } - return null; - }), - /** * Alias to `value`. * This way we accept `value` or `selection` properties. @@ -102,38 +71,6 @@ export default Ember.Component.extend({ */ 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('_labelPath', '_valuePath', 'content.[]', function() { - var content = this.get('content') || []; - return content.map((object) => { - var label; - var value = object; - var valuePath = this.get('_valuePath'); - var labelPath = this.get('_labelPath'); - - if (valuePath) { - value = Ember.get(object, valuePath); - } - - if (labelPath) { - label = Ember.get(object, labelPath); - } else { - label = value; - } - - return { - value: value, - label: label - }; - }); - }), - /** * The collection of options for this select box. When options are * inserted into the dom, they will register themselves with their diff --git a/app/templates/components/x-select.hbs b/app/templates/components/x-select.hbs index 380d093..889d9ee 100644 --- a/app/templates/components/x-select.hbs +++ b/app/templates/components/x-select.hbs @@ -1,10 +1 @@ -{{#if hasBlock}} - {{yield}} -{{else}} - {{#if placeholder}} - - {{/if}} - {{#each _optionValues as |option|}} - {{#x-option value=option.value}}{{option.label}}{{/x-option}} - {{/each}} -{{/if}} +{{yield}} diff --git a/tests/acceptance/x-select-multiple-blockless-test.js b/tests/acceptance/x-select-multiple-blockless-test.js deleted file mode 100644 index a6e1613..0000000 --- a/tests/acceptance/x-select-multiple-blockless-test.js +++ /dev/null @@ -1,87 +0,0 @@ -/*global expect */ -/* jshint expr:true */ - -import Ember from 'ember'; -import startApp from '../helpers/start-app'; -import { it } from 'ember-mocha'; -import { beforeEach, afterEach, describe } from '../test-helper'; -import { shouldBindAttrs } from './shared/attr-test'; - -var App; - -describe('XSelect: Multiple Selection Blockless', function() { - beforeEach(function() { - App = startApp(); - visit("/blockless-multiple"); - }); - beforeEach(function() { - var el = Ember.$('select'); - this.component = getComponentById(el.attr('id')); - this.$ = function() { - return this.component.$.apply(this.component, arguments); - }; - this.controller = App.__container__.lookup('controller:blocklessMultiple'); - }); - - afterEach(function() { - Ember.run(App, 'destroy'); - }); - - it("does not fire any actions on didInsertElement", function() { - expect(this.controller.get('changedSelections')).not.to.be.ok; - }); - - it('marks all selected values', function() { - expect(this.$('option:eq(1)')).to.be.selected; - expect(this.$('option:eq(2)')).to.be.selected; - }); - - describe('choosing the last option', function() { - beforeEach(function() { - select('.x-select', 'Stanley'); - }); - - it('invokes action', function() { - expect(this.controller.get('it.length')).to.equal(1); - expect(this.controller.get('it.firstObject.name')).to.deep.equal('Stanley'); - }); - }); - - describe('manually setting the selected binding', function() { - beforeEach(function() { - this.controller.set('it', [this.controller.get('charles'), this.controller.get('stanley')]); - }); - it('updates the selected option', function() { - expect(this.$('option:first')).to.be.selected; - expect(this.$('option:eq(2)')).to.be.selected; - }); - }); - - describe("when no option is selected", function() { - beforeEach(function() { - this.$().prop('selectedIndex', 3).trigger('change'); - }); - it("has the empty array as a value", function() { - expect(this.controller.get('it.length')).to.equal(0); - }); - }); - - describe("trying to set the value to a non-array", function() { - beforeEach(function() { - try { - Ember.run(() => { - this.controller.set('it', 'OHAI!'); - }); - } catch (e) { - this.exception = e; - } - }); - it("throws an error", function() { - expect(this.exception).not.to.be.undefined; - expect(this.exception.message).to.match(/enumerable/); - }); - - }); - - shouldBindAttrs(); -}); diff --git a/tests/acceptance/x-select-single-blockless-option-value-test.js b/tests/acceptance/x-select-single-blockless-option-value-test.js deleted file mode 100644 index 6b359fc..0000000 --- a/tests/acceptance/x-select-single-blockless-option-value-test.js +++ /dev/null @@ -1,104 +0,0 @@ -/*global expect */ -/* jshint expr:true */ - -import Ember from 'ember'; -import startApp from '../helpers/start-app'; -import { it } from 'ember-mocha'; -import { beforeEach, afterEach, describe } from '../test-helper'; - -var App; - -describe('XSelect: Single Selection Blockless w/ Option Value', function() { - var component, controller; - beforeEach(function() { - App = startApp(); - visit("/blockless-single-option-value"); - }); - beforeEach(function() { - var el = Ember.$('select'); - component = getComponentById(el.attr('id')); - this.$ = function() { - return component.$.apply(component, arguments); - }; - controller = App.__container__.lookup('controller:blocklessSingleOptionValue'); - }); - - afterEach(function() { - Ember.run(App, 'destroy'); - }); - - it("does not fire any actions on didInsertElement", function() { - expect(controller.get('tagged')).not.to.be.ok; - }); - - it('is enabled by default', function() { - expect(this.$()).not.to.be.disabled; - }); - - it('renders the first option for placeholder', function() { - expect(this.$('option').length).to.equal(4); - expect(this.$('option:first')).to.have.text('choose one'); - }); - - it('renders an option for each view', function() { - expect(this.$('option').length).to.equal(4); - expect(this.$('option:eq(1)')).to.have.text('Bastion'); - expect(this.$('option:last')).to.have.text('Charles'); - }); - - it('placeholder is the default selected option', function() { - var self = this; - Ember.run(function() { - expect(self.$('option:eq(1)')).to.be.selected; - }); - }); - - describe('choosing the last option', function() { - beforeEach(function() { - this.$().prop('selectedIndex', 3).trigger('change'); - }); - - it('invokes action', function() { - expect(controller.get('tagged')).to.equal('yep'); - }); - }); - - - describe('manually setting the selected binding', function() { - beforeEach(function() { - controller.set('selectionValue', 'yep'); - }); - - it('updates the selected option', function() { - expect(this.$('option:eq(3)')).to.be.selected; - }); - }); - - describe('disabling', function() { - beforeEach(function() { - controller.set('isDisabled', true); - }); - it('disables the select box', function() { - expect(this.$()).not.to.be.enabled; - }); - }); - - describe("when no option is selected", function() { - beforeEach(function() { - this.$().prop('selectedIndex', 4).trigger('change'); - }); - it("has no value", function() { - expect(controller.get('tagged')).to.equal(null); - }); - }); - - describe('setting optionLabelPath to null', function() { - beforeEach(function() { - controller.set('optionLabelPath', null); - }); - - it('should not break the page', function() { - expect(this.$()).to.exist; - }); - }); -}); diff --git a/tests/acceptance/x-select-single-blockless-test.js b/tests/acceptance/x-select-single-blockless-test.js deleted file mode 100644 index f609f43..0000000 --- a/tests/acceptance/x-select-single-blockless-test.js +++ /dev/null @@ -1,93 +0,0 @@ -/*global expect */ -/* jshint expr:true */ - -import Ember from 'ember'; -import startApp from '../helpers/start-app'; -import { it } from 'ember-mocha'; -import { beforeEach, afterEach, describe } from '../test-helper'; -import { charles } from 'dummy/mixins/folks'; -import { shouldBindAttrs } from './shared/attr-test'; - -var App; - -describe('XSelect: Single Selection Blockless', function() { - beforeEach(function() { - App = startApp(); - visit("/blockless-single"); - }); - beforeEach(function() { - var el = Ember.$('select'); - this.component = getComponentById(el.attr('id')); - this.$ = function() { - return this.component.$.apply(this.component, arguments); - }; - this.controller = App.__container__.lookup('controller:blocklessSingle'); - }); - - afterEach(function() { - Ember.run(App, 'destroy'); - }); - - it("does not fire any actions on didInsertElement", function() { - expect(this.controller.get('tagged')).not.to.be.ok; - }); - - it('is enabled by default', function() { - expect(this.$()).not.to.be.disabled; - }); - - it('renders the first option for placeholder', function() { - expect(this.$('option').length).to.equal(4); - expect(this.$('option:first')).to.have.text('choose one'); - }); - - it('renders an option for each view', function() { - expect(this.$('option').length).to.equal(4); - expect(this.$('option:eq(1)')).to.have.text('Bastion'); - expect(this.$('option:last')).to.have.text('Charles'); - }); - - it('placeholder is the default selected option', function() { - expect(this.$('option:eq(1)')).to.be.selected; - }); - - describe('choosing the last option', function() { - beforeEach(function() { - this.$().prop('selectedIndex', 3).trigger('change'); - }); - - it('invokes action', function() { - expect(this.controller.get('tagged')).to.equal(charles); - }); - }); - - describe('manually setting the selected binding', function() { - beforeEach(function() { - this.controller.set('it', this.controller.get('charles')); - }); - it('updates the selected option', function() { - expect(this.$('option:eq(3)')).to.be.selected; - }); - }); - - describe('disabling', function() { - beforeEach(function() { - this.controller.set('isDisabled', true); - }); - it('disables the select box', function() { - expect(this.$()).not.to.be.enabled; - }); - }); - - describe("when no option is selected", function() { - beforeEach(function() { - this.$().prop('selectedIndex', 4).trigger('change'); - }); - it("has no value", function() { - expect(this.controller.get('tagged')).to.equal(null); - }); - }); - - shouldBindAttrs(); - -}); diff --git a/tests/dummy/app/controllers/blockless-multiple.js b/tests/dummy/app/controllers/blockless-multiple.js deleted file mode 100644 index 2f7d1a9..0000000 --- a/tests/dummy/app/controllers/blockless-multiple.js +++ /dev/null @@ -1,14 +0,0 @@ -import Ember from 'ember'; -import Folks from 'dummy/mixins/folks'; - -export default Ember.Controller.extend(Folks, { - isDisabled: false, - actions: { - tagYouAreIt: function(object) { - this.tagged = object; - }, - removeFolk: function(folk) { - this.get('folks').removeObject(folk); - } - } -}); diff --git a/tests/dummy/app/controllers/blockless-single-option-value.js b/tests/dummy/app/controllers/blockless-single-option-value.js deleted file mode 100644 index 4545d24..0000000 --- a/tests/dummy/app/controllers/blockless-single-option-value.js +++ /dev/null @@ -1,17 +0,0 @@ -import Ember from 'ember'; -import Folks from 'dummy/mixins/folks'; - -export default Ember.Controller.extend(Folks, { - isDisabled: false, - optionValuePath: 'content.cowboy', - optionLabelPath: 'content.name', - - actions: { - tagYouAreIt: function(object) { - this.tagged = object; - }, - removeFolk: function(folk) { - this.get('folks').removeObject(folk); - } - } -}); diff --git a/tests/dummy/app/controllers/blockless-single.js b/tests/dummy/app/controllers/blockless-single.js deleted file mode 100644 index 2f7d1a9..0000000 --- a/tests/dummy/app/controllers/blockless-single.js +++ /dev/null @@ -1,14 +0,0 @@ -import Ember from 'ember'; -import Folks from 'dummy/mixins/folks'; - -export default Ember.Controller.extend(Folks, { - isDisabled: false, - actions: { - tagYouAreIt: function(object) { - this.tagged = object; - }, - removeFolk: function(folk) { - this.get('folks').removeObject(folk); - } - } -}); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 160b516..cf2b91e 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -8,9 +8,6 @@ var Router = Ember.Router.extend({ Router.map(function() { this.route('single'); this.route('multiple'); - this.route('blockless-single'); - this.route('blockless-single-option-value'); - this.route('blockless-multiple'); this.route('zany-embedded-html'); }); diff --git a/tests/dummy/app/routes/blockless-multiple.js b/tests/dummy/app/routes/blockless-multiple.js deleted file mode 100644 index c8cc6b3..0000000 --- a/tests/dummy/app/routes/blockless-multiple.js +++ /dev/null @@ -1,13 +0,0 @@ -import Ember from 'ember'; -import Folks from 'dummy/mixins/folks'; - -export default Ember.Route.extend(Folks, { - model: function() { - return Ember.A([this.get('bastion'), this.get('stanley')]); - }, - setupController: function(controller, model) { - this._super.apply(this, arguments); - controller.set('it', model); - controller.set('folks', Ember.A([this.get('charles'), this.get('bastion'), this.get('stanley') ])); - } -}); diff --git a/tests/dummy/app/routes/blockless-single-option-value.js b/tests/dummy/app/routes/blockless-single-option-value.js deleted file mode 100644 index a76af80..0000000 --- a/tests/dummy/app/routes/blockless-single-option-value.js +++ /dev/null @@ -1,14 +0,0 @@ -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) { - this._super.apply(this, arguments); - controller.set('selectionValue', 'nope'); - controller.set('folks', Ember.A([this.get('bastion'), this.get('stanley'), this.get('charles')])); - } -}); diff --git a/tests/dummy/app/routes/blockless-single.js b/tests/dummy/app/routes/blockless-single.js deleted file mode 100644 index 2e8df9e..0000000 --- a/tests/dummy/app/routes/blockless-single.js +++ /dev/null @@ -1,13 +0,0 @@ -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')])); - } -}); diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index cf0baaf..ec03c4d 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1,6 +1,6 @@
-{{x-select action="tagYouAreIt" disabled=isDisabled - multiple=true - content=folks - selection=it - optionLabelPath="content.name" - title=title - required=isRequired - autofocus=hasAutofocus - name=attrName - form=attrForm - size=attrSize}} -
-Selected:
-All options:
--{{x-select action="tagYouAreIt" disabled=isDisabled - content=folks - selection=selectionValue - optionValuePath=optionValuePath - optionLabelPath=optionLabelPath - prompt="choose one"}} -
-Cowboy? {{selectionValue}}
-All options:
--{{x-select action="tagYouAreIt" disabled=isDisabled - content=folks - selection=it - optionLabelPath="content.name" - prompt="choose one" - title=title - required=isRequired - autofocus=hasAutofocus - name=attrName - form=attrForm - size=attrSize}} -
-Selected: {{it.name}}
-All options:
-