// Globals // ----------------------------------------------------------------------------- // NOTE: // Variable `entity_id` is defined before evaluating this script // id (int) : the id of edited post (or 0 if new post) var page; var id = (entity_id == 0) ? false : entity_id; var files = []; // array of { id:.., title:.., type:.., path:.. } records // TODO: support tags // var tags = []; // array of integers // an alternative--id when a page_id not exists (needed for file-upload) // ... consist of a 6-digit date string + random number up to 999 const yymmdd = new Date().toISOString().slice(2, 10).replaceAll('-',''); var rnd999 = Math.floor(Math.random() * 1000); var altID = (id == 0) ? ( yymmdd +'-'+ rnd999.toString() ) : id; // Supplamentary functions // ----------------------------------------------------------------------------- // function for sorting an array by 'label' attribute // --- -- -- - - - function compare_label (a,b) { if ( a.label < b.label ) { return -1; } if ( a.label > b.label ) { return 1; } return 0; } // return course record by course-id // --- -- -- - - - function course_record(id) { var record = 0; categories.forEach(el => { if (el.id == id) record = el; }); return record; } // Modal HTML Creators // ----------------------------------------------------------------------------- const modal_header = (title) => { return [ '