Fixed calendar flicker, removed buttons from exchange_rate_display().
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 21 Sep 2008 14:45:38 +0000 (14:45 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 21 Sep 2008 14:45:38 +0000 (14:45 +0000)
includes/ui/ui_view.inc

index 4b23e03059d274a7e8b32a6a1cc9cc010f025db4..5925579be558ed33433bbbf9d50e31d91c864972 100644 (file)
@@ -271,43 +271,40 @@ function get_trans_view_str($type, $trans_no, $label="")
 }
 
 //--------------------------------------------------------------------------------------
-
-function exchange_rate_display($from_currency, $to_currency, $date_, $buttons=true)
+// Displays currency exchange rate for given date.
+// When there is no exrate for today, 
+// gets it form ECB and stores in local database.
+//
+function exchange_rate_display($from_currency, $to_currency, $date_)
 {
     global $Ajax;
-    $hint = _('Get daily ECB exchange rate and save for later use in invoicing process');
+
        if ($from_currency != $to_currency)
        {
-               if ($buttons && isset($_POST['get_rate']))
-               {
-                       $comp_currency = get_company_currency();
-                       if ($from_currency == $comp_currency)
-                               $currency = $to_currency;
-                       else
-                               $currency = $from_currency;
-
-                       $rate = get_ecb_rate($currency);
-                       if ($rate && ($date_==Today())) {
-                               if (get_date_exchange_rate($currency, $date_))
-                                       update_exchange_rate($currency, $date_, $rate, $rate);
-                               else
+               $comp_currency = get_company_currency();
+               if ($from_currency == $comp_currency)
+                       $currency = $to_currency;
+               else
+                       $currency = $from_currency;
+               $rate = 0;
+               if ($date_ == Today()) {
+                       $rate = get_date_exchange_rate($currency, $date_);
+                       if (!$rate) {
+                               $rate = get_ecb_rate($currency);
+                               if ($rate) 
                                        add_exchange_rate($currency, $date_, $rate, $rate);
-                       } else
-                               $rate = get_exchange_rate_from_to($to_currency, $from_currency, $date_);
-                       
-                       if ($from_currency == $comp_currency)
-                               $rate = 1 / $rate;
-                       $Ajax->activate('get_rate');
+                       }
                }
-               else
+               if (!$rate)
                        $rate = get_exchange_rate_from_to($to_currency, $from_currency, $date_);
+                       
+               if ($from_currency == $comp_currency)
+                       $rate = 1 / $rate;
 
                $rate = number_format2($rate, user_exrate_dec());
-       label_row(_("Exchange Rate:"),"1 " . $from_currency . " = <span id='_ex_rate'>" . $rate . "</span> " . $to_currency .
-               ($buttons?"  " . submit('get_rate',_("Get"), false, $hint, true):""));
-           if($buttons) {
-                 $Ajax->addUpdate('get_rate','_ex_rate', $rate);
-               }
+       label_row(_("Exchange Rate:"),"1 " . $from_currency 
+                       . " = <span id='_ex_rate'>" . $rate . "</span> " . $to_currency );
+                 $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
        }
 }
 
@@ -846,6 +843,9 @@ function CC() {
 ";
        $js .= "
       dateField.value = dateString;
+         setFocus(dateField.name);
+         if (dateField.className=='searchbox')
+               dateField.onblur();
       hide();
     }
     return;
@@ -1006,19 +1006,19 @@ function CC() {
     if(document.getElementById){
       calendar = document.getElementById(calendarId);
       calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
-      setProperty('display', 'block');
       var fieldPos = new positionInfo(dateField);
       var calendarPos = new positionInfo(calendarId);
       var x = fieldPos.getElementLeft();
       var y = fieldPos.getElementBottom();
       setProperty('left', x + 'px');
       setProperty('top', y + 'px');
+      setProperty('display', 'block');
       if (document.all) {
-        setElementProperty('display', 'block', 'CCIframe');
         setElementProperty('left', x + 'px', 'CCIframe');
         setElementProperty('top', y + 'px', 'CCIframe');
         setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
         setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
+        setElementProperty('display', 'block', 'CCIframe');
       }
     }
   }