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,32 +1396,30 @@
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));
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']) {
QR.reset(file);
} else { } else {
if (((file = $('#files input', QR.el)) && file.files.length) || conf['Persistent QR']) { QR.close();
QR.reset(file); }
} else { if (conf['Cooldown']) {
QR.close(); cooldown = Date.now() + 30 * SECOND;
} $.set("cooldown/" + g.BOARD, cooldown);
if (conf['Cooldown']) { return QR.cooldown();
cooldown = Date.now() + 30 * SECOND;
$.set("cooldown/" + g.BOARD, 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,22 +1095,21 @@ 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
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']
QR.reset file
else else
if ((file = $('#files input', QR.el)) and file.files.length) or conf['Persistent QR'] QR.close()
QR.reset file if conf['Cooldown']
else cooldown = Date.now() + 30*SECOND
QR.close() $.set "cooldown/#{g.BOARD}", cooldown
if conf['Cooldown'] QR.cooldown()
cooldown = Date.now() + 30*SECOND
$.set "cooldown/#{g.BOARD}", 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 = ''