PageRenderTime 66ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/js/admin.js

https://gitlab.com/mtellezgalindo/PrestaShop
JavaScript | 1549 lines | 1340 code | 146 blank | 63 comment | 239 complexity | 43d50c4cba73c3b6d194e7f73d0bdda6 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-3.0
  1. /*
  2. *
  3. * NOTICE OF LICENSE
  4. *
  5. * This source file is subject to the Open Software License (OSL 3.0)
  6. * that is bundled with this package in the file LICENSE.txt.
  7. * It is also available through the world-wide-web at this URL:
  8. * http://opensource.org/licenses/osl-3.0.php
  9. * If you did not receive a copy of the license and are unable to
  10. * obtain it through the world-wide-web, please send an email
  11. * to license@prestashop.com so we can send you a copy immediately.
  12. *
  13. * DISCLAIMER
  14. *
  15. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  16. * versions in the future. If you wish to customize PrestaShop for your
  17. * needs please refer to http://www.prestashop.com for more information.
  18. *
  19. * @author PrestaShop SA <contact@prestashop.com>
  20. * @copyright 2007-2014 PrestaShop SA
  21. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  22. * International Registered Trademark & Property of PrestaShop SA
  23. */
  24. var ajax_running_timeout = null;
  25. if (!id_language)
  26. var id_language = Number(1);
  27. function str2url(str, encoding, ucfirst)
  28. {
  29. str = str.toUpperCase();
  30. str = str.toLowerCase();
  31. if (PS_ALLOW_ACCENTED_CHARS_URL)
  32. str = str.replace(/[^a-z0-9\s\'\:\/\[\]-]\\u00A1-\\uFFFF/g,'');
  33. else
  34. {
  35. /* Lowercase */
  36. str = str.replace(/[\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u0101\u0103\u0105\u0430]/g, 'a');
  37. str = str.replace(/[\u0431]/g, 'b');
  38. str = str.replace(/[\u00E7\u0107\u0109\u010D\u0446]/g, 'c');
  39. str = str.replace(/[\u010F\u0111\u0434]/g, 'd');
  40. str = str.replace(/[\u00E8\u00E9\u00EA\u00EB\u0113\u0115\u0117\u0119\u011B\u0435\u044D]/g, 'e');
  41. str = str.replace(/[\u0444]/g, 'f');
  42. str = str.replace(/[\u011F\u0121\u0123\u0433\u0491]/g, 'g');
  43. str = str.replace(/[\u0125\u0127]/g, 'h');
  44. str = str.replace(/[\u00EC\u00ED\u00EE\u00EF\u0129\u012B\u012D\u012F\u0131\u0438\u0456]/g, 'i');
  45. str = str.replace(/[\u0135\u0439]/g, 'j');
  46. str = str.replace(/[\u0137\u0138\u043A]/g, 'k');
  47. str = str.replace(/[\u013A\u013C\u013E\u0140\u0142\u043B]/g, 'l');
  48. str = str.replace(/[\u043C]/g, 'm');
  49. str = str.replace(/[\u00F1\u0144\u0146\u0148\u0149\u014B\u043D]/g, 'n');
  50. str = str.replace(/[\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8\u014D\u014F\u0151\u043E]/g, 'o');
  51. str = str.replace(/[\u043F]/g, 'p');
  52. str = str.replace(/[\u0155\u0157\u0159\u0440]/g, 'r');
  53. str = str.replace(/[\u015B\u015D\u015F\u0161\u0441]/g, 's');
  54. str = str.replace(/[\u00DF]/g, 'ss');
  55. str = str.replace(/[\u0163\u0165\u0167\u0442]/g, 't');
  56. str = str.replace(/[\u00F9\u00FA\u00FB\u00FC\u0169\u016B\u016D\u016F\u0171\u0173\u0443]/g, 'u');
  57. str = str.replace(/[\u0432]/g, 'v');
  58. str = str.replace(/[\u0175]/g, 'w');
  59. str = str.replace(/[\u00FF\u0177\u00FD\u044B]/g, 'y');
  60. str = str.replace(/[\u017A\u017C\u017E\u0437]/g, 'z');
  61. str = str.replace(/[\u00E6]/g, 'ae');
  62. str = str.replace(/[\u0447]/g, 'ch');
  63. str = str.replace(/[\u0445]/g, 'kh');
  64. str = str.replace(/[\u0153]/g, 'oe');
  65. str = str.replace(/[\u0448]/g, 'sh');
  66. str = str.replace(/[\u0449]/g, 'ssh');
  67. str = str.replace(/[\u044F]/g, 'ya');
  68. str = str.replace(/[\u0454]/g, 'ye');
  69. str = str.replace(/[\u0457]/g, 'yi');
  70. str = str.replace(/[\u0451]/g, 'yo');
  71. str = str.replace(/[\u044E]/g, 'yu');
  72. str = str.replace(/[\u0436]/g, 'zh');
  73. /* Uppercase */
  74. str = str.replace(/[\u0100\u0102\u0104\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u0410]/g, 'A');
  75. str = str.replace(/[\u0411]/g, 'B');
  76. str = str.replace(/[\u00C7\u0106\u0108\u010A\u010C\u0426]/g, 'C');
  77. str = str.replace(/[\u010E\u0110\u0414]/g, 'D');
  78. str = str.replace(/[\u00C8\u00C9\u00CA\u00CB\u0112\u0114\u0116\u0118\u011A\u0415\u042D]/g, 'E');
  79. str = str.replace(/[\u0424]/g, 'F');
  80. str = str.replace(/[\u011C\u011E\u0120\u0122\u0413\u0490]/g, 'G');
  81. str = str.replace(/[\u0124\u0126]/g, 'H');
  82. str = str.replace(/[\u0128\u012A\u012C\u012E\u0130\u0418\u0406]/g, 'I');
  83. str = str.replace(/[\u0134\u0419]/g, 'J');
  84. str = str.replace(/[\u0136\u041A]/g, 'K');
  85. str = str.replace(/[\u0139\u013B\u013D\u0139\u0141\u041B]/g, 'L');
  86. str = str.replace(/[\u041C]/g, 'M');
  87. str = str.replace(/[\u00D1\u0143\u0145\u0147\u014A\u041D]/g, 'N');
  88. str = str.replace(/[\u00D3\u014C\u014E\u0150\u041E]/g, 'O');
  89. str = str.replace(/[\u041F]/g, 'P');
  90. str = str.replace(/[\u0154\u0156\u0158\u0420]/g, 'R');
  91. str = str.replace(/[\u015A\u015C\u015E\u0160\u0421]/g, 'S');
  92. str = str.replace(/[\u0162\u0164\u0166\u0422]/g, 'T');
  93. str = str.replace(/[\u00D9\u00DA\u00DB\u00DC\u0168\u016A\u016C\u016E\u0170\u0172\u0423]/g, 'U');
  94. str = str.replace(/[\u0412]/g, 'V');
  95. str = str.replace(/[\u0174]/g, 'W');
  96. str = str.replace(/[\u0176\u042B]/g, 'Y');
  97. str = str.replace(/[\u0179\u017B\u017D\u0417]/g, 'Z');
  98. str = str.replace(/[\u00C6]/g, 'AE');
  99. str = str.replace(/[\u0427]/g, 'CH');
  100. str = str.replace(/[\u0425]/g, 'KH');
  101. str = str.replace(/[\u0152]/g, 'OE');
  102. str = str.replace(/[\u0428]/g, 'SH');
  103. str = str.replace(/[\u0429]/g, 'SHH');
  104. str = str.replace(/[\u042F]/g, 'YA');
  105. str = str.replace(/[\u0404]/g, 'YE');
  106. str = str.replace(/[\u0407]/g, 'YI');
  107. str = str.replace(/[\u0401]/g, 'YO');
  108. str = str.replace(/[\u042E]/g, 'YU');
  109. str = str.replace(/[\u0416]/g, 'ZH');
  110. str = str.toLowerCase();
  111. str = str.replace(/[^a-z0-9\s\'\:\/\[\]-]/g,'');
  112. }
  113. str = str.replace(/[\u0028\u0029\u0021\u003F\u002E\u0026\u005E\u007E\u002B\u002A\u002F\u003A\u003B\u003C\u003D\u003E]/g, '');
  114. str = str.replace(/[\s\'\:\/\[\]-]+/g, ' ');
  115. // Add special char not used for url rewrite
  116. str = str.replace(/[ ]/g, '-');
  117. str = str.replace(/[\/\\"'|,;%]*/g, '');
  118. if (ucfirst == 1) {
  119. var first_char = str.charAt(0);
  120. str = first_char.toUpperCase()+str.slice(1);
  121. }
  122. return str;
  123. }
  124. function copy2friendlyURL()
  125. {
  126. if (typeof(id_product) == 'undefined')
  127. id_product = false;
  128. if (ps_force_friendly_product || !$('#link_rewrite_' + id_language).val().length || !id_product)//check if user didn't type anything in rewrite field, to prevent overwriting
  129. {
  130. $('#link_rewrite_' + id_language).val(str2url($('#name_' + id_language).val().replace(/^[0-9]+\./, ''), 'UTF-8').replace('%', ''));
  131. if ($('#friendly-url'))
  132. $('#friendly-url').html($('#link_rewrite_' + id_language).val());
  133. // trigger onchange event to use anything binded there
  134. $('#link_rewrite_' + id_language).change();
  135. }
  136. return;
  137. }
  138. function copyMeta2friendlyURL()
  139. {
  140. if (!$('input[name="id_cms"]').length)
  141. $('#link_rewrite_' + id_language).val(str2url($('#name_' + id_language).val().replace(/^[0-9]+\./, ''), 'UTF-8'));
  142. }
  143. function updateCurrentText()
  144. {
  145. $('#current_product').html($('#name_' + id_language).val());
  146. }
  147. function updateFriendlyURLByName()
  148. {
  149. $('#link_rewrite_' + id_language).val(str2url($('#name_' + id_language).val(), 'UTF-8'));
  150. $('#friendly-url_' + id_language).html($('#link_rewrite_' + id_language).val());
  151. }
  152. function updateFriendlyURL()
  153. {
  154. var link = $('#link_rewrite_' + id_language);
  155. if (link[0])
  156. {
  157. $('#friendly-url_' + id_language).text(str2url($('#link_rewrite_' + id_language).val(), 'UTF-8'));
  158. }
  159. }
  160. function updateLinkRewrite()
  161. {
  162. var link = $('#link_rewrite_' + id_language);
  163. if (link[0])
  164. {
  165. link.val(str2url($('#link_rewrite_' + id_language).val(), 'UTF-8'));
  166. $('#friendly-url_' + id_language).text(link.val());
  167. }
  168. }
  169. function toggleLanguageFlags(elt)
  170. {
  171. $(elt).parents('.displayed_flag').siblings('.language_flags').toggle();
  172. }
  173. // Kept for retrocompatibility only (out of AdminProducts & AdminCategories)
  174. function changeLanguage(field, fieldsString, id_language_new, iso_code)
  175. {
  176. $('div[id^='+field+'_]').hide();
  177. var fields = fieldsString.split('¤');
  178. for (var i = 0; i < fields.length; ++i)
  179. {
  180. $('div[id^='+fields[i]+'_]').hide();
  181. $('#'+fields[i]+'_'+id_language_new).show();
  182. $('#'+'language_current_'+fields[i]).attr('src', '../img/l/' + id_language_new + '.jpg');
  183. }
  184. $('#languages_' + field).hide();
  185. id_language = id_language_new;
  186. }
  187. // kept for retrocompatibility - you should use hideOtherLanguage(id) since 1.6
  188. function changeFormLanguage(id_language_new, iso_code, employee_cookie)
  189. {
  190. $('.translatable').each(function() {
  191. $(this).find('.lang_' + id_language_new)
  192. .show()
  193. .siblings('div:not(.displayed_flag):not(.clear)').hide();
  194. $(this).find('.language_current').attr('src', '../img/l/' + id_language_new + '.jpg');
  195. });
  196. // For multishop checkboxes
  197. $('.multishop_lang_'+id_language_new).show().siblings('div[class^=\'multishop_lang_\']').hide();
  198. id_language = id_language_new;
  199. changeEmployeeLanguage();
  200. updateCurrentText();
  201. }
  202. function displayFlags(languages, defaultLanguageID, employee_cookie)
  203. {
  204. if ($('.translatable'))
  205. {
  206. $('.translatable').each(function() {
  207. if (!$(this).find('.displayed_flag').length > 0) {
  208. $.each(languages, function(key, language) {
  209. if (language['id_lang'] == defaultLanguageID)
  210. {
  211. defaultLanguage = language;
  212. return false;
  213. }
  214. });
  215. var displayFlags = $('<div></div>')
  216. .addClass('displayed_flag')
  217. .append($('<img>')
  218. .addClass('language_current')
  219. .addClass('pointer')
  220. .attr('src', '../img/l/' + defaultLanguage['id_lang'] + '.jpg')
  221. .attr('alt', defaultLanguage['name'])
  222. .click(function() {
  223. toggleLanguageFlags(this);
  224. })
  225. );
  226. var languagesFlags = $('<div></div>')
  227. .addClass('language_flags')
  228. .html(choose_language_translate+':<br /><br />');
  229. $.each(languages, function(key, language) {
  230. var img = $('<img>')
  231. .addClass('pointer')
  232. .css('margin', '2px 2px')
  233. .attr('src', '../img/l/' + language['id_lang'] + '.jpg')
  234. .attr('alt', language['name'])
  235. .click(function() {
  236. changeFormLanguage(language['id_lang'], language['iso_code'], employee_cookie);
  237. });
  238. languagesFlags.append(img);
  239. });
  240. if ($(this).find('p:last-child').hasClass('clear'))
  241. $(this).find('p:last-child').before(displayFlags).before(languagesFlags);
  242. else
  243. $(this).append(displayFlags).append(languagesFlags);
  244. }
  245. });
  246. }
  247. }
  248. function checkAll(pForm)
  249. {
  250. for (i = 0, n = pForm.elements.length; i < n; i++)
  251. {
  252. var objName = pForm.elements[i].name;
  253. var objType = pForm.elements[i].type;
  254. if (objType == 'checkbox' && objName != 'checkme')
  255. {
  256. box = eval(pForm.elements[i]);
  257. box.checked = !box.checked;
  258. }
  259. }
  260. }
  261. function checkDelBoxes(pForm, boxName, parent)
  262. {
  263. for (i = 0; i < pForm.elements.length; i++)
  264. if (pForm.elements[i].name == boxName)
  265. pForm.elements[i].checked = parent;
  266. }
  267. function checkPaymentBoxes(name, module)
  268. {
  269. setPaymentBoxes(name, module);
  270. current = $('input#checkedBox_'+ name +'_'+ module + '[type=hidden]');
  271. $('form#form_'+ name +' input[type=checkbox]').each(
  272. function()
  273. {
  274. if ($(this).attr('name') == module + '_' + name + '[]')
  275. $(this).attr("checked", ((current.val() == 'checked') ? true : false));
  276. }
  277. );
  278. current.val() == 'checked' ? current.val('unchecked') : current.val('checked');
  279. }
  280. function setPaymentBoxes(name, module)
  281. {
  282. current = $('input#checkedBox_'+ name +'_'+ module + '[type=hidden]');
  283. total = 0;
  284. checked = 0;
  285. $('form#form_'+ name +' input[type=checkbox]').each(
  286. function()
  287. {
  288. if ($(this).attr('name') == module + '_' + name + '[]')
  289. {
  290. ($(this).attr("checked") ? checked++ : '');
  291. total++;
  292. }
  293. }
  294. );
  295. (checked == total) ? current.val('unchecked') : current.val('checked');
  296. }
  297. function getE(name)
  298. {
  299. if (document.getElementById)
  300. var elem = document.getElementById(name);
  301. else if (document.all)
  302. var elem = document.all[name];
  303. else if (document.layers)
  304. var elem = document.layers[name];
  305. return elem;
  306. }
  307. function formSubmit(e, button)
  308. {
  309. var key;
  310. key = window.event ? window.event.keyCode : e.which;
  311. if (key == 13)
  312. {
  313. getE(button).focus();
  314. getE(button).click();
  315. e.preventDefault();
  316. }
  317. }
  318. function noComma(elem)
  319. {
  320. getE(elem).value = getE(elem).value.replace(new RegExp(',', 'g'), '.');
  321. }
  322. /* Code generator for Affiliation and vouchers */
  323. function gencode(size)
  324. {
  325. getE('code').value = '';
  326. /* There are no O/0 in the codes in order to avoid confusion */
  327. var chars = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
  328. for (var i = 1; i <= size; ++i)
  329. getE('code').value += chars.charAt(Math.floor(Math.random() * chars.length));
  330. }
  331. var tpl_viewing_window = null;
  332. function viewTemplates(id_select, lang, ext)
  333. {
  334. var loc = $(id_select).val();
  335. if (loc != 0)
  336. {
  337. if (tpl_viewing_window != null && !tpl_viewing_window.closed)
  338. tpl_viewing_window.close();
  339. var url_preview = $("option[value="+loc+"]", id_select).data('preview');
  340. tpl_viewing_window = window.open(url_preview + lang + loc + ext, 'tpl_viewing', 'toolbar=0,location=0,directories=0,statfr=no,menubar=0,scrollbars=yes,resizable=yes,width=520,height=400,top=50,left=300');
  341. tpl_viewing_window.focus();
  342. }
  343. }
  344. function orderDeleteProduct(txtConfirm, txtExplain)
  345. {
  346. ret = true;
  347. $('table#cancelProducts input[type=checkbox]:checked').each(
  348. function()
  349. {
  350. totalCancel = parseInt($(this).parent().parent().find('td.cancelQuantity input[type=text]').val());
  351. totalQty = parseInt($(this).parent().find('input#totalQty[type=hidden]').val());
  352. totalQtyReturn = parseInt($(this).parent().find('input#totalQtyReturn[type=hidden]').val());
  353. productName = $(this).parent().find('input#productName[type=hidden]').val();
  354. totalAvailable = totalQty - totalQtyReturn;
  355. if (totalCancel > totalAvailable)
  356. {
  357. jAlert(txtConfirm + ' : \'' + ' ' + productName + '\' ! \n\n' + txtExplain + ' ('+ totalCancel + ' > ' + totalAvailable +')' + '\n ');
  358. ret = false;
  359. }
  360. }
  361. );
  362. return ret;
  363. }
  364. function selectCheckbox(obj)
  365. {
  366. $(obj).parent().parent().find('td.cancelCheck input[type=checkbox]').attr("checked", true);
  367. }
  368. function toggleShippingCost()
  369. {
  370. generateDiscount = $('#generateDiscount').attr("checked");
  371. generateCreditSlip = $('#generateCreditSlip').attr("checked");
  372. if (generateDiscount != 'checked' && generateCreditSlip != 'checked')
  373. {
  374. $('#spanShippingBack input[type=checkbox]').attr("checked", false);
  375. $('#spanShippingBack').css('display', 'none');
  376. }
  377. else
  378. $('#spanShippingBack').css('display', 'block');
  379. }
  380. function orderOverwriteMessage(sl, text)
  381. {
  382. var $zone = $('#txt_msg');
  383. var sl_value = sl.options[sl.selectedIndex].value;
  384. if (sl_value != '0')
  385. {
  386. if ($zone.val().length > 0 && !confirm(text))
  387. return ;
  388. $zone.val(sl_value);
  389. }
  390. $zone.trigger('autosize.resize');
  391. }
  392. function setCancelQuantity(itself, id_order_detail, quantity)
  393. {
  394. $('#cancelQuantity_' + id_order_detail).val($(itself).prop('checked') ? quantity : '');
  395. }
  396. function stockManagementActivationAuthorization()
  397. {
  398. if (getE('PS_STOCK_MANAGEMENT_on').checked)
  399. {
  400. getE('PS_ORDER_OUT_OF_STOCK_on').disabled = false;
  401. getE('PS_ORDER_OUT_OF_STOCK_off').disabled = false;
  402. getE('PS_DISPLAY_QTIES_on').disabled = false;
  403. getE('PS_DISPLAY_QTIES_off').disabled = false;
  404. getE('PS_ADVANCED_STOCK_MANAGEMENT_on').disabled = false;
  405. getE('PS_ADVANCED_STOCK_MANAGEMENT_off').disabled = false;
  406. }
  407. else
  408. {
  409. getE('PS_DISPLAY_QTIES_off').checked = true;
  410. getE('PS_DISPLAY_QTIES_on').disabled = 'disabled';
  411. getE('PS_DISPLAY_QTIES_off').disabled = 'disabled';
  412. getE('PS_ORDER_OUT_OF_STOCK_on').checked = true;
  413. getE('PS_ORDER_OUT_OF_STOCK_on').disabled = 'disabled';
  414. getE('PS_ORDER_OUT_OF_STOCK_off').disabled = 'disabled';
  415. getE('PS_ADVANCED_STOCK_MANAGEMENT_off').checked = true;
  416. getE('PS_ADVANCED_STOCK_MANAGEMENT_on').disabled = 'disabled';
  417. getE('PS_ADVANCED_STOCK_MANAGEMENT_off').disabled = 'disabled';
  418. getE('PS_FORCE_ASM_NEW_PRODUCT_off').checked = true;
  419. getE('PS_FORCE_ASM_NEW_PRODUCT_on').disabled = 'disabled';
  420. getE('PS_FORCE_ASM_NEW_PRODUCT_off').disabled = 'disabled';
  421. getE('PS_DEFAULT_WAREHOUSE_NEW_PRODUCT').disabled = 'disabled';
  422. }
  423. }
  424. function advancedStockManagementActivationAuthorization()
  425. {
  426. if (getE('PS_ADVANCED_STOCK_MANAGEMENT_on').checked)
  427. {
  428. getE('PS_FORCE_ASM_NEW_PRODUCT_on').disabled = false;
  429. getE('PS_FORCE_ASM_NEW_PRODUCT_off').disabled = false;
  430. getE('PS_DEFAULT_WAREHOUSE_NEW_PRODUCT').disabled = false;
  431. }
  432. else
  433. {
  434. getE('PS_FORCE_ASM_NEW_PRODUCT_off').checked = true;
  435. getE('PS_FORCE_ASM_NEW_PRODUCT_on').disabled = 'disabled';
  436. getE('PS_FORCE_ASM_NEW_PRODUCT_off').disabled = 'disabled';
  437. getE('PS_DEFAULT_WAREHOUSE_NEW_PRODUCT').disabled = 'disabled';
  438. }
  439. }
  440. function hookCheckboxes(id, opt, champ)
  441. {
  442. if (opt == 1 && champ.checked == false)
  443. $('#Ghook'+id).attr('checked', false);
  444. else if (opt == 0)
  445. {
  446. if (champ.checked)
  447. $('.hook'+id).attr('checked', "checked");
  448. else
  449. $('.hook'+id).attr('checked', false);
  450. }
  451. }
  452. function changeCMSActivationAuthorization()
  453. {
  454. if (getE('PS_CONDITIONS_on').checked)
  455. getE('PS_CONDITIONS_CMS_ID').disabled = false;
  456. else
  457. getE('PS_CONDITIONS_CMS_ID').disabled = 'disabled';
  458. }
  459. function disableZipFormat()
  460. {
  461. if ($('#need_zip_code_on').prop('checked') == false)
  462. {
  463. $('.zip_code_format').hide();
  464. $('#zip_code_format').val('');
  465. }
  466. else
  467. $('.zip_code_format').show();
  468. }
  469. function disableTAASC()
  470. {
  471. if ($('#iso_code').val() == 'US')
  472. $('#TAASC').show();
  473. else
  474. $('#TAASC').hide();
  475. }
  476. function spreadFees(id_range)
  477. {
  478. newVal = $('#fees_all_'+id_range).val().replace(/,/g, '.');
  479. $('.fees_'+id_range).val(newVal);
  480. }
  481. function clearAllFees(id_range)
  482. {
  483. $('#fees_all_'+id_range).val('');
  484. }
  485. function toggleDraftWarning(show)
  486. {
  487. if (show)
  488. $('.draft').hide();
  489. else
  490. $('.draft').show();
  491. }
  492. function showRedirectProductOptions(show)
  493. {
  494. if (show)
  495. $('.redirect_product_options').fadeIn();
  496. else
  497. $('.redirect_product_options').fadeOut();
  498. redirectSelectChange();
  499. }
  500. function redirectSelectChange()
  501. {
  502. if ($('#redirect_type :selected').val() == '404')
  503. showRedirectProductSelectOptions(false);
  504. else
  505. showRedirectProductSelectOptions(true);
  506. }
  507. function addRelatedProduct(id_product_to_add, product_name)
  508. {
  509. if (!id_product_to_add || id_product == id_product_to_add)
  510. return;
  511. $('#related_product_name').html(product_name);
  512. $('input[name=id_product_redirected]').val(id_product_to_add);
  513. $('#related_product_autocomplete_input').parent().hide();
  514. $('#related_product_remove').show();
  515. }
  516. function removeRelatedProduct()
  517. {
  518. $('#related_product_name').html(no_related_product);
  519. $('input[name=id_product_redirected]').val(0);
  520. $('#related_product_remove').hide();
  521. $('#related_product_autocomplete_input').parent().fadeIn();
  522. }
  523. function showRedirectProductSelectOptions(show)
  524. {
  525. if (show)
  526. $('.redirect_product_options_product_choise').show();
  527. else
  528. {
  529. $('.redirect_product_options_product_choise').hide();
  530. removeRelatedProduct();
  531. }
  532. }
  533. function showOptions(show)
  534. {
  535. if (show)
  536. $('tr#product_options').show();
  537. else
  538. $('tr#product_options').hide();
  539. }
  540. function submitAddProductAndPreview()
  541. {
  542. $('#fakeSubmitAddProductAndPreview').attr('name','submitAddProductAndPreview');
  543. $('#product_form').submit();
  544. }
  545. function submitAddcmsAndPreview()
  546. {
  547. $('#previewSubmitAddcmsAndPreview').attr('name','submitAddcmsAndPreview');
  548. $('#cms').submit();
  549. }
  550. function checkAllMultishopDefaultValue(item)
  551. {
  552. $(item).parent().find('input[name^=\'multishopOverrideOption\']').each(function(k, v)
  553. {
  554. $(v).attr('checked', item.checked);
  555. var name = $(v).attr('name');
  556. checkMultishopDefaultValue(v, name.substr(24, name.length - 25));
  557. })
  558. }
  559. function checkMultishopDefaultValue(obj, key)
  560. {
  561. if (!$(obj).prop('checked') || $('#'+key).hasClass('isInvisible'))
  562. {
  563. $('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select, #conf_id_'+key+' button').prop('disabled', true);
  564. $('#conf_id_'+key+' label.conf_title').addClass('isDisabled');
  565. $(obj).prop('disabled', false);
  566. }
  567. else
  568. {
  569. $('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select, #conf_id_'+key+' button').prop('disabled', false);
  570. $('#conf_id_'+key+' label.conf_title').removeClass('isDisabled');
  571. }
  572. $('#conf_id_'+key+' .preference_default_multishop input').prop('disabled', false);
  573. }
  574. function toggleAllMultishopDefaultValue($container, value)
  575. {
  576. $container.find('input[name^=\'multishopOverrideOption\']').each(function(k, v)
  577. {
  578. $(v).attr('checked', value);
  579. var name = $(v).attr('name');
  580. toggleMultishopDefaultValue(v, name.substr(24, name.length - 25));
  581. })
  582. }
  583. function toggleMultishopDefaultValue(obj, key)
  584. {
  585. if (!$(obj).prop('checked') || $('#'+key).hasClass('isInvisible'))
  586. {
  587. $('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select, #conf_id_'+key+' button').attr('disabled', true);
  588. $('#conf_id_'+key+' label.conf_title').addClass('isDisabled');
  589. }
  590. else
  591. {
  592. $('#conf_id_'+key+' input, #conf_id_'+key+' textarea, #conf_id_'+key+' select, #conf_id_'+key+' button').attr('disabled', false);
  593. $('#conf_id_'+key+' label.conf_title').removeClass('isDisabled');
  594. }
  595. $('#conf_id_'+key+' input[name^=\'multishopOverrideOption\']').attr('disabled', false);
  596. }
  597. function doAdminAjax(data, success_func, error_func)
  598. {
  599. $.ajax(
  600. {
  601. url : 'index.php',
  602. data : data,
  603. type : 'POST',
  604. success : function(data){
  605. if (success_func)
  606. return success_func(data);
  607. data = $.parseJSON(data);
  608. if (data.confirmations.length != 0)
  609. showSuccessMessage(data.confirmations);
  610. else
  611. showErrorMessage(data.error);
  612. },
  613. error : function(data){
  614. if (error_func)
  615. return error_func(data);
  616. alert("[TECHNICAL ERROR]");
  617. }
  618. });
  619. }
  620. //display a success/error/notice message
  621. function showSuccessMessage(msg) {
  622. $.growl.notice({ title: "", message:msg});
  623. }
  624. function showErrorMessage(msg) {
  625. $.growl.error({ title: "", message:msg});
  626. }
  627. function showNoticeMessage(msg) {
  628. $.growl.notice({ title: "", message:msg});
  629. }
  630. $(document).ready(function()
  631. {
  632. if (typeof helper_tabs != 'undefined' && typeof unique_field_id != 'undefined')
  633. {
  634. $.each(helper_tabs, function(index) {
  635. $('#'+unique_field_id+'fieldset_'+index+' .form-wrapper').prepend('<div class="tab-content panel" />');
  636. $('#'+unique_field_id+'fieldset_'+index+' .form-wrapper').prepend('<ul class="nav nav-tabs" />');
  637. $.each(helper_tabs[index], function(key, value) {
  638. // Move every form-group into the correct .tab-content > .tab-pane
  639. $('#'+unique_field_id+'fieldset_'+index+' .tab-content').append('<div id="'+key+'" class="tab-pane" />');
  640. var elemts = $('#'+unique_field_id+'fieldset_'+index).find("[data-tab-id='" + key + "']");
  641. $(elemts).appendTo('#'+key);
  642. // Add the item to the .nav-tabs
  643. if (elemts.length != 0)
  644. $('#'+unique_field_id+'fieldset_'+index+' .nav-tabs').append('<li><a href="#'+key+'" data-toggle="tab">'+value+'</a></li>');
  645. });
  646. // Activate the first tab
  647. $('#'+unique_field_id+'fieldset_'+index+' .tab-content div').first().addClass('active');
  648. $('#'+unique_field_id+'fieldset_'+index+' .nav-tabs li').first().addClass('active');
  649. });
  650. }
  651. if (typeof formToMove != 'undefined' && typeof formDestination != 'undefined' )
  652. {
  653. $('<hr style="margin 24px 0;" />').appendTo('#'+formDestination)
  654. $('#theme_fieldset_'+formToMove+' .form-wrapper').appendTo('#'+formDestination);
  655. }
  656. $('select.chosen').each(function(k, item){
  657. $(item).chosen({disable_search_threshold: 10});
  658. });
  659. // Apply chosen() when modal is loaded
  660. $(document).on('shown.bs.modal', function (e) {
  661. $('select.chosen-modal').chosen();
  662. })
  663. $('.isInvisible input, .isInvisible select, .isInvisible textarea').attr('disabled', true);
  664. $('.isInvisible label.conf_title').addClass('isDisabled');
  665. // Disable options fields for each row with a multishop default checkbox
  666. $('.preference_default_multishop input[type=checkbox]').each(function(k, v)
  667. {
  668. var key = $(v).attr('name');
  669. var len = key.length;
  670. checkMultishopDefaultValue(v, key.substr(24, len - 25));
  671. });
  672. $('input[name^=\'multishopOverrideOption\']').each(function(k, v)
  673. {
  674. var key = $(v).attr('name');
  675. var len = key.length;
  676. toggleMultishopDefaultValue(v, key.substr(24, len - 25));
  677. });
  678. $(document).on('keyup change', '.copy2friendlyUrl', function(e){
  679. if (!isArrowKey(e))
  680. return copy2friendlyURL();
  681. });
  682. // on live will make this binded for dynamic content
  683. $(document).on('keyup change', '.updateCurrentText', function(e){
  684. if (typeof e == KeyboardEvent)
  685. if(isArrowKey(e))
  686. return;
  687. updateCurrentText();
  688. });
  689. $(document).on('keyup change', '.copyMeta2friendlyURL', function(e){
  690. if (!isArrowKey(e))
  691. return copyMeta2friendlyURL()
  692. });
  693. $('#ajax_running').ajaxStart(function() {
  694. ajax_running_timeout = setTimeout(function() {showAjaxOverlay()}, 1000);
  695. });
  696. $('#ajax_running').ajaxStop(function() {
  697. var element = $(this)
  698. setTimeout(function(){element.hide()}, 1000);
  699. clearTimeout(ajax_running_timeout);
  700. });
  701. $('#ajax_running').ajaxError(function() {
  702. var element = $(this)
  703. setTimeout(function(){element.hide()}, 1000);
  704. clearTimeout(ajax_running_timeout);
  705. });
  706. bindTabModuleListAction();
  707. bindAddonsButtons();
  708. //Check filters value on submit filter
  709. $("[name='submitFilter']").click(function(event) {
  710. var list_id = $(this).data('list-id');
  711. var empty_filters = true;
  712. $(document.body).find("input[name*='"+list_id+"Filter']").each(function() {
  713. if ($(this).val() != '')
  714. {
  715. empty_filters = false;
  716. return false;
  717. }
  718. });
  719. $(document.body).find("select[name*='"+list_id+"Filter']").each(function() {
  720. if ($(this).val() != '')
  721. {
  722. empty_filters = false;
  723. return false;
  724. }
  725. });
  726. if (empty_filters)
  727. {
  728. event.preventDefault();
  729. $('#'+list_id+'-empty-filters-alert').show();
  730. }
  731. });
  732. var message = $('.toolbarHead');
  733. var view = $(window);
  734. // bind only if message exists. placeholder will be its parent
  735. view.bind("scroll resize", function(e)
  736. {
  737. message.each(function(el){
  738. if (message.length)
  739. {
  740. placeholder = $(this).parent();
  741. if (e.type == 'resize')
  742. $(this).css('width', $(this).parent().width());
  743. placeholderTop = placeholder.offset().top;
  744. var viewTop = view.scrollTop() + 15;
  745. // here we force the toolbar to be "not fixed" when
  746. // the height of the window is really small (toolbar hiding the page is not cool)
  747. window_is_more_than_twice_the_toolbar = view.height() > message.parent().height() * 2;
  748. if (!$(this).hasClass("fix-toolbar") && (window_is_more_than_twice_the_toolbar && (viewTop > placeholderTop)))
  749. {
  750. $(this).css('width', $(this).width());
  751. // fixing parent height will prevent that annoying "pagequake" thing
  752. // the order is important : this has to be set before adding class fix-toolbar
  753. $(this).parent().css('height', $(this).parent().height());
  754. $(this).addClass("fix-toolbar");
  755. }
  756. else if ($(this).hasClass("fix-toolbar") && (!window_is_more_than_twice_the_toolbar || (viewTop <= placeholderTop)) )
  757. {
  758. $(this).removeClass("fix-toolbar");
  759. $(this).removeAttr('style');
  760. $(this).parent().removeAttr('style');
  761. }
  762. }
  763. });
  764. }); // end bind
  765. $(document).on('click', '.untrustedaddon', function(e){
  766. e.preventDefault();
  767. var moduleName = $(this).data('module-name');
  768. var moduleDisplayName = $(this).data('module-display-name');
  769. var moduleImage = $(this).data('module-image');
  770. var authorName = $(this).data('author-name');
  771. var moduleLink = $(this).data('link');
  772. var authorUri = $(this).data('author-uri');
  773. var isValidUri = /(https?):\/\/([a-z0-9\.]*)?(prestashop.com).*/gi;
  774. var addonsSearchLink = 'http://addons.prestashop.com/en/search?search_query='+encodeURIComponent(moduleDisplayName)+'&utm_source=back-office&utm_medium=addons-certified&utm_campaign=back-office-'+iso_user.toUpperCase();
  775. $('.modal #untrusted-module-logo').attr('src', moduleImage);
  776. $('.modal .module-display-name-placeholder').text(moduleDisplayName);
  777. $('.modal .author-name-placeholder').text(authorName);
  778. if (isValidUri.test(authorUri))
  779. $('.modal .author-name-placeholder').wrap('<a href="'+authorUri+'" onclick="window.open(this.href);return false;"></a>');
  780. $('.modal #proceed-install-anyway').attr('href', moduleLink);
  781. $('.modal .catalog-link').attr('href', addonsSearchLink);
  782. $('.modal .catalog-link').attr('onclick', 'window.open(this.href);return false;');
  783. });
  784. $(document).on('click', '#untrusted-show-risk', function(e){
  785. e.preventDefault();
  786. $('.untrusted-content-action').hide();
  787. $('.untrusted-content-more-info').show();
  788. });
  789. $(document).on('click', '#untrusted-show-action', function(e){
  790. e.preventDefault();
  791. $('.untrusted-content-more-info').hide();
  792. $('.untrusted-content-action').show();
  793. });
  794. // if count errors
  795. $('#hideError').on('click', function(e)
  796. {
  797. e.preventDefault();
  798. $('.error').hide('slow', function (){
  799. $('.error').remove();
  800. });
  801. return false;
  802. });
  803. // if count warnings
  804. $(document).on('click', '#linkSeeMore', function(e){
  805. e.preventDefault();
  806. $('#seeMore').show();
  807. $(this).hide();
  808. $('#linkHide').show();
  809. return false;
  810. });
  811. $(document).on('click', '#linkHide', function(e){
  812. e.preventDefault();
  813. $('#seeMore').hide();
  814. $(this).hide();
  815. $('#linkSeeMore').show();
  816. return false;
  817. });
  818. $(document).on('click', '#hideWarn', function(e){
  819. e.preventDefault();
  820. $('.warn').hide('slow', function (){
  821. $('.warn').remove();
  822. });
  823. return false;
  824. });
  825. // js for the buttons of swap helper
  826. $("#addSwap").on('click', function(e) {
  827. e.preventDefault();
  828. $('#availableSwap option:selected').each( function() {
  829. $('#selectedSwap').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
  830. $(this).remove();
  831. });
  832. $('#selectedSwap option').prop('selected', true);
  833. });
  834. $("#removeSwap").on('click', function(e) {
  835. e.preventDefault();
  836. $('#selectedSwap option:selected').each( function() {
  837. $('#availableSwap').append("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>");
  838. $(this).remove();
  839. });
  840. $('#selectedSwap option').prop('selected', true);
  841. });
  842. if ($('#selectedSwap').length != 0) {
  843. $('button:submit').click(function() {
  844. $('#selectedSwap option').attr('selected', 'selected');
  845. });
  846. }
  847. });
  848. function bindTabModuleListAction()
  849. {
  850. $('.action_tab_module').each( function (){
  851. $(this).click(function () {
  852. option = $('#'+$(this).data('option')+' :selected');
  853. if ($(option).data('onclick') != '')
  854. {
  855. var f = eval("(function(){ "+$(option).data('onclick')+"})");
  856. if (f.call())
  857. window.location.href = $(option).data('href');
  858. }
  859. else
  860. window.location.href = $(option).data('href');
  861. return false;
  862. });
  863. });
  864. }
  865. // Delete all tags HTML
  866. function stripHTML(oldString)
  867. {
  868. var newString = '';
  869. var inTag = false;
  870. for(var i = 0; i < oldString.length; i++) {
  871. if(oldString.charAt(i) == '<') inTag = true;
  872. if(oldString.charAt(i) == '>') {
  873. if(oldString.charAt(i+1)!='<')
  874. {
  875. inTag = false;
  876. i++;
  877. }
  878. }
  879. if(!inTag) newString += oldString.charAt(i);
  880. }
  881. return newString;
  882. }
  883. /**
  884. * Display a loading bar while an ajax call is ongoing.
  885. *
  886. * To prevent the loading bar display for a specific ajax call, set the beforeSend event in your ajax declaration:
  887. * beforeSend : function(data)
  888. {
  889. // don't display the loading notification bar
  890. clearTimeout(ajax_running_timeout);
  891. }
  892. */
  893. function showAjaxOverlay()
  894. {
  895. $('#ajax_running').show('fast');
  896. clearTimeout(ajax_running_timeout);
  897. }
  898. function display_action_details(row_id, controller, token, action, params)
  899. {
  900. var id = action+'_'+row_id;
  901. var current_element = $('#details_'+id);
  902. if (!current_element.data('dataMaped')) {
  903. var ajax_params = {
  904. 'id': row_id,
  905. 'controller': controller,
  906. 'token': token,
  907. 'action': action,
  908. 'ajax': true
  909. };
  910. $.each(params, function(k, v) {
  911. ajax_params[k] = v;
  912. });
  913. $.ajax({
  914. url: 'index.php',
  915. data: ajax_params,
  916. dataType: 'json',
  917. cache: false,
  918. context: current_element,
  919. async: false,
  920. success: function(data) {
  921. if (typeof(data.use_parent_structure) == 'undefined' || (data.use_parent_structure == true))
  922. {
  923. if (current_element.parent().parent().hasClass('alt_row'))
  924. var alt_row = true;
  925. else
  926. var alt_row = false;
  927. current_element.parent().parent().after($('<tr class="details_'+id+' small '+(alt_row ? 'alt_row' : '')+'"></tr>')
  928. .append($('<td style="border:none!important;" class="empty"></td>')
  929. .attr('colspan', current_element.parent().parent().find('td').length)));
  930. $.each(data.data, function(it, row)
  931. {
  932. var bg_color = ''; // Color
  933. if (row.color)
  934. bg_color = 'style="background:' + row.color +';"';
  935. var content = $('<tr class="action_details details_'+id+' '+(alt_row ? 'alt_row' : '')+'"></tr>');
  936. content.append($('<td class="empty"></td>'));
  937. var first = true;
  938. var count = 0; // Number of non-empty collum
  939. $.each(row, function(it)
  940. {
  941. if(typeof(data.fields_display[it]) != 'undefined')
  942. count++;
  943. });
  944. $.each(data.fields_display, function(it, line)
  945. {
  946. if (typeof(row[it]) == 'undefined')
  947. {
  948. if (first || count == 0)
  949. content.append($('<td class="'+current_element.align+' empty"' + bg_color + '></td>'));
  950. else
  951. content.append($('<td class="'+current_element.align+'"' + bg_color + '></td>'));
  952. }
  953. else
  954. {
  955. count--;
  956. if (first)
  957. {
  958. first = false;
  959. content.append($('<td class="'+current_element.align+' first"' + bg_color + '>'+row[it]+'</td>'));
  960. }
  961. else if (count == 0)
  962. content.append($('<td class="'+current_element.align+' last"' + bg_color + '>'+row[it]+'</td>'));
  963. else
  964. content.append($('<td class="'+current_element.align+' '+count+'"' + bg_color + '>'+row[it]+'</td>'));
  965. }
  966. });
  967. content.append($('<td class="empty"></td>'));
  968. current_element.parent().parent().after(content.show('slow'));
  969. });
  970. }
  971. else
  972. {
  973. if (current_element.parent().parent().hasClass('alt_row'))
  974. var content = $('<tr class="details_'+id+' alt_row"></tr>');
  975. else
  976. var content = $('<tr class="details_'+id+'"></tr>');
  977. content.append($('<td style="border:none!important;">'+data.data+'</td>').attr('colspan', current_element.parent().parent().find('td').length));
  978. current_element.parent().parent().after(content);
  979. current_element.parent().parent().parent().find('.details_'+id).hide();
  980. }
  981. current_element.data('dataMaped', true);
  982. current_element.data('opened', false);
  983. if (typeof(initTableDnD) != 'undefined')
  984. initTableDnD('.details_'+id+' table.tableDnD');
  985. }
  986. });
  987. }
  988. if (current_element.data('opened'))
  989. {
  990. current_element.find('i.icon-collapse-top').attr('class', 'icon-collapse');
  991. current_element.parent().parent().parent().find('.details_'+id).hide('fast');
  992. current_element.data('opened', false);
  993. }
  994. else
  995. {
  996. current_element.find('i.icon-collapse').attr('class', 'icon-collapse-top');
  997. current_element.parent().parent().parent().find('.details_'+id).show('fast');
  998. current_element.data('opened', true);
  999. }
  1000. }
  1001. function quickSelect(elt)
  1002. {
  1003. var eltVal = $(elt).val();
  1004. if (eltVal == "0")
  1005. return false;
  1006. else if (eltVal.substr(eltVal.length - 6) == '_blank')
  1007. window.open(eltVal.substr(0, eltVal.length - 6), '_blank');
  1008. else
  1009. location.href = eltVal;
  1010. }
  1011. function changeEmployeeLanguage()
  1012. {
  1013. if (typeof allowEmployeeFormLang !== 'undefined' && allowEmployeeFormLang)
  1014. $.post("index.php", {
  1015. action: 'formLanguage',
  1016. tab: 'AdminEmployees',
  1017. ajax: 1,
  1018. token: employee_token,
  1019. form_language_id: id_language
  1020. });
  1021. }
  1022. function hideOtherLanguage(id)
  1023. {
  1024. $('.translatable-field').hide();
  1025. $('.lang-' + id).show();
  1026. var id_old_language = id_language;
  1027. id_language = id;
  1028. if (id_old_language != id)
  1029. changeEmployeeLanguage();
  1030. updateCurrentText();
  1031. }
  1032. function sendBulkAction(form, action)
  1033. {
  1034. String.prototype.splice = function(index, remove, string) {
  1035. return (this.slice(0, index) + string + this.slice(index + Math.abs(remove)));
  1036. };
  1037. var form_action = $(form).attr('action');
  1038. if (form_action.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ') == '')
  1039. return false;
  1040. if (form_action.indexOf('#') == -1)
  1041. $(form).attr('action', form_action + '&' + action);
  1042. else
  1043. $(form).attr('action', form_action.splice(form_action.lastIndexOf('&'), 0, '&' + action));
  1044. $(form).submit();
  1045. }
  1046. function openModulesList()
  1047. {
  1048. if (!modules_list_loaded)
  1049. {
  1050. $.ajax({
  1051. type: "POST",
  1052. url : admin_modules_link,
  1053. async: true,
  1054. data : {
  1055. ajax : "1",
  1056. controller : "AdminModules",
  1057. action : "getTabModulesList",
  1058. tab_modules_list : tab_modules_list,
  1059. back_tab_modules_list : window.location.href
  1060. },
  1061. success : function(data)
  1062. {
  1063. $('#modules_list_container_tab_modal').html(data).slideDown();
  1064. $('#modules_list_loader').hide();
  1065. modules_list_loaded = true;
  1066. $('.help-tooltip').tooltip();
  1067. }
  1068. });
  1069. }
  1070. else
  1071. {
  1072. $('#modules_list_container_tab_modal').slideDown();
  1073. $('#modules_list_loader').hide();
  1074. }
  1075. return false;
  1076. }
  1077. function bindAddonsButtons()
  1078. {
  1079. // Method to log on PrestaShop Addons WebServices
  1080. $('#addons_login_button').click(function()
  1081. {
  1082. var username_addons = $("#username_addons").val();
  1083. var password_addons = $("#password_addons").val();
  1084. try
  1085. {
  1086. resAjax = $.ajax({
  1087. type:"POST",
  1088. url : admin_modules_link,
  1089. async: true,
  1090. data : {
  1091. ajax : "1",
  1092. controller : "AdminModules",
  1093. action : "logOnAddonsWebservices",
  1094. username_addons : username_addons,
  1095. password_addons : password_addons
  1096. },
  1097. beforeSend: function(xhr){
  1098. $('#addons_loading').html('<img src="../img/loader.gif" alt="" border="0" />');
  1099. },
  1100. success : function(data){
  1101. if (data == 'OK')
  1102. {
  1103. $('#addons_loading').html('');
  1104. $('#addons_login_div').fadeOut();
  1105. window.location.href = currentIndex + '&token=' + token + '&conf=32';
  1106. }
  1107. else
  1108. $('#addons_loading').html('<br><div class="alert alert-danger">'+errorLogin+'</div>');
  1109. }
  1110. });
  1111. }
  1112. catch(e){}
  1113. return false;
  1114. });
  1115. // Method to log out PrestaShop Addons WebServices
  1116. $('#addons_logout_button').click(function()
  1117. {
  1118. try
  1119. {
  1120. resAjax = $.ajax({
  1121. type:"POST",
  1122. url : admin_modules_link,
  1123. async: true,
  1124. data : {
  1125. ajax : "1",
  1126. controller : "AdminModules",
  1127. action : "logOutAddonsWebservices"
  1128. },
  1129. beforeSend: function(xhr){
  1130. $('#addons_loading').html('<img src="../img/loader.gif" alt="" border="0" />');
  1131. },
  1132. success: function(data) {
  1133. if (data == 'OK')
  1134. {
  1135. $('#addons_loading').html('');
  1136. $('#addons_login_div').fadeOut();
  1137. window.location.reload();
  1138. }
  1139. else
  1140. $('#addons_loading').html(errorLogin);
  1141. }
  1142. });
  1143. }
  1144. catch(e){}
  1145. return false;
  1146. });
  1147. }
  1148. function ajaxStates(id_state_selected)
  1149. {
  1150. $.ajax({
  1151. url: "index.php",
  1152. cache: false,
  1153. data: "token="+state_token+"&ajax=1&action=states&tab=AdminStates&no_empty=0&id_country="+$('#id_country').val() + "&id_state=" + $('#id_state').val(),
  1154. success: function(html)
  1155. {
  1156. if (html == 'false')
  1157. {
  1158. $("#contains_states").fadeOut();
  1159. $('#id_state option[value=0]').attr("selected", "selected");
  1160. }
  1161. else
  1162. {
  1163. $("#id_state").html(html);
  1164. $("#contains_states").fadeIn();
  1165. $('#id_state option[value=' + id_state_selected + ']').attr("selected", "selected");
  1166. }
  1167. }
  1168. });
  1169. if (module_dir && vat_number)
  1170. {
  1171. $.ajax({
  1172. type: "GET",
  1173. url: window.location.origin + module_dir + "vatnumber/ajax.php?id_country=" + $('#id_country').val(),
  1174. success: function(isApplicable)
  1175. {
  1176. if(isApplicable == 1)
  1177. $('#vat_area').show();
  1178. else
  1179. $('#vat_area').hide();
  1180. }
  1181. });
  1182. }
  1183. }
  1184. function check_for_all_accesses(tabsize, tabnumber)
  1185. {
  1186. var i = 0;
  1187. var res = 0;
  1188. var right = 0;
  1189. var rights = new Array('view', 'add', 'edit', 'delete', 'all');
  1190. while (i != parseInt(tabsize) + 1)
  1191. {
  1192. if ($('#view'+i).prop('checked') == false || $('#edit'+i).prop('checked') == false || $('#add'+i).prop('checked') == false || $('#delete'+i).prop('checked') == false)
  1193. $('#all'+i).attr('checked', false);
  1194. else
  1195. $('#all'+i).attr('checked', "checked");
  1196. i++;
  1197. }
  1198. right = 0;
  1199. while (right != 5)
  1200. {
  1201. res = 0;
  1202. i = 0;
  1203. while (i != tabsize)
  1204. {
  1205. if ($('#'+rights[right]+i).prop('checked') == true)
  1206. res++;
  1207. i++;
  1208. }
  1209. if (res == tabnumber - 1)
  1210. $('#'+rights[right]+'all').attr('checked', "checked");
  1211. else
  1212. $('#'+rights[right]+'all').attr('checked', false);
  1213. right++;
  1214. }
  1215. }
  1216. function perfect_access_js_gestion(src, action, id_tab, tabsize, tabnumber, table)
  1217. {
  1218. if (id_tab == '-1' && action == 'all')
  1219. {
  1220. $(table+' .add').attr('checked', src.checked);
  1221. $(table+' .edit').attr('checked', src.checked);
  1222. $(table+' .delete').attr('checked', src.checked);
  1223. $(table+' .view').attr('checked', src.checked);
  1224. $(table+' .all').attr('checked', src.checked);
  1225. }
  1226. else if (action == 'all')
  1227. $(table+' .'+id_tab).attr('checked', src.checked);
  1228. else if (id_tab == '-1')
  1229. $(table+' .'+action).attr('checked', src.checked);
  1230. check_for_all_accesses(tabsize, tabnumber);
  1231. }
  1232. verifMailREGEX = /^([\w+-]+(?:\.[\w+-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
  1233. function verifyMail(testMsg, testSubject)
  1234. {
  1235. $("#mailResultCheck").removeClass("alert-danger").removeClass('alert-success').html('<img src="../img/admin/ajax-loader.gif" alt="" />');
  1236. $("#mailResultCheck").slideDown("slow");
  1237. //local verifications
  1238. if (!($("#testEmail").val().length > 0))
  1239. {
  1240. $("#mailResultCheck").addClass("alert-danger").removeClass("alert-success").removeClass('userInfos').html(errorMail);
  1241. return false;
  1242. }
  1243. else if (!verifMailREGEX.test( $("#testEmail").val() ))
  1244. {
  1245. $("#mailResultCheck").addClass("alert-danger").removeClass("alert-success").removeClass('userInfos').html(errorMail);
  1246. return false;
  1247. }
  1248. else
  1249. {
  1250. //external verifications and sets
  1251. $.ajax(
  1252. {
  1253. url: "index.php",
  1254. cache: false,
  1255. type : "POST",
  1256. data:
  1257. {
  1258. "mailMethod" : (($("input[name=PS_MAIL_METHOD]:checked").val() == 2) ? "smtp" : "native"),
  1259. "smtpSrv" : $("input[name=PS_MAIL_SERVER]").val(),
  1260. "testEmail" : $("#testEmail").val(),
  1261. "smtpLogin" : $("input[name=PS_MAIL_USER]").val(),
  1262. "smtpPassword" : $("input[name=PS_MAIL_PASSWD]").val(),
  1263. "smtpPort" : $("input[name=PS_MAIL_SMTP_PORT]").val(),
  1264. "smtpEnc" : $("select[name=PS_MAIL_SMTP_ENCRYPTION]").val(),
  1265. "testMsg" : textMsg,
  1266. "testSubject" : textSubject,
  1267. "token" : token_mail,
  1268. "ajax" : 1,
  1269. "tab" : 'AdminEmails',
  1270. "action" : 'sendMailTest'
  1271. },
  1272. success: function(ret)
  1273. {
  1274. if (ret == "ok")
  1275. {
  1276. $("#mailResultCheck").addClass("alert-success").removeClass("alert-danger").removeClass('userInfos').html(textSendOk);
  1277. mailIsOk = true;
  1278. }
  1279. else
  1280. {
  1281. mailIsOk = false;
  1282. $("#mailResultCheck").addClass("alert-danger").removeClass("alert-success").removeClass('userInfos').html(textSendError + '<br />' + ret);
  1283. }
  1284. }
  1285. }
  1286. );
  1287. }
  1288. }
  1289. function checkLangPack(token){
  1290. if ($('#iso_code').val().length == 2)
  1291. {
  1292. $('#lang_pack_loading').show();
  1293. $('#lang_pack_msg').hide();
  1294. doAdminAjax(
  1295. {
  1296. controller:'AdminLanguages',
  1297. action:'checkLangPack',
  1298. token:token,
  1299. ajax:1,
  1300. iso_lang:($('#iso_code').val()).toLowerCase(),
  1301. ps_version:$('#ps_version').val()
  1302. },
  1303. function(ret)
  1304. {
  1305. $('#lang_pack_loading').hide();
  1306. ret = $.parseJSON(ret);
  1307. if( ret.status == 'ok')
  1308. {
  1309. content = $.parseJSON(ret.content);
  1310. message = langPackOk + ' <b>'+content['name'] + '</b>) :'
  1311. +'<br />' + langPackVersion + ' ' + content['version']
  1312. + ' <a href="http://www.prestashop.com/download/lang_packs/gzip/' + content['version'] + '/'
  1313. + ($('#iso_code').val()).toLowerCase()+'.gzip" target="_blank" class="link">'+download+'</a><br />' + langPackInfo;
  1314. $('#lang_pack_msg').html(message);
  1315. $('#lang_pack_msg').show();
  1316. }
  1317. else
  1318. showErrorMessage(ret.error);
  1319. }
  1320. );
  1321. }
  1322. }
  1323. function redirect(new_page) { window.location = new_page; }
  1324. function saveCustomerNote(customerId){
  1325. var noteContent = $('#noteContent').val();
  1326. var data = 'token=' + token_admin_customers + '&tab=AdminCustomers&ajax=1&action=updateCustomerNote&id_customer=' + customerId + '&note=' + encodeURIComponent(noteContent);
  1327. $.ajax({
  1328. type: "POST",
  1329. url: "index.php",
  1330. data: data,
  1331. async : true,
  1332. success: function(r) {
  1333. if (r == 'ok') {
  1334. $('#submitCustomerNote').attr('disabled', true);
  1335. }
  1336. showSuccessMessage(update_success_msg);
  1337. }
  1338. });
  1339. }
  1340. function isCleanHtml(content)
  1341. {
  1342. var events = 'onmousedown|onmousemove|onmmouseup|onmouseover|onmouseout|onload|onunload|onfocus|onblur|onchange';
  1343. events += '|onsubmit|ondblclick|onclick|onkeydown|onkeyup|onkeypress|onmouseenter|onmouseleave|onerror|onselect|onreset|onabort|ondragdrop|onresize|onactivate|onafterprint|onmoveend';
  1344. events += '|onafterupdate|onbeforeactivate|onbeforecopy|onbeforecut|onbeforedeactivate|onbeforeeditfocus|onbeforepaste|onbeforeprint|onbeforeunload|onbeforeupdate|onmove';
  1345. events += '|onbounce|oncellchange|oncontextmenu|oncontrolselect|oncopy|oncut|ondataavailable|ondatasetchanged|ondatasetcomplete|ondeactivate|ondrag|ondragend|ondragenter|onmousewheel';
  1346. events += '|ondragleave|ondragover|ondragstart|ondrop|onerrorupdate|onfilterchange|onfinish|onfocusin|onfocusout|onhashchange|onhelp|oninput|onlosecapture|onmessage|onmouseup|onmovestart';
  1347. events += '|onoffline|ononline|onpaste|onpropertychange|onreadystatechange|onresizeend|onresizestart|onrowenter|onrowexit|onrowsdelete|onrowsinserted|onscroll|onsearch|onselectionchange';
  1348. events += '|onselectstart|onstart|onstop';
  1349. var script1 = /<[\s]*script/im;
  1350. var script2 = new RegExp('('+events+')[\s]*=', 'im');
  1351. var script3 = /.*script\:/im;
  1352. var script4 = /<[\s]*(i?frame|embed|object)/im;
  1353. if (script1.test(content) || script2.test(content) || script3.test(content) || script4.test(content))
  1354. return false;
  1355. return true;
  1356. }
  1357. function parseDate(date){
  1358. return $.datepicker.parseDate("yy-mm-dd", date);
  1359. }
  1360. function refresh_kpis()
  1361. {
  1362. $('.box-stats').each(function(){
  1363. window['refresh_' + $(this).attr('id').replace(/-/g, '_')]();
  1364. });
  1365. }
  1366. function createSqlQueryName()
  1367. {
  1368. var container = false;
  1369. if ($('.breadcrumb-container'))
  1370. container = $('.breadcrumb-container').first().text().replace(/\s+/g, ' ').trim();
  1371. var current = false;
  1372. if ($('.breadcrumb-current'))
  1373. current = $('.breadcrumb-current').first().text().replace(/\s+/g, ' ').trim();
  1374. var title = false;
  1375. if ($('.page-title'))
  1376. title = $('.page-title').first().text().replace(/\s+/g, ' ').trim();
  1377. var name = false;
  1378. if (container && current && container != current)
  1379. name = container + ' > ' + current;
  1380. else if (container)
  1381. name = container;
  1382. else if (current)
  1383. name = current;
  1384. if (title && title != current && title != container)
  1385. {
  1386. if (name)
  1387. name = name + ' > ' + title;
  1388. else
  1389. name = title;
  1390. }
  1391. return name.trim();
  1392. }
  1393. function confirm_link(head_text, display_text, confirm_text, cancel_text, confirm_link, cancel_link)
  1394. {
  1395. $.alerts.okButton = confirm_text;
  1396. $.alerts.cancelButton = cancel_text;
  1397. jConfirm(display_text, head_text, function(confirm){
  1398. if (confirm === true)
  1399. document.location = confirm_link;
  1400. else
  1401. document.location = cancel_link;
  1402. });
  1403. }