Created
December 1, 2015 15:22
-
-
Save charleslouis/ff5cc15ce7d2f3aee59d to your computer and use it in GitHub Desktop.
keystone-Page.js model page model
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
var keystone = require('keystone'); | |
var Types = keystone.Field.Types; | |
/** | |
* Page Model | |
* ========== | |
*/ | |
var Page = new keystone.List('Page', { | |
map: { name: 'title' }, | |
autokey: { path: 'slug', from: 'title', unique: true } | |
}); | |
Page.add({ | |
title: { type: String, required: true }, | |
state: { type: Types.Select, options: 'draft, published, archived', default: 'draft', index: true }, | |
author: { type: Types.Relationship, ref: 'User', index: true }, | |
publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } }, | |
//create a dropdown with templates | |
template: { type: Types.Select, options: 'page, about, team, contact, portfolio', default: 'page'}, | |
image: { type: Types.CloudinaryImage }, | |
content: { | |
brief: { type: Types.Html, wysiwyg: true, height: 150 }, | |
extended: { type: Types.Html, wysiwyg: true, height: 400 } | |
}, | |
//Display someField if the selected template is 'about' | |
someField: { type: String, dependsOn: { template: 'about' } }, | |
}); | |
Page.schema.virtual('content.full').get(function() { | |
return this.content.extended || this.content.brief; | |
}); | |
Page.defaultColumns = 'title, state|20%, author|20%, publishedDate|20%'; | |
Page.register(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment