Advertisement
Uno-Dan

Start App

Feb 12th, 2021
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready( () => {
  2.   let count = 10;
  3.   let debug =  true;
  4.   let restore = true;
  5.   let defaults = ( count ) => {
  6.     let row_count = count;
  7.     let rows = {};
  8.    
  9.     let row = [
  10.       0, 'Whole Foods', 'Whole Foods Yorkville - YRK', 0, '163.456.7890',
  11.       '432.546.4325', 'sam@abc.com', 'address', '#745', 'M5R-3R9',
  12.       'Canada', 'Ontario', 'Toronto',
  13.       'This is a test message...'
  14.     ];
  15.    
  16.     var mockup_data = {
  17.       keys: [
  18.         'status_id', 'customer_id', 'branch_id', 'agent_id', 'phone1',
  19.         'phone2', 'email_address', 'address', 'unit', 'postalcode', 'country_id',
  20.         'zone_id', 'location_id', 'notes'
  21.       ],
  22.       head: {
  23.         selector: 1,
  24.         columns: {
  25.           labels: [
  26.             'Status', 'Customer', 'Branch', 'Agent', 'Phone1', 'Phone2',
  27.             'Email Address', 'Address', 'Unit', 'Post Code', 'Country',
  28.             'State/Prov', 'City/Town', 'Notes'
  29.           ],
  30.           widths: []
  31.         }
  32.       },
  33.       body: {
  34.         selector: 0,
  35.         rows: {}
  36.       },
  37.       children: {
  38.         status_id: {
  39.           type: 'option',
  40.           children: { 0: '', 1: 'Active', 2: 'Prospect', 3: 'Pending', 4: 'On Hold' }
  41.         },
  42.         agent_id: {
  43.           type: 'option',
  44.           children: { 0: '', 1: 'Dan', 2: 'Danny', 3: 'Daniel', 4: 'Uno' }
  45.         }
  46.       }
  47.     };
  48.    
  49.     for ( let id = 1; id < row_count + 1; id++ ) {
  50.       let  r = [ ...row ];
  51.       r[ 0 ] = Math.floor( Math.random() * 4 ) + 1;
  52.       r[ 2 ] = 'Whole Foods Store - [' + (
  53.       Math.floor( Math.random() * 1000 ) + 1 ) + ']';
  54.       r[ 3 ] = Math.floor( Math.random() * 4 ) + 1;
  55.       rows[ id ] = r;
  56.     }
  57.     mockup_data.body.rows = rows;
  58.    
  59.     return [
  60.       {
  61.         id: 'tbl1',
  62.         data: mockup_data,
  63.         attrs: {
  64.           index: true,
  65.           selector: true,
  66.           colorize: {
  67.             th: {
  68.               color: 'white',
  69.               background: 'blue'
  70.             }
  71.           },
  72.           sortable: true,
  73.           context_menu: true,
  74.           column_sizing: true
  75.         },
  76.         timestamp: new Date()
  77.       },
  78.       {
  79.         id: 'tbl2',
  80.         data: mockup_data,
  81.         attrs: {
  82.           index: true,
  83.           selector: true,
  84.           colorize: {
  85.             th: {
  86.               color: 'white',
  87.               background: 'blue'
  88.             }
  89.           },
  90.           sortable: true,
  91.           context_menu: true,
  92.           column_sizing: true
  93.         },
  94.         timestamp: new Date()
  95.       },
  96.     ];
  97.   };
  98.    
  99.   // -------------------------
  100.  
  101.   let init = async ( cfg ) => {
  102.     try {
  103.       let app =
  104.       await new App( cfg, restore, debug );
  105.       await app.setup( { focus: cfg.focus } );
  106.       await app.config( defaults( count ) );
  107.       return await app.start();
  108.     } catch( err ) {
  109.       return [( 'ERROR: [init] Could not start app [' + cfg.name + ']' ), err ];
  110.     }
  111.   };
  112.      
  113.   init( {
  114.     id: 1,
  115.     name: 'Metta Tea CRM',
  116.     focus: 'tbl1',
  117.     db_name: 'mettatea',
  118.     db_stores: [ 'app', 'table_magic', 'test' ],
  119.     db_version: 1
  120.   } );
  121. });  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement