|
@@ -1393,21 +1393,53 @@ $(document).ready(function() {
|
|
|
Serialize Form to JSON
|
|
|
================================================= */
|
|
|
|
|
|
- // ååå 1
|
|
|
+ // ååå
|
|
|
+
|
|
|
+ /*
|
|
|
+ <li class="added_item">
|
|
|
+ <div class="expandable" name="' + key + '">' + itm + '</div>
|
|
|
+ <br />
|
|
|
+ <span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span>
|
|
|
+ </li>
|
|
|
+ */
|
|
|
|
|
|
$.fn.serializeObject = function() {
|
|
|
+ // Declarations
|
|
|
var o = {};
|
|
|
var a = this.serializeArray();
|
|
|
+ var addedIdeaLists = $(".card ul");
|
|
|
+
|
|
|
$.each(a, function() {
|
|
|
if (o[this.name]) {
|
|
|
if (!o[this.name].push) {
|
|
|
o[this.name] = [o[this.name]];
|
|
|
}
|
|
|
o[this.name].push(this.value || '');
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
o[this.name] = this.value || '';
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ // Add added ideas to the JSON object manually
|
|
|
+ $.each(addedIdeaLists, function() {
|
|
|
+ var field = $(this).attr("id");
|
|
|
+ var addedItemDivs = $(this).find($(".expandable"));
|
|
|
+ var addedItemArray = [];
|
|
|
+ var numberOfAddedItem = addedItemDivs.length;
|
|
|
+
|
|
|
+ if(numberOfAddedItem > 1) {
|
|
|
+ for(var i = 0; i < numberOfAddedItem; i++) {
|
|
|
+ addedItemArray[i] = addedItemDivs[i].textContent;
|
|
|
+ }
|
|
|
+
|
|
|
+ o[field + "[]"] = addedItemArray;
|
|
|
+ }
|
|
|
+ else if(numberOfAddedItem === 1) {
|
|
|
+ o[field + "[]"] = addedItemDivs[0].textContent;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
return o;
|
|
|
};
|
|
|
|
|
@@ -1422,7 +1454,7 @@ $(document).ready(function() {
|
|
|
if (twoDigitDate.length == 1) twoDigitDate = "0" + twoDigitDate;
|
|
|
|
|
|
var currentDate = fullDate.getFullYear() + "-" + twoDigitMonth + "-" + twoDigitDate;
|
|
|
- // set the currebt date in the date input field
|
|
|
+ // Set the current date in the date input field
|
|
|
$('.proj_date').val(currentDate);
|
|
|
|
|
|
/* ================================================
|
|
@@ -1445,14 +1477,12 @@ $(document).ready(function() {
|
|
|
otherwise load an empty canvas
|
|
|
================================================= */
|
|
|
|
|
|
- // ååå 2
|
|
|
-
|
|
|
// if a canvas is chosen by the user to be loaded
|
|
|
if (current_canvas_id !== '') {
|
|
|
var url = 'json/' + current_canvas_id + '.json';
|
|
|
// var url= 'json/test_canvas.json';
|
|
|
|
|
|
- // get the saved ISON object in the sendJSON.text file
|
|
|
+ // get the saved JSON object in the sendJSON.text file
|
|
|
$.getJSON(url, function(returnedObj) {
|
|
|
|
|
|
// Display the json data in the html
|
|
@@ -1462,14 +1492,11 @@ $(document).ready(function() {
|
|
|
$.each(returnedObj, function(key, value) {
|
|
|
// project name and tem field
|
|
|
if (key === 'field_00[]') {
|
|
|
-
|
|
|
$('.form-header').find('input.proj_title').val(value[
|
|
|
0]);
|
|
|
$('.form-header').find('input.proj_date').val(value[1]);
|
|
|
-
|
|
|
}
|
|
|
else if (key !== 'new_item') {
|
|
|
-
|
|
|
if ($.type(value) === "array") {
|
|
|
$.each(value, function(i, itm) {
|
|
|
|
|
@@ -1962,9 +1989,7 @@ $(document).ready(function() {
|
|
|
as a registered user
|
|
|
----------------------------------------------- */
|
|
|
|
|
|
- // ååå 3
|
|
|
-
|
|
|
- // php variables are retieved in the header of the canvas index.php as js variables -->
|
|
|
+ // php variables are retieved in the header of the canvas index.php as js variables -->
|
|
|
var name_save_canvas = $('.form-header').find('.proj_title').val();
|
|
|
var date_save_canvas = $('.form-header').find('.proj_date').val();
|
|
|
var save_canvas_obj = {
|
|
@@ -2005,16 +2030,15 @@ $(document).ready(function() {
|
|
|
and save it on the server
|
|
|
----------------------------------------------- */
|
|
|
|
|
|
- // ååå 4
|
|
|
-
|
|
|
// $('#result').text(JSON.stringify($('.canvas-form').serializeObject()));
|
|
|
|
|
|
// Make the JSON object into a JSON string
|
|
|
+ // var JSONstrObj = JSON.stringify($('.canvas-form').serializeObject());
|
|
|
var JSONstrObj = JSON.stringify($('.canvas-form').serializeObject());
|
|
|
var url = "php/canvas.php";
|
|
|
- /* Post the JSON stringified object to the php file
|
|
|
- (the php script will save it in a .json file )*/
|
|
|
- // also, send the canvas_id and use it for naming the file
|
|
|
+
|
|
|
+ // Post the JSON stringified object to the php file (the php script will save it in a .json file)
|
|
|
+ // Also, send the canvas_id and use it for naming the file
|
|
|
$.post(url, {
|
|
|
JSONstrObj: JSONstrObj,
|
|
|
canvas_id: canvas_id
|