Backbone view for attachment upload
Review Request #5911 — Created May 31, 2014 and submitted
Information | |
---|---|
volodymyr | |
Review Board | |
5824 | |
Reviewers | |
reviewboard, students | |
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 … |
|
|
All of the HTML in these strings should be indented 1 space, not 4. |
|
|
It's not important during prototyping, but we'll eventually want any user-visible strings to be passed into the template as variables, … |
|
|
You've got some badly defined HTML in here (all the <col> elements are un-closed). |
|
|
Make sure never to have a trailing comma on the last entry in a dictionary or list. It'll break some … |
|
|
variables should always be nameed likeThis. |
|
|
initialize should never call render. That's up to the caller who's constructing the view. Same with setting el. |
|
|
Instead of assigning that, pass this as the last parameter to save(), and the callbacks will end up having this … |
|
|
gReviewRequest is deprecated and was supposed to be removed. This view should be associated with a ReviewRequestEditor, which will have … |
|
|
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">', |
|
|
Can you wrap this? |
|
|
Arrays in javascript can't have trailing commas (it breaks on some browsers) |
|
|
Can you add method comments for this and all the others that don't have them? |
|
|
If you use this.$(...), it will be more efficient, since it doesn't have to scan the whole document. |
|
|
This should use gettext() |
|
|
'errorStr' is not HTML, so this should use .text() instead of .html(). |
|
|
You should be able to use the 'events' mapping for this: events: { ... existing other stuff ... 'click #upload-file-link': … |
|
|
You shouldn't need to pass el yourself. By default, a new div element will be created. |
|
|
I just committed a change to common.js that fixes some logic in this code (and simplifies things). Can you look … |
|
|
Can we name this $list, since it's a jquery object? |
|
|
Can we swap these (set HTML first, then append?) |
|
|
No trailing comma (breaks IE) |
|
|
No trailing comma (breaks IE) |
|
|
Either you should move the variable definition to the top of this method, or, more likely, just avoid assigning anything: … |
|
|
You can get rid of the uploadObject parameter by just passing in this.displayErrors as the value for error |
|
|
Get rid of the rsp parameter here (it's not used) |
|
|
What is this? I don't see any options anywhere. |
|
|
What is errors? I don't see where it's defined. |
|
|
Once the change in send above is made, this anonymous function could be replaced by _.bind(this.send, this). |
|
|
If you pass this as a second paramater to .save(), you don't have to create a local variable for displayErrors, … |
|
|
Variable definitions should be the first line in the function. |
|
|
Can you call this variable self instead of uploadObject? |
|
|
These two functions should probably be chained: this.$el .append(this.template({ ... })) .modalBox({ ... }); |
|

-
This is a review from Review Bot. Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/uploadAttachmentView.js
-
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 1) 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.
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 1) All of the HTML in these strings should be indented 1 space, not 4.
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 1) 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. -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 1) You've got some badly defined HTML in here (all the
<col>
elements are un-closed).
-
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 1) 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.)
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 1) variables should always be nameed likeThis.
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 1) initialize
should never callrender
. That's up to the caller who's constructing the view.Same with setting
el
. -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 1) Instead of assigning
that
, passthis
as the last parameter tosave()
, and the callbacks will end up havingthis
set correctly. -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 1) 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
-
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 4) 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">',
-
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 4) Arrays in javascript can't have trailing commas (it breaks on some browsers)
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 4) Can you add method comments for this and all the others that don't have them?
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 4) If you use this.$(...), it will be more efficient, since it doesn't have to scan the whole document.
-

-
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
-
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 5) 'errorStr' is not HTML, so this should use
.text()
instead of.html()
.
Change Summary:
Moved in some changes that previously were at https://reviews.reviewboard.org/r/5824/
Diff: |
Revision 6 (+150 -14) |
---|

-
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
-
-
reviewboard/static/rb/js/pages/views/reviewablePageView.js (Diff revision 6) You should be able to use the 'events' mapping for this:
events: { ... existing other stuff ... 'click #upload-file-link': '_onUploadFileClicked' }
-
reviewboard/static/rb/js/pages/views/reviewablePageView.js (Diff revision 6) You shouldn't need to pass
el
yourself. By default, a new div element will be created. -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 6) 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?
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 6) Can we name this
$list
, since it's a jquery object? -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 6) Can we swap these (set HTML first, then append?)
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 6) No trailing comma (breaks IE)
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 6) No trailing comma (breaks IE)

-
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
-
-
reviewboard/static/rb/js/pages/views/reviewablePageView.js (Diff revision 7) 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. -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 7) You can get rid of the
uploadObject
parameter by just passing inthis.displayErrors
as the value forerror
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 7) Get rid of the
rsp
parameter here (it's not used) -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 7) What is this? I don't see any
options
anywhere. -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 7) What is
errors
? I don't see where it's defined. -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 7) 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
-
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 8) If you pass
this
as a second paramater to.save()
, you don't have to create a local variable fordisplayErrors
, because it will use the right context. -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 8) Variable definitions should be the first line in the function.
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
-
Just a couple trivial coding style comments left. Nice job!
-
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 9) Can you call this variable
self
instead ofuploadObject
? -
reviewboard/static/rb/js/views/uploadAttachmentView.js (Diff revision 9) These two functions should probably be chained:
this.$el .append(this.template({ ... })) .modalBox({ ... });

-
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: |
|
|||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Testing Done: |
|