View | Details | Raw Unified | Return to bug 16040
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/lib/jquery/plugins/dataTables.fnReloadAjax.js (-50 / +101 lines)
Lines 1-50 Link Here
1
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
1
/**
2
 * By default DataTables only uses the sAjaxSource variable at initialisation
3
 * time, however it can be useful to re-read an Ajax source and have the table
4
 * update. Typically you would need to use the `fnClearTable()` and
5
 * `fnAddData()` functions, however this wraps it all up in a single function
6
 * call.
7
 *
8
 * DataTables 1.10 provides the `dt-api ajax.url()` and `dt-api ajax.reload()`
9
 * methods, built-in, to give the same functionality as this plug-in. As such
10
 * this method is marked deprecated, but is available for use with legacy
11
 * version of DataTables. Please use the new API if you are used DataTables 1.10
12
 * or newer.
13
 *
14
 *  @name fnReloadAjax
15
 *  @summary Reload the table's data from the Ajax source
16
 *  @author [Allan Jardine](http://sprymedia.co.uk)
17
 *  @deprecated
18
 *
19
 *  @param {string} [sNewSource] URL to get the data from. If not give, the
20
 *    previously used URL is used.
21
 *  @param {function} [fnCallback] Callback that is executed when the table has
22
 *    redrawn with the new data
23
 *  @param {boolean} [bStandingRedraw=false] Standing redraw (don't changing the
24
 *      paging)
25
 *
26
 *  @example
27
 *    var table = $('#example').dataTable();
28
 *
29
 *    // Example call to load a new file
30
 *    table.fnReloadAjax( 'media/examples_support/json_source2.txt' );
31
 *
32
 *    // Example call to reload from original file
33
 *    table.fnReloadAjax();
34
 */
35
36
jQuery.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
2
{
37
{
3
    if ( typeof sNewSource != 'undefined' && sNewSource != null )
38
	// DataTables 1.10 compatibility - if 1.10 then `versionCheck` exists.
4
    {
39
	// 1.10's API has ajax reloading built in, so we use those abilities
5
        oSettings.sAjaxSource = sNewSource;
40
	// directly.
6
    }
41
	if ( jQuery.fn.dataTable.versionCheck ) {
7
    this.oApi._fnProcessingDisplay( oSettings, true );
42
		var api = new jQuery.fn.dataTable.Api( oSettings );
8
    var that = this;
43
9
    var iStart = oSettings._iDisplayStart;
44
		if ( sNewSource ) {
10
    var aData = [];
45
			api.ajax.url( sNewSource ).load( fnCallback, !bStandingRedraw );
11
46
		}
12
    this.oApi._fnServerParams( oSettings, aData );
47
		else {
13
48
			api.ajax.reload( fnCallback, !bStandingRedraw );
14
    oSettings.fnServerData( oSettings.sAjaxSource, aData, function(json) {
49
		}
15
        /* Clear the old information from the table */
50
		return;
16
        that.oApi._fnClearTable( oSettings );
51
	}
17
52
18
        /* Got the data - add it to the table */
53
	if ( sNewSource !== undefined && sNewSource !== null ) {
19
        var aData =  (oSettings.sAjaxDataProp !== "") ?
54
		oSettings.sAjaxSource = sNewSource;
20
            that.oApi._fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ) : json;
55
	}
21
56
22
        for ( var i=0 ; i<aData.length ; i++ )
57
	// Server-side processing should just call fnDraw
23
        {
58
	if ( oSettings.oFeatures.bServerSide ) {
24
            that.oApi._fnAddData( oSettings, aData[i] );
59
		this.fnDraw();
25
        }
60
		return;
26
61
	}
27
        oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
62
28
        that.fnDraw();
63
	this.oApi._fnProcessingDisplay( oSettings, true );
29
64
	var that = this;
30
        if ( typeof bStandingRedraw != 'undefined' && bStandingRedraw === true )
65
	var iStart = oSettings._iDisplayStart;
31
        {
66
	var aData = [];
32
            oSettings._iDisplayStart = iStart;
67
33
            that.fnDraw( false );
68
	this.oApi._fnServerParams( oSettings, aData );
34
        }
69
35
70
	oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aData, function(json) {
36
        that.oApi._fnProcessingDisplay( oSettings, false );
71
		/* Clear the old information from the table */
37
72
		that.oApi._fnClearTable( oSettings );
38
        /* Callback user function - for event handlers etc */
73
39
        if ( typeof fnCallback == 'function' && fnCallback != null )
74
		/* Got the data - add it to the table */
40
        {
75
		var aData =  (oSettings.sAjaxDataProp !== "") ?
41
            fnCallback( oSettings );
76
			that.oApi._fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ) : json;
42
        }
77
43
    }, oSettings );
78
		for ( var i=0 ; i<aData.length ; i++ )
44
}
79
		{
45
80
			that.oApi._fnAddData( oSettings, aData[i] );
46
/* Example call to load a new file */
81
		}
47
//oTable.fnReloadAjax( 'media/examples_support/json_source2.txt' );
82
48
83
		oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
49
/* Example call to reload from original file */
84
50
//oTable.fnReloadAjax();
85
		that.fnDraw();
86
87
		if ( bStandingRedraw === true )
88
		{
89
			oSettings._iDisplayStart = iStart;
90
			that.oApi._fnCalculateEnd( oSettings );
91
			that.fnDraw( false );
92
		}
93
94
		that.oApi._fnProcessingDisplay( oSettings, false );
95
96
		/* Callback user function - for event handlers etc */
97
		if ( typeof fnCallback == 'function' && fnCallback !== null )
98
		{
99
			fnCallback( oSettings );
100
		}
101
	}, oSettings );
102
};
51
- 

Return to bug 16040