Skip to content
Browse files

Slowly fixing broken branch, fixed versioning so content can now be s…

…aved
  • Loading branch information...
1 parent 928f8c0 commit ebb46c3714e5086db377d92b390438a3b1e1e90a @cliftonc committed Apr 7, 2012
Showing with 30 additions and 14 deletions.
  1. +1 −1 lib/Form.js
  2. +3 −2 lib/Router.js
  3. +13 −0 lib/Utils.js
  4. +8 −7 modules/core/contentVersions/contentVersions.js
  5. +1 −0 modules/core/tagcloud/tagcloud.js
  6. +4 −4 package.json
View
2 lib/Form.js
@@ -1082,7 +1082,7 @@ function removeSection(form, sectionId) {
/**
* Simple object mapper, used to copy over form values to schemas
*/
-me.mapFields = function(fields,record) {
+me.mapFields = function(fields, record) {
var props = Object.getOwnPropertyNames(fields);
props.forEach( function(name) {
View
5 lib/Router.js
@@ -177,9 +177,10 @@ var Router = function (moduleName, modulePath) {
res.layout = "admin";
}
- /* Check to see if it requires admin access
+ // TODO
var isAdmin = req.session.user && req.session.user.isAdmin;
- if (route.admin && !isAdmin) {
+
+ /*if (route.admin && !isAdmin) {
req.flash('error', req.t('You need to be an administrative user to view that page.'));
res.statusCode = 401;
res.redirect("/");
View
13 lib/Utils.js
@@ -1,6 +1,7 @@
/**
* General utility methods
*/
+var _ = require('underscore');
exports = module.exports = {
/**
@@ -54,5 +55,17 @@ exports = module.exports = {
nsLen = nsArray.length;
}
return obj;
+ },
+
+ /**
+ * Simple mongo object copier, used to do a shallow copy of objects
+ */
+ copyMongoObject: function(object, copy, schema) {
+
+ var fields = _.keys(schema.paths);
+ _.each(fields, function(key) {
+ if(key !== '_id') copy.set(key, object.get(key));
+ });
+
}
}
View
15 modules/core/contentVersions/contentVersions.js
@@ -130,15 +130,14 @@ function saveVersion(event, content, next) {
// Create version and map fields
var version = new ContentVersion();
- calipso.form.mapFields(content, version);
+
+ calipso.utils.copyMongoObject(content, version, content.schema);
version.contentId = content._id;
if(version.get("version")) {
- calipso.e.pre_emit('CONTENT_VERSION',version);
+ calipso.e.pre_emit('CONTENT_VERSION', version);
}
- console.log("About to save version ...");
-
version.save(function(err) {
if(err) {
@@ -313,26 +312,28 @@ function revertVersion(req,res,template,block,next) {
ContentVersion.findById(id,function(err,version) {
+
if(err && !version) {
calipso.err(err);
next();
return;
}
// Copy over
- Content.findById(contentId,function(err,content) {
+ Content.findById(contentId,function(err, content) {
if(err && !content) {
calipso.err(err)
next();
return;
}
- calipso.form.mapFields(version.doc,content);
+ calipso.utils.copyMongoObject(version, content, content.schema);
+
content.author = req.session.user.username;
content.set("comment",'Reverted to version: ' + content.updated);
content.updated = new Date();
- content.set("version",'Yes');
+ content.set("version", 'Yes');
content.save(function(err) {
res.redirect('/content/show/' + contentId);
View
1 modules/core/tagcloud/tagcloud.js
@@ -94,6 +94,7 @@ function mapReduceTagCloud(event,options,next) {
mongoose.connection.db.executeDbCommand(command, function(err, dbres)
{
+
// Reset
calipso.mr.tagcloud = false;
if (err) {
View
8 package.json
@@ -21,13 +21,13 @@
"node": "0.4.x || 0.5.x"
},
"dependencies": {
- "express": "2.4.x",
- "connect": "1.6.x",
+ "express": "2.5.x",
+ "connect": "1.8.x",
"ejs": "0.4.x",
"jade": "0.13.x",
"stylus": "0.13.x",
"underscore":"1.1.x",
- "mongoose": "2.0.x",
+ "mongoose": "2.5.x",
"winston": "0.3.x",
"mongodb": "0.9.x",
"connect-form": "0.2.x",
@@ -42,7 +42,7 @@
"bcrypt": "0.2.x",
"semver":"1.0.x",
"hook.io":"0.7.x",
- "zipfile":"0.2.x",
+ "zipfile":"0.3.x",
"rimraf":"1.0.x",
"nconf":"0.2.x",
"async": "0.1.x"

0 comments on commit ebb46c3

Please sign in to comment.
Something went wrong with that request. Please try again.