remerged with new dev_working
This commit is contained in:
commit
6badd3ad56
|
@ -36,56 +36,97 @@ exports.create = function(req, res) {
|
||||||
/**
|
/**
|
||||||
* Upload PDF
|
* Upload PDF
|
||||||
*/
|
*/
|
||||||
exports.uploadPDF = function(files, user, cb) {
|
exports.uploadPDF = function(req, res, next) {
|
||||||
var _user = JSON.parse(''+user);
|
|
||||||
console.log(_user.username);
|
|
||||||
console.log(config.tmpUploadPath);
|
|
||||||
|
|
||||||
if(files) {
|
console.log('inside uploadPDF');
|
||||||
|
if(req.files){
|
||||||
|
var pdfFile = req.files.file;
|
||||||
|
var _user = req.user;
|
||||||
|
if (req.files.size === 0) {
|
||||||
|
next(new Error('File uploaded is EMPTY'));
|
||||||
|
}else if(req.files.size > 200000000){
|
||||||
|
next(new Error('File uploaded exceeds MAX SIZE of 200MB'));
|
||||||
|
}else {
|
||||||
|
fs.exists(pdfFile.path, function(exists) {
|
||||||
|
//If file exists move to user's tmp directory
|
||||||
|
if(exists) {
|
||||||
|
|
||||||
console.log('inside uploadPDF');
|
var newDestination = config.tmpUploadPath+_user.username;
|
||||||
console.log(files.file[0]);
|
var stat = null;
|
||||||
var pdfFile = files.file[0];
|
try {
|
||||||
|
stat = fs.statSync(newDestination);
|
||||||
|
} catch (err) {
|
||||||
|
fs.mkdirSync(newDestination);
|
||||||
|
}
|
||||||
|
if (stat && !stat.isDirectory()) {
|
||||||
|
console.log('Directory cannot be created');
|
||||||
|
next(new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"'));
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.move(pdfFile.path, path.join(newDestination, pdfFile.name), function (err) {
|
||||||
|
if (err) {
|
||||||
|
next(new Error(err.message));
|
||||||
|
}
|
||||||
|
pdfFile.path = path.join(newDestination, pdfFile.name);
|
||||||
|
console.log(pdfFile.name + ' uploaded to ' + pdfFile.path);
|
||||||
|
res.status(200).send(pdfFile);
|
||||||
|
});
|
||||||
|
|
||||||
if (pdfFile.size === 0) {
|
} else {
|
||||||
throw new Error('Files uploaded are EMPTY');
|
next(new Error('Did NOT get your file!'));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//If file exists move to user's tmp directory
|
|
||||||
fs.open(pdfFile.path,'r',function(err,fd){
|
|
||||||
if (err && err.code === 'ENOENT') {
|
|
||||||
return res.status(400).send({
|
|
||||||
message: 'Did NOT get your file!'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var stat = null;
|
|
||||||
try {
|
|
||||||
stat = fs.statSync(newDestination);
|
|
||||||
} catch (err) {
|
|
||||||
fs.mkdirSync(newDestination);
|
|
||||||
}
|
|
||||||
if (stat && !stat.isDirectory()) {
|
|
||||||
console.log('Directory cannot be created');
|
|
||||||
throw new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"');
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.move(pdfFile.path, path.join(newDestination, pdfFile.name), function (err) {
|
|
||||||
if (err) {
|
|
||||||
throw new Error(err.message);
|
|
||||||
}
|
|
||||||
pdfFile.path = path.join(newDestination, pdfFile.name);
|
|
||||||
|
|
||||||
return cb(pdfFile);
|
|
||||||
});
|
|
||||||
return res.status(200);
|
|
||||||
});
|
|
||||||
}else {
|
}else {
|
||||||
throw new Error('File NOT uploaded');
|
next(new Error('Uploaded files were NOT detected'));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// exports.uploadPDF = function(pdfFile, _user, cb) {
|
||||||
|
// // console.log(_user.username);
|
||||||
|
// // console.log(config.tmpUploadPath);
|
||||||
|
|
||||||
|
|
||||||
|
// console.log('inside uploadPDF');
|
||||||
|
// // console.log(pdfFile);
|
||||||
|
|
||||||
|
// if (pdfFile.size === 0) {
|
||||||
|
// cb(new Error('Files uploaded are EMPTY'), null);
|
||||||
|
// }else {
|
||||||
|
// fs.exists(pdfFile.path, function(exists) {
|
||||||
|
// //If file exists move to user's tmp directory
|
||||||
|
// if(exists) {
|
||||||
|
|
||||||
|
// var newDestination = config.tmpUploadPath+""+_user.username;
|
||||||
|
// var stat = null;
|
||||||
|
// try {
|
||||||
|
// stat = fs.statSync(newDestination);
|
||||||
|
// } catch (err) {
|
||||||
|
// fs.mkdirSync(newDestination);
|
||||||
|
// }
|
||||||
|
// if (stat && !stat.isDirectory()) {
|
||||||
|
// console.log('Directory cannot be created');
|
||||||
|
// cb(new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"'), null);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fs.move(pdfFile.path, path.join(newDestination, pdfFile.name), function (err) {
|
||||||
|
// if (err) {
|
||||||
|
// return cb(new Error(err.message), null);
|
||||||
|
// }
|
||||||
|
// pdfFile.path = path.join(newDestination, pdfFile.name);
|
||||||
|
|
||||||
|
// return cb(null, pdfFile);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// } else {
|
||||||
|
// cb(new Error('Did NOT get your file!'), null);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the current form
|
* Show the current form
|
||||||
*/
|
*/
|
||||||
|
@ -164,9 +205,11 @@ exports.listSubmissions = function(req, res) {
|
||||||
* Update a form
|
* Update a form
|
||||||
*/
|
*/
|
||||||
exports.update = function(req, res) {
|
exports.update = function(req, res) {
|
||||||
|
console.log('in form.update()');
|
||||||
|
|
||||||
var form = req.form;
|
var form = req.form;
|
||||||
form = _.extend(form, req.body);
|
// console.log(req.body.form);
|
||||||
|
form = _.extend(form, req.body.form);
|
||||||
form.admin = req.user;
|
form.admin = req.user;
|
||||||
|
|
||||||
form.save(function(err) {
|
form.save(function(err) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ var mongoose = require('mongoose'),
|
||||||
config = require('../../config/config'),
|
config = require('../../config/config'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
|
async = require('async'),
|
||||||
Field = mongoose.model('Field', FieldSchema);
|
Field = mongoose.model('Field', FieldSchema);
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,54 +74,6 @@ var FormSchema = new Schema({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
//Update lastModified everytime we save
|
|
||||||
FormSchema.pre('save', function (next) {
|
|
||||||
this.lastModified = Date.now();
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
//Move PDF to permanent location after new template is uploaded
|
|
||||||
FormSchema.pre('save', function (next) {
|
|
||||||
|
|
||||||
if(this.pdf && this.isModified('pdf')){
|
|
||||||
console.log('Relocating PDF');
|
|
||||||
|
|
||||||
var new_filename = this.pdf.title.trim()+'_template.pdf';
|
|
||||||
|
|
||||||
var newDestination = path.join(config.pdfUploadPath, this.pdf.title.trim()),
|
|
||||||
stat = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
stat = fs.statSync(newDestination);
|
|
||||||
} catch (err) {
|
|
||||||
fs.mkdirSync(newDestination);
|
|
||||||
}
|
|
||||||
if (stat && !stat.isDirectory()) {
|
|
||||||
console.log('Directory cannot be created');
|
|
||||||
next( new Error('Directory cannot be created because an inode of a different type exists at "' + config.pdfUploadPath + '"') );
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('about to move PDF');
|
|
||||||
fs.move(this.pdf.path, path.join(newDestination, new_filename), function (err) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
next( new Error(err.message) );
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pdf.path = path.join(newDestination, new_filename);
|
|
||||||
this.pdf.name = new_filename;
|
|
||||||
|
|
||||||
console.log('PDF file:'+this.pdf.name+' successfully moved to: '+this.pdf.path);
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}else {
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Delete template PDF of current Form
|
//Delete template PDF of current Form
|
||||||
FormSchema.pre('remove', function (next) {
|
FormSchema.pre('remove', function (next) {
|
||||||
if(this.pdf){
|
if(this.pdf){
|
||||||
|
@ -132,74 +85,218 @@ FormSchema.pre('remove', function (next) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Autogenerate FORM from PDF if 'isGenerated' flag is 'true'
|
//Create folder for user's pdfs
|
||||||
FormSchema.pre('save', function (next) {
|
FormSchema.pre('save', function (next) {
|
||||||
var field, _form_fields;
|
var newDestination = path.join(config.pdfUploadPath, this.admin.username.replace(/ /g,'')),
|
||||||
|
stat = null;
|
||||||
if(this.isGenerated && this.pdf){
|
|
||||||
|
|
||||||
var _typeConvMap = {
|
try {
|
||||||
'Multiline': 'textarea',
|
stat = fs.statSync(newDestination);
|
||||||
'Text': 'textfield',
|
} catch (err) {
|
||||||
'Button': 'checkbox',
|
fs.mkdirSync(newDestination);
|
||||||
'Choice': 'radio',
|
}
|
||||||
'Password': 'password',
|
if (stat && !stat.isDirectory()) {
|
||||||
'FileSelect': 'filefield',
|
console.log('Directory cannot be created');
|
||||||
'Radio': 'radio'
|
next( new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"') );
|
||||||
};
|
}else{
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var that = this;
|
//Update lastModified and created everytime we save
|
||||||
console.log('autogenerating form');
|
FormSchema.pre('save', function (next) {
|
||||||
|
var now = new Date();
|
||||||
try {
|
this.lastModified = now;
|
||||||
pdfFiller.generateFieldJson(this.pdf.path, function(_form_fields){
|
if( !this.created ){
|
||||||
|
this.created = now;
|
||||||
//Map PDF field names to FormField field names
|
}
|
||||||
for(var i = 0; i < _form_fields.length; i++){
|
|
||||||
field = _form_fields[i];
|
|
||||||
|
|
||||||
//Convert types from FDF to 'FormField' types
|
|
||||||
if(_typeConvMap[ field.fieldType+'' ]){
|
|
||||||
field.fieldType = _typeConvMap[ field.fieldType+'' ];
|
|
||||||
}
|
|
||||||
|
|
||||||
field.fieldValue = '';
|
|
||||||
field.created = Date.now();
|
|
||||||
field.required = true;
|
|
||||||
field.disabled = false;
|
|
||||||
|
|
||||||
// field = new Field(field);
|
|
||||||
// field.save(function(err) {
|
|
||||||
// if (err) {
|
|
||||||
// console.error(err.message);
|
|
||||||
// throw new Error(err.message);
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
// _form_fields[i] = this;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
_form_fields[i] = field;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('NEW FORM_FIELDS: ');
|
|
||||||
console.log(_form_fields);
|
|
||||||
|
|
||||||
console.log('\n\nOLD FORM_FIELDS: ');
|
|
||||||
console.log(that.form_fields);
|
|
||||||
|
|
||||||
that.form_fields = _form_fields;
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
} catch(err){
|
|
||||||
next( new Error(err.message) );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Throw error if we encounter form with invalid type
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Move PDF to permanent location after new template is uploaded
|
||||||
|
FormSchema.pre('save', function (next) {
|
||||||
|
|
||||||
|
if(this.pdf){
|
||||||
|
var that = this;
|
||||||
|
async.series([
|
||||||
|
function(callback){
|
||||||
|
if(that.isModified('pdf')){
|
||||||
|
console.log('about to move PDF');
|
||||||
|
|
||||||
|
var new_filename = that.title.replace(/ /g,'')+'_template.pdf';
|
||||||
|
|
||||||
|
var newDestination = path.join(config.pdfUploadPath, that.admin.username.replace(/ /g,''), that.title.replace(/ /g,'')),
|
||||||
|
stat = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
stat = fs.statSync(newDestination);
|
||||||
|
} catch (err) {
|
||||||
|
fs.mkdirSync(newDestination);
|
||||||
|
}
|
||||||
|
if (stat && !stat.isDirectory()) {
|
||||||
|
console.log('Directory '+newDestination+' cannot be created');
|
||||||
|
callback( new Error('Directory cannot be created because an inode of a different type exists at "' + config.pdfUploadPath + '"') );
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('about to move PDF');
|
||||||
|
|
||||||
|
fs.move(that.pdf.path, path.join(newDestination, new_filename), function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
callback( new Error(err.message) );
|
||||||
|
}
|
||||||
|
that.pdf.path = path.join(newDestination, new_filename);
|
||||||
|
that.pdf.name = new_filename;
|
||||||
|
|
||||||
|
console.log('\n\n PDF file:'+that.pdf.name+' successfully moved to: '+that.pdf.path);
|
||||||
|
|
||||||
|
callback(null,null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
callback(null,null);
|
||||||
|
},
|
||||||
|
function(callback){
|
||||||
|
if(that.isGenerated){
|
||||||
|
that.pdf.path = path.join(config.pdfUploadPath, that.admin.username.replace(/ /g,''), that.title.replace(/ /g,''), that.title.replace(/ /g,'')+'_template.pdf');
|
||||||
|
that.pdf.name = that.title.replace(/ /g,'')+'_template.pdf';
|
||||||
|
var _typeConvMap = {
|
||||||
|
'Multiline': 'textarea',
|
||||||
|
'Text': 'textfield',
|
||||||
|
'Button': 'checkbox',
|
||||||
|
'Choice': 'radio',
|
||||||
|
'Password': 'password',
|
||||||
|
'FileSelect': 'filefield',
|
||||||
|
'Radio': 'radio'
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('autogenerating form');
|
||||||
|
console.log(that.pdf.path);
|
||||||
|
|
||||||
|
try {
|
||||||
|
pdfFiller.generateFieldJson(that.pdf.path, function(_form_fields){
|
||||||
|
|
||||||
|
//Map PDF field names to FormField field names
|
||||||
|
for(var i = 0; i < _form_fields.length; i++){
|
||||||
|
var field = _form_fields[i];
|
||||||
|
|
||||||
|
//Convert types from FDF to 'FormField' types
|
||||||
|
if(_typeConvMap[ field.fieldType+'' ]){
|
||||||
|
field.fieldType = _typeConvMap[ field.fieldType+'' ];
|
||||||
|
}
|
||||||
|
|
||||||
|
field.fieldValue = '';
|
||||||
|
field.created = Date.now();
|
||||||
|
field.required = true;
|
||||||
|
field.disabled = false;
|
||||||
|
|
||||||
|
// field = new Field(field);
|
||||||
|
// field.save(function(err) {
|
||||||
|
// if (err) {
|
||||||
|
// console.error(err.message);
|
||||||
|
// throw new Error(err.message);
|
||||||
|
// });
|
||||||
|
// } else {
|
||||||
|
// _form_fields[i] = that;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
_form_fields[i] = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('NEW FORM_FIELDS: ');
|
||||||
|
console.log(_form_fields);
|
||||||
|
|
||||||
|
console.log('\n\nOLD FORM_FIELDS: ');
|
||||||
|
console.log(that.form_fields);
|
||||||
|
|
||||||
|
that.form_fields = _form_fields;
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
} catch(err){
|
||||||
|
next( new Error(err.message) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback(null,null);
|
||||||
|
}
|
||||||
|
], function(err, results) {
|
||||||
|
if(err){
|
||||||
|
next(new Error({
|
||||||
|
message: err.message
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
//Autogenerate Form_fields from PDF if 'isGenerated' flag is set
|
||||||
|
// FormSchema.pre('save', function (next) {
|
||||||
|
// var field, _form_fields;
|
||||||
|
|
||||||
|
// if(this.pdf){
|
||||||
|
// if(this.isGenerated){
|
||||||
|
|
||||||
|
// var _typeConvMap = {
|
||||||
|
// 'Multiline': 'textarea',
|
||||||
|
// 'Text': 'textfield',
|
||||||
|
// 'Button': 'checkbox',
|
||||||
|
// 'Choice': 'radio',
|
||||||
|
// 'Password': 'password',
|
||||||
|
// 'FileSelect': 'filefield',
|
||||||
|
// 'Radio': 'radio'
|
||||||
|
// };
|
||||||
|
|
||||||
|
// var that = this;
|
||||||
|
// console.log('autogenerating form');
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// pdfFiller.generateFieldJson(this.pdf.path, function(_form_fields){
|
||||||
|
|
||||||
|
// //Map PDF field names to FormField field names
|
||||||
|
// for(var i = 0; i < _form_fields.length; i++){
|
||||||
|
// field = _form_fields[i];
|
||||||
|
|
||||||
|
// //Convert types from FDF to 'FormField' types
|
||||||
|
// if(_typeConvMap[ field.fieldType+'' ]){
|
||||||
|
// field.fieldType = _typeConvMap[ field.fieldType+'' ];
|
||||||
|
// }
|
||||||
|
|
||||||
|
// field.fieldValue = '';
|
||||||
|
// field.created = Date.now();
|
||||||
|
// field.required = true;
|
||||||
|
// field.disabled = false;
|
||||||
|
|
||||||
|
// // field = new Field(field);
|
||||||
|
// // field.save(function(err) {
|
||||||
|
// // if (err) {
|
||||||
|
// // console.error(err.message);
|
||||||
|
// // throw new Error(err.message);
|
||||||
|
// // });
|
||||||
|
// // } else {
|
||||||
|
// // _form_fields[i] = this;
|
||||||
|
// // }
|
||||||
|
// // });
|
||||||
|
// _form_fields[i] = field;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// console.log('NEW FORM_FIELDS: ');
|
||||||
|
// console.log(_form_fields);
|
||||||
|
|
||||||
|
// console.log('\n\nOLD FORM_FIELDS: ');
|
||||||
|
// console.log(that.form_fields);
|
||||||
|
|
||||||
|
// that.form_fields = _form_fields;
|
||||||
|
// next();
|
||||||
|
// });
|
||||||
|
// } catch(err){
|
||||||
|
// next( new Error(err.message) );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// next();
|
||||||
|
// });
|
||||||
|
|
||||||
FormSchema.methods.convertToFDF = function (cb) {
|
FormSchema.methods.convertToFDF = function (cb) {
|
||||||
var _keys = _.pluck(this.form_fields, 'title'),
|
var _keys = _.pluck(this.form_fields, 'title'),
|
||||||
_values = _.pluck(this.form_fields, 'fieldValue');
|
_values = _.pluck(this.form_fields, 'fieldValue');
|
||||||
|
|
|
@ -90,12 +90,11 @@ FormSubmissionSchema.pre('save', function (next) {
|
||||||
|
|
||||||
if(_form.autofillPDFs){
|
if(_form.autofillPDFs){
|
||||||
|
|
||||||
dest_filename = _form.title.trim()+'_submission_'+Date.now()+'.pdf';
|
dest_filename = _form.title.replace(/ /g,'')+'_submission_'+Date.now()+'.pdf';
|
||||||
dest_path = path.join(config.pdfUploadPath, dest_filename);
|
dest_path = path.join(config.pdfUploadPath, dest_filename);
|
||||||
|
|
||||||
this.pdfFilePath = dest_path;
|
this.pdfFilePath = dest_path;
|
||||||
|
|
||||||
// console.log('autofillPDFs check');
|
|
||||||
|
|
||||||
pdfFiller.fillForm(_form.pdf.path, dest_path, this.fdfData, function(err){
|
pdfFiller.fillForm(_form.pdf.path, dest_path, this.fdfData, function(err){
|
||||||
console.log('fdfData: \n');
|
console.log('fdfData: \n');
|
||||||
|
@ -108,7 +107,7 @@ FormSubmissionSchema.pre('save', function (next) {
|
||||||
console.log('\n err.message: '+err.message);
|
console.log('\n err.message: '+err.message);
|
||||||
next( new Error(err.message) );
|
next( new Error(err.message) );
|
||||||
}
|
}
|
||||||
console.log('Field data from Form: '+_form.title.trim()+' outputed to new PDF: '+dest_path);
|
console.log('Field data from Form: '+_form.title.replace(/ /g,'')+' outputed to new PDF: '+dest_path);
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -15,15 +15,15 @@ module.exports = function(app) {
|
||||||
.get(users.requiresLogin, forms.list)
|
.get(users.requiresLogin, forms.list)
|
||||||
.post(users.requiresLogin, forms.create);
|
.post(users.requiresLogin, forms.create);
|
||||||
|
|
||||||
app.route('/forms/:formId/submissions')
|
app.route('/forms/:formId([a-zA-Z0-9]+)')
|
||||||
.get(forms.listSubmissions);
|
|
||||||
|
|
||||||
app.route('/forms/:formId')
|
|
||||||
.get(forms.read)
|
.get(forms.read)
|
||||||
.post(forms.createSubmission)
|
// .post(forms.createSubmission)
|
||||||
.put(users.requiresLogin, forms.hasAuthorization, forms.update)
|
.put(users.requiresLogin, forms.hasAuthorization, forms.update)
|
||||||
.delete(users.requiresLogin, forms.hasAuthorization, forms.delete);
|
.delete(users.requiresLogin, forms.hasAuthorization, forms.delete);
|
||||||
|
|
||||||
|
app.route('/forms/:formId([a-zA-Z0-9]+)/submissions')
|
||||||
|
.get(forms.listSubmissions);
|
||||||
|
|
||||||
// Finish by binding the form middleware
|
// Finish by binding the form middleware
|
||||||
app.param('formId', forms.formByID);
|
app.param('formId', forms.formByID);
|
||||||
};
|
};
|
||||||
|
|
|
@ -107,19 +107,29 @@ module.exports = function(db) {
|
||||||
console.log(file.originalname + ' is starting ...');
|
console.log(file.originalname + ' is starting ...');
|
||||||
},
|
},
|
||||||
onFileUploadComplete: function (file, req, res) {
|
onFileUploadComplete: function (file, req, res) {
|
||||||
|
console.log(file.originalname + ' uploaded to ' + file.path);
|
||||||
// console.log('\n\nheadersSent in onFileUploadComplete: ', res.headersSent);
|
// console.log('\n\nheadersSent in onFileUploadComplete: ', res.headersSent);
|
||||||
console.log(req.body.user);
|
// res.status(200).send(file);
|
||||||
try{
|
|
||||||
formCtrl.uploadPDF(req.files, req.body.user, function(_file){
|
|
||||||
console.log(_file.filename + ' uploaded to ' + _file.path);
|
|
||||||
res.status(200).send(_file);
|
|
||||||
});
|
|
||||||
}catch(err) {
|
|
||||||
res.status(500).send({
|
|
||||||
message: err.message
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// console.log('\n\nheadersSent in onFileUploadComplete: ', res.headersSent);
|
||||||
|
// console.log(req.body.user);
|
||||||
|
// console.log(req.user);
|
||||||
|
// var _user = JSON.parse(req.body.user);
|
||||||
|
// console.log(file)
|
||||||
|
|
||||||
|
// formCtrl.uploadPDF(file, _user, function(err, _file){
|
||||||
|
// if(err){
|
||||||
|
// console.log('\n\n ERROR: '+err.message)
|
||||||
|
// res.status(500).send({
|
||||||
|
// message: err.message
|
||||||
|
// });
|
||||||
|
// }else {
|
||||||
|
// console.log(_file.filename + ' uploaded to ' + _file.path);
|
||||||
|
// res.status(200).send(_file);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// });
|
||||||
|
// }
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// CookieParser should be above session
|
// CookieParser should be above session
|
||||||
|
|
|
@ -14,7 +14,7 @@ angular.module('forms').run(['Menus',
|
||||||
return function(formObj){
|
return function(formObj){
|
||||||
//get keys
|
//get keys
|
||||||
var formKeys = Object.keys(formObj);
|
var formKeys = Object.keys(formObj);
|
||||||
// console.log(formKeys);
|
|
||||||
//we only care about things that don't start with $
|
//we only care about things that don't start with $
|
||||||
var fieldKeys = formKeys.filter(function(key){
|
var fieldKeys = formKeys.filter(function(key){
|
||||||
return key[0] !== '$';
|
return key[0] !== '$';
|
||||||
|
|
|
@ -12,10 +12,6 @@ angular.module('forms').config(['$stateProvider',
|
||||||
state('createForm', {
|
state('createForm', {
|
||||||
url: '/forms/create',
|
url: '/forms/create',
|
||||||
templateUrl: 'modules/forms/views/create-form.client.view.html',
|
templateUrl: 'modules/forms/views/create-form.client.view.html',
|
||||||
// parent: 'restricted',
|
|
||||||
// data: {
|
|
||||||
// roles: ['user', 'admin'],
|
|
||||||
// },
|
|
||||||
}).
|
}).
|
||||||
state('viewForm', {
|
state('viewForm', {
|
||||||
url: '/forms/:formId/admin',
|
url: '/forms/:formId/admin',
|
||||||
|
@ -32,10 +28,6 @@ angular.module('forms').config(['$stateProvider',
|
||||||
state('editForm', {
|
state('editForm', {
|
||||||
url: '/forms/:formId/edit',
|
url: '/forms/:formId/edit',
|
||||||
templateUrl: 'modules/forms/views/create-form.client.view.html',
|
templateUrl: 'modules/forms/views/create-form.client.view.html',
|
||||||
// parent: 'restricted',
|
|
||||||
// data: {
|
|
||||||
// roles: ['user', 'admin'],
|
|
||||||
// },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
]);
|
]);
|
|
@ -1,25 +1,22 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('forms').controller('EditFormController', ['$scope', '$state', '$rootScope', 'Upload', '$stateParams', 'FormFields', 'Forms', 'CurrentForm', '$modal', '$location',
|
angular.module('forms').controller('EditFormController', ['$scope', '$state', '$rootScope', 'Upload', '$stateParams', 'FormFields', 'Forms', 'CurrentForm', '$modal', '$location', '$http',
|
||||||
function ($scope, $state, $rootScope, Upload, $stateParams, FormFields, Forms, CurrentForm, $modal, $location) {
|
function ($scope, $state, $rootScope, Upload, $stateParams, FormFields, Forms, CurrentForm, $modal, $location, $http) {
|
||||||
|
|
||||||
$scope.isNewForm = false;
|
$scope.isNewForm = false;
|
||||||
$scope.pdfLoading = false;
|
$scope.pdfLoading = false;
|
||||||
var _current_upload = null;
|
|
||||||
|
$scope.form = {};
|
||||||
$scope.log = '';
|
$scope.log = '';
|
||||||
|
var _current_upload = null;
|
||||||
|
|
||||||
// Get current form if it exists, or create new one
|
// Get current form if it exists, or create new one
|
||||||
if($stateParams.formId){
|
if($stateParams.formId){
|
||||||
$scope.form = {};
|
Forms.get({ formId: $stateParams.formId}, function(form){
|
||||||
var _form = Forms.get({ formId: $stateParams.formId}, function(form){
|
$scope.form = angular.fromJson(angular.toJson(form));
|
||||||
_form.pdf = form.pdf;
|
console.log($scope.form);
|
||||||
_form.$save();
|
|
||||||
|
|
||||||
$scope.form = angular.fromJson(angular.toJson(_form));
|
|
||||||
console.log(JSON.stringify($scope.form.pdf));
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$scope.form = {};
|
|
||||||
$scope.form.form_fields = [];
|
$scope.form.form_fields = [];
|
||||||
$scope.isNewForm = true;
|
$scope.isNewForm = true;
|
||||||
}
|
}
|
||||||
|
@ -28,12 +25,13 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', '$
|
||||||
$scope.cancelUpload = function(){
|
$scope.cancelUpload = function(){
|
||||||
_current_upload.abort();
|
_current_upload.abort();
|
||||||
$scope.pdfLoading = false;
|
$scope.pdfLoading = false;
|
||||||
|
$scope.removePDF();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.removePDF = function(){
|
$scope.removePDF = function(){
|
||||||
$scope.form.pdf = null;
|
$scope.form.pdf = null;
|
||||||
$scope.isGenerated = false;
|
$scope.form.isGenerated = false;
|
||||||
$scope.autofillPDFs = false;
|
$scope.form.autofillPDFs = false;
|
||||||
|
|
||||||
console.log('form.pdf: '+$scope.form.pdf+' REMOVED');
|
console.log('form.pdf: '+$scope.form.pdf+' REMOVED');
|
||||||
};
|
};
|
||||||
|
@ -56,13 +54,14 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', '$
|
||||||
evt.config.file.name + '\n' + $scope.log;
|
evt.config.file.name + '\n' + $scope.log;
|
||||||
$scope.pdfLoading = true;
|
$scope.pdfLoading = true;
|
||||||
}).success(function (data, status, headers, config) {
|
}).success(function (data, status, headers, config) {
|
||||||
$scope.log = 'file ' + data.originalname + 'uploaded as '+ data.name +'. JSON: ' + JSON.stringify(data) + '\n' + $scope.log;
|
$scope.log = 'file ' + data.originalname + ' uploaded as '+ data.name +'. JSON: ' + JSON.stringify(data) + '\n' + $scope.log;
|
||||||
$scope.form.pdf = data;
|
console.log($scope.form.pdf);
|
||||||
|
$scope.form.pdf = angular.fromJson(angular.toJson(data));
|
||||||
$scope.pdfLoading = false;
|
$scope.pdfLoading = false;
|
||||||
|
|
||||||
console.log($scope.log);
|
console.log($scope.log);
|
||||||
console.log('$scope.pdf: '+$scope.form.pdf.name);
|
console.log('$scope.pdf: '+$scope.form.pdf.name);
|
||||||
if(!$scope.$$phase) {
|
if(!$scope.$$phase){
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
}
|
}
|
||||||
}).error(function(err){
|
}).error(function(err){
|
||||||
|
@ -84,23 +83,20 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', '$
|
||||||
if($scope.isNewForm){
|
if($scope.isNewForm){
|
||||||
// Create new Form object
|
// Create new Form object
|
||||||
var form = new Forms($scope.form);
|
var form = new Forms($scope.form);
|
||||||
form.$save(function(response) {
|
|
||||||
|
|
||||||
|
$http.post('/forms', {form: $scope.form})
|
||||||
|
.success(function(data, status, headers){
|
||||||
console.log('form created');
|
console.log('form created');
|
||||||
// console.log(response.pdf);
|
|
||||||
|
|
||||||
// Clear form fields
|
// Clear form fields
|
||||||
$scope.form = {};
|
$scope.form = {};
|
||||||
|
|
||||||
// Redirect after save
|
// Redirect after save
|
||||||
$scope.goToWithId('viewForm', response._id);
|
$scope.goToWithId('viewForm', $scope.form._id);
|
||||||
|
}).error(function(errorResponse){
|
||||||
}, function(errorResponse) {
|
|
||||||
console.log(errorResponse.data.message);
|
console.log(errorResponse.data.message);
|
||||||
$scope.error = errorResponse.data.message;
|
$scope.error = errorResponse.data.message;
|
||||||
});
|
});
|
||||||
} else{
|
} else{
|
||||||
console.log('update form');
|
|
||||||
$scope.update();
|
$scope.update();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -108,14 +104,24 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', '$
|
||||||
// Update existing Form
|
// Update existing Form
|
||||||
$scope.update = function() {
|
$scope.update = function() {
|
||||||
var form = new Forms($scope.form);
|
var form = new Forms($scope.form);
|
||||||
form.$update(function(response) {
|
console.log('update form');
|
||||||
console.log('form updated');
|
console.log($scope.form);
|
||||||
$scope.goToWithId('viewForm', response._id);
|
|
||||||
// $location.path('forms/' + response._id + '/admin');
|
$http.put('/forms/'+$scope.form._id, {form: $scope.form})
|
||||||
}, function(errorResponse) {
|
.success(function(data, status, headers){
|
||||||
console.log(errorResponse.data.message);
|
console.log('form updated successfully');
|
||||||
$scope.error = errorResponse.data.message;
|
$scope.goToWithId('viewForm', $scope.form._id);
|
||||||
|
}).error(function(err){
|
||||||
|
console.log('Error occured during form UPDATE.\n');
|
||||||
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
// form.$update({formId: $scope.form._id}, function(response) {
|
||||||
|
// console.log('form successfully updated');
|
||||||
|
// $scope.goToWithId('viewForm', response._id);
|
||||||
|
// }, function(errorResponse) {
|
||||||
|
// console.log(errorResponse.data.message);
|
||||||
|
// $scope.error = errorResponse.data.message;
|
||||||
|
// });
|
||||||
};
|
};
|
||||||
|
|
||||||
//Populate AddField with all available form field types
|
//Populate AddField with all available form field types
|
||||||
|
@ -152,7 +158,6 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', '$
|
||||||
|
|
||||||
// put newField into fields array
|
// put newField into fields array
|
||||||
$scope.form.form_fields.push(newField);
|
$scope.form.form_fields.push(newField);
|
||||||
// console.log($scope.form.form_fields);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// deletes particular field on button click
|
// deletes particular field on button click
|
||||||
|
@ -229,4 +234,4 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', '$
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -0,0 +1,242 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('forms').controller('EditFormController', ['$scope', '$state', '$rootScope', 'Upload', '$stateParams', 'FormFields', 'Forms', 'CurrentForm', '$modal', '$location', '$http',
|
||||||
|
function ($scope, $state, $rootScope, Upload, $stateParams, FormFields, Forms, CurrentForm, $modal, $location, $http) {
|
||||||
|
|
||||||
|
$scope.isNewForm = false;
|
||||||
|
$scope.pdfLoading = false;
|
||||||
|
|
||||||
|
$scope.form = {};
|
||||||
|
$scope.log = '';
|
||||||
|
var _current_upload = null;
|
||||||
|
|
||||||
|
// Get current form if it exists, or create new one
|
||||||
|
if($stateParams.formId){
|
||||||
|
Forms.get({ formId: $stateParams.formId}, function(form){
|
||||||
|
$scope.form = angular.fromJson(angular.toJson(form));
|
||||||
|
console.log($scope.form);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$scope.form.form_fields = [];
|
||||||
|
$scope.isNewForm = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//PDF Functions
|
||||||
|
$scope.cancelUpload = function(){
|
||||||
|
_current_upload.abort();
|
||||||
|
$scope.pdfLoading = false;
|
||||||
|
$scope.removePDF();
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.removePDF = function(){
|
||||||
|
$scope.form.pdf = null;
|
||||||
|
$scope.form.isGenerated = false;
|
||||||
|
$scope.form.autofillPDFs = false;
|
||||||
|
|
||||||
|
console.log('form.pdf: '+$scope.form.pdf+' REMOVED');
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.uploadPDF = function(files) {
|
||||||
|
|
||||||
|
if (files && files.length) {
|
||||||
|
// for (var i = 0; i < files.length; i++) {
|
||||||
|
var file = files[0];
|
||||||
|
_current_upload = Upload.upload({
|
||||||
|
url: '/upload/pdf',
|
||||||
|
fields: {
|
||||||
|
'user': $scope.user,
|
||||||
|
'form': $scope.form
|
||||||
|
},
|
||||||
|
file: file
|
||||||
|
}).progress(function (evt) {
|
||||||
|
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
|
||||||
|
$scope.log = 'progress: ' + progressPercentage + '% ' +
|
||||||
|
evt.config.file.name + '\n' + $scope.log;
|
||||||
|
$scope.pdfLoading = true;
|
||||||
|
}).success(function (data, status, headers, config) {
|
||||||
|
$scope.log = 'file ' + data.originalname + ' uploaded as '+ data.name +'. JSON: ' + JSON.stringify(data) + '\n' + $scope.log;
|
||||||
|
console.log($scope.form.pdf);
|
||||||
|
$scope.form.pdf = angular.fromJson(angular.toJson(data));
|
||||||
|
$scope.pdfLoading = false;
|
||||||
|
|
||||||
|
console.log($scope.log);
|
||||||
|
console.log('$scope.pdf: '+$scope.form.pdf.name);
|
||||||
|
if(!$scope.$$phase){
|
||||||
|
$scope.$apply();
|
||||||
|
}
|
||||||
|
}).error(function(err){
|
||||||
|
$scope.pdfLoading = false;
|
||||||
|
console.log('Error occured during upload.\n');
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.goToWithId = function(route, id) {
|
||||||
|
$state.go(route, {'formId': id}, {reload: true});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create new Form
|
||||||
|
$scope.createOrUpdate = function() {
|
||||||
|
|
||||||
|
if($scope.isNewForm){
|
||||||
|
// Create new Form object
|
||||||
|
var form = new Forms($scope.form);
|
||||||
|
<<<<<<< HEAD
|
||||||
|
form.$save(function(response) {
|
||||||
|
|
||||||
|
=======
|
||||||
|
|
||||||
|
$http.post('/forms', {form: $scope.form})
|
||||||
|
.success(function(data, status, headers){
|
||||||
|
>>>>>>> dev_working
|
||||||
|
console.log('form created');
|
||||||
|
|
||||||
|
// Clear form fields
|
||||||
|
$scope.form = {};
|
||||||
|
// Redirect after save
|
||||||
|
$scope.goToWithId('viewForm', response._id);
|
||||||
|
}).error(function(err){
|
||||||
|
console.log(errorResponse.data.message);
|
||||||
|
$scope.error = errorResponse.data.message;
|
||||||
|
});
|
||||||
|
} else{
|
||||||
|
$scope.update();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update existing Form
|
||||||
|
$scope.update = function() {
|
||||||
|
var form = new Forms($scope.form);
|
||||||
|
console.log('update form');
|
||||||
|
console.log($scope.form);
|
||||||
|
|
||||||
|
$http.put('/forms/'+$scope.form._id, {form: $scope.form})
|
||||||
|
.success(function(data, status, headers){
|
||||||
|
console.log('form updated successfully');
|
||||||
|
$scope.goToWithId('viewForm', $scope.form._id);
|
||||||
|
}).error(function(err){
|
||||||
|
console.log('Error occured during form UPDATE.\n');
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
// form.$update({formId: $scope.form._id}, function(response) {
|
||||||
|
// console.log('form successfully updated');
|
||||||
|
// $scope.goToWithId('viewForm', response._id);
|
||||||
|
// }, function(errorResponse) {
|
||||||
|
// console.log(errorResponse.data.message);
|
||||||
|
// $scope.error = errorResponse.data.message;
|
||||||
|
// });
|
||||||
|
};
|
||||||
|
|
||||||
|
//Populate AddField with all available form field types
|
||||||
|
$scope.addField = {};
|
||||||
|
$scope.addField.types = FormFields.fields;
|
||||||
|
$scope.addField.new = $scope.addField.types[0].name;
|
||||||
|
$scope.addField.lastAddedID = 0;
|
||||||
|
|
||||||
|
// preview form mode
|
||||||
|
$scope.previewMode = false;
|
||||||
|
|
||||||
|
// previewForm - for preview purposes, form will be copied into this
|
||||||
|
// otherwise, actual form might get manipulated in preview mode
|
||||||
|
$scope.previewForm = {};
|
||||||
|
|
||||||
|
|
||||||
|
// accordion settings
|
||||||
|
$scope.accordion = {};
|
||||||
|
$scope.accordion.oneAtATime = true;
|
||||||
|
|
||||||
|
// create new field button click
|
||||||
|
$scope.addNewField = function(){
|
||||||
|
|
||||||
|
// incr field_id counter
|
||||||
|
$scope.addField.lastAddedID++;
|
||||||
|
|
||||||
|
var newField = {
|
||||||
|
'title' : 'New field - ' + ($scope.addField.lastAddedID),
|
||||||
|
'fieldType' : $scope.addField.new,
|
||||||
|
'fieldValue' : '',
|
||||||
|
'required' : true,
|
||||||
|
'disabled' : false
|
||||||
|
};
|
||||||
|
|
||||||
|
// put newField into fields array
|
||||||
|
$scope.form.form_fields.push(newField);
|
||||||
|
};
|
||||||
|
|
||||||
|
// deletes particular field on button click
|
||||||
|
$scope.deleteField = function (field_id){
|
||||||
|
for(var i = 0; i < $scope.form.form_fields.length; i++){
|
||||||
|
if($scope.form.form_fields[i].field_id === field_id){
|
||||||
|
$scope.form.form_fields.splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// add new option to the field
|
||||||
|
$scope.addOption = function (field){
|
||||||
|
if(!field.field_options)
|
||||||
|
field.field_options = [];
|
||||||
|
|
||||||
|
var lastOptionID = 0;
|
||||||
|
|
||||||
|
if(field.field_options[field.field_options.length-1])
|
||||||
|
lastOptionID = field.field_options[field.field_options.length-1].option_id;
|
||||||
|
|
||||||
|
// new option's id
|
||||||
|
var option_id = lastOptionID + 1;
|
||||||
|
|
||||||
|
var newOption = {
|
||||||
|
'option_id' : option_id,
|
||||||
|
'option_title' : 'Option ' + option_id,
|
||||||
|
'option_value' : option_id
|
||||||
|
};
|
||||||
|
|
||||||
|
// put new option into field_options array
|
||||||
|
field.field_options.push(newOption);
|
||||||
|
};
|
||||||
|
|
||||||
|
// delete particular option
|
||||||
|
$scope.deleteOption = function (field, option){
|
||||||
|
for(var i = 0; i < field.field_options.length; i++){
|
||||||
|
if(field.field_options[i].option_id === option.option_id){
|
||||||
|
field.field_options.splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// preview form
|
||||||
|
$scope.previewOn = function(){
|
||||||
|
if($scope.form.form_fields === null || $scope.form.form_fields.length === 0) {
|
||||||
|
var title = 'Error';
|
||||||
|
var msg = 'No fields added yet, please add fields to the form before preview.';
|
||||||
|
var btns = [{result:'ok', label: 'OK', cssClass: 'btn-primary'}];
|
||||||
|
|
||||||
|
// $dialog.messageBox(title, msg, btns).open();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$scope.previewMode = !$scope.previewMode;
|
||||||
|
$scope.form.submitted = false;
|
||||||
|
angular.copy($scope.form, $scope.previewForm);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// hide preview form, go back to create mode
|
||||||
|
$scope.previewOff = function(){
|
||||||
|
$scope.previewMode = !$scope.previewMode;
|
||||||
|
$scope.form.submitted = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// decides whether field options block will be shown (true for dropdown and radio fields)
|
||||||
|
$scope.showAddOptions = function (field){
|
||||||
|
if(field.field_type === 'radio' || field.field_type === 'dropdown')
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]);
|
|
@ -28,26 +28,14 @@ angular.module('forms').controller('ViewSubmissionController', ['$scope', '$stat
|
||||||
|
|
||||||
// Remove existing submission
|
// Remove existing submission
|
||||||
$scope.remove = function(submission) {
|
$scope.remove = function(submission) {
|
||||||
if (submission) {
|
if (!submission) {
|
||||||
submission.$remove();
|
submission = $scope.submission;
|
||||||
|
|
||||||
$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..');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
$http.delete('/forms/'+$stateParams.formId+'/submissions/'+submission._id).
|
||||||
|
success(function(data, status, headers){
|
||||||
|
console.log('submission deleted successfully');
|
||||||
|
alert('submission deleted..');
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,12 @@ angular.module('forms').controller('ViewFormController', ['$scope', '$stateParam
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log($scope.submissions);
|
console.log($scope.submissions);
|
||||||
}
|
};
|
||||||
|
|
||||||
//hide submissions of Form
|
//hide submissions of Form
|
||||||
$scope.hideSubmissions = function(){
|
$scope.hideSubmissions = function(){
|
||||||
$scope.viewSubmissions = false;
|
$scope.viewSubmissions = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
// Return all user's Forms
|
// Return all user's Forms
|
||||||
$scope.findAll = function() {
|
$scope.findAll = function() {
|
||||||
|
@ -56,11 +56,10 @@ angular.module('forms').controller('ViewFormController', ['$scope', '$stateParam
|
||||||
|
|
||||||
// Remove existing Form
|
// Remove existing Form
|
||||||
$scope.remove = function() {
|
$scope.remove = function() {
|
||||||
console.log('hello');
|
|
||||||
var form = CurrentForm.getForm()
|
var form = CurrentForm.getForm();
|
||||||
if(!form){
|
if(!form) form = $scope.form;
|
||||||
form = $scope.form
|
|
||||||
}
|
|
||||||
$http.delete('/forms/'+$scope.form._id)
|
$http.delete('/forms/'+$scope.form._id)
|
||||||
.success(function(data, status, headers){
|
.success(function(data, status, headers){
|
||||||
console.log('form deleted successfully');
|
console.log('form deleted successfully');
|
||||||
|
|
31
public/modules/forms/directives/table.client.directive.js
Normal file
31
public/modules/forms/directives/table.client.directive.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('forms').directive('tableDirective', ['$http', '$timeout', 'Auth',
|
||||||
|
function ($http, $timeout, Auth) {
|
||||||
|
return {
|
||||||
|
controller: function($scope){
|
||||||
|
|
||||||
|
$scope.toggleChecker = function(checked) {
|
||||||
|
var rows = $scope.gridOptions.$gridScope.renderedRows,
|
||||||
|
allChecked = true;
|
||||||
|
|
||||||
|
for (var r = 0; r < rows.length; r++) {
|
||||||
|
if (rows[r].entity.checker !== true) {
|
||||||
|
allChecked = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.gridOptions.$gridScope.checker = allChecked;
|
||||||
|
};
|
||||||
|
|
||||||
|
},
|
||||||
|
templateUrl: './modules/forms/views/directiveViews/table/table.html',
|
||||||
|
restrict: 'E',
|
||||||
|
scope: {
|
||||||
|
rows:'=',
|
||||||
|
extras:'=',
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]);
|
|
@ -23,43 +23,3 @@ angular.module('users').config(['$httpProvider',
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
||||||
// Config HTTP Error Handling
|
|
||||||
// angular.module('users').config(['$httpProvider',
|
|
||||||
// function($httpProvider) {
|
|
||||||
// // Set the httpProvider "not authorized" interceptor
|
|
||||||
// $httpProvider.interceptors.push(['$q', '$location', 'Principal',
|
|
||||||
// function($q, $state, Principal) {
|
|
||||||
// return {
|
|
||||||
// responseSuccess: function(response) {
|
|
||||||
// Principal.identity().then(function(user){
|
|
||||||
// console.log(user);
|
|
||||||
// // $rootScope.user = user;
|
|
||||||
// }, function(error){
|
|
||||||
// console.log("Coudn't get current user. \n ERROR: "+error);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// },
|
|
||||||
// responseError: function(rejection) {
|
|
||||||
// switch (rejection.status) {
|
|
||||||
// case 401:
|
|
||||||
// // Deauthenticate the global user
|
|
||||||
// Principal.authenticate(null);
|
|
||||||
|
|
||||||
// // Redirect to signin page
|
|
||||||
// $location.path('/signin');
|
|
||||||
// break;
|
|
||||||
// case 403:
|
|
||||||
// // Add unauthorized behaviour
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
>>>>>>> dev_working
|
|
||||||
|
|
||||||
return $q.reject(rejection);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
]);
|
|
|
@ -6,8 +6,6 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$loca
|
||||||
$scope = $rootScope;
|
$scope = $rootScope;
|
||||||
$scope.credentials = {};
|
$scope.credentials = {};
|
||||||
|
|
||||||
// $scope.authentication = Principal;
|
|
||||||
|
|
||||||
// If user is signed in then redirect back home
|
// If user is signed in then redirect back home
|
||||||
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,10 @@
|
||||||
|
|
||||||
angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$state', 'User',
|
angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$state', 'User',
|
||||||
function($scope, $stateParams, $state, User) {
|
function($scope, $stateParams, $state, User) {
|
||||||
// $scope.authentication = Principal;
|
|
||||||
|
|
||||||
//If user is signed in then redirect back home
|
//If user is signed in then redirect back home
|
||||||
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
||||||
|
|
||||||
// Principal.identity().then(function(response){
|
|
||||||
// $scope.authentication.user = response;
|
|
||||||
|
|
||||||
// Submit forgotten password account id
|
// Submit forgotten password account id
|
||||||
$scope.askForPasswordReset = function() {
|
$scope.askForPasswordReset = function() {
|
||||||
User.askForPasswordReset($scope.credentials).then(
|
User.askForPasswordReset($scope.credentials).then(
|
||||||
|
@ -41,21 +37,6 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam
|
||||||
$scope.passwordDetails = null;
|
$scope.passwordDetails = null;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// $scope.success = $scope.error = null;
|
|
||||||
|
|
||||||
// $http.post('/auth/reset/' + $stateParams.token, $scope.passwordDetails).success(function(response) {
|
|
||||||
// // If successful show success message and clear form
|
|
||||||
// $scope.passwordDetails = null;
|
|
||||||
|
|
||||||
// // Attach user profile
|
|
||||||
// // Principal.user() = response;
|
|
||||||
|
|
||||||
// // And redirect to the index page
|
|
||||||
// $state.go('reset-success');
|
|
||||||
// }).error(function(response) {
|
|
||||||
// $scope.error = response.message;
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
]);
|
]);
|
|
@ -1,47 +1,47 @@
|
||||||
'use strict';
|
// 'use strict';
|
||||||
|
|
||||||
angular.module('users').factory('Authorization', ['$rootScope', '$http', '$q', '$state', 'Principal',
|
// angular.module('users').factory('Authorization', ['$rootScope', '$http', '$q', '$state', 'Principal',
|
||||||
function($rootScope, $http, $q, $state, Principal) {
|
// function($rootScope, $http, $q, $state, Principal) {
|
||||||
var service = {
|
// var service = {
|
||||||
authorize: function(){
|
// authorize: function(){
|
||||||
var deferred = $q.defer();
|
// var deferred = $q.defer();
|
||||||
$http.get('/user/me').success(function(response) {
|
// $http.get('/user/me').success(function(response) {
|
||||||
|
|
||||||
|
|
||||||
//user is logged in
|
// //user is logged in
|
||||||
if(response.data !== null){
|
// if(response.data !== null){
|
||||||
deferred.resolve();
|
// deferred.resolve();
|
||||||
}else {
|
// }else {
|
||||||
$rootScope.message = 'You need to log in.';
|
// $rootScope.message = 'You need to log in.';
|
||||||
deferred.reject();
|
// deferred.reject();
|
||||||
$state.go('/login');
|
// $state.go('/login');
|
||||||
}
|
// }
|
||||||
|
|
||||||
});
|
// });
|
||||||
return deferred.promise();
|
// return deferred.promise();
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
return service;
|
// return service;
|
||||||
// this.authorize = function() {
|
// // this.authorize = function() {
|
||||||
// return Principal.identity().then(function(){
|
// // return Principal.identity().then(function(){
|
||||||
// var isAuthenticated = Principal.isAuthenticated();
|
// // var isAuthenticated = Principal.isAuthenticated();
|
||||||
// if( angular.isDefined($rootScope.toState.data) ){
|
// // if( angular.isDefined($rootScope.toState.data) ){
|
||||||
// // if ($rootScope.toState.data.roles && $rootScope.toState.data.roles.length > 0 && !principal.isInAnyRole($rootScope.toState.data.roles)) {
|
// // // if ($rootScope.toState.data.roles && $rootScope.toState.data.roles.length > 0 && !principal.isInAnyRole($rootScope.toState.data.roles)) {
|
||||||
// if (!isAuthenticated){ //$location.path('/access_denied'); // user is signed in but not authorized for desired state
|
// // if (!isAuthenticated){ //$location.path('/access_denied'); // user is signed in but not authorized for desired state
|
||||||
// // console.log('isAuthenticated: '+isAuthenticated);
|
// // // console.log('isAuthenticated: '+isAuthenticated);
|
||||||
|
|
||||||
// // else {
|
// // // else {
|
||||||
// // user is not authenticated. so the state they wanted before you
|
// // // user is not authenticated. so the state they wanted before you
|
||||||
// // send them to the signin state, so you can return them when you're done
|
// // // send them to the signin state, so you can return them when you're done
|
||||||
// $rootScope.returnToState = $rootScope.toState;
|
// // $rootScope.returnToState = $rootScope.toState;
|
||||||
// $rootScope.returnToStateParams = $rootScope.toStateParams;
|
// // $rootScope.returnToStateParams = $rootScope.toStateParams;
|
||||||
|
|
||||||
// // now, send them to the signin state so they can log in
|
// // // now, send them to the signin state so they can log in
|
||||||
// $location.path('/signin');
|
// // $location.path('/signin');
|
||||||
// }
|
// // }
|
||||||
// // }
|
// // // }
|
||||||
// }
|
// // }
|
||||||
// });
|
// // });
|
||||||
// };
|
// // };
|
||||||
}
|
// }
|
||||||
]);
|
// ]);
|
|
@ -1,202 +1,202 @@
|
||||||
'use strict';
|
// 'use strict';
|
||||||
|
|
||||||
angular.module('users').factory('AuthenticationService', function($http, $timeout, $q) {
|
// angular.module('users').factory('AuthenticationService', function($http, $timeout, $q) {
|
||||||
var error;
|
// var error;
|
||||||
var service = {
|
// var service = {
|
||||||
// Information about the current user
|
// // Information about the current user
|
||||||
currentUser: null,
|
// currentUser: null,
|
||||||
|
|
||||||
login: function(credentials) {
|
// login: function(credentials) {
|
||||||
var login = $http.post('/auth/signin', credentials);
|
// var login = $http.post('/auth/signin', credentials);
|
||||||
login.success(function(data) {
|
// login.success(function(data) {
|
||||||
service.currentUser = data.user;
|
// service.currentUser = data.user;
|
||||||
// $flash.clear();
|
// // $flash.clear();
|
||||||
}).error(function(error) {
|
// }).error(function(error) {
|
||||||
error = error.error ? error.error : error;
|
// error = error.error ? error.error : error;
|
||||||
console.error(error.message || error);
|
// console.error(error.message || error);
|
||||||
});
|
|
||||||
return login;
|
|
||||||
},
|
|
||||||
|
|
||||||
logout: function() {
|
|
||||||
var logout = $http.get('/auth/logout');
|
|
||||||
logout.success(function() {
|
|
||||||
service.currentUser = null;
|
|
||||||
console.log("You've successfully logged out");
|
|
||||||
});
|
|
||||||
return logout;
|
|
||||||
},
|
|
||||||
|
|
||||||
signup: function(credentials) {
|
|
||||||
var signup = $http.post('/auth/signup', credentials)
|
|
||||||
signup.success(function(response) {
|
|
||||||
console.log("You've successfully created an account");
|
|
||||||
}).error(function(response) {
|
|
||||||
error = error.error ? error.error : error;
|
|
||||||
console.error(error.message || error);
|
|
||||||
});
|
|
||||||
|
|
||||||
return signup;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Ask the backend to see if a user is already authenticated -
|
|
||||||
// this may be from a previous session.
|
|
||||||
identity: function() {
|
|
||||||
if (service.isAuthenticated()) {
|
|
||||||
return $q.when(service.currentUser);
|
|
||||||
} else {
|
|
||||||
return $http.get('/user/me').then(function(response) {
|
|
||||||
service.currentUser = response.data.user;
|
|
||||||
return service.currentUser;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Is the current user authenticated?
|
|
||||||
isAuthenticated: function() {
|
|
||||||
return !!service.currentUser;
|
|
||||||
},
|
|
||||||
|
|
||||||
isInRole: function(role) {
|
|
||||||
return service.isAuthenticated() (service.currentUser.roles.indexOf(role) !== -1);
|
|
||||||
},
|
|
||||||
|
|
||||||
isInAnyRole: function(roles) {
|
|
||||||
if ( !service.isAuthenticated() || !service.currentUser.roles) return false;
|
|
||||||
var roles = service.currentUser.roles;
|
|
||||||
|
|
||||||
for (var i = 0; i < roles.length; i++) {
|
|
||||||
if (this.isInRole(roles[i])) return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
};
|
|
||||||
return service;
|
|
||||||
});
|
|
||||||
|
|
||||||
// .factory('Principal', ['$window', '$http', '$q', '$timeout', '$state',
|
|
||||||
// function($window, $http, $q, $timeout, $state) {
|
|
||||||
// var _identity,
|
|
||||||
// _authenticated = false;
|
|
||||||
|
|
||||||
// return {
|
|
||||||
// isIdentityResolved: function() {
|
|
||||||
// return angular.isDefined(_identity);
|
|
||||||
// },
|
|
||||||
// isAuthenticated: function() {
|
|
||||||
// return _authenticated;
|
|
||||||
// },
|
|
||||||
// isInRole: function(role) {
|
|
||||||
// if (!_authenticated || !_identity.roles) return false;
|
|
||||||
|
|
||||||
// return _identity.roles.indexOf(role) !== -1;
|
|
||||||
// },
|
|
||||||
// isInAnyRole: function(roles) {
|
|
||||||
// if (!_authenticated || !_identity.roles) return false;
|
|
||||||
|
|
||||||
// for (var i = 0; i < roles.length; i++) {
|
|
||||||
// if (this.isInRole(roles[i])) return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return false;
|
|
||||||
// },
|
|
||||||
// authenticate: function(user) {
|
|
||||||
// _identity = user;
|
|
||||||
// _authenticated = (user !== null);
|
|
||||||
|
|
||||||
// // for this demo, we'll store the identity in localStorage. For you, it could be a cookie, sessionStorage, whatever
|
|
||||||
// if (user) $window.user = user;
|
|
||||||
// else $window.user = null;
|
|
||||||
// },
|
|
||||||
// signin: function(credentials) {
|
|
||||||
|
|
||||||
// var deferred = $q.defer();
|
|
||||||
// var self = this;
|
|
||||||
// $http.post('/auth/signin', credentials).success(function(response) {
|
|
||||||
// // If successful we assign the response to the global user model
|
|
||||||
// self.authenticate(response);
|
|
||||||
// deferred.resolve(response);
|
|
||||||
// }).error(function(response) {
|
|
||||||
// _authenticated = false;
|
|
||||||
// deferred.reject({ error: response.message });
|
|
||||||
// });
|
// });
|
||||||
// return deferred.promise;
|
// return login;
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
// logout: function() {
|
||||||
|
// var logout = $http.get('/auth/logout');
|
||||||
|
// logout.success(function() {
|
||||||
|
// service.currentUser = null;
|
||||||
|
// console.log("You've successfully logged out");
|
||||||
|
// });
|
||||||
|
// return logout;
|
||||||
|
// },
|
||||||
|
|
||||||
// signup: function(credentials) {
|
// signup: function(credentials) {
|
||||||
|
// var signup = $http.post('/auth/signup', credentials)
|
||||||
// var deferred = $q.defer();
|
// signup.success(function(response) {
|
||||||
|
// console.log("You've successfully created an account");
|
||||||
// $http.post('/auth/signup', credentials).success(function(response) {
|
|
||||||
// // If successful we assign the response to the global user model
|
|
||||||
// deferred.resolve(response);
|
|
||||||
// }).error(function(response) {
|
// }).error(function(response) {
|
||||||
|
// error = error.error ? error.error : error;
|
||||||
// deferred.reject({ error: response.message });
|
// console.error(error.message || error);
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// return deferred.promise;
|
// return signup;
|
||||||
// },
|
// },
|
||||||
// signout: function() {
|
|
||||||
// var deferred = $q.defer();
|
|
||||||
// $http.get('/auth/signout').success(function(response) {
|
|
||||||
// // If successful we assign the response to the global user model
|
|
||||||
// deferred.resolve({});
|
|
||||||
// }).error(function(response) {
|
|
||||||
// deferred.reject({ error: response.message });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// _authenticated = false;
|
// // Ask the backend to see if a user is already authenticated -
|
||||||
// _identity = undefined;
|
// // this may be from a previous session.
|
||||||
|
|
||||||
// return deferred.promise;
|
|
||||||
// },
|
|
||||||
// identity: function() {
|
// identity: function() {
|
||||||
// var self = this;
|
// if (service.isAuthenticated()) {
|
||||||
|
// return $q.when(service.currentUser);
|
||||||
// var deferred = $q.defer();
|
// } else {
|
||||||
|
// return $http.get('/user/me').then(function(response) {
|
||||||
// // check and see if we have retrieved the user data from the server. if we have, reuse it by immediately resolving
|
// service.currentUser = response.data.user;
|
||||||
// if (angular.isDefined(_identity)) {
|
// return service.currentUser;
|
||||||
|
// });
|
||||||
// deferred.resolve(_identity);
|
// }
|
||||||
// return deferred.promise;
|
|
||||||
// }else if($window.user){
|
|
||||||
// // console.log($window.user);
|
|
||||||
// // self.authenticate($window.user);
|
|
||||||
// // var user = $window.user;
|
|
||||||
// _identity = $window.user;
|
|
||||||
// self.authenticate(_identity);
|
|
||||||
// deferred.resolve(_identity);
|
|
||||||
|
|
||||||
// return deferred.promise;
|
|
||||||
// }else {
|
|
||||||
|
|
||||||
// // otherwise, retrieve the user data from the server, update the user object, and then resolve.
|
|
||||||
// $http.get('/users/me', { ignoreErrors: true })
|
|
||||||
// .success(function(response) {
|
|
||||||
// self.authenticate(response);
|
|
||||||
// $window.user = response;
|
|
||||||
// deferred.resolve(_identity);
|
|
||||||
// })
|
|
||||||
// .error(function() {
|
|
||||||
// _identity = null;
|
|
||||||
// _authenticated = false;
|
|
||||||
// $window.user = null;
|
|
||||||
// $state.path('signin');
|
|
||||||
// deferred.resolve(_identity);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// return deferred.promise;
|
|
||||||
// }
|
|
||||||
// },
|
// },
|
||||||
// getUser: function(){
|
|
||||||
// this.identity(false).then( function(user){
|
// // Is the current user authenticated?
|
||||||
// return user;
|
// isAuthenticated: function() {
|
||||||
// });
|
// return !!service.currentUser;
|
||||||
// }
|
// },
|
||||||
// };
|
|
||||||
|
// isInRole: function(role) {
|
||||||
|
// return service.isAuthenticated() (service.currentUser.roles.indexOf(role) !== -1);
|
||||||
|
// },
|
||||||
|
|
||||||
|
// isInAnyRole: function(roles) {
|
||||||
|
// if ( !service.isAuthenticated() || !service.currentUser.roles) return false;
|
||||||
|
// var roles = service.currentUser.roles;
|
||||||
|
|
||||||
|
// for (var i = 0; i < roles.length; i++) {
|
||||||
|
// if (this.isInRole(roles[i])) return true;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return false;
|
||||||
|
// },
|
||||||
|
|
||||||
|
// };
|
||||||
|
// return service;
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // .factory('Principal', ['$window', '$http', '$q', '$timeout', '$state',
|
||||||
|
// // function($window, $http, $q, $timeout, $state) {
|
||||||
|
// // var _identity,
|
||||||
|
// // _authenticated = false;
|
||||||
|
|
||||||
|
// // return {
|
||||||
|
// // isIdentityResolved: function() {
|
||||||
|
// // return angular.isDefined(_identity);
|
||||||
|
// // },
|
||||||
|
// // isAuthenticated: function() {
|
||||||
|
// // return _authenticated;
|
||||||
|
// // },
|
||||||
|
// // isInRole: function(role) {
|
||||||
|
// // if (!_authenticated || !_identity.roles) return false;
|
||||||
|
|
||||||
|
// // return _identity.roles.indexOf(role) !== -1;
|
||||||
|
// // },
|
||||||
|
// // isInAnyRole: function(roles) {
|
||||||
|
// // if (!_authenticated || !_identity.roles) return false;
|
||||||
|
|
||||||
|
// // for (var i = 0; i < roles.length; i++) {
|
||||||
|
// // if (this.isInRole(roles[i])) return true;
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// // return false;
|
||||||
|
// // },
|
||||||
|
// // authenticate: function(user) {
|
||||||
|
// // _identity = user;
|
||||||
|
// // _authenticated = (user !== null);
|
||||||
|
|
||||||
|
// // // for this demo, we'll store the identity in localStorage. For you, it could be a cookie, sessionStorage, whatever
|
||||||
|
// // if (user) $window.user = user;
|
||||||
|
// // else $window.user = null;
|
||||||
|
// // },
|
||||||
|
// // signin: function(credentials) {
|
||||||
|
|
||||||
|
// // var deferred = $q.defer();
|
||||||
|
// // var self = this;
|
||||||
|
// // $http.post('/auth/signin', credentials).success(function(response) {
|
||||||
|
// // // If successful we assign the response to the global user model
|
||||||
|
// // self.authenticate(response);
|
||||||
|
// // deferred.resolve(response);
|
||||||
|
// // }).error(function(response) {
|
||||||
|
// // _authenticated = false;
|
||||||
|
// // deferred.reject({ error: response.message });
|
||||||
|
// // });
|
||||||
|
// // return deferred.promise;
|
||||||
|
// // },
|
||||||
|
// // signup: function(credentials) {
|
||||||
|
|
||||||
|
// // var deferred = $q.defer();
|
||||||
|
|
||||||
|
// // $http.post('/auth/signup', credentials).success(function(response) {
|
||||||
|
// // // If successful we assign the response to the global user model
|
||||||
|
// // deferred.resolve(response);
|
||||||
|
// // }).error(function(response) {
|
||||||
|
|
||||||
|
// // deferred.reject({ error: response.message });
|
||||||
|
// // });
|
||||||
|
|
||||||
|
// // return deferred.promise;
|
||||||
|
// // },
|
||||||
|
// // signout: function() {
|
||||||
|
// // var deferred = $q.defer();
|
||||||
|
// // $http.get('/auth/signout').success(function(response) {
|
||||||
|
// // // If successful we assign the response to the global user model
|
||||||
|
// // deferred.resolve({});
|
||||||
|
// // }).error(function(response) {
|
||||||
|
// // deferred.reject({ error: response.message });
|
||||||
|
// // });
|
||||||
|
|
||||||
|
// // _authenticated = false;
|
||||||
|
// // _identity = undefined;
|
||||||
|
|
||||||
|
// // return deferred.promise;
|
||||||
|
// // },
|
||||||
|
// // identity: function() {
|
||||||
|
// // var self = this;
|
||||||
|
|
||||||
|
// // var deferred = $q.defer();
|
||||||
|
|
||||||
|
// // // check and see if we have retrieved the user data from the server. if we have, reuse it by immediately resolving
|
||||||
|
// // if (angular.isDefined(_identity)) {
|
||||||
|
|
||||||
|
// // deferred.resolve(_identity);
|
||||||
|
// // return deferred.promise;
|
||||||
|
// // }else if($window.user){
|
||||||
|
// // // console.log($window.user);
|
||||||
|
// // // self.authenticate($window.user);
|
||||||
|
// // // var user = $window.user;
|
||||||
|
// // _identity = $window.user;
|
||||||
|
// // self.authenticate(_identity);
|
||||||
|
// // deferred.resolve(_identity);
|
||||||
|
|
||||||
|
// // return deferred.promise;
|
||||||
|
// // }else {
|
||||||
|
|
||||||
|
// // // otherwise, retrieve the user data from the server, update the user object, and then resolve.
|
||||||
|
// // $http.get('/users/me', { ignoreErrors: true })
|
||||||
|
// // .success(function(response) {
|
||||||
|
// // self.authenticate(response);
|
||||||
|
// // $window.user = response;
|
||||||
|
// // deferred.resolve(_identity);
|
||||||
|
// // })
|
||||||
|
// // .error(function() {
|
||||||
|
// // _identity = null;
|
||||||
|
// // _authenticated = false;
|
||||||
|
// // $window.user = null;
|
||||||
|
// // $state.path('signin');
|
||||||
|
// // deferred.resolve(_identity);
|
||||||
|
// // });
|
||||||
|
|
||||||
|
// // return deferred.promise;
|
||||||
|
// // }
|
||||||
|
// // },
|
||||||
|
// // getUser: function(){
|
||||||
|
// // this.identity(false).then( function(user){
|
||||||
|
// // return user;
|
||||||
|
// // });
|
||||||
|
// // }
|
||||||
|
// // };
|
||||||
|
|
||||||
// }
|
// // }
|
||||||
// ]);
|
// // ]);
|
||||||
|
|
Loading…
Reference in a new issue