Project

General

Profile

1
$(function() {
2

    
3
    if(Modernizr.touch) {
4
        // make table cell focusable
5
        var $focus_highlight = $('.focus-highlight');
6
        if ( $focus_highlight.length ) {
7
            $focus_highlight
8
                .find('td, th')
9
                .attr('tabindex', '1')
10
                .on('touchstart', function() {
11
                    $(this).focus();
12
                });
13
        }
14
        // disable fastclick on table headers (touch devices)
15
        $('.tablesorter').find('th').addClass('needsclick');
16
    }
17

    
18
    // pager + filters
19
	altair_tablesorter.pager_filter_example();
20
    // align widget example
21
	altair_tablesorter.align_widget_example();
22
    // custom filters
23
    altair_tablesorter.custom_filters();
24
});
25

    
26
altair_tablesorter = {
27
    pager_filter_example: function() {
28

    
29
        var $ts_pager_filter = $("#ts_pager_filter"),
30
            $columnSelector = $('#columnSelector');
31

    
32
        // define pager options
33
        var pagerOptions = {
34
            // target the pager markup - see the HTML block below
35
            container: $(".ts_pager"),
36
            // output string - default is '{page}/{totalPages}'; possible variables: {page}, {totalPages}, {startRow}, {endRow} and {totalRows}
37
            output: '{startRow} - {endRow} / {filteredRows} ({totalRows})',
38
            // if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
39
            // table row set to a height to compensate; default is false
40
            fixedHeight: true,
41
            // remove rows from the table to speed up the sort of large tables.
42
            // setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
43
            removeRows: false,
44
            // go to page selector - select dropdown that sets the current page
45
            cssGoto: '.ts_gotoPage'
46
        };
47

    
48
        // change popup print & close button text
49
        $.tablesorter.language.button_print = "Print table";
50
        $.tablesorter.language.button_close = "Cancel";
51

    
52
        // print table
53
        $('#printTable').on('click',function(e) {
54
            e.preventDefault();
55
            $ts_pager_filter.trigger('printTable');
56
        });
57

    
58
        // Initialize tablesorter
59
        var ts_users = $ts_pager_filter
60
            .tablesorter({
61
                theme: 'altair',
62
                widthFixed: true,
63
                widgets: ['zebra', 'filter','print','columnSelector'],
64
                headers: {
65
                    0: {
66
                        sorter: false,
67
                        parser: false
68
                    }
69
                },
70
                widgetOptions : {
71
                    // column selector widget
72
                    columnSelector_container : $columnSelector,
73
                        columnSelector_name : 'data-name',
74
                        columnSelector_layout : '<li class="padding_md"><input type="checkbox"><label class="inline-label">{name}</label></li>',
75
                        columnSelector_saveColumns: false,
76
                        // print widget
77
                        print_title      : '',          // this option > caption > table id > "table"
78
                        print_dataAttrib : 'data-name', // header attrib containing modified header name
79
                        print_rows       : 'f',         // (a)ll, (v)isible, (f)iltered, or custom css selector
80
                        print_columns    : 's',         // (a)ll, (v)isible or (s)elected (columnSelector widget)
81
                        print_extraCSS   : '',          // add any extra css definitions for the popup window here
82
                        print_styleSheet : '',          // add the url of your print stylesheet
83
                        print_now        : true,        // Open the print dialog immediately if true
84
                        // callback executed when processing completes - default setting is null
85
                        print_callback   : function(config, $table, printStyle){
86
                        // hide sidebar
87
                        altair_main_sidebar.hide_sidebar();
88
                        setTimeout(function () {
89
                            // print the table using the following code
90
                            $.tablesorter.printTable.printOutput( config, $table.html(), printStyle );
91
                        }, 300);
92
                    }
93
                }
94
            })
95
            // initialize the pager plugin
96
            .tablesorterPager(pagerOptions)
97
            .on('pagerComplete', function(e, filter){
98
                // update selectize value
99
                if(typeof selectizeObj !== 'undefined' && selectizeObj.data('selectize')) {
100
                    selectizePage = selectizeObj[0].selectize;
101
                    selectizePage.setValue($('select.ts_gotoPage option:selected').index() + 1, false);
102
                }
103

    
104
            });
105

    
106
        // replace column selector checkboxes
107
        $columnSelector.children('li').each(function(index) {
108
            var $this = $(this);
109

    
110
            var id = index == 0 ? 'auto' : index;
111
            $this.children('input').attr('id','column_'+id);
112
            $this.children('label').attr('for','column_'+id);
113

    
114
            $this.children('input')
115
                .prop('checked',true)
116
                .iCheck({
117
                    checkboxClass: 'icheckbox_md',
118
                    radioClass: 'iradio_md',
119
                    increaseArea: '20%'
120
                });
121

    
122
            if(index != 0) {
123
                $this.find('input')
124
                    .on('ifChanged', function (ev) {
125
                        $(ev.target).toggleClass('checked').change();
126
                    })
127
            }
128

    
129
        });
130

    
131
        $('#column_auto')
132
            .on('ifChecked',function(ev) {
133
                $(this)
134
                    .closest('li')
135
                    .siblings('li')
136
                    .find('input').iCheck('disable');
137
                $(ev.target).removeClass('checked').change();
138
            })
139
            .on('ifUnchecked',function(ev) {
140
                $(this)
141
                    .closest('li')
142
                    .siblings('li')
143
                    .find('input').iCheck('enable');
144
                $(ev.target).addClass('checked').change();
145
            });
146

    
147
        // replace 'goto Page' select
148
        function createPageSelectize() {
149
            selectizeObj = $('select.ts_gotoPage')
150
                .val($("select.ts_gotoPage option:selected").val())
151
                .after('<div class="selectize_fix"></div>')
152
                .selectize({
153
                    hideSelected: true,
154
                    onDropdownOpen: function($dropdown) {
155
                        $dropdown
156
                            .hide()
157
                            .velocity('slideDown', {
158
                                duration: 200,
159
                                easing: easing_swiftOut
160
                            })
161
                    },
162
                    onDropdownClose: function($dropdown) {
163
                        $dropdown
164
                            .show()
165
                            .velocity('slideUp', {
166
                                duration: 200,
167
                                easing: easing_swiftOut
168
                            });
169

    
170
                        // hide tooltip
171
                        $('.uk-tooltip').hide();
172
                    }
173
                });
174
        }
175
        createPageSelectize();
176

    
177
        // replace 'pagesize' select
178
        $('.pagesize.ts_selectize')
179
            .after('<div class="selectize_fix"></div>')
180
            .selectize({
181
                hideSelected: true,
182
                onDropdownOpen: function($dropdown) {
183
                    $dropdown
184
                        .hide()
185
                        .velocity('slideDown', {
186
                            duration: 200,
187
                            easing: easing_swiftOut
188
                        })
189
                },
190
                onDropdownClose: function($dropdown) {
191
                    $dropdown
192
                        .show()
193
                        .velocity('slideUp', {
194
                            duration: 200,
195
                            easing: easing_swiftOut
196
                        });
197

    
198
                    // hide tooltip
199
                    $('.uk-tooltip').hide();
200

    
201
                    if(typeof selectizeObj !== 'undefined' && selectizeObj.data('selectize')) {
202
                        selectizePage = selectizeObj[0].selectize;
203
                        selectizePage.destroy();
204
                        $('.ts_gotoPage').next('.selectize_fix').remove();
205
                        setTimeout(function() {
206
                            createPageSelectize()
207
                        })
208
                    }
209

    
210
                }
211
            });
212

    
213
        // select/unselect table rows
214
        $('.ts_checkbox_all')
215
            .iCheck({
216
                checkboxClass: 'icheckbox_md',
217
                radioClass: 'iradio_md',
218
                increaseArea: '20%'
219
            })
220
            .on('ifChecked',function() {
221
                $ts_pager_filter
222
                    .find('.ts_checkbox')
223
                    // check all checkboxes in table
224
                    .prop('checked',true)
225
                    .iCheck('update')
226
                    // add highlight to row
227
                    .closest('tr')
228
                    .addClass('row_highlighted');
229
            })
230
            .on('ifUnchecked',function() {
231
                $ts_pager_filter
232
                    .find('.ts_checkbox')
233
                    // uncheck all checkboxes in table
234
                    .prop('checked',false)
235
                    .iCheck('update')
236
                    // remove highlight from row
237
                    .closest('tr')
238
                    .removeClass('row_highlighted');
239
            });
240

    
241
        // select/unselect table row
242
        $ts_pager_filter.find('.ts_checkbox')
243
            .on('ifUnchecked',function() {
244
                $(this).closest('tr').removeClass('row_highlighted');
245
                $('.ts_checkbox_all').prop('checked',false).iCheck('update');
246
            }).on('ifChecked',function() {
247
                $(this).closest('tr').addClass('row_highlighted');
248
            });
249

    
250
        // remove single row
251
        $ts_pager_filter.on('click','.ts_remove_row',function(e) {
252
            e.preventDefault();
253

    
254
            var $this = $(this);
255
            UIkit.modal.confirm('Are you sure you want to delete this user?', function(){
256
                $this.closest('tr').remove();
257
                ts_users.trigger('update');
258
            }, {
259
                labels: {
260
                    'Ok': 'Delete'
261
                }
262
            });
263
        });
264

    
265
    },
266
    align_widget_example: function() {
267
        $('#ts_align')
268
            .tablesorter({
269
                theme: 'altair',
270
                widgets: ['zebra', 'alignChar'],
271
                widgetOptions : {
272
                    alignChar_wrap         : '<i/>',
273
                    alignChar_charAttrib   : 'data-align-char',
274
                    alignChar_indexAttrib  : 'data-align-index',
275
                    alignChar_adjustAttrib : 'data-align-adjust' // percentage width adjustments
276
                }
277
            });
278
    },
279
    custom_filters: function() {
280
        var $ts_customFilters = $('#ts_custom_filters');
281

    
282
            $ts_customFilters
283
                .tablesorter({
284
                    theme: 'altair',
285
                    headerTemplate: '{content} {icon}',
286
                    widgets: ['zebra', 'filter'],
287
                    widgetOptions: {
288
                        filter_reset : 'button.ts_cf_reset',
289
                        filter_cssFilter: ['', 'ts_cf_range', 'ts_cf_select_single', 'ts_cf_datepicker']
290
                    }
291
                });
292

    
293
            // rangeSlider
294
            var slider = $('.ts_cf_range').ionRangeSlider({
295
                "min": "0",
296
                "max": "1000",
297
                "type": "double",
298
                "grid-num": "10",
299
                "from-min": "10",
300
                "from-max": "30",
301
                "input_values_separator": " - "
302
            }).data("ionRangeSlider");
303

    
304

    
305
            // selectize
306
            var $selectize = $('.ts_cf_select_single')
307
                .after('<div class="selectize_fix"></div>')
308
                .selectize({
309
                    hideSelected: true,
310
                    dropdownParent: 'body',
311
                    closeAfterSelect: true,
312
                    onDropdownOpen: function($dropdown) {
313
                        $dropdown
314
                            .hide()
315
                            .velocity('slideDown', {
316
                                duration: 200,
317
                                easing: [ 0.4,0,0.2,1 ]
318
                            })
319
                    },
320
                    onDropdownClose: function($dropdown) {
321
                        $dropdown
322
                            .show()
323
                            .velocity('slideUp', {
324
                                duration: 200,
325
                                easing: [ 0.4,0,0.2,1 ]
326
                            });
327
                    }
328
                });
329

    
330
            var cf_selectize = $selectize[0].selectize;
331

    
332
            var modal = UIkit.modal("#modal_daterange", {
333
                center: true
334
            });
335

    
336
            $('.ts_cf_datepicker').on('focus',function() {
337
                if ( modal.isActive() ) {
338
                    modal.hide();
339
                } else {
340
                    modal.show();
341
                }
342
            });
343

    
344
            var $dp_start = $('#ts_dp_start'),
345
                $dp_end = $('#ts_dp_end');
346

    
347
            var start_date = UIkit.datepicker($dp_start, {
348
                format:'MMM D, YYYY'
349
            });
350

    
351
            var end_date = UIkit.datepicker($dp_end, {
352
                format:'MMM D, YYYY'
353
            });
354

    
355
            $dp_start.on('change',function() {
356
                end_date.options.minDate = $dp_start.val();
357
            });
358

    
359
            $dp_end.on('change',function() {
360
                start_date.options.maxDate = $dp_end.val();
361
            });
362

    
363
            $('#daterangeApply').on('click', function(e){
364
                e.preventDefault();
365
                modal.hide();
366
                $('.ts_cf_datepicker').val(
367
                    $dp_start.val() + ' - ' + $dp_end.val()
368
                ).change().blur();
369
            });
370

    
371
            $('button.ts_cf_reset').on('click', function() {
372
                // reset selectize
373
                cf_selectize.clear();
374
                // slider reset
375
                slider.reset();
376
            })
377

    
378
    }
379
};
(105-105/114)