|
@@ -0,0 +1,367 @@
|
|
|
+/*
|
|
|
+ * 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 sect_count=0;
|
|
|
+var sect_active=-1;
|
|
|
+var cont_sect=[];
|
|
|
+
|
|
|
+var sect_count=0;
|
|
|
+var itm_count=0;
|
|
|
+var itm_active=-1;
|
|
|
+var cont_tmpids=0;
|
|
|
+var itm_tmpids=0;
|
|
|
+
|
|
|
+// ------------------------------------------------
|
|
|
+// Sections
|
|
|
+// ------------------------------------------------
|
|
|
+
|
|
|
+function cont_get_sect_index(id)
|
|
|
+{
|
|
|
+ var i;
|
|
|
+ for(i=0; i<cont_sect.length; i++)
|
|
|
+ if(cont_sect[i].id == id)
|
|
|
+ return i;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+function cont_sect_show()
|
|
|
+{
|
|
|
+ var sect = cont_get_sect_index(sect_active);
|
|
|
+ var i;
|
|
|
+ $('#input_2_sect_rename').val(cont_sect[sect].title);
|
|
|
+ $('#input_2_itm_list').empty();
|
|
|
+ for(i=0; i<cont_sect[sect].sections.length; i++)
|
|
|
+ {
|
|
|
+ cont_itm_add(cont_sect[sect].sections[i]);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function cont_sect_select(x)
|
|
|
+{
|
|
|
+ var y = false;
|
|
|
+ if(x==sect_active) return;
|
|
|
+ $("#input_2_sect_list a").removeClass("active");
|
|
|
+ $("#input_2_sect_"+x).addClass('active');
|
|
|
+ if(sect_active==-1) y=true;
|
|
|
+ sect_active=x;
|
|
|
+
|
|
|
+ cont_sect_show();
|
|
|
+
|
|
|
+ $('#input_2_content_list').hide();
|
|
|
+ $('#input_2_itm_root').hide();
|
|
|
+ $('#input_2_itm_root').show(400);
|
|
|
+}
|
|
|
+
|
|
|
+function cont_sect_up()
|
|
|
+{
|
|
|
+ if(sect_active<0) return 0;
|
|
|
+ var i;
|
|
|
+ for(i=1; i<cont_sect.length; i++)
|
|
|
+ {
|
|
|
+ if(cont_sect[i].id==sect_active)
|
|
|
+ {
|
|
|
+ var x = $('#input_2_sect_'+cont_sect[i].id);
|
|
|
+ x.remove();
|
|
|
+ x.insertBefore('#input_2_sect_'+cont_sect[i-1].id);
|
|
|
+
|
|
|
+ var a = cont_sect[i];
|
|
|
+ cont_sect[i]=cont_sect[i-1];
|
|
|
+ cont_sect[i-1]=a;
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function cont_sect_down()
|
|
|
+{
|
|
|
+ if(sect_active<0) return 0;
|
|
|
+ var i;
|
|
|
+ for(i=0; i<cont_sect.length-1; i++)
|
|
|
+ {
|
|
|
+ if(cont_sect[i].id==sect_active)
|
|
|
+ {
|
|
|
+ var x = $('#input_2_sect_'+cont_sect[i].id);
|
|
|
+ x.remove();
|
|
|
+ x.insertAfter('#input_2_sect_'+cont_sect[i+1].id);
|
|
|
+
|
|
|
+
|
|
|
+ var a = cont_sect[i];
|
|
|
+ cont_sect[i]=cont_sect[i+1];
|
|
|
+ cont_sect[i+1]=a;
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function cont_sect_del()
|
|
|
+{
|
|
|
+ if(sect_count<0) return;
|
|
|
+ var x = cont_get_sect_index(sect_active);
|
|
|
+
|
|
|
+ $('#input_2_sect_'+sect_active).remove();
|
|
|
+ cont_sect.splice(x, 1);
|
|
|
+
|
|
|
+
|
|
|
+ sect_active=-1;
|
|
|
+ $('#input_2_itm_root').hide(400);
|
|
|
+ $('#input_2_content_list').hide(400);
|
|
|
+}
|
|
|
+
|
|
|
+function cont_sect_add(obj)
|
|
|
+{
|
|
|
+ obj = (typeof obj === 'undefined') ? null : obj;
|
|
|
+ sect_count++;
|
|
|
+ var id;
|
|
|
+ if(obj==null)
|
|
|
+ {
|
|
|
+ id=sect_count;
|
|
|
+ text=$("#input_2_sect").val();
|
|
|
+ cont_sect.push({ "id" : id, "title" : $("#input_2_sect").val(), sections : [] });
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ id=cont_tmpids++;
|
|
|
+ text=obj.title;
|
|
|
+ obj.id=id;
|
|
|
+ }
|
|
|
+
|
|
|
+ var o = $('<a class="list-group-item" onclick="cont_sect_select('+id+')" id="input_2_sect_'+id+'">'+ text +'</a>');
|
|
|
+ $('#input_2_sect_list').append(o);
|
|
|
+ $("#input_2_sect").val("");
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function cont_sect_rename()
|
|
|
+{
|
|
|
+ console.log(JSON.stringify(cont_sect));
|
|
|
+ var i = cont_get_sect_index(sect_active);
|
|
|
+ $("#input_2_sect_"+sect_active).html($('#input_2_sect_rename').val());
|
|
|
+ cont_sect[i].title=$('#input_2_sect_rename').val();
|
|
|
+ console.log(JSON.stringify(cont_sect));
|
|
|
+ console.log("\n\n");
|
|
|
+}
|
|
|
+
|
|
|
+// ------------------------------------------------
|
|
|
+// Items
|
|
|
+// ------------------------------------------------
|
|
|
+
|
|
|
+function cont_get_itm_index(sect, id)
|
|
|
+{
|
|
|
+ var i;
|
|
|
+ for(i=0; i<cont_sect[sect].sections.length; i++)
|
|
|
+ if(cont_sect[sect].sections[i].id == id)
|
|
|
+ return i;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+function cont_itm_show()
|
|
|
+{
|
|
|
+ var sect = cont_get_sect_index(sect_active);
|
|
|
+ var itm = cont_get_itm_index(sect, itm_active);
|
|
|
+ var i;
|
|
|
+ $('#input_2_itm_rename').val(cont_sect[sect].title);
|
|
|
+
|
|
|
+ $("#input_2_itm_rename").val(cont_sect[sect].sections[itm].name);
|
|
|
+ $("#input_2_itm_title").val(cont_sect[sect].sections[itm].content);
|
|
|
+ $("#input_2_itm_date").val(cont_sect[sect].sections[itm].date);
|
|
|
+ $("#input_2_itm_location").val(cont_sect[sect].sections[itm].location);
|
|
|
+ $("#input_2_itm_more").val(cont_sect[sect].sections[itm].more);
|
|
|
+
|
|
|
+ $('#input_2_itm_profils_list').empty();
|
|
|
+ var reg = get_regs();
|
|
|
+ for(i=0; i<reg.profiles.length; i++)
|
|
|
+ {
|
|
|
+ var state = "";
|
|
|
+ var j;
|
|
|
+ if(cont_sect[sect].sections[itm].profiles)
|
|
|
+ for(j=0; j<cont_sect[sect].sections[itm].profiles.length; j++)
|
|
|
+ {
|
|
|
+ if(cont_sect[sect].sections[itm].profiles[j] == reg.profiles[i][0])
|
|
|
+ {
|
|
|
+ state="checked='true'";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#input_2_itm_profils_list').append($('<div><label class="btn btn-primary profiles-btn"><input class="profiles-ck" '+state+' autocomplete="off" id="input_2_prof_'+reg.profiles[i][0]
|
|
|
+ +'" type="checkbox">'+reg.profiles[i][1]+'</label></div>'));
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function cont_itm_select(x)
|
|
|
+{
|
|
|
+ var y = false;
|
|
|
+ if(x==itm_active) return;
|
|
|
+ $("#input_2_itm_list a").removeClass("active");
|
|
|
+ $("#input_2_itm_"+x).addClass('active');
|
|
|
+ if(itm_active==-1) y=true;
|
|
|
+ itm_active=x;
|
|
|
+ cont_itm_show();
|
|
|
+ $('#input_2_content_list').hide();
|
|
|
+ $('#input_2_content_list').show(400);
|
|
|
+}
|
|
|
+
|
|
|
+function cont_itm_up()
|
|
|
+{
|
|
|
+ if(itm_active<0) return 0;
|
|
|
+ var i;
|
|
|
+ var sect = cont_get_sect_index(itm_active);
|
|
|
+ console.log(JSON.stringify(cont_sect));
|
|
|
+ for(i=1; i<cont_sect[sect].sections.length; i++)
|
|
|
+ {
|
|
|
+ if(cont_sect[sect].sections[i].id==itm_active)
|
|
|
+ {
|
|
|
+ var x = $('#input_2_itm_'+cont_sect[sect].sections[i].id);
|
|
|
+ x.remove();
|
|
|
+ x.insertBefore('#input_2_itm_'+cont_sect[sect].sections[i-1].id);
|
|
|
+
|
|
|
+ var a = cont_sect[sect].sections[i];
|
|
|
+ cont_sect[sect].sections[i]=cont_sect[sect].sections[i-1];
|
|
|
+ cont_sect[sect].sections[i-1]=a;
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function cont_sect_down()
|
|
|
+{
|
|
|
+ if(sect_active<0) return 0;
|
|
|
+ var i;
|
|
|
+ for(i=0; i<cont_sect.length-1; i++)
|
|
|
+ {
|
|
|
+ if(cont_sect[i].id==sect_active)
|
|
|
+ {
|
|
|
+ var x = $('#input_2_sect_'+cont_sect[i].id);
|
|
|
+ x.remove();
|
|
|
+ x.insertAfter('#input_2_sect_'+cont_sect[i+1].id);
|
|
|
+
|
|
|
+
|
|
|
+ var a = cont_sect[i];
|
|
|
+ cont_sect[i]=cont_sect[i+1];
|
|
|
+ cont_sect[i+1]=a;
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function cont_itm_del()
|
|
|
+{
|
|
|
+ if(itm_active<0) return;
|
|
|
+ var x = cont_get_sect_index(sect_active);
|
|
|
+ var y = cont_get_sect_index(x, itm_active);
|
|
|
+
|
|
|
+ $('#input_2_itm_'+itm_active).remove();
|
|
|
+ cont_sect[x].sections.splice(y, 1);
|
|
|
+
|
|
|
+ itm_active=-1;
|
|
|
+ $('#input_2_content_list').hide(400);
|
|
|
+}
|
|
|
+
|
|
|
+function cont_itm_add(obj)
|
|
|
+{
|
|
|
+ obj = (typeof obj === 'undefined') ? null : obj;
|
|
|
+
|
|
|
+ itm_count++;
|
|
|
+
|
|
|
+ var id;
|
|
|
+ if(obj==null)
|
|
|
+ {
|
|
|
+ id=itm_count;
|
|
|
+ text=$("#input_2_itm").val();
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ id=itm_tmpids++;
|
|
|
+ text=obj.name;
|
|
|
+ obj.id=id;
|
|
|
+ }
|
|
|
+
|
|
|
+ var sect = cont_get_sect_index(sect_active);
|
|
|
+ var o = $('<a class="list-group-item" onclick="cont_itm_select('+id+')" id="input_2_itm_'+id+'">'+ text+'</a>');
|
|
|
+ $('#input_2_itm_list').append(o)
|
|
|
+ if(obj==null) cont_sect[sect].sections.push({"id" : id, "name" :text, "content" : "", "date" : "", "more" : "", "location" : "", "date" : "", "profiles" : [] });
|
|
|
+ $("#input_2_itm").val("");
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// ---------------------------------
|
|
|
+// Contenu
|
|
|
+// ---------------------------------
|
|
|
+function cont_cont_rename()
|
|
|
+{
|
|
|
+ var sect = cont_get_sect_index(sect_active);
|
|
|
+ var itm = cont_get_itm_index(sect, itm_active);
|
|
|
+
|
|
|
+ cont_sect[sect].sections[itm].name=$("#input_2_itm_rename").val();
|
|
|
+ $("#input_2_itm_"+itm_active).html($("#input_2_itm_rename").val());
|
|
|
+}
|
|
|
+
|
|
|
+function cont_cont_save()
|
|
|
+{
|
|
|
+ var sect = cont_get_sect_index(sect_active);
|
|
|
+ var itm = cont_get_itm_index(sect, itm_active);
|
|
|
+ var i;
|
|
|
+ var reg = get_regs();
|
|
|
+
|
|
|
+ cont_sect[sect].sections[itm].name=$("#input_2_itm_rename").val();
|
|
|
+ cont_sect[sect].sections[itm].content=$("#input_2_itm_title").val();
|
|
|
+ cont_sect[sect].sections[itm].date=$("#input_2_itm_date").val();
|
|
|
+ cont_sect[sect].sections[itm].location=$("#input_2_itm_location").val();
|
|
|
+ cont_sect[sect].sections[itm].more=$("#input_2_itm_more").val();
|
|
|
+ $('#input_2_content_list').hide(400);
|
|
|
+ $("#input_2_itm_list a").removeClass("active");
|
|
|
+ cont_sect[sect].sections[itm].profiles=[];
|
|
|
+ for(i=0; i<reg.profiles.length; i++)
|
|
|
+ {
|
|
|
+ if( $('#input_2_prof_'+reg.profiles[i][0]+":checked").val() == "on" )
|
|
|
+ {
|
|
|
+ cont_sect[sect].sections[itm].profiles.push(reg.profiles[i][0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ itm_active=-1;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function cont_open(main)
|
|
|
+{
|
|
|
+ var i;
|
|
|
+ cont_tmpids=0;
|
|
|
+ itm_tmpids=1;
|
|
|
+ $('#input_2_sect_list').empty();
|
|
|
+
|
|
|
+ cont_sect=JSON.parse( JSON.stringify( main ));
|
|
|
+ for(i=0; i<cont_sect.length; i++)
|
|
|
+ cont_sect_add(cont_sect[i]);
|
|
|
+
|
|
|
+ $('#input_2_itm_root').hide();
|
|
|
+ $('#input_2_content_list').hide();
|
|
|
+ $("#input_2_itm_list a").removeClass("active");
|
|
|
+ $("#input_2_sect_list a").removeClass("active");
|
|
|
+ sect_active=-1;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function get_conts()
|
|
|
+{
|
|
|
+ return cont_sect;
|
|
|
+}
|
|
|
+
|