Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2020
8
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //var gun = Gun(['http://localhost:8080/gun']);
  2. var gun = Gun();
  3. var user = gun.user();
  4.  
  5. $('#up').on('click', function(e){
  6.     user.create($('#alias').val(), $('#pass').val());
  7. });
  8.  
  9. $('#sign').on('submit', function(e){
  10.     e.preventDefault();
  11.     user.auth($('#alias').val(), $('#pass').val());
  12. });
  13.  
  14. user.recall({sessionStorage: true});
  15.  
  16. gun.on('auth', function(){
  17.     $('#sign').hide();
  18.     $('#logout').show();
  19.   $('.auth_content').show();
  20.  
  21.   var notes_category =document.querySelector("#your_cat"), notes_category_item;
  22.   notes_category.innerHTML = '';
  23.      
  24.   user.get('notes').get('category').map().once( function(data, key){
  25.     notes_category_item =  ('<div class="" data-node="'+data._['#']+'" data-node-key="'+key+'">Title: '+data.name+'<br>Color: '+data.color+'</div><br>');
  26.     notes_category.insertAdjacentHTML('beforeend', notes_category_item);
  27.    
  28.   });
  29. });
  30.  
  31. $('#logout').on('click', function(e){
  32.   $('#sign').show();
  33.   $('#logout').hide();
  34.   $('.auth_content').hide();  
  35.   user.leave();
  36.   //location.reload();
  37. });
  38.  
  39. document.getElementById("cat_add").addEventListener("click", function(e){
  40. //$('#cat_add').on('click', function(e){
  41.   e.preventDefault();
  42.   if(!user.is){ return alert("login first") }
  43.  
  44.   var cat_title = document.querySelector('form input[name=cat_title]').value;
  45.   var cat_color = document.querySelector('form select[name=cat_color]').value;
  46.   var objectData = {name: cat_title, color: cat_color};
  47.   console.log(objectData);
  48.   //user.get('notes').get('category').get(Gun.time.is()).put(objectData);
  49.   var $gk = {};
  50.   $gk[Gun.time.is()] = objectData;
  51.     user.get('notes').get('category').put($gk)
  52.    
  53.   document.querySelector('form input[name="cat_title"]').value = '';
  54.   document.querySelector('form select[name="cat_color"]').selectedIndex = 1;
  55.  
  56. });
  57.  
  58. //Delete All data in node "Category"
  59. document.getElementById("cat_all_delete").addEventListener("click", function(e){
  60.  
  61.   user.get('notes').get('category').put(null);
  62.  
  63.  
  64. });
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement