Changeset 26293


Ignore:
Timestamp:
06/08/10 10:28:57 (7 years ago)
Author:
gudd
Message:

Moved javascript from style to static js-file.
Refs #1773

Location:
branches/ragnaroek/midcom/org.openpsa.invoices
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ragnaroek/midcom/org.openpsa.invoices/handler/action.php

    r26267 r26293  
    199199        }
    200200        //get invoice_items for this invoice
    201         $this->_request_data['invoice_items_no_task'] = $this->_object->get_invoice_items();
     201        $this->_request_data['invoice_items'] = $this->_object->get_invoice_items();
    202202
    203203        return true;
     
    263263                )
    264264            );
     265        $_MIDCOM->enable_jquery();
     266        $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL . '/org.openpsa.invoices/invoice_item.js');
    265267    }
    266268}
  • branches/ragnaroek/midcom/org.openpsa.invoices/style/show-itemedit.php

    r26161 r26293  
    1 <script type="text/javascript">
    2 $(document).ready(function()
    3 {
    4     $(".report_checkbox").click(
    5     function()
    6     {
    7         id = "sum_"+$(this).attr('id');
    8         invoice_value = $("#"+ id).html();
    9         sum_value = $("#new_invoice_sum").attr('value');
    10         if($(this).is(':checked'))
    11         {
    12             sum_value = Number(sum_value) + Number(invoice_value);
    13         }
    14         else
    15         {
    16             sum_value = Number(sum_value) - Number(invoice_value);
    17         }
    18         $("#new_invoice_sum").attr('value' , sum_value);
    19         window.console.log($(this));
    20     })
    21 });
    22 
    23 id_count = 1;
    24 //function to add a new row
    25 function add_new_row()
    26 {
    27     html = "<tr id='row_" + id_count +"' class='invoice_item_row'>";
    28     /*html += "<td>" + position++ + "</td>";*/
    29     //html += "<td><input class='input_description' type='text' name='invoice_items_new[" + id_count + "][description]' value='' /></td>";
    30     html += "<td><textarea class='input_description' name='invoice_items_new[" + id_count + "][description]' ></textarea></td>";
    31 
    32     html += "<td><input class='input_price_per_unit numeric' type='text' onchange=\"calculate_row('" + id_count +"')\" id='price_per_unit_" + id_count +"' name='invoice_items_new[" + id_count + "][price_per_unit]' value='' /></td>";
    33     html += "<td><input class='input_units numeric' type='text' onchange=\"calculate_row('" + id_count +"')\" id='units_" + id_count +"' name='invoice_items_new[" + id_count + "][units]' value='' /></td>";
    34     html += "<td class='row_sum numeric' id='row_sum_" + id_count +"'>0</td>";
    35     html += "<td><div class='remove_button' onclick=\"remove_row('" + id_count + " ')\">\&nbsp;</div> </td>";
    36     html += "</tr>";
    37     id_count++;
    38     jQuery("#row_invoice_sum").before(html);
    39 }
    40 /* function to parse the input and exchanges , with .
    41 */
    42 function parse_input(string)
    43 {
    44     search_string = ',';
    45     replace_string = '.';
    46 
    47     return string.replace(search_string , replace_string);
    48 }
    49 
    50 function calculate_row(id)
    51 {
    52     window.console.log("test");
    53     //remove old invoice_item_sum from total sum
    54     recalculate_invoice_sum(id , true);
    55 
    56     price_unit = parse_input($("#price_per_unit_" + id).val());
    57     units = parse_input($("#units_" + id).val());
    58     //check if they are numbers
    59     if(isNaN(price_unit)
    60         && isNaN(units))
    61     {
    62         sum = 0;
    63     }
    64     else
    65     {
    66         sum = price_unit * units;
    67     }
    68     window.console.log(sum);
    69     $('#row_sum_' + id).html(sum.toFixed(2));
    70     recalculate_invoice_sum(id , false);
    71 }
    72 
    73 //function to calculate the total sum with the row for the passed id
    74 function recalculate_invoice_sum(id , remove)
    75 {
    76     invoice_sum = Number($("#invoice_sum").html());
    77     row_sum = Number($('#row_sum_' + id).html());
    78 
    79     if(remove == true)
    80     {
    81         row_sum = row_sum * -1;
    82     }
    83     sum = (invoice_sum + row_sum);
    84     $("#invoice_sum").html(sum.toFixed(2));
    85 }
    86 
    87 //function to add an hidden input field - which indicates the handler to delete the row
    88 function mark_remove(object , guid)
    89 {
    90     //check if it is already marked as remove
    91     if($(object).children("input").length > 0)
    92     {
    93         $(object).children("input").remove();
    94         $(object).parent().parent().removeClass('remove');
    95         $(object).addClass('remove_button');
    96         recalculate_invoice_sum(guid , false);
    97     }
    98     else
    99     {
    100         html = "<input type='hidden' name='invoice_items[" + guid + "][delete]' value='delete' />";
    101         $(object).append(html);
    102         $(object).removeClass('remove_button');
    103         $(object).addClass('add_button');
    104         $(object).parent().parent().addClass('remove');
    105         recalculate_invoice_sum(guid , true);
    106     }
    107 }
    108 //function to completely remove the row with passed id
    109 function remove_row(id)
    110 {
    111     recalculate_invoice_sum(id , true);
    112     $("#row_" + id).remove();
    113 }
    114 
    115 </script>
    116 
    1171<form method="post">
    1182<div style='padding-bottom:10px;'><?php echo "<input type='button' onclick='add_new_row();' value='" . $data['l10n']->get('add new invoice item') ."' />";?></div>
     
    13115<?php
    13216    $invoice_sum = 0;
    133     $invoice_items = array_merge($data['invoice_items_no_task'] , $data['invoice_items_task']);
     17    $invoice_items = $data['invoice_items'];
    13418    foreach($invoice_items as $invoice_item)
    13519    {
Note: See TracChangeset for help on using the changeset viewer.