Skip to content

Commit

Permalink
Sync: 2024-01-25 20:35:16
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelAllen committed Jan 26, 2024
1 parent 314ed0b commit 4ae0a6f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Rock/z_Other/delete-person-records.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tags:
- language/sql
- type/cleanup
date created: 2024-01-25 18:04:56
date modified: 2024-01-25 20:02:13
date modified: 2024-01-25 20:33:43
---

# Delete Person Records
Expand All @@ -12,7 +12,7 @@ date modified: 2024-01-25 20:02:13
Delete person records in bulk. Handles cleaning up date from all of the related tables.

This is primarily used to cleanup after a bot attatck.
This is primarily used to cleanup after a bot attack.

> [!Danger]
> This will **permanently delete** data from Rock. Do not run this unless you are 100% confident that the SELECT statement is correct and you have made a backup.
Expand Down
92 changes: 92 additions & 0 deletions Rock/z_Other/obsidian-mutation-observer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
tags:
- language/js
- type/utility
date created: 2024-01-25 20:04:07
date modified: 2024-01-25 20:24:18
---

# Obsidian Mutation Observer

If you are trying to make changes to the DOM of an Obsidian control, you will have to use a mutation observer.

> [!Warning]
> Because the observer fires on any change, you need to be careful about having a stop condition. Otherwise, your change will trigger the observer again; potentially causing an infinite loop.
## Example 1 - Registration Block

I want to change the text "How many ___ will you be registering?" to "How many ___ will you be purchasing?"

```liquid
<script>
function updateTitle() {
var title = $('.registrationentry-intro h1');
var needsUpdate = title.text().includes('registering');
if (title && needsUpdate) {
title.text(title.text().replace('registering','purchasing'));
}
}
const observer = new MutationObserver(updateTitle);
$(function() {
updateTitle();
observer.observe(document, { childList: true, subtree: true });
});
</script>
```

## Example 2 - Add "Gross, Fee, Net" Table to Batch Detail Screen

```liquid
{% capture CustomDetails %}
[
{% for Transaction in Context.FinancialBatch.Transactions %}
{% for Detail in Transaction.TransactionDetails %}
{
'AccountName' : {{ Detail.Account.Name | ToJSON }},
'Amount' : {{ Detail.Amount | AsDecimal }},
'Fee' : {{ Detail.FeeAmount | Default:'0' | AsDecimal }}
},
{% endfor %}
{% endfor %}
]
{% endcapture %}
{% assign CustomDetails = CustomDetails | FromJSON | GroupBy:'AccountName' %}
<script>
function addTable() {
var updated = ($('.financial-batch-detail .grid-table').first().parent().html() ?? '').includes("Fee");
if (! updated) {
var tableContent = '' +
'<table class="grid-table table table-auto">' +
'<tbody>' +
'<tr>' +
'<th align="left">Account</th>' +
'<th align="right">Gross</th>' +
'<th align="right">Fee</th>' +
'<th align="right">Net</th>' +
'</tr>' +
{%- for Account in CustomDetails -%}
{%- assign AccountParts = Account | PropertyToKeyValue -%}
{%- assign Name = AccountParts.Key -%}
{%- assign Gross = AccountParts.Value | Select:'Amount' | Sum -%}
{%- assign Fee = AccountParts.Value | Select:'Fee' | Sum -%}
'<tr>' +
'<td align="left">{{ Name }}</td>' +
'<td align="right">${{ Gross | Format:'#,##0.00' }}</td>' +
'<td align="right">$({{ Fee | Format:'#,##0.00' }})</td>' +
'<td align="right">${{ Gross | Minus:Fee | Format:'#,##0.00'}}</td>' +
'</tr>' +
{%- endfor -%}
'</tbody>' +
'</table>';
$('.financial-batch-detail .grid-table').first().parent().html(tableContent);
}
}
const observer = new MutationObserver(addTable);
$(function() {
addTable();
observer.observe(document.getElementById('bid_2847'), { childList: true, subtree: true });
});
</script>
```
2 changes: 1 addition & 1 deletion Rock/z_Other/run-javascript-on-page-load.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ date modified: 2024-01-25 20:03:36

There are 2 options here. Which one to use depends on what you are trying to do. I tent to use option 1 as a default, and only switch to option 2 if I need to have my code run on every postback (ex: modifying a control on the page that changes on postback)

If you need to interact with an Obsidian control, neither of these options will work. You will have to use a mutation observer instead.
If you need to interact with an Obsidian control, neither of these options will work. You will have to use a [[obsidian-mutation-observer|mutation observer]] instead.

## Option 1 - jQuery

Expand Down

0 comments on commit 4ae0a6f

Please sign in to comment.