Fix server communication and handling in BaseResource.
Review Request #3833 — Created Feb. 3, 2013 and submitted — Latest diff uploaded
Fix server communication and handling in BaseResource. BaseResource now sends POST/PUT data to the server using encoded form data instead of Backbone.js's default JSON encoding. It goes through RB.apiCall for now, so that all our behavior (such as the "Loading..." indicator) works as expected. It also parses the error response to give us an appropriate error message from the server. Some fixes were made to save(). Previously, it would fail to create new objects, because it didn't have a url at the right time. This needed to happen after the object was ready and its parent resource, if any, was known to be created. parse() now ensures that rspNamespace is filled out, so we don't have weird 'undefined' errors when a subclass isn't written correctly. And finally, save(), fetch(), destroy(), etc. take a context parameter for the callbacks. This is something Backbone.js should really be providing, since it establishes this pattern with other callback-reated functions, but it doesn't. We now wrap the callbacks when calling the parent functions.
Unit tests pass. These changes came about from some of the first real-world usage with my upcoming comment change, which exercised each of these code paths.