contrib/opportunity: store local participant's name in a cookie
[nit.git] / contrib / opportunity / src / templates / meetup.nit
index 07a5f66..043c86b 100644 (file)
@@ -13,7 +13,7 @@
 # limitations under the License
 
 # Shows a meetup and allows to modify its participants
-module meetup
+module meetup is i18n
 
 import opportunity_model
 import boilerplate
@@ -211,7 +211,11 @@ class OpportunityMeetupPage
                                .fail(function(data){
                                        //TODO: Notify of failure
                                });
+
+                       // Remember the participant's name client-side
+                       set_cookie("opportunity_participant_name", pname);
                }
+
                function remove_people(ele){
                        var arr = ele.id.split("_")
                        var pid = arr[1]
@@ -226,19 +230,20 @@ class OpportunityMeetupPage
                                }
                        });
                }
+
                // ID of line currently open for modification
                var in_modification_id = null;
                function modify_people(ele, id){
                        if (in_modification_id != null) {
                                // reset to normal values
-                               $('#modify_'+in_modification_id).text("Modify or delete");
+                               $('#modify_'+in_modification_id).text("{{{"Modify or delete"}}}");
                                $('#modify_'+in_modification_id).attr("class", "btn btn-xs btn-warning");
                                $('#line_'+in_modification_id).css("background-color", "");
                                $('#delete_'+in_modification_id).css("display", "none");
                        }
                        if (in_modification_id != id) {
                                // activate modifiable mode
-                               $('#modify_'+id).text("Done");
+                               $('#modify_'+id).text("{{{"Done"}}}");
                                $('#modify_'+id).attr("class", "btn btn-xs btn-success");
                                $('#line_'+id).css("background-color", "LightYellow");
                                $('#delete_'+id).show();
@@ -248,6 +253,30 @@ class OpportunityMeetupPage
                                in_modification_id = null;
                        }
                }
+
+               function get_cookie(cookie_name) {
+                   var name = cookie_name + "=";
+                       var ca = document.cookie.split(';');
+                       for(var i = 0; i < ca.length; i ++) {
+                               var c = ca[i];
+                               while (c.charAt(0) == ' ') c = c.substring(1);
+                               if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
+                       }
+                       return "";
+               }
+
+               function set_cookie(cookie_name, value) {
+                   var date = new Date();
+                       date.setTime(date.getTime() + (365*24*60*60*1000));
+                       var expires = "expires="+date.toUTCString();
+                       document.cookie = cookie_name + "=" + value + "; " + expires;
+               }
+
+               // Retrieve the last client-side participant's name
+               window.onload = function () {
+                       var name_field = document.getElementById("new_name");
+                       name_field.value = get_cookie("opportunity_participant_name");
+               }
                """
        end
 
@@ -274,16 +303,16 @@ redef class Meetup
        <center><h1>{{{name}}}</h1></center>
 """
                if not date.is_empty then t.add """
-       <center><h4>When: {{{date}}}</h4></center>"""
+       <center><h4>{{{"When:"}}} {{{date}}}</h4></center>"""
 
                if not place.is_empty then t.add """
-       <center><h4>Where: {{{place}}}</h4></center>"""
+       <center><h4>{{{"Where:"}}} {{{place}}}</h4></center>"""
 
                t.add """
 </div>
 <table class="table">
 """
-               t.add "<th>Participant name</th>"
+               t.add "<th>{"Participant name"}</th>"
                for i in answers(db) do
                        t.add "<th class=\"text-center\">"
                        t.add i.to_s
@@ -333,19 +362,19 @@ redef class Meetup
                                end
                                t.add "</center></td>"
                        end
-                       t.add """<td class="opportunity-action"><center><button class="btn btn-xs btn-warning" type="button" onclick="modify_people(this, {{{i.id}}})" id="modify_{{{i.id}}}">Modify or delete</button>&nbsp;"""
-                       t.add """<button class="btn btn-xs btn-danger" type="button" onclick="remove_people(this)" id="delete_{{{i.id}}}" style="display: none;">Delete</button></center></td>"""
+                       t.add """<td class="opportunity-action"><center><button class="btn btn-xs btn-warning" type="button" onclick="modify_people(this, {{{i.id}}})" id="modify_{{{i.id}}}">{{{"Modify or delete"}}}</button>&nbsp;"""
+                       t.add """<button class="btn btn-xs btn-danger" type="button" onclick="remove_people(this)" id="delete_{{{i.id}}}" style="display: none;">{{{"Delete"}}}</button></center></td>"""
                        t.add "</tr>"
                end
                t.add """
 <tr id="newrow" style="background-color: LightYellow">
-       <td><input id="new_name" type="text" placeholder="Your name" class="input-large"></td>
+       <td><input id="new_name" type="text" placeholder="{{{"Your name"}}}" class="input-large"></td>
                """
                for i in answers(db) do
                        t.add "<td class=\"answer\" id=\"newans_{i.id}\" onclick=\"change_temp_answer(this)\" style=\"color:red;\"><center>✘</center></td>"
                end
                t.add """
-       <td><center><span id="add_{{{id}}}" onclick="add_part(this)" style="color:green;" class="action"><button class="btn btn-xs btn-success" type="button">Done</button></span></center></td>"""
+       <td><center><span id="add_{{{id}}}" onclick="add_part(this)" style="color:green;" class="action"><button class="btn btn-xs btn-success" type="button">{{{"Done"}}}</button></span></center></td>"""
                t.add "</tr>"
                # Compute score for each answer
                var scores = new HashMap[Int, Int]