TOC html
Jump to navigation
Jump to search
| (51 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | |||
| − | |||
<html> | <html> | ||
| Line 18: | Line 16: | ||
--> | --> | ||
| + | |||
| + | |||
| + | <!--------------------------path--------------------------> | ||
| + | |||
| + | <div class="ci_form_section"> | ||
| + | <span class="ci_form_section_label"> | ||
| + | Target url | ||
| + | </span> | ||
| + | |||
| + | <input class="ci_form_input" type="text" placeholder="" name="Form TOC[target url]" value=""> | ||
| + | |||
| + | <span class="ci_form_section_help"> | ||
| + | Enter the target url of this set of pages, e.g.: https://culturaitaliana.org/organizations/Centro_italiano_Barcellona | ||
| + | </span> | ||
| + | |||
| + | </div> | ||
| + | |||
| + | |||
<div id="TOC_tree"></div> | <div id="TOC_tree"></div> | ||
| Line 42: | Line 58: | ||
<div class="ci_form_section_submit"> | <div class="ci_form_section_submit"> | ||
<input type="hidden" name="wpSave" value="Save page"> | <input type="hidden" name="wpSave" value="Save page"> | ||
| − | <input type="hidden" name="pf_free_text" value=" | + | <input type="hidden" id="pf_free_text" name="pf_free_text" value=""> |
<input class="ci_form_submit" type="submit" value="save"> | <input class="ci_form_submit" type="submit" value="save"> | ||
| Line 56: | Line 72: | ||
$ci(function() { | $ci(function() { | ||
| + | |||
| + | |||
| + | var wiki_list = [] | ||
| + | |||
| + | |||
| + | function walk_through_TOC(children,parent,depth) { | ||
| + | |||
| + | if(!children || !Object.keys(children).length) { | ||
| + | return | ||
| + | } | ||
| + | |||
| + | |||
| + | depth++ | ||
| + | |||
| + | |||
| + | for(var value of children) { | ||
| + | |||
| + | // '&&' does not work ! | ||
| + | if(value.path) { | ||
| + | |||
| + | if(value.state.selected) { | ||
| + | wiki_list.push('#'.repeat(depth) + '[[' + value.path + '|' + value.text + ']]') | ||
| + | } | ||
| + | |||
| + | } else { | ||
| + | |||
| + | if(value.state.selected) { | ||
| + | wiki_list.push('#'.repeat(depth) + value.text) | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | if(value.children) { | ||
| + | walk_through_TOC(value.children,value,depth); | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | } | ||
var contents = $ci('#TOC_contents').val(); | var contents = $ci('#TOC_contents').val(); | ||
| − | + | ||
| − | + | contents = TOC_functions.base64_to_utf8(contents); | |
| − | contents = | + | |
| − | |||
| − | |||
if(contents) { | if(contents) { | ||
| − | contents = JSON.parse(contents) | + | contents = JSON.parse(contents); |
| − | + | ||
| + | TOC_functions.translate_TOC_rec(contents,'from'); | ||
| Line 74: | Line 130: | ||
checkbox: function(event, data) { | checkbox: function(event, data) { | ||
// Hide checkboxes for folders | // Hide checkboxes for folders | ||
| − | return data.node.isFolder() ? false : true; | + | return data.node.isFolder()? false: true; |
}, | }, | ||
| − | dnd5: | + | dnd5: TOC_functions.fancytree_dnd5_conf |
}); | }); | ||
} | } | ||
| Line 82: | Line 138: | ||
$ci('form').submit(function() { | $ci('form').submit(function() { | ||
| + | |||
| + | if(typeof tree == 'undefined') { | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | var index_obj_saved = tree.toDict(true).children; | ||
| + | |||
| + | TOC_functions.translate_TOC_rec(index_obj_saved,'to'); | ||
| + | |||
| + | // create wiki_list | ||
| + | walk_through_TOC(index_obj_saved,null,0); | ||
| + | |||
| + | |||
| + | index_obj_saved = TOC_functions.utf8_to_base64(JSON.stringify(index_obj_saved)); | ||
| + | |||
| + | |||
| + | $ci('#TOC_contents').val(index_obj_saved) | ||
| + | var today = new Date(); | ||
| + | var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate(); | ||
| + | var time = today.getHours() + ":" + (today.getMinutes() + '').padStart(2, '0') + ":" + (today.getSeconds() + '').padStart(2, '0'); | ||
| + | |||
| + | |||
| + | $ci('#pf_free_text').val(`<!-- | ||
| + | The content of this page has been created automatically on ` + date + ` at ` + time + `. | ||
| + | Don't edit it without the form, since any additional content | ||
| + | will be lost on the next automatic update! | ||
| + | -->` + wiki_list.join("\n") + ` | ||
| + | |||
| + | [[Category:TOCs]]`) | ||
| − | |||
| − | |||
| − | |||
return true; | return true; | ||
| + | |||
}); | }); | ||
Latest revision as of 22:35, 13 February 2021