Created
September 11, 2018 10:33
-
-
Save taburetkin/beed1781c3bc123a9d9f4214daa611f3 to your computer and use it in GitHub Desktop.
edit-model control
This file contains 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 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