From af7521b2400c25cb63dcd5b8e4d1dd5c43a1a20d Mon Sep 17 00:00:00 2001
From: Dino Cikatic <dcikatic@edx.org>
Date: Wed, 17 Jun 2015 14:07:30 +0200
Subject: [PATCH] SOL-994 fix js loading if search features disabled

---
 lms/envs/common.py                       | 15 ++++++++++++---
 lms/templates/courseware/courses.html    |  4 ++++
 lms/templates/courseware/courseware.html | 15 +++++++++------
 lms/templates/dashboard.html             |  3 +++
 4 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/lms/envs/common.py b/lms/envs/common.py
index 03e968a3933..4581e0263e1 100644
--- a/lms/envs/common.py
+++ b/lms/envs/common.py
@@ -1202,10 +1202,11 @@ courseware_js = (
         for pth in ['courseware', 'histogram', 'navigation', 'time']
     ] +
     ['js/' + pth + '.js' for pth in ['ajax-error']] +
-    ['js/search/course/main.js'] +
     sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/modules/**/*.js'))
 )
 
+courseware_search_js = ['js/search/course/main.js']
+
 
 # Before a student accesses courseware, we do not
 # need many of the JS dependencies.  This includes
@@ -1235,9 +1236,9 @@ main_vendor_js = base_vendor_js + [
 ]
 
 dashboard_js = (
-    sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/dashboard/**/*.js')) +
-    ['js/search/dashboard/main.js']
+    sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/dashboard/**/*.js'))
 )
+dashboard_search_js = ['js/search/dashboard/main.js']
 discussion_js = sorted(rooted_glob(COMMON_ROOT / 'static', 'coffee/src/discussion/**/*.js'))
 rwd_header_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/utils/rwd_header.js'))
 staff_grading_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/staff_grading/**/*.js'))
@@ -1472,6 +1473,10 @@ PIPELINE_JS = {
         'source_filenames': courseware_js,
         'output_filename': 'js/lms-courseware.js',
     },
+    'courseware_search': {
+        'source_filenames': courseware_search_js,
+        'output_filename': 'js/lms-courseware-search.js',
+    },
     'base_vendor': {
         'source_filenames': base_vendor_js,
         'output_filename': 'js/lms-base-vendor.js',
@@ -1512,6 +1517,10 @@ PIPELINE_JS = {
         'source_filenames': dashboard_js,
         'output_filename': 'js/dashboard.js'
     },
+    'dashboard_search': {
+        'source_filenames': dashboard_search_js,
+        'output_filename': 'js/dashboard-search.js',
+    },
     'rwd_header': {
         'source_filenames': rwd_header_js,
         'output_filename': 'js/rwd_header.js'
diff --git a/lms/templates/courseware/courses.html b/lms/templates/courseware/courses.html
index 06f9c97bf06..ce124bb5361 100644
--- a/lms/templates/courseware/courses.html
+++ b/lms/templates/courseware/courses.html
@@ -8,6 +8,7 @@
 <%namespace name='static' file='../static_content.html'/>
 
 <%block name="header_extras">
+  % if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
   % for template_name in ["result_item", "filter_bar", "filter", "search_facets_list", "search_facets_section", "search_facet", "more_less_links"]:
   <script type="text/template" id="${template_name}-tpl">
       <%static:include path="discovery/${template_name}.underscore" />
@@ -20,10 +21,13 @@
         }});
       }})(define || RequireJS.define);
   </script>
+  % endif
 </%block>
 
 <%block name="js_extra">
+  % if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
   <%static:js group='discovery'/>
+  % endif
 </%block>
 
 <%block name="pagetitle">${_("Courses")}</%block>
diff --git a/lms/templates/courseware/courseware.html b/lms/templates/courseware/courseware.html
index 4a5f45b72d1..7e3e3862c0e 100644
--- a/lms/templates/courseware/courseware.html
+++ b/lms/templates/courseware/courseware.html
@@ -25,13 +25,13 @@ ${page_title_breadcrumbs(course_name())}
     <%static:include path="common/templates/${template_name}.underscore" />
 </script>
 % endfor
-
-% for template_name in ["course_search_item", "course_search_results", "search_loading", "search_error"]:
-<script type="text/template" id="${template_name}-tpl">
-    <%static:include path="search/${template_name}.underscore" />
-</script>
+% if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH'):
+    % for template_name in ["course_search_item", "course_search_results", "search_loading", "search_error"]:
+    <script type="text/template" id="${template_name}-tpl">
+        <%static:include path="search/${template_name}.underscore" />
+    </script>
 % endfor
-
+% endif
 </%block>
 
 <%block name="headextra">
@@ -65,6 +65,9 @@ ${page_title_breadcrumbs(course_name())}
 
   <%static:js group='courseware'/>
   <%static:js group='discussion'/>
+  % if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH'):
+    <%static:js group='courseware_search'/>
+  % endif
 
   <%include file="../discussion/_js_body_dependencies.html" />
   % if staff_access:
diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html
index 7c55e21be23..3dc379fab64 100644
--- a/lms/templates/dashboard.html
+++ b/lms/templates/dashboard.html
@@ -44,6 +44,9 @@ from django.core.urlresolvers import reverse
       });
     });
   </script>
+  % if settings.FEATURES.get('ENABLE_DASHBOARD_SEARCH'):
+    <%static:js group='dashboard_search'/>
+  % endif
 </%block>
 
 <div class="dashboard-notifications" tabindex="-1">
-- 
GitLab