X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/60d93ca0876dc20fd02cd886aa2f653119831d55..bc998bc1f290dd5768a15c183953a05ad24c5c7a:/js/kivi.CustomerVendor.js diff --git a/js/kivi.CustomerVendor.js b/js/kivi.CustomerVendor.js index 371434c21..134efb492 100644 --- a/js/kivi.CustomerVendor.js +++ b/js/kivi.CustomerVendor.js @@ -1,6 +1,8 @@ -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 ) { @@ -11,12 +13,18 @@ namespace('kivi.CustomerVendor', function() { $(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(); } }; @@ -35,7 +43,7 @@ namespace('kivi.CustomerVendor', function() { } }; - this.selectContact = function() { + this.selectContact = function(params) { var contactId = $('#contact_cp_id').val(); if( contactId ) { @@ -44,40 +52,99 @@ namespace('kivi.CustomerVendor', function() { $.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(''+ kivi.t8(') + .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 )