Ignore:
Timestamp:
2021-08-09T10:44:46+12:00 (3 years ago)
Author:
davidb
Message:

Add transcription remove button

Location:
main/trunk/model-interfaces-dev/atea
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/js/asr/asr-controller.js

    r35262 r35265  
    122122function insertTranscription(transcription)
    123123{
    124     // Insert a new transcription row
     124    // Create a new transcription row
    125125    /** @type {HTMLLIElement} */
    126126    const clone = TRANSCRIPTION_TEMPLATE.content.firstElementChild.cloneNode(true);
    127127
    128     // TODO: Give all children of the node the fileName data item.
    129     clone.dataset.fileName = transcription.file_name;
    130 
    131128    const fileNameElement = clone.querySelector(".transcription__file-name");
    132129    fileNameElement.textContent = transcription.file_name;
    133130
    134131    // Hook up the remove button
    135     /** @type {HTMLButtonElement[]} */
    136     const removeButton = clone.querySelectorAll("transcription__remove-button");
    137     removeButton.forEach
    138     (
    139         button =>
    140         {
    141             button.onclick = function() {
    142 
    143             }
    144         }
    145     );
    146    
    147     // Get the metadata list and template
    148     /** @type {HTMLUListElement} */
    149     const metadataList = clone.querySelector(".metadata-list");
    150 
     132    /** @type {HTMLButtonElement} */
     133    const removeButton = clone.querySelector(".transcription__remove-button");
     134    removeButton.onclick = onDeleteTranscription;
     135
     136    loadAudioFile(transcription.file_name);
     137   
    151138    // Prepare the audio slider
    152     loadAudioFile(transcription.file_name);
    153 
    154139    /** @type {HTMLInputElement} */
    155140    const audioSlider = clone.querySelector(".audio-slider");
    156141    audioSlider.max = TRANSCRIPTION_AUDIO_ELEMENT.duration;
    157142    audioSlider.step = 0.01;
     143
     144    // Get the metadata list
     145    /** @type {HTMLUListElement} */
     146    const metadataList = clone.querySelector(".metadata-list");
    158147   
    159148    // Insert metadata rows
    160149    for (const metadata of transcription.metadata) {
    161         metadataList.appendChild(buildMetadataNode(metadata, transcription.file_name));
    162     }
     150        metadataList.appendChild(buildMetadataNode(metadata));
     151    }
     152
     153    // Set the filename data property on every element in the clone's DOM node
     154    recurseAddData(clone, "file-name", transcription.file_name);
    163155   
    164156    TRANSCRIPTIONS_LIST.appendChild(clone);
     
    175167 * @returns {Node} The constructed DOM node.
    176168 */
    177 function buildMetadataNode(metadata, fileName)
     169function buildMetadataNode(metadata)
    178170{
    179171    const metadataClone = metadataTemplate.content.firstElementChild.cloneNode(true);
     
    184176    /** @type {HTMLButtonElement} */
    185177    const button = metadataClone.querySelector("button");
    186    
    187     button.dataset.fileName = fileName;
     178
    188179    button.onclick = function(e)
    189180    {
     
    229220}
    230221
     222/**
     223 * Removes a transcription from the DOM.
     224 *
     225 * @param {MouseEvent} ev The mouse click event.
     226 */
     227function onDeleteTranscription(ev)
     228{
     229    const fileName = ev.target.dataset.fileName;
     230    const child = document.querySelector(`.transcription__container[data-file-name='${fileName}']`);
     231
     232    TRANSCRIPTIONS_LIST.removeChild(child);
     233    cachedAudioFileList.delete(fileName);
     234}
     235
     236/**
     237 * Recurses through the entire tree of a parent and adds the given data attribute.
     238 *
     239 * @param {HTMLElement} parent The parent node.
     240 * @param {String} dataElementname The name of the data element. Must use hyphen notation, rather than camel case.
     241 * @param {String} value The value of the data element.
     242 */
     243function recurseAddData(parent, dataElementName, value)
     244{
     245    parent.setAttribute("data-" + dataElementName, value);
     246
     247    for (const child of parent.children) {
     248        recurseAddData(child, dataElementName, value);
     249    }
     250}
     251
    231252/** @type {HTMLTemplateElement} */
    232253const errorTemplate = document.querySelector("#errorTemplate");
     
    261282});
    262283
    263 // whenever we hover over a menu item that has a submenu
    264284$('.tooltip-parent').on('mouseover', function() {
    265285    var $menuItem = $(this),
  • main/trunk/model-interfaces-dev/atea/style/asr.css

    r35262 r35265  
    6161    border-radius: 50%;
    6262    padding: 0.2em;
     63    cursor: pointer;
    6364
    6465    -webkit-transition-duration: 0.2s;
  • main/trunk/model-interfaces-dev/atea/transform/pages/asr.xsl

    r35262 r35265  
    5151            <div class="audio-slider__container">
    5252                <button type="button" class="btn-fab btn-fab-small">
    53                     <span class="material-icons">&#xE037;</span>
     53                    <span class="material-icons">&#xE037;</span> <!-- play_arrow -->
    5454                </button>
    5555                <input type="range" min="0" value="0" class="audio-slider__range" />
     
    7373                        <div class="transcription__header">
    7474                            <button class="btn-fab transcription__play-button" type="button">
    75                                 <span class="material-icons">&#xE037;</span>
     75                                <span class="material-icons">&#xE037;</span> <!-- play_arrow -->
    7676                            </button>
    7777                            <button class="btn-fab transcription__remove-button" type="button">
    78                                 <span class="material-icons">&#xE872;</span>
     78                                <span class="material-icons">&#xE872;</span> <!-- delete -->
    7979                            </button>
    8080                            <p class="transcription__file-name"></p>   
Note: See TracChangeset for help on using the changeset viewer.