Files
animal_management/views/animals/progress-updates.php
2026-04-04 13:13:00 -04:00

695 lines
33 KiB
PHP

<?php
use humhub\modules\animal_management\models\Animal;
use humhub\modules\animal_management\helpers\DateDisplayHelper;
use humhub\modules\animal_management\models\AnimalGalleryItem;
use humhub\modules\animal_management\models\AnimalProgressUpdate;
use humhub\modules\animal_management\models\forms\AnimalProgressUpdateForm;
use humhub\modules\space\models\Space;
use humhub\widgets\Button;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
/* @var Space $space */
/* @var Animal $animal */
/* @var bool $canManage */
/* @var AnimalProgressUpdateForm $progressUpdateForm */
/* @var AnimalProgressUpdate[] $progressUpdates */
/* @var AnimalGalleryItem[] $galleryItems */
$renderCustomField = static function (string $fieldKey, AnimalProgressUpdateForm $model, array $definitions): string {
if (!isset($definitions[$fieldKey])) {
return '';
}
$definition = $definitions[$fieldKey];
$inputType = (string)$definition['input_type'];
$label = (string)$definition['label'];
if ((int)$definition['required'] === 1) {
$label .= ' *';
}
$fieldName = "AnimalProgressUpdateForm[customFields][$fieldKey]";
$fieldValue = $model->customFields[$fieldKey] ?? '';
ob_start();
?>
<?php if ($inputType === 'textarea'): ?>
<div class="form-group">
<label class="control-label" for="animalprogressupdateform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::textarea($fieldName, (string)$fieldValue, ['class' => 'form-control', 'rows' => 3, 'id' => "animalprogressupdateform-customfields-$fieldKey"]) ?>
</div>
<?php elseif ($inputType === 'boolean'): ?>
<div class="checkbox" style="margin-bottom:10px;">
<label>
<?= Html::hiddenInput($fieldName, '0') ?>
<?= Html::checkbox($fieldName, !empty($fieldValue), ['value' => '1']) ?>
<?= Html::encode($label) ?>
</label>
</div>
<?php elseif ($inputType === 'select'): ?>
<div class="form-group">
<label class="control-label" for="animalprogressupdateform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::dropDownList(
$fieldName,
(string)$fieldValue,
$model->getCustomFieldSelectOptions($fieldKey),
['class' => 'form-control', 'prompt' => Yii::t('AnimalManagementModule.base', 'Select...'), 'id' => "animalprogressupdateform-customfields-$fieldKey"]
) ?>
</div>
<?php elseif ($inputType === 'number'): ?>
<div class="form-group">
<label class="control-label" for="animalprogressupdateform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::input('number', $fieldName, (string)$fieldValue, ['class' => 'form-control', 'step' => 'any', 'id' => "animalprogressupdateform-customfields-$fieldKey"]) ?>
</div>
<?php elseif ($inputType === 'date'): ?>
<div class="form-group">
<label class="control-label" for="animalprogressupdateform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::input('date', $fieldName, (string)$fieldValue, ['class' => 'form-control', 'id' => "animalprogressupdateform-customfields-$fieldKey"]) ?>
</div>
<?php elseif ($inputType === 'datetime'): ?>
<div class="form-group">
<label class="control-label" for="animalprogressupdateform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::input('datetime-local', $fieldName, (string)$fieldValue, ['class' => 'form-control', 'id' => "animalprogressupdateform-customfields-$fieldKey"]) ?>
</div>
<?php else: ?>
<div class="form-group">
<label class="control-label" for="animalprogressupdateform-customfields-<?= Html::encode($fieldKey) ?>"><?= Html::encode($label) ?></label>
<?= Html::textInput($fieldName, (string)$fieldValue, ['class' => 'form-control', 'id' => "animalprogressupdateform-customfields-$fieldKey"]) ?>
</div>
<?php endif; ?>
<?php
return (string)ob_get_clean();
};
$progressCustomDefinitions = $progressUpdateForm->getCustomFieldDefinitions();
$knownProgressKeys = ['progress_notes', 'routine_updates', 'media_reference'];
$otherProgressCustomDefinitions = [];
foreach ($progressCustomDefinitions as $fieldKey => $definition) {
if (in_array($fieldKey, $knownProgressKeys, true)) {
continue;
}
$otherProgressCustomDefinitions[$fieldKey] = $definition;
}
$currentMediaReference = trim((string)($progressUpdateForm->customFields['media_reference'] ?? ''));
$progressAddModalId = 'add-progress-update-modal';
$progressFormId = 'add-progress-update-main-form';
$openProgressEditId = (int)Yii::$app->request->get('inlineProgressEdit', 0);
$openProgressAdd = (int)Yii::$app->request->get('inlineProgressAdd', 0) === 1;
?>
<style>
.progress-feed-card {
position: relative;
overflow: hidden;
border: 1px solid #d5dfe8;
border-radius: 12px;
background: #223446;
margin-bottom: 12px;
min-height: 240px;
box-shadow: 0 8px 22px rgba(12, 24, 36, 0.16);
}
.progress-feed-cover {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.progress-feed-overlay {
position: absolute;
inset: 0;
background: linear-gradient(110deg, rgba(10, 18, 28, 0.28) 10%, rgba(10, 18, 28, 0.55) 52%, rgba(10, 18, 28, 0.75) 100%);
}
.progress-feed-content {
position: relative;
z-index: 1;
min-height: 240px;
padding: 14px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 10px;
}
.progress-feed-top-row {
width: 100%;
max-width: none;
margin-left: 0;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.progress-feed-date {
font-size: 15px;
font-weight: 700;
color: #ffffff;
margin-right: auto;
}
.progress-chip-row {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 10px;
}
.progress-chip-row--top {
margin-bottom: 0;
justify-content: flex-end;
}
.progress-chip {
display: inline-block;
background: rgba(255, 255, 255, 0.16);
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 999px;
padding: 4px 10px;
font-size: 12px;
color: #ffffff;
}
.progress-feed-details {
width: 55%;
max-width: 55%;
min-width: 0;
margin-left: auto;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.22);
background: rgba(10, 18, 28, 0.5);
backdrop-filter: blur(2px);
padding: 12px;
color: #ecf2f8;
}
.progress-feed-header {
display: flex;
justify-content: flex-end;
align-items: flex-start;
gap: 8px;
margin-bottom: 8px;
}
.progress-feed-label {
font-size: 11px;
text-transform: uppercase;
letter-spacing: .04em;
color: rgba(231, 241, 249, 0.78);
margin-bottom: 4px;
}
.progress-feed-copy {
color: #eff5fb;
margin-bottom: 10px;
}
.progress-feed-inline-editor {
position: relative;
z-index: 2;
width: auto;
max-width: none;
min-width: 0;
margin: 0 0 14px 0;
padding-top: 0;
align-self: stretch;
box-sizing: border-box;
}
.progress-feed-inline-editor iframe {
display: block;
width: 100%;
}
@media (max-width: 1200px) {
.progress-feed-details {
width: 55%;
max-width: 55%;
min-width: 0;
}
}
@media (max-width: 991px) {
.progress-feed-details {
width: 55%;
max-width: 55%;
min-width: 0;
}
.progress-chip-row--top {
justify-content: flex-start;
}
}
</style>
<div id="progress-updates-page" class="panel panel-default">
<div class="panel-heading" style="display:flex;align-items:center;">
<span style="font-size:20px;line-height:1.2;"><?= Yii::t('AnimalManagementModule.base', '<strong>Progress Feed</strong>') ?></span>
</div>
<div class="panel-body">
<div style="display:flex;gap:18px;flex-wrap:wrap;align-items:center;margin-bottom:12px;">
<?= Html::a(
Html::encode($animal->getDisplayName()),
$space->createUrl('/animal_management/animals/view', ['id' => $animal->id]),
['style' => 'font-size:20px;font-weight:700;line-height:1.2;']
) ?>
<?= Html::a(
Yii::t('AnimalManagementModule.base', 'All Animals'),
$space->createUrl('/animal_management/animals/index'),
['style' => 'font-size:16px;line-height:1.2;']
) ?>
<?php if ($canManage): ?>
<?= Html::a('<i class="fa fa-plus"></i> ' . Yii::t('AnimalManagementModule.base', 'Add Progress Update'), '#progress-add-inline', [
'class' => 'btn btn-success btn-sm',
'title' => Yii::t('AnimalManagementModule.base', 'Add Progress Update'),
'aria-label' => Yii::t('AnimalManagementModule.base', 'Add Progress Update'),
'data-toggle' => 'collapse',
]) ?>
<?php endif; ?>
</div>
<?php if ($canManage): ?>
<div id="progress-add-inline" class="collapse progress-feed-inline-editor<?= $openProgressAdd ? ' in' : '' ?>" style="margin:0 0 14px 0;">
<iframe
src="<?= Html::encode($space->createUrl('/animal_management/animals/add-progress-update-inline', ['id' => $animal->id, 'inline' => 1, 'returnTo' => 'progress-updates', '_v' => time()])) ?>"
style="width:100%;min-height:860px;border:1px solid rgba(255,255,255,0.22);border-radius:10px;background:transparent;"
loading="lazy"
></iframe>
</div>
<?php endif; ?>
<?php if (empty($progressUpdates)): ?>
<div class="text-muted" style="margin-bottom:10px;"><?= Yii::t('AnimalManagementModule.base', 'No progress updates recorded.') ?></div>
<?php else: ?>
<?php foreach ($progressUpdates as $update): ?>
<?php
$progressCustomValues = $update->getCustomFieldDisplayValues($canManage);
$mediaReference = '';
$progressCustomDisplayValues = [];
foreach ($progressCustomValues as $customField) {
if ((string)($customField['field_key'] ?? '') === 'media_reference') {
$mediaReference = trim((string)$customField['value']);
continue;
}
$progressCustomDisplayValues[] = $customField;
}
$hasMediaImage = $mediaReference !== '' && (preg_match('/^https?:\/\//i', $mediaReference) || substr($mediaReference, 0, 1) === '/');
?>
<div id="progress-update-<?= (int)$update->id ?>" class="progress-feed-card">
<?php if ($hasMediaImage): ?>
<img class="progress-feed-cover" src="<?= Html::encode($mediaReference) ?>" alt="<?= Yii::t('AnimalManagementModule.base', 'Progress media') ?>">
<?php endif; ?>
<div class="progress-feed-overlay"></div>
<div class="progress-feed-content">
<div class="progress-feed-top-row">
<span class="progress-feed-date"><?= Html::encode(DateDisplayHelper::format((string)$update->update_at)) ?></span>
<?php if (!empty($update->weight) || !empty($update->vitals)): ?>
<div class="progress-chip-row progress-chip-row--top">
<?php if (!empty($update->weight)): ?><span class="progress-chip"><?= Yii::t('AnimalManagementModule.base', 'Weight') ?>: <?= Html::encode((string)$update->weight) ?></span><?php endif; ?>
<?php if (!empty($update->vitals)): ?><span class="progress-chip"><?= Yii::t('AnimalManagementModule.base', 'Vitals') ?></span><?php endif; ?>
</div>
<?php endif; ?>
</div>
<div class="progress-feed-details">
<div class="progress-feed-header">
<?php if ($canManage): ?>
<?= Html::a(
'<i class="fa fa-pencil"></i>',
'#progress-edit-inline-' . (int)$update->id,
[
'class' => 'btn btn-xs btn-default',
'data-toggle' => 'collapse',
'title' => Yii::t('AnimalManagementModule.base', 'Edit'),
'aria-label' => Yii::t('AnimalManagementModule.base', 'Edit'),
]
) ?>
<?php endif; ?>
</div>
<?php if (!empty($update->vitals)): ?><div class="progress-feed-label"><?= Yii::t('AnimalManagementModule.base', 'Vitals') ?></div><div class="progress-feed-copy"><?= nl2br(Html::encode($update->vitals)) ?></div><?php endif; ?>
<?php if (!empty($update->behavior_notes)): ?><div class="progress-feed-label"><?= Yii::t('AnimalManagementModule.base', 'Behavior') ?></div><div class="progress-feed-copy"><?= nl2br(Html::encode($update->behavior_notes)) ?></div><?php endif; ?>
<?php if (!empty($update->meal_plan_changes)): ?><div class="progress-feed-label"><?= Yii::t('AnimalManagementModule.base', 'Meal Plan') ?></div><div class="progress-feed-copy"><?= nl2br(Html::encode($update->meal_plan_changes)) ?></div><?php endif; ?>
<?php if (!empty($update->housing_changes)): ?><div class="progress-feed-label"><?= Yii::t('AnimalManagementModule.base', 'Housing') ?></div><div class="progress-feed-copy"><?= nl2br(Html::encode($update->housing_changes)) ?></div><?php endif; ?>
<?php if (!empty($update->medical_concerns)): ?><div class="progress-feed-label"><?= Yii::t('AnimalManagementModule.base', 'Medical Concerns') ?></div><div class="progress-feed-copy"><?= nl2br(Html::encode($update->medical_concerns)) ?></div><?php endif; ?>
<?php if (!empty($progressCustomDisplayValues)): ?>
<div class="progress-feed-label"><?= Yii::t('AnimalManagementModule.base', 'Additional Fields') ?></div>
<div class="progress-feed-copy">
<?php foreach ($progressCustomDisplayValues as $customField): ?>
<div><strong><?= Html::encode((string)$customField['label']) ?>:</strong> <?= nl2br(Html::encode((string)$customField['value'])) ?></div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php if ($canManage): ?>
<div id="progress-edit-inline-<?= (int)$update->id ?>" class="collapse progress-feed-inline-editor<?= $openProgressEditId === (int)$update->id ? ' in' : '' ?>">
<iframe
src="<?= Html::encode($space->createUrl('/animal_management/animals/edit-progress-update', ['id' => $animal->id, 'updateId' => $update->id, 'inline' => 1, 'returnTo' => 'progress-updates', '_v' => time()])) ?>"
style="width:100%;min-height:760px;border:1px solid rgba(255,255,255,0.22);border-radius:10px;background:transparent;"
loading="lazy"
></iframe>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php if ($canManage): ?>
<div class="modal fade" id="<?= Html::encode($progressAddModalId) ?>" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="<?= Yii::t('AnimalManagementModule.base', 'Close') ?>"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><?= Yii::t('AnimalManagementModule.base', 'Add Progress Update') ?></h4>
</div>
<div class="modal-body">
<?php $progressForm = ActiveForm::begin([
'action' => $space->createUrl('/animal_management/animals/add-progress-update', ['id' => $animal->id]),
'options' => ['id' => $progressFormId, 'enctype' => 'multipart/form-data'],
]); ?>
<?= Html::hiddenInput('returnTo', 'progress-updates') ?>
<?= $progressForm->errorSummary($progressUpdateForm, ['showAllErrors' => true]) ?>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Progress Update') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<div class="row">
<div class="col-sm-4"><?= $progressForm->field($progressUpdateForm, 'weight') ?></div>
<div class="col-sm-8"><?= $progressForm->field($progressUpdateForm, 'vitals')->textInput(['maxlength' => 255]) ?></div>
<div class="col-sm-6"><?= $progressForm->field($progressUpdateForm, 'behavior_notes')->textarea(['rows' => 2]) ?></div>
<div class="col-sm-6"><?= $progressForm->field($progressUpdateForm, 'medical_concerns')->textarea(['rows' => 2]) ?></div>
<div class="col-sm-6"><?= $progressForm->field($progressUpdateForm, 'meal_plan_changes')->textarea(['rows' => 2]) ?></div>
<div class="col-sm-6"><?= $progressForm->field($progressUpdateForm, 'housing_changes')->textarea(['rows' => 2]) ?></div>
</div>
</div>
</div>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Notes') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<?= $renderCustomField('progress_notes', $progressUpdateForm, $progressCustomDefinitions) ?>
<?= $renderCustomField('routine_updates', $progressUpdateForm, $progressCustomDefinitions) ?>
</div>
</div>
<?php if (!empty($otherProgressCustomDefinitions)): ?>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Additional Details') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<?php foreach ($otherProgressCustomDefinitions as $fieldKey => $definition): ?>
<?= $renderCustomField($fieldKey, $progressUpdateForm, $otherProgressCustomDefinitions) ?>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Media') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<input type="hidden" id="progress-media-gallery-path" name="progressMediaGalleryPath" value="<?= Html::encode($currentMediaReference) ?>">
<div class="row">
<div class="col-sm-4" style="margin-bottom:8px;">
<div id="progress-media-preview" style="border-radius:8px;overflow:hidden;background:#f2f4f6;height:150px;display:flex;align-items:center;justify-content:center;">
<?php if ($currentMediaReference !== '' && (preg_match('/^https?:\/\//i', $currentMediaReference) || substr($currentMediaReference, 0, 1) === '/')): ?>
<img src="<?= Html::encode($currentMediaReference) ?>" alt="<?= Yii::t('AnimalManagementModule.base', 'Selected media') ?>" style="width:100%;height:100%;object-fit:cover;">
<?php else: ?>
<i class="fa fa-image fa-2x" style="color:#a7b0b8;"></i>
<?php endif; ?>
</div>
</div>
<div class="col-sm-8">
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#progress-media-modal" style="margin-bottom:8px;">
<i class="fa fa-photo"></i> <?= Yii::t('AnimalManagementModule.base', 'Choose from Gallery or Upload') ?>
</button>
<div class="checkbox" style="margin-top:0;">
<label>
<input type="checkbox" name="removeProgressMedia" value="1">
<?= Yii::t('AnimalManagementModule.base', 'Remove selected media') ?>
</label>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-default" style="margin-bottom:12px;">
<div class="panel-heading"><strong><?= Yii::t('AnimalManagementModule.base', 'Social Post') ?></strong></div>
<div class="panel-body" style="padding-bottom:8px;">
<?= $progressForm->field($progressUpdateForm, 'post_to_space_feed')->checkbox() ?>
<?= $progressForm->field($progressUpdateForm, 'post_to_animal_feed')->checkbox() ?>
</div>
</div>
<?= Button::save(Yii::t('AnimalManagementModule.base', 'Add Progress Update'))->submit() ?>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
</div>
<div class="modal fade" id="progress-media-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="<?= Yii::t('AnimalManagementModule.base', 'Close') ?>"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><?= Yii::t('AnimalManagementModule.base', 'Select Progress Media') ?></h4>
</div>
<div class="modal-body">
<?php if (empty($galleryItems)): ?>
<div class="text-muted" style="margin-bottom:10px;"><?= Yii::t('AnimalManagementModule.base', 'No gallery images available yet.') ?></div>
<?php else: ?>
<div class="row" style="max-height:280px;overflow:auto;margin-bottom:10px;">
<?php foreach ($galleryItems as $galleryItem): ?>
<?php $galleryUrl = trim((string)$galleryItem->getImageUrl()); ?>
<?php if ($galleryUrl === '') { continue; } ?>
<div class="col-xs-6 col-sm-4" style="margin-bottom:8px;">
<button type="button" class="btn btn-default progress-media-select-thumb" data-media-url="<?= Html::encode($galleryUrl) ?>" style="width:100%;padding:3px;">
<img src="<?= Html::encode($galleryUrl) ?>" alt="<?= Yii::t('AnimalManagementModule.base', 'Gallery image') ?>" style="width:100%;height:120px;object-fit:cover;border-radius:4px;">
</button>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="form-group" style="margin-bottom:0;">
<label class="control-label" for="progressMediaUpload"><?= Yii::t('AnimalManagementModule.base', 'Upload New Image') ?></label>
<input type="file" class="form-control" id="progressMediaUpload" name="progressMediaUpload" form="<?= Html::encode($progressFormId) ?>" accept="image/*">
</div>
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php
$this->registerCss(<<<CSS
.progress-media-select-thumb.is-selected {
border-color: #2f7df4 !important;
box-shadow: 0 0 0 2px rgba(47, 125, 244, 0.22);
}
CSS
);
$this->registerJs(<<<JS
(function() {
var pageRootSelector = '#progress-updates-page';
var formSelector = '#{$progressFormId}';
function scrollInlineEditorIntoView(editor) {
var editorNode = $(editor);
if (!editorNode.length) {
return;
}
var sideSpacing = parseFloat(editorNode.css('margin-left'));
if (!(sideSpacing > 0)) {
sideSpacing = parseFloat(editorNode.closest('.panel-body').css('padding-left'));
}
if (!(sideSpacing > 0)) {
sideSpacing = 14;
}
var fixedHeaderHeight = 0;
$('.navbar-fixed-top:visible, #topbar:visible, .topbar:visible, .layout-top-container:visible').each(function() {
var h = $(this).outerHeight() || 0;
if (h > fixedHeaderHeight) {
fixedHeaderHeight = h;
}
});
var topReserve = Math.max(sideSpacing, 14) + Math.max(fixedHeaderHeight, 64) + 28;
var top = Math.max(0, editorNode.offset().top - topReserve);
$('html, body').stop(true).animate({scrollTop: top}, 220);
}
function refreshProgressUpdatesPageRoot() {
return $.get(window.location.href).done(function(html) {
var doc = $('<div></div>').append($.parseHTML(html, document, true));
var nextRoot = doc.find(pageRootSelector).first();
if (!nextRoot.length) {
return;
}
$(pageRootSelector).replaceWith(nextRoot);
if (typeof window.initProgressUpdatesPage === 'function') {
window.initProgressUpdatesPage();
}
});
}
if (!window.__animalProgressUpdatesInlineListenerBound) {
window.__animalProgressUpdatesInlineListenerBound = true;
window.addEventListener('message', function(event) {
var data = event.data || {};
if (!data || typeof data !== 'object' || data.source !== 'animal-inline-editor') {
return;
}
if (data.type === 'cancel') {
if (data.collapseId) {
$('#' + data.collapseId).collapse('hide');
}
return;
}
if (data.type === 'saved') {
if (data.collapseId) {
$('#' + data.collapseId).collapse('hide');
}
refreshProgressUpdatesPageRoot();
}
});
}
window.initProgressUpdatesPage = function() {
$(document)
.off('shown.bs.collapse.progressInlineScroll', pageRootSelector + ' .progress-feed-inline-editor')
.on('shown.bs.collapse.progressInlineScroll', pageRootSelector + ' .progress-feed-inline-editor', function() {
scrollInlineEditorIntoView(this);
});
$(document)
.off('click.progressInlineScroll', pageRootSelector + ' a[href^="#progress-edit-inline-"], ' + pageRootSelector + ' a[href="#progress-add-inline"]')
.on('click.progressInlineScroll', pageRootSelector + ' a[href^="#progress-edit-inline-"], ' + pageRootSelector + ' a[href="#progress-add-inline"]', function() {
var target = $(this).attr('href');
if (!target || target.charAt(0) !== '#') {
return;
}
window.setTimeout(function() {
scrollInlineEditorIntoView($(target));
}, 260);
});
var preopenedEditor = $(pageRootSelector + ' .progress-feed-inline-editor.in').first();
if (preopenedEditor.length) {
window.setTimeout(function() {
scrollInlineEditorIntoView(preopenedEditor);
}, 260);
}
function markSelectedMediaThumb(value) {
$('.progress-media-select-thumb').removeClass('is-selected');
if (!value) {
return;
}
$('.progress-media-select-thumb').each(function() {
if (($(this).attr('data-media-url') || '') === value) {
$(this).addClass('is-selected');
}
});
}
$(document).off('click.progressMediaSelect', '.progress-media-select-thumb').on('click.progressMediaSelect', '.progress-media-select-thumb', function(event) {
event.preventDefault();
var mediaUrl = $(this).attr('data-media-url') || '';
$('#progress-media-gallery-path').val(mediaUrl);
markSelectedMediaThumb(mediaUrl);
$('#progressMediaUpload').val('');
$('input[name="removeProgressMedia"]').prop('checked', false);
if (mediaUrl) {
$('#progress-media-preview').html('<img src="' + mediaUrl + '" alt="Selected media" style="width:100%;height:100%;object-fit:cover;">');
}
$('#progress-media-modal').modal('hide');
});
$(document).off('change.progressMediaUpload', '#progressMediaUpload').on('change.progressMediaUpload', '#progressMediaUpload', function() {
var file = this.files && this.files[0] ? this.files[0] : null;
if (!file) {
return;
}
$('#progress-media-gallery-path').val('');
markSelectedMediaThumb('');
$('input[name="removeProgressMedia"]').prop('checked', false);
var reader = new FileReader();
reader.onload = function(e) {
$('#progress-media-preview').html('<img src="' + e.target.result + '" alt="Selected media" style="width:100%;height:100%;object-fit:cover;">');
$('#progress-media-modal').modal('hide');
};
reader.readAsDataURL(file);
});
$(document).off('shown.bs.modal.progressMediaModal', '#progress-media-modal').on('shown.bs.modal.progressMediaModal', '#progress-media-modal', function() {
markSelectedMediaThumb($('#progress-media-gallery-path').val());
});
$(document).off('show.bs.modal.progressMediaStack', '#progress-media-modal').on('show.bs.modal.progressMediaStack', '#progress-media-modal', function() {
var zIndex = 1060 + (10 * $('.modal.in:visible').length);
$(this).css('z-index', zIndex);
window.setTimeout(function() {
$('.modal-backdrop').not('.progress-media-stack').last().css('z-index', zIndex - 1).addClass('progress-media-stack');
}, 0);
});
$(document).off('hidden.bs.modal.progressMediaStack', '#progress-media-modal').on('hidden.bs.modal.progressMediaStack', '#progress-media-modal', function() {
$(this).css('z-index', '');
if ($('#{$progressAddModalId}').is(':visible')) {
$('body').addClass('modal-open');
}
});
$(document).off('submit.progressAjax', formSelector).on('submit.progressAjax', formSelector, function(event) {
event.preventDefault();
var form = this;
var formData = new FormData(form);
var submitButtons = $(form).find('button[type="submit"], input[type="submit"]');
submitButtons.prop('disabled', true);
$.ajax({
url: form.action,
type: 'POST',
data: formData,
processData: false,
contentType: false
}).always(function() {
submitButtons.prop('disabled', false);
}).done(function() {
$('#{$progressAddModalId}').modal('hide');
refreshProgressUpdatesPageRoot();
});
});
};
window.initProgressUpdatesPage();
})();
JS
);
?>