Changeset 12269
- Timestamp:
- 09/14/07 10:41:05 (1 year ago)
- Files:
-
- trunk/midcom/midcom.helper.datamanager2/callback/select/countries.php (added)
- trunk/midcom/midcom.helper.datamanager2/static/position/position_widget.css (modified) (2 diffs)
- trunk/midcom/midcom.helper.datamanager2/static/position/refresh_geoclue.png (deleted)
- trunk/midcom/midcom.helper.datamanager2/static/position/refresh_geodata.png (added)
- trunk/midcom/midcom.helper.datamanager2/static/position/widget.js (modified) (8 diffs)
- trunk/midcom/midcom.helper.datamanager2/widget/position.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midcom.helper.datamanager2/static/position/position_widget.css
r12256 r12269 4 4 } 5 5 6 .position_widget_tab_content_place .geo clue_button6 .position_widget_tab_content_place .geodata_btn 7 7 { 8 8 margin-right: 5px; … … 10 10 width: 16px; 11 11 height: 16px; 12 background: url('refresh_geo clue.png');12 background: url('refresh_geodata.png'); 13 13 cursor: pointer; 14 14 } trunk/midcom/midcom.helper.datamanager2/static/position/widget.js
r12259 r12269 1 1 var widgets = []; 2 2 var current_pos = null; 3 var position_marker = null; 3 4 var widgets_mapstrations = []; 4 5 … … 10 11 widgets[w.id] = widget; 11 12 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 }); 17 35 18 36 widgets_mapstrations[widget_id] = mapstration; … … 24 42 current_pos = point; 25 43 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 } 33 50 34 51 indicator.hide(); 35 52 36 geo clue_btn.bind('click', function(e){37 refresh_geo clue();38 geo clue_btn.hide();53 geodata_btn.bind('click', function(e){ 54 refresh_geodata(); 55 geodata_btn.hide(); 39 56 indicator.show(); 40 57 }); 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 { 47 61 var get_params = { 48 service: backend_service 62 service: backend_service, 63 dir: 'reverse', 64 latitude: current_pos.lat, 65 longitude: current_pos.lon 49 66 }; 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 68 68 jQuery.ajax({ 69 69 type: "GET", … … 73 73 error: function(request, type, expobj){ 74 74 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); 78 149 }, 79 150 success: function(data){ … … 85 156 function parse_error(error_string) 86 157 { 158 indicator.hide(); 159 geodata_btn.show(); 160 87 161 status_box.html(error_string); 88 162 } … … 114 188 { 115 189 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); 128 193 129 194 current_pos = new LatLonPoint(location_data['latitude'],location_data['longitude']); … … 140 205 } 141 206 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 }); 143 222 } 144 223 145 224 function get_key_name(key) 146 225 { 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]; 204 234 } 205 235 … … 207 237 } 208 238 209 function init_current_pos( lat,lon)239 function init_current_pos(widget_id,lat,lon) 210 240 { 211 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 // } 212 273 } 213 274 trunk/midcom/midcom.helper.datamanager2/widget/position.php
r12260 r12269 64 64 var $service = null; 65 65 66 var $_countrylist = array(); 67 68 var $_other_xep_keys = array(); 69 66 70 /** 67 71 * The initialization event handler post-processes the maxlength setting. … … 137 141 $_MIDCOM->add_jquery_state_script($script); 138 142 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 139 156 return true; 140 157 } … … 201 218 $html = "\n<div id=\"{$this->_element_id}_tab_content_place\" class=\"position_widget_tab_content_place\"><!-- tab_content_place starts -->\n"; 202 219 203 $html .= "<div class=\"geo clue_button\" id='{$this->_element_id}_geoclue_button'></div>";220 $html .= "<div class=\"geodata_btn\" id='{$this->_element_id}_geodata_btn'></div>"; 204 221 $html .= "<div class=\"indicator\" id='{$this->_element_id}_indicator' style=\"display: none;\"></div>"; 205 222 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); 215 235 216 236 $city_name = ''; … … 235 255 $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}\" />"; 236 256 $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 238 269 $html .= "<div id=\"{$this->_element_id}_status_box\" class=\"status_box\"></div>"; 239 270 … … 311 342 312 343 $orp_map = new org_routamc_positioning_map("{$this->_element_id}_map"); 313 //$orp_map->add_object($this->_type->storage);314 344 $html .= $orp_map->show(420,300,false); 315 345 … … 395 425 } 396 426 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 397 487 function get_default() 398 488 { … … 404 494 } 405 495 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"; 407 497 $_MIDCOM->add_jquery_state_script($script); 408 498
