You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* ProductFamily */
  2. /*function initLcTaxPriceWidget() {
  3. lcTaxPriceInit() ;
  4. $('#productfamily_price').change(lcTaxPriceEventPrice);
  5. $('#productfamily_priceWithTax').change(lcTaxPriceEventPriceWithTax);
  6. }
  7. function lcTaxPriceInit() {
  8. lcTaxPriceUpdate('priceWithTax') ;
  9. $('#productfamily_price').val(parseFloat($('#productfamily_price').val()).toFixed(3));
  10. }
  11. function lcTaxPriceEventPrice() {
  12. lcTaxPriceUpdate('priceWithTax') ;
  13. }
  14. function lcTaxPriceEventPriceWithTax() {
  15. lcTaxPriceUpdate('price') ;
  16. }
  17. function lcTaxGetTaxRate() {
  18. taxRate = $('#productfamily_taxRate').find('option:selected').data('tax-rate-value');
  19. if(typeof taxRate == 'undefined') {
  20. taxRate = 0 ;
  21. }
  22. return taxRate ;
  23. }
  24. function lcTaxPriceUpdate(priceType) {
  25. var taxRate = lcTaxGetTaxRate() ;
  26. if(priceType == 'priceWithTax') {
  27. $('#productfamily_priceWithTax').val(getPriceWithTax($('#productfamily_price').val(), taxRate));
  28. }
  29. else {
  30. $('#productfamily_price').val(getPrice($('#productfamily_priceWithTax').val(), taxRate));
  31. }
  32. }*/
  33. /* CKEditor */
  34. function initLcCkEditor(){
  35. var elements = $( '.lc-ckeditor' );
  36. for ( var i = 0; i < elements.length; ++i ) {
  37. var editor = CKEDITOR.replace( elements[ i ], {"toolbar":[
  38. {name:"styles",items:["Format",'Bold', 'Italic', 'Underline', 'Strike',"Link","BulletedList"]},
  39. {name: 'paragraph', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] },
  40. {name: 'insert', items: [ 'Image','SpecialChar'] },
  41. {name:"document",items:["Source"]},
  42. ],
  43. "language":"fr"} );
  44. CKFinder.setupCKEditor(editor);
  45. }
  46. }
  47. /**
  48. * Retourne un prix sans taxe sur base du prix avec tax
  49. *
  50. * @param priceWithTax
  51. * @param taxRate
  52. * @returns {string}
  53. */
  54. function getPrice(priceWithTax, taxRate) {
  55. return parseFloat(parseFloat(priceWithTax) / ((taxRate/100) + 1)).toFixed(3);
  56. }
  57. /**
  58. * Retourne un prix avec taxe sur base du prix sans taxe
  59. *
  60. * @param priceWithoutTax
  61. * @param taxRate
  62. * @returns {string}
  63. */
  64. function getPriceWithTax(priceWithoutTax, taxRate) {
  65. return parseFloat(parseFloat(priceWithoutTax) * ((taxRate/100) + 1)).toFixed(2);
  66. }
  67. /**
  68. * Formate un prix en l'arrondissant et en ajoutant le sigle de la monnaie
  69. *
  70. * @param price
  71. * @returns {string}
  72. */
  73. function formatPrice(price) {
  74. return Number(price).toFixed(2).replace('.', ',') + ' €';
  75. }
  76. /**
  77. * Formate une date au format jj/mm/yyyy
  78. * @param date
  79. * @returns {*}
  80. */
  81. function formatDate(date) {
  82. if (date) {
  83. return ('0' + date.getDate()).slice(-2) + '/' + ('0' + (date.getMonth() + 1)).slice(-2) + '/' + date.getFullYear();
  84. }
  85. return false;
  86. }
  87. /**
  88. * Equivalent de console.log (ne déclenche pas d'erreur si la console est fermé)
  89. *
  90. * @param msg
  91. */
  92. function log(msg) {
  93. try {
  94. console.log(msg);
  95. } catch (e) {
  96. }
  97. }
  98. /**
  99. * Convertit un formulaire ou un objet en JSON (utilisé pour l'envoie de donnée en ajax)
  100. */
  101. $.fn.serializeObject = function () {
  102. var o = {};
  103. var a = this.serializeArray();
  104. $.each(a, function () {
  105. if (o[this.name] !== undefined) {
  106. if (!o[this.name].push) {
  107. o[this.name] = [o[this.name]];
  108. }
  109. o[this.name].push(this.value || '');
  110. } else {
  111. o[this.name] = this.value || '';
  112. }
  113. });
  114. return o;
  115. };
  116. function getDateFormatted(date, separator) {
  117. if(date) {
  118. var date = new Date(date);
  119. var _d = date.getDate(),
  120. d = _d > 9 ? _d : '0' + _d,
  121. _m = date.getMonth() + 1,
  122. m = _m > 9 ? _m : '0' + _m,
  123. formatted = d + separator + m + separator + date.getFullYear();
  124. return formatted;
  125. }else{
  126. return '';
  127. }
  128. }
  129. //Affiche une alert au click sur un bouton submit lorsqu'un utilisateur admin tente de modifer un établissement
  130. function userNotAllowToEdit() {
  131. alert('Vous n\'êtes pas autorisé à effectuer cette action');
  132. return false;
  133. }
  134. function generateNotice(type, text) {
  135. toastr.options.timeOut = 30000;
  136. toastr[type](text);
  137. /*var n = noty({
  138. text: text,
  139. type: type,
  140. dismissQueue: true,
  141. layout: 'topRight',
  142. closeWith: ['click'],
  143. autoHide: true,
  144. clickToHide: false,
  145. autoHideDelay: 50,
  146. maxVisible: 10,
  147. animation: {
  148. open: 'animated bounceInDown',
  149. close: 'animated bounceOutDown',
  150. easing: 'swing',
  151. speed: 500
  152. }
  153. });*/
  154. }