From 34d1285e4b0fbae4e43b0692c9b39c61ec39cf51 Mon Sep 17 00:00:00 2001
From: j <j@mailb.org>
Date: Fri, 24 Jan 2025 19:54:18 +0530
Subject: [PATCH] transcribe audio dialog

---
 pandora/config.padma.jsonc   |  1 +
 pandora/config.pandora.jsonc |  1 +
 static/js/editor.js          | 37 ++++++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+)

diff --git a/pandora/config.padma.jsonc b/pandora/config.padma.jsonc
index 3bd3b748b..82fe120c7 100644
--- a/pandora/config.padma.jsonc
+++ b/pandora/config.padma.jsonc
@@ -56,6 +56,7 @@
         "canExportAnnotations": {"member": true, "staff": true, "admin": true},
         "canImportAnnotations": {"member": true, "staff": true, "admin": true},
         "canImportItems": {"member": true, "staff": true, "admin": true},
+        "canTranscribeAudio": {"staff": true, "admin": true},
         "canManageDocuments": {"member": true, "staff": true, "admin": true},
         "canManageEntities": {"member": true, "staff": true, "admin": true},
         "canManageHome": {"staff": true, "admin": true},
diff --git a/pandora/config.pandora.jsonc b/pandora/config.pandora.jsonc
index 51aaee249..5f08873f8 100644
--- a/pandora/config.pandora.jsonc
+++ b/pandora/config.pandora.jsonc
@@ -63,6 +63,7 @@ examples (config.SITENAME.jsonc) that are part of this pan.do/ra distribution.
         "canExportAnnotations": {"member": true, "staff": true, "admin": true},
         "canImportAnnotations": {"member": true, "staff": true, "admin": true},
         "canImportItems": {"member": true, "staff": true, "admin": true},
+        "canTranscribeAudio": {},
         "canManageDocuments": {"member": true, "staff": true, "admin": true},
         "canManageEntities": {"member": true, "staff": true, "admin": true},
         "canManageHome": {"staff": true, "admin": true},
diff --git a/static/js/editor.js b/static/js/editor.js
index 19a9f99e0..82a75344a 100644
--- a/static/js/editor.js
+++ b/static/js/editor.js
@@ -27,6 +27,7 @@ pandora.ui.editor = function(data) {
             enableDownload: pandora.hasCapability('canDownloadVideo') >= data.rightslevel || data.editable,
             enableExport: pandora.hasCapability('canExportAnnotations') || data.editable,
             enableImport: pandora.hasCapability('canImportAnnotations') || data.editable,
+            enableTranscribe: pandora.hasCapability('canTranscribeAudio') && data.editable,
             enableSetPosterFrame: !pandora.site.media.importFrames && data.editable,
             enableSubtitles: ui.videoSubtitles,
             find: ui.itemFind,
@@ -432,6 +433,42 @@ pandora.ui.editor = function(data) {
             togglesize: function(data) {
                 pandora.UI.set({videoSize: data.size});
             },
+            transcribeaudio: function() {
+                const $dialog = pandora.ui.iconDialog({
+                    buttons: [
+                        Ox.Button({
+                                id: 'cancel',
+                                title: Ox._('Cancel')
+                            })
+                            .bindEvent({
+                                click: function() {
+                                    $dialog.close();
+                                }
+                            }),
+                        Ox.Button({
+                                id: 'transcribe',
+                                title: Ox._('Transcribe Audio')
+                            })
+                            .bindEvent({
+                                click: function() {
+                                    $dialog.close();
+                                    pandora.api.transcribeAudio({
+                                        item: pandora.user.ui.item
+                                    })
+                                }
+                            })
+                    ],
+                    content: Ox._(
+                        'Are you sure you want to add automated transcription to "{0}"',
+                        [data.title]
+                    ),
+                    keys: {enter: 'transcribe', escape: 'cancel'},
+                    title: Ox._(
+                        'Transcribe {0} {1}', [data.title]
+                    )
+                });
+                $dialog.open()
+            },
             pandora_showannotations: function(data) {
                 that.options({showAnnotations: data.value});
             },