CXM_jquery_datatable.anubis 2.93 KB
/*
 * Created by PyramIDE.
 * User: Jeremy
 * Date: 12/09/2012
 * Time: 16:14
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

read calexium_lib/web/CXM_making_a_web_site.anubis
read calexium_lib/web/CXM_jquery.anubis
read calexium_lib/web/CXM_jquery_datatable_types.anubis
read tools/basis.anubis
read system/string.anubis
   
/* Initialize jQuery in compatiblity mode with jQueryUI */
public define List(HTML_Head_Tag)
  jquery_datatables_init
  (
   String web_dir,
  )
  =
    [ 
      css(css_file("/css/jquery/jquery.dataTables.css")),
      css(css_file("/css/jquery/jquery.dataTables_themeroller.css")),
      js(js_file("/js/jquery/jquery.dataTables.min.js"))
    ]
  .


public define HTML_Partial_Content
  jquery_datatable
  (
    String table_id,
    HTML_Off_Form table
  )
  =
    partial_content(
      [ js_inline(script("", "$(document).ready(function(){$('#"+table_id+"').dataTable();});")) ],
      table
    )
  .
  
public define HTML_Partial_Content
  jquery_datatable
  (
    String        table_id,
    HTML_Off_Form table,
    Bool          enable_jqueryui,
  )
  =
    if enable_jqueryui then
      partial_content(
        [ js_inline(script("", "$(document).ready(function(){$('#"+table_id+"').dataTable({\"bJQueryUI\":true});});")) ],
        table
      )
    else
      jquery_datatable(table_id, table)
  .
  
public define String
  bool_to_string
  (
    Bool b
  )
  =
    if b then "true" else "false"
  .
  
public define HTML_Partial_Content
  jquery_datatable
  (
    String                            table_id,
    HTML_Off_Form                     table,
    Bool                              enable_jqueryui,
    Bool                              enable_pagination,
    JQuery_datatable_pagination_type  pagination_type,
    Bool                              enable_change_page_length,  // if true, "enable_pagination" must be true too.
    Bool                              enable_search_field,
    Bool                              enable_columns_sorting
  )
  =
    partial_content(
        [
          js_inline(
            script(
              "", 
              "
                $(document).ready(function()
                {
                  $('#"+table_id+"').dataTable(
                  {
                    \"bJQueryUI\":"+bool_to_string(enable_jqueryui)+",
                    \"sPaginationType\":'"+jquery_datatable_pagination_type_to_string(pagination_type)+"',
                    \"bFilter\":"+bool_to_string(enable_search_field)+",
                    \"bPaginate\":"+bool_to_string(enable_pagination)+",
                    \"bLengthChange\":"+bool_to_string(enable_change_page_length)+",
                    \"bSort\":"+bool_to_string(enable_columns_sorting)+"
                  });
                });
              "
            )
          )
        ],
        table
      )
  .