Changeset 12306

Show
Ignore:
Timestamp:
09/16/07 01:10:04 (1 year ago)
Author:
w_i
Message:

Rewrote the position widgets structure.
Started implementing alternative search results...

Files:

Legend:

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

    r12269 r12306  
    44} 
    55 
    6 .position_widget_tab_content_place .geodata_btn 
     6.position_widget_tab_content .geodata_btn 
    77{ 
    88    margin-right: 5px; 
     
    1414} 
    1515 
    16 .position_widget_tab_content_place .indicator 
     16.position_widget_tab_content .indicator 
    1717{ 
    1818    margin-right: 5px; 
     
    2222    background: url('../ajax-loading-small.gif'); 
    2323} 
     24 
     25.position_widget_actions 
     26{ 
     27    margin-bottom: 10px; 
     28} 
     29.position_widget_actions div 
     30{ 
     31    font-weight: bold; 
     32    cursor: pointer; 
     33} 
  • trunk/midcom/midcom.helper.datamanager2/static/position/widget.js

    r12269 r12306  
    1 var widgets = []; 
    2 var current_pos = null; 
    3 var position_marker = null; 
    4 var widgets_mapstrations = []; 
    5  
    6 function init_position_widget(widget_id, mapstration) 
    7 {    
    8     jQuery('#' + widget_id).each(function(i,w){ 
    9         var widget = jQuery(w); 
    10  
    11         widgets[w.id] = widget; 
    12  
    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 = {}; 
     1// var widgets = []; 
     2// var current_pos = []; 
     3// var position_marker = []; 
     4// var alternative_markers = []; 
     5// var alternative_markers_visible = []; 
     6// var widgets_mapstractions = []; 
     7// var widget_options = []; 
     8 
     9jQuery.fn.extend({ 
     10        dm2_position_widget: function(mapstraction, options) { 
     11                options = jQuery.extend(jQuery.midcom_helper_datamanager2_widget_position.defaults, options); 
     12        return this.each(function() { 
     13                    return new jQuery.midcom_helper_datamanager2_widget_position(this, mapstraction, options); 
     14        }); 
     15        }, 
     16        dm2_pw_new_position: function(point) { 
     17                return this.trigger("new_position",[point]); 
     18        }, 
     19        dm2_pw_clear_alternative_markers: function() { 
     20                return this.trigger("clear_alternative_markers",[]); 
     21        }, 
     22        dm2_pw_set_marker: function(label, info) { 
     23                return this.trigger("set_marker",[label, info]); 
     24        }, 
     25        dm2_pw_init_current_pos: function(lat, lon) 
     26        { 
     27            return this.trigger("init_current_pos",[lat, lon]); 
     28        }, 
     29        dm2_pw_position_map_to_current: function() { 
     30                return this.trigger("position_map_to_current",[]); 
     31        } 
     32}); 
     33 
     34jQuery.midcom_helper_datamanager2_widget_position = function(widget_block, mapstraction, options) { 
     35     
     36    var widget = jQuery(widget_block); 
     37    var widget_id = widget.attr('id'); 
     38 
     39    mapstraction.addMapTypeControls(); 
     40    mapstraction.addEventListener('click', new_position); 
     41     
     42    var geodata_btn = jQuery('#' + widget_id + '_geodata_btn', widget); 
     43    var indicator = jQuery('#' + widget_id + '_indicator', widget); 
     44     
     45    var revgeodata_btn = jQuery('#' + widget_id + '_revgeodata_btn', widget); 
     46    var revindicator = jQuery('#' + widget_id + '_revindicator', widget); 
     47     
     48    var actions_cam = jQuery('#' + widget_id + '_position_widget_action_cam', widget); 
     49     
     50    var status_box = jQuery('#' + widget_id + '_status_box', widget); 
     51 
     52    var current_pos_icon_url = MIDCOM_STATIC_URL + '/midcom.helper.datamanager2/position/current_position_marker.png' 
     53    var backend_url = jQuery('input.position_widget_backend_url',widget).attr('value'); 
     54    var backend_service = jQuery('input.position_widget_backend_service',widget).attr('value');         
     55    var input_data = {}; 
     56    var current_pos = null; 
     57    var position_marker = null; 
     58    var alternative_markers = null; 
     59    var alternative_markers_visible = true; 
     60         
     61    widget.bind("new_position", function(event, point){ 
     62        new_position(point); 
     63        }).bind("clear_alternative_markers", function(event, point){ 
     64        clear_alternative_markers(); 
     65    }).bind("set_marker", function(event, label, info){ 
     66        set_marker(label, info); 
     67    }).bind("init_current_pos", function(event, lat, lon){ 
     68        init_current_pos(lat, lon); 
     69    }).bind("position_map_to_current", function(event){ 
     70        position_map_to_current(); 
     71    }); 
     72     
     73    indicator.hide(); 
     74    revindicator.hide(); 
     75     
     76    geodata_btn.bind('click', function(e){ 
     77        refresh_geodata(); 
     78        geodata_btn.hide(); 
     79        indicator.show(); 
     80    }); 
     81    revgeodata_btn.bind('click', function(e){ 
     82        var lat = jQuery('#' + input_data['latitude']['id']).attr('value'); 
     83        var lon = jQuery('#' + input_data['longitude']['id']).attr('value'); 
     84         
     85        new_position(new LatLonPoint(lat,lon)); 
     86         
     87        revgeodata_btn.hide(); 
     88        revindicator.show(); 
     89    }); 
     90 
     91    actions_cam.bind('click', function(e){ 
     92        clear_alternative_markers(); 
     93    }); 
     94         
     95        jQuery('.position_widget_input',widget).each(function(i, o){ 
     96        var jqo = jQuery(o); 
     97        var key = get_key_name(jqo.attr('name')); 
     98        input_data[key] = { 
     99            id: jqo.attr('id'), 
     100            value: jqo.attr('value') 
     101        }; 
     102 
     103        if (input_data[key]['value'] == undefined) 
     104        { 
     105            input_data[key]['value'] = ''; 
     106        } 
     107    }); 
     108     
     109    function disable_tabs() 
     110    { 
     111        widget.disableTab(1); 
     112        widget.disableTab(2); 
     113        widget.disableTab(3); 
     114    } 
     115    function enable_tabs() 
     116    { 
     117        widget.enableTab(1); 
     118        widget.enableTab(2); 
     119        widget.enableTab(3); 
     120    } 
     121     
     122    function new_position(point) 
     123    { 
     124        current_pos = point; 
     125         
     126        jQuery('#' + input_data['latitude']['id']).attr('value', current_pos.lat); 
     127        jQuery('#' + input_data['longitude']['id']).attr('value', current_pos.lon); 
     128         
     129        set_marker('Current position', ''); 
     130        get_reversed_geodata(); 
     131    } 
     132     
     133    function get_reversed_geodata() 
     134    { 
     135        disable_tabs(); 
     136        clear_alternative_markers(); 
     137         
     138        var opts_str = '?'; 
     139        jQuery.each(options, function(key,value){ 
     140            opts_str += 'options[' + key + ']=' + value + '&'; 
     141        }); 
     142         
     143        opts_str = opts_str.substr(0,opts_str.length-1); 
     144         
     145        var get_params = { 
     146            service: backend_service, 
     147            dir: 'reverse', 
     148            latitude: current_pos.lat, 
     149            longitude: current_pos.lon 
     150        }; 
     151         
     152        jQuery.ajax({ 
     153            type: "GET", 
     154            url: backend_url + opts_str, 
     155            data: get_params, 
     156            dataType: "xml", 
     157            error: function(request, type, expobj){ 
     158                parse_error(request.responseText); 
     159            }, 
     160            success: function(data){ 
     161                var parsed = parse_response(data); 
     162                update_widget_inputs(parsed[0]); 
     163                handle_alternatives(parsed); 
     164            } 
     165        }); 
     166         
     167        function parse_error(error_string) 
     168        { 
     169            indicator.hide(); 
     170            revindicator.hide(); 
     171            geodata_btn.show(); 
     172            revgeodata_btn.show(); 
     173            enable_tabs(); 
     174             
     175            status_box.html(error_string); 
     176        } 
     177 
     178        function parse_response(data) 
     179        { 
     180            status_box.html(''); 
     181             
     182            var results = []; 
     183            jQuery('position',data).each(function(idx) {             
     184                var rel_this = jQuery(this); 
     185 
     186                results[idx] = { 
     187                    latitude: rel_this.find("latitude").text(), 
     188                    longitude: rel_this.find("longitude").text(), 
     189                    distance: { 
     190                        meters: rel_this.find("distance").find("meters").text(), 
     191                        bearing: rel_this.find("distance").find("bearing").text() 
     192                    }, 
     193                    city: rel_this.find("city").text(), 
     194                    region: rel_this.find("region").text(), 
     195                    country: rel_this.find("country").text(), 
     196                    alternate_names: rel_this.find("alternate_names").text(), 
     197                    accuracy: rel_this.find("accuracy").text() 
     198                }; 
     199            }); 
     200 
     201                return results; 
     202        } 
     203    } 
     204     
     205    function refresh_geodata() 
     206    { 
     207        disable_tabs(); 
     208        clear_alternative_markers(); 
     209 
     210        var opts_str = '?';             
     211        var opts_len = options.length; 
     212        var i = 1; 
     213        jQuery.each(options, function(key,value){ 
     214            if (i < opts_len) 
     215            { 
     216                opts_str += '&'; 
     217            } 
     218            opts_str += 'options[' + key + ']=' + value; 
     219            i++; 
     220        }); 
     221         
     222        var get_params = { 
     223            service: backend_service, 
     224        }; 
    21225 
    22226        jQuery('.position_widget_input',widget).each(function(i, o){ 
     
    32236                input_data[key]['value'] = ''; 
    33237            } 
    34         }); 
    35  
    36         widgets_mapstrations[widget_id] = mapstration; 
    37         widgets_mapstrations[widget_id].addMapTypeControls(); 
    38         widgets_mapstrations[widget_id].addEventListener('click', new_position); 
    39          
    40         function new_position(point) 
    41         { 
    42             current_pos = point; 
     238            else 
     239            { 
     240                get_params[key] = input_data[key]['value']; 
     241            } 
     242        }); 
     243 
     244        jQuery.ajax({ 
     245            type: "GET", 
     246            url: backend_url + opts_str, 
     247            data: get_params, 
     248            dataType: "xml", 
     249            error: function(request, type, expobj){ 
     250                parse_error(request.responseText); 
     251            }, 
     252            success: function(data){ 
     253                var parsed = parse_response(data); 
     254                update_widget(parsed[0]); 
     255                handle_alternatives(parsed); 
     256            } 
     257        }); 
     258 
     259        function parse_error(error_string) 
     260        { 
     261            indicator.hide(); 
     262            revindicator.hide(); 
     263            geodata_btn.show(); 
     264            revgeodata_btn.show(); 
     265            enable_tabs(); 
    43266             
    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         } 
    50  
     267            status_box.html(error_string); 
     268        } 
     269 
     270        function parse_response(data) 
     271        { 
     272            status_box.html(''); 
     273             
     274            var results = []; 
     275            jQuery('position',data).each(function(idx) {             
     276                var rel_this = jQuery(this); 
     277 
     278                results[idx] = {             
     279                    latitude: rel_this.find("latitude").text(),  
     280                    longitude: rel_this.find("longitude").text(), 
     281                    distance: { 
     282                        meters: rel_this.find("distance").find("meters").text(), 
     283                        bearing: rel_this.find("distance").find("bearing").text() 
     284                    }, 
     285                    accuracy: rel_this.find("accuracy").text(), 
     286                    city: rel_this.find("city").text(), 
     287                    region: rel_this.find("region").text(), 
     288                    country: rel_this.find("country").text(), 
     289                    alternate_names: rel_this.find("alternate_names").text(), 
     290                    postalcode: rel_this.find("postalcode").text() 
     291                }; 
     292            }); 
     293 
     294                return results; 
     295        } 
     296    } 
     297     
     298    function update_widget(location_data) 
     299    { 
     300        update_widget_inputs(location_data); 
     301 
     302        current_pos = new LatLonPoint(location_data['latitude'],location_data['longitude']); 
     303 
     304        var info = location_data['city'] + ", " + location_data['country'] + ", " + location_data['postalcode']; 
     305        var label = 'Current position'; 
     306        if (input_data['description']) 
     307        { 
     308            label = input_data['description']; 
     309        } 
     310        else if (location_data['description']) 
     311        { 
     312            label = location_data['description']; 
     313        } 
     314         
     315        set_marker(label, info); 
     316    } 
     317     
     318    function update_widget_inputs(location_data) 
     319    { 
     320        enable_tabs(); 
    51321        indicator.hide(); 
    52  
    53         geodata_btn.bind('click', function(e){ 
    54             refresh_geodata(); 
    55             geodata_btn.hide(); 
    56             indicator.show(); 
    57         }); 
    58          
    59         function get_reversed_geodata() 
    60         { 
    61             var get_params = { 
    62                 service: backend_service, 
    63                 dir: 'reverse', 
    64                 latitude: current_pos.lat, 
    65                 longitude: current_pos.lon 
    66             }; 
    67              
    68             jQuery.ajax({ 
    69                 type: "GET", 
    70                 url: backend_url, 
    71                 data: get_params, 
    72                 dataType: "xml", 
    73                 error: function(request, type, expobj){ 
    74                     parse_error(request.responseText); 
    75                 }, 
    76                 success: function(data){ 
    77                     var parsed = parse_response(data); 
    78                     update_widget_inputs(parsed); 
     322        revindicator.hide(); 
     323        geodata_btn.show(); 
     324        revgeodata_btn.show(); 
     325                     
     326        jQuery.each(location_data, function(key,value){ 
     327            if (input_data[key]) 
     328            { 
     329                jQuery('#' + input_data[key]['id']).attr('value',value); 
     330            } 
     331        }); 
     332    } 
     333 
     334    function get_key_name(key) 
     335    { 
     336        var re = /widget_([a-z]*)_([a-z]{5,11})_([a-z]*)/; 
     337        var reg = re.exec(key); 
     338         
     339        return reg[3]; 
     340    } 
     341     
     342    function handle_alternatives(items) 
     343    { 
     344        var total = items.length; 
     345        for (var i=1; i<total; i++) 
     346        {                
     347            var point = new LatLonPoint(items[i]['latitude'],items[i]['longitude']); 
     348            var info = items[i]['city'] + ", " + items[i]['country'] + ", " + items[i]['postalcode']; 
     349            set_alternative_marker('Alternative position', info, point); 
     350        } 
     351    } 
     352     
     353    function init_current_pos(lat, lon) 
     354    { 
     355        current_pos = new LatLonPoint(lat,lon); 
     356        set_marker('Current position', ''); 
     357    } 
     358 
     359    function set_marker(label, info) 
     360    { 
     361        if (position_marker != null) 
     362        { 
     363             mapstraction.removeMarker(position_marker); 
     364        } 
     365 
     366        position_marker = new Marker(current_pos); 
     367        position_marker.setIcon(current_pos_icon_url); 
     368         
     369        //position_marker.draggable = true; 
     370        //position_marker.draggable_end_event = function(marker){var p = marker.getPoint(); alert(p.lat);}; 
     371        //position_marker.addEventListener('dragend', function(){alert('drop');}); 
     372        // jQuery.extend(this, function(){ 
     373        //             var point = position_marker.getPoint(); 
     374        //             dm2_pw_new_position(point); 
     375        //         }); 
     376 
     377        if (label != undefined) 
     378        { 
     379            position_marker.setLabel(label);                 
     380        } 
     381 
     382        if (   info != undefined 
     383            && info != '') 
     384        { 
     385            position_marker.setInfoBubble(info); 
     386        } 
     387 
     388        mapstraction.addMarker(position_marker); 
     389 
     390        // if (info != undefined) 
     391        // { 
     392        //     position_marker[widget_id].openBubble(); 
     393        // } 
     394    } 
     395 
     396    function set_alternative_marker(label, info, pos) 
     397    { 
     398        if (! alternative_markers) 
     399        { 
     400            alternative_markers = []; 
     401        } 
     402 
     403        var last_key = alternative_markers.push( new Marker(pos) ); 
     404 
     405        if (label != undefined) 
     406        { 
     407            alternative_markers[last_key-1].setLabel(label);                 
     408        } 
     409 
     410        if (   info != undefined 
     411            && info != '') 
     412        { 
     413            alternative_markers[last_key-1].setInfoBubble(info); 
     414        } 
     415 
     416        mapstraction.addMarker(alternative_markers[last_key-1]); 
     417 
     418        // if (info != undefined) 
     419        // { 
     420        //     alternative_markers[widget_id][last_key-1].openBubble(); 
     421        // } 
     422    } 
     423 
     424    function clear_alternative_markers() 
     425    { 
     426        if (   alternative_markers 
     427            && alternative_markers.length > 0) 
     428        { 
     429            var length = alternative_markers.length; 
     430            for (var i=0; i<length; i++) 
     431            { 
     432                mapstraction.removeMarker(alternative_markers[i]); 
     433            } 
     434        } 
     435    } 
     436 
     437    function toggle_alternative_markers() 
     438    { 
     439        if (! alternative_markers_visible) 
     440        { 
     441            alternative_markers_visible = true; 
     442 
     443            if (   alternative_markers 
     444                && alternative_markers.length > 0) 
     445            { 
     446                var length = alternative_markers.length; 
     447                for (var i=0; i<length; i++) 
     448                { 
     449                    alternative_markers[i].show(); 
    79450                } 
    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) 
     451            } 
     452        } 
     453        else 
     454        { 
     455            alternative_markers_visible = false; 
     456 
     457            if (   alternative_markers 
     458                && alternative_markers.length > 0) 
     459            { 
     460                var length = alternative_markers.length; 
     461                for (var i=0; i<length; i++) 
    126462                { 
    127                     input_data[key]['value'] = ''
     463                    alternative_markers[i].hide()
    128464                } 
    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); 
    149                 }, 
    150                 success: function(data){ 
    151                     var parsed = parse_response(data); 
    152                     update_widget(parsed); 
    153                 } 
    154             }); 
    155  
    156             function parse_error(error_string) 
    157                 { 
    158                 indicator.hide(); 
    159                 geodata_btn.show(); 
    160                  
    161                 status_box.html(error_string); 
    162                 } 
    163  
    164             function parse_response(data) 
    165                 { 
    166                     status_box.html(''); 
    167                      
    168                 var results = []; 
    169                 jQuery('position',data).each(function(idx) {             
    170                     var rel_this = jQuery(this); 
    171  
    172                     results[idx] = {                 
    173                         latitude: rel_this.find("latitude").text(),  
    174                         longitude: rel_this.find("longitude").text(), 
    175                         accuracy: rel_this.find("accuracy").text(), 
    176                         city: rel_this.find("city").text(), 
    177                         region: rel_this.find("region").text(), 
    178                         country: rel_this.find("country").text(), 
    179                         postalcode: rel_this.find("postalcode").text() 
    180                     }; 
    181                 }); 
    182  
    183                 return results[0]; 
    184                 } 
    185         } 
    186  
    187         function update_widget(location_data) 
    188         { 
    189             indicator.hide(); 
    190             geodata_btn.show(); 
    191  
    192             update_widget_inputs(location_data); 
    193  
    194             current_pos = new LatLonPoint(location_data['latitude'],location_data['longitude']); 
    195  
    196             var info = location_data['city'] + ", " + location_data['country'] + ", " + location_data['postalcode']; 
    197             var label = 'Current position'; 
    198             if (input_data['description']) 
    199             { 
    200                 label = input_data['description']; 
    201             } 
    202             else if (location_data['description']) 
    203             { 
    204                 label = location_data['description']; 
    205             } 
    206              
    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             }); 
    222         } 
    223  
    224         function get_key_name(key) 
    225         { 
    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]; 
    234         } 
    235  
    236     }); 
    237 
    238  
    239 function init_current_pos(widget_id,lat,lon) 
    240 
    241     current_pos = new LatLonPoint(lat,lon); 
    242     set_marker('Current position','',widget_id); 
    243 
    244  
    245 function 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     // } 
    273 
    274  
    275 function position_map_to_current(widget_id) 
    276 
    277     //console.log("position_map_to_current widget_id: "+widget_id); 
    278     //console.log("current_pos: "+current_pos); 
    279      
    280     if (current_pos != null) 
    281     { 
    282         widgets_mapstrations[widget_id].resizeTo(400,280); 
    283         widgets_mapstrations[widget_id].setCenterAndZoom(current_pos, 13); 
    284         widgets_mapstrations[widget_id].resizeTo(420,300); 
    285     } 
    286 
     465            } 
     466        } 
     467    } 
     468 
     469    function position_map_to_current() 
     470    { 
     471        if (current_pos != null) 
     472        { 
     473            mapstraction.resizeTo(400,280); 
     474            mapstraction.setCenterAndZoom(current_pos, 13); 
     475            mapstraction.resizeTo(420,300); 
     476        } 
     477    }     
     478     
     479}; 
     480 
     481jQuery.midcom_helper_datamanager2_widget_position.defaults = { 
     482    maxRows: 1, 
     483    radius: 5 
     484}; 
  • trunk/midcom/midcom.helper.datamanager2/widget/position.php

    r12269 r12306  
    5454     */ 
    5555    var $enabled_methods = null; 
     56     
     57    /** 
     58     * The service backend to use for searches. Defaults to geonames 
     59     */ 
     60    var $service = null; 
    5661 
    5762    /** 
     
    5964     */ 
    6065    var $_widget_elements = array(); 
    61  
    62     var $_main_group = array(); 
    63      
    64     var $service = null; 
    65      
    66     var $_countrylist = array(); 
    67      
     66    var $_main_group = array();     
     67    var $_countrylist = array();     
    6868    var $_other_xep_keys = array(); 
     69     
     70    /** 
     71     * Options to pass to the javascript widget. 
     72     * Possible values: 
     73     * - (int) maxRows : Maximum amount of results returned. If this is set greater than 1, 
     74     *   the widget will show alternative results and lets user to choose the best match. 
     75     *   Defaults to: 1 
     76     * - (int) radius : Radius of the area we search for alternatives. (in Kilometers) 
     77     *   Defaults to: 5 
     78     */ 
     79      
     80    var $js_maxRows = null; 
     81    var $js_radius = null; 
     82     
     83    var $js_options = array(); 
     84    var $js_options_str = ''; 
    6985     
    7086    /** 
     
    7591    function _on_initialize() 
    7692    { 
     93        if (version_compare(phpversion(), "5.0.0", "<")) 
     94        { 
     95            debug_push_class(__CLASS__, __FUNCTION__); 
     96            debug_add("The position widget used on field {$this->name} currently requires PHP5.", 
     97                MIDCOM_LOG_ERROR); 
     98            debug_pop(); 
     99        } 
     100         
    77101        if (is_a('midcom_helper_datamanager2_type_position', $this->_type)) 
    78102        { 
     
    81105                MIDCOM_LOG_WARN); 
    82106            debug_pop(); 
    83             //return false; 
     107            return false; 
    84108        } 
    85109         
     
    134158            fxSpeed: 'fast', 
    135159            onShow: function() { 
    136                 position_map_to_current('{$this->_element_id}'); 
     160                //dm2_pw_position_map_to_current('{$this->_element_id}'); 
     161                jQuery('#{$this->_element_id}').dm2_pw_position_map_to_current(); 
    137162            } 
    138163        }"; 
     
    142167         
    143168        $this->_get_country_list(); 
     169        $this->_init_widgets_js_options(); 
    144170         
    145171        $this->_other_xep_keys = array( 
     
    216242    function _add_place_method_elements() 
    217243    { 
    218         $html = "\n<div id=\"{$this->_element_id}_tab_content_place\" class=\"position_widget_tab_content_place\"><!-- tab_content_place starts -->\n";         
     244        $html = "\n<div id=\"{$this->_element_id}_tab_content_place\" class=\"position_widget_tab_content position_widget_tab_content_place\"><!-- tab_content_place starts -->\n";         
    219245         
    220246        $html .= "<div class=\"geodata_btn\" id='{$this->_element_id}_geodata_btn'></div>"; 
     
    246272        $html .= "</label>"; 
    247273         
     274        $html .= "<label for='{$this->_element_id}_input_place_region' id='{$this->_element_id}_input_place_region_label'>"; 
     275        $html .= "<span class=\"field_text\">" . $_MIDCOM->i18n->get_string('region', 'org.routamc.positioning') . "</span>";         
     276        $html .= "<input size=\"40\" class=\"shorttext position_widget_input position_widget_input_place_region\" id=\"{$this->_element_id}_input_place_region\" name=\"{$this->_element_id}_input_place_region\" type=\"text\" value=\"{$this->_type->location->region}\" />"; 
     277        $html .= "</label>"; 
     278         
    248279        $html .= "<label for='{$this->_element_id}_input_place_street' id='{$this->_element_id}_input_place_street_label'>"; 
    249280        $html .= "<span class=\"field_text\">" . $_MIDCOM->i18n->get_string('street', 'org.routamc.positioning') . "</span>";         
     
    278309            $html 
    279310        ); 
    280          
    281         // $this->_widget_elements[] =& HTML_QuickForm::createElement 
    282         // ( 
    283         //     'text', 
    284         //     "{$this->_element_id}_input_place_name", 
    285         //     $_MIDCOM->i18n->get_string('name', 'org.routamc.positioning'), 
    286         //     array 
    287         //     ( 
    288         //         'class'         => 'shorttext position_widget_input_place_name', 
    289         //         'id'            => "{$this->_element_id}_input_place_name", 
    290         //     ) 
    291         // ); 
    292         //  
    293         // $this->_widget_elements[] =& HTML_QuickForm::createElement 
    294         // ( 
    295         //     'text', 
    296         //     "{$this->_element_id}_input_place_country", 
    297         //     $_MIDCOM->i18n->get_string('country', 'org.routamc.positioning'), 
    298         //     array 
    299         //     ( 
    300         //         'class'         => 'shorttext position_widget_input_place_country', 
    301         //         'id'            => "{$this->_element_id}_input_place_country", 
    302         //     ) 
    303         // ); 
    304         //  
    305         // $this->_widget_elements[] =& HTML_QuickForm::createElement 
    306         // ( 
    307         //     'text', 
    308         //     "{$this->_element_id}_input_place_city", 
    309         //     $_MIDCOM->i18n->get_string('city', 'org.routamc.positioning'), 
    310         //     array 
    311         //     ( 
    312         //         'class'         => 'shorttext position_widget_input_place_city', 
    313         //         'id'            => "{$this->_element_id}_input_place_city", 
    314         //     ) 
    315         // ); 
    316         //  
    317         // $this->_widget_elements[] =& HTML_QuickForm::createElement 
    318         // ( 
    319         //     'text', 
    320         //     "{$this->_element_id}_input_place_street", 
    321         //     $_MIDCOM->i18n->get_string('street', 'org.routamc.positioning'), 
    322         //     array 
    323         //     ( 
    324         //         'class'         => 'shorttext position_widget_input_place_street', 
    325         //         'id'            => "{$this->_element_id}_input_place_street", 
    326         //     ) 
    327         // ); 
    328  
    329         // $html = "\n</div><!-- tab_content_place ends -->\n"; 
    330         // $this->_widget_elements[] =& HTML_QuickForm::createElement 
    331         // ( 
    332         //     'static', 
    333         //     "{$this->_element_id}_static_place_end", 
    334         //     '', 
    335         //     $html 
    336         // ); 
    337311    } 
    338312     
    339313    function _add_map_method_elements() 
    340314    { 
    341         $html = "\n<div id=\"{$this->_element_id}_tab_content_map\" class=\"position_widget_tab_content_map\"><!-- tab_content_map starts -->\n";         
    342  
     315        $html = "\n<div id=\"{$this->_element_id}_tab_content_map\" class=\"position_widget_tab_content position_widget_tab_content_map\"><!-- tab_content_map starts -->\n";         
     316         
     317        $html .= "\n<div class=\"position_widget_actions\">\n"; 
     318        $html .= "\n<div id=\"{$this->_element_id}_position_widget_action_cam\">[ Clear alternatives ]</div> \n"; 
     319        $html .= "\n</div>\n"; 
     320         
    343321        $orp_map = new org_routamc_positioning_map("{$this->_element_id}_map"); 
    344322        $html .= $orp_map->show(420,300,false); 
     
    354332        ); 
    355333 
    356         $script = "init_position_widget('{$this->_element_id}', mapstraction_{$this->_element_id}_map);"; 
     334        //$script = "init_position_widget('{$this->_element_id}', mapstraction_{$this->_element_id}_map, {$this->js_options_str});"; 
     335        $script = "jQuery('#{$this->_element_id}').dm2_position_widget(mapstraction_{$this->_element_id}_map, {$this->js_options_str});";         
    357336        $_MIDCOM->add_jquery_state_script($script); 
    358      
    359         // $html = "\n</div><!-- tab_content_map ends -->\n"; 
    360         // $this->_widget_elements[] =& HTML_QuickForm::createElement 
    361         // ( 
    362         //     'static', 
    363         //     "{$this->_element_id}_static_map_end", 
    364         //     '', 
    365         //     $html 
    366         // ); 
    367337    } 
    368338     
    369339    function _add_coordinates_method_elements() 
    370340    { 
    371         $html = "\n<div id=\"{$this->_element_id}_tab_content_coordinates\" class=\"position_widget_tab_content_coordinates\"><!-- tab_content_coordinates starts -->\n";         
     341        $html = "\n<div id=\"{$this->_element_id}_tab_content_coordinates\" class=\"position_widget_tab_content position_widget_tab_content_coordinates\"><!-- tab_content_coordinates starts -->\n";         
     342 
     343        $html .= "<div class=\"geodata_btn\" id='{$this->_element_id}_revgeodata_btn'></div>"; 
     344        $html .= "<div class=\"indicator\" id='{$this->_element_id}_revindicator' style=\"display: none;\"></div>"; 
    372345 
    373346        $html .= "<label for='{$this->_element_id}_input_coordinates_latitude' id='{$this->_element_id}_input_coordinates_latitude_label'>"; 
    374347        $html .= "<span class=\"field_text\">" . $_MIDCOM->i18n->get_string('latitude', 'org.routamc.positioning') . "</span>";         
    375         $html .= "<input size=\"40\" class=\"shorttext position_widget_input position_widget_input_coordinates_latitude\" id=\"{$this->_element_id}_input_coordinates_latitude\" name=\"{$this->_element_id}_input_coordinates_latitude\" type=\"text\" value=\"{$this->_type->location->latitude}\" />"; 
     348        $html .= "<input size=\"20\" class=\"shorttext position_widget_input position_widget_input_coordinates_latitude\" id=\"{$this->_element_id}_input_coordinates_latitude\" name=\"{$this->_element_id}_input_coordinates_latitude\" type=\"text\" value=\"{$this->_type->location->latitude}\" />"; 
    376349        $html .= "</label>"; 
    377350         
    378351        $html .= "<label for='{$this->_element_id}_input_coordinates_longitude' id='{$this->_element_id}_input_coordinates_longitude_label'>"; 
    379352        $html .= "<span class=\"field_text\">" . $_MIDCOM->i18n->get_string('longitude', 'org.routamc.positioning') . "</span>";         
    380         $html .= "<input size=\"40\" class=\"shorttext position_widget_input position_widget_input_coordinates_longitude\" id=\"{$this->_element_id}_input_coordinates_longitude\" name=\"{$this->_element_id}_input_coordinates_longitude\" type=\"text\" value=\"{$this->_type->location->longitude}\" />"; 
     353        $html .= "<input size=\"20\" class=\"shorttext position_widget_input position_widget_input_coordinates_longitude\" id=\"{$this->_element_id}_input_coordinates_longitude\" name=\"{$this->_element_id}_input_coordinates_longitude\" type=\"text\" value=\"{$this->_type->location->longitude}\" />"; 
    381354        $html .= "</label>"; 
    382355         
     
    390363            $html 
    391364        ); 
    392  
    393         // $this->_widget_elements[] =& HTML_QuickForm::createElement 
    394         // ( 
    395         //     'text', 
    396         //     "{$this->_element_id}_input_coordinates_latitude", 
    397         //     $_MIDCOM->i18n->get_string('latitude', 'org.routamc.positioning'), 
    398         //     array 
    399         //     ( 
    400         //         'class'         => 'shorttext position_widget_input_coordinates_latitude', 
    401         //         'id'            => "{$this->_element_id}_input_coordinates_latitude", 
    402         //     ) 
    403         // ); 
    404         //      
    405         // $this->_widget_elements[] =& HTML_QuickForm::createElement 
    406         // ( 
    407     &