Set the plugin configuration - refs #7279

1.9.x
Angel Fernando Quiroz Campos 11 years ago
parent 36836206e8
commit 222261d16f
  1. 36
      plugin/tour/index.php
  2. 136
      plugin/tour/views/script.tpl

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

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

Loading…
Cancel
Save