Backbone view for attachment upload
Review Request #5911 — Created May 31, 2014 and submitted
A working version of a Backbone view for file uploads (the one that you see when you click Update -> Add File). Previously that popup is used gReviewRequest hack. Now it's a standalone view, as that view is also needed for attachment revisioning.
Side note: The only other thing that needs gReviewRequest hack is "Update Diff" popup. Once someone writes a view for that, gReviewRequest can be removed.
Tested: * Uploading new attachments. * Error when no attachment is specified. * Multiple errors returned from server side (see screenshots).
Description | From | Last Updated |
---|---|---|
Styles should be defined in the .less files. That said, a lot of this looks like you're manually copying stuff … |
david | |
All of the HTML in these strings should be indented 1 space, not 4. |
david | |
It's not important during prototyping, but we'll eventually want any user-visible strings to be passed into the template as variables, … |
david | |
You've got some badly defined HTML in here (all the <col> elements are un-closed). |
david | |
Make sure never to have a trailing comma on the last entry in a dictionary or list. It'll break some … |
chipx86 | |
variables should always be nameed likeThis. |
chipx86 | |
initialize should never call render. That's up to the caller who's constructing the view. Same with setting el. |
chipx86 | |
Instead of assigning that, pass this as the last parameter to save(), and the callbacks will end up having this … |
chipx86 | |
gReviewRequest is deprecated and was supposed to be removed. This view should be associated with a ReviewRequestEditor, which will have … |
chipx86 | |
Would you mind wrapping this to try to keep it under 80 columns? ' <form encoding="multipart/form-data"', ' enctype="multipart/form-data"', ' id="attachment-upload-form">', |
david | |
Can you wrap this? |
david | |
Arrays in javascript can't have trailing commas (it breaks on some browsers) |
david | |
Can you add method comments for this and all the others that don't have them? |
david | |
If you use this.$(...), it will be more efficient, since it doesn't have to scan the whole document. |
david | |
This should use gettext() |
david | |
'errorStr' is not HTML, so this should use .text() instead of .html(). |
david | |
You should be able to use the 'events' mapping for this: events: { ... existing other stuff ... 'click #upload-file-link': … |
david | |
You shouldn't need to pass el yourself. By default, a new div element will be created. |
david | |
I just committed a change to common.js that fixes some logic in this code (and simplifies things). Can you look … |
david | |
Can we name this $list, since it's a jquery object? |
david | |
Can we swap these (set HTML first, then append?) |
david | |
No trailing comma (breaks IE) |
david | |
No trailing comma (breaks IE) |
david | |
Either you should move the variable definition to the top of this method, or, more likely, just avoid assigning anything: … |
david | |
You can get rid of the uploadObject parameter by just passing in this.displayErrors as the value for error |
david | |
Get rid of the rsp parameter here (it's not used) |
david | |
What is this? I don't see any options anywhere. |
david | |
What is errors? I don't see where it's defined. |
david | |
Once the change in send above is made, this anonymous function could be replaced by _.bind(this.send, this). |
david | |
If you pass this as a second paramater to .save(), you don't have to create a local variable for displayErrors, … |
david | |
Variable definitions should be the first line in the function. |
david | |
Can you call this variable self instead of uploadObject? |
david | |
These two functions should probably be chained: this.$el .append(this.template({ ... })) .modalBox({ ... }); |
david |
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js
-
-
Styles should be defined in the .less files.
That said, a lot of this looks like you're manually copying stuff that's autogenerated. Your view should use $.modalBox to create the modal, which will handle the background, etc.
-
-
It's not important during prototyping, but we'll eventually want any user-visible strings to be passed into the template as variables, so that we can call
gettext()
on them. -
-
-
Make sure never to have a trailing comma on the last entry in a dictionary or list. It'll break some browsers.
It's good to get in the habit of running 'jshint' within the js/ directory. (You'll need to install that.)
-
-
initialize
should never callrender
. That's up to the caller who's constructing the view.Same with setting
el
. -
Instead of assigning
that
, passthis
as the last parameter tosave()
, and the callbacks will end up havingthis
set correctly. -
gReviewRequest is deprecated and was supposed to be removed. This view should be associated with a ReviewRequestEditor, which will have a handle to the ReviewRequest model.
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js
-
This is a review from Review Bot. Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js
-
This is a review from Review Bot. Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js
-
Tool: PEP8 Style Checker Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js Tool: Pyflakes Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js
-
Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js
- Change Summary:
-
Moved in some changes that previously were at https://reviews.reviewboard.org/r/5824/
-
Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html
-
-
You should be able to use the 'events' mapping for this:
events: { ... existing other stuff ... 'click #upload-file-link': '_onUploadFileClicked' }
-
-
I just committed a change to common.js that fixes some logic in this code (and simplifies things). Can you look at that change (76caaa7) and copy the changes into your code here?
-
-
-
-
-
Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html
-
-
Either you should move the variable definition to the top of this method, or, more likely, just avoid assigning anything:
this.$('#upload-file-link') .click(_.bind(this._onUploadFileClicked, this));
This code should probably also go into the
render
method. -
You can get rid of the
uploadObject
parameter by just passing inthis.displayErrors
as the value forerror
-
-
-
-
Once the change in
send
above is made, this anonymous function could be replaced by_.bind(this.send, this)
.
-
Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html
- Change Summary:
-
Modified displayErrors a bit and retested. Made sure that it works with both single errors and multiple errors (single errors by not including file, multiple errors by sending appropriate reply from the python side). Attached screenshots of errors.
- Diff:
-
Revision 9 (+137 -14)
- Added Files:
-
Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html
-
Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js reviewboard/templates/reviews/review_request_dlgs.html
-
The code looks good, but the description seems out of date. Can you rewrite that, and then I'll do some final testing and push?
- Change Summary:
-
Description updated.
- Description:
-
~ A working version of a Backbone view for file uploads. It's not written very well and will be improved (since I need it for my project, I need a partial version).
~ A working version of a Backbone view for file uploads (the one that you see when you click Update -> Add File). Previously that popup is used gReviewRequest hack. Now it's a standalone view, as that view is also needed for attachment revisioning.
+ + Side note: The only other thing that needs gReviewRequest hack is "Update Diff" popup. Once someone writes a view for that, gReviewRequest can be removed.
- Testing Done:
-
~ Performed upload of new attachments, as well as updating existing versions.
~ Tested:
+ * Uploading new attachments. + * Error when no attachment is specified. + * Multiple errors returned from server side (see screenshots).