diff --git a/addressbook/inc/class.addressbook_hooks.inc.php b/addressbook/inc/class.addressbook_hooks.inc.php index b6aa7ad822..96a5a93f45 100644 --- a/addressbook/inc/class.addressbook_hooks.inc.php +++ b/addressbook/inc/class.addressbook_hooks.inc.php @@ -213,6 +213,22 @@ class addressbook_hooks 'admin' => false, 'default'=> 'infolog', ); + + $settings['geolocation_src'] = array( + 'type' => 'select', + 'label' => 'Default geolocation source address', + 'name' => 'geolocation_src', + 'values' => array( + 'browser' => lang('Browser location'), + 'one' => lang('Business address'), + 'two' => lang('Private address') + ), + 'help' => 'Select a source address to be used in geolocation routing system', + 'xmlrpc' => True, + 'admin' => false, + 'default'=> 'browser', + ); + $settings[] = array( 'type' => 'section', 'title' => lang('Data exchange settings'), @@ -528,8 +544,9 @@ class addressbook_hooks } // geolocation pre-defined maps $geoLocation = array( - array('id' => 'http://maps.google.com/?q=%s+%t+%z+%c', 'label' => 'Google Maps'), - array('id' => 'https://www.bing.com/maps/?q=%s+%t+%z+%c', 'label' => 'Bing Maps') + array('id' => 'https://maps.here.com/directions/drive{{%sr=/%sr}}%s0,%t0,%z0,%c0{{%d=/%d}}%s1,%t1,%z1', 'label' => 'Here Maps'), + array('id' => 'http://maps.google.com/{{%sr=?saddr=%sr}}%s0+%t0+%z0+%c0{{%d=&daddr=%d}}%s1+%t1+%z1+%c1', 'label' => 'Google Maps'), + array('id' => 'https://www.bing.com/maps/{{%sr=?rtp=adr.%sr}}%s0+%t0+%z0+%c0{{%d=~adr.%d}}%s1+%t1+%z1+%c1', 'label' => 'Bing Maps') ); $ret = array( 'sel_options' => array( diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index bbc0ac7bf8..aa7ae2e2ec 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -686,18 +686,19 @@ class addressbook_ui extends addressbook_bo $actions['geolocation'] = array( 'caption' => 'GeoLocation', 'icon' => 'map', - //'enabled' => 'javaScript:app.addressbook.geoLocation', 'group' => ++$group, 'children' => array ( 'private' => array( 'caption' => 'Private Address', 'enabled' => 'javaScript:app.addressbook.geoLocation_enabled', - 'onExecute' => 'javaScript:app.addressbook.geoLocationExec' + 'onExecute' => 'javaScript:app.addressbook.geoLocationExec', + ), 'business' => array( 'caption' => 'Buisness Address', 'enabled' => 'javaScript:app.addressbook.geoLocation_enabled', - 'onExecute' => 'javaScript:app.addressbook.geoLocationExec' + 'onExecute' => 'javaScript:app.addressbook.geoLocationExec', + ) ) ); @@ -1004,6 +1005,18 @@ window.egw_LAB.wait(function() { Api\Json\Response::get()->data($new_id == $list_id ? "true" : $new_id); } + /** + * Ajax function to get contact data out of provided account_id + * + * @param type $account_id + */ + function ajax_get_contact ($account_id) + { + $bo = new Api\Contacts(); + $contact = $bo->read('account:'.$account_id[0]); + Api\Json\Response::get()->data($contact); + } + /** * apply an action to multiple contacts * diff --git a/addressbook/js/app.js b/addressbook/js/app.js index 1e949208b1..91cbfd2da2 100644 --- a/addressbook/js/app.js +++ b/addressbook/js/app.js @@ -924,8 +924,34 @@ app.classes.addressbook = AppJS.extend( */ geoLocation_enabled: function(_action, _selected) { + // multiple selection is not supported + if (_selected.length>1) return false; + + var url = egw.config('geolocation_url'); + if (url) url = url[0]; + + // exit if no url or invalide url given + if (!url || typeof url === 'undefined' || typeof url !== 'string') + { + egw.debug('warn','no url or invalid url given as geoLocationUrl'); + return false; + } var content = egw.dataGetUIDdata(_selected[0].id); - return this.geoLocationUrl(content.data,_action.id === 'business'?'one':'two'); + var type = _action.id === 'business'?'one':'two'; + var addrs = [ + content.data['adr_'+type+'_street'], + content.data['adr_'+type+'_locality'], + content.data['adr_'+type+'_countrycode'], + content.data['adr_'+type+'_postalcode'] + ]; + + var fields = ''; + // Replcae placeholders with acctual values + for (var i=0;i < addrs.length; i++) + { + fields += addrs[i] ? addrs[i] : ''; + } + return (url !== '' && fields !== '')?true:false; }, /** @@ -933,14 +959,16 @@ app.classes.addressbook = AppJS.extend( * site configuration * * @param {object} _data - * @param {string} _type type of address, it can be either 'one' as business - * or 'two' as private address. + * @param {string} _dest_type type of destination address ('one'| 'two') + * @param {object} _src_data address data to be used as source contact data|coordination object + * @param {string} _src_type type of source address ('browser'|'one'|'two') + * * * @returns {Boolean|string} return url and return false if no address */ - geoLocationUrl: function (_data, _type) + geoLocationUrl: function (_dest_data, _dest_type,_src_data, _src_type) { - var type = _type || 'one'; + var dest_type = _dest_type || 'one'; var url = egw.config('geolocation_url'); if (url) url = url[0]; @@ -952,22 +980,47 @@ app.classes.addressbook = AppJS.extend( } // array of placeholders with their representing values - var ph = [ - {id:'s',val:_data['adr_'+type+'_street']}, - {id:'t',val:_data['adr_'+type+'_locality']}, - {id:'c',val:_data['adr_'+type+'_countrycode']}, - {id:'z',val:_data['adr_'+type+'_postalcode']} - ]; - var empty = true; + var addrs = [ - // Replcae placeholders with acctual values - for (var i=0;i < ph.length; i++) + [ // source address + {id:'s0',val:_src_type === 'browser'?_src_data.latitude:_src_data['adr_'+_src_type+'_street']}, + {id:'t0',val:_src_type === 'browser'?_src_data.longitude:_src_data['adr_'+_src_type+'_locality']}, + {id:'c0',val:_src_type === 'browser'?'':_src_data['adr_'+_src_type+'_countrycode']}, + {id:'z0',val:_src_type === 'browser'?'':_src_data['adr_'+_src_type+'_postalcode']} + ], + [ // destination address + {id:'s1',val:_dest_data['adr_'+dest_type+'_street']}, + {id:'t1',val:_dest_data['adr_'+dest_type+'_locality']}, + {id:'c1',val:_dest_data['adr_'+dest_type+'_countrycode']}, + {id:'z1',val:_dest_data['adr_'+dest_type+'_postalcode']} + ] + ]; + + var src_param = url.match(/{{%sr=.*%s}}/ig); + if (src_param[0]) { - empty = ph[i]['val']? false : true; - url = url.replace('%'+ph[i]['id'], ph[i]['val']? ph[i]['val'] : ""); + src_param = src_param[0].replace(/{{$sr=/,''); + src_param = src_param.replace(/%sr}}/,''); + url = url.replace(/{{%sr=.*%sr}}/, src_param) } - return (url !== '' && !empty ? url:false); + var d_param = url.match(/{{%d=.*%d}}/ig); + if (d_param[0]) + { + d_param = d_param[0].replace(/{{%d=/,''); + d_param = d_param.replace(/%d}}/,''); + url = url.replace(/{{%d=.*%d}}/, d_param) + } + + // Replcae placeholders with acctual values + for (var j=0;j