Ticket #2141: multiFileAttach.r9435.patch
| File multiFileAttach.r9435.patch, 7.5 KB (added by o.shirochenkov@…, 23 months ago) |
|---|
-
trac/attachment.py
594 594 595 595 # Internal methods 596 596 597 def _do_save (self, req, attachment):597 def _do_save_one(self, req, attachment, upload, description): 598 598 req.perm(attachment.resource).require('ATTACHMENT_CREATE') 599 599 600 if 'cancel' in req.args:601 req.redirect(get_resource_url(self.env, attachment.resource.parent,602 req.href))603 604 upload = req.args['attachment']605 600 if not hasattr(upload, 'filename') or not upload.filename: 606 601 raise TracError(_('No file uploaded')) 607 602 if hasattr(upload.file, 'fileno'): … … 629 624 raise TracError(_('No file uploaded')) 630 625 # Now the filename is known, update the attachment resource 631 626 # attachment.filename = filename 632 attachment.description = req.args.get('description', '')627 attachment.description = description 633 628 attachment.author = get_reporter_id(req, 'author') 634 629 attachment.ipnr = req.remote_addr 635 630 … … 667 662 attachment.filename = None 668 663 attachment.insert(filename, upload.file, size) 669 664 665 def _do_save_many(self,req, attachment): 666 curr_attach = 0 667 while curr_attach < int(req.args['multiple_attachments']): 668 upload=req.args['attachment-%d' % curr_attach] 669 if hasattr(upload, 'filename') and upload.filename: 670 attachment.filename = None 671 self._do_save_one(req, attachment, upload, req.args.get('description-%d' % curr_attach, '')) 672 curr_attach=curr_attach+1 673 674 def _do_save(self, req, attachment): 675 req.perm(attachment.resource).require('ATTACHMENT_CREATE') 676 677 if 'cancel' in req.args: 678 req.redirect(get_resource_url(self.env, attachment.resource.parent, 679 req.href)) 680 681 if 'multiple_attachments' in req.args: 682 self._do_save_many(req, attachment) 683 req.redirect(get_resource_url(self.env, attachment.resource(id=None), 684 req.href)) 685 else: 686 self._do_save_one(req, attachment, req.args['attachment'], req.args.get('description', '')) 687 # Redirect the user to list of attachments (must add a trailing '/') 670 688 req.redirect(get_resource_url(self.env, attachment.resource(id=None), 671 689 req.href)) 672 690 -
trac/htdocs/js/trac.js
105 105 } 106 106 107 107 })(jQuery); 108 109 var ATTACHFILE_COUNTER=0; 110 function manageMultipleAttachFields(_obj){ 111 if (_obj.value == '') { 112 if($("#multiAttach_tbody").get(0).rows.length == 1) return; 113 $("#multiAttach_tbody").get(0).deleteRow($(_obj).attr("attachnum")*1); 114 ATTACHFILE_COUNTER=0; 115 $("#multiAttach_tbody tr").each(function(index, element){ 116 $("input", $("td", element).get(0)) 117 .attr("attachnum",ATTACHFILE_COUNTER) 118 .get(0).name = "attachment-"+ATTACHFILE_COUNTER; 119 $("input", $("td", element).get(1)) 120 .get(0).name = "description-"+ATTACHFILE_COUNTER; 121 ATTACHFILE_COUNTER++; 122 }); 123 $("#multiAttach_count").get(0).value = $("#multiAttach_count").val()*1-1; 124 } else { 125 if ($(_obj).attr("attachnum") != $("#multiAttach_count").val()-1) return; 126 var tr = $("#multiAttach_tbody").get(0).insertRow(-1); 127 var td = tr.insertCell(-1); 128 $('<input type="file" onchange="manageMultipleAttachFields(this)">') 129 .attr("attachnum",$("#multiAttach_count").val()) 130 .appendTo(td) 131 .get(0).name = "attachment-"+$("#multiAttach_count").val(); 132 133 td = tr.insertCell(-1); 134 $('<input type="text">') 135 .attr("size",60) 136 .appendTo(td) 137 .get(0).name = "description-"+$("#multiAttach_count").val(); 138 $("#multiAttach_count").get(0).value = $("#multiAttach_count").val()*1+1; 139 } 140 } -
trac/templates/attachment.html
24 24 </head> 25 25 26 26 <body> 27 <div py:choose="mode" id="content" class="attachment"> 28 <py:when test="'new'"> 29 <h1>Add Attachment to <a href="${url_of(parent)}">${name_of(parent)}</a></h1> 30 <form id="attachment" method="post" enctype="multipart/form-data" action=""> 27 <py:def function="attach_oneFile()"> 28 <div class="field"> 29 <label>File:<br /><input type="file" name="attachment" /></label> 30 </div> 31 <fieldset> 32 <legend>Attachment Info</legend> 33 <py:if test="authname == 'anonymous'"> 31 34 <div class="field"> 32 <label> File<py:if test="max_size >= 0"> (size limit33 ${pretty_size(max_size)})</py:if>:<br/>34 <input type="file" name="attachment" /></label>35 <label>Your email or username:<br /> 36 <input type="text" name="author" size="30" value="$author" /> 37 </label> 35 38 </div> 39 </py:if> 40 <div class="field"> 41 <label>Description of the file (optional):<br /> 42 <input type="text" name="description" size="60" /></label> 43 </div> 44 <br /> 45 <div class="options"> 46 <label><input type="checkbox" name="replace" /> 47 Replace existing attachment of the same name</label> 48 </div> 49 <br /> 50 </fieldset> 51 </py:def> 52 <py:def function="attach_multiFile()"> 53 <table><thead> 54 <tr><th align="left">File</th><th align="left">Description</th></tr> 55 </thead> 56 <tbody id="multiAttach_tbody"> 57 <tr> 58 <td><input type="file" attachnum="0" name="attachment-0" onchange="manageMultipleAttachFields(this);"/></td> 59 <td><input type="text" name="description-0" size="60" /></td> 60 </tr> 61 </tbody></table> 62 <input type="hidden" id="multiAttach_count" name="multiple_attachments" value="1" /> 63 36 64 <fieldset> 37 65 <legend>Attachment Info</legend> 38 66 <py:if test="authname == 'anonymous'"> … … 42 70 </label> 43 71 </div> 44 72 </py:if> 45 <div class="field">46 <label>Description of the file (optional):<br />47 <input type="text" name="description" size="60" /></label>48 </div>49 <br />50 73 <py:if test="authname and authname != 'anonymous'"> 51 74 <div class="options"> 52 75 <label><input type="checkbox" name="replace" /> 53 Replace existing attachment of the same name</label>76 Replace existing attachments of the same name</label> 54 77 </div> 55 78 <br /> 56 79 </py:if> 57 80 </fieldset> 81 </py:def> 82 83 <div py:choose="mode" id="content" class="attachment"> 84 <py:when test="'new'"> 85 <h1>Add Attachment to <a href="${url_of(parent)}">${name_of(parent)}</a></h1> 86 <form id="attachment" method="post" enctype="multipart/form-data" action=""> 87 88 ${attach_multiFile()} 58 89 <div class="buttons"> 59 90 <input type="hidden" name="action" value="new" /> 60 91 <input type="hidden" name="realm" value="$parent.realm" />
