handle dup files

This commit is contained in:
James Campos 2011-09-02 23:00:20 -07:00
parent a0ac470623
commit 4f6c79a371
2 changed files with 44 additions and 32 deletions

View File

@ -1265,6 +1265,15 @@
$.append($('#files', QR.el), div); $.append($('#files', QR.el), div);
return file.click(); return file.click();
}, },
attachNext: function(file) {
var oldFile;
oldFile = $('[type=file]', QR.el);
file || (file = $.el('input', {
type: 'file',
name: 'upfile'
}));
return $.replace(oldFile, file);
},
autoPost: function() { autoPost: function() {
if (!QR.hasContent()) { if (!QR.hasContent()) {
return; return;
@ -1387,11 +1396,16 @@
return ta.focus(); return ta.focus();
}, },
receive: function(e) { receive: function(e) {
var data, file; var data, file, tc;
data = e.data; data = e.data;
if (data) { if (data) {
return $.extend($('a.error', QR.el), JSON.parse(data)); $.extend($('a.error', QR.el), JSON.parse(data));
} else { tc = data.textContent;
if (tc === 'Error: Duplicate file entry detected.') {
QR.attachNext();
}
return;
}
if (((file = $('#files input', QR.el)) && file.files.length) || conf['Persistent QR']) { if (((file = $('#files input', QR.el)) && file.files.length) || conf['Persistent QR']) {
QR.reset(file); QR.reset(file);
} else { } else {
@ -1402,17 +1416,10 @@
$.set("cooldown/" + g.BOARD, cooldown); $.set("cooldown/" + g.BOARD, cooldown);
return QR.cooldown(); return QR.cooldown();
} }
}
}, },
reset: function(file) { reset: function(file) {
var oldFile;
$('textarea', QR.el).value = ''; $('textarea', QR.el).value = '';
oldFile = $('[type=file]', QR.el); return QR.attachNext(file);
file || (file = $.el('input', {
type: 'file',
name: 'upfile'
}));
return $.replace(oldFile, file);
}, },
submit: function(e) { submit: function(e) {
var captcha, challenge, el, response; var captcha, challenge, el, response;

View File

@ -988,6 +988,12 @@ QR =
$.bind $('a', div), 'click', -> $.rm @parentNode $.bind $('a', div), 'click', -> $.rm @parentNode
$.append $('#files', QR.el), div $.append $('#files', QR.el), div
file.click() file.click()
attachNext: (file) ->
oldFile = $ '[type=file]', QR.el
file or= $.el 'input',
type: 'file'
name: 'upfile'
$.replace oldFile, file
autoPost: -> autoPost: ->
return unless QR.hasContent() return unless QR.hasContent()
QR.submit() QR.submit()
@ -1089,7 +1095,10 @@ QR =
{data} = e {data} = e
if data if data
$.extend $('a.error', QR.el), JSON.parse data $.extend $('a.error', QR.el), JSON.parse data
else tc = data.textContent
if tc is 'Error: Duplicate file entry detected.'
QR.attachNext()
return
if ((file = $('#files input', QR.el)) and file.files.length) or conf['Persistent QR'] if ((file = $('#files input', QR.el)) and file.files.length) or conf['Persistent QR']
QR.reset file QR.reset file
else else
@ -1100,11 +1109,7 @@ QR =
QR.cooldown() QR.cooldown()
reset: (file) -> reset: (file) ->
$('textarea', QR.el).value = '' $('textarea', QR.el).value = ''
oldFile = $ '[type=file]', QR.el QR.attachNext file
file or= $.el 'input',
type: 'file'
name: 'upfile'
$.replace oldFile, file
submit: (e) -> submit: (e) ->
#XXX e is undefined if we're called from QR.autoPost #XXX e is undefined if we're called from QR.autoPost
$('.error', qr.el).textContent = '' $('.error', qr.el).textContent = ''