Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready( () => {
- let count = 10;
- let debug = true;
- let force_restore = true;
- // -------------------------
- let db_name = 'mettatea';
- let db_stores = [ 'app', 'table_magic' ];
- let db_version = 1;
- let load = async ( app, store, defaults ) => {
- try {
- return await app.db.get( store, defaults.id );
- } catch( err ) {
- try {
- await app.db.add( store, defaults );
- return defaults;
- } catch( err ) { log( 'ERROR: [load] Could not open store.', err ); }
- }
- };
- let app_new = async () => {
- try {
- app = await new
- App( db_name, db_version, db_stores, force_restore, debug );
- return app;
- } catch( err ) {
- log( 'ERROR: [setup] could not open database [' + + ']', err );
- }
- };
- let app_setup = async ( app, args ) => {
- try {
- app.settings = await load( app, args.store, args.defaults );
- return app;
- } catch( err ) {
- log( 'ERROR: [setup] could not open database [' + + ']', err );
- }
- };
- let tm_setup = async ( app, args ) => {
- let id = args.defaults.id;
- await load( app, 'table_magic', args.defaults )
- .then( () => {
- app.magic_tables[ id ] =
- new TableMagic( $( '#' + id ), args.defaults.attrs, args.defaults.data );
- } );
- await app.init( id );
- };
- app_new()
- .then( app => {
- return app_setup( app, {
- store: 'app',
- defaults: { id: 1, focus: '#tbl1' }
- } );
- } )
- .then( app => {
- tm_setup( app, {
- store: 'table_magic',
- defaults: tm_defaults( count )[ 0 ]
- } );
- } );
- let tm_defaults = ( count ) => {
- let row_count = count;
- let rows = {};
- let row = [
- 0, 'Whole Foods', 'Whole Foods Yorkville - YRK', 0, '163.456.7890',
- '432.546.4325', 'sam@abc.com', 'address', '#745', 'M5R-3R9',
- 'Canada', 'Ontario', 'Toronto',
- 'This is a test message...'
- ];
- var mockup_data = {
- keys: [
- 'status_id', 'customer_id', 'branch_id', 'agent_id', 'phone1',
- 'phone2', 'email_address', 'address', 'unit', 'postalcode', 'country_id',
- 'zone_id', 'location_id', 'notes'
- ],
- head: {
- selector: 1,
- columns: {
- labels: [
- 'Status', 'Customer', 'Branch', 'Agent', 'Phone1', 'Phone2',
- 'Email Address', 'Address', 'Unit', 'Post Code', 'Country',
- 'State/Prov', 'City/Town', 'Notes'
- ],
- widths: []
- }
- },
- body: {
- selector: 0,
- rows: {}
- },
- children: {
- status_id: {
- type: 'option',
- children: { 0: '', 1: 'Active', 2: 'Prospect', 3: 'Pending', 4: 'On Hold' }
- },
- agent_id: {
- type: 'option',
- children: { 0: '', 1: 'Dan', 2: 'Danny', 3: 'Daniel', 4: 'Uno' }
- }
- }
- };
- for ( let id = 1; id < row_count + 1; id++ ) {
- let r = [ ...row ];
- r[ 0 ] = Math.floor( Math.random() * 4 ) + 1;
- r[ 2 ] = 'Whole Foods Store - [' + (
- Math.floor( Math.random() * 1000 ) + 1 ) + ']';
- r[ 3 ] = Math.floor( Math.random() * 4 ) + 1;
- rows[ id ] = r;
- }
- mockup_data.body.rows = rows;
- return [
- {
- id: 'tbl1',
- data: mockup_data,
- attrs: {
- index: true,
- selector: true,
- colorize: {
- th: {
- color: 'white',
- background: 'blue'
- }
- },
- sortable: true,
- context_menu: true,
- column_sizing: true
- },
- timestamp: new Date()
- },
- ];
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement