Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Add popovers to allow elements to be edited and deleted. Implement de…
Browse files Browse the repository at this point in the history
…letion.
  • Loading branch information
Karthik Viswanathan committed Jul 13, 2012
1 parent 6893c76 commit 4cdf1a5
Show file tree
Hide file tree
Showing 37 changed files with 848 additions and 104 deletions.
1 change: 1 addition & 0 deletions .jshintignore
Expand Up @@ -2,4 +2,5 @@ node_modules
public/javascripts/backbone.min.js
public/javascripts/underscore.min.js
public/javascripts/bootstrap.min.js
public/javascripts/bootstrap.js
public/javascripts/json2.js
4 changes: 2 additions & 2 deletions lib/elements.js
Expand Up @@ -5,7 +5,7 @@ const ALLOWED_FIELDS = {
head: undefined,

// > id of next element to form a linked list
next: undefined,
nextId: undefined,

// input fields
name: undefined,
Expand All @@ -31,7 +31,7 @@ function getDefaultElement(req) {
return {
type: req.body.type,
head: req.body.head,
next: req.body.next,
nextId: req.body.nextId,
name: req.body.name,
required: req.body.required || false,
src: req.body.src,
Expand Down
4 changes: 2 additions & 2 deletions lib/scaffold.js
Expand Up @@ -115,11 +115,11 @@ exports.generate = function(parents, children, name, getDefault,
callback = callback || utils.noop;

crud.update(req, key, id, allowedFields, db,
function(err, project) {
function(err, object) {
if (err) {
callback(err);
} else {
callback(null, project);
callback(null, object);
}
});
};
Expand Down
24 changes: 14 additions & 10 deletions lib/utils.js
Expand Up @@ -15,22 +15,26 @@ exports.generateUniqueId = function(name, id) {
return name.toString().toLowerCase().replace(ALPHANUM_MATCH, '_') + id;
};

/* Generically map object to req.body
/* Generically map curObject to req.body. If a property exists in curObject,
* req.body, and allowedFields, curObject's value is updated to equal
* req.body's value. If a property exists in req.body and allowedFields, but
* not in curObject, it is added to curObject with req.body's value.
*
* Requires: web request, current object, allowed fields
* Returns: The updated object if it exists, else false
*/
exports.updateObject = function(req, currObject, allowedFields) {
if (typeof currObject !== 'object') {
currObject = JSON.parse(currObject);
exports.updateObject = function(req, curObject, allowedFields) {
if (typeof curObject !== 'object') {
curObject = JSON.parse(curObject);
}

if (currObject) {
var setFields = function(currObject, from, allowedFields) {
if (curObject) {
var setFields = function(curObject, from, allowedFields) {
var props = Object.getOwnPropertyNames(from);
var dest = currObject;
var dest = curObject;

props.forEach(function(name) {
if (name in dest && name in allowedFields) {
if (name in allowedFields) {
var destination = Object.getOwnPropertyDescriptor(from, name);

if (destination) {
Expand All @@ -39,10 +43,10 @@ exports.updateObject = function(req, currObject, allowedFields) {
}
});

return currObject;
return curObject;
};

return setFields(currObject, req.body, allowedFields);
return setFields(curObject, req.body, allowedFields);
}

return false;
Expand Down
5 changes: 5 additions & 0 deletions public/javascripts/.jshintrc
@@ -0,0 +1,5 @@
{
"node": true,
"strict": false,
"esnext": true
}

0 comments on commit 4cdf1a5

Please sign in to comment.