Fix server communication and handling in BaseResource.

Review Request #3833 — Created Feb. 3, 2013 and submitted

Information

Review Board
master

Reviewers

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.
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
      Ignored Files:
        reviewboard/static/rb/js/datastore.js
        reviewboard/static/rb/js/models/tests/baseResourceModelTests.js
        reviewboard/static/rb/js/models/baseResourceModel.js
    
    
  2. 
      
david
  1. The code looks fine, though I'd like to see more tests.
  2. 
      
chipx86
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
      Ignored Files:
        reviewboard/static/rb/js/datastore.js
        reviewboard/static/rb/js/models/tests/baseResourceModelTests.js
        reviewboard/templates/js/tests.html
        reviewboard/static/rb/js/models/baseResourceModel.js
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to master (623fc5a0d953809f82cabb2f58f93ca06daba96d)