Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 58 additions & 27 deletions app/Domain/Timesheets/Js/timesheetsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,37 +105,68 @@ leantime.timesheetsController = (function () {
});
};

var initEditTimeModal = function () {
var canvasoptions = {
sizes: {
minW: 700,
maxW: 1000,
minH: 1000,
},
resizable: false,
autoSizable: false,
callbacks: {
beforeShowCont: function () {
jQuery(".showDialogOnLoad").show();

if (closeModal === true) {
closeModal = false;
location.reload();
}
},
beforeClose: function () {
var isReady = false;
var pendingClick = null;

document.addEventListener('click', function(e) {
var target = e.target.closest('.editTimeModal');
if (target && !isReady) {
e.preventDefault();
e.stopPropagation();

target.style.opacity = '0.5';
target.style.cursor = 'wait';

pendingClick = target;
}
}, true);

function initWhenReady() {
initEditTimeModal();
isReady = true;

if (pendingClick) {
var $pending = jQuery(pendingClick);
pendingClick.style.opacity = '';
pendingClick.style.cursor = '';
$pending.trigger('click');
pendingClick = null;
}
}

var initEditTimeModal = function () {
var canvasoptions = {
sizes: {
minW: 700,
maxW: 1000,
minH: 1000,
},
resizable: false,
autoSizable: false,
callbacks: {
beforeShowCont: function () {
jQuery(".showDialogOnLoad").show();

if (closeModal === true) {
closeModal = false;
location.reload();
}
},
titleFromIframe: true
};

jQuery(document).on('click', '.editTimeModal', function (e) {
e.preventDefault();
jQuery(this).nyroModal(canvasoptions);
});
beforeClose: function () {
location.reload();
}
},
titleFromIframe: true
};

jQuery(document).on('click', 'a.editTimeModal', function (e) {
if (!isReady) return;
e.preventDefault();
jQuery(this).nyroModal(canvasoptions);
});
};

initWhenReady();

var formatHours = function (hours) {
var hoursFormat = jQuery('.timesheetTable').data('hours-format') ||
Expand Down Expand Up @@ -196,4 +227,4 @@ leantime.timesheetsController = (function () {
initEditTimeModal: initEditTimeModal,
formatHours: formatHours,
};
})();
})();
15 changes: 13 additions & 2 deletions app/Domain/Timesheets/Templates/editTime.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,23 @@
weekHeader: leantime.i18n.__("language.weekHeader"),
});
});
});
jQuery("#editTimeForm").on("submit", function(e) {
e.preventDefault();
jQuery.post(jQuery(this).attr("action"), jQuery(this).serialize(), function() {
if (window.parent && window.parent.jQuery) {
window.parent.jQuery.growl({ message: "Time saved successfully", style: "success" });
}
}).fail(function() {
jQuery.growl({ message: "Could not save time entry", style: "error" });
});
});
});

</script>

<?php echo $tpl->displayNotification() ?>
<h4 class="widgettitle title-light"><span class="fa-regular fa-clock"></span> <?php echo $tpl->__('headlines.edit_todo'); ?></h4>
<form action="<?= BASE_URL?>/timesheets/editTime/<?= (int) $_GET['id']?>" method="post" class="editTimeModal">
<form action="<?= BASE_URL?>/timesheets/editTime/<?= (int) $_GET['id']?>" method="post" id="editTimeForm">

<label for="projects" ><?php echo $tpl->__('label.project')?></label>
<select name="projects" id="projects" class="project-select">
Expand Down
5 changes: 4 additions & 1 deletion app/Domain/Timesheets/Templates/showMy.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@

jQuery("#finalSum").text(roundedSum);
});
<?php if ($login::userIsAtLeast($roles::$manager)) { ?>
leantime.timesheetsController.initEditTimeModal();
<?php } ?>
});
</script>

Expand Down Expand Up @@ -517,4 +520,4 @@ class="hourCell"
<div class="clearall"></div>
</form>
</div>
</div>
</div>
Loading