From 41b4b34d4f0dd76c09d0b20563aab0851d7b8f7c Mon Sep 17 00:00:00 2001 From: meichthys Date: Mon, 10 Nov 2025 06:01:03 +0000 Subject: [PATCH] Add AndBible Integration. --- .../church_bible_reference.js | 32 +++++++++++++++++++ .../church_bible_verse/church_bible_verse.js | 29 +++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/church/church_study/doctype/church_bible_reference/church_bible_reference.js b/church/church_study/doctype/church_bible_reference/church_bible_reference.js index a31305d..9164287 100644 --- a/church/church_study/doctype/church_bible_reference/church_bible_reference.js +++ b/church/church_study/doctype/church_bible_reference/church_bible_reference.js @@ -1,6 +1,38 @@ frappe.ui.form.on("Church Bible Reference", { import_reference_text: frm => { fetch_bible_text(frm); + }, + refresh: async function(frm) { + frm.add_custom_button('Open in AndBible', async function() { + const start_verse = await frappe.get_doc("Church Bible Verse", frm.doc.start_verse); + if (!start_verse.book || !start_verse.chapter || !start_verse.verse) { + frappe.msgprint(__('Please make sure reference Start Verse has a Chapter and Verse.')); + return; + } + + try { + // Fetch abbreviation from linked Church Bible Book record + const book = await frappe.db.get_doc('Church Bible Book', start_verse.book); + const abbreviation = book.abbreviation; + + if (!abbreviation) { + frappe.msgprint(__(`No abbreviation found for Book: ${book}.`)); + return; + } + + // Construct OSIS reference (e.g., Gen.1.1) + const osisRef = `${abbreviation}.${start_verse.chapter}.${start_verse.verse}`; + + // Build AndBible deep link + const url = `https://read.andbible.org/${osisRef}`; + + // Open the link (will launch AndBible if installed) + window.open(url, '_blank'); + } catch (error) { + frappe.msgprint(__('Failed to open verse in AndBible.')); + console.error(error); + } + }); } }); diff --git a/church/church_study/doctype/church_bible_verse/church_bible_verse.js b/church/church_study/doctype/church_bible_verse/church_bible_verse.js index d7afe92..dbfdb9d 100644 --- a/church/church_study/doctype/church_bible_verse/church_bible_verse.js +++ b/church/church_study/doctype/church_bible_verse/church_bible_verse.js @@ -31,6 +31,35 @@ frappe.ui.form.on('Church Bible Verse', { frm.set_df_property('verse', 'options', Array.from({ length: 176 }, (_, i) => i + 1).join('\n')); } } + frm.add_custom_button('Open in AndBible', async function() { + if (!frm.doc.book || !frm.doc.chapter || !frm.doc.verse) { + frappe.msgprint(__('Please make sure Book, Chapter, and Verse are filled in.')); + return; + } + + try { + // Fetch abbreviation from linked Church Bible Book record + const bookData = await frappe.db.get_doc('Church Bible Book', frm.doc.book); + const abbreviation = bookData.abbreviation; + + if (!abbreviation) { + frappe.msgprint(__('No abbreviation found for this Book.')); + return; + } + + // Construct OSIS reference (e.g., Gen.1.1) + const osisRef = `${abbreviation}.${frm.doc.chapter}.${frm.doc.verse}`; + + // Build AndBible deep link + const url = `https://read.andbible.org/${osisRef}`; + + // Open the link (will launch AndBible if installed) + window.open(url, '_blank'); + } catch (error) { + frappe.msgprint(__('Failed to open verse in AndBible.')); + console.error(error); + } + }); }, book: async function(frm) {