X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Ftemplates%2Fmobile%2Fexpense_edit.tpl;h=ea29723810366b6d1e9297f71a84d1cee3d77122;hb=f1f7c9878df54a56803a8fb2e557497a28def409;hp=41e3c2e213b06ab9302b963e1ba13583f3fb7990;hpb=ee49ee74b2a7d3c6daaa2d4bc6397b0c89e3099b;p=timetracker.git diff --git a/WEB-INF/templates/mobile/expense_edit.tpl b/WEB-INF/templates/mobile/expense_edit.tpl index 41e3c2e2..ea297238 100644 --- a/WEB-INF/templates/mobile/expense_edit.tpl +++ b/WEB-INF/templates/mobile/expense_edit.tpl @@ -26,6 +26,14 @@ projects = new Array(); // Mandatory top option for project dropdown. empty_label_project = '{$i18n.dropdown.select|escape:'javascript'}'; +// Prepare an array of predefined expenses. +idx = 0; +var defined_expenses = new Array(); +{foreach $predefined_expenses as $predefined_expense} + defined_expenses[idx] = new Array("{$predefined_expense.id}", "{$predefined_expense.name|escape:'javascript'}", "{$predefined_expense.cost}"); + idx++; +{/foreach} + // 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) { @@ -66,6 +74,42 @@ function get_date() { var date = new Date(); return date.strftime("%Y-%m-%d"); } + +// The recalculateCost function recalculates cost based on the current selection +// of predefined expense and quantity and also changes the comment accordingly. +function recalculateCost() { + var quantity_control = document.getElementById("quantity"); + // Set quantity to 1 if it is not set already. + if (!quantity_control.value) { + quantity_control.value = "1"; + } + + var comment_control = document.getElementById("item_name"); + var cost_control = document.getElementById("cost"); + var replaceDecimalMark = ("." != "{$user->decimal_mark}"); + + // Calculate cost. + var dropdown = document.getElementById("predefined_expense"); + if (dropdown.selectedIndex == 0) { + quantity_control.value = ""; + comment_control.value = ""; + cost_control.value = ""; + } else { + comment_control.value = defined_expenses[dropdown.selectedIndex - 1][1] + " - " + quantity_control.value; + var quantity = quantity_control.value; + if (isNaN(quantity)) + cost_control.value = ""; + else { + var expenseCost = defined_expenses[dropdown.selectedIndex - 1][2]; + if (replaceDecimalMark) + expenseCost = expenseCost.replace("{$user->decimal_mark}", "."); + var newCost = (quantity_control.value * expenseCost).toFixed(2); + if (replaceDecimalMark) + newCost = newCost.replace(".", "{$user->decimal_mark}"); + cost_control.value = newCost; + } + } +} {$forms.expenseItemForm.open} @@ -87,6 +131,16 @@ function get_date() {