From: Nik Okuntseff Date: Fri, 30 Nov 2018 21:27:42 +0000 (+0000) Subject: Some improvements to confirm save feature. X-Git-Tag: timetracker_1.19-1~513 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=35af76f7c66ba10e2e1279f2e9afbdb2b09a141d;p=timetracker.git Some improvements to confirm save feature. --- diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 8b98caa3..692d80ef 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -202,6 +202,12 @@ class ttUser { return ($this->behalfGroup ? $this->behalfGroup->config : $this->config); } + // getConfirmSave returns confirm_save option for user. + function getConfirmSave() { + return true; // TODO: implement this properly. + // return ($this->behalfGroup ? $this->behalfGroup->config : $this->config); + } + // can - determines whether user has a right to do something. function can($do_something) { return in_array($do_something, $this->rights); diff --git a/WEB-INF/templates/expense_edit.tpl b/WEB-INF/templates/expense_edit.tpl index 9e447a30..d3a27375 100644 --- a/WEB-INF/templates/expense_edit.tpl +++ b/WEB-INF/templates/expense_edit.tpl @@ -34,8 +34,8 @@ var defined_expenses = new Array(); idx++; {/foreach} -// TODO: improve on conditional confirmSave. -// Existing entry date for confirm save warnings. +{* Conditional include of confirmSave handler. *} +{if $confirm_save} var original_date = "{$entry_date}"; function confirmSave() { @@ -44,7 +44,7 @@ function confirmSave() { return confirm("{$i18n.warn.confirm_save}"); } } -// TODO: improve on conditional confirmSave above. +{/if} // The fillProjectDropdown function populates the project combo box with // projects associated with a selected client (client id is passed here as id). diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index b54e8814..9d88e933 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- diff --git a/WEB-INF/templates/time_edit.tpl b/WEB-INF/templates/time_edit.tpl index f6f46939..bc563e9e 100644 --- a/WEB-INF/templates/time_edit.tpl +++ b/WEB-INF/templates/time_edit.tpl @@ -1,8 +1,8 @@ {include file="time_script.tpl"} +{* Conditional include of confirmSave handler. *} +{if $confirm_save} +{/if} {$forms.timeRecordForm.open}
 Anuko Time Tracker 1.18.28.4551 | Copyright © Anuko | +  Anuko Time Tracker 1.18.28.4552 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/mobile/expense_edit.tpl b/WEB-INF/templates/mobile/expense_edit.tpl index ea297238..97140507 100644 --- a/WEB-INF/templates/mobile/expense_edit.tpl +++ b/WEB-INF/templates/mobile/expense_edit.tpl @@ -34,6 +34,18 @@ var defined_expenses = new Array(); idx++; {/foreach} +{* Conditional include of confirmSave handler. *} +{if $confirm_save} +var original_date = "{$entry_date}"; + +function confirmSave() { + var date_on_save = document.getElementById("date").value; + if (original_date != date_on_save) { + return confirm("{$i18n.warn.confirm_save}"); + } +} +{/if} + // The fillProjectDropdown function populates the project combo box with // projects associated with a selected client (client id is passed here as id). function fillProjectDropdown(id) { diff --git a/WEB-INF/templates/mobile/time_edit.tpl b/WEB-INF/templates/mobile/time_edit.tpl index 8c6a1414..79c5c03c 100644 --- a/WEB-INF/templates/mobile/time_edit.tpl +++ b/WEB-INF/templates/mobile/time_edit.tpl @@ -1,5 +1,19 @@ {include file="time_script.tpl"} +{* Conditional include of confirmSave handler. *} +{if $confirm_save} + +{/if} + {$forms.timeRecordForm.open} @@ -41,7 +55,7 @@ - +
{$forms.timeRecordForm.date.control}
{$i18n.label.note}:
{$forms.timeRecordForm.note.control}
{$forms.timeRecordForm.btn_save.control} {$forms.timeRecordForm.btn_delete.control}
{$forms.timeRecordForm.btn_save.control} {$forms.timeRecordForm.btn_copy.control} {$forms.timeRecordForm.btn_delete.control}
diff --git a/expense_edit.php b/expense_edit.php index cca8225a..a4bb6a4f 100644 --- a/expense_edit.php +++ b/expense_edit.php @@ -51,6 +51,7 @@ if (!$expense_item || $expense_item['invoice_id']) { } $item_date = new DateAndTime(DB_DATEFORMAT, $expense_item['date']); +$confirm_save = $user->getConfirmSave(); // Initialize variables. $cl_date = $cl_client = $cl_project = $cl_item_name = $cl_cost = null; @@ -147,9 +148,10 @@ $form->addInput(array('type'=>'datefield','name'=>'date','maxlength'=>'20','valu // Hidden control for record id. $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id)); $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click. -// TODO: improve on conditional confirmSave. -$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date();return(confirmSave())','value'=>$i18n->get('button.save'))); -$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.copy'))); +$on_click_action = 'browser_today.value=get_date();'; +$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy'))); +if ($confirm_save) $on_click_action .= 'return(confirmSave());'; +$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save'))); $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete'))); if ($request->isPost()) { @@ -221,9 +223,10 @@ if ($request->isPost()) { } } // isPost -// TODO: improve on conditional confirmSave. -$smarty->assign('entry_date', $cl_date); - +if ($confirm_save) { + $smarty->assign('confirm_save', true); + $smarty->assign('entry_date', $cl_date); +} $smarty->assign('predefined_expenses', $predefined_expenses); $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); diff --git a/mobile/expense_edit.php b/mobile/expense_edit.php index a039f42f..9cae0181 100644 --- a/mobile/expense_edit.php +++ b/mobile/expense_edit.php @@ -51,6 +51,7 @@ if (!$expense_item || $expense_item['invoice_id']) { } $item_date = new DateAndTime(DB_DATEFORMAT, $expense_item['date']); +$confirm_save = $user->getConfirmSave(); // Initialize variables. $cl_date = $cl_client = $cl_project = $cl_item_name = $cl_cost = null; @@ -142,8 +143,10 @@ $form->addInput(array('type'=>'datefield','name'=>'date','maxlength'=>'20','valu // Hidden control for record id. $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id)); $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click. -$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.save'))); -$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.copy'))); +$on_click_action = 'browser_today.value=get_date();'; +$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy'))); +if ($confirm_save) $on_click_action .= 'return(confirmSave());'; +$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save'))); $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete'))); if ($request->isPost()) { @@ -215,6 +218,10 @@ if ($request->isPost()) { } } // isPost +if ($confirm_save) { + $smarty->assign('confirm_save', true); + $smarty->assign('entry_date', $cl_date); +} $smarty->assign('predefined_expenses', $predefined_expenses); $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); diff --git a/mobile/time_edit.php b/mobile/time_edit.php index b2655e8f..3094df64 100644 --- a/mobile/time_edit.php +++ b/mobile/time_edit.php @@ -57,6 +57,7 @@ if ($user->isPluginEnabled('cf')) { } $item_date = new DateAndTime(DB_DATEFORMAT, $time_rec['date']); +$confirm_save = $user->getConfirmSave(); // Initialize variables. $cl_start = $cl_finish = $cl_duration = $cl_date = $cl_note = $cl_project = $cl_task = $cl_billable = null; @@ -205,7 +206,10 @@ $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id)); if ($user->isPluginEnabled('iv')) $form->addInput(array('type'=>'checkbox','name'=>'billable','value'=>$cl_billable)); $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save click. -$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.save'))); +$on_click_action = 'browser_today.value=get_date();'; +$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy'))); +if ($confirm_save) $on_click_action .= 'return(confirmSave());'; +$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save'))); $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete'))); if ($request->isPost()) { @@ -324,12 +328,79 @@ if ($request->isPost()) { } } + // Save as new record. + if ($request->getParameter('btn_copy')) { + // We need to: + // 1) Prohibit saving into locked range. + // 2) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists. + + // Now, step by step. + if ($err->no()) { + // 1) Prohibit saving into locked range. + if ($user->isDateLocked($new_date)) + $err->add($i18n->get('error.range_locked')); + + // 2) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists. + $uncompleted = ($cl_finish == '' && $cl_duration == ''); + if ($uncompleted) { + $not_completed_rec = ttTimeHelper::getUncompleted($user_id); + if ($not_completed_rec) { + // We have another not completed record. + $err->add($i18n->get('error.uncompleted_exists')." ".$i18n->get('error.goto_uncompleted').""); + } + } + } + + // Prohibit creating an overlapping record. + if ($err->no()) { + if (ttTimeHelper::overlaps($user_id, $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish)) + $err->add($i18n->get('error.overlap')); + } + + // Now, a new insert. + if ($err->no()) { + + $id = ttTimeHelper::insert(array( + 'date'=>$new_date->toString(DB_DATEFORMAT), + 'user_id'=>$user_id, + 'group_id'=>$user->getGroup(), + 'org_id' => $user->org_id, + 'client'=>$cl_client, + 'project'=>$cl_project, + 'task'=>$cl_task, + 'start'=>$cl_start, + 'finish'=>$cl_finish, + 'duration'=>$cl_duration, + 'note'=>$cl_note, + 'billable'=>$cl_billable, + 'paid'=>$cl_paid)); + + // Insert a custom field if we have it. + $res = true; + if ($id && $custom_fields && $cl_cf_1) { + if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT) + $res = $custom_fields->insert($id, $custom_fields->fields[0]['id'], null, $cl_cf_1); + elseif ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN) + $res = $custom_fields->insert($id, $custom_fields->fields[0]['id'], $cl_cf_1, null); + } + if ($id && $res) { + header('Location: time.php?date='.$new_date->toString(DB_DATEFORMAT)); + exit(); + } + $err->add($i18n->get('error.db')); + } + } + if ($request->getParameter('btn_delete')) { header("Location: time_delete.php?id=$cl_id"); exit(); } } // isPost +if ($confirm_save) { + $smarty->assign('confirm_save', true); + $smarty->assign('entry_date', $cl_date); +} $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); $smarty->assign('task_list', $task_list); diff --git a/time_edit.php b/time_edit.php index 17ba34b4..5dd958b5 100644 --- a/time_edit.php +++ b/time_edit.php @@ -57,6 +57,7 @@ if ($user->isPluginEnabled('cf')) { } $item_date = new DateAndTime(DB_DATEFORMAT, $time_rec['date']); +$confirm_save = $user->getConfirmSave(); // Initialize variables. $cl_start = $cl_finish = $cl_duration = $cl_date = $cl_note = $cl_project = $cl_task = $cl_billable = null; @@ -210,9 +211,10 @@ if ($user->isPluginEnabled('iv')) if ($user->can('manage_invoices') && $user->isPluginEnabled('ps')) $form->addInput(array('type'=>'checkbox','name'=>'paid','value'=>$cl_paid)); $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click. -// TODO: improve on conditional confirmSave. -$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date();return(confirmSave())','value'=>$i18n->get('button.save'))); -$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.copy'))); +$on_click_action = 'browser_today.value=get_date();'; +$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy'))); +if ($confirm_save) $on_click_action .= 'return(confirmSave());'; +$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save'))); $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete'))); if ($request->isPost()) { @@ -401,9 +403,10 @@ if ($request->isPost()) { } } // isPost -// TODO: improve on conditional confirmSave. -$smarty->assign('entry_date', $cl_date); - +if ($confirm_save) { + $smarty->assign('confirm_save', true); + $smarty->assign('entry_date', $cl_date); +} $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); $smarty->assign('task_list', $task_list);