Skip to content

Commit

Permalink
Compiling the form and data together into a unified whole. Need to mo…
Browse files Browse the repository at this point in the history
…dify the data before sending though. The console is giving me the right output but the node app is sending the unmodified body. Maybe I should compile them on the server side instead.
  • Loading branch information
Flowdeeps committed Apr 4, 2017
1 parent 3d8e201 commit c3e9e52
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 19 deletions.
14 changes: 2 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,27 +308,17 @@ app.use(bodyParser.urlencoded({ extended: true }));
app.post('/update', function(req, res) {
res.setHeader('Content-Type', 'application/json');

//mimic a slow network connection

var meta = {"meta":{}};

var items = req.body;

res.send(JSON.stringify({
data: data
}));

fs.writeFile("test/tmp.txt", JSON.stringify(items), function( err ) {
fs.writeFile("test/output.json", JSON.stringify(data), function( err ) {
if (err) {
return console.log( err );
}
console.log("file was written");
console.log(data);
});

for (item in items) {
console.log(item, items[item]);
}

});

// Hot Reload the Preview
Expand Down
4 changes: 4 additions & 0 deletions assets/css/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ body {
z-index: 10;
}

textarea {
min-height: 150px;
}

legend,
button#save
{
Expand Down
75 changes: 68 additions & 7 deletions assets/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
save.addEventListener('click', function (event){
event.preventDefault();
event.stopPropagation();
saveData();
saveData(meta, items);
});
}
};
Expand Down Expand Up @@ -204,7 +204,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
}
});
} else if ($(this).hasClass('js-PosterImage')) {
$(this).find('input, textarea').each(function () {
$(this).find('input').each(function () {
var name = this.name;
for (key in item["image"]) {
if (name == key) {
Expand Down Expand Up @@ -278,7 +278,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
}
});
}
})
});
}
}
}
Expand Down Expand Up @@ -350,6 +350,51 @@ document.addEventListener("DOMContentLoaded", function (event) {
}
}
}

var videoFullpageEl = $('.js-VideoFullpage')[0];

if (typeof videoFullpageEl != "undefined") {
for (var i = 0; i < Object.keys(items).length; i++) {
var item = items[i];
if (typeof item["videofullpage"] != "undefined") {
if (window.id == item["videofullpage"]["id"]) {
item = item["videofullpage"];
// console.log(item); // uncomment this to see the item
$('fieldset').each( function () {
if ($(this).hasClass('js-Format')) {
// it's the checkbox so you need to do some stuff
} else if ($(this).hasClass('js-VideoSources')) {
$(this).find('input, textarea').each(function () {
var name = this.name;
for (key in item["video"]) {
if (name == key) {
$(this).val(item["video"][key]);
}
}
});
} else if ($(this).hasClass('js-PosterImage')) {
$(this).find('input').each(function () {
var name = this.name;
for (key in item["image"]) {
if (name == key) {
$(this).val(item["image"][key]);
}
}
});
} else {
$(this).find('input, textarea').each( function () {
var name = $(this).attr('name');
for (key in item) {
$(this).val(item[name]);
}
});
}
});
}
}
}
}

};

function addAssets() {
Expand Down Expand Up @@ -464,7 +509,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
});
}

function saveData() {
function saveData(meta, items) {

var type = window.type,
postData = {},
Expand All @@ -473,6 +518,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
slides = [],
slideImage = [],
posterImage = {};
postData["items"] = [];
var i = 0;
postData[type] = {};
if (window.type != "meta") {
Expand All @@ -496,7 +542,6 @@ document.addEventListener("DOMContentLoaded", function (event) {
snippetImage = [];
} else if ($(this).hasClass('js-Slides')) {
$(this).find('input').each( function () {
console.log($(this)[0]);
slideImage.push(this.dataset.name + ": " + this.value);
});
slides.push(slideImage);
Expand Down Expand Up @@ -571,19 +616,35 @@ document.addEventListener("DOMContentLoaded", function (event) {
}
}

// console.log(postData);
function modifyData(postData) {
if (typeof postData["meta"] != "undefined") {
postData["items"] = items;
} else {
postData["meta"] = meta;
for (item in items) {
for (thisItem in items[item]) {
if (window.id == items[item][thisItem]) {
postData["items"].push(postData[type]);
} else {
postData["items"].push(items[item]);
}
}
}
}
}

$.ajax({
url: '/update',
type: 'POST',
beforeSend: modifyData(postData),
data: postData,
success: postSuccessHandler(postData)
});

};

function postSuccessHandler(postData) {
console.log("Posted data: ", postData);
console.log(postData);
}

});

0 comments on commit c3e9e52

Please sign in to comment.