Ticket #2141: miltiFileAttach.r6165.patch
| File miltiFileAttach.r6165.patch, 7.1 KB (added by Slava Zanko <slavaz>, 12 months ago) |
|---|
-
trac/attachment.py
505 505 506 506 # Internal methods 507 507 508 def _do_save (self, req, attachment):508 def _do_save_one(self, req, attachment, upload, description): 509 509 req.perm(attachment.resource).require('ATTACHMENT_CREATE') 510 510 511 if 'cancel' in req.args:512 req.redirect(get_resource_url(self.env, attachment.resource.parent,513 req.href))514 511 515 upload = req.args['attachment']516 512 if not hasattr(upload, 'filename') or not upload.filename: 517 513 raise TracError(_('No file uploaded')) 518 514 if hasattr(upload.file, 'fileno'): … … 540 536 raise TracError(_('No file uploaded')) 541 537 # Now the filename is known, update the attachment resource 542 538 # attachment.filename = filename 543 attachment.description = req.args.get('description', '')539 attachment.description = description 544 540 attachment.author = get_reporter_id(req, 'author') 545 541 attachment.ipnr = req.remote_addr 546 542 … … 569 565 attachment.filename = None 570 566 attachment.insert(filename, upload.file, size) 571 567 572 req.redirect(get_resource_url(self.env, attachment.resource(id=None), 568 def _do_save_many(self,req, attachment): 569 curr_attach = 0 570 while curr_attach < int(req.args['multiple_attachments']): 571 upload=req.args['attachment-%d' % curr_attach] 572 if hasattr(upload, 'filename') and upload.filename: 573 attachment.filename = None 574 self._do_save_one(req, attachment, upload, req.args.get('description-%d' % curr_attach, '')) 575 curr_attach=curr_attach+1 576 577 def _do_save(self, req, attachment): 578 req.perm(attachment.resource).require('ATTACHMENT_CREATE') 579 580 if 'cancel' in req.args: 581 req.redirect(get_resource_url(self.env, attachment.resource.parent, 582 req.href)) 583 584 if 'multiple_attachments' in req.args: 585 self._do_save_many(req, attachment) 586 req.redirect(get_resource_url(self.env, attachment.resource(id=None), 573 587 req.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 575 594 def _do_delete(self, req, attachment): 576 595 req.perm(attachment.resource).require('ATTACHMENT_DELETE') -
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 function manageMultipleAttachFields(_obj){ 74 if (_obj.value == '') { 75 if($("#multiAttach_tbody").get(0).rows.length == 1) return; 76 $("#multiAttach_tbody").get(0).deleteRow($(_obj).attr("attachnum")*1); 77 ATTACHFILE_COUNTER=0; 78 $("#multiAttach_tbody tr").each(function(index, element){ 79 $("input", $("td", element).get(0)) 80 .attr("attachnum",ATTACHFILE_COUNTER) 81 .get(0).name = "attachment-"+ATTACHFILE_COUNTER; 82 $("input", $("td", element).get(1)) 83 .get(0).name = "description-"+ATTACHFILE_COUNTER; 84 ATTACHFILE_COUNTER++; 85 }); 86 $("#multiAttach_count").get(0).value = $("#multiAttach_count").val()*1-1; 87 } else { 88 if ($(_obj).attr("attachnum") != $("#multiAttach_count").val()-1) return; 89 var tr = $("#multiAttach_tbody").get(0).insertRow(-1); 90 var td = tr.insertCell(-1); 91 $('<input type="file" onchange="manageMultipleAttachFields(this)">') 92 .attr("attachnum",$("#multiAttach_count").val()) 93 .appendTo(td) 94 .get(0).name = "attachment-"+$("#multiAttach_count").val(); 95 96 td = tr.insertCell(-1); 97 $('<input type="text">') 98 .attr("size",60) 99 .appendTo(td) 100 .get(0).name = "description-"+$("#multiAttach_count").val(); 101 $("#multiAttach_count").get(0).value = $("#multiAttach_count").val()*1+1; 102 } 103 } -
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" attachnum="0" name="attachment-0" onchange="manageMultipleAttachFields(this);"/></td> 49 <td><input type="text" 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" />
