-namespace('kivi.CustomerVendor', function() {
+namespace('kivi.CustomerVendor', function(ns) {
- this.selectShipto = function() {
+ var kivi = namespace('kivi');
+
+ this.selectShipto = function(params) {
var shiptoId = $('#shipto_shipto_id').val();
if( shiptoId ) {
$(document.getElementById('shipto_'+ key)).val(data[key]);
$('#action_delete_shipto').show();
+
+ if( params.onFormSet )
+ params.onFormSet();
});
}
else {
$('#shipto :input').not(':button, :submit, :reset, :hidden').val('');
$('#action_delete_shipto').hide();
+
+ if( params.onFormSet )
+ params.onFormSet();
}
};
}
};
- this.selectContact = function() {
+ this.selectContact = function(params) {
var contactId = $('#contact_cp_id').val();
if( contactId ) {
$.getJSON(url, function(data) {
var contact = data.contact;
for(var key in contact)
- $(document.getElementById('contact_'+ key)).val(contact[key]);
+ $(document.getElementById('contact_'+ key)).val(contact[key])
var cvars = data.contact_cvars;
for(var key in cvars)
$(document.getElementById('contact_cvar_'+ key)).val(cvars[key]);
$('#action_delete_contact').show();
+
+ if( params.onFormSet )
+ params.onFormSet();
});
}
else {
$('#contacts :input').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
$('#action_delete_contact').hide();
+
+ if( params.onFormSet )
+ params.onFormSet();
}
$('#contact_cp_title_select, #contact_cp_abteilung_select').val('');
};
+ var mapSearchStmts = [
+ '#street',
+ ', ',
+ '#zipcode',
+ ' ',
+ '#city',
+ ', ',
+ '#country'
+ ];
+
+ this.showMapWidget = function(prefix, widgetWrapper) {
+ var result = {
+ };
+
+ $(function(){
+
+ widgetWrapper = $(widgetWrapper);
+
+ 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 isNotEmpty = function() {
+ for(var i in mapSearchElements)
+ if( mapSearchElements[i].val() == '' )
+ return false;
+ return true;
+ };
- this.showMap = function(prefix) {
- var searchStmts = [
- '#street',
- ', ',
- '#zipcode',
- ' ',
- '#city',
- ', ',
- '#country'
- ];
+ widgetWrapper
+ .html('<img src="image/map.png" alt="'+ kivi.t8("Map") +'" title="'+ kivi.t8("Map") +'" />')
+ .click(function(){
+ ns.showMap(prefix);
+ });
+ var testInputs = function() {
+ if( isNotEmpty() )
+ widgetWrapper.show();
+ else
+ widgetWrapper.hide();
+ };
+
+ result.testInputs = testInputs;
+
+ $(mapSearchElements)
+ .map(function() {
+ return this.toArray();
+ })
+ .keyup(testInputs)
+
+ if( !isNotEmpty() )
+ widgetWrapper.hide();
+
+ });
+
+ return result;
+ };
+
+ this.showMap = function(prefix) {
var searchString = "";
- for(var i in searchStmts) {
- var stmt = searchStmts[i];
+ for(var i in mapSearchStmts) {
+ var stmt = mapSearchStmts[i];
if( stmt.charAt(0) == '#' ) {
var val = $('#'+ prefix + stmt.substring(1)).val();
if( val )
empty_title = LxERP.t8('New contact'),
value_key = 'cp_id',
title_key = 'full_name',
- onchange = "namespace('kivi.CustomerVendor').selectContact();")
+ onchange = "namespace('kivi.CustomerVendor').selectContact({onFormSet: function(){contactsMapWidget.testInputs();}});",
+ )
%]
</td>
</tr>
<td>
[% L.input_tag('contact.cp_street', SELF.contact.cp_street, size = 40, maxlength = 75) %]
-
- <a href="#" onclick="namespace('kivi.CustomerVendor').showMap('contact_cp_');" title="[% 'Map' | $T8 %]">
- <img src="image/map.png" alt="[% 'Map' | $T8 %]" />
- </a>
+ <span id="contact_map"></span>
+ <script type="text/javascript">
+ var contactsMapWidget = namespace('kivi.CustomerVendor').showMapWidget('contact_cp_', $('#contact_map'));
+ </script>
</td>
</tr>
title_key = 'displayable_id',
with_empty = 1,
empty_title = LxERP.t8('New shipto'),
- onchange = "namespace('kivi.CustomerVendor').selectShipto();"
+ onchange = "namespace('kivi.CustomerVendor').selectShipto({onFormSet: function(){shiptoMapWidget.testInputs();}});",
)
%]
</td>
<td>
[% L.input_tag('shipto.shiptostreet', SELF.shipto.shiptostreet, size = 35, maxlength = 75) %]
- <a href="#" onclick="namespace('kivi.CustomerVendor').showMap('shipto_shipto');" title="[% 'Map' | $T8 %]">
- <img src="image/map.png" alt="[% 'Map' | $T8 %]" />
- </a>
+ <span id="shipto_map"></span>
+ <script type="text/javascript">
+ var shiptoMapWidget = namespace('kivi.CustomerVendor').showMapWidget('shipto_shipto', $('#shipto_map'));
+ </script>
</td>
</tr>