Skip to content

Instantly share code, notes, and snippets.

@csprocket777
Last active August 29, 2015 14:00
Show Gist options
  • Save csprocket777/ec02f90c8705e3263cc5 to your computer and use it in GitHub Desktop.
Save csprocket777/ec02f90c8705e3263cc5 to your computer and use it in GitHub Desktop.
Hack solution to updating Ember.Select with computed property created using defineProperty()
export default Ember.View.extend({
didInsertElement: function(){
var self = this;
setTimeout(function(){
self.get('controller.model').fixBindingsHack();
}, 100);
}
});
import BaseModel from "appkit/models/base-model";
export default BaseModel.extend({
title: DS.attr('string'),
order: DS.attr('number'),
active: DS.attr('boolean'),
step_type: DS.attr('number'),
step_type_label: DS.attr('string'),
model_name: DS.attr('string'),
record_workflow_segment_step_params: DS.hasMany('record-workflow-segment-step-param', {inverse: 'record_workflow_segment_step'}),
record_workflow_segment: DS.belongsTo('record-workflow-segment', {inverse:'record_workflow_segment_steps'}),
dynamicPropertiesList: Ember.A([]),
setupExistingParams: function(){
Ember.defineProperty(this, 'record_phase', Ember.computed('record_workflow_segment_step_params.[]', function(key, value){
if( this.get('step_type').toString() !== "1" ){
return undefined;
}
var param = this.get('record_workflow_segment_step_params').findBy('name', 'record_phase');
if( !Ember.isNone( value ) && param )
{
param.set('value', value);
}
if( !Ember.isBlank(param.get("model_name")) )
{
return Ember.isNone(param.get('value')) ? null: this.store.find( param.get('model_name'), param.get('value') );
}else{
return param ? param.get('value').toString(): null;
}
}).property());
this.get('dynamicPropertiesList').pushObject('record_phase');
this.set('dynamicPropertiesExist', true);
}.on('didLoad'),
dynamicPropertiesExist: false,
fixBindingsHack: function(){
this.get('dynamicPropertiesList').forEach(function(item){
if( !Ember.isBlank( this.get(item) ) )
{
var tmp = this.get(item);
this.set(item, "1000000000000");
this.set(item, tmp);
}
tmp = null;
}, this);
}
});
{{#each step in arrangedContent itemController="list-item-controller" itemView="list-item-view"}}
<label>Select a phase to assign:</label>
{{view Ember.Select
classNames="form-control"
content=phaseOptions
optionLabelPath="content.title"
optionValuePath="content.id"
value=step.record_phase
prompt="Select a phase to assign"
}}
{{/each}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment