Method: WidgetList::List#render

Defined in:
lib/widget_list.rb

#render(results = {}) ⇒ Object

pass results of $DATABASE.final_results after running a _select query

Parameters:

  • (defaults to: {})


2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
# File 'lib/widget_list.rb', line 2369

def render(results={})

  if @isAdministrating
    if $_REQUEST.key?('name')
      return WidgetList::Administration.new.save_and_show_code()
    elsif $_REQUEST.key?('ajax') && $_REQUEST.key?('model')
      return WidgetList::Administration.new.ajax_get_field_json($_REQUEST['model'])
    elsif $_REQUEST.key?('ajax') && $_REQUEST.key?('save')
      return WidgetList::Administration.new.save_and_show_code()
    else
      return WidgetList::Administration.new.show_interface()
    end
  end

  begin
    if !results.empty?
      @items['data'] = results
    end

    #Get total records for statement validation and pagination
    #
    @items['data'].keys.each { |column|
      @items['fields'][column.downcase] = auto_column_name(column)
    } if !@items['data'].empty? && @items['fields'].empty?

    if @items['data'].empty?
      # Generate count() from database
      #
      @totalResultCount = get_total_records()
    else
      # Count the items in the passed data
      #
      @items['data'].keys.each { |column|
        @totalResultCount = @items['data'][column].count
        @totalRowCount    = @totalResultCount
        @totalRows        = @totalResultCount
        break
      }
    end

    build_rows()

    build_summary_row()

    build_headers()

    listJumpUrl = {}
    listJumpUrl['PAGE_ID']             = @items['pageId']
    listJumpUrl['ACTION']              = 'AJAX'
    listJumpUrl['BUTTON_VALUE']        = @items['buttonVal']
    listJumpUrl['LIST_COL_SORT']       = @items['LIST_COL_SORT']
    listJumpUrl['LIST_COL_SORT_ORDER'] = @items['LIST_COL_SORT_ORDER']
    listJumpUrl['LIST_FILTER_ALL']     = @items['LIST_FILTER_ALL']
    listJumpUrl['ROW_LIMIT']           = @items['ROW_LIMIT']
    listJumpUrl['LIST_SEQUENCE']       = @sequence
    listJumpUrl['LIST_NAME']           = @items['name']
    listJumpUrl['SQL_HASH']            = @sqlHash

    if $_REQUEST.key?('switch_grouping')
      listJumpUrl['switch_grouping'] = $_REQUEST['switch_grouping']
    end

    @templateFill['<!--CORNER_RADIUS-->']        = get_radius_value()
    @templateFill['<!--BOX_SHADOW-->']           = @items['useBoxShadow'] ? 'box-shadow: <!--SHADOW_INSET--> <!--SHADOW_INSET--> <!--SHADOW_SPREAD--> <!--SHADOW_COLOR-->;'  : ''
    @templateFill['<!--SHADOW_INSET-->']         = get_shadow_inset_value()
    @templateFill['<!--SHADOW_SPREAD-->']        = get_shadow_spread_value()
    @templateFill['<!--SHADOW_COLOR-->']         = @items['shadowColor']
    @templateFill['<!--BORDER_HEAD_FOOT_TOP-->'] = @items['borderHeadFoot'] ? 'border-top:' + @items['headFootBorderStyle'] + ';' : ''
    if @items['fontFamily']
      @templateFill['<!--FONT-->']               = 'font-family:' + @items['fontFamily'] + ';'
    end
    @templateFill['<!--FONT_HEADER-->']          = @items['headerFooterFontSize']


    @templateFill['<!--CUSTOM_CONTENT_BOTTOM-->']= @items['customFooter']
    @templateFill['<!--CUSTOM_CONTENT_TOP-->']   = @items['customHeader']
    @templateFill['<!--WRAP_START-->']           = ''
    @templateFill['<!--WRAP_END-->']             = ''
    if !$_REQUEST.key?('BUTTON_VALUE')
      @templateFill['<!--WRAP_START-->']         = '<div class="widget_list_outer">
                                               <input type="hidden" id="<!--NAME-->_jump_url_original" value="<!--JUMP_URL-->"/>'
      @templateFill['<!--WRAP_END-->']           = '</div>'
    end

    @templateFill['<!--HEADER-->']               = @items['templateHeader']
    @templateFill['<!--TABLE_BORDER-->']         = @items['tableBorder']
    @templateFill['<!--HEADER_COLOR-->']         = @items['headerBGColor']
    @templateFill['<!--FOOTER_COLOR-->']         = @items['footerBGColor']
    @templateFill['<!--HEADER_TXT_COLOR-->']     = @items['headerFontColor']
    @templateFill['<!--FOOTER_TXT_COLOR-->']     = @items['footerFontColor']
    @templateFill['<!--TITLE-->']                = @items['title']
    @templateFill['<!--CLASS-->']                = @items['class']

    if @totalRowCount > 0
      @templateFill['<!--INLINE_STYLE-->']       = ''
      @templateFill['<!--TABLE_CLASS-->']        = @items['tableclass']
    else
      @templateFill['<!--INLINE_STYLE-->']       = 'table-layout:auto;'
    end

    #Filter form
    #
    if @items['showSearch'] === true
      if ! @items['templateFilter'].empty?
        @templateFill['<!--FILTER_HEADER-->']    = @items['templateFilter']
      else

        @templateFill['<!--FILTER_HEADER-->'] = ''

        if !$_REQUEST.key?('search_filter') && !@isJumpingList

          #Search page url
          #
          searchUrl = ''
          searchVal = ''

          if ! @items['buttonVal'].empty?
            searchVal = @items['buttonVal']
          else
            searchVal = @items['name']
          end

          filterParameters = {}
          filterParameters['BUTTON_VALUE'] = searchVal
          filterParameters['PAGE_ID']      = @items['pageId']
          filterParameters['LIST_NAME']    = @items['name']
          filterParameters['SQL_HASH']     = @sqlHash

          @items['carryOverRequsts'].each { |value|
            if $_REQUEST.key?(value)
              filterParameters[value] = $_REQUEST[value]
            end
          }

          searchUrl =  WidgetList::Utils::build_url(@items['pageId'], filterParameters, (!$_REQUEST.key?('BUTTON_VALUE')))

          list_search  = {}
          #
          # Search value
          #
          list_search['value'] = ''

          if @items['searchSession']
            if $_SESSION.key?('SEARCH_FILTER') && !$_SESSION['SEARCH_FILTER'].nil? && $_SESSION['SEARCH_FILTER'].key?(@items['name'])
              list_search['value'] = $_SESSION['SEARCH_FILTER'][@items['name']]
            end
          end

          #
          # Search Input Field
          #
          list_search['list-search'] = true
          list_search['width']       = '500'
          list_search['input_class'] = 'info-input'
          list_search['title']       = @items['searchTitle']
          list_search['id']          = 'list_search_id_' + @items['name']
          list_search['name']        = 'list_search_name_' + @items['name']
          list_search['class']       = 'inputOuter widget-search-outer ' + @items['name'].downcase + '-search'
          list_search['search_ahead']       = {
              'url'               => searchUrl,
              'skip_queue'        => false,
              'target'            => @items['name'],
              'search_form'       => @items['listSearchForm'],
              'onkeyup'           => (! @items['searchOnkeyup'].empty?) ? WidgetList::Utils::fill({'<!--URL-->'=>searchUrl, '<!--TARGET-->' => @items['name'], '<!--FUNCTION_ALL-->' => @items['ajaxFunctionAll']}, @items['searchOnkeyup'] + '<!--FUNCTION_ALL-->') : ''
          }

          fillRansack = {}
          if @items['ransackSearch'] != false
            fillRansack['<!--RANSACK-->'] = ActionController::Base.new.render_to_string(:partial => 'widget_list/ransack_fields', :locals => { 'search_object' => @items['ransackSearch'], 'url' => '--JUMP_URL--'})
          end

          @headerPieces['searchBar']            = WidgetList::Utils::fill(fillRansack,WidgetList::Widgets::widget_input(list_search))
          @templateFill['<!--FILTER_HEADER-->'] = @headerPieces['searchBar']

        end

        #
        # Grouping box
        #
        if ! @items['groupByItems'].empty?
          list_group = {}
          list_group['arrow_action']  = 'var stub;'
          list_group['readonly']      = true
          if @items['groupBySelected']
            list_group['value']      = @items['groupBySelected']
          elsif $_REQUEST.key?('group_row_id')
            tmp                      = $_REQUEST['group_row_id'].gsub(@items['name'] + '_row_','')
            if Float(tmp.to_i) != nil
              list_group['value']      = @items['groupByItems'][tmp.to_i - 1]
            end
          else
            list_group['value']      = @items['groupByItems'][0]
          end

          list_group['style']         = 'cursor:pointer;margin-left:5px;'
          list_group['input_style']   = 'cursor:pointer;'
          list_group['outer_onclick'] = 'ToggleAdvancedSearch(this);SelectBoxResetSelectedRow(\'' + @items['name'] + '\');'
          list_group['list-search']   = false
          list_group['width']         = '200'  #hard code for now.  needs to be dynamic based on max str length if this caller is made into a "WidgetFakeSelect"
          list_group['id']            = 'list_group_id_' + @items['name']
          list_group['name']          = 'list_group_name_' + @items['name']
          list_group['class']         = 'inputOuter widget-search-outer ' + @items['name'].downcase + '-group'

          className = ''
          groupRows = []
          if !@items['groupBySelected']
            className     = 'widget-search-results-row-selected'
          end

          num = 1
          @items['groupByItems'].each { |grouping|
            if @items['groupBySelected'] && @items['groupBySelected'] === grouping
              className     = 'widget-search-results-row-selected'
            end
            groupRows << '<div class="widget-search-results-row ' +  className + '" id="' + @items['name'] + '_row_' + num.to_s + '" title="' + grouping + '" onmouseover="jQuery(\'.widget-search-results-row\').removeClass(\'widget-search-results-row-selected\')" onclick="SelectBoxSetValue(\'' + grouping + '\',\'' + @items['name'] + '\');' + @items['groupByClick'] + '">' + grouping + '</div>'
            className = ''
            num = num + 1
          }

          list_group['search_ahead']  = {
              'skip_queue' => false,
              'search_form'=>  '
                             <div id="advanced-search-container" style="height:100% !important;">
                                ' + groupRows.join("\n") + '
                             </div>'
          }
          if !@templateFill.key?('<!--FILTER_HEADER-->')
            @templateFill['<!--FILTER_HEADER-->'] = ''
          end
          @headerPieces['groupByItems']           = '<div class="fake-select ' + @items['name'] + '-group-by"><div class="label">' + @items['groupByLabel'] + ':</div> ' + WidgetList::Widgets::widget_input(list_group) + '</div>'
          @templateFill['<!--FILTER_HEADER-->']  += @headerPieces['groupByItems']

        end

        if @items['showExport']
          @headerPieces['exportButton']           =  '<span class="' + @items['name'] + '-export">' + WidgetList::Widgets::widget_button(@items['exportButtonTitle'], { 'onclick' => 'ListExport(\'' + @items['name'] + '\');' , 'innerClass' => @items['defaultButtonClass'] }, true) + '</span>'
          @templateFill['<!--FILTER_HEADER-->']  += @headerPieces['exportButton']
        end

      end
    end

    @templateFill['<!--NAME-->']                 = @items['name']
    @templateFill['<!--JUMP_URL-->']             = WidgetList::Utils::build_url(@items['pageId'],listJumpUrl,(!$_REQUEST.key?('BUTTON_VALUE')))
    @templateFill['--JUMP_URL--']                = @templateFill['<!--JUMP_URL-->']
    @templateFill['<!--JUMP_URL_NAME-->']        = @items['name'] + '_jump_url'

  rescue Exception => e
    out = '<tr><td colspan="50"><div id="noListResults">' + generate_error_output(e) + @items['noDataMessage'] + '</div></td></tr>'
    if !@templateFill.key?('<!--DATA-->')
      @templateFill['<!--DATA-->']  = out
    else
      @templateFill['<!--DATA-->'] += out
    end
  end

  if $_REQUEST.key?('export_widget_list')
    csv = ''
    @csv.each{ |v|
      csv += v.to_csv
    }
    return csv
  else
    return WidgetList::Utils::fill(@templateFill, @items['template'])
  end
end