Created
January 25, 2016 00:16
-
-
Save rishighan/f1a974d18490f5ed7197 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
// pasting relevant bits | |
$scope.createPost = function() { | |
$http({ | |
method: 'POST', | |
url: '/db/createpost', | |
data: $scope.postFormModel, | |
headers: {'Content-Type': undefined}, | |
}).then(function successCallback(data) { | |
console.log(data); | |
}, function errorCallback(data) { | |
console.log(data); | |
}); | |
}; | |
// dropzone config | |
$scope.dropzoneConfig = { | |
'options': { // passed into the Dropzone constructor | |
url: "/db/createpost", | |
maxFilesize: 100, | |
paramName: "uploadfile", | |
maxThumbnailFilesize: 5, | |
autoProcessQueue: false, | |
maxFiles: 1 | |
}, | |
'eventHandlers': { | |
'sending': function (file, xhr, formData) { | |
}, | |
'success': function (file, response) { | |
}, | |
'maxfilesexceeded': function(file){ | |
this.removeFile(file); | |
}, | |
'addedfile' : function(file){ | |
$scope.postFormModel.flag = file.name; | |
$scope.$digest(); | |
} | |
} | |
}; | |
// Form Fields | |
$scope.postFormFields = [{ | |
type: 'input', | |
key: 'postTitle', | |
className: 'clearfix', | |
templateOptions: { | |
label: 'Title', | |
required: true, | |
className: 'col-md-6 col-xs-6' | |
} | |
}, { | |
key: 'tags', | |
type: 'ui-select-multiple', | |
className: 'row margin20', | |
templateOptions: { | |
className: 'col-md-8 col-xs-6', | |
optionsAttr: 'bs-options', | |
ngOptions: 'option in to.options | filter: $select.search', | |
label: 'Select tags', | |
valueProp: 'id', | |
labelProp: 'label', | |
placeholder: 'Select tags for your content', | |
options: testData, // Model containing tags | |
tagTransform: $scope.tagTransform // the tag transform function needs to be a part of templateOptions | |
} | |
}, { | |
type: 'textarea', | |
key: 'content', | |
className: 'clearfix', | |
templateOptions: { | |
rows: "12", | |
label: 'Content', | |
required: true, | |
className: 'col-md-10 col-xs-12' | |
} | |
}, { | |
type: 'textarea', | |
key: 'excerpt', | |
className: 'clearfix margin20', | |
templateOptions: { | |
rows: "3", | |
label: 'Excerpt', | |
required: true, | |
className: 'col-md-10 col-xs-12' | |
} | |
}, | |
{ | |
key: 'flag', | |
type: 'customInput', | |
templateOptions: { | |
label: 'flag', | |
type: 'input', | |
placeholder: 'Upload that image', | |
required: true | |
}, | |
}, | |
{ | |
type: 'repeatSection', | |
key: 'citations', | |
className: 'margin20', | |
templateOptions: { | |
btnText: 'Add another citation', | |
fields: [{ | |
fieldGroup: [{ | |
type: 'input', | |
key: 'citationName', | |
className: 'formly-repeatSection', | |
templateOptions: { | |
className: 'col-md-10 col-xs-6', | |
label: 'Citation:', | |
required: false | |
} | |
}, { | |
type: 'input', | |
key: 'citationSource', | |
className: 'formly-repeatSection', | |
templateOptions: { | |
className: 'col-md-12 col-xs-6', | |
label: 'Source or hyperlink:', | |
placeholder: 'http://thisthatortheother.com/docs/papersonhysteria', | |
required: false | |
} | |
}] | |
}] | |
} | |
}]; | |
} |
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
<form ng-submit="createPost()" name="form" novalidate enctype="multipart/form-data"> | |
<formly-form model = "postFormModel" fields = "postFormFields" form="form" class="admin"> | |
<button dropzone="dropzoneConfig" class="btn btn-primary"> | |
Drag and drop files here or click to upload | |
</button> | |
<div class="margin20"> | |
<button class="btn btn-primary" type="submit" ng-disabled="form.$invalid">Save Post</button> | |
</div> | |
</formly-form> | |
</form> |
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 multer = require('multer'); | |
var express = require('express'); | |
var app = express(); | |
app.post('/db/createpost', upload.single('flag'), function(req, res, next) { | |
console.log(req.files) // undefined | |
postModel.create({ | |
title: req.body.postTitle, | |
tags: req.body.tags, | |
date_created: new Date(), | |
date_updated: new Date(), | |
attachment: req.body.attachedFile, | |
is_draft: false, | |
content: req.body.content, | |
excerpt: req.body.excerpt, | |
citation: req.body.citations, | |
}, function(err, post){ | |
if(err){ | |
res.send(err); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment