Unknown 7 anos atrás
pai
commit
167851b6c8

+ 4 - 0
canvas/css/canvas.css

@@ -1040,6 +1040,10 @@ a.login-to-save {
 
 /* The save canvas PHP under the save/export buttons */
 
+p#save-canvas {
+    margin-bottom: 16px;
+}
+
 .save-canvas-feedback p {
     text-align: center;
     color: #15af97;

+ 41 - 17
canvas/js/canvas.js

@@ -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

+ 1 - 0
canvas/json/2x5zfZgdWu.json

@@ -0,0 +1 @@
+{"canvas_id":"2x5zfZgdWu","username":"a.burburan@gmail.com","field_00[]":["Test",""],"new_item":"","share-canvas-email":"","add-collaborator":"Please enter an email address...","field_01[]":["ia1","ia2","ia3"],"field_03[]":"b1","field_04[]":"r1","field_06[]":"gc1","field_10[]":["ui1","ui2"]}

+ 22 - 22
canvas/php/canvas.php

@@ -1,24 +1,24 @@
 <?php
-//for the ajax post call
-echo 'JSON stringified Object: '.$_POST['JSONstrObj'].' was sent to the php file\n';
-//for the ajax post call in stringified object data form
-$post_data = $_POST['JSONstrObj'];
-$canvas_id_data = $_POST['canvas_id'];
-
-$filename ='../json/'.$canvas_id_data.'.json';
-$handle = fopen($filename, "w");
-
-if (empty($post_data)) {
-    echo 'Hmm... I did NOT get any data posted by AJAX.';
-}
-if (!empty($post_data)) {
-  echo 'Awesome! Got the JSON info :)';
-    //$dir = 'YOUR-SERVER-DIRECTORY/files';
-    //$file = uniqid().getmypid();
-    //$filename = $dir.$file.'.txt';
-     // Write to file
-    fwrite($handle, $post_data);
-}
+    //for the ajax post call
+    echo 'JSON stringified Object: '.$_POST['JSONstrObj'].' was sent to the php file\n';
+    //for the ajax post call in stringified object data form
+    $post_data = $_POST['JSONstrObj'];
+    $canvas_id_data = $_POST['canvas_id'];
+    
+    $filename = '../json/'.$canvas_id_data.'.json';
+    $handle = fopen($filename, "w");
+    
+    if (empty($post_data)) {
+        echo 'Hmm... I did NOT get any data posted by AJAX.';
+    }
+    if (!empty($post_data)) {
+        echo 'Awesome! Got the JSON info :)';
+        //$dir = 'YOUR-SERVER-DIRECTORY/files';
+        //$file = uniqid().getmypid();
+        //$filename = $dir.$file.'.txt';
+        // Write to file
+        fwrite($handle, $post_data);
+    }
     // Close the file
-     fclose($handle);
-?>
+    fclose($handle);
+?>

+ 0 - 1
canvas/php/save-canvas.php

@@ -18,7 +18,6 @@
             // Canvas already exists. Return canvas_id to overwrite JSON file.
             echo $_SESSION['canvas_id'];
         }
-        
         else { // New canvas in the database
             // Retrieve user credentials
             $email = $params['email_save_canvas'];