periodicjs.core.controllerhelper
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -23,3 +23,8 @@ /* | ||
*/ | ||
var ControllerHelper = function () { | ||
var logger,appSettings; | ||
var ControllerHelper = function (resources) { | ||
logger = resources.logger; | ||
appSettings = resources.settings; | ||
}; | ||
@@ -87,2 +92,106 @@ | ||
ControllerHelper.prototype.handleDocumentQueryRender = function (options) { | ||
var res = options.res, | ||
req = options.req, | ||
redirecturl = options.redirecturl, | ||
err = options.err, | ||
callback = options.callback, | ||
responseData = options.responseData; | ||
if (err) { | ||
this.handleDocumentQueryErrorResponse({ | ||
res: res, | ||
req: req, | ||
err: err, | ||
callback: callback, | ||
redirecturl: redirecturl | ||
}); | ||
} | ||
else { | ||
responseData.periodic = responseData.periodic || {}; | ||
responseData.periodic.version = appSettings.version; | ||
responseData.periodic.name = appSettings.name; | ||
responseData.request = { | ||
query: req.query, | ||
params: req.params, | ||
baseurl: req.baseUrl, | ||
originalurl: req.originalUrl, | ||
parsed: req._parsedUrl | ||
}; | ||
responseData.flash_messages = req.flash(); | ||
if (req.query.format === 'json' || req.params.ext === 'json') { | ||
res.send(responseData); | ||
} | ||
else if (req.query.callback) { | ||
res.jsonp(responseData); | ||
} | ||
else if (options.redirecturl) { | ||
res.redirect(options.redirecturl); | ||
} | ||
else { | ||
res.render(options.renderView, responseData); | ||
} | ||
} | ||
if (callback) { | ||
callback(); | ||
} | ||
}; | ||
ControllerHelper.prototype.handleDocumentQueryErrorResponse = function (options) { | ||
var err = options.err, | ||
errormessage = (typeof options.err === 'string') ? options.err : options.err.message, | ||
redirecturl = options.redirecturl, | ||
req = options.req, | ||
res = options.res, | ||
callback = options.callback; //, | ||
// errorFlashMessage = (options.errorflash) ? options.errorflash : errormessage; | ||
res.status(400); | ||
logger.error(err.stack); | ||
logger.error(errormessage, req.url); | ||
if (req.query.format === 'json') { | ||
res.send({ | ||
'result': 'error', | ||
'data': { | ||
error: errormessage | ||
} | ||
}); | ||
} | ||
else { | ||
if (options.errorflash !== false) { | ||
req.flash('error', errormessage); | ||
} | ||
if (callback) { | ||
callback(); | ||
} | ||
else if (redirecturl) { | ||
res.redirect(redirecturl); | ||
} | ||
else { | ||
var self = this; | ||
self.getPluginViewDefaultTemplate({ | ||
viewname: 'home/error404', | ||
themefileext: appSettings.templatefileextension | ||
}, | ||
function (err, templatepath) { | ||
self.handleDocumentQueryRender({ | ||
res: res, | ||
req: req, | ||
renderView: templatepath, | ||
responseData: { | ||
pagedata: { | ||
title: 'Not Found' | ||
}, | ||
user: req.user, | ||
url: req.url | ||
} | ||
}); | ||
} | ||
); | ||
} | ||
} | ||
}; | ||
module.exports = ControllerHelper; |
{ | ||
"name": "periodicjs.core.controllerhelper", | ||
"description": "Customizable CMS platform", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17144
484