[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [ENH] AutoIncrement/Math fields override option - ability for users to...
"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <69ca6aef69fc1_3b18f13c12951@gitlab-sidekiq-low-urgency-cpu-bound-v2-6695d99cb4-tdwvz.mail> |
Victor Emanouilov pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki
Commits:
475f4d50 by Victor Emanouilov at 2026-03-30T15:21:58+03:00
[ENH] AutoIncrement/Math fields override option - ability for users to...
---
* [ENH] AutoIncrement/Math fields override option - ability for users to override values when they are wrong. Some examples follow.
- AutoIncrement that syncs with other data sources but the sync hasn't happened - user needs to clear existing value and trigger a re-sync which might inherit the correct number after save
- Math calculation that (concat self (formula here...)) - i.e. stores the calculated value in the field but needs a manual way to save another value or trigger initial formula in case of an error
See merge request tikiwiki/tiki!9885
- - - - -
5 changed files:
- lib/core/Tracker/Field/AutoIncrement.php
- lib/core/Tracker/Field/Math.php
- lib/jquery_tiki/tiki-trackers.js
- templates/trackerinput/autoincrement.tpl
- + templates/trackerinput/math.tpl
Changes:
=====================================
lib/core/Tracker/Field/AutoIncrement.php
=====================================
@@ -63,6 +63,16 @@ class Tracker_Field_AutoIncrement extends \Tracker\Field\AbstractItemField imple
1 => tr('Yes'),
],
],
+ 'overridable' => [
+ 'name' => tr('Overridable'),
+ 'description' => tr('Allow the value to be overridden by the user. Use with caution.'),
+ 'filter' => 'int',
+ 'options' => [
+ 0 => tr('No'),
+ 1 => tr('Yes'),
+ ],
+ 'default' => 0,
+ ],
],
],
];
@@ -116,7 +126,7 @@ class Tracker_Field_AutoIncrement extends \Tracker\Field\AbstractItemField imple
$value = false;
if ($this->getOption('itemId') == 'itemId') {
$value = $this->getItemId();
- } elseif (is_null($oldValue)) {
+ } elseif (is_null($oldValue) || ($this->getOption('overridable') && ! $value)) {
$value = $this->syncFromSource();
if ($value === false) {
$value = TikiLib::lib('trk')->get_maximum_value($this->getConfiguration('fieldId'));
=====================================
lib/core/Tracker/Field/Math.php
=====================================
@@ -64,6 +64,16 @@ class Tracker_Field_Math extends \Tracker\Field\AbstractItemField implements \Tr
'text_sort' => tr('Text'),
],
],
+ 'overridable' => [
+ 'name' => tr('Overridable'),
+ 'description' => tr('Allow the value to be overridden by the user. Useful when calculated value is stored in the field to avoid recalculations but still need a way to override it.'),
+ 'filter' => 'int',
+ 'options' => [
+ 0 => tr('No'),
+ 1 => tr('Yes'),
+ ],
+ 'default' => 0,
+ ],
],
],
];
@@ -86,7 +96,7 @@ class Tracker_Field_Math extends \Tracker\Field\AbstractItemField implements \Tr
public function renderInput($context = [])
{
- return tr('Value will be re-calculated on save. Current value: %0', $this->getValue());
+ return $this->renderTemplate('trackerinput/math.tpl', $context);
}
public function renderOutput($context = [])
@@ -190,6 +200,9 @@ class Tracker_Field_Math extends \Tracker\Field\AbstractItemField implements \Tr
*/
public function handleFinalSave(array &$data)
{
+ if ($this->getOption('overridable') && $this->getValue()) {
+ return $this->getValue();
+ }
try {
$this->prepareFieldValues($data);
$data = array_merge($data, $this->calcMetadata());
=====================================
lib/jquery_tiki/tiki-trackers.js
=====================================
@@ -680,6 +680,21 @@
$('.'+$(this).attr('id')).addClass('d-none');
});
+ $(document).on("click", ".math-override-toggle", function(e) {
+ e.preventDefault();
+ var $container = $(this).closest(".math-field-override");
+ $container.find(".input-group").slideDown(150);
+ $container.find("input").prop("disabled", false).focus();
+ $(this).hide();
+ });
+ $(document).on("click", ".math-override-cancel", function() {
+ var $container = $(this).closest(".math-field-override");
+ var $input = $container.find("input");
+ $input.val($input.data("original-value")).prop("disabled", true);
+ $container.find(".input-group").slideUp(150);
+ $container.find(".math-override-toggle").show();
+ });
+
$(document).on('hidden.bs.modal', function (event) {
if (m = window.location.href.match(/item(\d+)|itemId=(\d+)/)) {
var itemId = m[1] || m[2];
=====================================
templates/trackerinput/autoincrement.tpl
=====================================
@@ -4,7 +4,11 @@
{if !empty($field.options_map.prepend)}
<span class="input-group-text">{$field.options_map.prepend} </span>
{/if}
- <input type="text" class="form-control" value="{$field.value|escape}" disabled="disabled">
+ {if $field.options_map.overridable}
+ <input type="text" class="form-control" id="{$field.ins_id|replace:'[':'_'|replace:']':''}" name="{$field.ins_id}" value="{$field.value|escape}">
+ {else}
+ <input type="text" class="form-control" value="{$field.value|escape}" disabled="disabled">
+ {/if}
{if !empty($field.options_map.append)}
<span class="input-group-text">{$field.options_map.append}</span>
{/if}
=====================================
templates/trackerinput/math.tpl
=====================================
@@ -0,0 +1,16 @@
+{if $field.options_map.overridable}
+ <div class="math-field-override">
+ <span class="form-text text-muted">
+ {tr _0=$field.value}Value will be re-calculated on save. Current value: %0{/tr}
+ <a href="#" class="math-override-toggle ms-1" title="{tr}Override value{/tr}"><span class="fas fa-pen fa-sm"></span></a>
+ </span>
+ <div class="input-group mt-1" style="display:none;">
+ <input type="text" class="form-control" id="{$field.ins_id|replace:'[':'_'|replace:']':''}" name="{$field.ins_id}" value="{$field.value|escape}" data-original-value="{$field.value|escape}" disabled>
+ <button type="button" class="btn btn-outline-secondary btn-sm math-override-cancel" title="{tr}Cancel override{/tr}">
+ <span class="fas fa-times"></span>
+ </button>
+ </div>
+ </div>
+{else}
+ {tr _0=$field.value}Value will be re-calculated on save. Current value: %0{/tr}
+{/if}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/475f4d50d0f4de1d1c8f4fba896384e9a06182a1
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/475f4d50d0f4de1d1c8f4fba896384e9a06182a1
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs