files_upload.mako
222 lines
| 7.6 KiB
| application/x-mako
|
MakoHtmlLexer
r3710 | <%inherit file="/base/base.mako"/> | |||
<%def name="title()"> | ||||
r3754 | ${_('{} Files Upload').format(c.repo_name)} | |||
r3710 | %if c.rhodecode_name: | |||
· ${h.branding(c.rhodecode_name)} | ||||
%endif | ||||
</%def> | ||||
<%def name="menu_bar_nav()"> | ||||
${self.menu_items(active='repositories')} | ||||
</%def> | ||||
r3754 | <%def name="breadcrumbs_links()"></%def> | |||
r3710 | ||||
<%def name="menu_bar_subnav()"> | ||||
${self.repo_menu(active='files')} | ||||
</%def> | ||||
<%def name="main()"> | ||||
r3754 | ||||
r3710 | <div class="box"> | |||
r3754 | ## Template for uploads | |||
<div style="display: none" id="tpl-dropzone"> | ||||
<div class="dz-preview dz-file-preview"> | ||||
<div class="dz-details"> | ||||
<div class="dz-filename"> | ||||
<span data-dz-name></span> | ||||
</div> | ||||
<div class="dz-filename-size"> | ||||
<span class="dz-size" data-dz-size></span> | ||||
r3710 | ||||
r3754 | </div> | |||
<div class="dz-sending" style="display: none">${_('Uploading...')}</div> | ||||
<div class="dz-response" style="display: none"> | ||||
${_('Uploaded')} 100% | ||||
</div> | ||||
</div> | ||||
<div class="dz-progress"> | ||||
<span class="dz-upload" data-dz-uploadprogress></span> | ||||
</div> | ||||
<div class="dz-error-message"> | ||||
</div> | ||||
</div> | ||||
r3710 | </div> | |||
r3754 | <div class="edit-file-title"> | |||
r5274 | % if c.replace_binary: | |||
<span class="title-heading">${_('Replace content of')} <b>${c.f_path}</b> @ <code>${h.show_id(c.commit)}</code></span> | ||||
% else: | ||||
<span class="title-heading">${_('Upload new file')} @ <code>${h.show_id(c.commit)}</code></span> | ||||
% endif | ||||
r3755 | % if c.commit.branch: | |||
<span class="tag branchtag"> | ||||
<i class="icon-branch"></i> ${c.commit.branch} | ||||
</span> | ||||
% endif | ||||
r3754 | </div> | |||
r5274 | % if not c.replace_binary: | |||
<% form_url = h.route_path('repo_files_upload_file', repo_name=c.repo_name, commit_id=c.commit.raw_id, f_path=c.f_path) %> | ||||
<div class="edit-file-fieldset"> | ||||
<div class="path-items"> | ||||
<ul class="tooltip" title="Repository path to store uploaded files. To change it, navigate to different path and click upload from there."> | ||||
<li class="breadcrumb-path"> | ||||
<div> | ||||
<a href="${h.route_path('repo_files', repo_name=c.repo_name, commit_id=c.commit.raw_id, f_path='')}"><i class="icon-home"></i></a> / | ||||
<a href="${h.route_path('repo_files', repo_name=c.repo_name, commit_id=c.commit.raw_id, f_path=c.f_path)}">${c.f_path}</a>${('/' if c.f_path else '')} | ||||
</div> | ||||
</li> | ||||
<li class="location-path"> | ||||
r3754 | ||||
r5274 | </li> | |||
</ul> | ||||
</div> | ||||
r3710 | </div> | |||
r5274 | % else: | |||
<% form_url = h.route_path('repo_files_replace_binary', repo_name=c.repo_name, commit_id=c.commit.raw_id, f_path=c.f_path) %> | ||||
% endif | ||||
r3754 | ||||
<div class="upload-form table"> | ||||
r3882 | <div> | |||
r3710 | ||||
r4449 | <div class="dropzone-wrapper" id="file-uploader" style="border: none; padding: 40px 0"> | |||
r3754 | <div class="dropzone-pure"> | |||
<div class="dz-message"> | ||||
<i class="icon-upload" style="font-size:36px"></i></br> | ||||
r5274 | % if not c.replace_binary: | |||
${_("Drag'n Drop files here or")} <span class="link">${_('Choose your files')}</span>.<br> | ||||
% else: | ||||
${_("Drag'n Drop file here or")} <span class="link">${_('Choose your file')}</span>.<br> | ||||
% endif | ||||
r3754 | </div> | |||
</div> | ||||
r3710 | </div> | |||
</div> | ||||
</div> | ||||
r3754 | <div class="upload-form edit-file-fieldset"> | |||
<div class="fieldset"> | ||||
<div class="message"> | ||||
<textarea id="commit" name="message" placeholder="${c.default_message}"></textarea> | ||||
r3710 | </div> | |||
r3754 | </div> | |||
<div class="pull-left"> | ||||
${h.submit('commit_btn',_('Commit changes'), class_="btn btn-small btn-success")} | ||||
r3710 | </div> | |||
</div> | ||||
r3754 | ##${h.end_form()} | |||
r3710 | ||||
r3754 | <div class="file-upload-transaction-wrapper" style="display: none"> | |||
<div class="file-upload-transaction"> | ||||
r4302 | <h3>${_('Committing...')}</h3> | |||
r3754 | <p>${_('Please wait while the files are being uploaded')}</p> | |||
<p class="error" style="display: none"> | ||||
</p> | ||||
<i class="icon-spin animate-spin"></i> | ||||
<p></p> | ||||
r3710 | </div> | |||
r3754 | </div> | |||
r3710 | </div> | |||
r3754 | ||||
r3710 | <script type="text/javascript"> | |||
r3754 | $(document).ready(function () { | |||
r3710 | ||||
r3754 | //see: https://www.dropzonejs.com/#configuration | |||
myDropzone = new Dropzone("div#file-uploader", { | ||||
url: "${form_url}", | ||||
headers: {"X-CSRF-Token": CSRF_TOKEN}, | ||||
paramName: function () { | ||||
return "files_upload" | ||||
}, // The name that will be used to transfer the file | ||||
parallelUploads: 20, | ||||
maxFiles: 20, | ||||
uploadMultiple: true, | ||||
//chunking: true, // use chunking transfer, not supported at the moment | ||||
//maxFilesize: 2, // in MBs | ||||
autoProcessQueue: false, // if false queue will not be processed automatically. | ||||
createImageThumbnails: false, | ||||
previewTemplate: document.querySelector('#tpl-dropzone').innerHTML, | ||||
accept: function (file, done) { | ||||
done(); | ||||
}, | ||||
init: function () { | ||||
this.on("addedfile", function (file) { | ||||
r3710 | ||||
r3754 | }); | |||
this.on("sending", function (file, xhr, formData) { | ||||
formData.append("message", $('#commit').val()); | ||||
$(file.previewElement).find('.dz-sending').show(); | ||||
}); | ||||
r3710 | ||||
r3754 | this.on("success", function (file, response) { | |||
$(file.previewElement).find('.dz-sending').hide(); | ||||
$(file.previewElement).find('.dz-response').show(); | ||||
if (response.error !== null) { | ||||
$('.file-upload-transaction-wrapper .error').html('ERROR: {0}'.format(response.error)); | ||||
$('.file-upload-transaction-wrapper .error').show(); | ||||
$('.file-upload-transaction-wrapper i').hide() | ||||
} | ||||
var redirect_url = response.redirect_url || '/'; | ||||
window.location = redirect_url | ||||
r3710 | ||||
r3754 | }); | |||
this.on("error", function (file, errorMessage, xhr) { | ||||
var error = null; | ||||
r3710 | ||||
r3754 | if (xhr !== undefined){ | |||
var httpStatus = xhr.status + " " + xhr.statusText; | ||||
r3994 | if (xhr !== undefined && xhr.status >= 500) { | |||
r3754 | error = httpStatus; | |||
} | ||||
} | ||||
r3710 | ||||
r3754 | if (error === null) { | |||
error = errorMessage.error || errorMessage || httpStatus; | ||||
} | ||||
$(file.previewElement).find('.dz-error-message').html('ERROR: {0}'.format(error)); | ||||
}); | ||||
} | ||||
}); | ||||
r3710 | ||||
r3754 | $('#commit_btn').on('click', function(e) { | |||
e.preventDefault(); | ||||
var button = $(this); | ||||
if (button.hasClass('clicked')) { | ||||
button.attr('disabled', true); | ||||
} else { | ||||
button.addClass('clicked'); | ||||
} | ||||
r3710 | ||||
r3754 | var files = myDropzone.getQueuedFiles(); | |||
if (files.length === 0) { | ||||
alert("Missing files"); | ||||
e.preventDefault(); | ||||
} | ||||
$('.upload-form').hide(); | ||||
$('.file-upload-transaction-wrapper').show(); | ||||
myDropzone.processQueue(); | ||||
}); | ||||
r3710 | }); | |||
</script> | ||||
</%def> | ||||