define(['text!./filter-all.html', 'app', 'lodash','angular','jquery'], function(template, app, _,angular,$) { 'use strict';

app.directive('filterAll',['$http','Thesaurus','$timeout', function ($http,thesaurus,$timeout) {
    return {
        restrict: 'EAC',
        template: template,
        replace: true,
        require : '^reportingDisplay',
        scope: {
              title: '@title',
              items: '=ngModel',
              facet: '@facet',
              count: '=count' // total count of all children subquires needed for 0 result combinations
        },
          link : function ($scope, $element, $attr, reportingDisplayCtrl)
        {
            $scope.expanded = false;
            var termsMap =[];
            $scope.termsModal = {};

            $scope.terms = [{
              id: 'B3079A36-32A3-41E2-BDE0-65E4E3A51601',
              title: '5th National Report',
              count:0,
              selected: 0
            }, {
              id: '272B0A17-5569-429D-ADF5-2A55C588F7A7',
              title: '4th National Report',
              count:0,
              selected: 0
            }, {
              id: 'DA7E04F1-D2EA-491E-9503-F7923B1FD7D4',
              title: '3rd National Report',
              count:0,
              selected: 0
            }, {
              id: 'A49393CA-2950-4EFD-8BCC-33266D69232F',
              title: '2nd National Report',
              count:0,
              selected: 0
            }, {
              id: 'F27DBC9B-FF25-471B-B624-C0F73E76C8B3',
              title: '1st National Report',
              count:0,
              selected: 0
            }];


            $scope.$watch('items',function(){reportingDisplayCtrl.updateTerms(termsMap,$scope.items,$scope.facet);});

            //=======================================================================
            //
            //=======================================================================
            function buildTermsAndQuery() {


              $scope.terms = searchCtrl.updateTerms($scope.terms,$scope.items,$scope.facet);
              searchCtrl.buildChildQuery($scope.terms,$scope.items,$scope.facet);
            }//buildTermsAndQuery()


            //=======================================================================
            //
            //=======================================================================
            $scope.termsNotSelected = function () {
                  _.each($scope.terms, function (term) {
                      term.selected=0;
                  });
            }//buildTermsAndQuery()


            //============================================================
        		//
        		//
        		//============================================================
        		function getAichiTargets() {

          			var  queryParameters = {
          							'q': 'schema_s:nationalReport',
          							'fl': '*',
          							'wt': 'json',
          							'start': 0,
          							'rows': 20,
          			};
          			//return defer;
          			return $http.get('https://api.cbd.int/api/v2013/index/select', { params: queryParameters, cache:true })				.then(function (data) {
                					return {'data':data.data.response.docs};
                });

        		}// getOrganizations



              //=======================================================================
              //
              //=======================================================================
              $scope.loadReports = function (type) {

                if(type)
                    reportingDisplayCtrl.addSubQuery('nationalReport','schema_s:nationalReport AND _latest_s:true AND _state_s:public AND reportType_s:'+type+' ',true);
                else
                    reportingDisplayCtrl.deleteAllSubQuery('nationalReport');
                reportingDisplayCtrl.search();

              };// flatten

        }//link
    }; // return
  }]);  //app.directive('searchFilterCountries
});// define

@@ -762,876 +762,8 @@
 %7D;%0A%0A
-            $scope.terms = %5B%7B%0A              id: 'B3079A36-32A3-41E2-BDE0-65E4E3A51601',%0A              title: '5th National Report',%0A              count:0,%0A              selected: 0%0A            %7D, %7B%0A              id: '272B0A17-5569-429D-ADF5-2A55C588F7A7',%0A              title: '4th National Report',%0A              count:0,%0A              selected: 0%0A            %7D, %7B%0A              id: 'DA7E04F1-D2EA-491E-9503-F7923B1FD7D4',%0A              title: '3rd National Report',%0A              count:0,%0A              selected: 0%0A            %7D, %7B%0A              id: 'A49393CA-2950-4EFD-8BCC-33266D69232F',%0A              title: '2nd National Report',%0A              count:0,%0A              selected: 0%0A            %7D, %7B%0A              id: 'F27DBC9B-FF25-471B-B624-C0F73E76C8B3',%0A              title: '1st National Report',%0A              count:0,%0A              selected: 0%0A            %7D%5D;
 %0A%0A%0A 
@@ -763,32 +763,34 @@
 ;%0A%0A%0A%0A%0A          
+//
   $scope.$watch(
@@ -885,32 +885,35 @@
 %7D);%0A%0A           
+ //
  //=============
@@ -977,32 +977,35 @@
 =%0A            //
+ //
 %0A            //=
@@ -992,32 +992,35 @@
 / //%0A           
+ //
  //=============
@@ -1089,16 +1089,19 @@
         
+ //
  functio
@@ -1125,17 +1125,45 @@
 ery() %7B%0A
-%0A
+            //%0A            //
 %0A       
@@ -1158,32 +1158,35 @@
   //%0A           
+ //
    $scope.terms 
@@ -1263,18 +1263,21 @@
         
+//
   
+ 
 searchCt
@@ -1340,32 +1340,35 @@
 t);%0A            
+// 
 %7D//buildTermsAnd
@@ -1379,1125 +1379,8 @@
 y()%0A
-%0A%0A            //=======================================================================%0A            //%0A            //=======================================================================%0A            $scope.termsNotSelected = function () %7B%0A                  _.each($scope.terms, function (term) %7B%0A                      term.selected=0;%0A                  %7D);%0A            %7D//buildTermsAndQuery()%0A%0A%0A            //============================================================%0A        %09%09//%0A        %09%09//%0A        %09%09//============================================================%0A        %09%09function getAichiTargets() %7B%0A%0A          %09%09%09var  queryParameters = %7B%0A          %09%09%09%09%09%09%09'q': 'schema_s:nationalReport',%0A          %09%09%09%09%09%09%09'fl': '*',%0A          %09%09%09%09%09%09%09'wt': 'json',%0A          %09%09%09%09%09%09%09'start': 0,%0A          %09%09%09%09%09%09%09'rows': 20,%0A          %09%09%09%7D;%0A          %09%09%09//return defer;%0A          %09%09%09return $http.get('https://api.cbd.int/api/v2013/index/select', %7B params: queryParameters, cache:true %7D)%09%09%09%09.then(function (data) %7B%0A                %09%09%09%09%09return %7B'data':data.data.response.docs%7D;%0A                %7D);%0A%0A        %09%09%7D// getOrganizations
 %0A%0A%0A%0A
@@ -1599,20 +1599,20 @@
 e.loadRe
-port
+cord
 s = func
@@ -1621,46 +1621,14 @@
 on (
-type
 ) %7B%0A%0A
-                if(type)%0A    
+%0A
     
@@ -1665,32 +1665,48 @@
 rl.addSubQuery('
+all','(schema_s:
 nationalReport',
@@ -1703,19 +1703,20 @@
 alReport
-','
+ OR 
 schema_s
@@ -1724,22 +1724,28 @@
 national
-Report
+Assessment) 
  AND _la
@@ -1780,141 +1780,17 @@
 lic 
-AND reportType_s:'+type+' ',true);%0A                else%0A                    reportingDisplayCtrl.deleteAllSubQuery('nationalReport');
+',true);%0A
 %0A   

Clean all record filter