Created
November 28, 2009 13:46
-
-
Save bobtfish/244511 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Roundtripping objects in Javascript with Joose: | |
| Joose.Storage.Unpacker.patchJSON(); | |
| // Represents a page fragment | |
| Class("Fragment", { | |
| does: Joose.Storage, | |
| has: { | |
| html: { | |
| is: "rw", | |
| init: " " | |
| }, | |
| id: { | |
| is: "rw" | |
| }, | |
| after_fragment: { | |
| is: "rw" | |
| } | |
| }, | |
| }); | |
| // Represents a response to sending a page fragment to the server.. | |
| Class("SaveResponse", { | |
| does: Joose.Storage, | |
| has: { | |
| id: { | |
| is: "ro" | |
| }, | |
| old_id: { | |
| is: "ro", | |
| predicate: "has_old_id" | |
| }, | |
| status: { | |
| is: "ro" | |
| } | |
| }, | |
| methods: { | |
| forPanel: function () { | |
| if (this.status == 'DELETED') { | |
| return "<div>Deleted <b>" + this.id + "</b></div>"; | |
| } | |
| else if (this.status == 'OK') { | |
| return "<div>Saved <b>" + this.id + "</b></div>"; | |
| } | |
| return JSON.stringify(this); | |
| } | |
| } | |
| }); | |
| // Actual code to deal with the command | |
| $.ajax({ | |
| type: "POST", | |
| //url: "bin/process.php", | |
| data: JSON.stringify(myFragment), | |
| contentType: "application/json", | |
| success: function(json) { | |
| var response = JSON.parse(json); | |
| // Assign status from response.forPanel() to UI element here.. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment