added stuff
This commit is contained in:
parent
a923b2d30e
commit
3ec944392e
|
@ -112,13 +112,6 @@ exports.createSubmission = function(req, res) {
|
|||
|
||||
submission.fdfData = fdfData;
|
||||
|
||||
//Create new file
|
||||
// pdfFiller.fillForm( form.pdf.path, config.pdfUploadPath+form.title+'/'+form.title+'_'+Date.now()+'_submission.pdf', fdfData, function() {
|
||||
// console.log('\n\n\n fdfData');
|
||||
// console.log(fdfData);
|
||||
// console.log('\n\n\n :\n');
|
||||
// console.log(req.body);
|
||||
|
||||
submission.save(function(err){
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
@ -129,7 +122,6 @@ exports.createSubmission = function(req, res) {
|
|||
return res.status(200);
|
||||
}
|
||||
});
|
||||
// });
|
||||
};
|
||||
|
||||
|
||||
|
@ -139,7 +131,7 @@ exports.createSubmission = function(req, res) {
|
|||
exports.listSubmissions = function(req, res) {
|
||||
var _form = req.form;
|
||||
|
||||
FormSubmission.find({ form: req.form }).exec(function(err, submissions) {
|
||||
FormSubmission.find({ form: req.form }).populate('admin', 'form').exec(function(err, submissions) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
|
|
|
@ -33,7 +33,7 @@ var FormSchema = new Schema({
|
|||
type: String,
|
||||
default: '',
|
||||
},
|
||||
form_fields: [FieldSchema],
|
||||
form_fields: [{type: Schema.Types.Mixed}],
|
||||
|
||||
submissions: [{
|
||||
type: Schema.Types.ObjectId,
|
||||
|
@ -141,9 +141,9 @@ FormSchema.pre('save', function (next) {
|
|||
}
|
||||
|
||||
field.fieldValue = '';
|
||||
// field.created = Date.now();
|
||||
// field.required = true;
|
||||
//field.disabled = false;
|
||||
field.created = Date.now();
|
||||
field.required = true;
|
||||
field.disabled = false;
|
||||
|
||||
// field = new Field(field);
|
||||
// field.save(function(err) {
|
||||
|
|
|
@ -11,6 +11,8 @@ var mongoose = require('mongoose'),
|
|||
config = require('../../config/config'),
|
||||
path = require('path'),
|
||||
Form = mongoose.model('Form'),
|
||||
FieldSchema = require('./form_field.server.model.js'),
|
||||
Field = mongoose.model('Field', FieldSchema),
|
||||
fs = require('fs-extra');
|
||||
|
||||
/**
|
||||
|
@ -30,7 +32,7 @@ var FormSubmissionSchema = new Schema({
|
|||
type: Schema.Types.ObjectId,
|
||||
ref: 'User',
|
||||
},
|
||||
form_fields: [Schema.Types.Mixed],
|
||||
form_fields: [{type: Schema.Types.Mixed}],
|
||||
form: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'Form',
|
||||
|
|
|
@ -12,14 +12,17 @@ module.exports = function(app) {
|
|||
.post(forms.uploadPDF);
|
||||
|
||||
app.route('/forms')
|
||||
.get(forms.list)
|
||||
.get(users.requiresLogin, forms.hasAuthorization, forms.list)
|
||||
.post(users.requiresLogin, forms.create);
|
||||
|
||||
app.route('/forms/:formId/submissions')
|
||||
.get(forms.listSubmissions);
|
||||
|
||||
app.route('/forms/:formId')
|
||||
.get(forms.read)
|
||||
.post(forms.createSubmission)
|
||||
.put(users.requiresLogin, forms.hasAuthorization, forms.update)
|
||||
.delete(users.requiresLogin, forms.delete);
|
||||
.delete(users.requiresLogin, forms.hasAuthorization, forms.delete);
|
||||
|
||||
// Finish by binding the form middleware
|
||||
app.param('formId', forms.formByID);
|
||||
|
|
|
@ -50,9 +50,9 @@
|
|||
<body class="ng-cloak" >
|
||||
<header data-ng-include="'/modules/core/views/header.client.view.html'"></header>
|
||||
<section class="content">
|
||||
<section class="container">
|
||||
<!-- <section class="container"> -->
|
||||
{% block content %}{% endblock %}
|
||||
</section>
|
||||
<!-- </section> -->
|
||||
</section>
|
||||
|
||||
<!--Embedding The User Object-->
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
|
||||
/*Navbar Custom CSS*/
|
||||
.navbar .navbar-brand {
|
||||
font-size: 1.6em;
|
||||
font-weight: 900;
|
||||
|
@ -10,7 +9,7 @@
|
|||
}
|
||||
|
||||
.content {
|
||||
margin-top: 50px;
|
||||
/*margin-top: 50px;*/
|
||||
}
|
||||
.undecorated-link:hover {
|
||||
text-decoration: none;
|
||||
|
@ -30,17 +29,22 @@ body.ng-cloak
|
|||
display: block;
|
||||
}
|
||||
|
||||
section > .jumbotron {
|
||||
padding-top: 15px;
|
||||
/*Hero Section CSS (for /home)*/
|
||||
section.hero-section {
|
||||
/*padding-top:30px;*/
|
||||
width: 100%;
|
||||
}
|
||||
section.hero-section > .jumbotron {
|
||||
background-image: url(http://yourplaceandmine.ie/wp-content/uploads/2014/09/Daingean-meeting-048_13-1080x675.jpg);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 50% 50%;
|
||||
background-position: 0 50%;
|
||||
background-position-top: 0px;
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
section > .jumbotron > .opacity-background {
|
||||
background-color: rgba(70,51,51,0.5);
|
||||
height:inherit;
|
||||
width:inherit;
|
||||
padding:inherit;
|
||||
background-color: rgba(71,61,61,0.5);
|
||||
color: white;
|
||||
padding: inherit;
|
||||
height: inherit;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<section data-ng-controller="HomeController">
|
||||
<section data-ng-controller="HomeController" class="hero-section">
|
||||
|
||||
<div class="jumbotron text-center">
|
||||
<div class="opacity-background jumbotron">
|
||||
<div class="opacity-background">
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-12">
|
||||
<!-- <img alt="MEAN.JS" class="img-responsive text-center" src="modules/core/img/brand/logo.png" /> -->
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
'use strict';
|
||||
|
||||
// submissions controller
|
||||
angular.module('forms').controller('ViewSubmissionController', ['$scope', '$stateParams', '$state', 'Submissions','$http',
|
||||
function($scope, $stateParams, $state, Submissions, $http) {
|
||||
$scope.submissionId = undefined;
|
||||
|
||||
// Principal.identity().then(function(user){
|
||||
// $scope.authentication.user = user;
|
||||
// }).then(function(){
|
||||
|
||||
|
||||
// Return all form's submissions
|
||||
$scope.findAll = function() {
|
||||
$scope.submissions = submissions.query({
|
||||
formId: $stateParams.formId
|
||||
});
|
||||
};
|
||||
|
||||
// Find a specific submission
|
||||
$scope.findOne = function() {
|
||||
$scope.submission = submissions.get({
|
||||
submissionId: $scope.submissionId,
|
||||
formId: $stateParams.formId
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Remove existing submission
|
||||
$scope.remove = function(submission) {
|
||||
if (submission) {
|
||||
submission.$remove();
|
||||
|
||||
$http.delete('/forms/'+$stateParams.formId+'submissions/'+$scope.submission._id).
|
||||
success(function(data, status, headers){
|
||||
console.log('submission deleted successfully');
|
||||
alert('submission deleted..');
|
||||
});
|
||||
|
||||
} else {
|
||||
$scope.submission.$remove(function() {
|
||||
console.log('remove');
|
||||
$state.path('submissions');
|
||||
$http.delete('/forms/'+$stateParams.formId+'/submissions/'+$scope.submission._id).
|
||||
success(function(data, status, headers){
|
||||
console.log('submission deleted successfully');
|
||||
alert('submission deleted..');
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// });
|
||||
}
|
||||
]);
|
|
@ -35,7 +35,7 @@ angular.module('forms').controller('ViewFormController', ['$scope', '$stateParam
|
|||
$state.go('listForms');
|
||||
});
|
||||
|
||||
} else {
|
||||
} else{
|
||||
$scope.form.$remove(function() {
|
||||
console.log('remove');
|
||||
$state.path('forms');
|
||||
|
|
22
public/modules/forms/services/submissions.client.service.js
Normal file
22
public/modules/forms/services/submissions.client.service.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
//Submissions service used for communicating with the forms REST endpoints
|
||||
angular.module('forms').factory('Submissions', ['$resource',
|
||||
function($resource) {
|
||||
return $resource('forms/:formID/submissions/:submissionId', {
|
||||
submissionId: '@_id',
|
||||
formId: '@_id'
|
||||
}, {
|
||||
'query' : {
|
||||
method: 'GET',
|
||||
isArray: true,
|
||||
},
|
||||
'update': {
|
||||
method: 'PUT'
|
||||
},
|
||||
'save': {
|
||||
method: 'POST'
|
||||
}
|
||||
});
|
||||
}
|
||||
]);
|
|
@ -1,37 +1,16 @@
|
|||
<section data-ng-controller="ViewSubmissionsController" data-ng-init="findAll()">
|
||||
<div class="row">
|
||||
<div class="page-header col-xs-10 col-xs-offset-1">
|
||||
<h1>{{submissions[0].form.title}} submissions</h1>
|
||||
<section data-ng-controller="ViewSubmissionController" data-ng-init="findAll()">
|
||||
<div class="page-header">
|
||||
<h1>{{form.title}} Submissions</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row container">
|
||||
<a data-ng-href="#!/forms/create" class="col-xs-2 col-xs-offset-1 form-item row container create-new">
|
||||
<div class="title-row col-xs-12">
|
||||
<h4 class=" fa fa-plus fa-6"></h4>
|
||||
</div>
|
||||
<div class="col-xs-12 details-row">
|
||||
|
||||
<small class="list-group-item-text">
|
||||
Create a new form
|
||||
</small>
|
||||
|
||||
</div>
|
||||
|
||||
</a>
|
||||
<a data-ng-repeat="form in forms" data-ng-href="#!/forms/{{form._id}}/admin" class="col-xs-2 col-xs-offset-1 form-item row">
|
||||
<div class="title-row col-xs-12">
|
||||
<h4 class="list-group-item-heading" data-ng-bind="form.title"></h4>
|
||||
</div>
|
||||
<div class="col-xs-12 details-row">
|
||||
|
||||
<div class="list-group">
|
||||
<a data-ng-repeat="submission in submissions" data-ng-href="#!/forms/{{form._id}}/admin" class="list-group-item">
|
||||
<small class="list-group-item-text">
|
||||
Created on
|
||||
<span data-ng-bind="form.created | date:'mediumDate'"></span>
|
||||
<span data-ng-bind="submission.created | date:'mediumDate'"></span>
|
||||
by
|
||||
<span data-ng-bind="form.user.displayName"></span>
|
||||
</small>
|
||||
|
||||
</div>
|
||||
<h4 class="list-group-item-heading" data-ng-bind="submission.title"></h4>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
'use strict';
|
||||
|
||||
// Config HTTP Error Handling
|
||||
// angular.module('users').config(['$httpProvider',
|
||||
// function($httpProvider) {
|
||||
// // Set the httpProvider "not authorized" interceptor
|
||||
// $httpProvider.interceptors.push(['$q', '$state', 'Principal',
|
||||
// function($q, $location, Principal) {
|
||||
// return {
|
||||
// responseError: function(rejection) {
|
||||
// switch (rejection.status) {
|
||||
// case 401:
|
||||
// // Deauthenticate the global user
|
||||
angular.module('users').config(['$httpProvider',
|
||||
function($httpProvider) {
|
||||
// Set the httpProvider "not authorized" interceptor
|
||||
$httpProvider.interceptors.push(['$q', '$state', 'Principal',
|
||||
function($q, $state, Principal) {
|
||||
return {
|
||||
responseError: function(rejection) {
|
||||
switch (rejection.status) {
|
||||
case 401:
|
||||
// Deauthenticate the global user
|
||||
Principal.authenticate(null);
|
||||
|
||||
// Redirect to signin page
|
||||
$state.go('signin');
|
||||
break;
|
||||
case 403:
|
||||
// Add unauthorized behaviour
|
||||
break;
|
||||
}
|
||||
|
||||
// // Redirect to signin page
|
||||
// $state.go('signin');
|
||||
// break;
|
||||
// case 403:
|
||||
// // Add unauthorized behaviour
|
||||
// break;
|
||||
// }
|
||||
|
||||
// return $q.reject(rejection);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
// ]);
|
||||
// }
|
||||
// ]);
|
||||
return $q.reject(rejection);
|
||||
}
|
||||
};
|
||||
}
|
||||
]);
|
||||
}
|
||||
]);
|
|
@ -14,7 +14,7 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam
|
|||
$scope.askForPasswordReset = function() {
|
||||
Principal.askForPasswordReset($scope.credentials).then(
|
||||
function(response){
|
||||
$scope.success = response.message
|
||||
$scope.success = response.message;
|
||||
$scope.credentials = null;
|
||||
},
|
||||
function(error){
|
||||
|
@ -26,13 +26,19 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam
|
|||
|
||||
// Change user password
|
||||
$scope.resetUserPassword = function() {
|
||||
Principal.askForPasswordReset($scope.credentials).then(
|
||||
$scope.success = $scope.error = null;
|
||||
Principal.resetPassword($scope.passwordDetails, $stateParams.token).then(
|
||||
function(response){
|
||||
$scope.credentials = null;
|
||||
// If successful show success message and clear form
|
||||
$scope.success = response.message;
|
||||
$scope.passwordDetails = null;
|
||||
|
||||
// And redirect to the index page
|
||||
$state.go('reset-success');
|
||||
},
|
||||
function(error){
|
||||
$scope.error = error;
|
||||
$scope.credentials = null;
|
||||
$scope.error = error.message || error;
|
||||
$scope.passwordDetails = null;
|
||||
}
|
||||
);
|
||||
// $scope.success = $scope.error = null;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('users').factory('Principal', ['$window', '$q', '$timeout', '$http',
|
||||
function($window, $q, $timeout, $http) {
|
||||
angular.module('users').factory('Principal', ['$window', '$q', '$timeout', '$http', '$state',
|
||||
function($window, $q, $timeout, $http, $state) {
|
||||
|
||||
var service = {
|
||||
_currentUser: null,
|
||||
|
@ -75,17 +75,13 @@ angular.module('users').factory('Principal', ['$window', '$q', '$timeout', '$htt
|
|||
return deferred.promise;
|
||||
},
|
||||
|
||||
resetPassword: function(scope) {
|
||||
resetPassword: function(passwordDetails, token) {
|
||||
var deferred = $q.defer();
|
||||
$http.get('/auth/password'+_currentUser._id, scope.passwordDetails).success(function(response) {
|
||||
// If successful show success message and clear form
|
||||
scope.passwordDetails = null;
|
||||
$http.get('/auth/password/'+token, passwordDetails).success(function(response) {
|
||||
|
||||
// Attach user profile
|
||||
// Principal.user() = response;
|
||||
service.authenticate(response);
|
||||
|
||||
// And redirect to the index page
|
||||
$state.go('reset-success');
|
||||
deferred.resolve();
|
||||
}).error(function(error) {
|
||||
deferred.reject(error.message || error);
|
||||
|
@ -96,7 +92,7 @@ angular.module('users').factory('Principal', ['$window', '$q', '$timeout', '$htt
|
|||
|
||||
// Submit forgotten password account id
|
||||
askForPasswordReset: function(credentials) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
$http.post('/auth/forgot', credentials).success(function(response) {
|
||||
// Show user success message and clear form
|
||||
|
||||
|
|
Loading…
Reference in a new issue