Skip to content

Instantly share code, notes, and snippets.

@taburetkin
Created September 11, 2018 10:33
Show Gist options
  • Save taburetkin/beed1781c3bc123a9d9f4214daa611f3 to your computer and use it in GitHub Desktop.
Save taburetkin/beed1781c3bc123a9d9f4214daa611f3 to your computer and use it in GitHub Desktop.
edit-model control
import ControlWrapper from 'components/controls/wrapper';
//import CollectionView from 'base/collection-view';
import ModelSchema from '../model-schema';
import EditProperty from './edit-property';
export default ControlWrapper.extend({
className:'edit-model-control',
renderAllCustoms: true,
isControlWrapper: false,
validateOnReady: true,
shouldShowError: false,
buttonsInFooter: true,
constructor(options = {}){
ControlWrapper.apply(this, arguments);
this.schema = new ModelSchema(options.properties || this.properties);
if(this.getOption('validateOnReady')){
this.once('customs:render', () => this.makeControlReady());
}
},
buildCustom(property){
if(_.isString(property)) {
let view = new EditProperty({
controlName: property,
propertySchema: this.schema.getProperty(property, { create: true }),
property,
value: this.getPropertyValue(property),
proxyTo: this
});
return view;
} else {
return ControlWrapper.prototype.buildCustom.apply(this, arguments);
}
},
getPropertyValue(property){
if(!this.model) return;
return this.model.get(property);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment