Forked from peavers/components.site-power-select.js
Created
November 19, 2017 21:15
-
-
Save cibernox/8190803f892e2a47796b95c40aa3a91e to your computer and use it in GitHub Desktop.
power-select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const {get, set, Component} = Ember; | |
export default Component.extend({ | |
tagName: "", | |
classNames: "", | |
actions: { | |
customAction(items) { | |
const dashboard = get(this, 'dashboard'); | |
let objects = get(dashboard, 'powerSelects'); | |
if (objects === null) { | |
objects = {}; | |
} | |
items.forEach(function (item) { | |
const parent = item.get('object.title'); | |
const child = item.get('title'); | |
objects[parent].push({title: child}); | |
}); | |
dashboard.set('powerSelects', objects); | |
dashboard.save(); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
// Empty array | |
powerSelects: attr(), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
title: attr('string'), | |
powerSelect: belongsTo('power-select'), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
title: attr('string'), | |
options: hasMany('power-select-option'), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return RSVP.hash({ | |
powerSelects: get(this, 'store').findAll('power-select'), | |
}); | |
}, | |
setupController(controller, models) { | |
this._super(...arguments); | |
controller.setProperties(models); | |
}, | |
actions: { | |
addPowerSelect() { | |
const powerSelect = get(this, 'store').createRecord('power-select'); | |
powerSelect.save(); | |
}, | |
addOption(powerSelect) { | |
const option = this.get('store').createRecord('power-select-option', { | |
powerSelect: powerSelect | |
}); | |
option.save().then(() => { | |
powerSelect.save(); | |
}); | |
}, | |
}, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1", | |
"ember-power-select": "1.9.10" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment