modify statusChanged onchange for info_(status|percent|datecompleted) to work with new and old eT2

thought current Et2Select has a problem with fixed options from Et2Select* widgets
This commit is contained in:
ralf 2022-03-16 10:07:00 +02:00
parent c120f13466
commit 689e7e6ee5
3 changed files with 47 additions and 61 deletions

View File

@ -19,6 +19,7 @@ import {CRMView} from "../../addressbook/js/CRM";
import {et2_selectbox} from "../../api/js/etemplate/et2_widget_selectbox"; import {et2_selectbox} from "../../api/js/etemplate/et2_widget_selectbox";
import {nm_open_popup} from "../../api/js/etemplate/et2_extension_nextmatch_actions.js"; import {nm_open_popup} from "../../api/js/etemplate/et2_extension_nextmatch_actions.js";
import {egw} from "../../api/js/jsapi/egw_global"; import {egw} from "../../api/js/jsapi/egw_global";
import {et2_date} from "../../api/js/etemplate/et2_widget_date";
/** /**
* UI for Infolog * UI for Infolog
@ -410,77 +411,72 @@ class InfologApp extends EgwApp
/** /**
* If one of info_status, info_percent or info_datecompleted changed --> set others to reasonable values * If one of info_status, info_percent or info_datecompleted changed --> set others to reasonable values
* *
* @param {string} changed_id id of changed element * @param _event
* @param {string} status_id * @param {et2_widget} _widget
* @param {string} percent_id
* @param {string} datecompleted_id
*/ */
status_changed(changed_id, status_id, percent_id, datecompleted_id) statusChanged(_event, _widget)
{ {
// Make sure this doesn't get executed while template is loading // Make sure this doesn't get executed while template is loading
if(this.et2 == null || this.et2.getInstanceManager() == null) return; if (!this.et2?.getInstanceManager()) return;
var status = <HTMLInputElement>document.getElementById(status_id); const status = <et2_selectbox>this.et2.getWidgetById('info_status');
var percent = <HTMLInputElement>document.getElementById(percent_id); const percent = <et2_selectbox>this.et2.getWidgetById('info_percent');
var datecompleted = <HTMLInputElement>document.getElementById(datecompleted_id+'[str]'); const datecompleted = <et2_date>this.et2.getWidgetById('info_datecompleted');
if(!datecompleted) const old_status = status.get_value();
{ const old_percent = parseInt(percent.get_value());
datecompleted = <HTMLInputElement>jQuery('#'+datecompleted_id +' input').get(0); let completed : boolean;
}
var completed;
switch(changed_id) switch(_widget.id)
{ {
case status_id: case 'info_status':
completed = status.value == 'done' || status.value == 'billed'; completed = old_status === 'done' || old_status === 'billed';
if (completed || status.value == 'not-started' || if (completed || old_status === 'not-started' ||
(status.value == 'ongoing') != (parseFloat(percent.value) > 0 && parseFloat(percent.value) < 100)) (old_status === 'ongoing') !== (0 < old_percent && old_percent < 100))
{ {
if (completed) if (completed)
{ {
percent.value = '100'; percent.set_value('100');
} }
else if (status.value == 'not-started') else if (old_status == 'not-started')
{ {
percent.value = '0'; percent.set_value('0');
} }
else if (!completed && (parseInt(percent.value) == 0 || parseInt(percent.value) == 100)) else if (!completed && !old_percent || old_percent === 100)
{ {
percent.value = '10'; percent.set_value('10');
} }
} }
break; break;
case percent_id: case 'info_percent':
completed = parseInt(percent.value) == 100; completed = old_percent === 100;
if (completed != (status.value == 'done' || status.value == 'billed') || if (completed !== (old_status === 'done' || old_status === 'billed') ||
(status.value == 'not-started') != (parseInt(percent.value) == 0)) (old_status === 'not-started') !== !old_percent)
{ {
status.value = parseInt(percent.value) == 0 ? (jQuery('[value="not-started"]',status).length ? status.set_value(!old_percent ? (old_status === 'not-started' ? 'not-started' : 'ongoing') :
'not-started':'ongoing') : (parseInt(percent.value) == 100 ? 'done' : 'ongoing'); (old_percent === 100 ? 'done' : 'ongoing'));
} }
break; break;
case datecompleted_id+'[str]': case 'info_datecompleted':
case datecompleted_id: completed = !datecompleted.get_value();
completed = datecompleted.value != ''; if (completed !== (old_status === 'done' || old_status === 'billed'))
if (completed != (status.value == 'done' || status.value == 'billed'))
{ {
status.value = completed ? 'done' : 'not-started'; status.set_value(completed ? 'done' : 'not-started');
} }
if (completed != (parseInt(percent.value) == 100)) if (completed !== (old_percent === 100))
{ {
percent.value = completed ? '100' : '0'; percent.set_value(completed ? '100' : '0');
} }
break; break;
} }
if (!completed && datecompleted && datecompleted.value != '') if (!completed && datecompleted && datecompleted.get_value())
{ {
datecompleted.value = ''; datecompleted.set_value('');
} }
else if (completed && datecompleted && datecompleted.value == '') else if (completed && datecompleted && !datecompleted.get_value())
{ {
// todo: set current date in correct format datecompleted.set_value(new Date());
} }
} }

View File

@ -124,7 +124,7 @@
</row> </row>
<row> <row>
<description value="Date completed" for="info_datecompleted"/> <description value="Date completed" for="info_datecompleted"/>
<date-time statustext="Date completed (leave it empty to have it automatic set if status is done or billed)" id="info_datecompleted" onchange="app.infolog.status_changed(this.id, form::name('info_status'), form::name('info_percent'), form::name('info_datecompleted'))" class="et2_fullWidth"/> <date-time statustext="Date completed (leave it empty to have it automatic set if status is done or billed)" id="info_datecompleted" onchange="app.infolog.statusChanged" class="et2_fullWidth"/>
</row> </row>
<row class="row"> <row class="row">
<description value="Location" for="info_location"/> <description value="Location" for="info_location"/>
@ -207,14 +207,10 @@
</row> </row>
<row class="dialogOperators"> <row class="dialogOperators">
<description value="Status" for="info_status"/> <description value="Status" for="info_status"/>
<menulist class="et2_fullWidth"> <select class="et2_fullWidth" statustext="@status_help" id="info_status" onchange="app.infolog.statusChanged"/>
<menupopup statustext="@status_help" id="info_status" onchange="app.infolog.status_changed(this.id, form::name('info_status'), form::name('info_percent'), form::name('info_datecompleted'))"/>
</menulist>
<description/> <description/>
<description value="Completed" for="info_percent"/> <description value="Completed" for="info_percent"/>
<menulist class="et2_fullWidth"> <select-percent class="et2_fullWidth" statustext="Percent completed" id="info_percent" onchange="app.infolog.statusChanged"/>
<menupopup type="select-percent" statustext="Percent completed" id="info_percent" onchange="app.infolog.status_changed(this.id, form::name('info_status'), form::name('info_percent'), form::name('info_datecompleted'))"/>
</menulist>
</row> </row>
<row disabled="!@info_owner" class="dialogOperators"> <row disabled="!@info_owner" class="dialogOperators">
<description value="Owner"/> <description value="Owner"/>

View File

@ -92,13 +92,11 @@
</row> </row>
<row> <row>
<description value="Priority" for="info_priority"/> <description value="Priority" for="info_priority"/>
<menulist class="et2_fullWidth"> <select class="et2_fullWidth" statustext="select a priority for this task" id="info_priority"/>
<menupopup statustext="select a priority for this task" id="info_priority"/>
</menulist>
</row> </row>
<row> <row>
<description value="Date completed" for="info_datecompleted"/> <description value="Date completed" for="info_datecompleted"/>
<date-time statustext="Date completed (leave it empty to have it automatic set if status is done or billed)" id="info_datecompleted" onchange="app.infolog.status_changed(this.id, form::name('info_status'), form::name('info_percent'), form::name('info_datecompleted'))" class="et2_fullWidth"/> <date-time statustext="Date completed (leave it empty to have it automatic set if status is done or billed)" id="info_datecompleted" onchange="app.infolog.statusChanged" class="et2_fullWidth"/>
</row> </row>
<row> <row>
<description value="Contact" for="info_from"/> <description value="Contact" for="info_from"/>
@ -190,15 +188,11 @@
</row> </row>
<row> <row>
<description value="Status" for="info_status"/> <description value="Status" for="info_status"/>
<menulist class="et2_fullWidth"> <select class="et2_fullWidth" statustext="@status_help" id="info_status" onchange="app.infolog.statusChanged"/>
<menupopup statustext="@status_help" id="info_status" onchange="app.infolog.status_changed(this.id, form::name('info_status'), form::name('info_percent'), form::name('info_datecompleted'))"/>
</menulist>
</row> </row>
<row> <row>
<description value="Completed" for="info_percent"/> <description value="Completed" for="info_percent"/>
<menulist class="et2_fullWidth" span="4"> <select-percent class="et2_fullWidth" span="4" statustext="Percent completed" id="info_percent" onchange="app.infolog.statusChanged"/>
<menupopup type="select-percent" statustext="Percent completed" id="info_percent" onchange="app.infolog.status_changed(this.id, form::name('info_status'), form::name('info_percent'), form::name('info_datecompleted'))"/>
</menulist>
</row> </row>
<row> <row>
<tabbox id="tabs" span="all" width="100%" align_tabs="v"> <tabbox id="tabs" span="all" width="100%" align_tabs="v">