您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

424 行
14KB

  1. /**
  2. Copyright distrib (2018)
  3. contact@opendistrib.net
  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. $('button[data-toggle=popover]').popover();
  33. opendistrib_commandeauto();
  34. opendistrib_points_vente_acces();
  35. opendistrib_tooltip();
  36. opendistrib_ordre_produits();
  37. opendistrib_ordre_categories();
  38. opendistrib_products();
  39. opendistrib_product_prices();
  40. opendistrib_product_index();
  41. opendistrib_confirm_delete();
  42. opendistrib_product_availability_points_sale();
  43. opendistrib_user_index();
  44. opendistrib_menu_treeview();
  45. opendistrib_select2();
  46. });
  47. var UrlManager = {
  48. getBaseUrl: function () {
  49. return $('meta[name=baseurl]').attr('content') + '/';
  50. },
  51. getBaseUrlAbsolute: function () {
  52. return $('meta[name=baseurl-absolute]').attr('content') + '/';
  53. }
  54. };
  55. function opendistrib_select2() {
  56. $('.select2').select2({
  57. width: 'resolve'
  58. });
  59. }
  60. function opendistrib_user_index() {
  61. if ($('body').hasClass('user-index')) {
  62. $('#w0-filters input:first').focus();
  63. }
  64. }
  65. function opendistrib_menu_treeview() {
  66. $('li.treeview a').unbind('click').click(function () {
  67. var href = $(this).attr('href');
  68. if (href != '#') {
  69. $(location).attr('href', href);
  70. }
  71. });
  72. }
  73. function opendistrib_product_index() {
  74. $('body.product-index .toggle input').change(function() {
  75. var id = $(this).data('id');
  76. var checked = $(this).prop('checked');
  77. var active = 0;
  78. if(checked) {
  79. active = 1;
  80. }
  81. $.get(UrlManager.getBaseUrl() + 'product/ajax-toggle-active', {
  82. id: id,
  83. active: active
  84. });
  85. })
  86. }
  87. function opendistrib_product_availability_points_sale() {
  88. $('input[name="Product[available_on_points_sale]"]').change(function () {
  89. var available = parseInt($(this).val());
  90. var label = 'disponible';
  91. if (available == 1) {
  92. label = 'indisponible';
  93. }
  94. $('#label-availability-points-sale span').html(label);
  95. });
  96. }
  97. function opendistrib_confirm_delete() {
  98. $('.btn-confirm-delete').click(function (event) {
  99. if (!confirm('Souhaitez-vous vraiment supprimer cette entrée ?')) {
  100. event.stopPropagation();
  101. return false;
  102. }
  103. });
  104. }
  105. function opendistrib_products() {
  106. if ($('.product-create').size() || $('.product-update').size()) {
  107. opendistrib_products_event_unit(false);
  108. $('#product-unit').change(function () {
  109. opendistrib_products_event_unit(true);
  110. });
  111. opendistrib_products_event_price_with_tax();
  112. $('#product-price').change(opendistrib_products_event_price_with_tax);
  113. $('#product-price-with-tax').change(opendistrib_products_event_price);
  114. $('#product-id_tax_rate').change(opendistrib_products_event_price_with_tax);
  115. }
  116. }
  117. function opendistrib_products_event_price_with_tax() {
  118. taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value');
  119. if (typeof taxRateSelected == 'undefined') {
  120. taxRateSelected = 0;
  121. }
  122. if($('#product-price').length) {
  123. var price = $('#product-price').val().replace(',', '.');
  124. if (price) {
  125. $('#product-price-with-tax').val(getPriceWithTax(price, taxRateSelected));
  126. // formattage
  127. $('#product-price').val(parseFloat(price).toFixed(3));
  128. }
  129. }
  130. }
  131. function opendistrib_products_event_price() {
  132. taxRateSelected = $('#product-id_tax_rate').find('option:selected').data('tax-rate-value');
  133. var priceWithTax = $('#product-price-with-tax').val();
  134. if (priceWithTax) {
  135. $('#product-price').val(getPrice(priceWithTax, taxRateSelected));
  136. // formattage
  137. $('#product-price-with-tax').val(parseFloat(priceWithTax).toFixed(2));
  138. }
  139. }
  140. function opendistrib_products_event_unit(change) {
  141. var unit = $('#product-unit').val();
  142. if (unit == 'piece') {
  143. $('.field-product-step').hide();
  144. $('.field-product-weight label').html('Poids (g)');
  145. $('.field-product-weight').show();
  146. } else {
  147. $('.field-product-step').show();
  148. $('.field-product-weight label').html('Poids (' + $('#product-unit').val() + ')');
  149. $('.field-product-weight').hide();
  150. }
  151. var label_price_ttc = $('.field-product-price .control-label.with-tax');
  152. var label_price_ht = $('.field-product-price .control-label.without-tax');
  153. var label_step = $('.field-product-step .control-label');
  154. var label_quantity_max = $('.field-product-quantity_max .control-label');
  155. if (unit == 'piece') {
  156. label_price_ttc.html('Prix (la pièce) TTC');
  157. label_price_ht.html('Prix (la pièce) HT');
  158. label_quantity_max.html('Quantité max par défaut (pièces)');
  159. } else if (unit == 'g' || unit == 'kg') {
  160. label_price_ttc.html('Prix (au kg) TTC');
  161. label_price_ht.html('Prix (au kg) HT');
  162. label_quantity_max.html('Quantité max par défaut (kg)');
  163. label_step.html('Pas (' + unit + ')');
  164. } else if (unit == 'mL' || unit == 'L') {
  165. label_price_ttc.html('Prix (au litre) TTC');
  166. label_price_ht.html('Prix (au litre) HT');
  167. label_quantity_max.html('Quantité max par défaut (litres)');
  168. label_step.html('Pas (' + unit + ')');
  169. }
  170. if (change) {
  171. if (unit == 'piece') {
  172. $('#product-step').val(1);
  173. } else {
  174. $('#product-step').val('');
  175. }
  176. }
  177. }
  178. function opendistrib_product_prices() {
  179. if ($('.product-prices-create').size() || $('.product-prices-update').size()) {
  180. opendistrib_product_prices_event_price_with_tax();
  181. $('#productprice-price').change(opendistrib_product_prices_event_price_with_tax);
  182. $('#productprice-price-with-tax').change(opendistrib_product_prices_event_price);
  183. }
  184. }
  185. function opendistrib_product_prices_event_price_with_tax() {
  186. var taxRateValue = $('#productprice-price-with-tax').data('tax-rate-value');
  187. var price = $('#productprice-price').val().replace(',', '.');
  188. if (price) {
  189. $('#productprice-price-with-tax').val(getPriceWithTax(price, taxRateValue));
  190. // formattage
  191. $('#productprice-price').val(parseFloat(price).toFixed(3));
  192. }
  193. }
  194. function opendistrib_product_prices_event_price() {
  195. var taxRateValue = $('#productprice-price-with-tax').data('tax-rate-value');
  196. var priceWithTax = $('#productprice-price-with-tax').val().replace(',', '.');
  197. if (priceWithTax) {
  198. $('#productprice-price').val(getPrice(priceWithTax, taxRateValue));
  199. // formattage
  200. $('#productprice-price-with-tax').val(parseFloat(priceWithTax).toFixed(2));
  201. }
  202. }
  203. function opendistrib_tooltip() {
  204. $('[data-toggle="tooltip"]').tooltip({container: 'body'});
  205. }
  206. function opendistrib_nl2br(str, is_xhtml) {
  207. var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
  208. return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
  209. }
  210. function opendistrib_points_vente_acces() {
  211. // affichage du bloc acces restreint
  212. $('#pointsale-restricted_access').change(function () {
  213. opendistrib_points_vente_acces_event();
  214. });
  215. opendistrib_points_vente_acces_event();
  216. // affichage du champs commentaire
  217. $('#pointsale-users input[type=checkbox]').change(function () {
  218. opendistrib_points_vente_commentaire_event();
  219. });
  220. opendistrib_points_vente_commentaire_event();
  221. }
  222. function opendistrib_points_vente_commentaire_event() {
  223. $('#pointsale-users input[type=checkbox]').each(function () {
  224. if ($(this).prop('checked')) {
  225. $(this).parent().find('.commentaire').fadeIn();
  226. } else {
  227. $(this).parent().find('.commentaire').hide();
  228. }
  229. });
  230. }
  231. function opendistrib_points_vente_acces_event() {
  232. if ($('#pointsale-restricted_access').prop('checked')) {
  233. $('#pointsale-users').fadeIn();
  234. } else {
  235. $('#pointsale-users').hide();
  236. }
  237. }
  238. function opendistrib_commandeauto() {
  239. $('#subscriptionform-date_begin, #subscriptionform-date_end').datepicker();
  240. }
  241. function opendistrib_sortable_list(element_selector, button_selector, route_ajax) {
  242. var fixHelper = function (e, ui) {
  243. ui.children().each(function () {
  244. $(this).width($(this).width());
  245. });
  246. return ui;
  247. };
  248. $(element_selector + " table tbody").sortable({
  249. items: "> tr",
  250. appendTo: "parent",
  251. cursor: "move",
  252. placeholder: "ui-state-highlight",
  253. handle: button_selector,
  254. helper: fixHelper,
  255. stop: function (event, ui) {
  256. var tab_ordre = {};
  257. var ordre = 1;
  258. if ($('ul.pagination').size()) {
  259. var page = parseInt($('ul.pagination li.active a').html());
  260. var nb_items_by_page = parseInt($('#page-size').html());
  261. if (page != 1) {
  262. ordre = (page - 1) * nb_items_by_page;
  263. }
  264. }
  265. $(element_selector + " table tbody tr").each(function () {
  266. tab_ordre[$(this).attr('data-key')] = ordre;
  267. ordre++;
  268. });
  269. $.post(UrlManager.getBaseUrl() + route_ajax, {
  270. array: JSON.stringify(tab_ordre)
  271. });
  272. }
  273. }).disableSelection();
  274. }
  275. function opendistrib_ordre_categories() {
  276. opendistrib_sortable_list(
  277. '.product-category-index',
  278. '.btn-position',
  279. 'product-category/position'
  280. );
  281. }
  282. function opendistrib_ordre_produits() {
  283. opendistrib_sortable_list(
  284. '.product-index',
  285. '.btn-order',
  286. 'product/order'
  287. );
  288. /*var fixHelper = function(e, ui) {
  289. ui.children().each(function() {
  290. $(this).width($(this).width());
  291. });
  292. return ui;
  293. };
  294. $(".product-index table tbody").sortable({
  295. items: "> tr",
  296. appendTo: "parent",
  297. cursor: "move",
  298. placeholder: "ui-state-highlight",
  299. handle: '.btn-order',
  300. //helper: "clone"
  301. helper: fixHelper,
  302. stop: function(event, ui) {
  303. var tab_ordre = {} ;
  304. var ordre = 1 ;
  305. if($('ul.pagination').size()) {
  306. var page = parseInt($('ul.pagination li.active a').html()) ;
  307. var nb_items_by_page = parseInt($('#page-size').html()) ;
  308. if(page != 1) {
  309. ordre = (page - 1) * nb_items_by_page ;
  310. }
  311. }
  312. $(".product-index table tbody tr").each(function() {
  313. tab_ordre[$(this).attr('data-key')] = ordre ;
  314. ordre++ ;
  315. }) ;
  316. $.post(UrlManager.getBaseUrl()+'product/order',{
  317. array: JSON.stringify(tab_ordre)
  318. }) ;
  319. }
  320. }).disableSelection();*/
  321. }
  322. function opendistrib_datepicker() {
  323. $('input.datepicker').datepicker({dateFormat: 'dd/mm/yy'});
  324. }
  325. /* French initialisation for the jQuery UI date picker plugin. */
  326. /* Written by Keith Wood (kbwood{at}iinet.com.au),
  327. Stéphane Nahmani (sholby@sholby.net),
  328. Stéphane Raimbault <stephane.raimbault@gmail.com> */
  329. (function (factory) {
  330. if (typeof define === "function" && define.amd) {
  331. // AMD. Register as an anonymous module.
  332. define(["../jquery.ui.datepicker"], factory);
  333. } else {
  334. // Browser globals
  335. factory(jQuery.datepicker);
  336. }
  337. }(function (datepicker) {
  338. datepicker.regional['fr'] = {
  339. closeText: 'Fermer',
  340. prevText: 'Précédent',
  341. nextText: 'Suivant',
  342. currentText: 'Aujourd\'hui',
  343. monthNames: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin',
  344. 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
  345. monthNamesShort: ['janv.', 'févr.', 'mars', 'avril', 'mai', 'juin',
  346. 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
  347. dayNames: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
  348. dayNamesShort: ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'],
  349. dayNamesMin: ['D', 'L', 'M', 'M', 'J', 'V', 'S'],
  350. weekHeader: 'Sem.',
  351. dateFormat: 'dd/mm/yy',
  352. firstDay: 1,
  353. isRTL: false,
  354. showMonthAfterYear: false,
  355. yearSuffix: ''
  356. };
  357. datepicker.setDefaults(datepicker.regional['fr']);
  358. return datepicker.regional['fr'];
  359. }));