Browse Source

Set the plugin configuration - refs #7279

Angel Fernando Quiroz Campos 10 years ago
parent
commit
222261d16f
2 changed files with 89 additions and 83 deletions
  1. 20 16
      plugin/tour/index.php
  2. 69 67
      plugin/tour/views/script.tpl

+ 20 - 16
plugin/tour/index.php

@@ -14,24 +14,28 @@ $pluginWebPath = api_get_path(WEB_PLUGIN_PATH) . 'tour/';
 $userId = api_get_user_id();
 
 $tourPlugin = Tour::create();
-
 $config = $tourPlugin->getTourCofig();
+$showTour = $tourPlugin->get('show_tour') === 'true';
 
-$pages = array();
+if ($showTour) {
+    $pages = array();
 
-foreach ($config as $pageContent) {
-    $pages[] = array(
-        'pageClass' => $pageContent['pageClass'],
-        'show' => $tourPlugin->checkTourForUser($pageContent['pageClass'], $userId)
-    );
-}
+    foreach ($config as $pageContent) {
+        $pages[] = array(
+            'pageClass' => $pageContent['pageClass'],
+            'show' => $tourPlugin->checkTourForUser($pageContent['pageClass'], $userId)
+        );
+    }
 
-$_template['pages'] = json_encode($pages);
+    $_template['show_tour'] = $showTour;
 
-$_template['web_path'] = array(
-    'intro_css' => "{$pluginWebPath}intro.js/introjs.min.css",
-    'intro_theme_css' => "{$pluginWebPath}intro.js/introjs-nassim.css",
-    'intro_js' => "{$pluginWebPath}intro.js/intro.min.js",
-    'steps_ajax' => "{$pluginWebPath}ajax/steps.ajax.php",
-    'save_ajax' => "{$pluginWebPath}ajax/save.ajax.php"
-);
+    $_template['pages'] = json_encode($pages);
+
+    $_template['web_path'] = array(
+        'intro_css' => "{$pluginWebPath}intro.js/introjs.min.css",
+        'intro_theme_css' => "{$pluginWebPath}intro.js/introjs-nassim.css",
+        'intro_js' => "{$pluginWebPath}intro.js/intro.min.js",
+        'steps_ajax' => "{$pluginWebPath}ajax/steps.ajax.php",
+        'save_ajax' => "{$pluginWebPath}ajax/save.ajax.php"
+    );
+}

+ 69 - 67
plugin/tour/views/script.tpl

@@ -1,84 +1,86 @@
-<script type="text/javascript">
-    var chamiloTour = (function() {
-        var intro = null;
-        var $btnStart = null;
+{% if tour.show_tour %}
+    <script type="text/javascript">
+        var chamiloTour = (function() {
+            var intro = null;
+            var $btnStart = null;
 
-        var setSteps = function (stepsData) {
-            var steps = new Array();
+            var setSteps = function (stepsData) {
+                var steps = new Array();
 
-            $.each(stepsData, function () {
-                var step = this;
+                $.each(stepsData, function () {
+                    var step = this;
 
-                if (step.element) {
-                    if ($(step.element).length > 0) {
+                    if (step.element) {
+                        if ($(step.element).length > 0) {
+                            steps.push(step);
+                        }
+                    } else {
                         steps.push(step);
                     }
-                } else {
-                    steps.push(step);
-                }
-            });
+                });
 
-            return steps;
-        };
+                return steps;
+            };
 
-        return {
-            init: function(pageClass) {
-                $.getJSON('{{ tour.web_path.steps_ajax }}', {
-                    'page_class': pageClass
-                }, function(response) {
-                    intro = introJs();
-                    intro.setOptions({
-                        steps: setSteps(response),
-                        nextLabel: '{{ 'Next' | get_lang }}',
-                        prevLabel: '{{ 'Prev' | get_lang }}',
-                        skipLabel: '{{ 'Skip' | get_lang }}',
-                        doneLabel: '{{ 'Done' | get_lang }}'
-                    });
-                    intro.oncomplete(function () {
-                        $.post('{{ tour.web_path.save_ajax }}', {
-                            page_class: pageClass
-                        }, function () {
-                            $btnStart.remove();
+            return {
+                init: function(pageClass) {
+                    $.getJSON('{{ tour.web_path.steps_ajax }}', {
+                        'page_class': pageClass
+                    }, function(response) {
+                        intro = introJs();
+                        intro.setOptions({
+                            steps: setSteps(response),
+                            nextLabel: '{{ 'Next' | get_lang }}',
+                            prevLabel: '{{ 'Prev' | get_lang }}',
+                            skipLabel: '{{ 'Skip' | get_lang }}',
+                            doneLabel: '{{ 'Done' | get_lang }}'
+                        });
+                        intro.oncomplete(function () {
+                            $.post('{{ tour.web_path.save_ajax }}', {
+                                page_class: pageClass
+                            }, function () {
+                                $btnStart.remove();
+                            });
                         });
-                    });
 
-                    $btnStart = $('<button>', {
-                        class: 'btn btn-primary btn-large',
-                        text: '{{ 'StartButtonText' | get_lang }}',
-                        click: function(e) {
-                            e.preventDefault();
+                        $btnStart = $('<button>', {
+                            class: 'btn btn-primary btn-large',
+                            text: '{{ 'StartButtonText' | get_lang }}',
+                            click: function(e) {
+                                e.preventDefault();
 
-                            intro.start();
-                        }
-                    }).appendTo('#tour-button-cotainer');
-                });
-            }
-        };
-    })();
+                                intro.start();
+                            }
+                        }).appendTo('#tour-button-cotainer');
+                    });
+                }
+            };
+        })();
 
-    $(document).on('ready', function() {
-        var pages = {{ tour.pages }};
+        $(document).on('ready', function() {
+            var pages = {{ tour.pages }};
 
-        $.each(pages, function(index, page) {
-            var thereIsSelectedPage = $(page.pageClass).length > 0;
+            $.each(pages, function(index, page) {
+                var thereIsSelectedPage = $(page.pageClass).length > 0;
 
-            if (thereIsSelectedPage && page.show) {
-                $('<link>', {
-                    href: '{{ tour.web_path.intro_css }}',
-                    rel: 'stylesheet'
-                }).appendTo('head');
+                if (thereIsSelectedPage && page.show) {
+                    $('<link>', {
+                        href: '{{ tour.web_path.intro_css }}',
+                        rel: 'stylesheet'
+                    }).appendTo('head');
 
-                $('<link>', {
-                    href: '{{ tour.web_path.intro_theme_css }}',
-                    rel: 'stylesheet'
-                }).appendTo('head');
+                    $('<link>', {
+                        href: '{{ tour.web_path.intro_theme_css }}',
+                        rel: 'stylesheet'
+                    }).appendTo('head');
 
-                $.getScript('{{ tour.web_path.intro_js }}', function() {
-                    chamiloTour.init(page.pageClass);
-                });
-            }
+                    $.getScript('{{ tour.web_path.intro_js }}', function() {
+                        chamiloTour.init(page.pageClass);
+                    });
+                }
+            });
         });
-    });
-</script>
+    </script>
 
-<div id="tour-button-cotainer"></div>
+    <div id="tour-button-cotainer"></div>
+{% endif %}