1 namespace('kivi.CustomerVendor', function(ns) {
3 this.selectShipto = function(params) {
4 var shiptoId = $('#shipto_shipto_id').val();
7 var url = 'controller.pl?action=CustomerVendor/ajaj_get_shipto&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ shiptoId;
9 $.getJSON(url, function(data) {
11 $('#shipto_'+ key).val(data[key]);
13 $('#action_delete_shipto').show();
15 if( params.onFormSet )
20 $('#shipto :input').not(':button, :submit, :reset, :hidden').val('');
22 $('#action_delete_shipto').hide();
24 if( params.onFormSet )
29 this.selectDelivery = function(fromDate, toDate) {
30 var deliveryId = $('#delivery_id').val();
33 $("#delivery").empty();
35 var url = 'controller.pl?action=CustomerVendor/get_delivery&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ $('#delivery_id').val();
37 if( fromDate && toDate )
38 url += '&delivery_from='+ fromDate +'&delivery_to='+ toDate;
40 $('#delivery').load(url);
44 this.setCustomVariablesFromAJAJ = function(cvars) {
45 for (var key in cvars) {
46 var cvar = cvars[key];
47 var $ctrl = $('#contact_cvars_'+ key);
49 if (cvar.type == 'bool')
50 $ctrl.prop('checked', cvar.value == 1 ? 'checked' : '');
52 else if ((cvar.type == 'customer') || (cvar.type == 'vendor'))
53 kivi.CustomerVendorPicker($ctrl).set_item({ id: cvar.id, name: cvar.value });
55 else if (cvar.type == 'part')
56 kivi.PartPicker($ctrl).set_item({ id: cvar.id, name: cvar.value });
59 $ctrl.val(cvar.value);
63 this.selectContact = function(params) {
64 var contactId = $('#contact_cp_id').val();
66 var url = 'controller.pl?action=CustomerVendor/ajaj_get_contact&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&contact_id='+ contactId;
68 $.getJSON(url, function(data) {
69 var contact = data.contact;
70 for(var key in contact)
71 $('#contact_'+ key).val(contact[key])
73 kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.contact_cvars);
76 $('#action_delete_contact').show();
78 $('#action_delete_contact').hide();
80 if ( params.onFormSet )
84 $('#contact_cp_title_select, #contact_cp_abteilung_select').val('');
87 var mapSearchStmts = [
97 this.MapWidget = function(prefix, source_address)
99 var $mapSearchElements = [];
102 var init = function() {
103 if( $mapSearchElements.length > 0 )
106 for(var i in mapSearchStmts) {
107 var stmt = mapSearchStmts[i];
108 if( stmt.charAt(0) == '#' ) {
109 var $elem = $('#'+ prefix + stmt.substring(1));
111 $mapSearchElements.push($elem);
116 var isNotEmpty = function() {
117 for(var i in $mapSearchElements)
118 if( ($mapSearchElements[i].attr('id') != prefix + 'country') && ($mapSearchElements[i].val() === '') )
123 var showMap = function() {
124 var searchString = "";
126 for(var i in mapSearchStmts) {
127 var stmt = mapSearchStmts[i];
128 if( stmt.charAt(0) == '#' ) {
129 var val = $('#'+ prefix + stmt.substring(1)).val();
134 searchString += stmt;
137 source_address = source_address || '';
138 var query = source_address !== '' ? 'saddr=' + encodeURIComponent(source_address) + '&daddr=' : 'q=';
139 var url = 'https://maps.google.com/maps?' + query + encodeURIComponent(searchString);
141 window.open(url, '_blank');
145 var render = function(widgetWrapper) {
148 $widgetWrapper = $(widgetWrapper);
151 .html('<img src="image/map.png" alt="'+ kivi.t8("Map") +'" title="'+ kivi.t8("Map") +'" />')
155 for(var i in $mapSearchElements)
156 $mapSearchElements[i].keyup(testInputs);
160 var testInputs = function() {
164 $widgetWrapper.show();
166 $widgetWrapper.hide();
169 this.render = render;
170 this.testInputs = testInputs;
173 this.showHistoryWindow = function(id) {
174 var xPos = (screen.width - 800) / 2;
175 var yPos = (screen.height - 500) / 2;
176 var parm = "left="+ xPos +",top="+ yPos +",width=800,height=500,status=yes,scrollbars=yes";
177 var url = "common.pl?INPUT_ENCODING=UTF-8&action=show_history&longdescription=&input_name="+ encodeURIComponent(id);
178 window.open(url, "_new_generic", parm);
181 this.update_dial_action = function($input) {
182 var $action = $('#' + $input.prop('id') + '-dial-action');
187 var number = $input.val().replace(/\s+/g, '');
191 $action.prop('href', 'controller.pl?action=CTI/call&number=' + encodeURIComponent(number)).show();
196 this.init_dial_action = function(input) {
197 if ($('#_cti_enabled').val() != 1)
200 var $input = $(input);
201 var action_id = $input.prop('id') + '-dial-action';
203 if (!$('#' + action_id).size()) {
204 var $action = $('<a href="" id="' + action_id + '" class="cti_call_action" target="_blank" tabindex="-1"></a>');
205 $input.wrap('<span nobr></span>').after($action);
207 $input.change(function() { kivi.CustomerVendor.update_dial_action($input); });
210 kivi.CustomerVendor.update_dial_action($input);
215 this.inline_report = function(target, source, data){
218 success: function (rsp) {
220 $(target).find('.paginate').find('a').click(function(event){ ns.redirect_event(event, target) });
221 $(target).find('a.report-generator-header-link').click(function(event){ ns.redirect_event(event, target) });
226 this.redirect_event = function(event, target){
227 event.preventDefault();
228 ns.inline_report(target, event.target + '', {});
232 function local_reinit_widgets() {
233 $('#cv_phone,#shipto_shiptophone,#contact_cp_phone1,#contact_cp_phone2,#contact_cp_mobile1,#contact_cp_mobile2').each(function(idx, elt) {
234 kivi.CustomerVendor.init_dial_action($(elt));