123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /*
- * This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- var profils_created=0;
- var regs={ "title" : "", "photo":"", "profiles" : [] };
- var profiles_list_id=[];
- const authorized_profile_id="azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN-_.";
- const authorized_profile_label="azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN-_.";
- var reg_tmpid;
- function check_profil_id(id)
- {
- var i;
- if(id.length<1)
- {
- alert("Veuillez remplir le champ ID");
- return false;
- }
- for(i=0; i<id.length; i++)
- if(authorized_profile_id.indexOf(id[i])<0)
- {
- alert("Caractère '"+id[i]+"' non autorisé dans le champ ID");
- return false;
- }
-
- return true;
- }
- function check_profil_label(id)
- {
- var i;
- if(id.length<1)
- {
- alert("Veuillez remplir le champ Label");
- return false;
- }
- for(i=0; i<id.length; i++)
- if(authorized_profile_id.indexOf(id[i])<0)
- {
- alert("Caractère '"+id[i]+"' non autorisé dans le champ ID");
- return false;
- }
-
- return true;
- }
- function delete_profil(index)
- {
- $("#input_0_prof_"+index).remove();
- profiles_list_id = jQuery.grep(profiles_list_id, function(value) {
- return value != index;
- });
- }
- function add_form_profils(k, v)
- {
- k = (typeof k === 'undefined') ? null : k;
- v = (typeof v === 'undefined') ? null : v;
-
- if( (k==null && v==null) && (!check_profil_id($('#input_0_prof_id').val()) || !check_profil_label($('#input_0_prof_label').val())) )return;
- profils_created++;
-
- var n;
-
- if(k==null)
- {
- n=profils_created;
- k=$('#input_0_prof_id').val();
- v=$('#input_0_prof_label').val();
- }
- else
- {
- n=reg_tmpid++;
- }
-
-
- var o = $("<tr id='input_0_prof_"+n+"'></tr>");
- o.append($("<td id='input_0_prof_id_"+n+"'>"+k+"</td>"));
- o.append($("<td id='input_0_prof_label_"+n+"'>"+v+"</td>"));
- o.append($("<td><button class='btn btn-default glyphicon glyphicon-minus' onclick='delete_profil("+n+")'></button></td>"));
- o.insertBefore("#input_0_prof_tr");
- $('#input_0_prof_id').val("");
- $('#input_0_prof_label').val("");
- profiles_list_id.push(n);
- }
- function construct_reglages()
- {
- //build_form_profils_input().insertBefore("#input_0_profils_list_add")
- }
- function regs_open(data)
- {
- var i;
- reg_tmpid=0;
-
- for(i=0; i<profiles_list_id.length; i++)
- $('#input_0_prof_id_'+profiles_list_id[i]).parent().remove();
- profiles_list_id=[];
-
- regs=JSON.parse(JSON.stringify(data));
- for(i=0; i<regs.profiles.length; i++)
- add_form_profils(regs.profiles[i][0], regs.profiles[i][1]);
- $('#input_0_prof_id').val("");
- $('#input_0_prof_label').val("");
- $('#input_0_titre').val(data.title);
- $('#input_0_fileinput').val(data.photo);
- }
- function reg_changefile()
- {
- $('#input_0_fileinput').val( "icons/"+$('#input_0_file').val() );
- }
- function get_regs()
- {
- var i;
- regs.title=$('#input_0_titre').val();
- regs.photo=$('#input_0_fileinput').val();
- regs.profiles=[];
- for(i=0; i<profiles_list_id.length; i++)
- regs.profiles.push( [$('#input_0_prof_id_'+profiles_list_id[i]).html(), $('#input_0_prof_label_'+profiles_list_id[i]).html()] );
-
- return regs;
- }
|