kivitendo/js/kivi.CustomerVendor.js @ 16e18c50
bc998bc1 | Thomas Heck | namespace('kivi.CustomerVendor', function(ns) {
|
||
4cb3a908 | Thomas Heck | |||
bc998bc1 | Thomas Heck | this.selectShipto = function(params) {
|
||
4cb3a908 | Thomas Heck | var shiptoId = $('#shipto_shipto_id').val();
|
||
if( shiptoId ) {
|
||||
var url = 'controller.pl?action=CustomerVendor/ajaj_get_shipto&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ shiptoId;
|
||||
$.getJSON(url, function(data) {
|
||||
for(var key in data)
|
||||
$(document.getElementById('shipto_'+ key)).val(data[key]);
|
||||
$('#action_delete_shipto').show();
|
||||
bc998bc1 | Thomas Heck | |||
if( params.onFormSet )
|
||||
params.onFormSet();
|
||||
4cb3a908 | Thomas Heck | });
|
||
}
|
||||
else {
|
||||
$('#shipto :input').not(':button, :submit, :reset, :hidden').val('');
|
||||
$('#action_delete_shipto').hide();
|
||||
bc998bc1 | Thomas Heck | |||
if( params.onFormSet )
|
||||
params.onFormSet();
|
||||
4cb3a908 | Thomas Heck | }
|
||
};
|
||||
this.selectDelivery = function(fromDate, toDate) {
|
||||
var deliveryId = $('#delivery_id').val();
|
||||
if( !deliveryId )
|
||||
$("#delivery").empty();
|
||||
else {
|
||||
var url = 'controller.pl?action=CustomerVendor/get_delivery&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&shipto_id='+ $('#delivery_id').val();
|
||||
if( fromDate && toDate )
|
||||
url += '&delivery_from='+ fromDate +'&delivery_to='+ toDate;
|
||||
$('#delivery').load(url);
|
||||
}
|
||||
};
|
||||
65690235 | Moritz Bunkus | this.setCustomVariablesFromAJAJ = function(cvars) {
|
||
for (var key in cvars) {
|
||||
var cvar = cvars[key];
|
||||
var $ctrl = $('#contact_cvars_'+ key);
|
||||
console.log($ctrl, cvar);
|
||||
if (cvar.type == 'bool')
|
||||
$ctrl.prop('checked', cvar.value == 1 ? 'checked' : '');
|
||||
else if ((cvar.type == 'customer') || (cvar.type == 'vendor'))
|
||||
kivi.CustomerVendorPicker($ctrl).set_item({ id: cvar.id, name: cvar.value });
|
||||
else if (cvar.type == 'part')
|
||||
kivi.PartPicker($ctrl).set_item({ id: cvar.id, name: cvar.value });
|
||||
else
|
||||
$ctrl.val(cvar.value);
|
||||
}
|
||||
};
|
||||
bc998bc1 | Thomas Heck | this.selectContact = function(params) {
|
||
4cb3a908 | Thomas Heck | var contactId = $('#contact_cp_id').val();
|
||
a56b873b | Thomas Heck | var url = 'controller.pl?action=CustomerVendor/ajaj_get_contact&id='+ $('#cv_id').val() +'&db='+ $('#db').val() +'&contact_id='+ contactId;
|
||
4cb3a908 | Thomas Heck | |||
a56b873b | Thomas Heck | $.getJSON(url, function(data) {
|
||
var contact = data.contact;
|
||||
for(var key in contact)
|
||||
$(document.getElementById('contact_'+ key)).val(contact[key])
|
||||
4cb3a908 | Thomas Heck | |||
65690235 | Moritz Bunkus | kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.contact_cvars);
|
||
4cb3a908 | Thomas Heck | |||
a56b873b | Thomas Heck | if ( contactId )
|
||
4cb3a908 | Thomas Heck | $('#action_delete_contact').show();
|
||
a56b873b | Thomas Heck | else
|
||
$('#action_delete_contact').hide();
|
||||
bc998bc1 | Thomas Heck | |||
a56b873b | Thomas Heck | if ( params.onFormSet )
|
||
bc998bc1 | Thomas Heck | params.onFormSet();
|
||
a56b873b | Thomas Heck | });
|
||
4cb3a908 | Thomas Heck | |||
$('#contact_cp_title_select, #contact_cp_abteilung_select').val('');
|
||||
};
|
||||
bc998bc1 | Thomas Heck | var mapSearchStmts = [
|
||
'#street',
|
||||
', ',
|
||||
'#zipcode',
|
||||
' ',
|
||||
'#city',
|
||||
', ',
|
||||
'#country'
|
||||
];
|
||||
df601bd3 | Moritz Bunkus | this.MapWidget = function(prefix, source_address)
|
||
ef6fcba9 | Thomas Heck | {
|
||
var $mapSearchElements = [];
|
||||
var $widgetWrapper;
|
||||
bc998bc1 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | var init = function() {
|
||
if( $mapSearchElements.length > 0 )
|
||||
return;
|
||||
bc998bc1 | Thomas Heck | |||
for(var i in mapSearchStmts) {
|
||||
var stmt = mapSearchStmts[i];
|
||||
if( stmt.charAt(0) == '#' ) {
|
||||
ef6fcba9 | Thomas Heck | var $elem = $('#'+ prefix + stmt.substring(1));
|
||
if( $elem )
|
||||
$mapSearchElements.push($elem);
|
||||
bc998bc1 | Thomas Heck | }
|
||
}
|
||||
ef6fcba9 | Thomas Heck | };
|
||
bc998bc1 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | var isNotEmpty = function() {
|
||
for(var i in $mapSearchElements)
|
||||
16e18c50 | Moritz Bunkus | if( ($mapSearchElements[i].attr('id') != prefix + 'country') && ($mapSearchElements[i].val() === '') )
|
||
ef6fcba9 | Thomas Heck | return false;
|
||
return true;
|
||||
};
|
||||
4cb3a908 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | var showMap = function() {
|
||
var searchString = "";
|
||||
4cb3a908 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | for(var i in mapSearchStmts) {
|
||
var stmt = mapSearchStmts[i];
|
||||
if( stmt.charAt(0) == '#' ) {
|
||||
var val = $('#'+ prefix + stmt.substring(1)).val();
|
||||
if( val )
|
||||
searchString += val;
|
||||
}
|
||||
bc998bc1 | Thomas Heck | else
|
||
ef6fcba9 | Thomas Heck | searchString += stmt;
|
||
}
|
||||
bc998bc1 | Thomas Heck | |||
df601bd3 | Moritz Bunkus | source_address = source_address || '';
|
||
16e18c50 | Moritz Bunkus | var query = source_address !== '' ? 'saddr=' + encodeURIComponent(source_address) + '&daddr=' : 'q=';
|
||
df601bd3 | Moritz Bunkus | var url = 'https://maps.google.com/maps?' + query + encodeURIComponent(searchString);
|
||
bc998bc1 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | window.open(url, '_blank');
|
||
window.focus();
|
||||
};
|
||||
bc998bc1 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | var render = function(widgetWrapper) {
|
||
init();
|
||||
bc998bc1 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | $widgetWrapper = $(widgetWrapper);
|
||
bc998bc1 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | $widgetWrapper
|
||
.html('<img src="image/map.png" alt="'+ kivi.t8("Map") +'" title="'+ kivi.t8("Map") +'" />')
|
||||
.click(function() {
|
||||
showMap();
|
||||
});
|
||||
for(var i in $mapSearchElements)
|
||||
2c45e101 | Moritz Bunkus | $mapSearchElements[i].keyup(testInputs);
|
||
ef6fcba9 | Thomas Heck | this.testInputs();
|
||
};
|
||||
bc998bc1 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | var testInputs = function() {
|
||
init();
|
||||
4cb3a908 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | if( isNotEmpty() )
|
||
$widgetWrapper.show();
|
||||
4cb3a908 | Thomas Heck | else
|
||
ef6fcba9 | Thomas Heck | $widgetWrapper.hide();
|
||
};
|
||||
4cb3a908 | Thomas Heck | |||
ef6fcba9 | Thomas Heck | this.render = render;
|
||
this.testInputs = testInputs;
|
||||
4cb3a908 | Thomas Heck | };
|
||
this.showHistoryWindow = function(id) {
|
||||
var xPos = (screen.width - 800) / 2;
|
||||
var yPos = (screen.height - 500) / 2;
|
||||
var parm = "left="+ xPos +",top="+ yPos +",width=800,height=500,status=yes,scrollbars=yes";
|
||||
var url = "common.pl?INPUT_ENCODING=UTF-8&action=show_history&longdescription=&input_name="+ encodeURIComponent(id);
|
||||
window.open(url, "_new_generic", parm);
|
||||
};
|
||||
53d80f2a | Moritz Bunkus | |||
this.update_dial_action = function($input) {
|
||||
var $action = $('#' + $input.prop('id') + '-dial-action');
|
||||
if (!$action)
|
||||
return true;
|
||||
var number = $input.val().replace(/\s+/g, '');
|
||||
16e18c50 | Moritz Bunkus | if (number === '')
|
||
53d80f2a | Moritz Bunkus | $action.hide();
|
||
else
|
||||
$action.prop('href', 'controller.pl?action=CTI/call&number=' + encodeURIComponent(number)).show();
|
||||
return true;
|
||||
};
|
||||
this.init_dial_action = function(input) {
|
||||
if ($('#_cti_enabled').val() != 1)
|
||||
return false;
|
||||
var $input = $(input);
|
||||
var action_id = $input.prop('id') + '-dial-action';
|
||||
if (!$('#' + action_id).size()) {
|
||||
var $action = $('<a href="" id="' + action_id + '" class="cti_call_action" target="_blank" tabindex="-1"></a>');
|
||||
$input.wrap('<span nobr></span>').after($action);
|
||||
$input.change(function() { kivi.CustomerVendor.update_dial_action($input); });
|
||||
}
|
||||
kivi.CustomerVendor.update_dial_action($input);
|
||||
return true;
|
||||
};
|
||||
685108d7 | Sven Schöling | |||
this.inline_report = function(target, source, data){
|
||||
$.ajax({
|
||||
url: source,
|
||||
success: function (rsp) {
|
||||
$(target).html(rsp);
|
||||
$(target).find('.paginate').find('a').click(function(event){ ns.redirect_event(event, target) });
|
||||
$(target).find('a.report-generator-header-link').click(function(event){ ns.redirect_event(event, target) });
|
||||
},
|
||||
data: data,
|
||||
});
|
||||
};
|
||||
this.redirect_event = function(event, target){
|
||||
event.preventDefault();
|
||||
ns.inline_report(target, event.target + '', {});
|
||||
};
|
||||
4cb3a908 | Thomas Heck | });
|
||
53d80f2a | Moritz Bunkus | |||
function local_reinit_widgets() {
|
||||
$('#cv_phone,#shipto_shiptophone,#contact_cp_phone1,#contact_cp_phone2,#contact_cp_mobile1,#contact_cp_mobile2').each(function(idx, elt) {
|
||||
kivi.CustomerVendor.init_dial_action($(elt));
|
||||
});
|
||||
}
|