Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

6 месяцев назад
6 месяцев назад
6 месяцев назад
9 месяцев назад
8 месяцев назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /**
  2. Copyright Souke (2018)
  3. contact@souke.fr
  4. Ce logiciel est un programme informatique servant à aider les producteurs
  5. à distribuer leur production en circuits courts.
  6. Ce logiciel est régi par la licence CeCILL soumise au droit français et
  7. respectant les principes de diffusion des logiciels libres. Vous pouvez
  8. utiliser, modifier et/ou redistribuer ce programme sous les conditions
  9. de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  10. sur le site "http://www.cecill.info".
  11. En contrepartie de l'accessibilité au code source et des droits de copie,
  12. de modification et de redistribution accordés par cette licence, il n'est
  13. offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
  14. seule une responsabilité restreinte pèse sur l'auteur du programme, le
  15. titulaire des droits patrimoniaux et les concédants successifs.
  16. A cet égard l'attention de l'utilisateur est attirée sur les risques
  17. associés au chargement, à l'utilisation, à la modification et/ou au
  18. développement et à la reproduction du logiciel par l'utilisateur étant
  19. donné sa spécificité de logiciel libre, qui peut le rendre complexe à
  20. manipuler et qui le réserve donc à des développeurs et des professionnels
  21. avertis possédant des connaissances informatiques approfondies. Les
  22. utilisateurs sont donc invités à charger et tester l'adéquation du
  23. logiciel à leurs besoins dans des conditions permettant d'assurer la
  24. sécurité de leurs systèmes et ou de leurs données et, plus généralement,
  25. à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
  26. Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
  27. pris connaissance de la licence CeCILL, et que vous en avez accepté les
  28. termes.
  29. */
  30. $(document).ready(function () {
  31. opendistrib_datepicker();
  32. opendistrib_popover();
  33. opendistrib_points_vente_acces();
  34. opendistrib_tooltip();
  35. opendistrib_ordre_produits();
  36. opendistrib_ordre_categories();
  37. opendistrib_products();
  38. opendistrib_product_prices();
  39. opendistrib_product_index();
  40. opendistrib_confirm_delete();
  41. opendistrib_product_availability_points_sale();
  42. opendistrib_user_index();
  43. opendistrib_menu_treeview();
  44. opendistrib_select2();
  45. opendistrib_dropdown_producers();
  46. opendistrib_gridview_pagesize();
  47. opendistrib_producers_admin();
  48. opendistrib_user_form();
  49. opendistrib_features_index();
  50. opendistrib_point_sale_form();
  51. opendistrib_check_all_checkboxes();
  52. opendistrib_dashboard_admin_statistics();
  53. opendistrib_tinymce_responsive();
  54. opendistrib_sponsorship();
  55. });
  56. function label_unit_reference(unit) {
  57. if(unit == 'piece') {
  58. return 'p.';
  59. }
  60. else if(unit == 'g' || unit == 'kg') {
  61. return 'kg';
  62. }
  63. else {
  64. return 'litre(s)';
  65. }
  66. }
  67. function opendistrib_sponsorship() {
  68. $('#sponsorship-link-copy').click(function() {
  69. navigator.clipboard.writeText($(this).attr('href'));
  70. appAlerts.alert('success', 'Lien de parrainage copié');
  71. return false;
  72. });
  73. }
  74. function saveData (data, fileName) {
  75. var a = document.createElement("a");
  76. document.body.appendChild(a);
  77. a.style = "display: none";
  78. var blob = new Blob([data], {type: "octet/stream"}),
  79. url = window.URL.createObjectURL(blob);
  80. a.href = url;
  81. a.download = fileName;
  82. a.click();
  83. window.URL.revokeObjectURL(url);
  84. }
  85. var UrlManager = {
  86. getBaseUrl: function () {
  87. return $('meta[name=baseurl]').attr('content') + '/';
  88. },
  89. getBaseUrlAbsolute: function () {
  90. return $('meta[name=baseurl-absolute]').attr('content') + '/';
  91. }
  92. };
  93. function opendistrib_tinymce_responsive() {
  94. // tinymce.activeEditor.mode.set('readonly');
  95. //tinymce.activeEditor.hide();
  96. //tinymce.EditorManager.execCommand('mceRemoveEditor',true, 'textarea#mailform-message');
  97. //tinyMCE.init({readonly : 1});
  98. //tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
  99. //tinyMCE.get('mailform-message').getBody().setAttribute('contenteditable', false);
  100. }
  101. function opendistrib_dashboard_admin_statistics() {
  102. var selector = '#dashboard-admin-statistics-html';
  103. if($(selector).length) {
  104. $(selector+' .btn-load').click(function() {
  105. $(selector).html('Chargement ...');
  106. $.get(UrlManager.getBaseUrl() + 'dashboard-admin/ajax-statistics-html', {}, function(result) {
  107. $(selector).html(result);
  108. });
  109. });
  110. }
  111. }
  112. function opendistrib_check_all_checkboxes() {
  113. $('.check-all-checkboxes').change(function() {
  114. var selector = $(this).data('selector');
  115. var checked = $(this).prop('checked');
  116. $(selector).prop('checked', checked);
  117. if(checked){
  118. $(selector).unbind('change').change(function() {
  119. if(!$(this).prop('checked')) {
  120. $('.check-all-checkboxes').prop('checked', false);
  121. }
  122. });
  123. }
  124. });
  125. }
  126. function opendistrib_point_sale_form() {
  127. if($('.point-sale-form').length) {
  128. opendistrib_point_sale_form_days_distribution_event();
  129. $('#days-distribution .day input[type=checkbox]').change(function() {
  130. opendistrib_point_sale_form_days_distribution_event();
  131. });
  132. }
  133. }
  134. function opendistrib_point_sale_form_days_distribution_event() {
  135. $('#days-distribution .day').each(function() {
  136. var isChecked = $(this).find('input[type=checkbox]').prop('checked');
  137. var $textareaInfos = $(this).find('textarea');
  138. if(isChecked) {
  139. $textareaInfos.show();
  140. }
  141. else {
  142. $textareaInfos.hide();
  143. }
  144. });
  145. }
  146. function opendistrib_user_form() {
  147. if($('#app-user-form').length) {
  148. var $fieldUserEmail = $('#app-user-form .field-user-email input');
  149. var $fieldSendMailWelcome = $('#app-user-form .field-user-send_mail_welcome');
  150. opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome);
  151. $fieldUserEmail.keyup(function () {
  152. opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome);
  153. });
  154. }
  155. }
  156. function opendistrib_user_form_event($fieldUserEmail, $fieldSendMailWelcome) {
  157. var val = $fieldUserEmail.val();
  158. if (val.length > 0) {
  159. $fieldSendMailWelcome.show();
  160. }
  161. else {
  162. $fieldSendMailWelcome.hide();
  163. }
  164. }
  165. function opendistrib_producers_admin() {
  166. $('.producer-admin-index .btn-alwaysdata, .producer-admin-index .btn-dolibarr').click(function () {
  167. var $button = $(this);
  168. $button.attr('disabled', 'disabled');
  169. axios.get($button.attr('href'), {})
  170. .then(function (response) {
  171. appAlerts.alertResponse(response);
  172. $button.removeAttr('disabled');
  173. });
  174. return false;
  175. });
  176. }
  177. function opendistrib_gridview_pagesize() {
  178. $('.gridview-pagesize select').change(function () {
  179. $(this).parent().parent().submit();
  180. });
  181. }
  182. function opendistrib_dropdown_producers() {
  183. $('.producer-menu .dropdown-toggle').click(function () {
  184. setTimeout(function() { $('.producer-menu .search-producer').focus(); }, 100);
  185. });
  186. $('.producer-menu .search-producer').keyup(function (event) {
  187. var $alertNoResults = $('.producer-menu .li-alert-no-results');
  188. var searchWords = $(this).val().toLowerCase();
  189. var count = 0;
  190. if (searchWords && searchWords.length > 0) {
  191. $('.producer-menu li.producer').each(function () {
  192. if ($(this).find('a').text().toLowerCase().indexOf(searchWords) >= 0 || !searchWords) {
  193. $(this).show();
  194. count++;
  195. } else {
  196. $(this).hide();
  197. }
  198. });
  199. if (count) {
  200. $alertNoResults.hide();
  201. } else {
  202. $alertNoResults.show();
  203. }
  204. } else {
  205. $alertNoResults.hide();
  206. $('.producer-menu li.producer').show();
  207. }
  208. if(event.key == 'Enter') {
  209. $firstProducer = $('.producer-menu li.producer:visible:first');
  210. if($firstProducer.length > 0) {
  211. window.location = $firstProducer.find('a').attr('href');
  212. }
  213. }
  214. });
  215. $('#link-display-producers-offline').click(function () {
  216. $(this).hide();
  217. $('.producer-menu .offline').show();
  218. return false;
  219. });
  220. }
  221. function opendistrib_popover() {
  222. $('button[data-toggle=popover], a[data-toggle=popover]').popover();
  223. }
  224. function opendistrib_select2() {
  225. $('.select2').select2({
  226. width: 'resolve'
  227. });
  228. }
  229. function opendistrib_user_index() {
  230. if ($('body').hasClass('user-index')) {
  231. $('#w0-filters input:first').focus();
  232. }
  233. }
  234. function opendistrib_menu_treeview() {
  235. $('li.treeview a').unbind('click').click(function () {
  236. var href = $(this).attr('href');
  237. if (href != '#') {
  238. $(location).attr('href', href);
  239. }
  240. });
  241. }
  242. function opendistrib_product_index() {
  243. $('body.product-index .toggle input').change(function () {
  244. var id = $(this).data('id');
  245. var checked = $(this).prop('checked');
  246. $.get(UrlManager.getBaseUrl() + 'product/ajax-toggle-status', {
  247. id: id,
  248. status: checked ? 1 : 0
  249. });
  250. })
  251. }
  252. function opendistrib_product_availability_points_sale() {
  253. $('input[name="Product[available_on_points_sale]"]').change(function () {
  254. var available = parseInt($(this).val());
  255. var label = 'disponible';
  256. if (available == 1) {
  257. label = 'indisponible';
  258. }
  259. $('#label-availability-points-sale span').html(label);
  260. });
  261. }
  262. function opendistrib_confirm_delete() {
  263. $('.btn-confirm-delete').click(function (event) {
  264. if (!confirm('Souhaitez-vous vraiment supprimer cette entrée ?')) {
  265. event.stopPropagation();
  266. return false;
  267. }
  268. });
  269. }
  270. function opendistrib_products() {
  271. if ($('.product-create').size() || $('.product-update').size()) {
  272. opendistrib_products_event_unit(false);
  273. $('#product-unit').change(function () {
  274. opendistrib_products_event_unit(true);
  275. });
  276. opendistrib_products_event_price_with_tax();
  277. $('#product-price').change(opendistrib_products_event_price_with_tax);
  278. $('#product-price-with-tax').change(opendistrib_products_event_price);
  279. $('#product-id_tax_rate').change(opendistrib_products_event_price_with_tax);
  280. }
  281. }
  282. function opendistrib_products_event_price_with_tax() {
  283. taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value');
  284. if (typeof taxRateSelected == 'undefined') {
  285. taxRateSelected = 0;
  286. }
  287. if ($('#product-price').length) {
  288. var price = $('#product-price').val().replace(',', '.');
  289. if (price) {
  290. $('#product-price-with-tax').val(getPriceWithTax(price, taxRateSelected));
  291. // formattage
  292. $('#product-price').val(parseFloat(price).toFixed(5));
  293. }
  294. }
  295. }
  296. function opendistrib_products_event_price() {
  297. taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value');
  298. if (typeof taxRateSelected == 'undefined') {
  299. taxRateSelected = 0;
  300. }
  301. var priceWithTax = $('#product-price-with-tax').val();
  302. if (priceWithTax) {
  303. $('#product-price').val(getPrice(priceWithTax, taxRateSelected));
  304. // formattage
  305. $('#product-price-with-tax').val(parseFloat(priceWithTax).toFixed(2));
  306. }
  307. }
  308. function opendistrib_products_event_unit(change) {
  309. var unit = $('#product-unit').val();
  310. if (unit == 'piece') {
  311. $('.field-product-step').hide();
  312. $('.field-product-weight label').html('Poids (g)');
  313. } else {
  314. $('.field-product-step').show();
  315. //$('.field-product-weight label').html('Poids (' + $('#product-unit').val() + ')');
  316. $('.field-product-weight label').html('Poids (g)');
  317. }
  318. var label_price_ttc = $('.field-product-price .control-label.with-tax');
  319. var label_price_ht = $('.field-product-price .control-label.without-tax');
  320. var label_step = $('.field-product-step .control-label');
  321. var label_quantity_max = $('.field-product-quantity_max .control-label');
  322. if (unit == 'piece') {
  323. label_price_ttc.html('Prix (la pièce) TTC');
  324. label_price_ht.html('Prix (la pièce) HT');
  325. label_quantity_max.html('Par défaut (pièces)');
  326. } else if (unit == 'g' || unit == 'kg') {
  327. label_price_ttc.html('Prix (au kg) TTC');
  328. label_price_ht.html('Prix (au kg) HT');
  329. label_quantity_max.html('Par défaut (kg)');
  330. label_step.html('Pas (' + unit + ')');
  331. } else if (unit == 'mL' || unit == 'L') {
  332. label_price_ttc.html('Prix (au litre) TTC');
  333. label_price_ht.html('Prix (au litre) HT');
  334. label_quantity_max.html('Par défaut (litres)');
  335. label_step.html('Pas (' + unit + ')');
  336. }
  337. if (change) {
  338. if (unit == 'piece') {
  339. $('#product-step').val(1);
  340. } else {
  341. $('#product-step').val('');
  342. }
  343. }
  344. }
  345. function opendistrib_product_prices() {
  346. if ($('.product-prices-create').size() || $('.product-prices-update').size()) {
  347. opendistrib_product_prices_event_price_with_tax();
  348. $('#productprice-price').change(opendistrib_product_prices_event_price_with_tax);
  349. $('#productprice-price-with-tax').change(opendistrib_product_prices_event_price);
  350. $('#reduction-increase-percent').change(function () {
  351. opendistrib_product_prices_event_reduction_increase();
  352. });
  353. }
  354. }
  355. function opendistrib_product_prices_event_price_with_tax() {
  356. var taxRateValue = $('#productprice-price-with-tax').data('tax-rate-value');
  357. var price = $('#productprice-price').val().replace(',', '.');
  358. if (price) {
  359. $('#productprice-price-with-tax').val(getPriceWithTax(price, taxRateValue));
  360. // formattage
  361. $('#productprice-price').val(parseFloat(price).toFixed(5));
  362. opendistrib_product_prices_update_reduction_increase();
  363. }
  364. }
  365. function opendistrib_product_prices_event_price() {
  366. var taxRateValue = $('#productprice-price-with-tax').data('tax-rate-value');
  367. var priceWithTax = $('#productprice-price-with-tax').val().replace(',', '.');
  368. if (priceWithTax) {
  369. $('#productprice-price').val(getPrice(priceWithTax, taxRateValue));
  370. // formattage
  371. $('#productprice-price-with-tax').val(parseFloat(priceWithTax).toFixed(2));
  372. opendistrib_product_prices_update_reduction_increase();
  373. }
  374. }
  375. function opendistrib_product_prices_update_reduction_increase() {
  376. var productPriceBase = $('#reduction-increase-percent').data('price-base');
  377. var productPriceSpecific = $('#productprice-price').val().replace(',', '.');
  378. var reductionIncreasePercent = (productPriceSpecific / productPriceBase) * 100 - 100;
  379. $('#reduction-increase-percent').val(parseFloat(reductionIncreasePercent).toFixed(5));
  380. }
  381. function opendistrib_product_prices_event_reduction_increase() {
  382. var productPriceBase = $('#reduction-increase-percent').data('price-base');
  383. var reductionIncreasePercent = $('#reduction-increase-percent').val();
  384. if (reductionIncreasePercent) {
  385. var newPrice = productPriceBase + productPriceBase * (reductionIncreasePercent / 100);
  386. $('#productprice-price').val(parseFloat(newPrice).toFixed(5));
  387. opendistrib_product_prices_event_price_with_tax();
  388. }
  389. }
  390. function opendistrib_tooltip() {
  391. $('[data-toggle="tooltip"]').tooltip({
  392. container: 'body'
  393. });
  394. }
  395. function opendistrib_nl2br(str, is_xhtml) {
  396. var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
  397. return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
  398. }
  399. function opendistrib_points_vente_acces() {
  400. // affichage du bloc acces restreint
  401. $('#pointsale-restricted_access').change(function () {
  402. opendistrib_points_vente_acces_event();
  403. });
  404. opendistrib_points_vente_acces_event();
  405. // affichage du champs commentaire
  406. $('#pointsale-users input[type=checkbox]').change(function () {
  407. opendistrib_points_vente_commentaire_event();
  408. });
  409. opendistrib_points_vente_commentaire_event();
  410. }
  411. function opendistrib_points_vente_commentaire_event() {
  412. $('#pointsale-users input[type=checkbox]').each(function () {
  413. if ($(this).prop('checked')) {
  414. $(this).parent().find('.commentaire').fadeIn();
  415. } else {
  416. $(this).parent().find('.commentaire').hide();
  417. }
  418. });
  419. }
  420. function opendistrib_points_vente_acces_event() {
  421. if ($('#pointsale-restricted_access').prop('checked')) {
  422. $('#pointsale-users').fadeIn();
  423. } else {
  424. $('#pointsale-users').hide();
  425. }
  426. }
  427. function opendistrib_sortable_list(element_selector, button_selector, route_ajax) {
  428. var fixHelper = function (e, ui) {
  429. ui.children().each(function () {
  430. $(this).width($(this).width());
  431. });
  432. return ui;
  433. };
  434. $(element_selector + " table tbody").sortable({
  435. items: "> tr",
  436. appendTo: "parent",
  437. cursor: "move",
  438. placeholder: "ui-state-highlight",
  439. handle: button_selector,
  440. helper: fixHelper,
  441. stop: function (event, ui) {
  442. var tab_ordre = {};
  443. var ordre = 1;
  444. if ($('ul.pagination').size()) {
  445. var page = parseInt($('ul.pagination li.active a').html());
  446. var nb_items_by_page = parseInt($('#page-size').html());
  447. if (page != 1) {
  448. ordre = (page - 1) * nb_items_by_page;
  449. }
  450. }
  451. $(element_selector + " table tbody tr").each(function () {
  452. tab_ordre[$(this).attr('data-key')] = ordre;
  453. ordre++;
  454. });
  455. $.post(UrlManager.getBaseUrl() + route_ajax, {
  456. array: JSON.stringify(tab_ordre)
  457. });
  458. }
  459. }).disableSelection();
  460. }
  461. function opendistrib_ordre_categories() {
  462. opendistrib_sortable_list(
  463. '.product-category-index',
  464. '.btn-position',
  465. 'product-category/position'
  466. );
  467. }
  468. function opendistrib_ordre_produits() {
  469. opendistrib_sortable_list(
  470. '.product-index',
  471. '.btn-order',
  472. 'product/order'
  473. );
  474. }
  475. function opendistrib_features_index() {
  476. $('body.feature-admin-index .toggle input').change(function () {
  477. var id = $(this).data('id');
  478. var checked = $(this).prop('checked');
  479. /*$.get(UrlManager.getBaseUrl() + 'feature-admin/ajax-toggle-status', {
  480. id: id,
  481. status: checked ? 1 : 0
  482. });*/
  483. axios.get(UrlManager.getBaseUrlAbsolute() + "feature-admin/ajax-toggle-status", {
  484. params: {
  485. id: id,
  486. status: checked ? 1 : 0
  487. }
  488. })
  489. .then(function (response) {
  490. appAlerts.alertResponse(response);
  491. });
  492. });
  493. opendistrib_sortable_list(
  494. '.feature-admin-index',
  495. '.btn-position',
  496. 'feature-admin/position'
  497. );
  498. }
  499. function opendistrib_datepicker() {
  500. $('#subscriptionform-date_begin, #subscriptionform-date_end').datepicker();
  501. $('input.datepicker').datepicker({dateFormat: 'dd/mm/yy'});
  502. }
  503. /* French initialisation for the jQuery UI date picker plugin. */
  504. /* Written by Keith Wood (kbwood{at}iinet.com.au),
  505. Stéphane Nahmani (sholby@sholby.net),
  506. Stéphane Raimbault <stephane.raimbault@gmail.com> */
  507. (function (factory) {
  508. if (typeof define === "function" && define.amd) {
  509. // AMD. Register as an anonymous module.
  510. define(["../jquery.ui.datepicker"], factory);
  511. } else {
  512. // Browser globals
  513. factory(jQuery.datepicker);
  514. }
  515. }(function (datepicker) {
  516. datepicker.regional['fr'] = {
  517. closeText: 'Fermer',
  518. prevText: 'Précédent',
  519. nextText: 'Suivant',
  520. currentText: 'Aujourd\'hui',
  521. monthNames: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin',
  522. 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
  523. monthNamesShort: ['janv.', 'févr.', 'mars', 'avril', 'mai', 'juin',
  524. 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
  525. dayNames: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
  526. dayNamesShort: ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'],
  527. dayNamesMin: ['D', 'L', 'M', 'M', 'J', 'V', 'S'],
  528. weekHeader: 'Sem.',
  529. dateFormat: 'dd/mm/yy',
  530. firstDay: 1,
  531. isRTL: false,
  532. showMonthAfterYear: false,
  533. yearSuffix: ''
  534. };
  535. datepicker.setDefaults(datepicker.regional['fr']);
  536. return datepicker.regional['fr'];
  537. }));