2014-07-13 14:11:38 -04:00
|
|
|
export default Ember.Component.extend({
|
|
|
|
tagName: 'div',
|
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
_init: function(){
|
2014-07-13 14:11:38 -04:00
|
|
|
this.$("input").select2({
|
|
|
|
multiple: true,
|
|
|
|
width: '100%',
|
2015-03-17 17:59:05 -04:00
|
|
|
query: function(opts) {
|
|
|
|
opts.callback({ results: this.get("available").map(this._format) });
|
2014-07-13 14:11:38 -04:00
|
|
|
}.bind(this)
|
|
|
|
}).on("change", function(evt) {
|
|
|
|
if (evt.added){
|
2015-03-17 17:59:05 -04:00
|
|
|
this.triggerAction({
|
|
|
|
action: "groupAdded",
|
|
|
|
actionContext: this.get("available").findBy("id", evt.added.id)
|
|
|
|
});
|
2014-07-13 14:11:38 -04:00
|
|
|
} else if (evt.removed) {
|
2015-03-17 17:59:05 -04:00
|
|
|
this.triggerAction({
|
|
|
|
action:"groupRemoved",
|
|
|
|
actionContext: evt.removed.id
|
|
|
|
});
|
2014-07-13 14:11:38 -04:00
|
|
|
}
|
|
|
|
}.bind(this));
|
2015-03-17 17:59:05 -04:00
|
|
|
|
2014-07-15 09:35:16 -04:00
|
|
|
this._refreshOnReset();
|
2015-03-17 17:59:05 -04:00
|
|
|
}.on("didInsertElement"),
|
2014-07-13 14:11:38 -04:00
|
|
|
|
2015-03-17 17:59:05 -04:00
|
|
|
_format(item) {
|
|
|
|
return {
|
|
|
|
"text": item.name,
|
|
|
|
"id": item.id,
|
|
|
|
"locked": item.automatic
|
|
|
|
};
|
2014-07-13 14:11:38 -04:00
|
|
|
},
|
|
|
|
|
2014-07-15 09:35:16 -04:00
|
|
|
_refreshOnReset: function() {
|
2014-07-13 14:11:38 -04:00
|
|
|
this.$("input").select2("data", this.get("selected").map(this._format));
|
|
|
|
}.observes("selected")
|
2014-12-10 13:15:30 -05:00
|
|
|
});
|