Changeset 29982


Ignore:
Timestamp:
2015-06-16T13:33:20+12:00 (6 years ago)
Author:
davidb
Message:

Changes made during Fieldays event. Background colour remember between reloads (in localStorage) until published; more sophisticated support for handling JSON data

Location:
other-projects/nz-flag-design/trunk/main-form
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • other-projects/nz-flag-design/trunk/main-form/choose-palette.html

    r29950 r29982  
    115115            if (typeof flagCanvasSettings !== 'undefined') {
    116116                  flagCanvasSettings.backgroundColor = colour.toHexString();
     117            if (window.localStorage) {                 
     118                console.log("*** storing bacgkground flag color = " +      flagCanvasSettings.backgroundColor);
     119             window.localStorage.setItem("flagBackgroundColor",flagCanvasSettings.backgroundColor);
     120            }
    117121            }
    118122            }
  • other-projects/nz-flag-design/trunk/main-form/enter-name.html

    r29973 r29982  
    1313    <!--
    1414     <script>
    15      
     15
    1616    if (jQuery.mobile) {
    1717    $(document).on("pagebeforeshow", "enter-name", function(event,data) {
     
    9191
    9292          <div style="padding-top: 20px; padding-left: 10px; padding-right: 10px">
    93         <input id="mySubmit" type="submit" value="Submit Flag Design" disabled="disabled" />
     93        <input id="mySubmit" type="submit" value="Submit Flag Design" disabled="disabled" >
    9494          </div>
     95
     96
     97          <div style="padding-top: 20px; padding-left: 10px; padding-right: 10px; font-size: 140%;">
     98          <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
     99          </dvi>
     100
    95101        </form>
    96102
     
    262268
    263269
    264               // The following supresses the "unsaved changes, are you sure" popup
    265         window.addEventListener('beforeunload', function(e) {
    266             return; });
     270/*
     271$('#publish-data').validate({
     272    rules: {
     273        myFlagName: {
     274            required: true
     275        },
     276        myName: {
     277            required: true
     278        },
     279        myEmail: {
     280            required: true
     281        },
     282        myDesc: {
     283            required: true
     284        }
     285
     286    },
     287    messages: {
     288        myFlagName: {
     289            required: "Please enter a name for your flag."
     290        },
     291        myName: {
     292            required: "Please enter your name."
     293        },
     294        myEmail: {
     295            required: "Please enter your email."
     296        },
     297        myDesc: {
     298            required: "Please describe your flag design."
     299        }
     300
     301    },
     302    errorPlacement: function (error, element) {
     303        error.appendTo(element.parent().prev());
     304    },
     305    submitHandler: function (form) {
     306        var pubName = $('#myFlagName').val();
     307        var pubNameNoQuotes = pubName.replace(/"/g,"");
     308    console.log("*** pubName stripped of quotes: " + pubNameNoQuotes);
     309
     310    $('#myFlagName').val(pubNameNoQuotes);
     311        return true;
     312
     313//        $(':mobile-pagecontainer').pagecontainer('change', '#success', {
     314//            reload: false
     315//        });
     316//        return false;
     317
     318
     319    }
     320});
     321*/
     322
     323/*
     324          $('#myFlagName').on('submit', function(e){
     325               //e.preventDefault();
     326               var pubName = $('#myFlagName').val();
     327           var pubNameNoQuotes = pubName.replace(/"/g,"");
     328           console.log("*** pubName stripped of quotes: " + pubNameNoQuotes);
     329
     330           $('#myFlagName').val(pubNameNoQuotes);
     331           this.submit();
     332          });
     333*/
     334
     335
     336              // The following (hopefully) supresses the "unsaved changes, are you sure" popup
     337          //window.addEventListener('beforeunload', function(e) {
     338          //        return; });
     339
    267340
    268341                                 
  • other-projects/nz-flag-design/trunk/main-form/iterative-design-jsp.html

    r29971 r29982  
    198198                    var canvasWidth = svgCanvas.getResolution().w;
    199199                    var canvasHeight = svgCanvas.getResolution().h;
     200
     201            if (window.localStorage) {                         
     202             var flagBackgroundColor = window.localStorage.getItem("flagBackgroundColor");
     203             console.log("**** falg background color = " + flagBackgroundColor);
     204             if (flagBackgroundColor != null) {
     205                 settings.backgroundColor = flagBackgroundColor;
     206               }
     207             }
    200208
    201209                    var userBackground = settings.backgroundColor;
  • other-projects/nz-flag-design/trunk/main-form/my-design.jsp

    r29961 r29982  
    2222    <script src="lib-slider/js/jquery.mobile-1.3.0.js"></script>
    2323
    24 
     24    <script>
     25     window.addEventListener("beforeunload", function (event) {
     26    console.log("beforeunload() called");
     27    //var design_frame = document.getElementById('design-2d-iframe')
     28        //var svgEditor = design_frame.contentWindow.svgEditor;
     29
     30    //var name = 'svgedit-' + svgEditor.curConfig.canvasName;
     31    var name = 'svgedit-' + "default";
     32
     33    if (window.localStorage) {
     34       console.log("Removing stored SVG picture");
     35       window.localStorage.removeItem(name);
     36       window.localStorage.removeItem("flagBackgroundColor");
     37    }
     38
     39        event.preventDefault();
     40    return;
     41     });
     42
     43    </script>
    2544
    2645  <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*,javax.xml.bind.DatatypeConverter,java.nio.file.*,org.json.*" %>
     
    134153
    135154     BufferedWriter bw = new BufferedWriter(new FileWriter(full_pub_json_file));
    136          bw.write("{ \"name\": \"" + name + "\", \"email\": \"" + email + "\", \"desc\": \"" + desc + "\"}");
     155
     156
     157     JSONObject obj = new JSONObject();
     158     obj.append("pubName",pub_name);
     159     obj.append("name",name);
     160     obj.append("email",email);
     161     obj.append("desc",desc);
     162
     163     obj.write(bw);
     164         // bw.write("{ \"pubName\": \"" + pub_name + "\", \"name\": \"" + name + "\", \"email\": \"" + email + "\", \"desc\": \"" + desc + "\"}");
    137165         bw.close();
     166
    138167       }
    139168       catch (Exception e) {
     
    203232
    204233       JSONObject obj = new JSONObject(everything);
    205        name  = obj.getString("name");
    206        email = obj.getString("email");
    207        desc  = obj.getString("desc");
    208      }
    209 
    210      
     234       try {
     235           name  = obj.getString("name");
     236       }
     237       catch (Exception e) {
     238           name  = obj.getJSONArray("name").getString(0);
     239       }
     240
     241       try {
     242           email = obj.getString("email");
     243       }
     244       catch (Exception e) {
     245           email = obj.getJSONArray("email").getString(0);
     246       }
     247
     248       try {
     249           desc  = obj.getString("desc");
     250       }
     251       catch (Exception e) {
     252           desc  = obj.getJSONArray("desc").getString(0);
     253       }
     254     }
     255
     256     // For use in Javascript
     257     pub_name = pub_name.replace("\"","\\\"");
     258     name  = name.replace("\"","\\\"");
     259     email = email.replace("\"","\\\"");
     260     desc  = desc.replace("\"","\\\"");     
    211261   %>
    212262
     
    224274
    225275  <body>
     276
     277  <%     
     278     //String action = request.getParameter("action");
     279     // only add FB like ability if visiting the item after it has been published
     280
     281     if (action == null) {
     282  %>
     283
    226284<div id="fb-root"></div>
    227285<script>(function(d, s, id) {
    228   var js, fjs = d.getElementsByTagName(s)[0];
    229   if (d.getElementById(id)) return;
    230   js = d.createElement(s); js.id = id;
    231   js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3&appId=538218162984944";
    232   fjs.parentNode.insertBefore(js, fjs);
     286
     287    var js, fjs = d.getElementsByTagName(s)[0];
     288    if (d.getElementById(id)) return;
     289    js = d.createElement(s); js.id = id;
     290    //js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3&appId=538218162984944";
     291    js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3&appId=1612166589021423";
     292
     293    fjs.parentNode.insertBefore(js, fjs);
     294
    233295}(document, 'script', 'facebook-jssdk'));</script>
     296
     297  <%
     298      }
     299  %>
    234300
    235301    <div data-role="page" id="innovation-story-01" class="demo-page">
     
    256322          <div style="display: inline-block; position: relative">
    257323            <div>
    258           <a id="myflag-svg" data-ajax="false" ><img id="myflag-png" height="200" style="border: none;"/></a>
     324          <a id="myflag-svg" data-ajax="false" ><img id="myflag-png" title="Click on the image to see a larger SVG (Scalable Vector Graphic) version" height="200" style="border: none;"/></a>
    259325            </div>
    260326
     
    274340<script type="text/javascript">
    275341
    276 var published_id = "<%= request.getParameter("pub-name") %>";
     342var published_id = "<%= pub_name %>";
    277343var name  = "<%= name %>";
    278344var email = "<%= email %>";
     
    281347document.write("  <div style=\"width: 500px; background: #181818; padding: 5px; margin: 10px;\">");
    282348document.write("    <p>Designer: " + name + "<p/>");
    283 document.write("    <p>Email: " + email + "<p/>");
     349//document.write("    <p>Email: " + email + "<p/>");
    284350document.write("    <p>Description: " + desc + "<p/>");
    285351document.write("  </div>");
     
    291357var base_url = location.protocol + '//' + location.host + location.pathname;
    292358
    293 a2a_config.linkurl = base_url + "?pub-name=" + published_id
     359a2a_config.linkurl = base_url + "?pub-name=" + published_id.replace(/ /g,"+");
    294360
    295361</script>
     
    326392
    327393    <center>
     394    <p style="font-size: 220%;">
     395      <i>
     396    Or else view other flags designed at Fieldays through
     397    <a target="_blank" href="http://www.greenstone.org/greenstone3/flag-library/collection/fieldays/page/about">
     398      this link
     399    </a>
     400     </i>
     401    </p>   
     402    </center>
     403
     404    <center>
    328405    <p style="font-size: 200%;">
    329406      <i>
Note: See TracChangeset for help on using the changeset viewer.