Advertisement
Guest User

This * Austin

a guest
Nov 24th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var CSDModel = require('./models/CSDModel');
  2. var _ = require('lodash');
  3. module.exports = {//<-- Required by Node
  4.     "routes" : {
  5.         "partial/:fileName": {
  6.             get: function(nerd, rez){
  7.                 return rez.sendFile('./views/' + nerd.params.fileName);
  8.             },
  9.             post: function(nerd, success, error){
  10.                 return success("");
  11.             }
  12.         },
  13.         "style/:fileName": {
  14.             get: function(nerd, rez){
  15.                 return rez.sendFile('./style/' + nerd.params.fileName);
  16.             }
  17.         },
  18.         "images/:fileName": {
  19.             get: function(nerd, rez){
  20.                 return rez.sendFile('./images/' + nerd.params.fileName);
  21.             }
  22.         },
  23.         "itemTable":{
  24.             get: function(nerd, rez){
  25.                 var Vendors ={};
  26.                 var Clients ={};
  27.                 var Warehouse = nerd.query.warehouse;
  28.                 var Supplier = nerd.query.supplier;
  29.  
  30.                GetVendors(nerd.user,function(VendorList){
  31.                    Vendors = VendorList;
  32.                    console.log('yay');
  33.                    console.log(Vendors);
  34.                    urmom();
  35.                 });
  36.  
  37.  
  38.  
  39.                 nerd.user.getAppInfo('3plink','client')
  40.                     .then(function(data){
  41.                         var ClientString = _.pluck(data,'value').join("','");
  42.                        Clients = "('" + ClientString + "')";
  43.  
  44.                         urmom();
  45.                     })
  46.                     .catch(function(err){
  47.                         return rez.error(err);
  48.                     });
  49.  
  50.                 var urmom = _.after(2,function(){
  51.                     var input = {};
  52.                     input.vendor = Vendors;
  53.                     input.client = Clients;
  54.                     input.name = nerd.user.user_name;
  55.                     if(Warehouse != undefined)
  56.                     input.warehouse = Warehouse;
  57.                     if(Supplier != undefined)
  58.                         input.Supplier = Supplier;
  59.  
  60.                     CSDModel(input).item()
  61.                         .then(function(record){
  62.                             return rez({data: record});
  63.                         })
  64.                         .catch(function(err){
  65.                             return rez.error(err);
  66.                         });
  67.  
  68.                 });
  69.  
  70.             }
  71.         },
  72.         "LotsForItem/":{
  73.             get: function(nerd, rez){
  74.                 var reservationData;
  75.                 var lotData;
  76.  
  77.                     CSDModel(nerd).LotsForItem()
  78.                     .then(function(record){
  79.                             lotData = record;
  80.                             loadDropdown();
  81.                     })
  82.                     .catch(function(err){
  83.                         return rez.error(err);
  84.                     });
  85.  
  86.                 CSDModel(nerd).LotsForItem()
  87.                     .then(function(record){
  88.                         reservationData = record;
  89.                         loadDropdown();
  90.                     })
  91.                     .catch(function(err){
  92.                         return rez.error(err);
  93.                     });
  94.  
  95.                 var loadDropdown = _.after(2,function(){
  96.                    var lots = lotData;
  97.                     console.log(lots);
  98.  
  99.                 });
  100.  
  101.  
  102.             }
  103.  
  104.         }
  105.  
  106.     }
  107.  
  108. };
  109.  
  110. //Pass User and callback function, not NERD
  111. function GetVendors(user, fn){<-- fn = passed callback function
  112.  
  113.     user.getAppInfo('3plink','vendorname')
  114.         .then(function(data){
  115.             var VendorString = _.pluck(data,'value').join("','");
  116.              var VendorList = "('" + VendorString + "')";
  117.             return fn(VendorList);<-- Run callback function and pass vendor list when retrieved
  118.         })
  119.         .catch(function(err){
  120.         return fn(err);<-- return error or possibly null
  121.         });
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement