ct.pl als Controller
[kivitendo-erp.git] / js / kivi.CustomerVendor.js
1 namespace('kivi.CustomerVendor', function() {
2
3   this.selectShipto = function() {
4     var shiptoId = $('#shipto_shipto_id').val();
5
6     if( shiptoId ) {
7       var url = 'controller.pl?action=CustomerVendor/ajaj_get_shipto&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ shiptoId;
8
9       $.getJSON(url, function(data) {
10         for(var key in data)
11           $(document.getElementById('shipto_'+ key)).val(data[key]);
12
13         $('#action_delete_shipto').show();
14       });
15     }
16     else {
17       $('#shipto :input').not(':button, :submit, :reset, :hidden').val('');
18
19       $('#action_delete_shipto').hide();
20     }
21   };
22
23   this.selectDelivery = function(fromDate, toDate) {
24     var deliveryId = $('#delivery_id').val();
25
26     if( !deliveryId )
27       $("#delivery").empty();
28     else {
29       var url = 'controller.pl?action=CustomerVendor/get_delivery&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ $('#delivery_id').val();
30
31       if( fromDate && toDate )
32         url += '&delivery_from='+ fromDate +'&delivery_to='+ toDate;
33
34       $('#delivery').load(url);
35     }
36   };
37
38   this.selectContact = function() {
39     var contactId = $('#contact_cp_id').val();
40
41     if( contactId ) {
42       var url = 'controller.pl?action=CustomerVendor/ajaj_get_contact&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&contact_id='+ contactId;
43
44       $.getJSON(url, function(data) {
45         var contact = data.contact;
46         for(var key in contact)
47           $(document.getElementById('contact_'+ key)).val(contact[key]);
48
49         var cvars = data.contact_cvars;
50         for(var key in cvars)
51           $(document.getElementById('contact_cvar_'+ key)).val(cvars[key]);
52
53         $('#action_delete_contact').show();
54       });
55     }
56     else {
57       $('#contacts :input').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
58
59       $('#action_delete_contact').hide();
60     }
61
62     $('#contact_cp_title_select, #contact_cp_abteilung_select').val('');
63   };
64
65
66   this.showMap = function(prefix) {
67     var searchStmts = [
68       '#street',
69       ', ',
70       '#zipcode',
71       ' ',
72       '#city',
73       ', ',
74       '#country'
75     ];
76
77     var searchString = "";
78
79     for(var i in searchStmts) {
80       var stmt = searchStmts[i];
81       if( stmt.charAt(0) == '#' ) {
82         var val = $('#'+ prefix + stmt.substring(1)).val();
83         if( val )
84           searchString += val;
85       }
86       else
87         searchString += stmt;
88     }
89
90     var url = 'https://maps.google.com/maps?q='+ encodeURIComponent(searchString);
91
92     window.open(url, '_blank');
93     window.focus();
94   };
95
96   this.showHistoryWindow = function(id) {
97     var xPos = (screen.width - 800) / 2;
98     var yPos = (screen.height - 500) / 2;
99     var parm = "left="+ xPos +",top="+ yPos +",width=800,height=500,status=yes,scrollbars=yes";
100     var url = "common.pl?INPUT_ENCODING=UTF-8&action=show_history&longdescription=&input_name="+ encodeURIComponent(id);
101     window.open(url, "_new_generic", parm);
102   };
103 });