3/1/2016 - 9:46 AM

Arigato Gozaimas Kato

Arigato Gozaimas Kato


//Load auction data from Firebase (FB) 

thisAuction.on('value',  function(snapshot) {  
var setTime = snapshot.val().times; 
var setIncrement = snapshot.val().increment;     
var setItemImage = snapshot.val().image;     
var setItem = snapshot.val().item;     
var setItemDescription = snapshot.val().description;     
var setBidders = snapshot.val().bidders;     
var setBestBid = snapshot.val().bestBid; 

$('#timer').text(setTime); //countdown defined by creator 

// if (($('#timer').text())*1 ===0){ alert("Auction is not active yet");}                   

//Each time user clicks beats current amount by a constant increment defined by auction creator
 ui.on('click','#doBid',   function(event) {

var currentBestBid = ($('#currentBestBid').text())*1;
var increment = ($('#itemIncrement').text())*1;
var currentBid = currentBestBid+increment;  //What if 'n' users are pushing at the same time ? Will data be up to date?                            
var pushAvatar = $('#playerAvatarProfile').find("img").attr('src');   

var myBid = {
			bid: currentBid,
	me: pushAvatar,

		thisAuctionBids.push(myBid);  //public
  	myBids.push(myBid); //private 

//update the bestBid value of the auction so that cycle can start all over again 
// should we wrap this call in a transaction to ensure the bestBid value is updated to all clients properly? 

 });   //push offer/bid    

      ui.on('click','#doCreate', function(event) {
  	var itemName = $('#itemName').val();
     	var itemDescription = $('#itemDescription').val();
  	var itemUrl = $('#itemUrl').val();

  	var bidders = $('#biddersInput').val();
		var time = $('#timeInput').val();
		var maxBid = $('#maxBidInput').val();
	   	var increment = $('#incrementInput').val();
       	var passprotected = $('#passwordInput').val();  

 // This 3 next lines crashes the browser * check comment below 
var generateUrl = auctions.push();
var url =;
var generatedUrl= $("#urlInput").val(url);

	var newAuction = {   
			admin:, // push my as admin
			item: itemName,
			image: itemUrl,
			bidders: bidders,
			times: time,
		    maxBid: maxBid,
    , url: generatedUrl
 // *setTimeout prevents the browser from crashing but feels very dirty :( 

           setTimeout(function() {
}, 5000);

// on loading auction details check if user is the admin

thisAuction.on('value',  function(snapshot) {  
var admin= snapshot.val().admin; 
//if user is admin
if ({
//change ui (show a button that on click starts the auction)  

//is this a proper way of doing it? Security rules are the answer ? I'm not 'getting it' yet. looks a bit too much for what I'm aiming for