mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-04 07:09:14 +00:00
Refactor and update order cycle form controller [OFN-11613]
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#save-bar.animate-show{ "ng-show": 'dirty || persist || StatusMessage.active()' }
|
||||
.container
|
||||
.seven.columns.alpha
|
||||
%h5#status-message{ "ng-show": "StatusMessage.invalidMessage == ''", "ng-style": 'StatusMessage.statusMessage.style', data: { 'order-cycle-form-target': 'element' }, "ng-attr-data-type": "{{StatusMessage.statusMessage.type}}", "ng-attr-data-action-name": "{{StatusMessage.statusMessage.actionName}}" }
|
||||
%h5#status-message{ "ng-show": "StatusMessage.invalidMessage == ''", "ng-style": 'StatusMessage.statusMessage.style', data: { 'order-cycle-form-target': 'statusMessage' }, "ng-attr-data-type": "{{StatusMessage.statusMessage.type}}", "ng-attr-data-action-name": "{{StatusMessage.statusMessage.actionName}}" }
|
||||
{{ StatusMessage.statusMessage.text || " " }}
|
||||
%h5#status-message{ style: 'color: #C85136', "ng-show": "StatusMessage.invalidMessage !== ''" }
|
||||
{{ StatusMessage.invalidMessage || " " }}
|
||||
|
||||
@@ -310,8 +310,7 @@ module Admin
|
||||
def same_dates(date, string)
|
||||
false unless date && string
|
||||
|
||||
DateTime.parse(string).strftime('%Y-%m-%d %H:%M') ==
|
||||
date.to_datetime.strftime('%Y-%m-%d %H:%M')
|
||||
DateTime.parse(string).to_fs(:short) == date.to_fs(:short)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { Controller } from "stimulus";
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ['element']
|
||||
static targets = ['statusMessage']
|
||||
connect() {
|
||||
console.log(this.statusMessageTarget)
|
||||
this.observer = new MutationObserver(this.updateCallback);
|
||||
this.observer.observe(
|
||||
this.elementTarget,
|
||||
this.statusMessageTarget,
|
||||
{ attributes: true, attributeOldValue: true, attributeFilter: ['data-type'] }
|
||||
);
|
||||
}
|
||||
|
||||
// Callback to trigger warning modal
|
||||
updateCallback(mutationsList) {
|
||||
const newDataType = $('#status-message').attr('data-type');
|
||||
const actionName = $('#status-message').attr('data-action-name');
|
||||
const newDataType = document.getElementById('status-message').getAttribute('data-type');
|
||||
const actionName = document.getElementById('status-message').getAttribute('data-action-name');
|
||||
if(!actionName) return;
|
||||
|
||||
for(let mutation of mutationsList) {
|
||||
@@ -21,10 +22,18 @@ export default class extends Controller {
|
||||
// Only trigger warning modal when notice display (notice) is preceeded by progress display (progress)
|
||||
if(mutation.oldValue === 'progress' && newDataType === 'notice') {
|
||||
// Hide all confirmation buttons in warning modal
|
||||
$('#linked-order-warning-modal .modal-actions button.secondary').css({ display: 'none' })
|
||||
document.querySelectorAll(
|
||||
'#linked-order-warning-modal .modal-actions button.secondary'
|
||||
).forEach((node) => {
|
||||
node.style.display = 'none';
|
||||
});
|
||||
// Show the appropriate confirmation button, open warning modal, and return
|
||||
$(`#linked-order-warning-modal button[data-trigger-action=${actionName}]`).css({ display: 'block' });
|
||||
$('.warning-modal button.modal-target-trigger').trigger('click');
|
||||
document.querySelectorAll(
|
||||
`#linked-order-warning-modal button[data-trigger-action=${actionName}]`
|
||||
).forEach((node) => {
|
||||
node.style.display = 'block';
|
||||
})
|
||||
document.querySelector('.warning-modal button.modal-target-trigger').click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user