Changeset 12269

Show
Ignore:
Timestamp:
09/14/07 10:41:05 (1 year ago)
Author:
w_i
Message:

Added reverse geocoding, started adding optional xep key support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.helper.datamanager2/static/position/position_widget.css

    r12256 r12269  
    44} 
    55 
    6 .position_widget_tab_content_place .geoclue_butto
     6.position_widget_tab_content_place .geodata_bt
    77{ 
    88    margin-right: 5px; 
     
    1010    width: 16px; 
    1111    height: 16px; 
    12     background: url('refresh_geoclue.png'); 
     12    background: url('refresh_geodata.png'); 
    1313    cursor: pointer; 
    1414} 
  • trunk/midcom/midcom.helper.datamanager2/static/position/widget.js

    r12259 r12269  
    11var widgets = []; 
    22var current_pos = null; 
     3var position_marker = null; 
    34var widgets_mapstrations = []; 
    45 
     
    1011        widgets[w.id] = widget; 
    1112 
    12         var geoclue_btn = jQuery('.geoclue_button', widget); 
    13         var indicator = jQuery('.indicator', widget); 
    14         var status_box = jQuery('.status_box', widget); 
    15          
    16         var position_marker = null; 
     13        var geodata_btn = jQuery('#' + widget_id + '_geodata_btn', widget); 
     14        var indicator = jQuery('#' + widget_id + '_indicator', widget); 
     15        var status_box = jQuery('#' + widget_id + '_status_box', widget); 
     16 
     17        var backend_url = jQuery('input.position_widget_backend_url',widget).attr('value'); 
     18        var backend_service = jQuery('input.position_widget_backend_service',widget).attr('value'); 
     19         
     20        var input_data = {}; 
     21 
     22        jQuery('.position_widget_input',widget).each(function(i, o){ 
     23            var jqo = jQuery(o); 
     24            var key = get_key_name(jqo.attr('name')); 
     25            input_data[key] = { 
     26                id: jqo.attr('id'), 
     27                value: jqo.attr('value') 
     28            }; 
     29 
     30            if (input_data[key]['value'] == undefined) 
     31            { 
     32                input_data[key]['value'] = ''; 
     33            } 
     34        }); 
    1735 
    1836        widgets_mapstrations[widget_id] = mapstration; 
     
    2442            current_pos = point; 
    2543             
    26             jQuery('#' + input_data['latitude']['id']).attr('value',point.lat); 
    27             jQuery('#' + input_data['longitude']['id']).attr('value',point.lon); 
    28              
    29             set_marker('Current position'); 
    30         } 
    31          
    32         var input_data = {}; 
     44            jQuery('#' + input_data['latitude']['id']).attr('value',current_pos.lat); 
     45            jQuery('#' + input_data['longitude']['id']).attr('value',current_pos.lon); 
     46             
     47            set_marker('Current position','',widget_id); 
     48            get_reversed_geodata(); 
     49        } 
    3350 
    3451        indicator.hide(); 
    3552 
    36         geoclue_btn.bind('click', function(e){ 
    37             refresh_geoclue(); 
    38             geoclue_btn.hide(); 
     53        geodata_btn.bind('click', function(e){ 
     54            refresh_geodata(); 
     55            geodata_btn.hide(); 
    3956            indicator.show(); 
    4057        }); 
    41  
    42         function refresh_geoclue() 
    43         { 
    44             var backend_url = jQuery('input.position_widget_backend_url',widget).attr('value'); 
    45             var backend_service = jQuery('input.position_widget_backend_service',widget).attr('value'); 
    46  
     58         
     59        function get_reversed_geodata() 
     60        { 
    4761            var get_params = { 
    48                 service: backend_service 
     62                service: backend_service, 
     63                dir: 'reverse', 
     64                latitude: current_pos.lat, 
     65                longitude: current_pos.lon 
    4966            }; 
    50  
    51             jQuery('input.position_widget_input',widget).each(function(i,o){ 
    52                 var jqo = jQuery(o); 
    53                 var key = get_key_name(jqo.attr('name')); 
    54                 input_data[key] = { 
    55                     id: jqo.attr('id'), 
    56                     value: jqo.attr('value') 
    57                 }; 
    58                 if (input_data[key]['value'] == undefined) 
    59                 { 
    60                     input_data[key]['value'] = ''; 
    61                 } 
    62                 else 
    63                 { 
    64                     get_params[key] = input_data[key]['value']; 
    65                 } 
    66             }); 
    67  
     67             
    6868            jQuery.ajax({ 
    6969                type: "GET", 
     
    7373                error: function(request, type, expobj){ 
    7474                    parse_error(request.responseText); 
    75  
    76                     indicator.hide(); 
    77                     geoclue_btn.show(); 
     75                }, 
     76                success: function(data){ 
     77                    var parsed = parse_response(data); 
     78                    update_widget_inputs(parsed); 
     79                } 
     80            }); 
     81             
     82            function parse_error(error_string) 
     83                { 
     84                indicator.hide(); 
     85                geodata_btn.show(); 
     86                 
     87                status_box.html(error_string); 
     88                } 
     89 
     90            function parse_response(data) 
     91                { 
     92                    status_box.html(''); 
     93                     
     94                var results = []; 
     95                jQuery('position',data).each(function(idx) {             
     96                    var rel_this = jQuery(this); 
     97 
     98                    results[idx] = { 
     99                        accuracy: rel_this.find("accuracy").text(), 
     100                        city: rel_this.find("city").text(), 
     101                        region: rel_this.find("region").text(), 
     102                        country: rel_this.find("country").text(), 
     103                        accuracy: rel_this.find("accuracy").text() 
     104                    }; 
     105                }); 
     106 
     107                return results[0]; 
     108                } 
     109        } 
     110         
     111        function refresh_geodata() 
     112        { 
     113            var get_params = { 
     114                service: backend_service 
     115            }; 
     116 
     117            jQuery('.position_widget_input',widget).each(function(i, o){ 
     118                var jqo = jQuery(o); 
     119                var key = get_key_name(jqo.attr('name')); 
     120                input_data[key] = { 
     121                    id: jqo.attr('id'), 
     122                    value: jqo.attr('value') 
     123                }; 
     124 
     125                if (input_data[key]['value'] == undefined) 
     126                { 
     127                    input_data[key]['value'] = ''; 
     128                } 
     129                else 
     130                { 
     131                    get_params[key] = input_data[key]['value']; 
     132                } 
     133            }); 
     134 
     135            // jQuery.each(input_data, function(i,o){ 
     136            //     if (o['value'] != '') 
     137            //     { 
     138            //         get_params[i] = o['value']; 
     139            //     } 
     140            // }); 
     141 
     142            jQuery.ajax({ 
     143                type: "GET", 
     144                url: backend_url, 
     145                data: get_params, 
     146                dataType: "xml", 
     147                error: function(request, type, expobj){ 
     148                    parse_error(request.responseText); 
    78149                }, 
    79150                success: function(data){ 
     
    85156            function parse_error(error_string) 
    86157                { 
     158                indicator.hide(); 
     159                geodata_btn.show(); 
     160                 
    87161                status_box.html(error_string); 
    88162                } 
     
    114188        { 
    115189            indicator.hide(); 
    116             geoclue_btn.show(); 
    117  
    118             jQuery.each(location_data, function(key,value){ 
    119                 if (input_data[key]) 
    120                 { 
    121                     jQuery('#' + input_data[key]['id']).attr('value',value); 
    122                 } 
    123                 else 
    124                 { 
    125                     //console.log("Key: "+key+" not found in items."); 
    126                 } 
    127             }); 
     190            geodata_btn.show(); 
     191 
     192            update_widget_inputs(location_data); 
    128193 
    129194            current_pos = new LatLonPoint(location_data['latitude'],location_data['longitude']); 
     
    140205            } 
    141206             
    142             set_marker(label, info); 
     207            set_marker(label, info, widget_id); 
     208        } 
     209         
     210        function update_widget_inputs(location_data) 
     211        { 
     212            jQuery.each(location_data, function(key,value){ 
     213                if (input_data[key]) 
     214                { 
     215                    jQuery('#' + input_data[key]['id']).attr('value',value); 
     216                } 
     217                else 
     218                { 
     219                    //console.log("Key: "+key+" not found in items."); 
     220                } 
     221            }); 
    143222        } 
    144223 
    145224        function get_key_name(key) 
    146225        { 
    147             // if (pos = key.indexOf('name') != -1) 
    148             // { 
    149             //     return 'name'; 
    150             // } 
    151             if (pos = key.indexOf('country') != -1) 
    152             { 
    153                 return 'country'; 
    154             } 
    155             if (pos = key.indexOf('city') != -1) 
    156             { 
    157                 return 'city'; 
    158             } 
    159             if (pos = key.indexOf('street') != -1) 
    160             { 
    161                 return 'street'; 
    162             } 
    163             if (pos = key.indexOf('postalcode') != -1) 
    164             { 
    165                 return 'postalcode'; 
    166             } 
    167             if (pos = key.indexOf('latitude') != -1) 
    168             { 
    169                 return 'latitude'; 
    170             } 
    171             if (pos = key.indexOf('longitude') != -1) 
    172             { 
    173                 return 'longitude'; 
    174             } 
    175         } 
    176          
    177         function set_marker(label, info) 
    178         { 
    179             //console.log("set_marker label: "+label+" info: "+info); 
    180              
    181             if (position_marker != null) 
    182             { 
    183                  widgets_mapstrations[widget_id].removeMarker(position_marker); 
    184             } 
    185              
    186             position_marker = new Marker(current_pos); 
    187              
    188             if (label != undefined) 
    189             { 
    190                 position_marker.setLabel(label);                 
    191             } 
    192              
    193             if (info != undefined) 
    194             { 
    195                 position_marker.setInfoBubble(info);                 
    196             } 
    197              
    198             widgets_mapstrations[widget_id].addMarker(position_marker); 
    199  
    200             // if (info != undefined) 
    201             // { 
    202             //     position_marker.openBubble(); 
    203             // } 
     226            //var re = /^\s*(\s*)_(\w{5,11})_(\s*)$/; 
     227            var re = /widget_([a-z]*)_([a-z]{5,11})_([a-z]*)/; 
     228            var reg = re.exec(key); 
     229            // console.log("Reg: "+reg); 
     230            // console.log("Reg.length: "+reg.length); 
     231            // console.log("Reg[0]: "+reg[0]+" Reg[1]: "+reg[1]+" Reg[2]: "+reg[2]); 
     232             
     233            return reg[3]; 
    204234        } 
    205235 
     
    207237} 
    208238 
    209 function init_current_pos(lat,lon) 
     239function init_current_pos(widget_id,lat,lon) 
    210240{ 
    211241    current_pos = new LatLonPoint(lat,lon); 
     242    set_marker('Current position','',widget_id); 
     243} 
     244 
     245function set_marker(label, info, widget_id) 
     246{ 
     247    // console.log("set_marker label: "+label+" info: "+info+" widget_id: "+widget_id); 
     248     
     249    if (position_marker != null) 
     250    { 
     251         widgets_mapstrations[widget_id].removeMarker(position_marker); 
     252    } 
     253     
     254    position_marker = new Marker(current_pos); 
     255     
     256    if (label != undefined) 
     257    { 
     258        position_marker.setLabel(label);                 
     259    } 
     260     
     261    if (   info != undefined 
     262        && info != '') 
     263    { 
     264        position_marker.setInfoBubble(info); 
     265    } 
     266     
     267    widgets_mapstrations[widget_id].addMarker(position_marker); 
     268 
     269    // if (info != undefined) 
     270    // { 
     271    //     position_marker.openBubble(); 
     272    // } 
    212273} 
    213274 
  • trunk/midcom/midcom.helper.datamanager2/widget/position.php

    r12260 r12269  
    6464    var $service = null; 
    6565     
     66    var $_countrylist = array(); 
     67     
     68    var $_other_xep_keys = array(); 
     69     
    6670    /** 
    6771     * The initialization event handler post-processes the maxlength setting. 
     
    137141        $_MIDCOM->add_jquery_state_script($script); 
    138142         
     143        $this->_get_country_list(); 
     144         
     145        $this->_other_xep_keys = array( 
     146            'area', 
     147            'building', 
     148            'description', 
     149            'floor', 
     150            'region', 
     151            'room', 
     152            'text', 
     153            'uri', 
     154        ); 
     155         
    139156        return true; 
    140157    } 
     
    201218        $html = "\n<div id=\"{$this->_element_id}_tab_content_place\" class=\"position_widget_tab_content_place\"><!-- tab_content_place starts -->\n";         
    202219         
    203         $html .= "<div class=\"geoclue_button\" id='{$this->_element_id}_geoclue_button'></div>"; 
     220        $html .= "<div class=\"geodata_btn\" id='{$this->_element_id}_geodata_btn'></div>"; 
    204221        $html .= "<div class=\"indicator\" id='{$this->_element_id}_indicator' style=\"display: none;\"></div>"; 
    205222         
    206         // $html .= "<label for='{$this->_element_id}_input_place_name' id='{$this->_element_id}_input_place_name_label'>"; 
    207         // $html .= "<span class=\"field_text\">" . $_MIDCOM->i18n->get_string('name', 'org.routamc.positioning') . "</span>";         
    208         // $html .= "<input size=\"40\" class=\"shorttext position_widget_input position_widget_input_place_name\" id=\"{$this->_element_id}_input_place_name\" name=\"{$this->_element_id}_input_place_name\" type=\"text\" value=\"\" />"; 
    209         // $html .= "</label>"; 
    210          
    211         $html .= "<label for='{$this->_element_id}_input_place_country' id='{$this->_element_id}_input_place_country_label'>"; 
    212         $html .= "<span class=\"field_text\">" . $_MIDCOM->i18n->get_string('country', 'org.routamc.positioning') . "</span>";         
    213         $html .= "<input size=\"40\" class=\"shorttext position_widget_input position_widget_input_place_country\" id=\"{$this->_element_id}_input_place_country\" name=\"{$this->_element_id}_input_place_country\" type=\"text\" value=\"{$this->_type->location->country}\" />"; 
    214         $html .= "</label>"; 
     223        // $html .= "<div class=\"add_xep_keys_menu\" id='{$this->_element_id}_add_xep_keys_menu_holder'>"; 
     224        // $html .= "<select class=\"dropdown\" id=\"{$this->_element_id}_add_xep_keys_menu\" name=\"{$this->_element_id}_add_xep_keys_menu\">"; 
     225        // $html .= "<option value=\"\">" . $_MIDCOM->i18n->get_string('add xep keys', 'org.routamc.positioning') . "</option>"; 
     226        //  
     227        // foreach ($this->_other_xep_keys as $xep_key) 
     228        // { 
     229        //     $html .= "<option value=\"{$xep_key}\">{$xep_key}</option>";             
     230        // }         
     231        // $html .= "</select>"; 
     232        // $html .= "</div>"; 
     233         
     234        $html .= $this->_render_country_list($this->_type->location->country); 
    215235 
    216236        $city_name = ''; 
     
    235255        $html .= "<input size=\"40\" class=\"shorttext position_widget_input position_widget_input_place_postalcode\" id=\"{$this->_element_id}_input_place_postalcode\" name=\"{$this->_element_id}_input_place_postalcode\" type=\"text\" value=\"{$this->_type->location->postalcode}\" />"; 
    236256        $html .= "</label>"; 
    237  
     257         
     258        foreach ($this->_other_xep_keys as $xep_key) 
     259        { 
     260            if ($this->_type->location->$xep_key != '') 
     261            { 
     262                $html .= "<label for='{$this->_element_id}_input_place_{$xep_key}' id='{$this->_element_id}_input_place_{$xep_key}_label'>"; 
     263                $html .= "<span class=\"field_text\">" . $_MIDCOM->i18n->get_string($xep_key, 'org.routamc.positioning') . "</span>";         
     264                $html .= "<input size=\"40\" class=\"shorttext position_widget_input position_widget_input_place_{$xep_key}\" id=\"{$this->_element_id}_input_place_{$xep_key}\" name=\"{$this->_element_id}_input_place_{$xep_key}\" type=\"text\" value=\"{$this->_type->location->$xep_key}\" />"; 
     265                $html .= "</label>";                 
     266            } 
     267        } 
     268         
    238269        $html .= "<div id=\"{$this->_element_id}_status_box\" class=\"status_box\"></div>"; 
    239270         
     
    311342 
    312343        $orp_map = new org_routamc_positioning_map("{$this->_element_id}_map"); 
    313         //$orp_map->add_object($this->_type->storage); 
    314344        $html .= $orp_map->show(420,300,false); 
    315345 
     
    395425    } 
    396426     
     427    function _get_country_list() 
     428    { 
     429        $this->_countrylist = array 
     430        ( 
     431            '' => $this->_l10n_midcom->get('select your country'), 
     432        ); 
     433         
     434        $qb = org_routamc_positioning_country_dba::new_query_builder(); 
     435        $qb->add_constraint('code', '<>', ''); 
     436        $qb->add_order('name', 'ASC'); 
     437        $countries = $qb->execute_unchecked(); 
     438 
     439        if (count($countries) == 0) 
     440        { 
     441            debug_push_class(__CLASS__, __FUNCTION__); 
     442            debug_add('Cannot render country list: No countries found. You have to use org.routamc.positioning to import countries to database.'); 
     443            debug_pop(); 
     444        } 
     445         
     446        foreach ($countries as $country) 
     447        { 
     448            $this->_countrylist[$country->code] = $country->name; 
     449        } 
     450    } 
     451     
     452    function _render_country_list($current='') 
     453    { 
     454        $html = ''; 
     455         
     456        if (   empty($this->_countrylist) 
     457            || count($this->_countrylist) == 1) 
     458        { 
     459            $html .= "<label for='{$this->_element_id}_input_place_country' id='{$this->_element_id}_input_place_country_label'>"; 
     460            $html .= "<span class=\"field_text\">" . $_MIDCOM->i18n->get_string('country', 'org.routamc.positioning') . "</span>"; 
     461            $html .= "<input size=\"30\" class=\"shorttext position_widget_input position_widget_input_place_country\" id=\"{$this->_element_id}_input_place_country\" name=\"{$this->_element_id}_input_place_country\" type=\"text\" value=\"{$current}\" />"; 
     462            $html .= "</label>"; 
     463                     
     464            return $html; 
     465        } 
     466         
     467        $html .= "<label for='{$this->_element_id}_input_place_country' id='{$this->_element_id}_input_place_country_label'>"; 
     468        $html .= "<span class=\"field_text\">" . $_MIDCOM->i18n->get_string('country', 'org.routamc.positioning') . "</span>"; 
     469        $html .= "<select class=\"dropdown position_widget_input position_widget_input_place_country\" id=\"{$this->_element_id}_input_place_country\" name=\"{$this->_element_id}_input_place_country\">"; 
     470 
     471        foreach ($this->_countrylist as $code => $name) 
     472        { 
     473            $selected = ''; 
     474            if ($code == $current) 
     475            { 
     476                $selected = 'selected="selected"'; 
     477            } 
     478            $html .= "<option value=\"{$code}\" {$selected}>{$name}</option>"; 
     479        } 
     480         
     481        $html .= "</select>"; 
     482        $html .= "</label>"; 
     483         
     484        return $html; 
     485    } 
     486     
    397487    function get_default() 
    398488    {         
     
    404494        } 
    405495         
    406         $script = "init_current_pos({$this->_type->location->latitude},{$this->_type->location->longitude});\n"; 
     496        $script = "init_current_pos('{$this->_element_id}',{$this->_type->location->latitude},{$this->_type->location->longitude});\n"; 
    407497        $_MIDCOM->add_jquery_state_script($script); 
    408498