summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Holliday <n.g.holliday@gmail.com>2010-03-23 16:50:24 +0000
committerCraig Andrews <candrews@integralblue.com>2010-03-26 18:28:54 -0400
commit260f00d60bc83ac641d6fbe465e70aec33ccd9be (patch)
tree881c63245e4a24b0f7cb2faf40ba52186160ca76
parent92ded7c6cb56056a89bc8b3caabd08049104898e (diff)
Multiple file upload handling.
-rw-r--r--actions/newnotice.php35
-rw-r--r--js/util.js53
-rw-r--r--lib/noticeform.php14
-rw-r--r--theme/base/css/display.css12
-rw-r--r--theme/default/css/display.css7
5 files changed, 72 insertions, 49 deletions
diff --git a/actions/newnotice.php b/actions/newnotice.php
index ed0fa1b2b..2aa354870 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -164,22 +164,25 @@ class NewnoticeAction extends Action
$replyto = 'false';
}
- $upload = null;
- $upload = MediaFile::fromUpload('attach');
-
- if (isset($upload)) {
-
- $content_shortened .= ' ' . $upload->shortUrl();
-
- if (Notice::contentTooLong($content_shortened)) {
+ $uploads = array();
+ foreach($_FILES as $name => $value) {
+ if(substr($name, 0, 6) == "attach") {
+ $upload = MediaFile::fromUpload($name);
+ if (isset($upload)) {
+ $content_shortened .= ' ' . $upload->shortUrl();
+ }
+ }
+ }
+ if (Notice::contentTooLong($content_shortened)) {
+ foreach($uploads as $upload) {
$upload->delete();
- $this->clientError(
- sprintf(
- _('Max notice size is %d chars, including attachment URL.'),
- Notice::maxContent()
- )
- );
}
+ $this->clientError(
+ sprintf(
+ _('Max notice size is %d chars, including attachment URL.'),
+ Notice::maxContent()
+ )
+ );
}
$options = array('reply_to' => ($replyto == 'false') ? null : $replyto);
@@ -197,12 +200,10 @@ class NewnoticeAction extends Action
$notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
- if (isset($upload)) {
+ foreach($uploads as $upload) {
$upload->attachToNotice($notice);
}
-
-
if ($this->boolean('ajax')) {
header('Content-Type: text/xml;charset=utf-8');
$this->xw->startDocument('1.0', 'UTF-8');
diff --git a/js/util.js b/js/util.js
index 1320d11b4..d62adf33a 100644
--- a/js/util.js
+++ b/js/util.js
@@ -30,7 +30,8 @@ var SN = { // StatusNet
CounterBlackout: false,
MaxLength: 140,
PatternUsername: /^[0-9a-zA-Z\-_.]*$/,
- HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307]
+ HTTP20x30x: [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307],
+ UploadCounter: 0
},
S: { // Selector
@@ -172,6 +173,7 @@ var SN = { // StatusNet
FormNoticeXHR: function(form) {
SN.C.I.NoticeDataGeo = {};
form.append('<input type="hidden" name="ajax" value="1"/>');
+
form.ajaxForm({
dataType: 'xml',
timeout: '60000',
@@ -228,9 +230,10 @@ var SN = { // StatusNet
}
else {
if (parseInt(xhr.status) === 0 || jQuery.inArray(parseInt(xhr.status), SN.C.I.HTTP20x30x) >= 0) {
- form
- .resetForm()
- .find('#'+SN.C.S.NoticeDataAttachSelected).remove();
+ form.resetForm();
+ SN.U.NoticeClearAttachments(form);
+ SN.C.I.UploadCounter = 0;
+ SN.U.NoticeNewAttachment($('fieldset', form));
SN.U.FormNoticeEnhancements(form);
}
else {
@@ -287,8 +290,9 @@ var SN = { // StatusNet
}
}
form.resetForm();
- form.find('#'+SN.C.S.NoticeInReplyTo).val('');
- form.find('#'+SN.C.S.NoticeDataAttachSelected).remove();
+ SN.U.NoticeClearAttachments(form);
+ SN.C.I.UploadCounter = 0;
+ SN.U.NoticeNewAttachment($('fieldset', form));
SN.U.FormNoticeEnhancements(form);
}
},
@@ -309,6 +313,11 @@ var SN = { // StatusNet
}
});
},
+
+ NoticeClearAttachments: function(form) {
+ $('input:file', form).remove();
+ $('div[class=' + SN.C.S.Success + ']', form).remove();
+ },
NoticeReply: function() {
if ($('#'+SN.C.S.NoticeDataText).length > 0 && $('#content .notice_reply').length > 0) {
@@ -468,25 +477,31 @@ var SN = { // StatusNet
}
},
- NoticeDataAttach: function() {
- NDA = $('#'+SN.C.S.NoticeDataAttach);
+ NoticeDataAttach: function(NDANum) {
+ NDA = $('#'+SN.C.S.NoticeDataAttach+NDANum);
NDA.change(function() {
- S = '<div id="'+SN.C.S.NoticeDataAttachSelected+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">&#215;</button></div>';
- NDAS = $('#'+SN.C.S.NoticeDataAttachSelected);
- if (NDAS.length > 0) {
- NDAS.replaceWith(S);
- }
- else {
- $('#'+SN.C.S.FormNotice).append(S);
- }
- $('#'+SN.C.S.NoticeDataAttachSelected+' button').click(function(){
- $('#'+SN.C.S.NoticeDataAttachSelected).remove();
+ S = '<div id="'+SN.C.S.NoticeDataAttachSelected+SN.C.I.UploadCounter+'" class="'+SN.C.S.Success+'"><code>'+$(this).val()+'</code> <button class="close">&#215;</button></div>';
+ $('#'+SN.C.S.FormNotice).append(S);
+
+ $('#'+SN.C.S.NoticeDataAttachSelected+SN.C.I.UploadCounter+' button').click(function(){
+ $('#'+this.parentNode.getAttribute("id")).remove();
+ $('#'+this.parentNode.getAttribute("id").replace("_selected", "")).remove();
NDA.val('');
return false;
});
+ SN.C.I.UploadCounter++;
+ NDA.attr('style', 'display: none;');
+ SN.U.NoticeNewAttachment(NDA.parent());
+ $('#notice_data-attach-label').attr('for', SN.C.S.NoticeDataAttach+SN.C.I.UploadCounter);
});
},
+
+ NoticeNewAttachment: function(parent) {
+ NEWFILE = '<input id="'+SN.C.S.NoticeDataAttach+SN.C.I.UploadCounter+'" class="attach" type="file" name="attach'+SN.C.I.UploadCounter+'" title="'+NoticeAttachment_text.AttachFile+'"/>';
+ parent.append(NEWFILE);
+ SN.U.NoticeDataAttach(SN.C.I.UploadCounter);
+ },
NoticeLocationAttach: function() {
var NLat = $('#'+SN.C.S.NoticeLat).val();
@@ -720,7 +735,7 @@ var SN = { // StatusNet
SN.U.FormNoticeEnhancements($(this));
});
- SN.U.NoticeDataAttach();
+ SN.U.NoticeDataAttach("");
}
},
diff --git a/lib/noticeform.php b/lib/noticeform.php
index 7278c41a9..a55839de0 100644
--- a/lib/noticeform.php
+++ b/lib/noticeform.php
@@ -189,10 +189,14 @@ class NoticeForm extends Form
}
if (common_config('attachments', 'uploads')) {
- $this->out->element('label', array('for' => 'notice_data-attach'),_('Attach'));
+ $this->out->element('label', array('id' => 'notice_data-attach-label',
+ 'class' => 'attach-label',
+ 'for' => 'notice_data-attach'),
+ _('Attach'));
$this->out->element('input', array('id' => 'notice_data-attach',
+ 'class' => 'attach',
'type' => 'file',
- 'name' => 'attach',
+ 'name' => 'attach0',
'title' => _('Attach a file')));
$this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
}
@@ -212,8 +216,10 @@ class NoticeForm extends Form
$this->out->checkbox('notice_data-geo', _('Share my location'), true);
$this->out->elementEnd('div');
$this->out->inlineScript(' var NoticeDataGeo_text = {'.
- 'ShareDisable: "'._('Do not share my location').'",'.
- 'ErrorTimeout: "'._('Sorry, retrieving your geo location is taking longer than expected, please try again later').'"'.
+ 'ShareDisable: ' .json_encode(_('Do not share my location')).','.
+ 'ErrorTimeout: ' .json_encode(_('Sorry, retrieving your geo location is taking longer than expected, please try again later')).
+ '} ; var NoticeAttachment_text = {'.
+ 'AttachFile: ' . json_encode(_('Attach a file')) .
'}');
}
diff --git a/theme/base/css/display.css b/theme/base/css/display.css
index f48bdf55e..768d78ac2 100644
--- a/theme/base/css/display.css
+++ b/theme/base/css/display.css
@@ -550,19 +550,19 @@ float:left;
font-size:1.3em;
margin-bottom:7px;
}
-.form_notice label[for=notice_data-attach],
-.form_notice #notice_data-attach {
+.form_notice .attach-label,
+.form_notice .attach {
position:absolute;
top:25px;
right:10.5%;
cursor:pointer;
}
-.form_notice label[for=notice_data-attach] {
+.form_notice .attach-label {
text-indent:-9999px;
width:16px;
height:16px;
}
-.form_notice #notice_data-attach {
+.form_notice .attach {
padding:0;
height:16px;
}
@@ -606,7 +606,7 @@ width:81.5%;
margin-bottom:0;
line-height:1.618;
}
-.form_notice #notice_data-attach_selected code {
+.form_notice code {
float:left;
width:80%;
display:block;
@@ -614,7 +614,7 @@ overflow:auto;
margin-right:2.5%;
font-size:1.1em;
}
-.form_notice #notice_data-attach_selected button.close {
+.form_notice button.close {
float:right;
font-size:0.8em;
}
diff --git a/theme/default/css/display.css b/theme/default/css/display.css
index 5e3748cb7..44dc9a7c3 100644
--- a/theme/default/css/display.css
+++ b/theme/default/css/display.css
@@ -154,14 +154,15 @@ color:#333333;
.entity_actions .dialogbox input {
color:#000000;
}
-.form_notice label[for=notice_data-attach] {
+.form_notice .attach-label {
background-position:0 -328px;
}
-.form_notice #notice_data-attach {
+.form_notice .attach {
+position: absolute;
opacity:0;
}
-.form_notice label[for=notice_data-attach],
+.form_notice .attach-label,
#export_data li a.rss,
#export_data li a.atom,
#export_data li a.foaf,