Prevent filesize errors. Prepare single and multiple file selection.
This commit is contained in:
parent
ff34fa6de1
commit
c547815b7c
@ -1216,6 +1216,13 @@
|
||||
close: function() {
|
||||
return qr.el.hidden = true;
|
||||
},
|
||||
error: function(err) {
|
||||
$('.error', qr.el).textContent = err;
|
||||
return alert(err);
|
||||
},
|
||||
cleanError: function() {
|
||||
return $('.error', qr.el).textContent = null;
|
||||
},
|
||||
quote: function(e) {
|
||||
var caretPos, id, s, sel, ta, text, _ref;
|
||||
if (e != null) e.preventDefault();
|
||||
@ -1233,6 +1240,27 @@
|
||||
ta.focus();
|
||||
return ta.selectionEnd = ta.selectionStart = caretPos + text.length;
|
||||
},
|
||||
fileInput: function() {
|
||||
var file, _i, _len, _ref;
|
||||
qr.cleanError();
|
||||
if (this.files.length === 1) {
|
||||
if (this.files[0].size > this.max) {
|
||||
qr.error('File too large.');
|
||||
} else {
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
_ref = this.files;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
file = _ref[_i];
|
||||
if (file.size > this.max) {
|
||||
qr.error("File " + file.name + " is too large.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $.addClass(qr.el, 'dump');
|
||||
},
|
||||
dialog: function() {
|
||||
var file, input, name, _ref;
|
||||
qr.el = ui.dialog('qr', 'top:0;right:0;', '\
|
||||
@ -1311,7 +1339,7 @@ textarea.field {\
|
||||
<div><textarea title=Comment placeholder=Comment class=field></textarea><div>\
|
||||
<div class=captcha><img></div>\
|
||||
<div><input name=captcha title=Verification placeholder=Verification class=field size=1></div>\
|
||||
<div><input type=file name=upfile><input type=submit value=Submit></div>\
|
||||
<div><input type=file name=upfile multiple><input type=submit value=Submit></div>\
|
||||
<div class=error></div>\
|
||||
</form>');
|
||||
$.on($('#autohide', qr.el), 'click', qr.hide);
|
||||
@ -1347,12 +1375,14 @@ textarea.field {\
|
||||
return 'image/' + type;
|
||||
}
|
||||
});
|
||||
file.max = $('[name=MAX_FILE_SIZE]').value;
|
||||
$.on(file, 'change', qr.fileInput);
|
||||
return $.add(d.body, qr.el);
|
||||
},
|
||||
submit: function(e) {
|
||||
if (e != null) e.preventDefault();
|
||||
if (conf['Auto Hide QR']) qr.hide();
|
||||
return $('.error', qr.el).textContent = null;
|
||||
return qr.cleanError();
|
||||
},
|
||||
response: function(e) {
|
||||
var input, name, _ref, _results;
|
||||
|
||||
@ -877,16 +877,20 @@ qr =
|
||||
qr.hide.call input
|
||||
else
|
||||
qr.dialog()
|
||||
|
||||
hide: ->
|
||||
if this.checked
|
||||
$.addClass qr.el, 'autohide'
|
||||
else
|
||||
$.removeClass qr.el, 'autohide'
|
||||
|
||||
close: ->
|
||||
qr.el.hidden = true
|
||||
|
||||
error: (err) ->
|
||||
$('.error', qr.el).textContent = err
|
||||
alert err
|
||||
cleanError: ->
|
||||
$('.error', qr.el).textContent = null
|
||||
|
||||
quote: (e) ->
|
||||
e?.preventDefault()
|
||||
qr.open()
|
||||
@ -907,6 +911,22 @@ qr =
|
||||
#move the caret to the end of the new quote
|
||||
ta.selectionEnd = ta.selectionStart = caretPos + text.length
|
||||
|
||||
fileInput: ->
|
||||
qr.cleanError()
|
||||
if @files.length is 1
|
||||
if @files[0].size > @max
|
||||
qr.error 'File too large.'
|
||||
else
|
||||
# modify selected reply's file
|
||||
return
|
||||
for file in @files
|
||||
if file.size > @max
|
||||
qr.error "File #{file.name} is too large."
|
||||
break
|
||||
# add new reply
|
||||
# set reply's file
|
||||
$.addClass qr.el, 'dump'
|
||||
|
||||
dialog: ->
|
||||
qr.el = ui.dialog 'qr', 'top:0;right:0;', '
|
||||
<style>
|
||||
@ -984,7 +1004,7 @@ textarea.field {
|
||||
<div><textarea title=Comment placeholder=Comment class=field></textarea><div>
|
||||
<div class=captcha><img></div>
|
||||
<div><input name=captcha title=Verification placeholder=Verification class=field size=1></div>
|
||||
<div><input type=file name=upfile><input type=submit value=Submit></div>
|
||||
<div><input type=file name=upfile multiple><input type=submit value=Submit></div>
|
||||
<div class=error></div>
|
||||
</form>'
|
||||
$.on $('#autohide', qr.el), 'click', qr.hide
|
||||
@ -1014,13 +1034,15 @@ textarea.field {
|
||||
'application/PDF'
|
||||
else
|
||||
'image/' + type
|
||||
file.max = $('[name=MAX_FILE_SIZE]').value
|
||||
$.on file, 'change', qr.fileInput
|
||||
|
||||
$.add d.body, qr.el
|
||||
|
||||
submit: (e) ->
|
||||
e?.preventDefault()
|
||||
qr.hide() if conf['Auto Hide QR']
|
||||
$('.error', qr.el).textContent = null
|
||||
qr.cleanError()
|
||||
# magical xhr2
|
||||
|
||||
response: (e) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user