Ticket #6361: miltiFileAttach.patch
| File miltiFileAttach.patch, 8.0 KB (added by Slava Zanko <slavazanko@…>, 5 years ago) |
|---|
-
trac/attachment.py
504 504 parent=get_resource_name(self.env, resource.parent)) 505 505 506 506 # Internal methods 507 508 def _do_save(self, req, attachment): 507 def _do_save_one(self, req, attachment, upload, description): 509 508 req.perm(attachment.resource).require('ATTACHMENT_CREATE') 510 509 511 if 'cancel' in req.args:512 req.redirect(get_resource_url(self.env, attachment.resource.parent,513 req.href))514 510 515 upload = req.args['attachment']516 511 if not hasattr(upload, 'filename') or not upload.filename: 517 512 raise TracError(_('No file uploaded')) 518 513 if hasattr(upload.file, 'fileno'): … … 540 535 raise TracError(_('No file uploaded')) 541 536 # Now the filename is known, update the attachment resource 542 537 # attachment.filename = filename 543 attachment.description = req.args.get('description', '')538 attachment.description = description 544 539 attachment.author = get_reporter_id(req, 'author') 545 540 attachment.ipnr = req.remote_addr 546 541 … … 569 564 attachment.filename = None 570 565 attachment.insert(filename, upload.file, size) 571 566 572 req.redirect(get_resource_url(self.env, attachment.resource(id=None), 567 def _do_save_many(self,req, attachment): 568 curr_attach = 0 569 while curr_attach < int(req.args['multiple_attachments']): 570 upload=req.args['attachment-%d' % curr_attach] 571 if hasattr(upload, 'filename') and upload.filename: 572 attachment.filename = None 573 self._do_save_one(req, attachment, upload, req.args.get('description-%d' % curr_attach, '')) 574 curr_attach=curr_attach+1 575 576 def _do_save(self, req, attachment): 577 req.perm(attachment.resource).require('ATTACHMENT_CREATE') 578 579 if 'cancel' in req.args: 580 req.redirect(get_resource_url(self.env, attachment.resource.parent, 581 req.href)) 582 583 if 'multiple_attachments' in req.args: 584 self._do_save_many(req, attachment) 585 req.redirect(get_resource_url(self.env, attachment.resource(id=None), 573 586 req.href)) 587 # req.redirect(context.parent.resource_href()) 588 else: 589 self._do_save_one(req, attachment, req.args['attachment'], req.args.get('description', '')) 590 # Redirect the user to list of attachments (must add a trailing '/') 591 req.redirect(get_resource_url(self.env, attachment.resource(id=None), 592 req.href)) 574 593 594 595 596 #----------------------------------------------------------------------------------------------- 597 575 598 def _do_delete(self, req, attachment): 576 599 req.perm(attachment.resource).require('ATTACHMENT_DELETE') 577 600 -
trac/htdocs/js/trac.js
69 69 function getAncestorByTagName(elem, tagName) { 70 70 return $(elem).parents(tagName).get(0); 71 71 } 72 var ATTACHFILE_COUNTER=0; 73 74 function manageMultipleAttachFields(_obj){ 75 var count = document.getElementById("multiAttach_count"); 76 if (_obj.value == '') { 77 if($("#multiAttach_tbody").get(0).rows.length == 1) return; 78 $("#multiAttach_tbody").get(0).deleteRow(_obj.getAttribute("attachNum")*1); 79 ATTACHFILE_COUNTER=0; 80 $("#multiAttach_tbody tr").each(function(index, element){ 81 $("input", $("td", element).get(0)) 82 .attr("attachnum",ATTACHFILE_COUNTER) 83 .attr("id","multiAttach_attachment"+ATTACHFILE_COUNTER) 84 .get(0).name = "attachment-"+ATTACHFILE_COUNTER; 85 86 $("input", $("td", element).get(0)) 87 .attr("id","multiAttach_description"+ATTACHFILE_COUNTER) 88 .get(0).name = "description-"+ATTACHFILE_COUNTER; 89 90 ATTACHFILE_COUNTER++; 91 }); 92 count.value = count.value*1-1; 93 } else { 94 if ($(_obj).attr("attachnum") != count.value-1) return; 95 var tr = $("#multiAttach_tbody").get(0).insertRow(-1); 96 var td = tr.insertCell(-1); 97 td.innerHTML='<input type="file" id="multiAttach_attachment-'+count.value+'" attachnum="'+count.value+'" name="attachment-'+count.value+'" onchange="manageMultipleAttachFields(this);"/>'; 98 var td = tr.insertCell(-1); 99 td.innerHTML='<input type="text" id="multiAttach_description-'+count.value+'" name="description-'+count.value+'" size="60" />'+"\n"; 100 count.value = count.value*1+1; 101 } 102 } 103 No newline at end of file -
trac/__init__.py
12 12 # history and logs, available at http://trac.edgewall.org/log/. 13 13 14 14 __version__ = __import__('pkg_resources').get_distribution('Trac').version 15 -
trac/templates/attachment.html
13 13 <body py:with="parent = attachments and attachments.parent or 14 14 attachment.resource.parent"> 15 15 16 <div id="ctxtnav" class="nav"> 17 <h2>Attachment Navigation</h2> 18 <ul> 19 <li class="last"> 20 <a href="${chrome.links.up[0].href}">${_("Back to %(parent)s", parent=name_of(parent))}</a> 21 </li> 22 </ul> 23 </div> 24 25 <div py:choose="mode" id="content" class="attachment"> 26 <py:when test="'new'"> 27 <h1>Add Attachment to <a href="${url_of(parent)}">${name_of(parent)}</a></h1> 28 <form id="attachment" method="post" enctype="multipart/form-data" action=""> 16 <py:def function="attach_oneFile()"> 29 17 <div class="field"> 30 18 <label>File:<br /><input type="file" name="attachment" /></label> 31 19 </div> … … 49 37 </div> 50 38 <br /> 51 39 </fieldset> 40 41 </py:def> 42 <py:def function="attach_multiFile()"> 43 <table><thead> 44 <tr><th align="left">File</th><th align="left">Description</th></tr> 45 </thead> 46 <tbody id="multiAttach_tbody"> 47 <tr> 48 <td><input type="file" id="multiAttach_attachment-0" attachnum="0" name="attachment-0" onchange="manageMultipleAttachFields(this);"/></td> 49 <td><input type="text" id="multiAttach_description-0" name="description-0" size="60" /></td> 50 </tr> 51 </tbody></table> 52 <input type="hidden" id="multiAttach_count" name="multiple_attachments" value="1" /> 53 54 <fieldset> 55 <legend>Attachment Info</legend> 56 <py:if test="authname == 'anonymous'"> 57 <div class="field"> 58 <label>Your email or username:<br /> 59 <input type="text" name="author" size="30" value="$author" /> 60 </label> 61 </div> 62 </py:if> 63 <div class="options"> 64 <label><input type="checkbox" name="replace" /> 65 Replace existing attachments of the same name</label> 66 </div> 67 <br /> 68 </fieldset> 69 70 </py:def> 71 72 <div id="ctxtnav" class="nav"> 73 <h2>Attachment Navigation</h2> 74 <ul> 75 <li class="last"> 76 <a href="${chrome.links.up[0].href}">${_("Back to %(parent)s", parent=name_of(parent))}</a> 77 </li> 78 </ul> 79 </div> 80 81 <div py:choose="mode" id="content" class="attachment"> 82 <py:when test="'new'"> 83 <h1>Add Attachment to <a href="${url_of(parent)}">${name_of(parent)}</a></h1> 84 <form id="attachment" method="post" enctype="multipart/form-data" action=""> 85 86 ${attach_multiFile()} 52 87 <div class="buttons"> 53 88 <input type="hidden" name="action" value="new" /> 54 89 <input type="hidden" name="realm" value="$parent.realm" /> … … 57 92 <input type="submit" name="cancel" value="Cancel" /> 58 93 </div> 59 94 </form> 95 60 96 </py:when> 61 97 62 98 <py:when test="'delete'">
