Make RB.FileAttachment inherit from BaseResource.
Review Request #3996 — Created March 23, 2013 and submitted — Latest diff uploaded
Make RB.FileAttachment inherit from BaseResource. RB.FileAttachment is now ported to Backbone, and is a BaseResource. Since RB.FileAttachment sends file data one of two ways (through a new-style file upload, with DnD, or a form upload), BaseResource had to be modified to handle this, the same way the old RB.FileAttachment had to. Now, BaseResources can mark that they have a field representing a file to upload. If, during save, that field has a suitable file associated, BaseResource will go down another path for the save operation. It will structure a payload to put up to the server that contains form data. (It's worth noting that there's new API out there for making this much nicer and easier to generate, but it's still a draft and not very supported.) If instead we're going through a formDlg (for a manual file upload, not DnD), then we have to save by doing an HTTP POST for an HTML form, using our form.ajaxSubmit code. (This is needed for older browsers.) BaseResource now supports this as well. Basically, if options.form exists, it will take precedence over all other fields and pass it down to RB.apiCall, which will do the right thing. Unit tests were added to this, and other code around file attachments were changed to properly work with the new class.
Did a drag-and-drop and saw the file upload work and the thumbnail show. Tested a manual upload. Also worked. Unit tests passed.