Skip to content
Snippets Groups Projects
orderbook.js 4.76 KiB
Newer Older
TonyFord's avatar
TonyFord committed
---
---
var OB={{ site.data.orderbook | jsonify }};

var CAT={{ site.data.categories | jsonify }};

var PR={{ site.data.price-sources | jsonify }};

var CUR={{ site.data.currencies | jsonify }};

function createQRCode(qrcode){

  var peer=qrcode.split(/\_/g)[1];

  if( OB[peer] == undefined ){
    alert( 'peer not found!' );
    return false;
  }

  if( OB[peer].user == undefined ){
    alert( 'user.yml of peer not found!' );
    return false;
  }

  if( OB[peer].user.faircoinaddress == undefined ){
    alert( 'faircoinaddress of peer not not found in user.yml!' );
    return false;
  }


  var url='faircoin:'+OB[peer].user.faircoinaddress+'?amount='+$('#'+qrcode).attr('data-price');

  if( window[qrcode].innerHTML == '' ){

    window[qrcode] = new QRCode( qrcode , {
        text: url,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.M
    });
  } else {
    window[qrcode].clear(); // clear the code.
    window[qrcode].makeCode(url); // make another code.
  }

  $('.qrcode').toggleClass('invisble',true);
  $('#'+qrcode).parent().toggleClass('invisble');

}


$(document).ready(
  function(){
    showOrderbook();
  }
);

function showOrderbook(){
  var tmp='';
  $.each( OB,
    function( peer,data ){
      if( data.user == undefined ) return;
      $.each( data,
        function(i,order){
          if( i == 'user' ) return;
          if( order.tags == undefined ) return;
          tmp+='<div class="orderlist-div tag-'+order.tags.join(' tag-')+' order-'+i+'">';

          tmp+='  <div class="orderlist-date">'
TonyFord's avatar
TonyFord committed
          tmp+='    <div class="image"><small>'+( new Date(order.time * 1000).toJSON().replace(/T/g,' ').slice(0,-8) )+'</small>';
TonyFord's avatar
TonyFord committed
          if( order.image != undefined && order.image != null ){
            tmp+='    <img src="'+order.image+'">';
          }
          tmp+='    </div>';
          tmp+='  </div>';

          tmp+='  <div class="orderlist-title">';
          tmp+='    <a href="form.html?lang='+data.user.lang+'&tags='+order.tags.slice(0,2).join(',')+'&bid-ask='+order['bid-ask']+'&headline='+encodeURI(order.headline)+'&condition='+order.condition+'&description='+encodeURI(order.description)+'&unit='+order.unit+'&min-size='+order['min-size']+'&max-size='+order['max-size']+'&price-reference='+order['price-reference']+'&price-per-unit='+order['price-per-unit']+'"><span class="feather-icon icon-copy" title="Duplicate and Edit Order"></span></a> '+i+' -';
          tmp+='    <u>'+order.headline+'</u><br><small> @'+peer+' / <span class="user-address" onclick="createQRCode(\'qrcode_'+peer+'_'+i+'\')">'+data.user.faircoinaddress+'</span></small>';
          tmp+='    <br>';
          tmp+='    <small><bidask>'+(( order['bid-ask'] == 'ask') ? '<span class="feather-icon icon-help-circle"></span> ask' : '<span class="feather-icon icon-alert-circle"></span> bid' )+'</bidask> <lang><span class="feather-icon icon-tag"></span>'+data.user.lang+'</lang> <a href="https://www.latlong.net/c/?lat='+data.user.latitude.toFixed(6)+'&long='+data.user.longitude.toFixed(6)+'" target="latlong" title="latitude:'+data.user.latitude.toFixed(6)+' | longitude: '+data.user.longitude.toFixed(6)+'"><span class="d-none distance-data">'+data.user.latitude+','+data.user.longitude+','+data.user.country+'</span> <span class="distance"></span></a> <used><span class="feather-icon icon-tag"></span>'+order.condition+'</used>';
          tmp+=order.tags.map( (a,i) => '<tags class="li-tags li-tag-'+a+' clickable" title="'+a+'" onclick="getByTag( [\''+order.tags[0]+'\', \''+a+'\'], $(this).hasClass(\'active\') )">'+(( i == 2 ) ? '<br>' : '')+'<span class="feather-icon icon-tag"></span>'+(( i == 0 ) ? CAT[a].title[ln] : (( CAT[order.tags[0]].Tags[a] != undefined ) ? CAT[order.tags[0]].Tags[a][ln] : ' <custom>'+a+'</custom>' ) ) +'</tags>' ).join(' ');
          tmp+='    </small>';
          tmp+='    <div><small>'+order.description+'</small></div>';
          tmp+='  </div>';

          var price_ref=PR.FAIRO.last.toFixed(2);

          tmp+='  <div class="orderlist-price"><font class="faircoin-price">'+(order['price-per-unit'].toFixed(2))+' '+order['price-reference']+'</font><br>'+(( order['min'] > 0 ) ? order['min']+'..' : '')+order['max']+' '+order.unit+'<br>( '+(order['price-per-unit']/price_ref).toFixed(0)+' FAIR / '+order.unit+' )<br>( '+price_ref+' '+order['price-reference']+' / FAIR )<br><i><a href="'+CUR.FAIR['price-sources'].FAIRO.www+'"></a></i><br><br><br>';
          tmp+='  </div>';

          tmp+='  <div class="qrcode invisble">';
          tmp+='    <div onclick="$(this).parent().toggleClass(\'invisble\')" id="qrcode_'+peer+'_'+i+'" data-price="'+( Math.round(order['price-per-unit']/price_ref).toFixed(8) )+'" class=""></div>';
          tmp+='  </div>';

          tmp+='</div>';
        }
      );
    }
  );

  $('.orders').html(tmp);

}