main.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //CHARGEMENT DE LA PAGE
  2. function init_plugin_subscribe(){
  3. switch($.urlParam('page')){
  4. default:
  5. $('#subscribe-form.subscribe-disable-paste input[type="mail"]').on('cut copy paste', function(e){
  6. e.preventDefault();
  7. return false;
  8. })
  9. break;
  10. }
  11. subscribe_search();
  12. }
  13. //Enregistrement des configurations
  14. function subscribe_setting_save(){
  15. $.action({
  16. action: 'subscribe_setting_save',
  17. fields: $('#subscribe-setting-form').toJson()
  18. },function(){
  19. $.message('success','Enregistré');
  20. });
  21. }
  22. /** SUBSCRIBE **/
  23. //Permet de renouveler le captcha
  24. function subscribe_reload_captcha(element){
  25. if(isProcessing) return;
  26. var button = $(element);
  27. isProcessing = true;
  28. $('i', button).addClass('fa-spin');
  29. setTimeout(function(){
  30. var form = $('#subscribe-form');
  31. $('.subscribe-captcha-container').load(document.URL + ' .subscribe-captcha-container>*');
  32. $('i', button).removeClass('fa-spin');
  33. isProcessing = false;
  34. }, 1000);
  35. }
  36. function subscribe_password_update(element){
  37. var input = $(element);
  38. $('.subscribe-password-rules').attr({
  39. 'data-parameters' : JSON.stringify({password:input.val()})
  40. });
  41. }
  42. //Récuperation d'une liste de dans le tableau #s
  43. function subscribe_search(callback){
  44. $('#s').fill({
  45. action:'subscribe_search'
  46. },function(response){
  47. if(callback!=null) callback();
  48. });
  49. }
  50. //Ajout ou modification d'élément
  51. function subscribe_save(){
  52. var form = $('#subscribe-form')
  53. var data = form.toJson();
  54. data.captcha = $('.form-anti-robot').val();
  55. $('.btn-success', form).addClass('btn-preloader');
  56. $.action(data,function(r){
  57. var validation = $('.subscribe-validation');
  58. if(r.login!=null) $('code',validation).text(r.login);
  59. form.addClass('hidden');
  60. validation.removeClass('hidden');
  61. setTimeout(function(){
  62. validation.addClass('go-in')
  63. $('> img', validation).addClass('animate');
  64. },200);
  65. });
  66. }
  67. //Suppression d'élement
  68. function subscribe_delete(element){
  69. if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
  70. var line = $(element).closest('tr');
  71. $.action({
  72. action: 'subscribe_delete',
  73. id: line.attr('data-id')
  74. },function(r){
  75. line.remove();
  76. $.message('info','Item supprimé');
  77. });
  78. }