reglages.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. var profils_created=0;
  14. var regs={ "title" : "", "photo":"", "profiles" : [] };
  15. var profiles_list_id=[];
  16. const authorized_profile_id="azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN-_.";
  17. const authorized_profile_label="azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN-_.";
  18. var reg_tmpid;
  19. function check_profil_id(id)
  20. {
  21. var i;
  22. if(id.length<1)
  23. {
  24. alert("Veuillez remplir le champ ID");
  25. return false;
  26. }
  27. for(i=0; i<id.length; i++)
  28. if(authorized_profile_id.indexOf(id[i])<0)
  29. {
  30. alert("Caractère '"+id[i]+"' non autorisé dans le champ ID");
  31. return false;
  32. }
  33. return true;
  34. }
  35. function check_profil_label(id)
  36. {
  37. var i;
  38. if(id.length<1)
  39. {
  40. alert("Veuillez remplir le champ Label");
  41. return false;
  42. }
  43. for(i=0; i<id.length; i++)
  44. if(authorized_profile_id.indexOf(id[i])<0)
  45. {
  46. alert("Caractère '"+id[i]+"' non autorisé dans le champ ID");
  47. return false;
  48. }
  49. return true;
  50. }
  51. function delete_profil(index)
  52. {
  53. $("#input_0_prof_"+index).remove();
  54. profiles_list_id = jQuery.grep(profiles_list_id, function(value) {
  55. return value != index;
  56. });
  57. }
  58. function add_form_profils(k, v)
  59. {
  60. k = (typeof k === 'undefined') ? null : k;
  61. v = (typeof v === 'undefined') ? null : v;
  62. if( (k==null && v==null) && (!check_profil_id($('#input_0_prof_id').val()) || !check_profil_label($('#input_0_prof_label').val())) )return;
  63. profils_created++;
  64. var n;
  65. if(k==null)
  66. {
  67. n=profils_created;
  68. k=$('#input_0_prof_id').val();
  69. v=$('#input_0_prof_label').val();
  70. }
  71. else
  72. {
  73. n=reg_tmpid++;
  74. }
  75. var o = $("<tr id='input_0_prof_"+n+"'></tr>");
  76. o.append($("<td id='input_0_prof_id_"+n+"'>"+k+"</td>"));
  77. o.append($("<td id='input_0_prof_label_"+n+"'>"+v+"</td>"));
  78. o.append($("<td><button class='btn btn-default glyphicon glyphicon-minus' onclick='delete_profil("+n+")'></button></td>"));
  79. o.insertBefore("#input_0_prof_tr");
  80. $('#input_0_prof_id').val("");
  81. $('#input_0_prof_label').val("");
  82. profiles_list_id.push(n);
  83. }
  84. function construct_reglages()
  85. {
  86. //build_form_profils_input().insertBefore("#input_0_profils_list_add")
  87. }
  88. function regs_open(data)
  89. {
  90. var i;
  91. reg_tmpid=0;
  92. for(i=0; i<profiles_list_id.length; i++)
  93. $('#input_0_prof_id_'+profiles_list_id[i]).parent().remove();
  94. profiles_list_id=[];
  95. regs=JSON.parse(JSON.stringify(data));
  96. for(i=0; i<regs.profiles.length; i++)
  97. add_form_profils(regs.profiles[i][0], regs.profiles[i][1]);
  98. $('#input_0_prof_id').val("");
  99. $('#input_0_prof_label').val("");
  100. $('#input_0_titre').val(data.title);
  101. $('#input_0_fileinput').val(data.photo);
  102. }
  103. function reg_changefile()
  104. {
  105. $('#input_0_fileinput').val( "icons/"+$('#input_0_file').val() );
  106. }
  107. function get_regs()
  108. {
  109. var i;
  110. regs.title=$('#input_0_titre').val();
  111. regs.photo=$('#input_0_fileinput').val();
  112. regs.profiles=[];
  113. for(i=0; i<profiles_list_id.length; i++)
  114. regs.profiles.push( [$('#input_0_prof_id_'+profiles_list_id[i]).html(), $('#input_0_prof_label_'+profiles_list_id[i]).html()] );
  115. return regs;
  116. }