Last active
August 29, 2015 14:22
-
-
Save justindonnaruma/c0379e3bae315be8ce18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'), | |
Enquiry = keystone.list('Enquiry'); | |
exports = module.exports = function(req, res) { | |
var view = new keystone.View(req, res), | |
locals = res.locals; | |
// Set locals | |
locals.section = 'contact-us'; | |
locals.topic = Enquiry.fields.topic.ops; | |
locals.product = Enquiry.fields.product.ops; | |
locals.os = Enquiry.fields.os.ops; | |
locals.formData = req.body || {}; | |
locals.validationErrors = {}; | |
locals.caseSubmit = false; | |
locals.enquirySubmitted = false; | |
// On POST requests, add the Enquiry item to the database | |
view.on('post', { action: 'contact' }, function(next) { | |
console.log(req.files); | |
var newEnquiry = new Enquiry.model(), | |
updater = newEnquiry.getUpdateHandler(req); | |
updater.process(req.body, { | |
flashErrors: true, | |
fields: 'firstName, lastName, email, phone, product, topic, message', | |
errorMessage: 'There was a problem submitting your case:' | |
}, function(err) { | |
if (err) { | |
locals.validationErrors = err.errors; | |
console.log(locals.validationErrors); | |
locals.caseSubmit = true; | |
} else { | |
locals.enquirySubmitted = true; | |
//Enquiry._.attachment.uploadFile(req.body.attachment, true); | |
client.post("https://<url>/services/apexrest/ContactForm/createFeedback", args, function(data,response) { | |
// parsed response body as js object | |
console.log(data); | |
// raw response | |
// console.log(response); | |
}); | |
} | |
console.log(req.body.attachment); | |
console.log(locals.caseSubmit); | |
next(); | |
}); | |
}); | |
view.render('contact-us'); | |
}; |
This file contains hidden or 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'), | |
Types = keystone.Field.Types; | |
/** | |
* Enquiry Model | |
* ============= | |
*/ | |
var Enquiry = new keystone.List('Enquiry', { | |
nocreate: true, | |
noedit: true | |
}); | |
Enquiry.add({ | |
firstName: { type: String, required: true }, | |
lastName: { type: String, required: true }, | |
email: { type: Types.Email, required: true }, | |
phone: { type: String }, | |
os: { type: Types.Select, options: [ | |
{ value: 'Windows', label: 'Windows' }, | |
{ value: 'Mac', label: 'Mac' }, | |
{ value: 'iOS', label: 'iOS' }, | |
{ value: 'Android', label: 'Android'} | |
] }, | |
product: { type: Types.Select, required: true, options: [ | |
{ value: 'Personal', label: 'Personal' }, | |
{ value: 'Pro', label: 'Pro' }, | |
{ value: 'Server', label: 'Server' }, | |
{ value: 'Mobile', label: 'Mobile'} | |
] }, | |
topic: { type: Types.Select, required: true, options: [ | |
{ value: 'billing', label: 'Billing & Account' }, | |
{ value: 'restore', label: 'Restore Assistance' }, | |
{ value: 'technical', label: 'Technical Issues' }, | |
{ value: 'other', label: 'All Other Issues' } | |
] }, | |
message: { type: Types.Text, required: true }, | |
attachment: { | |
type: Types.LocalFile, | |
dest: '/data/files', | |
prefix: '/files/', | |
filename: function(item, file){ | |
return item.id + '.' + file.extension | |
} | |
}, | |
createdAt: { type: Date, default: Date.now } | |
}); | |
Enquiry.schema.pre('save', function(next) { | |
this.wasNew = this.isNew; | |
next(); | |
}); | |
Enquiry.schema.post('save', function() { | |
if (this.wasNew) { | |
// Push to Salesforce | |
} | |
}); | |
Enquiry.defaultSort = '-createdAt'; | |
Enquiry.defaultColumns = 'firstName, lastName, email, enquiryType, createdAt'; | |
Enquiry.register(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment