Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

431 lines
14KB

  1. jQuery(document).ready(function () {
  2. custom_switch_merchants();
  3. initAdminLtePlugin();
  4. initButtonConfirm()
  5. initNotice();
  6. initBtnEditReminder();
  7. initBtnWriteToUser();
  8. initCollectionWidget();
  9. initBtnShowTotalOrderProduct();
  10. $('form').on('focus', 'input[type=number]', function (e) {
  11. $(this).on('wheel.disableScroll', function (e) {
  12. e.preventDefault()
  13. })
  14. })
  15. $('form').on('blur', 'input[type=number]', function (e) {
  16. $(this).off('wheel.disableScroll')
  17. })
  18. });
  19. function initNotice() {
  20. $('#lc-flash-messages .notice').each(function (i, notice) {
  21. generateNotice($(notice).find('.type').html(), $(notice).find('.message').html());
  22. });
  23. $('#lc-flash-alert .modal').each(function (i, modal) {
  24. $(modal).modal('show');
  25. });
  26. }
  27. function initButtonConfirm() {
  28. $('.btn-confirm-js, .action-confirm').click(function () {
  29. return confirm('Êtes-vous sûr de vouloir réaliser cette action ?');
  30. });
  31. }
  32. function initLcNoty() {
  33. $('.lc-noty').each(function () {
  34. generateNotice($(this).data('type'), $(this).html());
  35. });
  36. }
  37. function custom_switch_merchants() {
  38. $('#switch-merchant').on('change', function () {
  39. $('#switch-merchant').parents('form').submit();
  40. });
  41. }
  42. function setBootstrapSwitch($checkbox) {
  43. $checkbox.bootstrapSwitch();
  44. $checkbox.bootstrapSwitch('state', true);
  45. $checkbox.on('switchChange.bootstrapSwitch', function (e, state) {
  46. var event = new Event('change');
  47. e.target.dispatchEvent(event);
  48. });
  49. }
  50. function initAdminLtePlugin() {
  51. /*$(".checkbox-switch input").each(function () {
  52. setBootstrapSwitch($(this));
  53. });*/
  54. $('[data-toggle="tooltip"]').tooltip();
  55. $(document).on('keypress', function (event) {
  56. /*if(event.keyCode == '13') {
  57. checkForm();
  58. }*/
  59. });
  60. $('form button[type="submit"]').on('click', function (e) {
  61. checkForm();
  62. })
  63. if ($('.select2, select.form-control').length) {
  64. $('form .form-widget>select.form-control, .select2').each(function (i, elm) {
  65. if (!$(this).hasClass('disable-select2')) {
  66. setSelect2($(elm));
  67. }
  68. });
  69. $('form .form-inline>select.form-control').each(function (i, elm) {
  70. if (!$(this).hasClass('disable-select2')) {
  71. setSelect2($(elm));
  72. }
  73. });
  74. }
  75. $('.autoresize textarea').each(function () {
  76. this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
  77. }).on('input', function () {
  78. log(this.scrollHeight);
  79. $(this).height('auto');
  80. log('BLOP' + this.scrollHeight);
  81. if (this.scrollHeight < 50) {
  82. $(this).outerHeight(this.scrollHeight - 12);
  83. } else {
  84. $(this).outerHeight(this.scrollHeight);
  85. }
  86. });
  87. $('.date-time-range, .date-range').each(function (i, picker) {
  88. options = {
  89. autoUpdateInput: false,
  90. locale: {
  91. "format": "DD/MM/YY",
  92. "separator": " - ",
  93. "applyLabel": "Appliquer",
  94. "cancelLabel": "Annuler",
  95. "fromLabel": "Du",
  96. "toLabel": "au",
  97. "customRangeLabel": "Custom",
  98. "daysOfWeek": ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
  99. "monthNames": ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Decembre"],
  100. "firstDay": 1
  101. }
  102. };
  103. if ($(picker).hasClass('date-time-range')){
  104. options = Object.assign(options, {
  105. timePicker: true,
  106. timePickerIncrement: 30,
  107. timePicker24Hour: true,
  108. locale: {
  109. "format": "DD/MM/YYYY HH:mm",
  110. }
  111. });
  112. }
  113. if ($(picker).nextAll('.date-time-range-fields').find('.date-start').val()) {
  114. options.startDate = new Date($(picker).nextAll('.date-time-range-fields').find('.date-start').val());
  115. options.autoUpdateInput = true;
  116. }
  117. if ($(picker).nextAll('.date-time-range-fields').find('.date-end').val()) {
  118. options.endDate = new Date($(picker).nextAll('.date-time-range-fields').find('.date-end').val());
  119. options.autoUpdateInput = true;
  120. }
  121. $(picker).daterangepicker(options);
  122. $(picker).on('apply.daterangepicker', function (ev, pickerElm) {
  123. if ($(picker).hasClass('date-time-range')) {
  124. $(this).val(pickerElm.startDate.format('DD/MM/YY HH:mm') + ' - ' + pickerElm.endDate.format(options.locale.format));
  125. }else{
  126. $(this).val(pickerElm.startDate.format('DD/MM/YY') + ' - ' + pickerElm.endDate.format(options.locale.format));
  127. }
  128. if ($(picker).hasClass('date-time-range')) {
  129. $(picker).nextAll('.date-time-range-fields').find('.date-start').val(pickerElm.startDate.format('YYYY-MM-DD HH:mm'));
  130. $(picker).nextAll('.date-time-range-fields').find('.date-end').val(pickerElm.endDate.format('YYYY-MM-DD HH:mm'));
  131. }else{
  132. $(picker).nextAll('.date-time-range-fields').find('.date-start').val(pickerElm.startDate.format('YYYY-MM-DD'));
  133. $(picker).nextAll('.date-time-range-fields').find('.date-end').val(pickerElm.endDate.format('YYYY-MM-DD'));
  134. }
  135. });
  136. });
  137. $(document).on('click', '[data-toggle="lightbox"]', function(event) {
  138. event.preventDefault();
  139. $(this).ekkoLightbox();
  140. });
  141. }
  142. function moment() {
  143. return '2020-04-08';
  144. }
  145. function checkForm() {
  146. $('form').addClass('form-sent');
  147. //Panel vues js
  148. if ($('form').find('.panel').length) {
  149. $('form').find('.panel').each(function (i, panel) {
  150. if ($(panel).find(':invalid').length) {
  151. $('#nav-params').find('.nav-item:eq(' + i + ')').addClass('has-invalid');
  152. } else {
  153. $('#nav-params').find('.nav-item:eq(' + i + ')').removeClass('has-invalid');
  154. }
  155. })
  156. }
  157. }
  158. function setSelect2($select) {
  159. if (typeof $select.data('select2-id') === 'undefined') {
  160. $select.data('init', 'set')
  161. var options = {
  162. width: "100%",
  163. theme: "bootstrap",
  164. dropdownAutoWidth: false,
  165. allowClear: true,
  166. minimumResultsForSearch: 8
  167. };
  168. if ($select.data('allow-clear') == 'false') {
  169. options.allowClear = false;
  170. }
  171. if ($select.data('width')) {
  172. options.width = 'auto'
  173. }
  174. if ($select.find('option[value=""]')) {
  175. options.placeholder = $select.find('option[value=""]').html()
  176. }
  177. /*if($select.is(':required') == false) {
  178. options.allowclear = true
  179. }*/
  180. myselect = $select.select2(options);
  181. myselect.on('select2:select', function (e) {
  182. var event = new Event('change');
  183. e.target.dispatchEvent(event);
  184. });
  185. myselect.on('select2:unselect', function (e) {
  186. var event = new Event('change');
  187. e.target.dispatchEvent(event);
  188. });
  189. return myselect;
  190. }
  191. }
  192. function initBtnEditReminder() {
  193. $('.btn-edit-reminder, .btn-add-reminder ').on('click', function () {
  194. $btn = $(this);
  195. var url = $(this).data('url');
  196. $('#modal-reminder').remove();
  197. $.ajax({
  198. url: url,
  199. method: "POST",
  200. dataType: "json",
  201. success: function (response) {
  202. $('body').append(response.data);
  203. if ($btn.hasClass('btn-add-reminder')) {
  204. $('#reminder_entityName').val(getUrlParameter('entity'));
  205. $('#reminder_entityId').val(getUrlParameter('id'));
  206. $('#reminder_entityAction').val(getUrlParameter('action'));
  207. }
  208. $('#modal-reminder').modal('show');
  209. initReminderModal(url);
  210. }
  211. });
  212. });
  213. $('.checkbox-valid-reminder').on('change', function () {
  214. var url = $(this).data('url');
  215. if ($(this).is(':checked')) {
  216. url = url + '&done=true'
  217. } else {
  218. url = url + '&done=false'
  219. }
  220. $.ajax({
  221. url: url,
  222. method: "POST",
  223. dataType: "json",
  224. success: function (response) {
  225. setFlashMessages(response.flashMessages);
  226. }
  227. });
  228. });
  229. }
  230. function initReminderModal(url) {
  231. setSelect2($('#reminderForm').find('select.form-control'));
  232. $('#modal-reminder .btn-save').on('click', function () {
  233. $('#modal-reminder').modal('hide');
  234. $.ajax({
  235. url: url,
  236. data: $('#reminderForm').serialize(),
  237. method: "POST",
  238. dataType: "json",
  239. success: function (response) {
  240. setFlashMessages(response.flashMessages);
  241. $('#modal-reminder').remove();
  242. }
  243. });
  244. });
  245. }
  246. function initBtnWriteToUser(){
  247. $('#btn-ticket-write-to-user').on('click', function () {
  248. $btn = $(this);
  249. var order = '';
  250. if($btn.data('order')) {
  251. order = '&orderId=' + $btn.data('order');
  252. }
  253. $.ajax({
  254. url: $btn.data('url'),
  255. data: "user="+$btn.data('user')+order,
  256. method: "POST",
  257. dataType: "json",
  258. success: function (response) {
  259. $('body').append(response.modal);
  260. initModalNewTicket();
  261. }
  262. });
  263. });
  264. }
  265. function initModalNewTicket(){
  266. $('#modal-new-ticket select.form-control').each(function (i, elm) {
  267. if (!$(this).hasClass('disable-select2')) {
  268. setSelect2($(elm));
  269. }
  270. });
  271. $('#modal-new-ticket').modal('show');
  272. log($('#modal-new-ticket .btn-save'));
  273. $('#modal-new-ticket .btn-save').on('click', function (){
  274. $form = $(this).parents('form');
  275. if(checkFormValidity('#'+$form.prop('id'))) {
  276. $('#modal-new-ticket').modal('hide');
  277. $.ajax({
  278. url: $form.prop('action'),
  279. data: $form.serialize(),
  280. method: $form.prop('method'),
  281. dataType: "json",
  282. success: function (response) {
  283. setFlashMessages(response.flashMessages);
  284. $('#modal-new-ticket').remove();
  285. }
  286. });
  287. }
  288. })
  289. }
  290. function initCollectionWidget(){
  291. $('.form-widget-compound>div[data-prototype]').each(function (i,collectionWidget){
  292. resetNumItemsCollectionField($(collectionWidget));
  293. $(collectionWidget).on('easyadmin.collection.item-added', function (){
  294. resetNumItemsCollectionField($(this));
  295. })
  296. });
  297. }
  298. function resetNumItemsCollectionField($collectionWidget){
  299. numItems = $collectionWidget.children('div.form-group').length;
  300. $collectionWidget.children('div.form-group').each(function (i,item){
  301. $field = $(item).find('input[type="text"]');
  302. //Chanegment ID
  303. posId = $field.prop('id').lastIndexOf('_') + 1;
  304. idPrefix = $field.prop('id').substr(0, posId);
  305. $field.prop('id', idPrefix+i);
  306. //Chanegment Name
  307. posName = $field.prop('name').lastIndexOf('[') + 1;
  308. namePrefix = $field.prop('name').substr(0, posName);
  309. $field.prop('name', namePrefix+i+']');
  310. $(item).find('.field-collection-item-action').remove();
  311. $(item).find('.field-collection-item-row').append('<button style="border:0px; background: none; " class="field-collection-item-action field-collection-item-remove" type="button">&times;</button>');
  312. });
  313. $collectionWidget.find('.field-collection-item-remove').off('click');
  314. $collectionWidget.find('.field-collection-item-remove').on('click', function (){
  315. $(this).parents('.form-group:first').remove();
  316. resetNumItemsCollectionField($collectionWidget);
  317. });
  318. }
  319. function initBtnShowTotalOrderProduct(){
  320. $('.lc-show-products-sales-statistic').unbind('click').on('click', function (){
  321. $btn = $(this);
  322. var url = $(this).data('url');
  323. $('#modal-products-sales-statistic').remove();
  324. $.ajax({
  325. url: url,
  326. method: "POST",
  327. dataType: "json",
  328. success: function (response) {
  329. $('body').append(response.data);
  330. $('#modal-products-sales-statistic').modal('show');
  331. initModalProductsSalesStatistic(response.statistics);
  332. }
  333. });
  334. });
  335. }
  336. function initModalProductsSalesStatistic(statistics) {
  337. var chart = null;
  338. $('.btn-products-sales-statistic').off('click');
  339. $('.btn-products-sales-statistic').on('click', function () {
  340. $('.table-products-sales-statistic').hide();
  341. $('.btn-products-sales-statistic').addClass('btn-secondary').removeClass('btn-primary');
  342. $(this).removeClass('btn-secondary').addClass('btn-primary');
  343. $('#table-products-sales-statistic-'+$(this).data('property-name')).show()
  344. if (chart) chart.destroy();
  345. $(this).removeClass('btn-secondary');
  346. chart = drawProductsSalesStatistic(statistics,$(this).data('property-name'))
  347. });
  348. $('.btn-products-sales-statistic').first().click();
  349. }
  350. function drawProductsSalesStatistic(statictics, propertyName) {
  351. var options = {
  352. bezierCurve : false,
  353. tooltips: {
  354. callbacks: {
  355. label: (item) => item.yLabel ,
  356. },
  357. },
  358. };
  359. chart = new Chart(document.getElementById("chart"), {
  360. "type": "line",
  361. "data": {
  362. "labels": Object.values(statictics.label),
  363. "datasets": [{
  364. "label": "Vente de produits / semaine",
  365. "data": Object.values(statictics.data[propertyName].data),
  366. "fill": false,
  367. "borderColor": "rgb(75, 192, 192)",
  368. "lineTension": 0.1
  369. }]
  370. },
  371. "options": options
  372. });
  373. return chart;
  374. }