Subversion Repositories SmartDukaan

Rev

Rev 37046 | Rev 37050 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37046 Rev 37048
Line 87... Line 87...
87
    // the date-scoped table; the view auto-scrolls there so a search from the bottom box is visible
87
    // the date-scoped table; the view auto-scrolls there so a search from the bottom box is visible
88
    // without the user having to scroll back up manually.
88
    // without the user having to scroll back up manually.
89
    var LEAD_SEARCH_BOXES = "#lead-table_filter input, #lead-table-bottom-filter";
89
    var LEAD_SEARCH_BOXES = "#lead-table_filter input, #lead-table-bottom-filter";
90
    var leadGlobalSearchTimer = null;
90
    var leadGlobalSearchTimer = null;
91
 
91
 
-
 
92
    function clearInjectedGlobalRows() {
-
 
93
        if ($.fn.dataTable.isDataTable('#lead-table')) {
-
 
94
            $('#lead-table').DataTable()
-
 
95
                .rows('.global-search-row')
-
 
96
                .remove()
-
 
97
                .draw(false);
-
 
98
        }
-
 
99
    }
-
 
100
 
92
    function runGlobalLeadSearch(term) {
101
    function runGlobalLeadSearch(term) {
93
        term = $.trim(term || "");
102
        term = $.trim(term || "");
94
        if (term.length < 2) {
103
        if (term.length < 2) {
95
            $('#global-search-results').html("");
104
            $('#global-search-results').html("");
-
 
105
            clearInjectedGlobalRows();
96
            return;
106
            return;
97
        }
107
        }
98
        var safeTerm = $('<div>').text(term).html();
108
        var safeTerm = $('<div>').text(term).html();
99
        doGetAjaxRequestHandler(context + "/globalLeadSearch?searchTerm=" + encodeURIComponent(term),
109
        doGetAjaxRequestHandler(context + "/globalLeadSearch?searchTerm=" + encodeURIComponent(term),
100
            function (response) {
110
            function (response) {
Line 103... Line 113...
103
                    + '<small class="text-muted">(matching "' + safeTerm + '")</small></h4>' + response);
113
                    + '<small class="text-muted">(matching "' + safeTerm + '")</small></h4>' + response);
104
                var resultsEl = document.getElementById('global-search-results');
114
                var resultsEl = document.getElementById('global-search-results');
105
                if (resultsEl) {
115
                if (resultsEl) {
106
                    resultsEl.scrollIntoView({behavior: 'smooth', block: 'start'});
116
                    resultsEl.scrollIntoView({behavior: 'smooth', block: 'start'});
107
                }
117
                }
-
 
118
 
-
 
119
                // Mirror the hits into the main #lead-table so the same row is findable there too.
-
 
120
                // Rows carry class .global-search-row so we can clear them on the next search.
-
 
121
                clearInjectedGlobalRows();
-
 
122
                var $hiddenRows = $('#global-search-main-rows tbody tr');
-
 
123
                if ($hiddenRows.length && $.fn.dataTable.isDataTable('#lead-table')) {
-
 
124
                    var dt = $('#lead-table').DataTable();
-
 
125
                    $hiddenRows.each(function () {
-
 
126
                        dt.row.add(this);
-
 
127
                    });
-
 
128
                    dt.draw(false);
-
 
129
                }
108
            });
130
            });
109
    }
131
    }
110
 
132
 
111
    $(document).on('keydown', LEAD_SEARCH_BOXES, function (e) {
133
    $(document).on('keydown', LEAD_SEARCH_BOXES, function (e) {
112
        if (e.which === 13) {
134
        if (e.which === 13) {