X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=WEB-INF%2Ftemplates%2Fmobile%2Fexpense_edit.tpl;h=ea29723810366b6d1e9297f71a84d1cee3d77122;hb=913eba1427598741fcfb8d1e53746923c1f9e0e4;hp=7881d7929befa470ad57163e3f74ae71a04fe726;hpb=5519f0c3855c71a81442f3da1d135df89f1baf71;p=timetracker.git diff --git a/WEB-INF/templates/mobile/expense_edit.tpl b/WEB-INF/templates/mobile/expense_edit.tpl index 7881d792..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() {