// ESTE SE USA PARA HTML RENDERING
function reparaFechas(){
var locale = "en";
$('.tiempoLocalLargo').each(function(){
if(typeof($(this).attr('locale'))!='undefined'){
locale = $(this).attr('locale');
}
var cuando = String($(this).text())+' Z';
var huy = cuando.replace(" ","T");
var momento = moment(huy);
momento.locale(locale);
$(this).text(momento.format('LLLL'));
});
$('.tiempoLocalCorto').each(function(){
var cuando = String($(this).text())+' Z';
var huy = cuando.replace(" ","T");
$(this).text(moment(huy).locale(locale).format('D/MM/YYYY'));
});
$('.tiempoLocalLargo2').each(function(){
var cuando = String($(this).text())+' Z';
var huy = cuando.replace(" ","T");
$(this).text(moment(huy).locale(locale).format('D/MM/YYYY h:mm a'));
});
$('.tiempoLocalFromNow').each(function(){
var cuando = String($(this).text())+' Z';
var huy = cuando.replace(" ","T");
$(this).text(moment(huy).locale(locale).fromNow(true));
});
$(".soyMoneda").each(function() {
var text = $(this).text().trim();
var number = Number(text.replace(/[^0-9.-]+/g, ""));
if (!isNaN(number) && text.match(/[0-9]/)) {
$(this).text(' $ ' + number.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"));
}
// else: leave the text as-is
});
$('.soyMonedaPDFonly').each(function(){
var currency = String($(this).text());
var number = Number(currency.replace(/[^0-9.-]+/g,""));
$(this).text(' $ ' +parseFloat(number, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString());
});
$("[type=file]:not([accept*='image/*'])").on("change", function() {
var fieldId = $(this).attr('id') + '-';
var currentId = $(this).attr('id');
$(".nuevoFile." + fieldId).remove();
$(".overwrite." + fieldId).remove();
var $papa = $(this);
var antiguos = ($(this).hasClass('singleFile')) ? 0 : $papa.next("p.help-block").has("a").length;
var files = this.files;
var totalSize = 0;
if (files.length > 10) {
bootbox.alert({
title: "Too many files!",
message: "Please upload max 10 files at a time.
You may revisit this record and upload more files later."
});
$(this).val('');
return;
}
if (antiguos == 0) {
$papa.next().text('');
}
$.each(files, function(i) {
totalSize += (parseFloat(files[i].size) / 1024000);
// Display the filename (like before)
var newFileEl = $("")
.addClass("nuevoFile " + fieldId)
.text(files[i].name)
.appendTo($papa.next());
// Upload if total size limit not exceeded
if (totalSize <= 150) {
uploadFileToS3(files[i], currentId, newFileEl);
}
});
if ($(this).val() != "" && antiguos > 0) {
$papa.next().after(
"" +
"" +
"" +
""
);
} else if ($(this).val() == "" && antiguos == 0) {
$(this).next().text('No file selected');
}
// Check total size limit
if (totalSize > 150) {
var totalString = totalSize.toFixed(1).toString();
bootbox.alert({
title: "Total file size is too large",
message:
"Maximum upload size per submit: 150Mb
" +
"Current file size: " + totalString + "Mb
" +
"Try uploading in multiple submits."
});
$(this).val(''); // reset input
$(".nuevoFile." + fieldId).remove(); // remove displayed files
}
});
$("[type=file][accept*='image/*']").on("change", function(){//este se usara en el q SOLO acepta imagenes
var fieldId = $(this).attr('id')+'-';
var currentId = $(this).attr('id');
$(".nuevoFile."+fieldId).remove();
$(".overwrite."+fieldId).remove();
var $papa = $(this);
var antiguos = ($(this).hasClass('singleFile'))? 0 : $papa.next("p.help-block").has("a,img").length; //para singleFiles debo (mas abajo) borrar todos los files y no dar opcion de overwrite
var files = this.files;
var totalSize = 0;
if(files.length>10){
bootbox.alert({title:"Too many files!",
message:"Please upload max 10 files at a time.
You may revisit this record and upload more files later."});
$(this).val('');
}else{
if(antiguos==0){
$papa.next().text('');
}
$.each( files, function(i) {
var reader = new FileReader();
reader.onload = function(event) {
var clase = "uploadedImg nuevoFile" + fieldId
var nuevaFoto = $($.parseHTML('
')).attr('src', event.target.result).attr('class', clase).attr('onclick',"openTagger($(this));").attr('data-filename',files[i].name).appendTo($papa.next());
uploadFileToS3(files[i],currentId,nuevaFoto);//para mandar los files a S3
}
reader.readAsDataURL(files[i]);//aƱadir foto
en vez de un a tag
totalSize += (parseFloat(files[i].size)/1024000);
});
if($(this).val()!=""){//si subieron files muestre el 'click to tag' prompt
$('div.tagprompt').removeClass('hidden');
}
if($(this).val()!="" && antiguos>0){
$papa.next().after("");
}else if(($(this).val()=="" && antiguos==0)){
$(this).next().text('No file selected');
$('div.tagprompt').addClass('hidden');//remove el prompt de tagger fotos
}
if(totalSize>150){
var totalString = totalSize.toFixed(1).toString();
bootbox.alert({title:"Total file size is too large",
message:"Maximum upload size per submit: 150Mb
Current file size: " + totalString + "Mb
Try uploading in multiple submits."});
}
}
});
}
function datesFormatter(value, row, index, field) {
var cuando = String(value)+' Z';
var huy = cuando.replace(" ","T");
return moment(huy).format('YYYY-MM-DD HH:mm:ss');
}
function currencyFormatter(value, row, index, field) {
if (value == null || value === '') {
return '';
}
var currency = value.toString();
var number = Number(currency.replace(/[^0-9.-]+/g, ""));
return ' $ ' + parseFloat(number, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
}
function pdfConTimeZone(url) {
var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
var locale = window.navigator.userLanguage || window.navigator.language;
window.location = url + '&timeZone=' +timeZone+ '&locale=' +locale;
}