Commit 7a7eb8f4 authored by Luc Didry's avatar Luc Didry
Browse files

Make copy-all button disappear if there is no more links

parent 170546df
......@@ -13,11 +13,10 @@
return '<%== url_for('/')->to_abs() %>'+url;
}
function share(url) {
console.log(url);
new MozActivity({
name: "share",
name: 'share',
data: {
type: "url",
type: 'url',
number: 1,
url: url
}
......@@ -33,12 +32,12 @@
function modify(url, short) {
$.ajax({
url : url,
type : "POST",
type : 'POST',
data : {
'image_url' : '<%== url_for('/')->to_abs() %>'+short,
'format' : 'json',
'first-view' : ($("#first-view-"+short).prop('checked')) ? 1 : 0,
'delete-day' : $("#day-"+short).val()
'first-view' : ($('#first-view-'+short).prop('checked')) ? 1 : 0,
'delete-day' : $('#day-'+short).val()
},
success: function(data) {
alert(data.msg);
......@@ -50,7 +49,7 @@
}
function copyToClipboard(el) {
el = el.siblings('input');
var textArea = document.createElement("textarea");
var textArea = document.createElement('textarea');
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;
......@@ -84,7 +83,7 @@
$('.view-link-input').each(function(index) {
text.push($(this).val());
});
var textArea = document.createElement("textarea");
var textArea = document.createElement('textarea');
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;
......@@ -113,7 +112,14 @@
document.body.removeChild(textArea);
}
function build_message(success, msg) {
function evaluateCopyAll() {
setTimeout(function() {
if ($('.view-link-input').length === 0) {
$('#copy-all').parent().remove();
}
}, 5);
}
function buildMessage(success, msg) {
if(success) {
var thumb = (msg.thumb !== null) ? '<div class="col-sm-1"><img class="thumbnail img-responsive" alt="'+msg.filename+' thumbnail" src="'+msg.thumb+'"></div>' : ''
return '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><div class="row">'
......@@ -161,7 +167,7 @@
} else {
return '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><strong><%= l('Something bad happened') %></strong><br>'
+msg.filename
+"<br>"
+'<br>'
+msg.msg
+'</div>';
}
......@@ -173,7 +179,7 @@
allowedTypes: 'image/*',
maxFileSize: <%= $max_file_size %>,
onNewFile: function(id, file){
$(".messages").append('<div id="'+id+'-div">'+file.name+'<br><div class="progress"><div id="'+id+'"class="progress-bar progress-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"><span id="'+id+'-text" class="pull-left" style="padding-left: 10px;"> 0%</span></div></div></div>');
$('.messages').append('<div id="'+id+'-div">'+file.name+'<br><div class="progress"><div id="'+id+'"class="progress-bar progress-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"><span id="'+id+'-text" class="pull-left" style="padding-left: 10px;"> 0%</span></div></div></div>');
},
onUploadProgress: function(id, percent){
var percentStr = ' '+percent+'%';
......@@ -183,52 +189,56 @@
},
onUploadSuccess: function(id, data){
$('#'+id+'-div').remove();
if ($("#copy-all").length === 0) {
$(".messages").append('<div class="col-xs-12 col-sm-11 col-sm-offset-1"><a id="copy-all" href="#" class="btn btn-info" onClick="copyAllToClipboard();"><%= l('Copy all view links to clipboard') %></a></div>');
if ($('#copy-all').length === 0 && data.success) {
$('.messages').prepend('<div class="col-xs-12 col-sm-11 col-sm-offset-1"><a id="copy-all" href="#" class="btn btn-info" onClick="copyAllToClipboard();"><%= l('Copy all view links to clipboard') %></a></div>');
}
$(".messages").append(build_message(data.success, data.msg));
$('.messages').append(buildMessage(data.success, data.msg));
$('.close').unbind('click', evaluateCopyAll);
$('.close').on('click', evaluateCopyAll);
},
onUploadError: function(id, message){
$(".messages").append(build_message(false, ''));
$('.messages').append(buildMessage(false, ''));
},
onFileSizeError: function(file){
$(".messages").append(build_message(false, { filename: file.name, msg: '<%= l('The file exceed the size limit (%1)', $max_file_size) %>'}));
$('.messages').append(buildMessage(false, { filename: file.name, msg: '<%= l('The file exceed the size limit (%1)', $max_file_size) %>'}));
}
});
}
function upload_url() {
var val = $("#lutim-file-url").val();
if (val !== undefined && val !== "") {
$("#lutim-file-url").prop('disabled', 'disabled');
$(".hidden-spin").css('display', 'block');
console.log(val);
var val = $('#lutim-file-url').val();
if (val !== undefined && val !== '') {
$('#lutim-file-url').prop('disabled', 'disabled');
$('.hidden-spin').css('display', 'block');
$.ajax({
url : '<%== url_for('/') %>',
type : "POST",
type : 'POST',
data : {
'lutim-file-url' : val,
'format' : 'json',
'first-view' : ($("#first-view").prop('checked')) ? 1 : 0,
'crypt' : ($("#crypt").prop('checked')) ? 1 : 0,
'delete-day' : $("#delete-day").val()
'first-view' : ($('#first-view').prop('checked')) ? 1 : 0,
'crypt' : ($('#crypt').prop('checked')) ? 1 : 0,
'delete-day' : $('#delete-day').val()
},
success: function(data) {
$(".messages").append(build_message(data.success, data.msg));
$('.messages').append(buildMessage(data.success, data.msg));
if (data.success) {
$("#lutim-file-url").val('');
if ($('#copy-all').length === 0) {
$('.messages').prepend('<div class="col-xs-12 col-sm-11 col-sm-offset-1"><a id="copy-all" href="#" class="btn btn-info" onClick="copyAllToClipboard();"><%= l('Copy all view links to clipboard') %></a></div>');
}
$('#lutim-file-url').val('');
$('.close').unbind('click', evaluateCopyAll);
$('.close').on('click', evaluateCopyAll);
}
},
error: function() {
$(".messages").append(build_message(false, ''));
$('.messages').append(buildMessage(false, ''));
},
complete: function() {
$("#lutim-file-url").prop('disabled', '');
$(".hidden-spin").css('display', 'none');
$('#lutim-file-url').prop('disabled', '');
$('.hidden-spin').css('display', 'none');
}
});
} else {
console.log("fhdsjnf");
}
}
......@@ -237,11 +247,11 @@
fd.append('file', file);
fd.append('format', 'json');
fd.append('first-view', ($("#first-view").prop('checked')) ? 1 : 0);
fd.append('crypt', ($("#crypt").prop('checked')) ? 1 : 0);
fd.append('delete-day', ($("#delete-day").val()));
fd.append('first-view', ($('#first-view').prop('checked')) ? 1 : 0);
fd.append('crypt', ($('#crypt').prop('checked')) ? 1 : 0);
fd.append('delete-day', ($('#delete-day').val()));
$(".messages").append('<div id="1-div">'+file.name+'<br><div class="progress"><div id="1"class="progress-bar progress-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"><span id="1-text" class="pull-left" style="padding-left: 10px;"> 0%</span></div></div></div>');
$('.messages').append('<div id="1-div">'+file.name+'<br><div class="progress"><div id="1"class="progress-bar progress-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"><span id="1-text" class="pull-left" style="padding-left: 10px;"> 0%</span></div></div></div>');
// Ajax Submit
$.ajax({
url: '<%== url_for('/') %>',
......@@ -274,10 +284,10 @@
},
success: function (data, message, xhr){
$('#1-div').remove();
$(".messages").append(build_message(data.success, data.msg));
$('.messages').append(buildMessage(data.success, data.msg));
},
error: function (xhr, status, errMsg){
$(".messages").append(build_message(false, ''));
$('.messages').append(buildMessage(false, ''));
},
});
}
......@@ -294,12 +304,12 @@
}
};
$('document').ready(function() {
var firstview = ($("#first-view").prop('checked')) ? 1 : 0;
var deleteday = ($("#delete-day").prop('checked')) ? 1 : 0;
var firstview = ($('#first-view').prop('checked')) ? 1 : 0;
var deleteday = ($('#delete-day').prop('checked')) ? 1 : 0;
bindddz(firstview, deleteday);
$("#file-url-button").on("click", upload_url);
$('#file-url-button').on('click', upload_url);
$('#lutim-file-url').keydown( function(e) {
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
if(key == 13) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment