user-edit.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* GNU FM -- a free network service for sharing your music listening habits
  2. Copyright (C) 2009 Free Software Foundation, Inc
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. function unrecognised ( msg )
  15. {
  16. $('#location_uri')[0].value = '';
  17. $('#location_uri_label').removeClass('ok');
  18. $('#location_uri_label').addClass('no');
  19. $('#location_uri_label').text( msg );
  20. return 0;
  21. }
  22. function UpdateLocationLabel ()
  23. {
  24. if ($('#location_uri')[0].value)
  25. {
  26. $('#location_uri_label').text($('#location_uri')[0].value);
  27. }
  28. }
  29. function LocationCheck ()
  30. {
  31. if ( !$('#location').val() )
  32. {
  33. return unrecognised("You must enter a location.");
  34. }
  35. ajaxLoading(1);
  36. var ajaxSuccess = function (data, status)
  37. {
  38. ajaxLoading(0);
  39. if (! data.geonames[0])
  40. {
  41. return unrecognised("This location was unrecognisable.");
  42. }
  43. var list;
  44. if ($('#chooser_list')[0])
  45. {
  46. $('#chooser_list').empty();
  47. $('#chooser_list').show();
  48. list = $('#chooser_list')[0];
  49. }
  50. else
  51. {
  52. list = document.createElement('UL');
  53. list.id = 'chooser_list';
  54. $('#chooser')[0].appendChild(list);
  55. }
  56. for (var g in data.geonames)
  57. {
  58. var G = data.geonames[g];
  59. var fullName = G.name;
  60. if (G.adminName3) fullName += ", " + G.adminName3;
  61. if (G.adminName2) fullName += ", " + G.adminName2;
  62. if (G.adminName1) fullName += ", " + G.adminName1;
  63. if (G.countryName) fullName += ", " + G.countryName;
  64. var coords = G.lat.toFixed(2) + ';' + G.lng.toFixed(2);
  65. var shortName = G.name;
  66. if (G.countryCode == 'US')
  67. shortName += ", " + G.adminCode1 + ", USA";
  68. else
  69. shortName += ", " + G.countryCode;
  70. var item = document.createElement('LI');
  71. var label1 = document.createElement('B');
  72. label1.appendChild(document.createTextNode(fullName));
  73. item.appendChild(label1);
  74. item.appendChild(document.createTextNode(' '));
  75. var label2 = document.createElement('SMALL');
  76. label2.appendChild(document.createTextNode('['+coords+']'));
  77. item.appendChild(label2);
  78. item.setAttribute('data-geoname', 'http://sws.geonames.org/' + G.geonameId + '/');
  79. item.setAttribute('data-geoname-name', shortName);
  80. item.setAttribute('data-geoname-coords', coords);
  81. item.onclick = function (e) {
  82. if (!e) var e = window.event;
  83. var tg = (window.event) ? e.srcElement : e.target;
  84. var geoname = $(tg).closest('li').attr('data-geoname');
  85. $('#location_uri')[0].value = geoname;
  86. $('#chooser_list').empty();
  87. $('#chooser_list').hide();
  88. UpdateLocationLabel();
  89. $('#location_uri_label').addClass('ok');
  90. $('#location_uri_label').removeClass('no');
  91. }
  92. $(item).hover(function ()
  93. {
  94. $(this).addClass('hover');
  95. },
  96. function ()
  97. {
  98. $(this).removeClass('hover');
  99. }
  100. );
  101. list.appendChild(item);
  102. }
  103. };
  104. var ajaxError = function (XMLHttpRequest, textStatus, errorThrown)
  105. {
  106. ajaxLoading(0);
  107. return unrecognised("Request error: " + textStatus);
  108. };
  109. $.ajax({
  110. 'type' : 'GET' ,
  111. 'url' : "/utils/location-ws.php" ,
  112. 'data' : { 'q' : $('#location').val() },
  113. 'dataType' : 'json' ,
  114. 'timeout' : 30000 ,
  115. 'success' : ajaxSuccess ,
  116. 'error' : ajaxError
  117. });
  118. }
  119. function ajaxLoading (l)
  120. {
  121. if (l==1)
  122. {
  123. if ($('#loading')[0])
  124. {
  125. $('#loading').show();
  126. }
  127. else
  128. {
  129. var loading = document.createElement('IMG');
  130. loading.id = 'loading';
  131. document.body.appendChild(loading);
  132. loading.src = '/i/loading.gif';
  133. loading.style.height = '32px';
  134. loading.style.width = '32px';
  135. loading.style.position = 'absolute';
  136. loading.style.top = '50%';
  137. loading.style.left = '50%';
  138. loading.style.marginTop = '-16px';
  139. loading.style.marginLeft = '-16px';
  140. }
  141. }
  142. else
  143. {
  144. $('#loading').hide();
  145. }
  146. }
  147. function webidLookup ()
  148. {
  149. window.open("/utils/webid-finder-ws/form.php?javascript=id",
  150. "webid-finder",
  151. "status=1,resizable=1,scrollbars=1,width=600,height=500");
  152. }
  153. function laconicaClick ()
  154. {
  155. if ($('#laconica_profile')[0].value == 'http://identi.ca/example')
  156. $('#laconica_profile')[0].value = '';
  157. }
  158. function laconicaChange ()
  159. {
  160. if ($('#laconica_profile')[0].value.match(/^http:\/\/.+\/.+/))
  161. {
  162. $('#journal_rss')[0].value = $('#laconica_profile')[0].value + '/rss';
  163. }
  164. }
  165. UpdateLocationLabel();
  166. if ($('#laconica_profile')[0].value == '')
  167. $('#laconica_profile')[0].value = 'http://identi.ca/example';