From 4dd5dbb28974b3f0d9cbcc9b502aab2d83b5e6f3 Mon Sep 17 00:00:00 2001
From: Simon Lejeune <sle@openerp.com>
Date: Thu, 4 Dec 2014 14:57:48 +0100
Subject: [PATCH] [FIX] survey: only load js scripts when needed

This is done with the help of website.if_dom_contains and 1) js_surveyform
class for survey.js 2) a new fake class js_surveyresult for survey_result.js
This fix also allow to avoid spurious logs on runbot during phantomjs tests.
---
 addons/survey/static/src/js/survey.js        | 8 ++++----
 addons/survey/static/src/js/survey_result.js | 8 +++++---
 addons/survey/views/survey_result.xml        | 2 +-
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/addons/survey/static/src/js/survey.js b/addons/survey/static/src/js/survey.js
index f0096ddd3ee5..d8c1d07f300e 100644
--- a/addons/survey/static/src/js/survey.js
+++ b/addons/survey/static/src/js/survey.js
@@ -21,12 +21,11 @@
  * the website engine.
  */
 
-$(document).ready(function () {
-    'use strict';
-
+(function () {
+'use strict';
+openerp.website.if_dom_contains('.js_surveyform', function (the_form) {
     console.debug("[survey] Custom JS for survey is loading...");
 
-    var the_form = $('.js_surveyform');
     var prefill_controller = the_form.attr("data-prefill");
     var validate_controller = the_form.attr("data-validate");
     var submit_controller = the_form.attr("data-submit");
@@ -153,3 +152,4 @@ $(document).ready(function () {
 
     console.debug("[survey] Custom JS for survey loaded!");
 });
+})();
diff --git a/addons/survey/static/src/js/survey_result.js b/addons/survey/static/src/js/survey_result.js
index 6a7ccad14310..780345c736b0 100644
--- a/addons/survey/static/src/js/survey_result.js
+++ b/addons/survey/static/src/js/survey_result.js
@@ -16,8 +16,9 @@
  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-$(document).ready(function () {
-    'use strict';
+(function () {
+'use strict';
+openerp.website.if_dom_contains('.js_surveyresult', function () {
     console.debug("[survey] Survey Result JS is loading...");
 
     //Script For Pagination
@@ -174,4 +175,5 @@ $(document).ready(function () {
     });
 
     console.debug("[survey] Survey Result JS loaded!");
-});
\ No newline at end of file
+});
+})();
diff --git a/addons/survey/views/survey_result.xml b/addons/survey/views/survey_result.xml
index 74742eb16c91..bc49f8008329 100644
--- a/addons/survey/views/survey_result.xml
+++ b/addons/survey/views/survey_result.xml
@@ -13,7 +13,7 @@
     <template id="result" name="Survey Result">
         <t t-call="website.layout">
             <div class="oe_structure" />
-            <div class="container">
+            <div class="container js_surveyresult">
                 <div class="jumbotron mt32">
                     <h1><span t-field="survey.title" /> <span style="font-size:1.5em;" class="fa fa-bar-chart-o pull-right "/></h1>
                     <div t-field="survey.description" class="oe_no_empty" />
-- 
GitLab