Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

770 lines
28KB

  1. $(document).ready(function() {
  2. chat_calendar() ;
  3. chat_datepicker() ;
  4. chat_vrac() ;
  5. chat_email_masse() ;
  6. $('button[data-toggle=popover]').popover() ;
  7. chat_ordre_produits() ;
  8. chat_index_commandes_liste_produits() ;
  9. chat_index_commandes_points_vente() ;
  10. chat_index_commandes_points_vente_livraison() ;
  11. chat_btn_plus_moins() ;
  12. chat_commandeauto() ;
  13. chat_points_vente_acces() ;
  14. chat_tooltip() ;
  15. chat_points_vente_jours_livraison() ;
  16. chat_index_commandes_maj_points_vente() ;
  17. // admin
  18. chat_select_etablissement() ;
  19. }) ;
  20. function chat_tooltip() {
  21. $('[data-toggle="tooltip"]').tooltip();
  22. }
  23. function chat_nl2br(str, is_xhtml) {
  24. var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
  25. return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
  26. }
  27. function chat_index_commandes_points_vente_livraison() {
  28. $('#productionpointvente-productions_point_vente input[type=checkbox]').change(function() {
  29. var nb = $('#productionpointvente-productions_point_vente input[type=checkbox]:checked').size() ;
  30. if(nb == 0) {
  31. $(this).prop('checked',true) ;
  32. chat_alert('danger','Vous devez avoir au moins un point de vente activé') ;
  33. }
  34. else {
  35. var val = $(this).val() ;
  36. var arr_val = val.split('-') ;
  37. var livraison = 0 ;
  38. if($(this).prop('checked'))
  39. livraison = 1 ;
  40. $.get('index.php',{
  41. r: 'commande/ajax-point-vente-livraison',
  42. id_production: arr_val[0],
  43. id_point_vente: arr_val[1],
  44. bool_livraison: livraison
  45. }, function(data) {
  46. chat_alert('success','Point de vente modifié') ;
  47. }) ;
  48. chat_index_commandes_maj_points_vente() ;
  49. }
  50. }) ;
  51. }
  52. function chat_index_commandes_maj_points_vente() {
  53. if($('#productions-point-vente').size()) {
  54. var nb = $('#productionpointvente-productions_point_vente input[type=checkbox]:checked').size() ;
  55. if(nb == 0)
  56. {
  57. $('#panel-commandes #tabs-points-vente, #panel-commandes #commandes-points-vente').hide() ;
  58. $('#panel-commandes .alert-danger').show();
  59. }
  60. else {
  61. $('#panel-commandes #tabs-points-vente, #panel-commandes #commandes-points-vente').show() ;
  62. $('#panel-commandes .alert-danger').hide();
  63. }
  64. }
  65. var id_production = $('#id-production').val() ;
  66. if(id_production) {
  67. $('#tabs-points-vente li').each(function() {
  68. var id_point_vente = $(this).find('a').attr('id').replace('btn-point-vente-','') ;
  69. var nb_commandes = parseInt($(this).find('.badge-success').html()) ;
  70. var checked = $('#productionpointvente-productions_point_vente input[value='+id_production+'-'+id_point_vente+']').prop('checked') ;
  71. if(checked || nb_commandes > 0)
  72. {
  73. $(this).show() ;
  74. }
  75. else {
  76. $(this).hide() ;
  77. }
  78. }) ;
  79. $('#tabs-points-vente li:visible:first a').click() ;
  80. }
  81. }
  82. function chat_points_vente_jours_livraison() {
  83. $('#pointvente-point_fabrication').change(function() {
  84. chat_points_vente_jours_livraison_event() ;
  85. }) ;
  86. chat_points_vente_jours_livraison_event();
  87. }
  88. function chat_points_vente_jours_livraison_event() {
  89. if($('#pointvente-point_fabrication').prop('checked')) {
  90. $('#jours-livraison').hide() ;
  91. }
  92. else {
  93. $('#jours-livraison').fadeIn() ;
  94. }
  95. }
  96. function chat_points_vente_acces() {
  97. // affichage du bloc acces restreint
  98. $('#pointvente-acces_restreint').change(function() {
  99. chat_points_vente_acces_event() ;
  100. }) ;
  101. chat_points_vente_acces_event() ;
  102. // affichage du champs commentaire
  103. $('#pointvente-users input[type=checkbox]').change(function() {
  104. chat_points_vente_commentaire_event() ;
  105. }) ;
  106. chat_points_vente_commentaire_event() ;
  107. }
  108. function chat_points_vente_commentaire_event() {
  109. $('#pointvente-users input[type=checkbox]').each(function() {
  110. if($(this).prop('checked')) {
  111. $(this).parent().find('.commentaire').fadeIn() ;
  112. }
  113. else {
  114. $(this).parent().find('.commentaire').hide() ;
  115. }
  116. }) ;
  117. }
  118. function chat_points_vente_acces_event() {
  119. if($('#pointvente-acces_restreint').prop('checked')) {
  120. $('#pointvente-users').fadeIn() ;
  121. }
  122. else {
  123. $('#pointvente-users').hide() ;
  124. }
  125. }
  126. function chat_select_etablissement() {
  127. $('select[name="select_etablissement"]').change(function() {
  128. window.location.href = 'index.php?r=site/change-etablissement&id='+$(this).val() ;
  129. }) ;
  130. }
  131. function chat_commandeauto() {
  132. // dates
  133. $('#commandeautoform-date_debut, #commandeautoform-date_fin').datepicker() ;
  134. }
  135. function chat_index_commandes_points_vente() {
  136. $('#commandes-points-vente .liste-commandes a').unbind('click').click(function() {
  137. var id_pv = $(this).data('pv-id') ;
  138. // affiche la commande
  139. var id_commande = $(this).data('id-commande') ;
  140. chat_index_commandes_affiche_commande(id_pv, id_commande) ;
  141. }) ;
  142. $('#commandes-points-vente .bloc-point-vente').each(function() {
  143. var id_pv = $(this).data('id-pv') ;
  144. // edit
  145. $('#point-vente-'+id_pv+' .btn-edit').unbind('click').click(function() {
  146. // boutons
  147. $('#point-vente-'+id_pv+' .buttons-edit-remove').hide() ;
  148. $('#point-vente-'+id_pv+' .buttons-save-cancel').show() ;
  149. $('#point-vente-'+id_pv+' .tr-total').hide() ;
  150. // inputs
  151. chat_index_commandes_inputs_commande(id_pv, true) ;
  152. }) ;
  153. // remove
  154. $('#point-vente-'+id_pv+' .btn-remove').unbind('click').click(function() {
  155. var id_commande = $(this).data('id-commande') ;
  156. $(this).attr('disabled', 'disabled') ;
  157. $.get('index.php',{
  158. r: 'commande/ajax-delete',
  159. date: $('#date-production').val(),
  160. id_commande: id_commande
  161. }, function(data) {
  162. $('#point-vente-'+id_pv+' .btn-remove').removeAttr('disabled') ;
  163. if($('#point-vente-'+id_pv+' .liste-commandes li').size()) {
  164. if($('#point-vente-'+id_pv+' .liste-commandes li:last-child a').is('.active')) {
  165. var commande_next = $('#point-vente-'+id_pv+' .liste-commandes a.active').parent().prev().find('a') ;
  166. }
  167. else {
  168. var commande_next = $('#point-vente-'+id_pv+' .liste-commandes a.active').parent().next().find('a') ;
  169. }
  170. $('#point-vente-'+id_pv+' .liste-commandes a.active').parent().remove() ;
  171. if($('#point-vente-'+id_pv+' .liste-commandes li').size()) {
  172. chat_index_commandes_affiche_commande(id_pv, commande_next.data('id-commande')) ;
  173. }
  174. else {
  175. $('#point-vente-'+id_pv+' .liste-commandes').hide() ;
  176. $('#point-vente-'+id_pv+' .creer-commande').trigger('click') ;
  177. }
  178. }
  179. chat_index_commandes_maj_recap_pv(id_pv, data.total_pv) ;
  180. chat_index_commandes_maj_total_commandes() ;
  181. chat_alert('success','Commande supprimée') ;
  182. }, 'json') ;
  183. });
  184. // cancel
  185. $('#point-vente-'+id_pv+' .btn-cancel').unbind('click').click(function() {
  186. $('#point-vente-'+id_pv+' .buttons-edit-remove').show() ;
  187. $('#point-vente-'+id_pv+' .buttons-save-cancel').hide() ;
  188. $('#point-vente-'+id_pv+' .btn-save').removeClass('is-create') ;
  189. chat_index_commandes_affiche_commande(id_pv, $(this).data('id-commande')) ;
  190. }) ;
  191. // save
  192. $('#point-vente-'+id_pv+' .btn-save').unbind('click').click(function() {
  193. var tab_produits = {} ;
  194. var cpt_produits = 0 ;
  195. $('#point-vente-'+id_pv+' .table-produits tr').each(function() {
  196. tab_produits[$(this).data('id-produit')] = $(this).find('.quantite').val() ;
  197. if($(this).find('.quantite').val())
  198. cpt_produits ++ ;
  199. }) ;
  200. if(cpt_produits) {
  201. // création
  202. if($(this).hasClass('is-create')) {
  203. if($('#point-vente-'+id_pv+' .user-id').val() || $('#point-vente-'+id_pv+' .username').val().length) {
  204. $(this).attr('disabled', 'disabled') ;
  205. $.get('index.php',{
  206. r: 'commande/ajax-create',
  207. date: $('#date-production').val(),
  208. id_pv: id_pv,
  209. id_user: $('#point-vente-'+id_pv+' .user-id').val(),
  210. username: $('#point-vente-'+id_pv+' .username').val(),
  211. produits: JSON.stringify(tab_produits),
  212. commentaire: $('#point-vente-'+id_pv+' .textarea-commentaire').val()
  213. }, function(data) {
  214. $('#point-vente-'+id_pv+' .btn-save').removeAttr('disabled') ;
  215. $('#point-vente-'+id_pv+' .btn-save').removeClass('is-create') ;
  216. $('#point-vente-'+id_pv+' .liste-commandes').append(data.commande) ;
  217. chat_index_commandes_points_vente() ;
  218. chat_index_commandes_maj_recap_pv(id_pv, data.total_pv) ;
  219. $('#point-vente-'+id_pv+' .buttons-edit-remove').show() ;
  220. $('#point-vente-'+id_pv+' .buttons-save-cancel').hide() ;
  221. $('#point-vente-'+id_pv+' .btn-create').removeClass('is-create') ;
  222. $('#point-vente-'+id_pv+' .user-id').val(0) ;
  223. $('#point-vente-'+id_pv+' .user-id').val('') ;
  224. chat_index_commandes_affiche_commande(id_pv, data.id_commande) ;
  225. chat_alert('success', 'Commande créée') ;
  226. }, 'json') ;
  227. }
  228. else {
  229. chat_alert('danger', 'Veuillez choisir ou saisir un nom d\'utilisateur') ;
  230. }
  231. }
  232. // modification
  233. else {
  234. var id_commande = $(this).data('id-commande') ;
  235. $(this).attr('disabled', 'disabled') ;
  236. $.get('index.php',{
  237. r: 'commande/ajax-update',
  238. id_commande: id_commande,
  239. produits: JSON.stringify(tab_produits),
  240. date: $('#date-production').val(),
  241. commentaire: $('#point-vente-'+id_pv+' .textarea-commentaire').val()
  242. }, function(data) {
  243. $('#point-vente-'+id_pv+' .btn-save').removeAttr('disabled') ;
  244. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').attr('data-commande',data.json_commande);
  245. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html(data.json_commande.str_montant) ;
  246. chat_index_commandes_affiche_commande(id_pv, id_commande) ;
  247. chat_index_commandes_maj_recap_pv(id_pv, data.total_pv) ;
  248. $('#point-vente-'+id_pv+' .buttons-edit-remove').show() ;
  249. $('#point-vente-'+id_pv+' .buttons-save-cancel').hide() ;
  250. chat_alert('success','Commande modifiée') ;
  251. }, 'json') ;
  252. }
  253. }
  254. else {
  255. chat_alert('danger', 'Veuillez saisir au moins un produit') ;
  256. }
  257. chat_index_commandes_maj_total_commandes() ;
  258. }) ;
  259. // create
  260. $('.creer-commande').unbind('click').click(function() {
  261. var id_pv = $(this).data('pv-id') ;
  262. $('#point-vente-'+id_pv+' .bloc-commande').fadeIn() ;
  263. $('#point-vente-'+id_pv+' .liste-commandes a.active').removeClass('active') ;
  264. $('#point-vente-'+id_pv+' .tr-total').hide() ;
  265. $('#point-vente-'+id_pv+' .buttons-edit-remove').hide() ;
  266. $('#point-vente-'+id_pv+' .the-title').hide() ;
  267. $('#point-vente-'+id_pv+' .buttons-save-cancel').show() ;
  268. $('#point-vente-'+id_pv+' .choix-user').show() ;
  269. $('#point-vente-'+id_pv+' .choix-user .user-id').val(0) ;
  270. $('#point-vente-'+id_pv+' .choix-user .username').val('') ;
  271. $('#point-vente-'+id_pv+' .commentaire').hide() ;
  272. $('#point-vente-'+id_pv+' .btn-save').addClass('is-create');
  273. /*if(!$('#point-vente-'+id_pv+' .btn-cancel').data('id-commande') &&
  274. $('#point-vente-'+id_pv+' .liste-commandes li').size()) {
  275. $('#point-vente-'+id_pv+' .btn-cancel').data('id-commande',$('#point-vente-'+id_pv+' .liste-commandes li:first a').data('id-commande')) ;
  276. }*/
  277. $('#point-vente-'+id_pv+' .btn-save').data('id-commande',0) ;
  278. chat_index_commandes_inputs_commande(id_pv, false) ;
  279. $('#point-vente-'+id_pv+' .title-user').show() ;
  280. }) ;
  281. }) ;
  282. $('#commandes-points-vente .liste-commandes').each(function() {
  283. //$(this).find('a:first').trigger('click') ;
  284. }) ;
  285. }
  286. function chat_index_commandes_maj_total_commandes() {
  287. $.get('index.php',{
  288. r: 'commande/ajax-total-commandes',
  289. date: $('#date-production').val()
  290. }, function(data) {
  291. $('#bloc-totaux').html(data.html_totaux) ;
  292. }, 'json') ;
  293. }
  294. function chat_index_commandes_maj_recap_pv(id_pv, total) {
  295. $('#point-vente-'+id_pv+' .recap-pv .recettes').html(total) ;
  296. var nb_commandes = $('#point-vente-'+id_pv+' .liste-commandes li').size() ;
  297. if(nb_commandes == 0) {
  298. $('#point-vente-'+id_pv+' .recap-pv .commandes').html('Aucune commande') ;
  299. $('#point-vente-'+id_pv+' .recap-pv .recettes').hide() ;
  300. $('#point-vente-'+id_pv+' .liste-commandes').addClass('no-commande') ;
  301. }
  302. else if(nb_commandes == 1) {
  303. $('#point-vente-'+id_pv+' .recap-pv .commandes').html('1 commande') ;
  304. $('#point-vente-'+id_pv+' .recap-pv .recettes').show() ;
  305. $('#point-vente-'+id_pv+' .liste-commandes').removeClass('no-commande') ;
  306. }
  307. else {
  308. $('#point-vente-'+id_pv+' .recap-pv .commandes').html(nb_commandes+' commandes') ;
  309. $('#point-vente-'+id_pv+' .recap-pv .recettes').show() ;
  310. $('#point-vente-'+id_pv+' .liste-commandes').removeClass('no-commande') ;
  311. }
  312. $('#btn-point-vente-'+id_pv+' .badge').html(nb_commandes) ;
  313. }
  314. function chat_index_commandes_inputs_commande(id_pv, use_quantite) {
  315. // commentaire
  316. $('#point-vente-'+id_pv+' .commentaire').hide() ;
  317. $('#point-vente-'+id_pv+' .textarea-commentaire').show() ;
  318. var id_commande = $('#point-vente-'+id_pv+' .btn-save').data('id-commande') ;
  319. if(id_commande) {
  320. var link = $('a[data-id-commande='+id_commande+']') ;
  321. if(!$.isPlainObject(link.attr('data-commande'))) {
  322. var commande = JSON.parse(link.attr('data-commande')) ;
  323. if(commande.commentaire && commande.commentaire.length)
  324. $('#point-vente-'+id_pv+' .textarea-commentaire').val(commande.commentaire) ;
  325. }
  326. }
  327. else {
  328. $('#point-vente-'+id_pv+' .textarea-commentaire').val('') ;
  329. }
  330. // produits
  331. $('#point-vente-'+id_pv+' .table-produits tr').each(function() {
  332. var quantite = '' ;
  333. if(use_quantite)
  334. quantite = $(this).find('.td-commande').html() ;
  335. var id_produit = $(this).data('id-produit') ;
  336. $(this).find('.td-commande').html('<div class="input-group">'+
  337. '<span class="input-group-btn">'+
  338. '<button class="btn btn-default btn-moins" type="button"><span class="glyphicon glyphicon-minus"></span></button>'+
  339. '</span>'+
  340. '<input type="text" class="form-control quantite" value="'+quantite+'" name="produit_'+id_produit+'">'+
  341. '<span class="input-group-btn">'+
  342. '<button class="btn btn-default btn-plus" type="button"><span class="glyphicon glyphicon-plus"></span></button>'+
  343. '</span>'+
  344. '</div>') ;
  345. }) ;
  346. // plus / moins
  347. chat_btn_plus_moins() ;
  348. }
  349. function chat_btn_plus_moins() {
  350. $('.btn-plus').each(function() {
  351. $(this).click(function() {
  352. var input = $(this).parent().parent().find('input') ;
  353. var value = input.val() ;
  354. if(value)
  355. value ++ ;
  356. else
  357. value = 1 ;
  358. input.val(value) ;
  359. }) ;
  360. }) ;
  361. $('.btn-moins').each(function() {
  362. $(this).click(function() {
  363. var input = $(this).parent().parent().find('input') ;
  364. var value = input.val() ;
  365. if(value && value > 1)
  366. value -- ;
  367. else
  368. value = '' ;
  369. input.val(value) ;
  370. }) ;
  371. }) ;
  372. }
  373. function chat_index_commandes_affiche_commande(id_pv, id_commande) {
  374. var link = $("a[data-id-commande="+id_commande+"]") ;
  375. if(id_commande) {
  376. $('#point-vente-'+id_pv+' .bloc-commande').hide() ;
  377. $('#point-vente-'+id_pv+' .liste-commandes a').removeClass('active') ;
  378. link.addClass('active') ;
  379. var commande = link.attr('data-commande') ;
  380. if(!$.isPlainObject(link.attr('data-commande'))) {
  381. commande = JSON.parse(link.attr('data-commande')) ;
  382. }
  383. // maj ligne commande
  384. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').removeClass('paye') ;
  385. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant .glyphicon').remove() ;
  386. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html() ;
  387. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html(commande.str_montant) ;
  388. if(commande.montant_paye >= commande.montant) {
  389. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').addClass('paye') ;
  390. if(commande.montant_paye > commande.montant) {
  391. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').append(' <span class="glyphicon glyphicon-warning-sign"></span>') ;
  392. }
  393. }
  394. // commentaire
  395. if(commande.commentaire && commande.commentaire.length) {
  396. if(!$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .glyphicon-comment').size()) {
  397. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').append(' <span class="glyphicon glyphicon-comment"></span>') ;
  398. }
  399. console.log(id_pv+' '+commande.commentaire) ;
  400. $('#point-vente-'+id_pv+' .commentaire').html(chat_nl2br(commande.commentaire)).show() ;
  401. }
  402. else {
  403. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .glyphicon-comment').remove() ;
  404. $('#point-vente-'+id_pv+' .commentaire').hide() ;
  405. }
  406. // set id_commande
  407. $('#point-vente-'+id_pv+' .btn-cancel').data('id-commande',id_commande) ;
  408. $('#point-vente-'+id_pv+' .btn-save').data('id-commande',id_commande) ;
  409. $('#point-vente-'+id_pv+' .btn-remove').data('id-commande',id_commande) ;
  410. $('#point-vente-'+id_pv+' .btn-create').removeClass('is-create') ;
  411. $('#point-vente-'+id_pv+' .buttons-edit-remove').show() ;
  412. $('#point-vente-'+id_pv+' .buttons-save-cancel').hide() ;
  413. $('#point-vente-'+id_pv+' .choix-user').hide() ;
  414. $('#point-vente-'+id_pv+' .the-title').show() ;
  415. $('#point-vente-'+id_pv+' .textarea-commentaire').hide() ;
  416. $('#point-vente-'+id_pv+' .td-commande').html('') ;
  417. $('#point-vente-'+id_pv+' .td-total').html('') ;
  418. $('#point-vente-'+id_pv+' tr').removeClass('active') ;
  419. $.each(commande.produits, function(i, item) {
  420. $('#point-vente-'+id_pv+' .produit-'+i+' .td-commande').html(item) ;
  421. $('#point-vente-'+id_pv+' .produit-'+i).addClass('active') ;
  422. }) ;
  423. $('#point-vente-'+id_pv+' .td-total').html('<span>'+commande.str_montant+'</span>') ;
  424. $('#point-vente-'+id_pv+' .tr-total').show() ;
  425. /*var commentaire = link.data('commentaire') ;
  426. if(commentaire) {
  427. $('#point-vente-'+id_pv+' .commentaire').html(commentaire).show() ;
  428. }
  429. else {
  430. $('#point-vente-'+id_pv+' .commentaire').hide() ;
  431. }*/
  432. $('#point-vente-'+id_pv+' .title-user span.the-title').html(link.find('.user').html()+" <small>"+link.data('date')+"</small>") ;
  433. $('#point-vente-'+id_pv+' .bloc-commande').fadeIn() ;
  434. $('#point-vente-'+id_pv+' .title-user').show() ;
  435. $('#point-vente-'+id_pv+' .tr-total').show() ;
  436. // paiement
  437. $.get('index.php',{
  438. r: 'commande/statut-paiement',
  439. id_commande: id_commande
  440. }, function(data) {
  441. $('#point-vente-'+id_pv+' .bloc-commande .td-paiement').html(data.html_statut_paiement) ;
  442. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').attr('data-commande',data.json_commande) ;
  443. chat_index_commandes_boutons_paiement(id_pv, id_commande) ;
  444. },'json') ;
  445. }
  446. else {
  447. $('#point-vente-'+id_pv+' .bloc-commande').hide() ;
  448. }
  449. }
  450. function chat_index_commandes_boutons_paiement(id_pv, id_commande) {
  451. // boutons paiement/remboursement
  452. $('#point-vente-'+id_pv+' .payer, #point-vente-'+id_pv+' .rembourser').click(function() {
  453. $.get('index.php',{
  454. r: 'commande/paiement',
  455. id_commande: id_commande,
  456. type: $(this).data('type'),
  457. montant: $(this).data('montant')
  458. }, function(data) {
  459. $('#point-vente-'+id_pv+' .bloc-commande .td-paiement').html(data.html_statut_paiement) ;
  460. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').attr('data-commande',data.json_commande) ;
  461. chat_index_commandes_affiche_commande(id_pv, id_commande) ;
  462. chat_index_commandes_boutons_paiement(id_pv, id_commande) ;
  463. }, 'json') ;
  464. }) ;
  465. }
  466. function chat_index_commandes_liste_produits() {
  467. $('#produits-production .td-max input').click(function() {
  468. $(this).select() ;
  469. }) ;
  470. $('#produits-production .td-actif input').change(function() {
  471. if($(this).prop('checked')) {
  472. $(this).parent().parent().addClass('active') ;
  473. }
  474. else {
  475. $(this).parent().parent().removeClass('active') ;
  476. }
  477. }) ;
  478. }
  479. function chat_alert(type, message) {
  480. var id = 'alert-'+$('#alerts-fixed .alert').size() + 1 ;
  481. $('#alerts-fixed').append('<div id="'+id+'" class="alert alert-'+type+'">'+message+'</div>') ;
  482. setTimeout('$("#'+id+'").fadeOut();',3000) ;
  483. }
  484. function chat_ordre_produits() {
  485. var fixHelper = function(e, ui) {
  486. ui.children().each(function() {
  487. $(this).width($(this).width());
  488. });
  489. return ui;
  490. };
  491. $(".produit-index table tbody").sortable({
  492. items: "> tr",
  493. appendTo: "parent",
  494. cursor: "move",
  495. placeholder: "ui-state-highlight",
  496. handle: '.btn-order',
  497. //helper: "clone"
  498. helper: fixHelper,
  499. stop: function(event, ui) {
  500. var tab_ordre = {} ;
  501. var ordre = 1 ;
  502. $(".produit-index table tbody tr").each(function() {
  503. tab_ordre[$(this).attr('data-key')] = ordre ;
  504. ordre++ ;
  505. }) ;
  506. console.log(tab_ordre) ;
  507. $.get('index.php',{
  508. r: 'produit/ordre',
  509. tab: JSON.stringify(tab_ordre)
  510. }) ;
  511. }
  512. }).disableSelection();
  513. }
  514. function chat_email_masse() {
  515. $('#ids-users .label').click(function() {
  516. if($(this).hasClass('label-default')) {
  517. $(this).removeClass('label\-default') ;
  518. $(this).addClass('label-danger') ;
  519. }
  520. else if($(this).hasClass('label-danger'))
  521. $(this).removeClass('label-danger').addClass('label-default') ;
  522. }) ;
  523. $('#email-masse-form button[type=submit]').click(function() {
  524. $(this).attr('disabled','disabled').html('Envoyer ...') ;
  525. chat_email_masse_send() ;
  526. return false ;
  527. }) ;
  528. }
  529. function chat_email_masse_send() {
  530. var user = $('#ids-users .label-default:first') ;
  531. if(user.size()) {
  532. $('input[name=id_user]').val(user.data('id')) ;
  533. $.post('index.php?r=user/mail',$('#email-masse-form').serialize(), function(retour) {
  534. user.removeClass('label-default').addClass('label-success') ;
  535. setTimeout("chat_email_masse_send()",30000) ;
  536. }) ;
  537. }
  538. else {
  539. alert('Fini !') ;
  540. }
  541. }
  542. function chat_vrac() {
  543. $('.edit-vrac').click(function() {
  544. if($('.vrac').css('display') == 'none')
  545. $('.vrac').show() ;
  546. else
  547. $('.vrac').hide() ;
  548. }) ;
  549. }
  550. function chat_datepicker() {
  551. $('.datepicker').datepicker({dateFormat:'dd/mm/yy'}) ;
  552. }
  553. function chat_calendar() {
  554. if($('#page-commande').size()) {
  555. var events = new Array ;
  556. $('ul#jours-production li').each(function() {
  557. var date = $(this).html() ;
  558. events.push({
  559. title: 'Production',
  560. start: date,
  561. allDay: true
  562. }) ;
  563. }) ;
  564. jQuery('#calendar').fullCalendar({
  565. header: {
  566. left:"prev,next",
  567. center: "title",
  568. //right:"month,agendaWeek,agendaDay"
  569. right:""
  570. },
  571. lang:"fr-fr",
  572. loading:function loading(bool) {
  573. if (bool) $('#loading').show();
  574. else $('#loading').hide();
  575. },
  576. dayClick: function(date, jsEvent, view) {
  577. var url = $(location).attr('href') ;
  578. var tab_url = url.split('?') ;
  579. $(location).attr('href',tab_url[0]+'?r=commande/index&date='+date.format());
  580. },
  581. eventRender: function (event, element) {
  582. var dataToFind = moment(event.start).format('YYYY-MM-DD');
  583. $("td[data-date='"+dataToFind+"']").addClass('dayWithEvent');
  584. },
  585. //eventBackgroundColor: '#000000',
  586. events: events,
  587. id:"calendar"
  588. });
  589. if($('#current-date').val())
  590. $('td[data-date='+$('#current-date').val()+']').addClass('current-date') ;
  591. }
  592. }
  593. /* French initialisation for the jQuery UI date picker plugin. */
  594. /* Written by Keith Wood (kbwood{at}iinet.com.au),
  595. Stéphane Nahmani (sholby@sholby.net),
  596. Stéphane Raimbault <stephane.raimbault@gmail.com> */
  597. (function( factory ) {
  598. if ( typeof define === "function" && define.amd ) {
  599. // AMD. Register as an anonymous module.
  600. define([ "../jquery.ui.datepicker" ], factory );
  601. } else {
  602. // Browser globals
  603. factory( jQuery.datepicker );
  604. }
  605. }(function( datepicker ) {
  606. datepicker.regional['fr'] = {
  607. closeText: 'Fermer',
  608. prevText: 'Précédent',
  609. nextText: 'Suivant',
  610. currentText: 'Aujourd\'hui',
  611. monthNames: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin',
  612. 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
  613. monthNamesShort: ['janv.', 'févr.', 'mars', 'avril', 'mai', 'juin',
  614. 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
  615. dayNames: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
  616. dayNamesShort: ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'],
  617. dayNamesMin: ['D','L','M','M','J','V','S'],
  618. weekHeader: 'Sem.',
  619. dateFormat: 'dd/mm/yy',
  620. firstDay: 1,
  621. isRTL: false,
  622. showMonthAfterYear: false,
  623. yearSuffix: ''};
  624. datepicker.setDefaults(datepicker.regional['fr']);
  625. return datepicker.regional['fr'];
  626. }));