=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js' --- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js 2013-09-08 19:44:49 +0000 +++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js 2013-09-08 20:40:11 +0000 @@ -6,6 +6,7 @@ dhis2.db.currentItemPos; dhis2.db.currentShareType; dhis2.db.currentShareId; +dhis2.db.currentMaxType = []; // TODO remove position from template // TODO support table as link and embedded @@ -47,7 +48,9 @@ dashboardIntro: "
  • ${i18n_add}
    " + "
    ${i18n_arrange}
  • ", - hitHeader: "
  • ${title}
  • ", + hitHeader: "
  • ${title}   " + + "See more hits »" + + "
  • ", hitItem: "
  • ${name}" + "{{if canManage}}Add{{/if}}
  • ", @@ -523,6 +526,18 @@ // Search //------------------------------------------------------------------------------ +dhis2.db.searchMore = function( type ) +{ + dhis2.db.currentMaxType.push( type ); + dhis2.db.search(); +} + +dhis2.db.searchFewer = function( type ) +{ + dhis2.db.currentMaxType.splice( $.inArray( type, dhis2.db.currentMaxType ), 1 ); + dhis2.db.search(); +} + dhis2.db.search = function() { var query = $.trim( $( "#searchField" ).val() ); @@ -532,15 +547,42 @@ dhis2.db.hideSearch(); return false; } - - var hits = $.get( "../api/dashboards/q/" + query, function( data ) { + + var hits = $.get( "../api/dashboards/q/" + query + dhis2.db.getMaxParams(), function( data ) { var $h = $( "#hitDiv" ); dhis2.db.renderSearch( data, $h ); + dhis2.db.setHitLinks(); $h.show(); $( "#searchField" ).focus(); } ); } +dhis2.db.setHitLinks = function() +{ + for ( var i = 0; i < dhis2.db.currentMaxType.length; i++ ) + { + var type = dhis2.db.currentMaxType[i]; + + $( "#hitMore-" + type ).hide(); + $( "#hitFewer-" + type ).show(); + } +} + +dhis2.db.getMaxParams = function() +{ + var params = "?"; + + if ( dhis2.db.currentMaxType.length ) + { + for ( var i = 0; i < dhis2.db.currentMaxType.length; i++ ) + { + params += "max=" + dhis2.db.currentMaxType[i] + "&"; + } + } + + return params.substring( 0, ( params.length - 1 ) ); +} + dhis2.db.renderSearch = function( data, $h ) { $h.empty().append( "