Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
Order code and change 'Download' to a button
Browse files Browse the repository at this point in the history
  • Loading branch information
aguilerapy committed Mar 31, 2020
1 parent d58fdf7 commit 67073ff
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 56 deletions.
4 changes: 2 additions & 2 deletions default/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@
.content-wrap.ocp-content {
padding-bottom: 2.5rem;
}
.btn.btn-primary.download-drive {
.btn.btn-primary.btn-download {
line-height: 0;
color: #9baf00;
background-color: transparent;
border-color: transparent;
padding: 0px 0px;
}
.btn.btn-primary.download-drive:hover {
.btn.btn-primary.btn-download:hover {
text-decoration-line: underline;
color: #6D812B;
}
17 changes: 12 additions & 5 deletions default/static/js/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ var app = {};
});
$.ajax($('#fileupload').attr('data-perform-action'), {data: actionParams})
.done(function (data) {
$('.response-success .file-size').html(utils.readableFileSize(data.size));
$('.response-success .download').attr('href', data.url);
$('.response-success .download-drive').attr('href', data.url + '?out=drive');
$('.response-success .f-file-size').html(utils.readableFileSize(data.size));
$('.response-success .f-file').attr('href', data.url);
$('.response-success .d-drive').attr('href', data.url + '?out=drive');
$('.response-success').removeClass('hidden');
if (data.hasOwnProperty('warnings') && data.warnings.length > 0) {
$('.response-warning.action-failed').removeClass('hidden');
Expand Down Expand Up @@ -172,9 +172,13 @@ var app = {};
;
}

function download() {
window.location = $(this).attr('href');
}

function saveDrive() {
showProcessingModal();
$.ajax($('.response-success .download-drive').attr('href'), { 'dataType': 'json' })
$.ajax($('.response-success .d-drive').attr('href'), { 'dataType': 'json' })
.done(function(data) {
$('.google-drive-success .file-google-name').html(data.name);
$('.google-drive-success .file-google-id').html(data.id);
Expand Down Expand Up @@ -206,8 +210,11 @@ var app = {};
/** upload call binding **/
$("#upload-button").click(upload);

/* click download button behaviour */
$('.f-file').click(download);

/* click save to Drive button behaviour */
$('#d-drive').click(saveDrive);
$('.d-drive').click(saveDrive);

/* add warning before closing/navigating away from page */
window.onload = function () {
Expand Down
8 changes: 5 additions & 3 deletions default/templates/default/base-uploader.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
{% block body %}
<div class="response-success alert alert-info hidden">
<b>{% trans "Success!" %}</b>
result.zip(<span class="file-size"></span>)
<a href="javascript:void(0)" class="download" target="_blank">{% trans "Download" %}</a>
result.zip(<span class="f-file-size"></span>)
<button type="button" class="btn btn-primary btn-download f-file">
<span>{% trans "Download" %}</span>
</button>
<span> / </span>
<button type="button" class="btn btn-primary download-drive" id="d-drive">
<button type="button" class="btn btn-primary btn-download d-drive">
<span>{% trans "Save to Google Drive" %}</span>
</button>
</div>
Expand Down
22 changes: 14 additions & 8 deletions default/templates/default/to-json.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
<b>{% trans "Success!" %}</b>
<ul>
<li>
result.zip (<span class="file-size-json"></span>)
<a href="javascript:void(0)" class="download-json">{% trans "Download" %}</a>
result.zip (<span class="f-file-size"></span>)
<button type="button" class="btn btn-primary btn-download f-file">
<span>{% trans "Download" %}</span>
</button>
<span> / </span>
<button type="button" class="btn btn-primary download-drive d-json" id="drive-json">
<button type="button" class="btn btn-primary btn-download d-drive">
<span>{% trans "Save to Google Drive" %}</span>
</button>
</li>
Expand Down Expand Up @@ -120,9 +122,9 @@
$('#processing-modal').modal('show');
$.ajax('/to-json/go/', { 'dataType': 'json' })
.done(function(data){
$('.response-success .download-json').attr('href', data.url);
$('.response-success .file-size-json').html(utils.readableFileSize(data.size));
$('.response-success .d-json').attr('href', data.url + '?out=drive');
$('.response-success .f-file').attr('href', data.url);
$('.response-success .f-file-size').html(utils.readableFileSize(data.size));
$('.response-success .d-drive').attr('href', data.url + '?out=drive');
$('.response-success').removeClass('hidden');
})
.fail(function(){
Expand All @@ -137,13 +139,17 @@
})
});

$('.f-file').click(function () {
window.location = $(this).attr('href');
});

/* Click drive json behaviour */
$('#drive-json').click(function(){
$('.d-drive').click(function(){
data
.submit()
.done(function(){
$('#processing-modal').modal('show');
$.ajax($('.response-success .d-json').attr('href'), { 'dataType': 'json' })
$.ajax($('.response-success .d-drive').attr('href'), { 'dataType': 'json' })
.done(function(data){
$('.google-drive-success .file-google-name').html(data.name);
$('.google-drive-success .file-google-id').html(data.id);
Expand Down
60 changes: 22 additions & 38 deletions default/templates/default/to-spreadsheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@
<b>{% trans "Success!" %}</b>
<ul>
<li>
result.xlsx (<span class="file-size-xlsx"></span>)
<a href="javascript:void(0)" class="download-xlsx">{% trans "Download" %}</a>
result.xlsx (<span class="f-size-xlsx"></span>)
<button type="button" class="btn btn-primary btn-download f-file f-xlsx">
<span>{% trans "Download" %}</span>
</button>
<span> / </span>
<button type="button" class="btn btn-primary download-drive d-xlsx" id="drive-xlsx">
<button type="button" class="btn btn-primary btn-download d-drive d-xlsx">
<span>{% trans "Save to Google Drive" %}</span>
</button>
</li>
<li>
result-csv.zip (<span class="file-size-csv"></span>)
<a href="javascript:void(0)" class="download-csv">{% trans "Download" %}</a>
result-csv.zip (<span class="f-size-csv"></span>)
<button type="button" class="btn btn-primary btn-download f-file f-csv">
<span>{% trans "Download" %}</span>
</button>
<span> / </span>
<button type="button" class="btn btn-primary download-drive d-csv" id="drive-csv">
<button type="button" class="btn btn-primary btn-download d-drive d-csv">
<span>{% trans "Save to Google Drive" %}</span>
</button>
</li>
Expand Down Expand Up @@ -120,10 +124,10 @@
$('#processing-modal').modal('show');
$.ajax('/to-spreadsheet/go/', { 'dataType': 'json' })
.done(function(data){
$('.response-success .download-xlsx').attr('href', data.xlsx.url);
$('.response-success .download-csv').attr('href', data.csv.url);
$('.response-success .file-size-xlsx').html(utils.readableFileSize(data.xlsx.size));
$('.response-success .file-size-csv').html(utils.readableFileSize(data.csv.size));
$('.response-success .f-xlsx').attr('href', data.xlsx.url);
$('.response-success .f-csv').attr('href', data.csv.url);
$('.response-success .f-size-xlsx').html(utils.readableFileSize(data.xlsx.size));
$('.response-success .f-size-csv').html(utils.readableFileSize(data.csv.size));
$('.response-success .d-xlsx').attr('href', data.xlsx.url + '?out=drive');
$('.response-success .d-csv').attr('href', data.csv.url + '?out=drive');
$('.response-success').removeClass('hidden');
Expand All @@ -149,38 +153,18 @@
});
});

/* Click drive xlsx behaviour */
$('#drive-xlsx').click(function(){
data
.submit()
.done(function(){
$('#processing-modal').modal('show');
$.ajax($('.response-success .d-xlsx').attr('href'), { 'dataType': 'json' })
.done(function(data){
$('.google-drive-success .file-google-name').html(data.name);
$('.google-drive-success .file-google-id').html(data.id);
$('.google-drive-success').removeClass('hidden');
$('.response-fail').addClass('hidden');
})
.fail(function(jqXHR, textStatus, errorThrown){
$('.response-fail').html(
'{% trans "<b>Error saving to Google Drive</b>: " %}'
+ ( jqXHR.responseText || textStatus ));
$('.response-fail').removeClass('hidden');
})
.always(function(){
$('#processing-modal').modal('hide');
});
})
});
$('.f-file').click(function () {
window.location = $(this).attr('href');
});

/* Click drive csv behaviour */
$('#drive-csv').click(function(){
data
/* Click drive xlsx behaviour */
$('.d-drive').click(function(){
url = $(this).attr('href')
data
.submit()
.done(function(){
$('#processing-modal').modal('show');
$.ajax($('.response-success .d-csv').attr('href'), { 'dataType': 'json' })
$.ajax(url, { 'dataType': 'json' })
.done(function(data){
$('.google-drive-success .file-google-name').html(data.name);
$('.google-drive-success .file-google-id').html(data.id);
Expand Down

0 comments on commit 67073ff

Please sign in to comment.