Advertisement
Guest User

albatross

a guest
Aug 29th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. log = {
  2.     log: {
  3.         date: FIELD,
  4.         type: 'R',
  5.         season: FIELD,
  6.         sample: TRUE,
  7.         comments: "STUFF",
  8.         attributes: [
  9.             {
  10.                 name: "bird status",
  11.                 value: "DEAD"
  12.             },
  13.             {
  14.                 name: "location",
  15.                 value: "bloody island"
  16.             }
  17.         ],
  18.         breeding: {
  19.             mate: 122073238,
  20.             attributes: [
  21.                 {
  22.                
  23.                 },
  24.                 {
  25.                
  26.                 }
  27.             ]
  28.         }
  29.     }
  30. };
  31.  
  32. {
  33.     response: {}
  34.     errors: []
  35. }
  36.  
  37.  
  38. var log_prepare_object = function() {
  39.     var log = {};
  40.     log['log'] = {};
  41.     l = log['log'];
  42.    
  43.     # Prepare log info page of the wizard
  44.     l['date'] = $('#log-datefield').val();
  45.     l['type'] = $('#log-type').val();
  46.    
  47.     # Prepare resight page
  48.    
  49.     # Prepare file page if necessary
  50.     if (l['type'] == 'F') {
  51.    
  52.     }
  53.    
  54.     # Prepare breeding page if necessary
  55.     if (l['type'] == 'B') {
  56.    
  57.     }
  58.    
  59.     return log;
  60. };
  61.  
  62. var log_validate = function(log) {
  63.     var errors = 0;
  64.     // check the date
  65.     if (log['log']['date'] > Date()) {
  66.         validation_errors.push("LOG DATE IS IN THE FUTURE!");
  67.         errors++;
  68.         return false;
  69.     }
  70.    
  71.     if (errors > 0) {
  72.         return false;
  73.     } else {
  74.    
  75.     return true;
  76.     }
  77.    
  78. }
  79. var validation_errors = [];
  80.  
  81. var submitform = function(event) {
  82.     event.preventDefault();
  83.     log = log_prepare_object();
  84.     if (log_validate(log)) {
  85.         console.log(JSON.stringify(log));
  86.     } else {
  87.         // display error panel with list of errors found in validation
  88.     }
  89. }
  90.  
  91. $(document).ready = function() {
  92.     $("#submitbtn).click(submitform);
  93. };
  94.  
  95.  
  96.  
  97. log.log.date
  98.  
  99. log['log']['log']['date']
  100.  
  101. log.log.attributes.push({name: 'Colour', value: 'BLUE'})
  102.  
  103. for (var i=0; i<log.log.attributes.length; i++) {
  104.     console.log(log.log.attributes[i].name + ':' + log.log.attributes[i].value)
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement