Skip to content

Commit

Permalink
Note to self: If you're going to check fieldset classes to determine …
Browse files Browse the repository at this point in the history
…information please ensure that you don't nest fieldsets and iterate through the forms again…
  • Loading branch information
Flowdeeps committed Apr 1, 2017
1 parent 02162b9 commit 59fc821
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
28 changes: 11 additions & 17 deletions assets/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
var navItem = this,
link = this.href;
window.id = this.dataset.id;
window.type = this.dataset.type;
$(bodyElement).load(link, function (response, status, xhr) {
if ( status !== "error" ) {
loadData();
Expand Down Expand Up @@ -255,13 +256,13 @@ document.addEventListener("DOMContentLoaded", function (event) {

function saveData() {

var postData = {},
var type = window.type,
postData = {},
snippets = [],
snippetImage = [];

var i = 0;
postData["postData"] = "postData";
postData["id"] = window.id;
postData[type] = {};
postData[type]["id"] = window.id;
$('fieldset').each( function () {
if ($(this).hasClass('js-SnippetText')) {
$(this).find('input, textarea').each( function () {
Expand All @@ -281,40 +282,34 @@ document.addEventListener("DOMContentLoaded", function (event) {
} else {
$(this).find('input, textarea').each( function () {
if (this.type == "checkbox") {
postData[this.dataset.name] = this.checked;
postData[type][this.dataset.name] = this.checked;
}
if ((this.type == "text") || (this.type == "textarea")) {
postData[this.dataset.name] = this.value;
postData[type][this.dataset.name] = this.value;
}
});
}
});

if (snippetImage.length > 0) {
for (image in snippetImage) {
console.log(snippetImage[image]);
}
}

if (snippets.length > 0) {
postData["snippets"] = [];
postData[type]["snippets"] = [];
for (snippet in snippets) {
if (typeof snippets[snippet] == "string") {
postData["snippets"].push({"text": snippets[snippet]});
postData[type]["snippets"].push({"text": snippets[snippet]});
} else {
var imageAttr = {};
for (var i = 0; i < snippets[snippet].length; i++) {
var key = snippets[snippet][i].split(":")[0],
value = snippets[snippet][i].split(":")[1];
imageAttr[key] = value;
}
postData["snippets"].push(imageAttr);
postData[type]["snippets"].push(imageAttr);
}
}
}

// console.log(postData);

$.ajax({
url: '/update',
type: 'POST',
Expand All @@ -324,7 +319,6 @@ document.addEventListener("DOMContentLoaded", function (event) {

};


function postSuccessHandler(postData) {
console.log("Posted data: ", postData);
}
Expand Down
7 changes: 2 additions & 5 deletions views/editor/pages/textcentred.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<form class="form-horizontal js-TextCentred" data-id="">
<fieldset>
<legend>Text Centred</legend>

<fieldset>
<div class="form-group">
<div class="togglebutton">
<label for="light">
Expand All @@ -17,8 +17,8 @@
{{> subtitle}}

{{> intro}}
</fieldset>

<fieldset>
<legend>Content Blocks</legend>
<ul class="js-ContentBlockSelector">
<li>
Expand All @@ -30,9 +30,6 @@
</ul>
<div class="js-ContentDynamic"></div>

</fieldset>

{{> formcontrols}}

</fieldset>
</form>

0 comments on commit 59fc821

Please sign in to comment.