/** * Documentor Admin — Vue.js Application * * Manages the WordPress admin UI for the Documentor plugin. * Handles creating, cloning, removing, sorting, and exporting * documentation posts (docs, sections, articles). * * Dependencies: * - jQuery (window.jQuery) * - Vue.js (global) * - SweetAlert (swal) — optional, used for confirmation dialogs * - wp.ajax — WordPress AJAX helper * - ajaxurl — WordPress global AJAX endpoint * - window.documentor_admin_vars — localised plugin data */ (function() { var $ = window.jQuery; var admin_vars = window.documentor_admin_vars; // Shorthand for the localised i18n strings (translations/labels). var __ = admin_vars.__; // Disable SweetAlert's built-in open/close animation if the library is loaded. if(typeof swal !== 'undefined') { swal.setDefaults({ animation: false }); } /** * Organises a flat list of docs into a category-keyed object. * * Each category entry has the shape: * { name: string, docs: Array } * * A default "uncategorised" bucket with key 0 is always created first, * so docs without a cat_id fall back to it. * * @param {Array} docs Flat array of doc objects returned by the server. * @return {Object} Category-keyed map: { [cat_id]: { name, docs[] } } */ function categorize_docs(docs) { // Clone the array so we don't mutate the original. var docs_copy = Object.assign([], docs); // Start with a default uncategorised bucket. var categorized = { 0: { name: '', docs: [] } }; docs_copy.forEach(function(doc) { var cat_id = doc.post.cat_id; // Create the category bucket if it doesn't exist yet. if(!categorized['' + cat_id]) { categorized['' + cat_id] = { name: doc.post.cat_name, docs: [] }; } categorized[cat_id].docs.push(doc); }); return categorized; } // --------------------------------------------------------------------------- // Custom Vue directive: v-sortable // Wraps jQuery UI Sortable on the bound element (a