CustomerVendor: MapWidget umgebaut
authorThomas Heck <theck@linet-services.de>
Tue, 16 Jul 2013 12:22:23 +0000 (14:22 +0200)
committerThomas Heck <theck@linet-services.de>
Tue, 16 Jul 2013 12:23:59 +0000 (14:23 +0200)
js/kivi.CustomerVendor.js
templates/webpages/customer_vendor/tabs/billing.html
templates/webpages/customer_vendor/tabs/contacts.html
templates/webpages/customer_vendor/tabs/shipto.html

index 928c673..aed7081 100644 (file)
@@ -84,78 +84,80 @@ namespace('kivi.CustomerVendor', function(ns) {
     '#country'
   ];
 
-  this.showMapWidget = function(prefix, widgetWrapper) {
-    var result = {
-    };
-
-    $(function(){
+  this.MapWidget = function(prefix)
+  {
+    var $mapSearchElements = [];
+    var $widgetWrapper;
 
-      widgetWrapper = $(widgetWrapper);
+    var init = function() {
+      if( $mapSearchElements.length > 0 )
+        return;
 
-      var mapSearchElements = [];
       for(var i in mapSearchStmts) {
         var stmt = mapSearchStmts[i];
         if( stmt.charAt(0) == '#' ) {
-          var elem = $('#'+ prefix + stmt.substring(1));
-          if( elem )
-            mapSearchElements.push(elem);
+          var $elem = $('#'+ prefix + stmt.substring(1));
+          if( $elem )
+            $mapSearchElements.push($elem);
         }
       }
+    };
 
-      var isNotEmpty = function() {
-        for(var i in mapSearchElements)
-          if( mapSearchElements[i].val() == '' )
-            return false;
-        return true;
-      };
+    var isNotEmpty = function() {
+      for(var i in $mapSearchElements)
+        if( $mapSearchElements[i].val() == '' )
+          return false;
+      return true;
+    };
 
-      widgetWrapper
-        .html('<img src="image/map.png" alt="'+ kivi.t8("Map") +'" title="'+ kivi.t8("Map") +'" />')
-        .click(function(){
-          ns.showMap(prefix);
-        });
+    var showMap = function() {
+      var searchString = "";
 
-      var testInputs = function() {
-        if( isNotEmpty() )
-          widgetWrapper.show();
+      for(var i in mapSearchStmts) {
+        var stmt = mapSearchStmts[i];
+        if( stmt.charAt(0) == '#' ) {
+          var val = $('#'+ prefix + stmt.substring(1)).val();
+          if( val )
+            searchString += val;
+        }
         else
-          widgetWrapper.hide();
-      };
+          searchString += stmt;
+      }
 
-      result.testInputs = testInputs;
+      var url = 'https://maps.google.com/maps?q='+ encodeURIComponent(searchString);
 
-      $(mapSearchElements)
-        .map(function() {
-          return this.toArray();
-        })
-        .keyup(testInputs)
+      window.open(url, '_blank');
+      window.focus();
+    };
 
-      if( !isNotEmpty() )
-        widgetWrapper.hide();
+    var render = function(widgetWrapper) {
+      init();
 
-    });
+      $widgetWrapper = $(widgetWrapper);
 
-    return result;
-  };
+      $widgetWrapper
+        .html('<img src="image/map.png" alt="'+ kivi.t8("Map") +'" title="'+ kivi.t8("Map") +'" />')
+        .click(function() {
+          showMap();
+        });
+      for(var i in $mapSearchElements)
+        $mapSearchElements[i].keyup(function() {
+          testInputs();
+        });
+      this.testInputs();
+    };
 
-  this.showMap = function(prefix) {
-    var searchString = "";
+    var testInputs = function() {
+      init();
 
-    for(var i in mapSearchStmts) {
-      var stmt = mapSearchStmts[i];
-      if( stmt.charAt(0) == '#' ) {
-        var val = $('#'+ prefix + stmt.substring(1)).val();
-        if( val )
-          searchString += val;
-      }
+      if( isNotEmpty() )
+        $widgetWrapper.show();
       else
-        searchString += stmt;
-    }
-
-    var url = 'https://maps.google.com/maps?q='+ encodeURIComponent(searchString);
+        $widgetWrapper.hide();
+    };
 
-    window.open(url, '_blank');
-    window.focus();
+    this.render = render;
+    this.testInputs = testInputs;
   };
 
   this.showHistoryWindow = function(id) {
index 7635af4..b7dfe9e 100644 (file)
         [% L.input_tag('cv.street', SELF.cv.street, size = 35, maxlength = 75) %]
         <span id="billing_map"></span>
         <script type="text/javascript">
-          kivi.CustomerVendor.showMapWidget('cv_', $('#billing_map'));
+          billingMapWidget = new kivi.CustomerVendor.MapWidget('cv_');
+          $(function() {
+            billingMapWidget.render($('#billing_map'));
+          });
         </script>
       </td>
     </tr>
index d2b87b1..6420cbe 100644 (file)
         [% L.input_tag('contact.cp_street', SELF.contact.cp_street, size = 40, maxlength = 75) %]
         <span id="contact_map"></span>
         <script type="text/javascript">
-        var contactsMapWidget = kivi.CustomerVendor.showMapWidget('contact_cp_', $('#contact_map'));
+          var contactsMapWidget = new kivi.CustomerVendor.MapWidget('contact_cp_');
+          $(function() {
+            contactsMapWidget.render($('#contact_map'));
+          });
         </script>
       </td>
     </tr>
index b4fbb28..0b238c3 100644 (file)
 
         <span id="shipto_map"></span>
         <script type="text/javascript">
-          var shiptoMapWidget = kivi.CustomerVendor.showMapWidget('shipto_shipto', $('#shipto_map'));
+          shiptoMapWidget = new kivi.CustomerVendor.MapWidget('shipto_shipto');
+          $(function() {
+            shiptoMapWidget.render($('#shipto_map'));
+          });
         </script>
       </td>
     </tr>