1{*
2* 2007-2016 PrestaShop
3*
4* NOTICE OF LICENSE
5*
6* This source file is subject to the Academic Free License (AFL 3.0)
7* that is bundled with this package in the file LICENSE.txt.
8* It is also available through the world-wide-web at this URL:
9* http://opensource.org/licenses/afl-3.0.php
10* If you did not receive a copy of the license and are unable to
11* obtain it through the world-wide-web, please send an email
12* to license@prestashop.com so we can send you a copy immediately.
13*
14* DISCLAIMER
15*
16* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17* versions in the future. If you wish to customize PrestaShop for your
18* needs please refer to http://www.prestashop.com for more information.
19*
20*  @author PrestaShop SA <contact@prestashop.com>
21*  @copyright  2007-2016 PrestaShop SA
22
23*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
24*  International Registered Trademark & Property of PrestaShop SA
25*}
26
27<script type="text/javascript">{$autocompleteList}</script>
28<script type="text/javascript">
29    var header_confirm_reset = '{l s='Confirm reset'}';
30    var body_confirm_reset = '{l s='Would you like to delete the content related to this module ?'}';
31    var left_button_confirm_reset = '{l s='No - reset only the parameters'}';
32    var right_button_confirm_reset = '{l s='Yes - reset everything'}';
33	var currentIndex = '{$currentIndex|escape:'html':'UTF-8'}';
34	var currentIndexWithToken = '{$currentIndex|escape:'html':'UTF-8'}&token={$token|escape:'html':'UTF-8'}';
35	var dirNameCurrentIndex = '{$dirNameCurrentIndex}';
36	var ajaxCurrentIndex = '{$ajaxCurrentIndex}';
37	var installed_modules = {if isset($installed_modules) && $installed_modules}{$installed_modules}{else}false{/if};
38	var by = '{l s='by'}';
39	var confirmPreferencesSaved = '{l s='Preferences saved'}';
40	{if isset($smarty.get.anchor) && !isset($error_module)}var anchor = '{$smarty.get.anchor|htmlentities|replace:'(':''|replace:')':''|replace:'{':''|replace:'}':''|replace:'\'':''|replace:'/':''}';{else}var anchor = '';{/if}
41
42	{if isset($smarty.get.module_name) && !isset($error_module) && (!isset($dont_filter) || !$dont_filter)}var module_name = '{$smarty.get.module_name|htmlentities|replace:'(':''|replace:')':''|replace:'{':''|replace:'}':''|replace:'\'':''|replace:'/':''}';{else}var module_name = '';{/if}
43
44	{literal}
45
46	function truncate_author(author){return ((author.length > 20) ? author.substring(0, 20)+"..." : author);}
47	function modules_management(action)
48	{
49		var modules = document.getElementsByName('modules');
50		var module_list = '';
51		for (var i = 0; i < modules.length; i++)
52		{
53			if (modules[i].checked == true)
54			{
55				rel = modules[i].getAttribute('data-rel');
56				if (rel != "false" && action == "uninstall")
57				{
58					if (!confirm(rel))
59						return false;
60				}
61				module_list += '|'+modules[i].value;
62			}
63		}
64		document.location.href=currentIndex+'&token='+token+'&'+action+'='+module_list.substring(1, module_list.length);
65	}
66
67	$('document').ready( function() {
68		// ScrollTo
69		if (anchor != '')
70			$.uiTableFilter($('#moduleContainer').find('table'), anchor);
71
72		if (module_name != '')
73			$.uiTableFilter($('#moduleContainer').find('table'), module_name);
74
75		$('#moduleQuicksearch').on('keyup', function(){
76			val = this.value;
77			if ($('#filter_all').hasClass('active'))
78				$.uiTableFilter($('#moduleContainer').find('table'), val);
79			else
80				$('#filter_all').trigger('click');
81				var interval = setInterval(function () {
82				if (!$('#loader_module_list').length)
83				{
84					$.uiTableFilter($('#moduleContainer').find('table'), val);
85					clearInterval(interval);
86					interval = null;
87				}
88
89		}, 100);
90
91
92		}).on('keydown', function(e){
93			if (e.keyCode == 13)
94				return false;
95		});
96
97		$('input[name="filtername"]').result(function(event, data, formatted) {
98			$('#filternameForm').submit();
99		});
100
101		// Method to check / uncheck all modules checkbox
102		$('#moduleContainer').on("click", "#checkme", function()
103		{
104			if ($(this).attr("rel") == 'false')
105			{
106				$(this).attr("checked", true);
107				$(this).attr("rel", "true");
108				$("input[name=modules]").attr("checked", true);
109			}
110			else
111			{
112				$(this).removeAttr("checked");
113				$(this).attr("rel", "false");
114				$("input[name=modules]").removeAttr("checked");
115			}
116		});
117
118		// Method to reload filter in ajax
119		$('.categoryModuleFilterLink').click(function()
120		{
121			if ($(this).hasClass('active'))
122				return false;
123			$('.categoryModuleFilterLink').removeClass('active');
124			$(this).addClass('active');
125			try
126			{
127				resAjax = $.ajax({
128					type:"POST",
129					url : $(this).attr('href')+'&rand=' + new Date().getTime(),
130					headers: {"cache-control": "no-cache"},
131					async: true,
132					cache: false,
133					data : {
134						ajax : "1",
135						token : token,
136						controller : "AdminModules",
137						action : "reloadModulesList"
138					},
139					beforeSend: function(xhr){
140						$('#moduleContainer').html('<img id="loader_module_list" src="../img/loader.gif" alt="" border="0" />');
141					},
142					success: function(data, status, request){
143						if (request.getResponseHeader('Login') === 'true')
144							return window.location.reload();
145
146						$('#moduleContainer').html(data);
147						$('.dropdown-toggle').dropdown();
148						$('.help-tooltip').tooltip();
149					}
150				});
151			}
152			catch(e){}
153			return false;
154		});
155
156		// Method to get modules_list.xml from prestashop.com and default_country_modules_list.xml from addons.prestashop.com
157		try
158		{
159			resAjax = $.ajax({
160				type:"POST",
161				url: ajaxCurrentIndex,
162				headers: {"cache-control": "no-cache"},
163				async: true,
164				cache: false,
165				data: {
166					ajaxMode : "1",
167					ajax : "1",
168					token : token,
169					controller : "AdminModules",
170					action : "refreshModuleList"
171				},
172				success: function(data){
173					if (data == '{"status":"refresh"}')
174						window.location.href = window.location.href;
175				}
176			});
177		}
178		catch(e) { }
179
180		// Method to set filter on modules
181		function setFilter()
182		{
183			var module_type = $("#module_type_filter").val();
184			var module_install = $("#module_install_filter").val();
185			var module_status = $("#module_status_filter").val();
186			var country_module_value = $("#country_module_value_filter").val();
187			try
188			{
189				resAjax = $.ajax({
190					type:"POST",
191					url : ajaxCurrentIndex,
192					async: true,
193					data : {
194						ajax : "1",
195						token : token,
196						controller : "AdminModules",
197						action : "setFilter",
198						module_type : module_type,
199						module_install : module_install,
200						module_status : module_status,
201						country_module_value : country_module_value,
202						filterModules : 'Filter'
203					},
204					success : function(data){
205						if (data == 'OK')
206							window.location.href = currentIndexWithToken;
207					}
208				});
209			}
210			catch(e){}
211			return false;
212		}
213
214		$(document).on('change', '#module_type_filter, #module_install_filter, #module_status_filter, #country_module_value_filter', function() {
215			setFilter();
216		});
217
218		$('.moduleTabPreferencesChoise').change(function()
219		{
220			var value_pref = $(this).val();
221			var module_pref = $(this).attr('name');
222			module_pref = module_pref.substring(2, module_pref.length);
223
224			$.ajax({
225				type:"POST",
226				url : ajaxCurrentIndex,
227				async: true,
228				data : {
229					ajax : "1",
230					token : token,
231					controller : "AdminModules",
232					action : "saveTabModulePreferences",
233					module_pref : module_pref,
234					value_pref : value_pref
235				},
236				success : function(data){
237					if (data == 'OK')
238						showSuccessMessage(confirmPreferencesSaved);
239				}
240			});
241		});
242
243		// Method to save favorites preferences
244		$('.moduleFavorite').change(function()
245		{
246			var value_pref = $(this).val();
247			var module_pref = $(this).attr('name');
248			var action_pref = module_pref.substring(0, 1);
249			module_pref = module_pref.substring(2, module_pref.length);
250			try
251			{
252				resAjax = $.ajax({
253					type:"POST",
254					url : ajaxCurrentIndex,
255					async: true,
256					data : {
257						ajax : "1",
258						token : token,
259						controller : "AdminModules",
260						action : "saveFavoritePreferences",
261						action_pref : action_pref,
262						module_pref : module_pref,
263						value_pref : value_pref
264					},
265					success : function(data){
266						if (data == 'OK')
267							showSuccessMessage(confirmPreferencesSaved);
268					}
269				});
270			}
271			catch(e){}
272			return false;
273		});
274
275		$('#moduleContainer').on("click", ".toggle_favorite", function()
276	    {
277	      var el = $(this);
278	      var value_pref = el.data('value');
279	      var module_pref = el.data('module');
280	      var action_pref = 'f';
281	      var total_favorites = parseInt($('#favorite-count').html());
282
283	      try
284	      {
285	        resAjax = $.ajax({
286	            type:"POST",
287	            url : ajaxCurrentIndex,
288	            async: true,
289	            data : {
290	              ajax : "1",
291	              token : token,
292	              controller : "AdminModules",
293	              action : "saveFavoritePreferences",
294	              action_pref : action_pref,
295	              module_pref : module_pref,
296	              value_pref : value_pref
297	            },
298	            success : function(data)
299	            {
300	              // res.status  = cache or refresh
301	              if (data == 'OK')
302	              {
303	                el.toggle();
304	                el.parent('li').siblings().find('a.toggle_favorite').toggle();
305
306					if (value_pref)
307						$('#favorite-count').html(total_favorites+1);
308					else
309						$('#favorite-count').html(total_favorites-1);
310	              }
311
312	            },
313	            error: function(res,textStatus,jqXHR)
314	            {
315	              //jAlert("TECHNICAL ERROR"+res);
316	            }
317	        });
318	      }
319	      catch(e){}
320	      return false;
321	    });
322	});
323
324	{/literal}
325</script>
326