~ubuntu-branches/ubuntu/wily/ntopng/wily-proposed

« back to all changes in this revision

Viewing changes to httpdocs/js/bootstrap-datatable.js

  • Committer: Package Import Robot
  • Author(s): Ludovico Cavedon
  • Date: 2014-07-27 16:13:47 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140727161347-0i8n5upu69ibq5d2
Tags: 1.2.0+dfsg1-1
* Imported Upstream version 1.2.0+dfsg1
* Update watch rule for new upstream naming convention.
* get-roig-source: Support both +svn and ~svn in version.
* Remove external hiredis from orig tarball.
* Remove Rickshaw from orig tarball.
* Remove documentation without source from orig tarball and insert an http
* Remove corrupted unused serializeCFJSON-0.1.js from orig tarball.
  link to it in README.Debian.
* Remove nDPI from orig tarball.
* Remove all debian/missing-sources files that are now included not-minified
  by upstream. Remove build-deps on node-uglify and cleancss.
* Remove references to third-party/redis-lua (removed upstream).
* Update copyright.
* Refresh patches and remove those merged upstream.
* Add external-hiredis.patch to use system libhiredis.
* Add rickshaw-keep-one.patch to remove references to additional rickshaw
  library.
* Add no-svn.patch to drop requirement on SVN.
* Add manpage.patch to fix usage of minus signs, hyphens, and dashes,
  missing space and line breaks.
* Add rickshaw.patch to use single rickshaw.{css,js} files.
* Split library removing part of build-flags.patch into remove-libs.patch.
* Rename debian-defaults.patch to path-defaults.patch and use installation
  path from configure.
* Use dh-autoreconf instead of autotools-dev.
* Add build-dep on libsqlite3-dev.
* Update build-dep on newer libndpi-dev.
* Cleanup of dh_install rules.
* Fix typo in font-awesome symlink path and remove and updates symlink links
  in ntopng-data/
* Remove executable bit to non executable files.
* Use system linjs-jquery tablesorter and form.
* Add Build-Dep on libhiredis-dev.
* Remove empty httpdocs/ssl directory.
* Add systemd support.
* Stop supporting ENABLED in /etc/default/ntopng and debian/NEWS to notify
  users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*!
2
 
 * Bootstrap Data Table Plugin v1.5.4
 
2
 * Bootstrap Data Table Plugin v1.5.5
3
3
 *
4
4
 * Author: Jeff Dupont
5
5
 * ==========================================================
31
31
    this.rows = [];
32
32
    this.buttons = [];
33
33
 
 
34
    // this needs to be handled better
34
35
    this.localStorageId = "datatable_" + (options.id || options.url.replace(/\W/ig, '_'));
35
36
 
36
37
    // set the defaults for the column options array
43
44
    this.$default = this.$element.children().length ?
44
45
      this.$element.children() :
45
46
      $("<div></div>")
46
 
        .addClass("alert alert-error")
 
47
// ------------- Start ntop Patch ---------------
 
48
        .addClass("alert alert-danger")
 
49
// ------------- End ntop Patch ---------------        
47
50
        .html("No Results Found");
48
51
 
49
52
    this.$element.addClass("clearfix");
53
56
      localStorage[this.localStorageId] = 'false';
54
57
    }
55
58
 
 
59
    if(this.options.tablePreRender && typeof this.options.tablePreRender === 'function')
 
60
      this.options.tablePreRender.call(this)
 
61
 
 
62
    // initialize the toolbar
 
63
    _initToolbar.call(this)
 
64
 
56
65
    if(this.options.autoLoad === true) this.render();
57
66
  };
58
67
 
91
100
        var that = this;
92
101
 
93
102
        // pull in the data from the ajax call
 
103
        if (o.debug) console.log($.extend({}, o.post, {
 
104
                  currentPage: o.currentPage
 
105
                , perPage: o.perPage
 
106
                , sort: o.sort
 
107
                , filter: o.filter
 
108
              }) );
94
109
        if(o.url !== "") {
95
110
          $.ajax({
96
111
              url: o.url
 
112
// ------------- Start ntop Patch ---------------
97
113
            , type: "GET"
98
114
            , dataType: "json"
99
 
            , data: $.extend({}, o.get, {
 
115
            , data: $.extend({}, o.post, {
100
116
                  currentPage: o.currentPage
101
117
                , perPage: o.perPage
102
 
                , sortColumn: o.sort[0][0]
103
 
                , sortOrder: o.sort[0][1]
 
118
                , sortColumn: (o.sort.length > 0) ? o.sort[0][0] : null
 
119
                , sortOrder: (o.sort.length > 0) ? o.sort[0][1] : null
 
120
 // ------------- End ntop Patch -----------------
104
121
                , filter: o.filter
105
122
              })
106
123
            , success: function( res ) {
107
 
                if(o.debug) console.log(res);
108
 
 
109
 
                if(!res || res === undefined) {
110
 
                  showError.call(that);
111
 
                  return;
112
 
                }
113
 
 
114
124
                that.resultset = res;
115
125
 
116
 
                if(!res.data || res.data.length === 0) {
 
126
                if(!res || res === undefined || !res.data || res.data.length == 0) {
117
127
                  showError.call(that);
118
128
                  return;
119
129
                }
129
139
                // set the current page if we're forcing it from the server
130
140
                if(res.currentPage) o.currentPage = parseInt(res.currentPage);
131
141
 
132
 
                if(o.tablePreRender && typeof o.tablePreRender === 'function')
133
 
                  o.tablePreRender.call(that);
134
 
 
135
 
                // TODO FUTURE FEATURE: retrieve the saved columns
136
 
                //_retrieveColumns.call(that, that.localStorageId);
 
142
                // retrieve the saved columns
 
143
                _retrieveColumns.call(that, localStorage[that.localStorageId])
137
144
 
138
145
                // append the table
139
146
                $e.append(that.table());
190
197
            })
191
198
            .append(
192
199
              $("<div></div>")
193
 
                .addClass("progress progress-striped active")
194
 
                .append($('<div class="bar" style="width: 100%"></div>'))
 
200
// ------------- Start ntop Patch ---------------              
 
201
                .addClass("progress progress-striped")
 
202
                .append(
 
203
                  $("<div></div>")
 
204
                    .addClass("progress-bar progress-bar-info")
 
205
                    .attr('style', "width: 40%")
 
206
// ------------- End ntop Patch -----------------                    
 
207
                )
195
208
            )
196
 
            .appendTo($e.parent());
 
209
            .appendTo(document.body)
197
210
        }
198
211
 
199
212
        if(show) {
241
254
          $e.before(this.$section_header);
242
255
        }
243
256
        else {
244
 
          if(!this.$section_header) {
245
 
            this.$section_header = $("<div></div>");
246
 
          }
247
 
          this.$section_header.append(this.$toolbar);
 
257
            if(!this.$toolbar_container) {
 
258
              this.$toolbar_container = $("<div></div>")
 
259
                .addClass('dt-toolbar-container clearfix')
 
260
            }
 
261
            $e.prepend(
 
262
              this.$toolbar_container
 
263
                .append(this.$toolbar)
 
264
            );
248
265
        }
249
266
 
250
267
        return this.$toolbar;
257
274
          , end = 0
258
275
          , that = this;
259
276
 
260
 
        start = (o.currentPage * o.perPage) - o.perPage + 1;
 
277
        start = (o.currentPage * o.perPage) - o.perPage + 1
 
278
        if(start < 1) start = 1;
 
279
 
261
280
        end = (o.currentPage * o.perPage);
262
281
        if(end > o.totalRows) end = o.totalRows;
263
282
 
289
308
 
290
309
        if(!this.$header) {
291
310
          this.$header = $('<thead></thead>');
 
311
          var row = $('<tr></tr>');
292
312
 
293
313
          // loop through the columns
294
314
          for(var column in o.columns) {
313
333
              }
314
334
            }
315
335
 
316
 
            this.$header.append($cell);
 
336
            row.append($cell);
 
337
            this.$header.append(row);
317
338
            this.columns.push($cell);
318
339
          }
319
340
 
328
349
      }
329
350
 
330
351
    , footer: function () {
331
 
        var res = this.resultset;
 
352
        var o = this.options
 
353
          , res = this.resultset
332
354
 
333
355
        if(!this.$footer) {
334
356
          this.$footer = $('<tfoot></tfoot>');
335
357
 
 
358
          // loop through the columns
 
359
          for(column in o.columns) {
 
360
            var $cell = $('<td></td>')
 
361
 
 
362
            $cell
 
363
              .data("cell_properties", o.columns[column])
 
364
              .addClass(o.columns[column].classname)
 
365
 
 
366
            this.$footer.append($cell);
 
367
          }
 
368
 
336
369
          // any final user adjustments to the footer
337
370
          if(o.footerCallback && typeof o.footerCallback === 'function')
338
 
            o.footerCallback.call(this);
 
371
            o.footerCallback.call(this, this.resultset.footer)
339
372
 
340
373
          this.$table
341
374
            .append(this.$footer);
422
455
 
423
456
        // preprocess on the cell data for a column
424
457
        if(o.columns[column].callback && typeof o.columns[column].callback === "function")
425
 
          celldata = o.columns[column].callback( data, o.columns[column] );
 
458
          celldata = o.columns[column].callback.call( $cell, data, o.columns[column] )
426
459
 
427
460
        $cell
428
461
          .data("cell_properties", o.columns[column])
429
462
          .addClass(o.columns[column].classname)
430
 
          .html(celldata || "&nbsp;");
 
463
          .append(celldata || "&nbsp;")
431
464
 
432
465
        if(o.columns[column].css) $cell.css(o.columns[column].css);
433
466
 
461
494
          , o = e.data.options
462
495
          , found = false;
463
496
 
464
 
        colprop.sortOrder = colprop.sortOrder ? (colprop.sortOrder == "desc" ? "asc" : "") : "desc";
 
497
        colprop.sortOrder = colprop.sortOrder ? (colprop.sortOrder == "asc" ? "desc" : "") : "asc";
465
498
 
466
499
        if(o.allowMultipleSort) {
467
500
          // does the sort already exist?
494
527
        if(o.perPage >= res.totalRows) return;
495
528
 
496
529
        if(!this.$pagination) {
497
 
          this.$pagination = $("<div></div>")
498
 
            .addClass("pagination pagination-right");
 
530
          this.$pagination = $("<div></div>").addClass("pull-right");
499
531
 
500
532
          // how many pages?
501
533
          o.pageCount = Math.ceil(res.totalRows / o.perPage);
502
534
 
503
535
          // setup the pager container and the quick page buttons
504
 
          var $pager = $("<ul></ul>")
 
536
          var $pager = $("<ul></ul>").addClass("pagination")
505
537
            , $first = $("<li></li>").append(
506
538
                $("<a></a>")
507
539
                  .attr("href", "#")
508
540
                  .data("page", 1)
509
 
                  .html("&larr; First")
 
541
                  .html("&laquo;")
510
542
                  .click(function() {
511
 
                    if (o.currentPage > 1) {
512
 
                      o.currentPage = 1;
513
 
                      that.render();
514
 
                    }
 
543
                    o.currentPage = 1
 
544
                    that.render();
515
545
                    return false;
516
546
                  })
517
547
              )
519
549
                $("<a></a>")
520
550
                  .attr("href", "#")
521
551
                  .data("page", o.currentPage - 1)
522
 
                  .text("Prev")
 
552
                  .html("&lt;")
523
553
                  .click(function() {
524
 
                    if (o.currentPage > 1) {
525
 
                      o.currentPage -= 1;
526
 
                      that.render();
527
 
                    }
 
554
                    o.currentPage -= 1
 
555
                    o.currentPage = o.currentPage >= 1 ? o.currentPage : 1
 
556
                    that.render();
528
557
                    return false;
529
558
                  })
530
559
              )
532
561
                $("<a></a>")
533
562
                  .attr("href", "#")
534
563
                  .data("page", o.currentPage + 1)
535
 
                  .text("Next")
 
564
                  .html("&gt;")
536
565
                  .click(function() {
537
 
                    if (o.currentPage < o.pageCount) {
538
 
                      o.currentPage += 1;
539
 
                      that.render();
540
 
                    }
 
566
                    o.currentPage += 1
 
567
                    o.currentPage = o.currentPage <= o.pageCount? o.currentPage : o.pageCount
 
568
                    that.render();
541
569
                    return false;
542
570
                  })
543
571
              )
545
573
                $("<a></a>")
546
574
                  .attr("href", "#")
547
575
                  .data("page", o.pageCount)
548
 
                  .html("Last &rarr;")
 
576
                  .html("&raquo;")
549
577
                  .click(function() {
550
 
                    if (o.currentPage < o.pageCount) {
551
 
                      o.currentPage = o.pageCount;
552
 
                      that.render();
553
 
                    }
 
578
                    o.currentPage = o.pageCount
 
579
                    that.render();
554
580
                    return false;
555
581
                  })
556
582
              );
584
610
                  .data("page", i)
585
611
                  .text(i)
586
612
                  .click(function() {
587
 
                    if (o.currentPage !== $(this).data('page')) {
588
 
                      o.currentPage = $(this).data('page');
589
 
                      that.render();
590
 
                    }
 
613
                    o.currentPage = $(this).data('page')
 
614
                    that.render();
591
615
                    return false;
592
616
                  })
593
617
              );
614
638
        return this.$pagination;
615
639
      }
616
640
 
 
641
    , remove: function() {
 
642
        var $e = this.$element
 
643
 
 
644
        if(this.$section_header) this.$section_header.remove();
 
645
 
 
646
        $e.data("datatable", null);
 
647
        $e.empty();
 
648
      }
 
649
 
617
650
  };
618
651
 
619
652
 
652
685
    var that = this;
653
686
 
654
687
    if(!this.$column_modal) {
 
688
      var randId = Math.floor((Math.random()*100)+1);
655
689
      this.$column_modal = $('<div></div>')
656
 
        .attr("id", "dt-column-modal_" + Math.floor((Math.random()*100)+1))
657
 
        .addClass("modal")
 
690
        .attr("id", "dt-column-modal_" + randId)
 
691
        .attr("tabindex","-1")
 
692
        .attr("role","dialog")
 
693
        .attr("aria-labelledby", "dt-column-modal-label_" + randId)
 
694
        .attr("aria-hidden","true")
 
695
        .addClass("modal fade")
658
696
        .hide();
659
697
 
660
698
      // render the modal header
664
702
          $("<button></button>")
665
703
            .addClass("close")
666
704
            .data("dismiss", "modal")
667
 
            .text('x')
668
 
            .click(function() {
 
705
            .attr("aria-hidden","true")
 
706
            .html('&times;')
 
707
            .click(function(){
669
708
              that.$column_modal.modal('hide');
670
709
            })
671
710
        )
672
711
        .append(
673
712
          $("<h3></h3>")
 
713
            .addClass("modal-title")
 
714
            .attr("id","dt-column-modal-label_" + randId)
674
715
            .text("Toggle Columns")
675
716
        );
676
717
 
678
719
      this.$column_modalfooter = $("<div></div>")
679
720
        .addClass("modal-footer")
680
721
        .append(
681
 
          $("<a></a>")
682
 
            .attr("href", "#")
683
 
            .addClass("btn btn-primary")
684
 
            .text("Save")
 
722
            // show the check 'all / none' columns
 
723
            $('<div class="pull-left"></div>')
 
724
              .append(
 
725
                $('<div class="btn-group"></div>')
 
726
                  .append(
 
727
                    $('<button></button>')
 
728
                      .addClass("btn btn-info")
 
729
                      .append(
 
730
                        $("<span></span>")
 
731
                          .addClass("glyphicon glyphicon-check")
 
732
                          .text("All")
 
733
                      )
 
734
                      .click(function () {
 
735
                        $(this).closest(".modal").find('button.on-off').each(function () {
 
736
                          if($(this).data('column-hidden')){
 
737
                              $(this).click();
 
738
                          }
 
739
                        })
 
740
                        return false;
 
741
                      }),
 
742
                    $('<button></button>')
 
743
                      .addClass("btn btn-warning")
 
744
                      .append(
 
745
                        $("<span></span>")
 
746
                          .addClass("glyphicon glyphicon-unchecked")
 
747
                          .text("None")
 
748
                      )
 
749
                      .click(function () {
 
750
                        $(this).closest(".modal").find('button.on-off').each(function () {
 
751
                          if(!$(this).data('column-hidden')){
 
752
                            $(this).click();
 
753
                          }
 
754
                        })
 
755
                        return false;
 
756
                      })
 
757
                  )
 
758
              )
 
759
 
 
760
          , o.allowSaveColumns ? $("<button></button>")
 
761
              .addClass("btn btn-primary")
 
762
              .text("Save")
 
763
              .click(function() {
 
764
                _saveColumns.call(that)
 
765
                return false;
 
766
              }) : ""
 
767
 
 
768
          , $("<button></button>")
 
769
            .addClass("btn btn-default")
 
770
            .data('dismiss', 'modal')
 
771
            .append(
 
772
              $("<span></span>")
 
773
            )
 
774
            .text("Close")
685
775
            .click(function() {
686
 
              _saveColumns.call(that);
 
776
              that.$column_modal.modal('hide')
687
777
              return false;
688
778
            })
689
779
        );
692
782
      this.$column_modalbody = $("<div></div>")
693
783
        .addClass("modal-body");
694
784
 
 
785
      this.$column_modaldialog = $("<div></div>")
 
786
        .addClass("modal-dialog")
 
787
        .append(
 
788
          $("<div></div>")
 
789
            .addClass("modal-content")
 
790
            .append(
 
791
              this.$column_modalheader
 
792
              ,this.$column_modalbody
 
793
              ,this.$column_modalfooter
 
794
            )
 
795
        );
 
796
 
695
797
      // render and add the modal to the container
696
798
      this.$column_modal
697
799
        .append(
698
 
            this.$column_modalheader
699
 
          , this.$column_modalbody
700
 
          , this.$column_modalfooter
701
 
        )
702
 
        .appendTo(document.body);
 
800
          this.$column_modaldialog
 
801
        ).appendTo(document.body);
703
802
    }
704
 
 
705
803
    // render the display modal button
706
804
    $toggle
707
805
      .addClass("btn")
708
806
      .data("toggle", "modal")
 
807
      .data("content", "Choose which columns you would like to display.")
 
808
      .data("target","#" + this.$column_modal.attr("id"))
709
809
      .attr("href", "#" + this.$column_modal.attr("id"))
710
 
      .html("<i class=\"icon-cog\"></i>")
 
810
      .append(
 
811
        $("<span></span>")
 
812
          .addClass("glyphicon glyphicon-cog")
 
813
      )
711
814
      .click(function(e) {
712
815
        that.$column_modal
713
 
          .on('show', function () {
 
816
          .on('show.bs.modal', function () {
 
817
            if(o.debug) console.log(that);
714
818
            _updateColumnModalBody.call(that, that.$column_modalbody);
715
819
          })
716
820
          .modal();
717
821
        return false;
 
822
      })
 
823
      .popover({
 
824
        "trigger": 'hover',
 
825
        "placement":'top'
718
826
      });
719
827
    this.buttons.unshift($toggle);
720
828
 
 
829
    if(o.debug) console.log($toggle);
 
830
 
721
831
    return this.$column_modal;
722
832
  }
723
833
 
726
836
      , $e = this.$element
727
837
      , $toggle = $("<a></a>");
728
838
 
729
 
    o.filterModal.hide();
730
 
 
731
839
    // render the display modal button
732
840
    $toggle
733
841
      .addClass("btn")
734
842
      .data("toggle", "modal")
735
843
      .attr("href", "#")
736
 
      .html("<i class=\"icon-filter\"></i>")
 
844
      .data("content", "Open the filter dialog.")
 
845
      .extend(
 
846
        $("<span></span>")
 
847
          .addClass("glyphicon glyphicon-filter")
 
848
      )
737
849
      .click(function() {
738
 
        $(o.filterModal)
739
 
          .modal();
 
850
        if($(o.filterModal).hasClass("modal"))
 
851
          $(o.filterModal)
 
852
            .modal();
 
853
        else if($(o.filterModal).is(":visible"))
 
854
          $(o.filterModal)
 
855
            .hide();
 
856
        else
 
857
          $(o.filterModal)
 
858
            .show();
 
859
 
740
860
        return false;
 
861
      })
 
862
      .popover({
 
863
        "trigger": 'hover',
 
864
        "placement":'top'
741
865
      });
742
866
    this.buttons.unshift($toggle);
743
867
  }
750
874
    // per page options and current filter/sorting
751
875
    var $perpage_select = $("<a></a>")
752
876
      .addClass("btn dropdown-toggle")
 
877
      .data("content", "Change the number of rows per page.")
753
878
      .attr("data-toggle", "dropdown")
754
879
      .html(o.perPage + "&nbsp;")
755
880
      .css({ fontWeight: 'normal' })
756
881
      .append(
757
882
        $("<span></span>")
758
883
          .addClass("caret")
759
 
      );
 
884
      )
 
885
      .popover({
 
886
        "trigger": 'hover',
 
887
        "placement":'top'
 
888
      });
760
889
    this.buttons.push($perpage_select);
761
890
 
762
891
    var $perpage_values = $("<ul></ul>")
763
892
      .addClass("dropdown-menu")
764
893
      .css({ fontSize: 'initial', fontWeight: 'normal' })
765
894
      .append(
766
 
          $('<li data-value="5"><a href="#">5</a></li>')
767
 
            .click(function() { _updatePerPage.call(this, that); return false; })
768
 
        , $('<li data-value="10"><a href="#">10</a></li>')
 
895
          $('<li data-value="10"><a href="#">10</a></li>')
769
896
            .click(function() { _updatePerPage.call(this, that); return false; })
770
897
        , $('<li data-value="20"><a href="#">20</a></li>')
771
898
            .click(function() { _updatePerPage.call(this, that); return false; })
773
900
            .click(function() { _updatePerPage.call(this, that); return false; })
774
901
        , $('<li data-value="100"><a href="#">100</a></li>')
775
902
            .click(function() { _updatePerPage.call(this, that); return false; })
 
903
        , $('<li data-value="150"><a href="#">200</a></li>')
 
904
            .click(function() { _updatePerPage.call(this, that); return false; })
776
905
      );
777
906
    this.buttons.push($perpage_values);
778
907
  }
786
915
    $info
787
916
      .addClass("btn")
788
917
      .attr("href", "#")
789
 
      .html("<i class=\"icon-info-sign\"></i>")
 
918
      .append(
 
919
        $("<span></span>")
 
920
          .addClass("glyphicon glyphicon-info-sign")
 
921
      )
790
922
      .click(function() {
791
923
        return false;
792
924
      });
812
944
      }
813
945
      $page_filter.push( (heading || k) + " = '" + v + "'" );
814
946
    });
815
 
 
816
 
    $($info).popover({
 
947
    $($info)
 
948
      .data("content",
 
949
        $('<dl></dl>').append(
 
950
          $page_sort.length > 0 ? '<dt><i class="icon-th-list"></i> Sort:</dt><dd>' + $page_sort.join(", ") + '</dd>' : ''
 
951
          ,
 
952
          $page_filter.length > 0 ? '<dt><i class="icon-filter"></i> Filter:</dt><dd>' + $page_filter.join(", ") + '</dd>' : ''
 
953
        ))
 
954
      .popover({
817
955
        placement: "bottom"
818
 
      , content: $('<dl></dl>').append(
819
 
            $page_sort.length > 0 ? '<dt><i class="icon-th-list"></i> Sort:</dt><dd>' + $page_sort.join(", ") + '</dd>' : ''
820
 
          , $page_filter.length > 0 ? '<dt><i class="icon-filter"></i> Filter:</dt><dd>' + $page_filter.join(", ") + '</dd>' : ''
821
 
        )
822
 
    });
 
956
      });
823
957
 
824
958
    this.buttons.unshift($info);
825
959
  }
831
965
 
832
966
    // create the button
833
967
    $overflow
834
 
      .addClass("btn add-on")
 
968
      .addClass("btn")
835
969
      .attr("href", "#")
836
 
      .html("<i class=\"icon-resize-full\"></i>")
 
970
      .attr("title", "Toggle the size of the table to fit the data or to fit the screen.")
 
971
      .append(
 
972
        $("<span></span>")
 
973
          .addClass("glyphicon glyphicon-resize-full")
 
974
      )
837
975
      .click(function() {
838
 
        _toggleOverflow.call(this, $wrapper);
 
976
        if($wrapper) _toggleOverflow.call(this, $wrapper);
839
977
        return false;
840
978
      });
 
979
 
 
980
    if(!this.resultset || !this.resultset.data || this.resultset.data.length == 0)
 
981
      $overflow
 
982
        .addClass("disabled")
 
983
 
841
984
    this.buttons.push($overflow);
842
985
  }
843
986
 
844
987
  function _toggleOverflow(el) {
845
988
    if(el.css('overflow') == 'scroll') {
846
 
      $(this).children("i")
847
 
        .attr("class", "icon-resize-full");
 
989
      $(this).children("span.glyphicon")
 
990
        .attr("class", "glyphicon glyphicon-resize-full");
848
991
 
849
992
      el.css({
850
993
          overflow: 'visible'
852
995
      });
853
996
    }
854
997
    else {
855
 
      $(this).children("i")
856
 
        .attr("class", "icon-resize-small");
 
998
      $(this).children("span.glyphicon")
 
999
        .attr("class", "glyphicon glyphicon-resize-small");
857
1000
 
858
1001
      el.css({
859
1002
          overflow: 'scroll'
874
1017
      o.currentPage--;
875
1018
      offset = o.currentPage * o.perPage;
876
1019
    }
877
 
 
878
 
    if(o.currentPage === 0) o.currentPage = 1;
 
1020
    if(o.currentPage < 1) o.currentPage = 1;
879
1021
 
880
1022
    if($(this).popover) $(this).popover('hide');
881
1023
 
889
1031
    var o = this.options
890
1032
      , $e = this.$element;
891
1033
 
 
1034
    $e.empty();
 
1035
 
892
1036
    // initialize the toolbar
893
1037
    _initToolbar.call(this);
894
1038
 
898
1042
 
899
1043
    this.loading( false );
900
1044
 
901
 
    $e.empty();
902
1045
    if(this.$default) $e.append(this.$default);
903
1046
  }
904
1047
 
913
1056
 
914
1057
  function _updateColumnModalBody(body) {
915
1058
    var o = this.options
916
 
      , $container = $("<fieldset></fieldset>")
 
1059
      , $container = $("<form></form>").addClass("form-inline")
917
1060
      , that = this;
918
1061
 
919
1062
    // loop through the columns
920
1063
    for(var column in o.columns) {
921
1064
      if(o.columns[column].title === "") continue;
922
 
      var $item = $('<div class="control-group" style="float: left" data-column="' + column + '"><label class="control-label">' + o.columns[column].title + '</label><div class="controls"><div class="btn-group" data-toggle="buttons-radio"><a href="#" class="btn ' + (o.columns[column].hidden ? "" : "active") + '"><i class="icon-ok"></i></a><a href="#" class="btn ' + (o.columns[column].hidden ? "active" : "") + '"><i class="icon-remove"></i></a></div></div></div>')
923
 
        .click(function() {
924
 
          _toggleColumn.call(this, that);
925
 
          return false;
926
 
        });
 
1065
      var $item = $('<div></div></br>')
 
1066
        .addClass('form-group')
 
1067
        .append(
 
1068
          $("<label></label>")
 
1069
            .addClass("control-label")
 
1070
            .append(
 
1071
              o.columns[column].title,
927
1072
 
 
1073
              $("<button></button>")
 
1074
                .addClass("on-off btn " + (o.columns[column].hidden ? 'btn-info' : 'btn-warning'))
 
1075
                .data("column", column)
 
1076
                .data("column-hidden",o.columns[column].hidden)
 
1077
                .text(o.columns[column].hidden ? "ON" : "OFF")
 
1078
                .click(function () {
 
1079
                  _toggleColumn.call(this, that);
 
1080
                  return false;
 
1081
                })
 
1082
            )
 
1083
        );
928
1084
      $container.append($item);
929
1085
    }
930
1086
 
931
1087
    body.empty();
932
1088
    body.append(
933
 
      $("<form></form>")
934
 
        .addClass("form-horizontal")
935
 
        .append($container)
 
1089
      $container
936
1090
    );
937
1091
  }
938
1092
 
944
1098
    if($column.is(":visible")) {
945
1099
      $column.hide();
946
1100
      o.columns[column].hidden = true;
 
1101
      $(this).removeClass("btn-warning").addClass("btn-info").text("ON").data("column-hidden",true);
947
1102
    }
948
1103
    else {
949
1104
      $column.show();
950
1105
      o.columns[column].hidden = false;
 
1106
      $(this).removeClass("btn-info").addClass("btn-warning").text("OFF").data("column-hidden",false);
951
1107
    }
952
 
 
953
 
    $(this)
954
 
      .find("a.active")
955
 
      .removeClass("active");
956
 
 
957
 
    o.columns[column].hidden ?
958
 
      $(this).find(".icon-remove").parent().addClass("active") :
959
 
      $(this).find(".icon-ok").parent().addClass("active");
960
 
 
961
1108
    return false;
962
1109
  }
963
1110
 
993
1140
      , columns = data ? JSON.parse(data) : []
994
1141
      , res = this.resultset;
995
1142
 
996
 
    for(var column in o.columns) {
997
 
      o.columns[column] = $.extend({}, o.columns[column], (res.columns ? res.columns[column] : []), columns[column]);
 
1143
    // if the server doesn't pass the column property back
 
1144
    if(!res.columns) res.columns = [];
 
1145
 
 
1146
    for(column in o.columns) {
 
1147
      o.columns[column] = $.extend({}, o.columns[column], res.columns[column], columns[column]);
998
1148
    }
999
1149
  }
1000
1150
 
1047
1197
  };
1048
1198
 
1049
1199
  $.fn.datatable.defaults = {
1050
 
      debug: false
1051
 
    , id: undefined
1052
 
    , title: 'Data Table Results'
1053
 
    , class: 'table table-striped table-bordered'
1054
 
    , perPage: 10
1055
 
    , pagePadding: 2
1056
 
    , sort: [[]]
1057
 
    , filter: {}
1058
 
    , post: {}
1059
 
    , buttons: []
1060
 
    , sectionHeader: undefined
1061
 
    , totalRows: 0
1062
 
    , currentPage: 1
1063
 
    , showPagination: false
1064
 
    , showTopPagination: false
1065
 
    , showHeader: true
1066
 
    , showFooter: false
1067
 
    , showFilterRow: false
1068
 
    , filterModal: undefined
1069
 
    , allowExport: false
1070
 
    , allowOverflow: true
1071
 
    , allowMultipleSort: false
1072
 
    , toggleColumns: true
1073
 
    , url: ''
1074
 
    , columns: []
1075
 
    , ascending: '<i class="icon-chevron-up"></i>'
1076
 
    , descending: '<i class="icon-chevron-down"></i>'
1077
 
    , rowCallback: undefined
1078
 
    , tableCallback: undefined
1079
 
    , headerCallback: undefined
1080
 
    , footerCallback: undefined
1081
 
    , tablePreRender: undefined
1082
 
    , autoLoad: true
 
1200
    debug: false,
 
1201
    id: undefined,
 
1202
    title: 'Data Table Results',
 
1203
    class: 'table table-striped table-bordered',
 
1204
    perPage: 10,
 
1205
    pagePadding: 2,
 
1206
    sort: [],
 
1207
    filter: {},
 
1208
    post: {},
 
1209
    buttons: [],
 
1210
    sectionHeader: undefined,
 
1211
    totalRows: 0,
 
1212
    currentPage: 1,
 
1213
    showPagination: true,
 
1214
    showTopPagination: false,
 
1215
    showHeader: true,
 
1216
    showFooter: false,
 
1217
    showFilterRow: false,
 
1218
    filterModal: undefined,
 
1219
    allowExport: false,
 
1220
    allowOverflow: true,
 
1221
    allowMultipleSort: false,
 
1222
    allowSaveColumns: true,
 
1223
    toggleColumns: true,
 
1224
    url: '',
 
1225
    columns: [],
 
1226
    ascending: $("<span></span>").addClass("glyphicon glyphicon-chevron-up"),
 
1227
    descending: $("<span></span>").addClass("glyphicon glyphicon-chevron-down"),
 
1228
    rowCallback: undefined,
 
1229
    tableCallback: undefined,
 
1230
    headerCallback: undefined,
 
1231
    footerCallback: undefined,
 
1232
    tablePreRender: undefined,
 
1233
    autoLoad: true
1083
1234
  };
1084
 
 
1085
 
 
1086
1235
})(window.jQuery);