Permalink
Browse files

basic ajax for changing person

  • Loading branch information...
1 parent 5da6ac9 commit 5f7302e9f79c234d6b95562cc9d915c14c93f8b5 WMR committed Jun 5, 2012
Showing with 640 additions and 39 deletions.
  1. +21 −2 app/controllers/Memberships.scala
  2. +29 −16 app/views/main.scala.html
  3. +7 −3 app/views/memberships/details.scala.html
  4. +1 −1 conf/routes
  5. BIN project/target/scala-2.9.1/sbt-0.11.2/cache/compile/compile
  6. BIN project/target/scala-2.9.1/sbt-0.11.2/cache/update/inputs
  7. BIN project/target/scala-2.9.1/sbt-0.11.2/cache/update/output
  8. +15 −15 project/target/streams/compile/compile/$global/out
  9. +2 −2 project/target/streams/compile/copy-resources/$global/out
  10. BIN public/stylesheets/libs/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png
  11. BIN public/stylesheets/libs/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png
  12. BIN public/stylesheets/libs/ui-lightness/images/ui-bg_flat_10_000000_40x100.png
  13. BIN public/stylesheets/libs/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png
  14. BIN public/stylesheets/libs/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png
  15. BIN public/stylesheets/libs/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png
  16. BIN public/stylesheets/libs/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png
  17. BIN public/stylesheets/libs/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png
  18. BIN public/stylesheets/libs/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png
  19. BIN public/stylesheets/libs/ui-lightness/images/ui-icons_222222_256x240.png
  20. BIN public/stylesheets/libs/ui-lightness/images/ui-icons_228ef1_256x240.png
  21. BIN public/stylesheets/libs/ui-lightness/images/ui-icons_ef8c08_256x240.png
  22. BIN public/stylesheets/libs/ui-lightness/images/ui-icons_ffd27a_256x240.png
  23. BIN public/stylesheets/libs/ui-lightness/images/ui-icons_ffffff_256x240.png
  24. +565 −0 public/stylesheets/libs/ui-lightness/jquery-ui-1.8.20.custom.css
@@ -10,6 +10,8 @@ import models.memberships._
import models.persons._
import models.finance._
+case class Change(salutation: String, firstname: String, lastname: String)
+
object Memberships extends Controller {
val newMembershipForm: Form[NewMembership] = Form(
mapping(
@@ -34,10 +36,20 @@ object Memberships extends Controller {
)
(NewMembership.apply)(NewMembership.unapply)
)
+
+ val changeForm: Form[Change] = Form(
+ mapping(
+ "salutation_input" -> text,
+ "firstname_input" -> text,
+ "lastname_input" -> text
+ )
+ (Change.apply)(Change.unapply)
+ )
+
/**
* Display an empty form.
*/
- def form = Action {
+ def form = Action {
Ok(html.memberships.form(newMembershipForm));
}
@@ -54,7 +66,14 @@ object Memberships extends Controller {
def edit(id: Long) = TODO
def update(id: Long) = TODO
- def updatePerson(id: Long) = TODO
+
+ def changePerson(id: Long) = Action { implicit request =>
+ changeForm.bindFromRequest.fold(
+ errors => { println("error"); Ok("error") },
+ changes => {
+ println(changes.firstname);
+ Ok(<person><firstname>{changes.firstname}</firstname><lastname>{changes.lastname}</lastname></person>) })
+ }
/**
* Handle form submission.
View
@@ -25,6 +25,28 @@
"bScrollCollapse": false,
"sScrollY": "100px"
});
+
+ function sendPersonForm() {
+ var xmlhttp;
+ if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
+ alert('getting XMLHttpRequest');
+ xmlhttp=new XMLHttpRequest();
+ } else {// code for IE6, IE5
+ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ xmlhttp.onreadystatechange=function() {
+ if (xmlhttp.readyState==4 && xmlhttp.status==200) {
+ alert("finished");
+ document.getElementById("firstname").innerHTML = xmlhttp.responseXML.documentElement.getElementsByTagName("firstname")[0].childNodes[0].nodeValue;
+ document.getElementById("lastname").innerHTML = xmlhttp.responseXML.documentElement.getElementsByTagName("lastname")[0].childNodes[0].nodeValue;
+
+ }
+ }
+ xmlhttp.open("POST","/changeperson/1",true);
+ xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
+ xmlhttp.send("salutation_input=Frau&firstname_input=Rosa&lastname_input=Ford");
+ }
+
$(function() {
$( "#change-person-dialog" ).dialog({
autoOpen: false,
@@ -33,22 +55,13 @@
modal: true,
buttons: {
OK: function() {
- var xhr;
- xhr = new XMLHttpRequest();
- xhr.open("PUT","/person/1" );
- xhr.sent("name=Wolf");
- xhr.onreadystatechange = function() {
- if (this.readyState == 4) {
- if (this.status >= 200 && this.status < 300) {
- alert("OK");
- }
- else {
- alert("problem");
- }
- }
- };
- $( this ).dialog( "close" ); },
- Zurück: function() { $( this ).dialog( "close" ); }
+ alert("about sending form");
+ sendPersonForm();
+ $( this ).dialog( "close" );
+ },
+ Zurück: function() {
+ $( this ).dialog( "close" );
+ }
}
});
@@ -13,11 +13,11 @@
<div class="span-2"><label>Titel:</label></div>
<div class="span-2">@membershipPerson._2.title</div><br />
<div class="span-2"><label>Vorname:</label></div>
- <div class="span-2">@membershipPerson._2.firstname</div><br />
+ <div class="span-3"><span id="firstname">@membershipPerson._2.firstname</span></div><br />
<div class="span-2"><label>Zuname:</label></div>
- <div class="span-2">@membershipPerson._2.lastname</div><br />
+ <div class="span-3"><span id="lastname">@membershipPerson._2.lastname</span></div><br />
<div class="span-2"><label>Geburtstag:</label></div>
- <div class="span-2">@membershipPerson._2.birthday</div><br />
+ <div class="span-3">@membershipPerson._2.birthday</div><br />
<div class="span-2"><button id="change-person">Ändern</button></div>
</fieldset>
@@ -124,10 +124,14 @@
<fieldset>
<label for="salutation_input">Anrede</label>
<input type="text" name="salutation" id="salutation-input" class="text ui-widget-content ui-corner-all" value="@membershipPerson._2.salutation"/>
+ <label for="title_input">Titel</label>
+ <input type="text" name="title_input" id="title_input" class="text ui-widget-content ui-corner-all" value="@membershipPerson._2.title"/>
<label for="firstname_input">Vorname</label>
<input type="text" name="firstname" id="firstname_input" value="@membershipPerson._2.firstname" class="text ui-widget-content ui-corner-all" />
<label for="lastname_input">Zuname</label>
<input type="text" name="lastname" id="lastname_input" value="@membershipPerson._2.lastname" class="text ui-widget-content ui-corner-all" />
+ <label for="birthday_input">Geburtstag</label>
+ <input type="text" name="birthday_input" id="birthday_input" value="@membershipPerson._2.birthday" class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>
</div>
View
@@ -12,6 +12,6 @@ GET /membership/:id/edit controllers.Memberships.edit(id: Long)
PUT /membership/:id controllers.Memberships.update(id: Long)
POST /memberships controllers.Memberships.submit
-PUT /person/:id controllers.Memberships.updatePerson(id: Long)
+POST /changeperson/:id controllers.Memberships.changePerson(id: Long)
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,15 +1,15 @@
-[debug] 
-[debug] Initial source changes: 
-[debug]  removed:Set()
-[debug]  added: Set()
-[debug]  modified: Set()
-[debug] Removed products: Set()
-[debug] Modified external sources: Set()
-[debug] Modified binary dependencies: Set()
-[debug] Initial directly invalidated sources: Set()
-[debug] 
-[debug] Sources indirectly invalidated by:
-[debug]  product: Set()
-[debug]  binary dep: Set()
-[debug]  external source: Set()
-[debug] Initially invalidated: Set()
+[debug]
+[debug] Initial source changes:
+[debug] removed:Set()
+[debug] added: Set()
+[debug] modified: Set()
+[debug] Removed products: Set()
+[debug] Modified external sources: Set()
+[debug] Modified binary dependencies: Set()
+[debug] Initial directly invalidated sources: Set()
+[debug]
+[debug] Sources indirectly invalidated by:
+[debug] product: Set()
+[debug] binary dep: Set()
+[debug] external source: Set()
+[debug] Initially invalidated: Set()
@@ -1,2 +1,2 @@
-[0m[[0mdebug[0m] [0mCopy resource mappings: [0m
-[0m[[0mdebug[0m] [0m [0m
+[debug] Copy resource mappings:
+[debug]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 5f7302e

Please sign in to comment.