mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-02 20:19:27 +01:00
Implement routing system for geolocation feature:
- Add default source address preference - Routing between user address and selected contact's address
This commit is contained in:
parent
a8b07f7f21
commit
4aaee9acd2
@ -213,6 +213,22 @@ class addressbook_hooks
|
|||||||
'admin' => false,
|
'admin' => false,
|
||||||
'default'=> 'infolog',
|
'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(
|
$settings[] = array(
|
||||||
'type' => 'section',
|
'type' => 'section',
|
||||||
'title' => lang('Data exchange settings'),
|
'title' => lang('Data exchange settings'),
|
||||||
@ -528,8 +544,9 @@ class addressbook_hooks
|
|||||||
}
|
}
|
||||||
// geolocation pre-defined maps
|
// geolocation pre-defined maps
|
||||||
$geoLocation = array(
|
$geoLocation = array(
|
||||||
array('id' => 'http://maps.google.com/?q=%s+%t+%z+%c', 'label' => 'Google 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' => 'https://www.bing.com/maps/?q=%s+%t+%z+%c', 'label' => 'Bing 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(
|
$ret = array(
|
||||||
'sel_options' => array(
|
'sel_options' => array(
|
||||||
|
@ -686,18 +686,19 @@ class addressbook_ui extends addressbook_bo
|
|||||||
$actions['geolocation'] = array(
|
$actions['geolocation'] = array(
|
||||||
'caption' => 'GeoLocation',
|
'caption' => 'GeoLocation',
|
||||||
'icon' => 'map',
|
'icon' => 'map',
|
||||||
//'enabled' => 'javaScript:app.addressbook.geoLocation',
|
|
||||||
'group' => ++$group,
|
'group' => ++$group,
|
||||||
'children' => array (
|
'children' => array (
|
||||||
'private' => array(
|
'private' => array(
|
||||||
'caption' => 'Private Address',
|
'caption' => 'Private Address',
|
||||||
'enabled' => 'javaScript:app.addressbook.geoLocation_enabled',
|
'enabled' => 'javaScript:app.addressbook.geoLocation_enabled',
|
||||||
'onExecute' => 'javaScript:app.addressbook.geoLocationExec'
|
'onExecute' => 'javaScript:app.addressbook.geoLocationExec',
|
||||||
|
|
||||||
),
|
),
|
||||||
'business' => array(
|
'business' => array(
|
||||||
'caption' => 'Buisness Address',
|
'caption' => 'Buisness Address',
|
||||||
'enabled' => 'javaScript:app.addressbook.geoLocation_enabled',
|
'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);
|
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
|
* apply an action to multiple contacts
|
||||||
*
|
*
|
||||||
|
@ -924,8 +924,34 @@ app.classes.addressbook = AppJS.extend(
|
|||||||
*/
|
*/
|
||||||
geoLocation_enabled: function(_action, _selected)
|
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);
|
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
|
* site configuration
|
||||||
*
|
*
|
||||||
* @param {object} _data
|
* @param {object} _data
|
||||||
* @param {string} _type type of address, it can be either 'one' as business
|
* @param {string} _dest_type type of destination address ('one'| 'two')
|
||||||
* or 'two' as private address.
|
* @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
|
* @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');
|
var url = egw.config('geolocation_url');
|
||||||
if (url) url = url[0];
|
if (url) url = url[0];
|
||||||
|
|
||||||
@ -952,22 +980,47 @@ app.classes.addressbook = AppJS.extend(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// array of placeholders with their representing values
|
// array of placeholders with their representing values
|
||||||
var ph = [
|
var addrs = [
|
||||||
{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;
|
|
||||||
|
|
||||||
// Replcae placeholders with acctual values
|
[ // source address
|
||||||
for (var i=0;i < ph.length; i++)
|
{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;
|
src_param = src_param[0].replace(/{{$sr=/,'');
|
||||||
url = url.replace('%'+ph[i]['id'], ph[i]['val']? ph[i]['val'] : "");
|
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<addrs.length;j++)
|
||||||
|
{
|
||||||
|
for (var i=0;i < addrs[j].length; i++)
|
||||||
|
{
|
||||||
|
url = url.replace('%'+addrs[j][i]['id'], addrs[j][i]['val']? addrs[j][i]['val'] : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url !== ''? url : false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -979,7 +1032,26 @@ app.classes.addressbook = AppJS.extend(
|
|||||||
geoLocationExec: function (_action, _selected)
|
geoLocationExec: function (_action, _selected)
|
||||||
{
|
{
|
||||||
var content = egw.dataGetUIDdata(_selected[0].id);
|
var content = egw.dataGetUIDdata(_selected[0].id);
|
||||||
var url = this.geoLocationUrl(content.data,_action.id === 'business'?'one':'two');
|
var geolocation_src = egw.preference('geolocation_src','addressbook');
|
||||||
window.open(url,'_blank');
|
var self = this;
|
||||||
|
|
||||||
|
if (geolocation_src === 'browser' && navigator.geolocation)
|
||||||
|
{
|
||||||
|
navigator.geolocation.getCurrentPosition(function(position){
|
||||||
|
if (position && position.coords)
|
||||||
|
{
|
||||||
|
var url = self.geoLocationUrl(content.data,_action.id === 'business'?'one':'two', position.coords, 'browser');
|
||||||
|
window.open(url,'_blank');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
egw.json('addressbook.addressbook_ui.ajax_get_contact', [egw.user('account_id')],function(_data){
|
||||||
|
var url = self.geoLocationUrl(content.data,_action.id === 'business'?'one':'two', _data, geolocation_src === 'browser'?'one':geolocation_src);
|
||||||
|
window.open(url,'_blank');
|
||||||
|
}).sendRequest();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -118,5 +118,4 @@ select#addressbook-index_col_filter\[tid\] {
|
|||||||
#addressbook-index_addressbook-index-row select{
|
#addressbook-index_addressbook-index-row select{
|
||||||
float: right;
|
float: right;
|
||||||
width: 134px;
|
width: 134px;
|
||||||
}
|
}
|
||||||
#addressbook-index_nm.et2_nextmatch .egwGridView_outer thead tr {border-left: 12px solid transparent;}
|
|
@ -134,9 +134,6 @@ select#addressbook-index_col_filter\[tid\] {
|
|||||||
float: right;
|
float: right;
|
||||||
width: 134px;
|
width: 134px;
|
||||||
}
|
}
|
||||||
#addressbook-index_nm.et2_nextmatch .egwGridView_outer thead tr {
|
|
||||||
border-left: 12px solid transparent;
|
|
||||||
}
|
|
||||||
@media all {
|
@media all {
|
||||||
/* #############################################################################
|
/* #############################################################################
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user