Improvements in template handling and loading

This commit is contained in:
Nathan Schneider
2025-07-22 12:17:25 -06:00
parent 3ef15444fe
commit 847b603734
59 changed files with 1070 additions and 2153 deletions

335
static/js/all-templates.js Normal file
View File

@@ -0,0 +1,335 @@
// All Templates - Consolidated for reliable loading
// This file contains all templates in a single file to avoid ES module issues in production
window.allTemplates = [
// Shalish Mediation Template
{
id: "shalish-mediation",
title: "Shalish Mediation",
description: "A process based on the traditional shalish process for village-level mediation in Bangladesh, with modernizing improvements",
data: {
stages: {
basics: {
community_rules: {
communityRulesText: "The rules and procedures for the Shalish mediation process are documented in a community handbook that explains the cultural tradition and modern adaptations made by the Madaripur Legal Aid Association. This handbook is translated into local languages and made available through community centers, government offices, and through trained mediators."
},
shared_values: {
sharedValuesText: "Shalish mediation centers on values of community harmony, restorative justice, and cultural respect. Mediators emphasize the importance of restoring relationships, fairness to all parties, and finding solutions that strengthen the community. Decisions are guided by local cultural norms and expectations alongside consideration of basic principles of justice and human dignity."
},
information_access: {
informationAccessText: "Information about specific cases is kept confidential among the participating parties and mediators. Statistical information about types of cases addressed (without identifying details) is collected for program evaluation and improvement. Participants receive copies of any agreements they reach during the process."
}
},
process: {
process_start: {
processStartText: "One or more disputant parties ask a third-party intervenor to assist in the dispute resolution process. If only one of the parties initiates the process, the other party/parties may or may not choose to participate. In the case of the latter, the mediator may require conflicting parties to submit to the mediation process. The mediator may need to educate one or more parties about the benefits of mediation for conflict resolution. Upon the agreement of all parties to participate, the mediator schedules a meeting time agreeable to all."
},
facilitation: {
facilitationText: "Upon the decision to enter the mediation process from the disputant parties, the mediator decides whether to mediate alone or co-mediate. In the case of co-mediation, the mediators determine each others' responsibilities for the different aspects of the mediation process, safety valves in case of problems between mediators, time schedules, a mediation site, the management of case records, and similar housekeeping aspects. Each party is allowed to make an initial statement. The mediators take notes throughout the entire mediation process. Mediators may choose to meet privately with one or all of the disputant parties. In the end, the mediators help the disputants write an agreement."
},
ground_rules: {
groundRulesText: "Communication in the mediation follows established ground rules: 1) Speak only for yourself and in the first person, 2) Use language that does not blame or find fault with others, 3) Do not interrupt while another is speaking, 4) Use non-inflammatory words, 5) If stating a complaint, raise it as your own concern and follow it with a constructive suggestion as to how it might be resolved, 6) Attack the problems and concerns at hand; do not attack the other person, 7) Make statements about your interests and needs instead of stating your position, 8) Be respectful to others, 9) Listen to understand what each person is saying without being judgmental about the person or the message."
}
},
outcome: {
documentation: {
documentationText: "All agreements reached through the shalish mediation process are documented in writing and signed by all parties. The agreement includes specific commitments made by each party, timelines for implementation, and consequences for non-compliance. Both parties receive copies of the signed agreement. A summary (without identifying information) is kept for program evaluation purposes."
},
monitoring: {
monitoringText: "Following the mediation, there is a follow-up period of 30-60 days during which the mediator checks with parties to ensure the agreement is being implemented. If problems arise, parties can return for additional mediation sessions. The community maintains records of successful resolutions to help improve the mediation process over time."
}
}
}
}
},
// Restorative Justice Template
{
id: "restorative-justice",
title: "Restorative Justice Circle",
description: "A community-based approach focusing on healing relationships and addressing root causes of conflict through inclusive dialogue",
data: {
stages: {
basics: {
community_rules: {
communityRulesText: "Our restorative justice process is governed by principles of respect, responsibility, and relationship repair. Guidelines are maintained in our Community Handbook and shared through regular community education sessions. All community members are expected to understand and support these principles."
},
shared_values: {
sharedValuesText: "We believe in the inherent worth and dignity of every person, the possibility of positive change, and the healing power of community support. Our process emphasizes accountability, making amends, and preventing future harm while building stronger community connections."
},
information_access: {
informationAccessText: "Circle processes maintain confidentiality within the circle participants. Outcomes and agreements are documented and shared as appropriate for accountability purposes. Community members receive regular education about restorative practices without sharing details of specific cases."
}
},
process: {
process_start: {
processStartText: "A community member, affected party, or community leader identifies harm that needs to be addressed. Initial conversations determine whether a restorative circle is appropriate and whether all affected parties are willing to participate. Preparation includes identifying circle participants and a suitable keeper/facilitator."
},
facilitation: {
facilitationText: "A trained circle keeper facilitates the process, beginning with opening ceremonies that center participants and establish sacred space. Each person shares their perspective on what happened and how they were affected. The circle explores root causes, community impacts, and pathways to healing and repair."
},
ground_rules: {
groundRulesText: "Circle participants agree to: speak from the heart with honesty and respect; listen with compassion and an open mind; say only what needs to be said; maintain confidentiality; take responsibility for their actions and words; commit to the healing process; and honor the sacred nature of the circle space."
}
},
outcome: {
documentation: {
documentationText: "Agreements reached in circle are documented with input from all participants. This includes specific actions for repair, support needed, and follow-up commitments. The agreement reflects the collective wisdom of the circle and is signed by all participants."
},
monitoring: {
monitoringText: "The circle keeper coordinates follow-up to ensure agreements are fulfilled and relationships continue healing. Additional circles may be convened as needed. The community celebrates successful repairs and learns from the process to strengthen future restorative responses."
}
}
}
}
},
// Peer-to-Peer Template
{
id: "peer-to-peer",
title: "Peer-to-Peer Resolution",
description: "A direct negotiation process between disputants with minimal third-party intervention, emphasizing self-determination",
data: {
stages: {
basics: {
community_rules: {
communityRulesText: "Peer-to-peer resolution operates under community agreements that support direct communication and mutual problem-solving. Guidelines emphasize respect, honesty, and good faith engagement. Resources and support are available but participation in formal processes remains voluntary."
},
shared_values: {
sharedValuesText: "We value individual autonomy, direct communication, and the capacity of community members to resolve their own conflicts. This approach builds on trust in people's ability to find mutually acceptable solutions when given appropriate support and frameworks."
},
information_access: {
informationAccessText: "Information sharing is controlled by the participants themselves. Community support persons may assist with communication but do not keep formal records. Outcomes are shared only as participants choose, with community learning happening through voluntary sharing of insights and experiences."
}
},
process: {
process_start: {
processStartText: "Either party may initiate peer-to-peer resolution by approaching the other party directly or requesting community assistance in making contact. The process begins only when both parties agree to participate. Initial focus is on establishing ground rules and communication methods that work for both parties."
},
facilitation: {
facilitationText: "Parties meet directly with minimal outside intervention. Community members may provide support such as helping to arrange meetings, offering neutral meeting spaces, or serving as witnesses if requested. The focus remains on the parties' own problem-solving abilities and preferences."
},
ground_rules: {
groundRulesText: "Participants commit to: engaging in good faith; treating each other with respect; focusing on specific behaviors and impacts rather than character; listening to understand; taking breaks when needed; maintaining confidentiality as agreed; and seeking community support when helpful."
}
},
outcome: {
documentation: {
documentationText: "Agreements are documented according to participants' preferences, ranging from informal verbal agreements to detailed written contracts. The level of formality and external oversight depends entirely on what the parties believe will best support their agreement."
},
monitoring: {
monitoringText: "Follow-up occurs as agreed by the parties, which may include self-monitoring, mutual check-ins, or involvement of chosen community members. The emphasis is on voluntary accountability and ongoing communication rather than external enforcement."
}
}
}
}
},
// Jury Protocol Template
{
id: "jury-protocol",
title: "Community Jury",
description: "A formal adjudication process where community members serve as jurors to make binding decisions on disputes",
data: {
stages: {
basics: {
community_rules: {
communityRulesText: "The Community Jury Protocol is established by community charter and operates under formal procedures documented in our Community Dispute Resolution Manual. Jury selection, evidence presentation, and decision-making processes follow established protocols designed to ensure fairness and community legitimacy."
},
shared_values: {
sharedValuesText: "This process upholds values of fairness, community participation in justice, peer accountability, and transparent decision-making. We believe community members are best positioned to understand local context and make decisions that serve community wellbeing while maintaining individual rights."
},
information_access: {
informationAccessText: "Jury proceedings follow established rules of evidence and documentation. Participants have rights to information relevant to their case. Jury deliberations remain confidential, but decisions and reasoning are documented and made available to the community as appropriate for transparency and precedent."
}
},
process: {
process_start: {
processStartText: "Cases come to the Community Jury through formal complaint processes or referral from other resolution attempts. Initial review determines whether the case is appropriate for jury resolution. If accepted, jury selection begins from a pool of trained community volunteers, with challenges allowed by both parties."
},
facilitation: {
facilitationText: "A trained community member serves as jury coordinator, managing procedures but not influencing decisions. Each party presents their case with supporting evidence and witnesses. Jury members may ask questions for clarification. The jury deliberates privately and reaches decisions by majority vote or consensus as specified in community protocols."
},
ground_rules: {
groundRulesText: "All participants agree to: respect the formal process and jury authority; present truthful information and evidence; treat all parties with dignity; accept the jury's decision as binding; maintain confidentiality of deliberations; and support the implementation of jury decisions."
}
},
outcome: {
documentation: {
documentationText: "Jury decisions are formally documented with reasoning, any dissenting opinions, and specific requirements for the parties. These documents become part of community records and may serve as precedent for future cases. Implementation requirements and timelines are clearly specified."
},
monitoring: {
monitoringText: "A designated community member monitors compliance with jury decisions and reports back to the community as needed. Non-compliance may result in additional community consequences or, in serious cases, exclusion from community participation. The community reviews the jury process periodically for effectiveness and fairness."
}
}
}
}
},
// Transformative Justice Template
{
id: "transformative-justice",
title: "Transformative Justice Process",
description: "A comprehensive approach addressing systemic issues and power dynamics while supporting both accountability and healing",
data: {
stages: {
basics: {
community_rules: {
communityRulesText: "Our transformative justice approach is grounded in anti-oppression principles and community agreements that center marginalized voices and address systemic harm. Guidelines prioritize survivor self-determination, community accountability, and structural change alongside individual healing."
},
shared_values: {
sharedValuesText: "We are committed to interrupting cycles of violence and oppression, building community capacity to address harm without relying on punitive systems, centering those most impacted by harm, and creating conditions for genuine transformation of individuals and communities."
},
information_access: {
informationAccessText: "Information sharing prioritizes survivor needs and community safety while maintaining transparency about processes and outcomes. Documentation focuses on community learning and systemic improvements rather than individual punishment. Privacy and safety considerations guide all information decisions."
}
},
process: {
process_start: {
processStartText: "Process begins with immediate safety and support for those harmed, led by their expressed needs and preferences. Community members assess capacity for transformative response and begin building support teams for all parties. Initial focus is on stabilization and safety rather than immediate resolution."
},
facilitation: {
facilitationText: "Multiple facilitators work together, often including those with lived experience of similar situations. The process includes separate and joint meetings as appropriate, with attention to power dynamics and safety throughout. Community members provide ongoing support to all parties while working toward systemic changes that address root causes."
},
ground_rules: {
groundRulesText: "All participants commit to: prioritizing safety and healing; acknowledging and addressing power imbalances; taking responsibility for harm caused; supporting survivor self-determination; engaging in ongoing learning about oppression and transformation; maintaining confidentiality as determined by survivors; and working toward community-wide culture change."
}
},
outcome: {
documentation: {
documentationText: "Outcomes focus on concrete steps for individual accountability, community healing, and systemic change. Documentation includes safety plans, accountability agreements, community education commitments, and structural changes to prevent future harm. Progress is tracked through survivor-centered metrics."
},
monitoring: {
monitoringText: "Long-term support teams continue working with all parties to ensure accountability agreements are met and healing continues. Community commits to ongoing culture change work and policy modifications. Regular assessment focuses on whether the community is becoming safer and more just for all members."
}
}
}
}
},
// Additional templates continue...
// Chosen Facilitator Template
{
id: "chosen-facilitator",
title: "Chosen Facilitator",
description: "A process where participants mutually select a facilitator to help guide their dispute resolution",
data: {
stages: {
basics: {
community_rules: {
communityRulesText: "Community rules and the dispute resolution protocol are available on the community website and in a physical binder kept in the community center. New members receive an orientation to these guidelines when they join."
},
shared_values: {
sharedValuesText: "Our community values open dialogue, mutual respect, and collaborative problem-solving. We believe that most conflicts can be resolved through good faith communication with appropriate support. We prioritize repairing relationships and finding solutions that address underlying needs rather than simply ending disputes."
},
information_access: {
informationAccessText: "Information is shared on a need-to-know basis. The Community Relations Committee keeps records of disputes, and the parties involved have access to all documentation related to their case. Annual anonymous statistics about disputes are shared with the community."
}
},
process: {
process_start: {
processStartText: "Either party may request facilitated dialogue by contacting the Community Relations Committee. If both parties agree to participate, they work together to choose a facilitator from a list of trained community members. The facilitator contacts both parties to schedule an initial meeting."
},
facilitation: {
facilitationText: "The chosen facilitator meets with each party individually first to understand their perspectives and concerns. They then bring parties together for structured dialogue, helping them communicate effectively and explore potential solutions. The facilitator remains neutral while guiding the conversation toward resolution."
},
ground_rules: {
groundRulesText: "Participants agree to: listen respectfully without interrupting; speak about their own experiences and needs rather than making accusations; maintain confidentiality about what is shared; come prepared to engage in good faith; respect the facilitator's guidance; and commit to implementing any agreements reached."
}
},
outcome: {
documentation: {
documentationText: "The facilitator documents any agreements reached, including specific actions each party will take and timelines for implementation. Both parties sign the agreement, and copies are provided to each party and filed with the Community Relations Committee."
},
monitoring: {
monitoringText: "The facilitator follows up with both parties after 30 days to check on implementation of the agreement. If issues arise, additional facilitated sessions may be scheduled. The Community Relations Committee tracks resolution outcomes to improve the process over time."
}
}
}
}
},
// Facilitation Council Template
{
id: "facilitation-council",
title: "Facilitation Council",
description: "A group of trained facilitators who collectively support dispute resolution processes and community healing",
data: {
stages: {
basics: {
community_rules: {
communityRulesText: "The Facilitation Council operates under community bylaws that establish its authority, composition, and procedures. Council members are elected for rotating terms and must complete training in conflict resolution and community facilitation. Their role is to support resolution processes, not to make binding decisions."
},
shared_values: {
sharedValuesText: "The Council embodies values of collaborative leadership, shared wisdom, and community healing. Members commit to serving the whole community while maintaining neutrality in specific conflicts. The Council prioritizes processes that strengthen community relationships and prevent future conflicts."
},
information_access: {
informationAccessText: "The Council maintains confidential records of its facilitation work while sharing general information about processes and outcomes with the community. Council meetings include both closed sessions for sensitive case discussions and open sessions for community input and transparency."
}
},
process: {
process_start: {
processStartText: "Community members may request Council support through formal application or informal consultation. The Council assesses each situation and recommends appropriate resolution processes, which may include Council-facilitated dialogue, referral to other community resources, or collaborative problem-solving approaches."
},
facilitation: {
facilitationText: "Council facilitation typically involves 2-3 members working together to provide balanced perspectives and mutual support. They guide structured dialogue processes, help parties explore underlying needs and interests, facilitate creative problem-solving, and support the development of sustainable agreements."
},
ground_rules: {
groundRulesText: "All participants in Council processes agree to: engage respectfully and constructively; share information honestly while respecting others' privacy; listen with openness to different perspectives; work collaboratively toward mutually beneficial solutions; respect the Council's facilitation role; and support implementation of agreements reached."
}
},
outcome: {
documentation: {
documentationText: "The Council documents resolution agreements with input from all parties, ensuring clarity about commitments and implementation steps. Council records include process notes for learning and improvement purposes, while maintaining confidentiality about personal information shared during facilitation."
},
monitoring: {
monitoringText: "Council members follow up with parties to support implementation of agreements and address any emerging concerns. The Council meets regularly to reflect on its work, identify systemic patterns in community conflicts, and recommend community-wide improvements to prevent future disputes."
}
}
}
}
},
// Referee Protocol Template
{
id: "referee-protocol",
title: "Community Referee",
description: "A neutral third party makes binding decisions after hearing from all parties in a formal but flexible process",
data: {
stages: {
basics: {
community_rules: {
communityRulesText: "The Community Referee system is established by community agreement and operates under procedures that balance formality with accessibility. Referees are selected from trained community members and serve rotating terms. Their decisions are binding within the scope of community authority."
},
shared_values: {
sharedValuesText: "This process values impartial judgment, community wisdom, and efficient resolution of disputes. We trust trained community members to make fair decisions based on community values and established principles while considering the unique circumstances of each situation."
},
information_access: {
informationAccessText: "Participants have the right to present relevant information and evidence to the referee. Referee decisions include reasoning and are made available to the parties and community as appropriate. The process maintains confidentiality of personal information while ensuring transparency in decision-making."
}
},
process: {
process_start: {
processStartText: "Parties may request referee resolution either by mutual agreement or through community referral processes. A referee is selected through established procedures, which may include random selection from qualified pool or mutual agreement by the parties. The referee schedules hearings at convenient times for all parties."
},
facilitation: {
facilitationText: "The referee conducts structured hearings where each party presents their perspective, evidence, and desired outcomes. The referee may ask questions, request additional information, or consult with community members about relevant policies or precedents. Decisions are made within specified timeframes."
},
ground_rules: {
groundRulesText: "All parties agree to: present information truthfully and completely; treat all participants with respect; accept the referee's authority to make binding decisions; comply with procedural requirements and timelines; maintain confidentiality as directed; and implement referee decisions in good faith."
}
},
outcome: {
documentation: {
documentationText: "Referee decisions are documented in writing with clear reasoning, specific requirements for each party, and timelines for implementation. Decisions may include remedial actions, behavior changes, or other appropriate responses. Documentation becomes part of community records for precedent and accountability."
},
monitoring: {
monitoringText: "Implementation of referee decisions is monitored by designated community members who report compliance to the referee and community as needed. Non-compliance may result in additional community consequences. The referee system is evaluated periodically for effectiveness and fairness."
}
}
}
}
}
];
console.log('All templates loaded:', window.allTemplates.length, 'templates available');

View File

@@ -100,6 +100,17 @@ document.addEventListener('DOMContentLoaded', function() {
box-shadow: none !important;
}
/* Make input fields read-only appearance */
#community-name, #protocol-summary {
border: none !important;
background-color: transparent !important;
padding: 0 !important;
pointer-events: none !important;
outline: none !important;
box-shadow: none !important;
color: inherit !important;
}
/* Only show filled textareas */
textarea:not(${contentTextareas.join(',')}) {
display: none !important;
@@ -205,72 +216,129 @@ document.addEventListener('DOMContentLoaded', function() {
// Load template data
let templates = [];
// Function to fetch templates - simplified approach
function fetchTemplates() {
console.log('Fetching templates...');
// Function to initialize templates - now uses Hugo data
function initializeTemplates() {
console.log('Initializing template system...');
// Load all templates at startup
try {
// First try loading from the standard path
fetch('/js/templates/index.js')
.then(response => {
if (!response.ok) {
throw new Error(`Failed to fetch templates: ${response.status} ${response.statusText}`);
}
return response.text();
})
.then(moduleText => {
// Add a script element to the document
const script = document.createElement('script');
script.type = 'module';
script.textContent = moduleText;
document.head.appendChild(script);
// Set a timeout to check for templates
setTimeout(() => {
// See if templates were loaded
if (window.allTemplates && Array.isArray(window.allTemplates)) {
console.log('Templates loaded successfully:', window.allTemplates.length, 'templates found');
templates = window.allTemplates;
// Populate the template selector
populateTemplateSelector(templates);
// Template selection is now handled by buttons in the template options
console.log('Template selection will be handled by buttons in the template options');
} else {
console.error('Templates not available after loading script');
}
}, 500);
})
.catch(error => {
console.error('Error fetching templates:', error);
// Try alternate loading method with ES modules import
console.log('Trying alternate loading method with ES modules...');
import('/js/templates/index.js')
.then(module => {
templates = module.default;
console.log('Templates loaded successfully using ES modules:', templates.length, 'templates found');
// Populate the template selector
populateTemplateSelector(templates);
// Template selection is now handled by buttons in the template options
console.log('Template selection will be handled by buttons in the template options');
})
.catch(importError => {
console.error('ES module import also failed:', importError);
console.error('Could not load templates through either method');
});
});
} catch (e) {
console.error('Error in template loading:', e);
// Check if templates are loaded from Hugo
if (window.allTemplates) {
let templatesData;
// Parse JSON string if needed
if (typeof window.allTemplates === 'string') {
try {
templatesData = JSON.parse(window.allTemplates);
console.log('Parsed templates JSON string successfully');
} catch (error) {
console.error('Failed to parse templates JSON:', error);
return;
}
} else {
templatesData = window.allTemplates;
}
// Convert Hugo data object to array format
if (typeof templatesData === 'object' && !Array.isArray(templatesData)) {
// Hugo data comes as an object, convert to array
templates = Object.values(templatesData);
console.log('Templates loaded from Hugo data:', templates.length, 'templates found');
console.log('Template IDs:', templates.map(t => t.id));
} else if (Array.isArray(templatesData)) {
// Already in array format
templates = templatesData;
console.log('Templates already in array format:', templates.length, 'templates found');
}
// Templates are already in the HTML, so we don't need to populate
// Just add event handlers to existing template options
addTemplateEventHandlers();
return;
}
// Fallback - check periodically if templates aren't immediately available
let checkCount = 0;
const maxChecks = 10; // Check for 5 seconds
const checkForTemplates = setInterval(() => {
checkCount++;
if (window.allTemplates) {
let templatesData;
// Parse JSON string if needed
if (typeof window.allTemplates === 'string') {
try {
templatesData = JSON.parse(window.allTemplates);
} catch (error) {
console.error('Failed to parse templates JSON in polling:', error);
return;
}
} else {
templatesData = window.allTemplates;
}
if (typeof templatesData === 'object' && !Array.isArray(templatesData)) {
templates = Object.values(templatesData);
} else if (Array.isArray(templatesData)) {
templates = templatesData;
}
console.log('Templates found via polling:', templates.length, 'templates');
addTemplateEventHandlers();
clearInterval(checkForTemplates);
} else if (checkCount >= maxChecks) {
console.error('Templates failed to load after', maxChecks * 500, 'ms');
clearInterval(checkForTemplates);
}
}, 500);
}
// Function to populate the template selector with cards
// Function to add event handlers to existing template options in HTML
function addTemplateEventHandlers() {
console.log('Adding event handlers to template options...');
// Add click handlers to all template options
const templateOptions = document.querySelectorAll('.template-option');
templateOptions.forEach(option => {
const templateId = option.getAttribute('data-template-id');
option.addEventListener('click', function() {
console.log('Template option clicked for:', templateId);
console.log('Available templates:', templates);
console.log('Templates array length:', templates.length);
if (templateId === '') {
// "Create Your Own" option
clearAllFields();
} else {
// Find and apply the template
const selectedTemplate = templates.find(t => t.id === templateId);
console.log('Found template:', selectedTemplate);
if (selectedTemplate) {
applyTemplate(selectedTemplate);
// Close the template section after selection
const templateSection = document.querySelector('.protocol-template-selector');
if (templateSection) {
const templateBody = templateSection.querySelector('.template-body');
const toggleBtn = templateSection.querySelector('.toggle-btn');
if (templateBody && toggleBtn) {
templateBody.style.display = 'none';
toggleBtn.textContent = '+';
}
}
} else {
console.error('Template not found:', templateId);
console.error('Available template IDs:', templates.map(t => t.id));
}
}
});
console.log('Added event handler for template:', templateId || 'Create Your Own');
});
}
// Function to populate the template selector with cards (legacy - kept for compatibility)
function populateTemplateSelector(templatesList) {
if (!templatesList || templatesList.length === 0) {
console.error('Cannot populate template selector - missing templates');
@@ -565,8 +633,8 @@ document.addEventListener('DOMContentLoaded', function() {
// No helper functions needed anymore as we've simplified the approach
// Start loading templates
fetchTemplates();
// Initialize template system
initializeTemplates();
// Protocol data structure
let protocol = {

View File

@@ -1,26 +1,34 @@
console.log('Testing toggle button functionality');
// Debug script to inspect template loading
// Debug script for dispute protocol builder
console.log("Debug script loaded");
document.addEventListener('DOMContentLoaded', function() {
console.log("DOM loaded in debug script");
// Log raw templates
console.log("Raw Protocol Templates:", typeof rawProtocolTemplates !== 'undefined' ? rawProtocolTemplates.length : "undefined");
if (typeof rawProtocolTemplates !== 'undefined') {
console.log("Template titles:", rawProtocolTemplates.map(t => t.title));
}
// Log processed templates
// Check template system after a delay
setTimeout(() => {
const templateSelect = document.getElementById('protocol-template');
if (templateSelect) {
console.log("Template options:", templateSelect.options.length);
const options = Array.from(templateSelect.options).map(o => o.textContent);
console.log("Option texts:", options);
// Check if templates are loaded
if (window.allTemplates) {
let templatesData;
try {
templatesData = typeof window.allTemplates === 'string' ?
JSON.parse(window.allTemplates) : window.allTemplates;
const templateCount = Object.keys(templatesData).length;
console.log(`✓ Templates loaded: ${templateCount} templates available`);
console.log("Template IDs:", Object.keys(templatesData));
} catch (error) {
console.error("✗ Error parsing templates:", error);
}
} else {
console.log("Template select element not found");
console.warn("Templates not found in window.allTemplates");
}
}, 1000);
// Check if template options are in the DOM
const templateOptions = document.querySelectorAll('.template-option');
console.log(`✓ Template options in DOM: ${templateOptions.length} found`);
// Check if form fields exist
const textareas = document.querySelectorAll('textarea');
console.log(`✓ Form fields: ${textareas.length} textareas found`);
}, 500);
});

View File

@@ -71,4 +71,4 @@ const chosenFacilitatorTemplate = {
};
// Export the template
export default chosenFacilitatorTemplate;
window.chosenFacilitatorTemplate = chosenFacilitatorTemplate;

View File

@@ -71,4 +71,4 @@ const facilitationCouncilTemplate = {
};
// Export the template
export default facilitationCouncilTemplate;
window.facilitationCouncilTemplate = facilitationCouncilTemplate;

View File

@@ -1,31 +1,58 @@
// Template index file
// This file imports and exports all templates
// Template index file - dynamically loads all template files
// This automatically discovers and loads any .js files in the templates folder
import shalishMediationTemplate from './shalish-mediation.js';
import restorativeJusticeTemplate from './restorative-justice.js';
import transformativeJusticeTemplate from './transformative-justice.js';
import juryProtocolTemplate from './jury-protocol.js';
import refereeProtocolTemplate from './referee-protocol.js';
import peerToPeerTemplate from './peer-to-peer.js';
import chosenFacilitatorTemplate from './chosen-facilitator.js';
import facilitationCouncilTemplate from './facilitation-council.js';
(async function loadAllTemplates() {
console.log('Dynamically loading all templates...');
// List of template filenames - add new templates here
const templateFiles = [
'shalish-mediation.js',
'restorative-justice.js',
'transformative-justice.js',
'jury-protocol.js',
'referee-protocol.js',
'peer-to-peer.js',
'chosen-facilitator.js',
'facilitation-council.js'
];
const templates = [];
try {
// Load each template file
for (const filename of templateFiles) {
try {
console.log(`Loading template: ${filename}`);
const module = await import(`./${filename}`);
if (module.default) {
templates.push(module.default);
console.log(`✓ Loaded template: ${module.default.title || filename}`);
} else {
console.warn(`✗ Template ${filename} has no default export`);
}
} catch (error) {
console.warn(`✗ Failed to load template ${filename}:`, error);
// Continue loading other templates even if one fails
}
}
// Set global variable
window.allTemplates = templates;
console.log(`Successfully loaded ${templates.length} templates out of ${templateFiles.length} files`);
// Dispatch event to notify other scripts that templates are ready
window.dispatchEvent(new CustomEvent('templatesLoaded', { detail: templates }));
} catch (error) {
console.error('Critical error loading templates:', error);
// Fallback: set empty array so the app doesn't break
window.allTemplates = [];
window.dispatchEvent(new CustomEvent('templatesLoaded', { detail: [] }));
}
})();
// Export the array of all templates
const templates = [
shalishMediationTemplate,
restorativeJusticeTemplate,
transformativeJusticeTemplate,
juryProtocolTemplate,
refereeProtocolTemplate,
peerToPeerTemplate,
chosenFacilitatorTemplate,
facilitationCouncilTemplate
];
// Set a global variable for non-module contexts
if (typeof window !== 'undefined') {
console.log('Setting global templates variable with', templates.length, 'templates');
window.allTemplates = templates;
}
export default templates;
// Instructions for adding new templates:
// 1. Create your new template file (e.g., 'my-new-template.js') in this folder
// 2. Add the filename to the templateFiles array above
// 3. The template will be automatically loaded and available in the UI

View File

@@ -71,4 +71,4 @@ const juryProtocolTemplate = {
};
// Export the template
export default juryProtocolTemplate;
window.juryProtocolTemplate = juryProtocolTemplate;

View File

@@ -71,4 +71,4 @@ const peerToPeerTemplate = {
};
// Export the template
export default peerToPeerTemplate;
window.peerToPeerTemplate = peerToPeerTemplate;

View File

@@ -71,4 +71,4 @@ const refereeProtocolTemplate = {
};
// Export the template
export default refereeProtocolTemplate;
window.refereeProtocolTemplate = refereeProtocolTemplate;

View File

@@ -71,4 +71,4 @@ const restorativeJusticeTemplate = {
};
// Export the template
export default restorativeJusticeTemplate;
window.restorativeJusticeTemplate = restorativeJusticeTemplate;

View File

@@ -71,4 +71,5 @@ const shalishMediationTemplate = {
};
// Export the template
export default shalishMediationTemplate;
// Make available globally
window.shalishMediationTemplate = shalishMediationTemplate;

View File

@@ -71,4 +71,4 @@ const transformativeJusticeTemplate = {
};
// Export the template
export default transformativeJusticeTemplate;
window.transformativeJusticeTemplate = transformativeJusticeTemplate;