[Toss-devel-svn] SF.net SVN: toss:[1497] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
|
From: <luk...@us...> - 2011-06-28 00:48:46
|
Revision: 1497
http://toss.svn.sourceforge.net/toss/?rev=1497&view=rev
Author: lukaszkaiser
Date: 2011-06-28 00:48:40 +0000 (Tue, 28 Jun 2011)
Log Message:
-----------
Tabs and opponents searching in profile.
Modified Paths:
--------------
trunk/Toss/Server/ReqHandler.ml
trunk/Toss/WebClient/Connect.js
trunk/Toss/WebClient/Login.js
trunk/Toss/WebClient/Main.js
trunk/Toss/WebClient/Play.js
trunk/Toss/WebClient/Style.css
trunk/Toss/WebClient/index.html
trunk/Toss/WebClient/profile.html
Modified: trunk/Toss/Server/ReqHandler.ml
===================================================================
--- trunk/Toss/Server/ReqHandler.ml 2011-06-25 14:13:14 UTC (rev 1496)
+++ trunk/Toss/Server/ReqHandler.ml 2011-06-28 00:48:40 UTC (rev 1497)
@@ -607,8 +607,33 @@
"\nYou can change it after you login on tPlay.\n" ^
"\nThank You!\n\ntPlay Team\n") in
ignore (send_mail email "New password on tPlay.org" mailtxt);
+ print_endline "Subject: New password on tPlay.org";
print_endline mailtxt;
"Your password has been reset and sent to " ^ email ^ "." in
+ let search_users txt =
+ let l, txtlen = "like \"%" ^ txt ^ "%\"", String.length txt in
+ let query_s =
+ Printf.sprintf "name %s or surname %s or id %s or email %s" l l l l in
+ let all = List.map (fun a -> a.(0)) (dbtable query_s "users") in
+ lstr (List.filter (fun s -> String.length s < 2*txtlen + 1) all) in
+ let invite uid email =
+ let usrs = dbtable ("email='" ^ email ^ "'") "users" in
+ if List.length usrs > 0 then
+ Printf.sprintf "Sorry, %s is already a registered email." email
+ else
+ let (uname, usurname, umail) = get_user_name_surname_mail uid in
+ let mailtxt =
+ ("\nYour Friend invites you to play on tPlay.org\n\n" ^
+ "\nYour friend " ^ uname ^ " " ^ usurname ^ " (" ^ umail ^ ") " ^
+ "invites you to join a game on tPlay.org.\n" ^
+ "To this end, please register on: www.tplay.org/register.html\n" ^
+ "\nWe wish you a good game!\n\ntPlay Team\n") in
+ let subj =
+ Printf.sprintf "Invitation to tPlay.org from %s %s" uname usurname in
+ ignore (send_mail email subj mailtxt);
+ print_endline ("Subject: " ^ subj);
+ print_endline mailtxt;
+ "Invitation email has been sent to " ^ email ^ "." in
let (tcmd, data) = split_two "#" msg in
let resp, new_cookies = match tcmd with
| "USERNAME" ->
@@ -634,6 +659,8 @@
let c =
[(tID ^ "username", "a", None); (tID ^ "passphrase", "a", None)] in
("User logged out: " ^ (verif_uid ()), c)
+ | "SEARCHUSR" ->
+ search_users data, []
| "ADDOPP" ->
add_opponent (verif_uid ()) data, []
| "GET_NAME" ->
@@ -645,6 +672,9 @@
| "GET_MAIL" ->
if verif_uid()="" then "You must login first to get email data.", [] else
let (_, _, mail) = get_user_name_surname_mail data in mail, []
+ | "INVITE" ->
+ let uid = verif_uid () in
+ if uid = "" then "Error: please Log In again", [] else invite uid data, []
| "FORGOTPWD" ->
forgotpwd data, []
| "CHANGEPWD" ->
Modified: trunk/Toss/WebClient/Connect.js
===================================================================
--- trunk/Toss/WebClient/Connect.js 2011-06-25 14:13:14 UTC (rev 1496)
+++ trunk/Toss/WebClient/Connect.js 2011-06-28 00:48:40 UTC (rev 1497)
@@ -122,7 +122,7 @@
}
this.friends = function () { return (srv ("LIST_FRIENDS", "user")); }
- this.allopnts = function () { return (srv ("LIST_FRIENDS", "**")); }
+ this.search_users = function (txt) { return (srv ("SEARCHUSR", txt)); }
this.plays = function () { return (srv("USERPLAYS", "user")); }
this.username = function () { return (srv("USERNAME", "user")); }
this.addopp = function (opp) { return (srv("ADDOPP", opp)); }
@@ -138,6 +138,7 @@
this.register = function (data, cpwd) {
return (srv ("REGISTER", data + "$" + cpwd));
}
+ this.invite = function (mail) { return (srv("INVITE", mail)); }
this.forgotpwd = function (mail) { return (srv("FORGOTPWD", mail)); }
this.change_pwd = function (un, pwd) {
var resp = srv("CHANGEPWD", pwd);
Modified: trunk/Toss/WebClient/Login.js
===================================================================
--- trunk/Toss/WebClient/Login.js 2011-06-25 14:13:14 UTC (rev 1496)
+++ trunk/Toss/WebClient/Login.js 2011-06-28 00:48:40 UTC (rev 1497)
@@ -31,7 +31,8 @@
list_plays_string ("Pawn-Whopping", udata[8]);
list_plays_string ("Tic-Tac-Toe", udata[9]);
/* list_plays_string ("Concurrent-Tic-Tac-Toe", udata[10]); */
- get_opponents ();
+ var lst = CONN.friends ();
+ FRIENDS = parse_list (',', lst);
}
// Clear view
@@ -86,13 +87,54 @@
}
}
-// Html of the list item for adding new opponents.
-function add_opponent_item_html (uname) {
- var onclick = 'onclick="add_opponent (' + "'" + uname + "'" + ')"';
- var bt = '<button class="bt" ' + onclick + ">Add</button>"
- return (bt + " " + disp_name(uname) + " (" + uname + ")")
+// Find opponents given (email or name or surname or username).
+function find_opnts () {
+ var txt = document.getElementById('findopnt').value;
+ if (txt.length < 2) {
+ alert ("Emails and names have at least 2 letters." + CORRMSG);
+ return;
+ }
+ if (txt.indexOf(" ") > 0) {
+ alert ("Emails and names do not contain spaces." + CORRMSG);
+ return;
+ }
+ // Get the list of found users.
+ var lst = CONN.search_users (txt);
+ var users = parse_list (',', lst);
+
+ // Offer to email an invitation if no user was found.
+ document.getElementById("invite").style.display = "block";
+
+ // Helper function: html of the list item for adding new opponents.
+ var add_opponent_item_html = function (uname) {
+ var onclick = 'onclick="add_opponent (' + "'" + uname + "'" + ')"';
+ var bt = '<button class="bt" ' + onclick + ">Add</button>"
+ return (bt + " " + disp_name(uname) + " (" + uname + ")")
+ }
+
+ // Print out the found list.
+ var u = document.getElementById("add-opponents-list");
+ while (u.childNodes.length > 0) { u.removeChild (u.firstChild); }
+ for (var i = 0; i < users.length; i++) {
+ if (users[i] != UNAME && FRIENDS.indexOf(users[i]) == -1) {
+ var li = document.createElement('li');
+ li.innerHTML = add_opponent_item_html (users[i]);
+ u.appendChild (li);
+ }
+ }
}
+// Send invitation email to a new user.
+function invite () {
+ var email = document.getElementById('findopnt').value;
+ if (email.indexOf("@") < 1 || email.indexOf(".") < 1) {
+ alert ("Please provide a valid email address in the search field.");
+ return;
+ }
+ alert (CONN.invite (email));
+ window.location.reload();
+}
+
// Onload handler for the profile page
function startup_profile () {
var un = CONN.username ();
@@ -108,23 +150,14 @@
document.getElementById('name').value = CONN.name (un);
document.getElementById('surname').value = CONN.surname (un);
document.getElementById('email').value = CONN.email (un);
- get_opponents ();
+ var lst = CONN.friends ();
+ FRIENDS = parse_list (',', lst);
var o = document.getElementById("opponents-list");
for (var i = 0; i < FRIENDS.length; i++) {
var li = document.createElement('li');
li.innerHTML = disp_name(FRIENDS[i]) + " (" + FRIENDS[i] + ")";
o.appendChild (li);
}
- var lst = CONN.allopnts ();
- var users = parse_list (',', lst);
- var u = document.getElementById("users-list");
- for (var i = 0; i < users.length; i++) {
- if (users[i] != un && FRIENDS.indexOf(users[i]) == -1) {
- var li = document.createElement('li');
- li.innerHTML = add_opponent_item_html (users[i]);
- u.appendChild (li);
- }
- }
};
}
@@ -149,19 +182,15 @@
// Logout
function logout () {
- clear_view ();
- resp = CONN.logout ();
+ //clear_view ();
+ var resp = CONN.logout ();
+ window.location.reload ();
return;
}
function logout_profile () {
- document.getElementById("loginform").style.display = "inline";
- document.getElementById("topright-register").style.display = "inline";
- document.getElementById("topright").style.display = "none";
- document.getElementById("topuser").innerHTML = "";
- document.getElementById("main-profile").style.display = "none";
- document.getElementById("welcome").style.display = "block";
- resp = CONN.logout ();
+ var resp = CONN.logout ();
+ window.location.reload ();
return;
}
Modified: trunk/Toss/WebClient/Main.js
===================================================================
--- trunk/Toss/WebClient/Main.js 2011-06-25 14:13:14 UTC (rev 1496)
+++ trunk/Toss/WebClient/Main.js 2011-06-28 00:48:40 UTC (rev 1497)
@@ -363,11 +363,6 @@
//document.getElementById ("plays-list-" + GAME_NAME).appendChild (li);
}
-function get_opponents () {
- var lst = CONN.friends ();
- FRIENDS = parse_list (',', lst);
-}
-
function play_anew (me_starts) {
document.getElementById ('payoffs').innerHTML = "Not Finished Yet";
document.getElementById ('payoffs').style.display = "none";
Modified: trunk/Toss/WebClient/Play.js
===================================================================
--- trunk/Toss/WebClient/Play.js 2011-06-25 14:13:14 UTC (rev 1496)
+++ trunk/Toss/WebClient/Play.js 2011-06-28 00:48:40 UTC (rev 1497)
@@ -55,6 +55,7 @@
PlayDISP.set_cur_move ("", "");
PlayDISP.show_payoff (this);
this.cur_state.draw_model (this.game);
+ document.getElementById("speedtab").style.display = "inline";
}
Play.prototype.redraw = play_redraw;
Modified: trunk/Toss/WebClient/Style.css
===================================================================
--- trunk/Toss/WebClient/Style.css 2011-06-25 14:13:14 UTC (rev 1496)
+++ trunk/Toss/WebClient/Style.css 2011-06-28 00:48:40 UTC (rev 1497)
@@ -220,34 +220,42 @@
#speed {
position: relative;
- top: -2px;
+ top: 0px;
font-weight: bold;
font-family: Verdana, 'TeXGyreHerosRegular', sans;
- color: #400827;
- background-color: #fff1d4;
+ color: #fff1d4;
+ background-color: #777777;
border-color: #fff1d4;
border-radius: 4px;
-moz-border-radius: 4px;
- border-width: 1px;
+ border-width: 0px;
}
.speed_val {
- color: #400827;
- background-color: #fff1d4;
- border-color: #400827;
+ color: #fff1d4;
+ font-weight: bold;
+ background-color: #666666;
+ border-width: 0px;
}
-.forminput {
+.forminput, .hiddenforminput {
border-color: #fff1d4;
border-radius: 4px;
-moz-border-radius: 4px;
border-width: 2px;
position: relative;
top: 2px;
+ width: 12em;
}
-.list_result
-{
+.hiddenforminput {
+ color: #fff1d4;
+ background-color: #fff1d4;
+ border: 0px;
+ margin: 4px;
+}
+
+.list_result {
font-size: 0.9em
}
@@ -284,16 +292,11 @@
}
#logoutbt {
- position: relative;
- top: -0.1em;
font-family: Verdana, 'TeXGyreHerosRegular', sans;
font-size: 1em;
font-weight: bold;
color: #fff1d4;
- background-color: #400827;
- border-color: #fff1d4;
- border-radius: 4px;
- -moz-border-radius: 4px;
+ background-color: #260314;
border-width: 0px;
}
@@ -376,7 +379,7 @@
#topright {
position: absolute;
- top: 0.7em;
+ top: 0.5em;
right: 1em;
margin-right: 0em;
display: none;
@@ -389,6 +392,19 @@
margin-right: 0em;
}
+.toprighttab {
+ position: relative;
+ top: 0.5em;
+ background-color: #260314;
+ border-color: #fff1d4;
+ border-style: solid;
+ border-width: 2px 2px 0px 2px;
+ border-radius: 6px 6px 0px 0px;
+ padding-top: 0.15em;
+ padding-bottom: 0.3em;
+ -moz-border-radius: 6px 6px 0px 0px;
+}
+
#bottom {
position: absolute;
bottom: 0px;
@@ -530,11 +546,43 @@
}
#main-profile {
+ display: none;
position: relative;
left: 1em;
top: 3em;
+ margin-bottom: 4em;
+ width: 100%;
}
+.separator-div {
+ width: 100%;
+ padding: 0px;
+ margin-left: -1em;
+ margin-top: 1em;
+ border-top: 1px solid #260314;
+
+}
+
+.positioning-div {
+ position: relative;
+ left: 0px;
+ right: 0px;
+ padding: 0px;
+ margin: 0px;
+}
+
+.profile-right {
+ position: absolute;
+ top: -1.2em;
+ left: 26em; /* 50%; */
+}
+
+#invite {
+ display: none;
+ position: relative;
+ top: -1em;
+}
+
.welcome-list {
list-style: square;
padding-left: 1.5em;
@@ -544,9 +592,9 @@
margin-top: 0.5em;
}
-#users-list {
+#add-opponents-list {
list-style: none;
- padding-left: 1.5em;
+ padding-left: 0em;
margin-top: 0.5em;
padding-bottom: 1em;
}
@@ -565,7 +613,7 @@
background-color: #400827;
font-weight: bold;
padding: 1em;
- border: 1px solid #260314;
+ border: 1px solid #260314;
z-index: 10;
}
Modified: trunk/Toss/WebClient/index.html
===================================================================
--- trunk/Toss/WebClient/index.html 2011-06-25 14:13:14 UTC (rev 1496)
+++ trunk/Toss/WebClient/index.html 2011-06-28 00:48:40 UTC (rev 1497)
@@ -55,18 +55,28 @@
</form>
</div>
<span id="topright">
- Speed: <select id="speed">
- <option class="speed_val" value="1">1s</option>
- <option class="speed_val" value="2">2s</option>
- <option class="speed_val" value="3">3s</option>
- <option class="speed_val" value="4">4s</option>
- <option class="speed_val" value="5">5s</option>
- <option class="speed_val" value="10">10s</option>
- <option class="speed_val" value="15">15s</option>
- <option class="speed_val" value="30">30s</option>
- <option class="speed_val" value="60">60s</option>
- </select>
- <button id="logoutbt" onclick="logout()">Logout</button>
+ <span class="toprighttab">
+ <a href="index.html">Games</a>
+ </span>
+ <span class="toprighttab">
+ <a href="profile.html">Profile</a>
+ </span>
+ <span class="toprighttab">
+ <button id="logoutbt" onclick="logout()">Logout</button>
+ </span>
+ <span class="toprighttab" id="speedtab" style="display: none;">
+ Speed: <select id="speed">
+ <option class="speed_val" value="1">1s</option>
+ <option class="speed_val" value="2">2s</option>
+ <option class="speed_val" value="3">3s</option>
+ <option class="speed_val" value="4">4s</option>
+ <option class="speed_val" value="5">5s</option>
+ <option class="speed_val" value="10">10s</option>
+ <option class="speed_val" value="15">15s</option>
+ <option class="speed_val" value="30">30s</option>
+ <option class="speed_val" value="60">60s</option>
+ </select>
+ </span>
</span>
<span id="topright-register">
<a href="register.html">Register</a>
@@ -179,6 +189,7 @@
<div id="news">
<h3>News</h3>
<ul id="welcome-list-news" class="welcome-list">
+<li><b>27/06/11</b> Tabs and searching opponents in the profile page</li>
<li><b>22/06/11</b> Better organized lists of plays</li>
<li><b>19/06/11</b> News section on the front page of tPlay</li>
<li><b>15/06/11</b> Bug with underscores in user names corrected</li>
Modified: trunk/Toss/WebClient/profile.html
===================================================================
--- trunk/Toss/WebClient/profile.html 2011-06-25 14:13:14 UTC (rev 1496)
+++ trunk/Toss/WebClient/profile.html 2011-06-28 00:48:40 UTC (rev 1497)
@@ -46,7 +46,15 @@
</form>
</div>
<span id="topright">
- <button id="logoutbt" onclick="logout_profile()">Logout</button>
+ <span class="toprighttab">
+ <a href="index.html">Games</a>
+ </span>
+ <span class="toprighttab">
+ <a href="profile.html">Profile</a>
+ </span>
+ <span class="toprighttab">
+ <button id="logoutbt" onclick="logout()">Logout</button>
+ </span>
</span>
<span id="topright-register">
<a href="register.html">Register</a>
@@ -59,8 +67,9 @@
</p>
</div>
-<div id="main-profile" style="display: none;">
-<h2>Your Profile</h2>
+<div id="main-profile">
+<div id="change-data">
+<h2>Change Your Data</h2>
<div id="changeprofileform">
<p> <span class="reglabel">Name:</span>
<input class="forminput" type="text" name="name" id="name" />
@@ -74,7 +83,9 @@
<p><button class="bt" id="changebt" type="button"
onclick="change_profile()">Change</button></p>
</div>
+</div>
+<div id="change-password" class="profile-right">
<h2>Change Password</h2>
<div id="changepwdform">
<p> <span class="reglabel">New Password:</span>
@@ -83,27 +94,51 @@
<p> <span class="reglabel">Repeat New Password:</span>
<input class="forminput" type="password" name="rptnewpwd" id="rptnewpwd" />
</p>
+<p> <input class="hiddenforminput" /> </p>
<p><button class="bt" id="changepwdbt" type="button"
onclick="change_password()">Change Password</button></p>
</div>
+</div>
-<h2>Your Current Opponents</h2>
+<div class="separator-div"></div>
-<div id="opponents-profile">
- <ul id="opponents-list"><li style="display: none;"/></ul>
-</div>
+<div class="positioning-div">
+ <div id="find-opponents">
+ <h2>Find New Opponents</h2>
+ <div id="findopntform">
+ <p> <span class="reglabel">Email or Name:</span>
+ <input class="forminput" type="text" name="findopnt" id="findopnt" />
+ </p>
+ <p><button class="bt" id="findopntbt" type="button"
+ onclick="find_opnts()">Find Opponents</button>
+ </p>
+ </div>
+ <ul id="add-opponents-list"><li style="display: none;"/></ul>
+ <div id="invite">
+ <p> <span class="reglabel">Your Friend not here?</span><br/> </p>
+ <p>
+ <button class="bt" id="invitebt" type="button"
+ onclick="invite()">Send Invitation</button>
+ </p>
+ </div>
+ </div>
-<h2>Suggested New Opponents</h2>
-
-<div id="users-profile">
- <ul id="users-list"><li style="display: none;"/></ul>
+ <div id="current-opponents" class="profile-right">
+ <h2>Your Current Opponents</h2>
+ <div id="opponents-profile">
+ <ul id="opponents-list"><li style="display: none;"/></ul>
+ </div>
+ </div>
</div>
</div>
<div id="bottom">
<a href="http://toss.sourceforge.net" id="toss-link">Powered by Toss</a>
-<a href="contact.html" id="contact">Contact and Info</a>
+<script type="text/javascript">begin_mailto(
+ "tossplay", "gmail.com", "Contact Us");</script>
+tossplay [AT] gmail [DOT] com
+<script type="text/javascript">end_mailto();</script>
</div>
</div>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|