-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/way more styles #2
base: master
Are you sure you want to change the base?
Changes from all commits
9d85972
0a5ce8f
0426ddf
071b5ff
66e5122
65efc52
71627c8
37d0aba
2e6e5fc
53b8de3
77f2d8d
66a851d
64e1ef0
6e0892b
00a78af
2b2ac46
63b584e
9cb20f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
source "https://rubygems.org" | ||
gemspec | ||
|
||
gem 'dvl-core', github: 'dobtco/dvl-core' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,21 @@ | |
|
||
@$form = @$el.closest('form') | ||
@$input = @$el.find('input') | ||
@$filename = @$el.find('.pfi_existing_filename') | ||
@$status = @$el.find('.pfi_status') | ||
@$filename = @$el.find('.js_pfi_filename') | ||
@$status = @$el.find('.js_pfi_status') | ||
@$button = @$el.find('.js_pfi_browse') | ||
@buttonText = @$button.text() | ||
@statusText = @$status.text() | ||
|
||
# If we're not persisted, immediately add the correct input name | ||
if [email protected] | ||
if @options.persisted | ||
@_calculateRemoveParams() | ||
@_copyOptionsFromForm() | ||
else | ||
@$input.attr('name', @options.name) | ||
|
||
@_bindEvents() | ||
|
||
_calculateRemoveParams: -> | ||
removeKey = if @options.name.match(/\[/) | ||
i = @options.name.lastIndexOf('[') | ||
"#{@options.name.substring(0, i)}[remove_#{@options.name.substring(i + 1, @options.name.length)}" | ||
|
@@ -30,26 +38,33 @@ | |
@removeParams = {} | ||
@removeParams[removeKey] = true | ||
|
||
_copyOptionsFromForm: -> | ||
@options.action ||= @$form.attr('action') | ||
@options.method ||= @$form.find('[name=_method]').val() || @$form.attr('method') | ||
|
||
@_bindEvents() | ||
|
||
remove: -> | ||
@$status.text @statusText | ||
|
||
if @options.persisted | ||
@_ajaxRemove() | ||
else | ||
@$input.val('') | ||
|
||
@$el.removeClass('is_uploaded') | ||
@_toggleState() | ||
|
||
_toggleState: -> | ||
$('.js_pfi_toggle').toggle() | ||
|
||
_baseParams: -> | ||
$.extend { pretty_file_input: true }, @options.additionalParams | ||
$.extend { | ||
pretty_file_input: true | ||
_method: @options.method | ||
}, @options.additionalParams | ||
|
||
_ajaxRemove: -> | ||
$.ajax | ||
url: @options.action | ||
type: @options.method | ||
type: 'POST' | ||
dataType: 'json' | ||
data: $.extend @_baseParams(), @removeParams | ||
|
||
|
@@ -60,49 +75,66 @@ | |
dataType: 'json' | ||
data: @_baseParams() | ||
uploadProgress: (_, __, ___, percentComplete) => | ||
@$status.text( | ||
@$button.text( | ||
if percentComplete == 100 | ||
'Finishing' | ||
'Finishing...' | ||
else | ||
"Uploading (#{percentComplete}%)" | ||
) | ||
complete: => | ||
@$input.show() | ||
$tmpForm.remove() | ||
success: $.proxy(@_uploadSuccess, @) | ||
error: $.proxy(@_uploadError, @) | ||
|
||
_createTemporaryForm: -> | ||
form = $(""" | ||
$form = $(""" | ||
<form action='#{@options.action}' method='post' style='display: inline;'> | ||
<input type='hidden' name='_method' value='#{@options.method}' /> | ||
</form> | ||
""") | ||
|
||
$oldInput = @$input | ||
@$input = $oldInput.clone().hide().val('').insertBefore($oldInput) | ||
@$input = $oldInput.clone().val('').insertBefore($oldInput) | ||
@_bindInputChange() | ||
$oldInput.appendTo(form) | ||
$oldInput.appendTo($form) | ||
|
||
# We only add the name immediately before uploading because we | ||
# don't want to send the input value during submission of an | ||
# outer form. | ||
$oldInput.attr('name', @options.name) | ||
|
||
form.insertBefore(@$input) | ||
$form.insertBefore(@$input) | ||
|
||
form | ||
$form | ||
|
||
_uploadSuccess: (data) -> | ||
if data?.additionalParams? | ||
@options.additionalParams = data.additionalParams | ||
|
||
@$status.text('') | ||
@$el.addClass('is_uploaded') | ||
@_resetButton() | ||
@_toggleState() | ||
|
||
_resetButton: -> | ||
@$button.removeClass('disabled') | ||
@$button.text @buttonText | ||
|
||
_uploadError: (xhr) -> | ||
@_resetButton() | ||
@_flashError( | ||
if (err = xhr.responseJSON?.error) | ||
"Error: #{err}" | ||
else | ||
'Whoops! An error occurred.' | ||
) | ||
|
||
_flashError: (msg) -> | ||
@$status.text msg | ||
@$status.addClass 'is_error' | ||
|
||
_uploadError: -> | ||
@$status.text 'Error' | ||
setTimeout ( => @$status.text('') ), 2000 | ||
setTimeout => | ||
@$status.removeClass 'is_error' | ||
@$status.text @statusText | ||
, 2500 | ||
|
||
_eventToFilename: (e) -> | ||
if e.target.files? | ||
|
@@ -114,13 +146,14 @@ | |
@$filename.text @_eventToFilename(e) | ||
|
||
if @options.persisted | ||
@$status.text 'Uploading...' | ||
@$button.addClass('disabled') | ||
@$button.text 'Uploading...' | ||
@_ajaxUpload() | ||
else | ||
@_uploadSuccess() | ||
|
||
_bindEvents: -> | ||
@$el.on 'click', '[data-pfi-remove]', $.proxy(@remove, @) | ||
@$el.on 'click', '.js_pfi_remove', $.proxy(@remove, @) | ||
@_bindInputChange() | ||
|
||
# FF6 doesn't bubble the 'change' event, so we need to bind | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,60 @@ | ||
// A more functional file input | ||
.pfi { | ||
.pfi_file_wrapper { | ||
width: 100%; | ||
max-width: 400px; | ||
position: relative; | ||
display: inline-block; | ||
height: $inputHeight; | ||
|
||
// Position the items absolutely | ||
input, .pfi_input { | ||
width: 100%; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
} | ||
// Hide the input via opacity | ||
input { | ||
display: inline; | ||
opacity: 0; | ||
height: $inputHeight; | ||
} | ||
} | ||
|
||
.pfi_uploaded{ | ||
display: none; | ||
} | ||
|
||
.is_uploaded { | ||
.pfi_uploaded { | ||
.pfi_input { | ||
user-select: none; | ||
display: block; | ||
|
||
span, a { | ||
display: inline-block; | ||
vertical-align: top; | ||
height: $inputHeight; | ||
} | ||
|
||
:first-child { | ||
font-size: 1rem; | ||
width: 65%; | ||
padding: 0.3rem 0.5rem; | ||
border: 1px solid $lightGray; | ||
border-right: 0; | ||
color: $darkGray; | ||
border-top-left-radius: $radius; | ||
border-bottom-left-radius: $radius; | ||
@include ellipses; | ||
|
||
&.is_error { | ||
border-color: $errorColor; | ||
} | ||
} | ||
|
||
:last-child { | ||
width: 35%; | ||
border: 0; // Fix alignment | ||
border-top-left-radius: 0; | ||
border-bottom-left-radius: 0; | ||
line-height: normal; | ||
} | ||
} | ||
.pfi_not_uploaded { | ||
display: none; | ||
} | ||
} | ||
|
||
// Override label weight | ||
label.pfi_file_wrapper { | ||
font-weight: $weightNormal; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ class PrettyFileInput::Component < Erector::Widget | |
|
||
def content | ||
div( | ||
class: "pfi cf #{@filename ? 'is_uploaded' : ''}", | ||
class: 'pfi cf', | ||
'data-pfi' => { | ||
name: @name, | ||
persisted: @persisted, | ||
|
@@ -19,14 +19,18 @@ def content | |
additionalParams: @additional_params | ||
}.to_json | ||
) { | ||
div.pfi_uploaded { | ||
span.pfi_existing_filename @filename | ||
text ' ' | ||
a.button.mini.info 'Remove', 'data-pfi-remove' => true | ||
div.js_pfi_toggle.pfi_file_wrapper(style: @filename ? nil : 'display:none;') { | ||
span.pfi_input { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using {...} for multi-line blocks. |
||
span.js_pfi_filename @filename | ||
a.button.info.js_pfi_remove 'Remove' | ||
} | ||
} | ||
div.pfi_not_uploaded { | ||
label.js_pfi_toggle.pfi_file_wrapper(style: @filename ? 'display:none;' : nil) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [86/80] |
||
input type: 'file' | ||
span.pfi_status | ||
span.pfi_input { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using {...} for multi-line blocks. |
||
span.js_pfi_filename.js_pfi_status 'Choose a file...' | ||
span.button.info.js_pfi_browse 'Browse' | ||
} | ||
} | ||
} | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#! /bin/bash | ||
|
||
bundle install | ||
cd spec/dummy | ||
bundle exec rake db:create db:migrate | ||
cd ../../ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#! /bin/bash | ||
|
||
bundle exec thin start --chdir spec/dummy --port 9393 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@import 'dvl/app'; | ||
@import 'pretty_file_input'; | ||
|
||
body { | ||
background: #ccc; | ||
} | ||
|
||
.container { | ||
margin: 50px; | ||
padding: 50px; | ||
background: white; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,8 @@ | |
<%= csrf_meta_tags %> | ||
</head> | ||
<body> | ||
|
||
<div class='container'> | ||
<%= yield %> | ||
|
||
</div> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [84/80]
Avoid using {...} for multi-line blocks.