Freedit L1+

Vrstva míst úprav pro nováčky Freedit L1+

  1. // ==UserScript==
  2. // @name Freedit L1+
  3. // @namespace https://greasyfork.org/users/10038-janek250
  4. // @author Janek250 & Martin Kolář & krizecek
  5. // @description Vrstva míst úprav pro nováčky Freedit L1+
  6. // @include https://www.waze.com/editor/*
  7. // @include https://www.waze.com/*/editor/*
  8. // @include https://editor-beta.waze.com/*
  9. // @include https://beta.waze.com/*
  10. // @version 0.6.7.2
  11. // @grant none
  12. // ==/UserScript==
  13. //--------------------------------------------------------------------------------------
  14.  
  15. FE_version = '0.6.7.2';
  16.  
  17. /* definice trvalých proměných */
  18. var FE_data = [];
  19. var FE_dataLoad = false;
  20. var FE_dataCount = 0;
  21. var FE_colors = ['#00BBFF', '#FFAE00', '#FFFF00', '#5E8F47', '#FF0000']; //HTML barvy modrá = #00BBFF oranžová = #FFAE00 žlutá = #FFFF00 zelená = #5E8F47 červená = #FF0000
  22. var FE_date = new Date();
  23. var Fe_me = null;
  24. var FE_baseURLs = [new RegExp("https://www.waze.com/editor/"), new RegExp("https://www.waze.com/[^/]+/editor/"), new RegExp("https://editor-beta.waze.com/")];
  25. var freedit_select_dataWaitForMergeEnd = false;
  26. var freedit_div_perma = null;
  27. var FE_url = '//www.wazer.cz/f/';
  28. // var FE_url = '//freedit.local/';
  29.  
  30. // controllors keys settings
  31. var FE_controllorKey = localStorage.getItem('FE_controllorKey');
  32. if (typeof FE_controllorKey != 'string') {
  33. FE_controllorKey = '';
  34. }
  35. else if (FE_controllorKey == '') {
  36. FE_controllorKey = ''; // pokud jsi dostal klic pro kontrolory, sem ho prosim zadej!
  37. }
  38.  
  39. // controllors keys settings
  40. var FE_controllorKeyEnable = localStorage.getItem('FE_controllorKeyEnable');
  41. if (typeof FE_controllorKeyEnable != 'string') {
  42. FE_controllorKeyEnable = '';
  43. }
  44.  
  45. // online/offline status
  46. var FE_status = localStorage.getItem('FE_status');
  47. if (FE_status === null) { // default status
  48. FE_status = 'on';
  49. }
  50.  
  51. console.log('WME Freedit Status: ' + FE_status);
  52.  
  53. var FE_linksSettings = {
  54. 'add_new': FE_url + 'addFreedit.php?name={name}&link={link}&region={region}&district={district}&added_by={added_by}',
  55. 'register_freedit': FE_url + 'giveMeEdit.php?editor={editor}&freedit={freedit}&state=1',
  56. 'send_freedit_to_control': FE_url + 'giveMeEdit.php?editor={editor}&freedit={freedit}',
  57. 'send_control_report': FE_url + 'sendControlMessage.php?freedit={freedit}&editor={editor}&key={key}',
  58. 'get_all_data_of_freedit': FE_url + 'getDataById.php?freedit={freedit}'
  59. };
  60.  
  61. // language settings
  62. // var FE_allowLanguage = ['cs', 'en'];
  63. var FE_allowLanguage = ['cs'];
  64. var FE_language = 'cs'; // default language
  65. var FE_translation = [];
  66.  
  67. // cs translation
  68. FE_translation['cs'] = {
  69. 'link': 'https://www.waze.com/cs/editor/?env=row&lon={lon}&lat={lat}&zoom={zoom}',
  70. 'map_layer_state_0': 'Freedit: {id}\nVložil: {added_by}',
  71. 'map_layer_state_1': 'Freedit: {id}\nEdituje: {editor}',
  72. 'map_layer_state_2': 'Freedit: {id}\neditoval: {editor}\n ke kontrole',
  73. 'map_layer_state_3': 'Freedit: {id}\neditoval: {editor}\n HOTOVO, děkujeme',
  74. 'map_layer_state_4': 'Freedit: {id}\neditoval: {editor}\n CHYBA',
  75. 'tab_add_new_freedit': 'Formulář pro zadání nového',
  76. 'tab_freedit_table': 'Tabulka',
  77. 'tab_graphs': 'Grafy',
  78. 'tab_forum': 'Fórum',
  79. 'tab_signpost': 'Rozcestník',
  80. 'tab_status_message_online': 'Status: <a href="#" id="freedit-switch-on-off">{state}</a><br> Načteno: {freedit_count} F',
  81. 'tab_status_message_offline': 'Status: <a href="#" id="freedit-switch-on-off">{state}</a><br> Načteno: {freedit_count} F<br>Data pochází z data: {date}',
  82. 'tab_hot_tips_headline': '<br /><br /><b>K editaci:</b>',
  83. 'tab_hot_tips_link': '<a href="{link}" class="freedit-link" data-freedit-id="{id}">Freedit {id}</a> {attrs}',
  84. 'tab_editing_headline': '<br /><b>Edituji:</b><br />',
  85. 'tab_editing_link': '<a href="{link}" class="freedit-link" data-freedit-id="{id}">Freedit {id}</a></u> {editor}: {attrs}',
  86. 'tab_control_headline': '<br /><b>Ke kontrole:</b><br />',
  87. 'tab_control_link': '<a href="{link}" class="freedit-link" data-freedit-id="{id}">Freedit {id}</a></u> {editor}: {attrs}',
  88. 'tab_mistake_headline': '<br /><b>Přepracovat:</b><br />',
  89. 'tab_mistake_link': '<a href="{link}" class="freedit-link" data-freedit-id="{id}">Freedit {id}</a> {editor}: {attrs}',
  90. 'tab_my_complete_freedit_headline': '<br /><b>Moje hotové freedity:</b><br />',
  91. 'tab_my_complete_freedit_link': '<a href="{link}" class="freedit-link" data-freedit-id="{id}">Freedit {id}</a> {editor}: {attrs}',
  92. 'tab_bottom_legend': '<font size="1">Legenda:<br />G - oprava geometrie<br />K - kreslit nové uličky / parkoviště<br />O - kontrola odbočení / jednosměrek<br />N - kontrola názvu ulic / obce<br />A - Areály</font>',
  93. 'script_version': '<font size="1"><a href="https://www.waze.com/forum/viewtopic.php?f=22&t=136397" target="_blank">Script Freedit L1+ verze {version}</a></font>',
  94. 'add_new_form_error': 'Formulář není kompletní! Vyplň všechny údaje!',
  95. 'add_new_form_success': 'Nový freedit byl úspěšně zadán. Děkujeme!',
  96. 'register_editing_error': 'Formulář není kompletní! Vyplň všechny údaje!',
  97. 'register_editing_success': 'Úspěšně jsi se přihlásil k editování. Můžeš začít!',
  98. 'freedit_to_control_error': 'Formulář není kompletní! Vyplň všechny údaje!',
  99. 'freedit_to_control_success': 'Díky za opravení. V nejbližší době se na tvoje dílo podívá L3+ editor a upozorní tě na případné chyby.',
  100. 'control_message_error': 'Formulář není kompletní! Vyplň všechny údaje!',
  101. 'control_message_success': 'Díky za kontrolu!',
  102. 'msg_center_change_status': 'Změna stavu:',
  103. 'msg_center_change_status_0': '0',
  104. 'msg_center_change_status_1': 'přihlášen k editaci.',
  105. 'msg_center_change_status_2': 'odevzdáno.',
  106. 'msg_center_change_status_3': 'uzavřeno.',
  107. 'msg_center_change_status_4': 'vráceno s chybou.',
  108. // forms
  109. 'modal-window-close': 'Zavřít okno',
  110. 'add-new-form-name': 'Název:',
  111. 'add-new-form-permalink': 'Permalink:',
  112. 'add-new-form-shape': 'Tvar:',
  113. 'add-new-form-shape-1': '1 - Obdelník na ležato (výřez z obrazovky)',
  114. 'add-new-form-shape-2': '2 - Obdelník na stojato',
  115. 'add-new-form-shape-3': '3 - Čtverec',
  116. 'add-new-form-region': 'Kraj:',
  117. 'add-new-form-district': 'Okres:',
  118. 'add-new-form-attr-header': 'Co je potřeba udělat:',
  119. 'add-new-form-shape-g': 'G - oprava geometrie',
  120. 'add-new-form-shape-k': 'K - kreslit nové uličky / parkoviště',
  121. 'add-new-form-shape-o': 'O - kontrola odbočení / jednosměrek',
  122. 'add-new-form-shape-n': 'N - kontrola názvu ulic / obce',
  123. 'add-new-form-shape-a': 'A - areál',
  124. 'add-new-form-added-by': 'Vložil:',
  125. 'add-new-form-button': 'Přidat',
  126.  
  127. 'register-editing-freedit-number': 'Číslo Freeditu:',
  128. 'register-editing-editor': 'Editor:',
  129. 'register-editing-freedit-state': 'Stav:',
  130. 'register-editing-freedit-state-1': '1 - Přihlásit se k editování',
  131. 'register-editing-freedit-state-2': '2 - Mám hotovo prosím zkontrolujte',
  132. 'register-editing-comment': 'Komentář:',
  133. 'register-editing-button': 'Odeslat',
  134.  
  135. 'control-message-freedit-number': 'Číslo Freeditu:',
  136. 'control-message-editor': 'Editor:',
  137. 'control-message-state': 'Stav:',
  138. 'control-message-state-3': '3 - Zkontrolováno, bez výhrad',
  139. 'control-message-state-4': '4 - Nedostatky, nutná oprava',
  140. 'control-message-comment': 'Komentář:',
  141. 'control-message-button': 'Odeslat',
  142.  
  143. 'send_error': 'Při odesílání formuláře došlo k chybě. Zkus to za chvíli znovu…',
  144. };
  145.  
  146. // en translation
  147. FE_translation['en'] = {
  148.  
  149. };
  150.  
  151. //Obdelník na ležato
  152. var FE_shape1x = [0.245760,0.122880,0.061440,0.030720,0.015360,0.007680,0.003840,0.001920,0.000960,0.000480,0.000240];
  153. var FE_shape1y = [0.088064,0.044032,0.022016,0.011008,0.005504,0.002752,0.001376,0.000688,0.000344,0.000172,0.000086];
  154. //Obdelní na stojato
  155. var FE_shape2x = [0.075562,0.037781,0.018890,0.009445,0.004723,0.002361,0.001181,0.000590,0.000295,0.000148,0.000074];
  156. var FE_shape2y = [0.088064,0.044032,0.022016,0.011008,0.005504,0.002752,0.001376,0.000688,0.000344,0.000172,0.000086];
  157. //Čtverec
  158. var FE_shape3x = [0.136272,0.068136,0.034068,0.017034,0.008517,0.004259,0.002129,0.001065,0.000532,0.000266,0.000133];
  159. var FE_shape3y = [0.088064,0.044032,0.022016,0.011008,0.005504,0.002752,0.001376,0.000688,0.000344,0.000172,0.000086];
  160.  
  161. // styles
  162. var FE_styles = '<style type="text/css">'
  163. + '#fe-modal-window-background { position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:99990; }'
  164. + '#fe-modal-window { position:fixed;width:900px;left:50%;margin-left:-450px;height:700px;top:50%;margin-top:-350px;z-index:99992;background:#ffffff;padding:20px; }'
  165. + '.fe-hot-tips {width:100%;height:300px;overflow-y:scroll;}'
  166. + '#FEmsg textarea {height: 140px;}'
  167. + '#FEmsg .header{background-color:#906090;}'
  168. + '#FEmsg .list-unstyled{overflow-y:auto;}'
  169. + '#FEmsg .problem-data{overflow-y:hidden;}'
  170. + '</style>';
  171.  
  172. if (FE_status == 'on') {
  173. console.log('WME Freedit: Start load data');
  174.  
  175. $.get(FE_url + 'getData.php', function(data) {
  176. localStorage.setItem("FE_data", JSON.stringify(data));
  177. localStorage.setItem("FE_data_date", FE_date.toLocaleDateString());
  178. for (var i in data) {
  179. FE_data[data[i].id] = data[i];
  180. }
  181.  
  182. FE_dataCount = FE_data.length;
  183. FE_dataLoad = true;
  184. }, 'json');
  185. }
  186. else {
  187. data = JSON.parse(localStorage.getItem("FE_data"));
  188.  
  189. for (var i in data) {
  190. FE_data[data[i].id] = data[i];
  191. }
  192.  
  193. FE_dataCount = FE_data.length;
  194. FE_dataLoad = true;
  195. }
  196.  
  197. //Ošetření service Greasymonkey
  198. function freedit_bootstrap() {
  199. bGreasemonkeyServiceDefined = false;
  200.  
  201. try {
  202. bGreasemonkeyServiceDefined = (typeof Components.interfaces.gmIGreasemonkeyService == 'object');
  203. }
  204. catch (err) {
  205. /* Ignore */
  206. }
  207.  
  208. if (typeof unsafeWindow == 'undefined' || !bGreasemonkeyServiceDefined) {
  209. unsafeWindow = (function (){
  210. dummyElem = document.createElement('p');
  211. dummyElem.setAttribute ('onclick', 'return window;');
  212. return dummyElem.onclick ();
  213. });
  214. }
  215.  
  216. /* Začátek kódu */
  217. freedit_wait();
  218. }
  219.  
  220. //definování funkce a vzhled polygonu
  221. function AddRaidPolygon(raidLayer, groupPoints, groupColor, groupNumber) {
  222. mro_Map = Waze.map;
  223. mro_OL = OpenLayers;
  224. groupName = 'RaidGroup' + groupNumber;
  225.  
  226. style = { //nastavení vzhledu polygonu
  227. strokeColor: groupColor,
  228. strokeOpacity: .7, //pruhlednost čáry
  229. strokeWidth: 2, //toušťka obvodové čáry
  230. fillColor: groupColor,
  231. fillOpacity: 0.10, //průhlednost výplně
  232. label: groupNumber,
  233. labelOutlineColor: 'black', //linka kolem textu
  234. labelOutlineWidth: 3, //šířka linky
  235. fontSize: 14,
  236. fontColor: groupColor,
  237. fontOpacity: .85,
  238. fontWeight: 'bold'
  239. };
  240.  
  241. attributes = {
  242. name: groupName,
  243. number: groupNumber
  244. };
  245.  
  246. pnt= [];
  247.  
  248. for (i = 0; i < groupPoints.length; i++){
  249. convPoint = new OpenLayers.Geometry.Point(groupPoints[i].lon,groupPoints[i].lat).transform(new OpenLayers.Projection('EPSG:4326'), mro_Map.getProjectionObject());
  250. pnt.push(convPoint);
  251. }
  252.  
  253. ring = new mro_OL.Geometry.LinearRing(pnt);
  254. polygon = new mro_OL.Geometry.Polygon([ring]);
  255. feature = new mro_OL.Feature.Vector(polygon,attributes,style);
  256. raidLayer.addFeatures([feature]);
  257. }
  258.  
  259. //funkce vycuc lon / lat / zoom z permalinku
  260. function getQueryString(link, name) {
  261. pos = link.indexOf( name + '=' ) + name.length + 1;
  262. len = link.substr(pos).indexOf('&');
  263. if (-1 == len) len = link.substr(pos).length;
  264. return link.substr(pos,len);
  265. }
  266.  
  267. //funkce MMR??
  268. function CurrentRaidLocation(raid_mapLayer) {
  269. mro_Map = Waze.map;
  270.  
  271. for(i = 0; i < raid_mapLayer.features.length; i++){
  272. raidMapCenter = mro_Map.getCenter();
  273. raidCenterPoint = new OpenLayers.Geometry.Point(raidMapCenter.lon,raidMapCenter.lat);
  274. raidCenterCheck = raid_mapLayer.features[i].geometry.components[0].containsPoint(raidCenterPoint);
  275.  
  276. if (raidCenterCheck === true) {
  277. raidLocationLabel = 'Editorův ráj - ' + $('.WazeControlLocationInfo').text();
  278.  
  279. setTimeout(function(){
  280. $('.WazeControlLocationInfo').text(raidLocationLabel);
  281. },200);
  282. }
  283. }
  284. }
  285.  
  286. //funkce inicializace MMR??
  287. function InitMapRaidOverlay() {
  288. mro_Map = Waze.map;
  289. mro_OL = OpenLayers;
  290. mro_mapLayers = mro_Map.getLayersBy('uniqueName','Freedit L1+');
  291. raid_mapLayer = new mro_OL.Layer.Vector('Freedit L1+', {
  292. displayInLayerSwitcher: true,
  293. uniqueName: 'Freedit L1+'
  294. });
  295.  
  296. // I18n.translations.en.layers.name['Freedit L1+'] = 'Freedit L1+';
  297. mro_Map.addLayer(raid_mapLayer);
  298.  
  299.  
  300. // // ***
  301. // // Načtení stavu vrstvy zobrazena/skryta
  302. // //
  303.  
  304. // // defaultně je vrstva zapnutá
  305. // var FE_visible = true;
  306.  
  307. // // načte poslední uložený stav zobrazení vrstvy z localstorage
  308. // if (localStorage) {
  309. // var options = JSON.parse(localStorage.getItem("FE_options"));
  310.  
  311. // FE_visible = options[0];
  312. // console.log("WME Freedit: Options loaded.");
  313. // }
  314.  
  315. // // uložení stavu zobrazení vrstvy při exitu WME
  316. // saveOptions = function() {
  317. // if (localStorage) {
  318. // var options = [];
  319.  
  320. // FE_visible = raid_mapLayer.visibility;
  321. // options[0] = FE_visible;
  322.  
  323. // localStorage.setItem("FE_options", JSON.stringify(options));
  324. // console.log("WME Freedit: Options saved.");
  325. // }
  326. // }
  327.  
  328. // window.addEventListener("beforeunload", saveOptions, false);
  329.  
  330. // // zobrazení nebo skrytí vrstvy podle posledního uloženého stavu
  331. // raid_mapLayer.setVisibility(true);
  332.  
  333. for (var i in FE_data) {
  334. actualFe = FE_data[i];
  335. if (typeof actualFe == 'object') {
  336. switch(actualFe.shape) {
  337. case 1:
  338. zx = FE_shape1x;
  339. zy = FE_shape1y;
  340. break;
  341. case 2:
  342. zx = FE_shape2x;
  343. zy = FE_shape2y;
  344. break;
  345. default:
  346. zx = FE_shape3x;
  347. zy = FE_shape3y;
  348. }
  349.  
  350. b1x = actualFe.lon - zx[actualFe.zoom];
  351. b1y = actualFe.lat + zy[actualFe.zoom];
  352. b2x = actualFe.lon + zx[actualFe.zoom];
  353. b3y = actualFe.lat - zy[actualFe.zoom];
  354.  
  355. FE_shapeOptions = [{lon:b1x,lat:b1y},{lon:b2x,lat:b1y},{lon:b2x,lat:b3y},{lon:b1x,lat:b3y}];
  356. FE_info = '';
  357. optionsTranslation = {};
  358.  
  359. switch(actualFe.state) {
  360. case 0:
  361. FE_info = fe_t('map_layer_state_0', {'id': actualFe.id, 'added_by': actualFe.added_by});
  362. break;
  363. case 1:
  364. FE_info = fe_t('map_layer_state_1', {'id': actualFe.id, 'editor': actualFe.editor});
  365. break;
  366. case 2:
  367. FE_info = fe_t('map_layer_state_2', {'id': actualFe.id, 'editor': actualFe.editor});
  368. break;
  369. case 3:
  370. FE_info = fe_t('map_layer_state_3', {'id': actualFe.id, 'editor': actualFe.editor});
  371. break;
  372. case 4:
  373. FE_info = fe_t('map_layer_state_4', {'id': actualFe.id, 'editor': actualFe.editor});
  374. break;
  375. }
  376.  
  377. AddRaidPolygon(raid_mapLayer, FE_shapeOptions, FE_colors[actualFe.state], FE_info);
  378. }
  379. }
  380.  
  381. setTimeout(function(){CurrentRaidLocation(raid_mapLayer);},3000);
  382. mro_Map.events.register('moveend', Waze.map, function(){CurrentRaidLocation(raid_mapLayer);});
  383. mro_Map.events.register('zoomend', Waze.map, function(){CurrentRaidLocation(raid_mapLayer);});
  384. }
  385.  
  386. //fce k záložce
  387. function getElementsByClassName(classname, node) {
  388. if (!node) {
  389. node = document.getElementsByTagName('body')[0];
  390. }
  391.  
  392. a = [];
  393. re = new RegExp('\\b' + classname + '\\b');
  394. els = node.getElementsByTagName('*');
  395.  
  396. for (i = 0, j = els.length; i<j; i++) {
  397. if (re.test(els[i].className)) {
  398. a.push(els[i]);
  399. }
  400. }
  401.  
  402. return a;
  403. }
  404.  
  405. //fce obsah záložky
  406. function getId(node) {
  407. return document.getElementById(node);
  408. }
  409.  
  410. function getActualGpsLon() {
  411. return getQueryString($('.WazeControlPermalink a').attr('href'), 'lon');
  412. }
  413.  
  414. function getActualGpsLat() {
  415. return getQueryString($('.WazeControlPermalink a').attr('href'), 'lat');
  416. }
  417.  
  418. function getActualZoom() {
  419. return parseInt(getQueryString($('.WazeControlPermalink a').attr('href'), 'zoom'));
  420. }
  421.  
  422. function returnWazeLink(lon, lat, zoom) {
  423. return fe_t('link', {'lon': lon, 'lat': lat, 'zoom': zoom});
  424. }
  425.  
  426. function prepareLinkForSend(url) {
  427. do {
  428. url = url.replace('&', '%26');
  429. } while (url.indexOf('&') !== -1);
  430.  
  431. return url;
  432. }
  433.  
  434. function checkCtrlPress() {
  435. if (event.ctrlKey || event.shiftKey || event.metaKey || (event.button && event.button == 1)) {
  436. return true;
  437. }
  438.  
  439. return false;
  440. }
  441.  
  442. function getUrlParameter(param, url) {
  443. sPageURL = url.substring(1);
  444. sURLVariables = sPageURL.split('&');
  445.  
  446. for (i = 0; i < sURLVariables.length; i++) {
  447. sParameterName = sURLVariables[i].split('=');
  448.  
  449. if (sParameterName[0] == param) {
  450. return sParameterName[1];
  451. }
  452. }
  453. }
  454.  
  455. function fe_t(name, params) { // function for translation
  456. if (typeof params === 'object') {
  457. returnString = FE_translation[FE_language][name];
  458.  
  459. for (var i in params) {
  460. do {
  461. returnString = returnString.replace('{' + i + '}', params[i]);
  462. } while (returnString.indexOf('{' + i + '}') !== -1);
  463. }
  464.  
  465. return returnString;
  466. }
  467. else {
  468. return FE_translation[FE_language][name];
  469. }
  470. }
  471.  
  472. function fe_l(name, params) { // function for links
  473. if (typeof params === 'object') {
  474. returnString = FE_linksSettings[name];
  475.  
  476. for (var i in params) {
  477. do {
  478. returnString = returnString.replace('{' + i + '}', params[i]);
  479. } while (returnString.indexOf('{' + i + '}') !== -1);
  480. }
  481.  
  482. return returnString;
  483. }
  484. else {
  485. return FE_linksSettings[FE_language][name];
  486. }
  487. }
  488.  
  489. function freedit_can_controll() {
  490. console.log(FE_controllorKey, FE_controllorKeyEnable);
  491. if (FE_controllorKey != '' && FE_controllorKeyEnable == '') {
  492. return true;
  493. }
  494.  
  495. return false;
  496. }
  497.  
  498. function freedit_can_control_disable() {
  499. if (FE_controllorKey != '' && FE_controllorKeyEnable == '0') {
  500. return true;
  501. }
  502.  
  503. return false;
  504. }
  505.  
  506. function freedit_make_tab() {
  507. FE_tipsHtml = '';
  508. FE_editingHtml = '';
  509. FE_forControllHtml = '';
  510. FE_mistakesHtml = '';
  511. FE_editlink = [];
  512. FE_onlineContent = '';
  513. FE_myCompleteHtml = '';
  514.  
  515. tCon = ''; // tabContent (obsah zalozky)
  516. tCon += '<div class="fe-tab-header">';
  517.  
  518. if (Fe_me.rank > 1) {
  519. tCon += '<a href="#" id="freedit-add-new">' + fe_t('tab_add_new_freedit') + '</a><br />';
  520. }
  521.  
  522. // + '<a href="https://docs.google.com/spreadsheets/d/1wywD5uYNmejO_t6Gufzu5tBW0SeVAFdr2KVdeSY1mWg/edit#gid=0" target="_blank">' + fe_t('tab_freedit_table') + '</a>'
  523.  
  524. tCon += ' / (' + fe_t('tab_graphs') + ') / '
  525. + '<a href="https://www.waze.com/forum/viewtopic.php?f=274&amp;t=134151#p1065158&quot;" target="_blank">' + fe_t('tab_forum') + '</a> <font size="1">(' + fe_t('tab_signpost') + ')</font><br><br>'
  526. + '<form action="" class="freedit_id_form"><input type="text" name="freedit_id_input" class="freedit_id_input" placeholder="Zadej číslo F…"><input type="submit" name="freedit_id_search" class="freedit_id_search" value="Přejít"></form>';
  527.  
  528. if (FE_status == 'on') {
  529. tCon += '<br /><br />' + fe_t('tab_status_message_online', {'state': 'ONline', 'freedit_count': FE_dataCount});
  530. }
  531. else {
  532. tCon += '<br /><br />' + fe_t('tab_status_message_offline', {'state': 'OFFline', 'freedit_count': FE_dataCount, 'date': localStorage.getItem("FE_data_date")});
  533. }
  534.  
  535. if (freedit_can_controll()) {
  536. tCon += '<br><br><a href="#" class="freedit-turn-off-controlor">Vypnout kontrolu</a>';
  537. }
  538. else if (freedit_can_control_disable()) {
  539. tCon += '<br><br><a href="#" class="freedit-turn-on-controlor">Zapnout kontrolu</a>';
  540. }
  541.  
  542. for (var i in FE_data) {
  543. switch(FE_data[i].state) {
  544. case 0:
  545. if (!freedit_can_controll()) {
  546. FE_tipsHtml += fe_t('tab_hot_tips_link', {'link': returnWazeLink(FE_data[i].lon, FE_data[i].lat, FE_data[i].zoom), 'id': FE_data[i].id, 'attrs': FE_data[i].attrs, 'user': Fe_me.userName});
  547. FE_tipsHtml += '<br />';
  548. }
  549. break;
  550.  
  551. case 1:
  552. if (FE_data[i].editor == Fe_me.userName) {
  553. FE_editingHtml += fe_t('tab_editing_link', {'link': returnWazeLink(FE_data[i].lon, FE_data[i].lat, FE_data[i].zoom), 'id': FE_data[i].id, 'editor': FE_data[i].editor, 'attrs': FE_data[i].attrs});
  554. FE_editingHtml += '<br />';
  555. }
  556. break;
  557.  
  558. case 2:
  559. if (freedit_can_controll() || FE_data[i].editor == Fe_me.userName) {
  560. FE_forControllHtml += fe_t('tab_control_link', {'link': returnWazeLink(FE_data[i].lon, FE_data[i].lat, FE_data[i].zoom), 'id': FE_data[i].id, 'editor': FE_data[i].editor, 'attrs': FE_data[i].attrs});
  561. FE_forControllHtml += '<br />';
  562. }
  563. break;
  564.  
  565. case 3:
  566. if (FE_data[i].editor == Fe_me.userName) {
  567. FE_myCompleteHtml += fe_t('tab_my_complete_freedit_link', {'link': returnWazeLink(FE_data[i].lon, FE_data[i].lat, FE_data[i].zoom), 'id': FE_data[i].id, 'editor': FE_data[i].editor, 'attrs': FE_data[i].attrs});
  568. FE_myCompleteHtml += '<br />';
  569. }
  570. break;
  571.  
  572. case 4:
  573. FE_mistakesHtml += fe_t('tab_mistake_link', {'link': returnWazeLink(FE_data[i].lon, FE_data[i].lat, FE_data[i].zoom), 'id': FE_data[i].id, 'editor': FE_data[i].editor, 'attrs': FE_data[i].attrs});
  574. FE_mistakesHtml += '<br />';
  575. break;
  576. }
  577. }
  578.  
  579. if (FE_editingHtml != '') { // pokud se prave neco edituje, zobrazime to
  580. FE_onlineContent += fe_t('tab_editing_headline') + FE_editingHtml;
  581. }
  582.  
  583. if (FE_forControllHtml != '') { // pokud je neco ke kontrole, zobrazime to
  584. FE_onlineContent += fe_t('tab_control_headline') + FE_forControllHtml;
  585. }
  586.  
  587. if (FE_mistakesHtml != '') { // pokud jsou nekde nejake chyby, zobrazime to
  588. FE_onlineContent += fe_t('tab_mistake_headline') + FE_mistakesHtml;
  589. }
  590.  
  591. if (FE_tipsHtml != '') { // pokud jsou nejake horke tipy, zobrazime
  592. FE_onlineContent += fe_t('tab_hot_tips_headline') + '<div class="fe-hot-tips">' + FE_tipsHtml + '</div>';
  593. }
  594.  
  595. if (FE_myCompleteHtml != '') { // pokud jsem neco dokoncil, tak to zobrazime
  596. FE_onlineContent += fe_t('tab_my_complete_freedit_headline') + FE_myCompleteHtml;
  597. }
  598.  
  599. tCon += '<br /><br />' + FE_onlineContent + '<br /><br />';
  600.  
  601. tCon += fe_t('tab_bottom_legend') + '<br />' + fe_t('script_version', {'version': FE_version});
  602.  
  603. userTabs = getId('user-info');
  604. navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
  605. tabContent = getElementsByClassName('tab-content', userTabs)[0];
  606.  
  607. newtab = document.createElement('li');
  608. newtab.innerHTML = '<a href="#sidepanel-freedit" data-toggle="tab">Freedit</a>';
  609. navTabs.appendChild(newtab);
  610.  
  611. addon = document.createElement('section');
  612. addon.innerHTML = tCon;
  613. addon.id = 'sidepanel-freedit';
  614. addon.className = 'tab-pane';
  615. tabContent.appendChild(addon);
  616.  
  617. $('.freedit_id_form').on('submit', function(event) {
  618. event.preventDefault();
  619.  
  620. freedit_id = parseInt($('.freedit_id_input').val());
  621.  
  622. if (!isNaN(freedit_id) && typeof FE_data[freedit_id] === 'object') {
  623. $('.freedit_id_input').val('');
  624. freedit_jump_to({lon:FE_data[freedit_id].lon, lat:FE_data[freedit_id].lat, zoom:FE_data[freedit_id].zoom, segments:null, nodes:null, venues:null, mapUpdateRequest:null});
  625. freedit_message_center(freedit_id);
  626. }
  627. else {
  628. alert('Freedit nenalezen.');
  629. }
  630. });
  631. }
  632.  
  633. function freedit_message_center(freedit_id) {
  634. var actualFe = FE_data[freedit_id];
  635.  
  636. $.get(fe_l('get_all_data_of_freedit', {'freedit': freedit_id}), function(data) {
  637. // console.log(actualFe, data, data.msgs, data.msgs.length);
  638.  
  639. msgCnt = '<div class="problem-edit severity-low" id="FEmsg">'
  640. + '<div class="header">'
  641. + '<a class="close-panel">×</a>'
  642. + '<div class="type">Freedit ' + freedit_id + '</div>'
  643. + '<div class="reported">' + actualFe.name + ' (' + actualFe.district + ') - ' + actualFe.attrs + '<br />Vložil: ' + actualFe.added_by;
  644.  
  645. if (actualFe.editor != null) {
  646. msgCnt += '<br> Editoval: ' + actualFe.editor;
  647. }
  648.  
  649. msgCnt += '</div>'
  650. + '</div>'
  651. + '<div class="body">'
  652. + '<div class="problem-data">'
  653. + '<div class="conversation section">'
  654. + '<div class="title">Diskuze<span class="comment-count-badge">' + data.msgs.length + '</span></div>'
  655. + '<div class="collapsible content">'
  656. + '<div class="conversation-view">'
  657. + '<div>'
  658. + '<ul class="list-unstyled" style="max-height: ' + ($('#WazeMap').height() - 430) + 'px;">';
  659.  
  660. prevStat = 0;
  661.  
  662. for (var i in data.msgs) {
  663. if (typeof data.msgs[i] === 'object') {
  664. if (data.msgs[i].comment != '' && prevStat != data.msgs[i].state) {
  665. msgCnt += freedit_message_center_comment(false, data.msgs[i].nick, data.msgs[i].date, data.msgs[i].comment);
  666. msgCnt += freedit_message_center_comment(true, data.msgs[i].nick, data.msgs[i].date, fe_t('msg_center_change_status') + ' ' + fe_t('msg_center_change_status_' + data.msgs[i].state));
  667. prevStat = data.msgs[i].state;
  668. }
  669. else if (data.msgs[i].comment == '') {
  670. msgCnt += freedit_message_center_comment(true, data.msgs[i].nick, data.msgs[i].date, fe_t('msg_center_change_status') + ' ' + fe_t('msg_center_change_status_' + data.msgs[i].state));
  671. prevStat = data.msgs[i].state;
  672. }
  673. else {
  674. msgCnt += freedit_message_center_comment(false, data.msgs[i].nick, data.msgs[i].date, data.msgs[i].comment);
  675. }
  676. }
  677. }
  678.  
  679. msgCnt += '</ul>';
  680.  
  681. if (actualFe.editor != null) {
  682. msgCnt += '<div class="clearfix new-comment-form">'
  683. + '<textarea class="form-control new-comment-text" placeholder="Přidat komentář..." required=""></textarea>'
  684. + '<div style="float: left; position: relative; left: 0; margin-top: 6px; display: block;"><a class=" fa fa-link icon-link">+</a></div>'
  685. + '<button class="btn btn-default" type="submit">Poslat</button>'
  686. + '</div>';
  687. }
  688.  
  689. msgCnt += '</div>'
  690. + '</div>'
  691. + '</div>'
  692. + '</div>'
  693. + '<div class="actions">'
  694. + '<div class="section">'
  695. + '<div class="content">';
  696.  
  697. if (actualFe.editor == null) {
  698. msgCnt += '<div class="navigation">'
  699. + '<div class="btn btn-block next" id="freedit-want-edit" data-freedit-id="' + freedit_id + '">Chci začít editovat!</div>'
  700. + '</div>';
  701. }
  702. else if (actualFe.editor == Fe_me.userName && (actualFe.state != 2 || actualFe.state != 3)) {
  703. msgCnt += '<div class="controls-container" data-freedit-href="' + fe_l('send_freedit_to_control', {'editor': Fe_me.userName, 'freedit': freedit_id}) + '">'
  704. + '<input type="radio" name="state" value="solved" id="state-solved"><label for="state-solved">Odevzdat ke kontrole</label>'
  705. + '<input type="radio" name="state" value="' + actualFe.state + '" id="state-not-identified" checked="checked"><label for="state-not-identified">Neměnit stav</label>'
  706. + '</div>';
  707. }
  708. else if (actualFe.editor == Fe_me.userName && actualFe.state >= 2) {
  709. msgCnt += '<div class="controls-container" data-freedit-href="' + fe_l('send_freedit_to_control', {'editor': Fe_me.userName, 'freedit': freedit_id}) + '"></div>';
  710. }
  711. else if (freedit_can_controll() && actualFe.state < 4) {
  712. msgCnt += '<div class="controls-container" data-freedit-href="' + fe_l('send_control_report', {'editor': Fe_me.userName, 'freedit': freedit_id, 'key': FE_controllorKey}) + '">'
  713. + '<input type="radio" name="state" value="4" id="state-open"><label for="state-open">Vrátit s chybou</label>'
  714. + '<input type="radio" name="state" value="3" id="state-solved"><label for="state-solved">Uzavřít freedit jako hotový</label>'
  715. + '<input type="radio" name="state" value="' + actualFe.state + '" id="state-not-identified" checked="checked"><label for="state-not-identified">Neměnit stav</label>'
  716. + '</div>';
  717. }
  718. else if (freedit_can_controll()) {
  719. msgCnt += '<div class="controls-container" data-freedit-href="' + fe_l('send_control_report', {'editor': Fe_me.userName, 'freedit': freedit_id}) + '"></div>';
  720. }
  721. else {
  722. msgCnt += '<div class="controls-container" data-freedit-href="' + fe_l('send_freedit_to_control', {'editor': Fe_me.userName, 'freedit': freedit_id, 'key': FE_controllorKey}) + '"></div>';
  723. }
  724.  
  725. msgCnt += '<input type="hidden" name="actualState" value="' + data.acutalState + '" />'
  726. + '</div>'
  727. + '</div>'
  728. + '</div>'
  729. + '</div>'
  730. + '</div>'
  731. + '</div>';
  732.  
  733. freedit_message_center_remove();
  734. panelContainer = getId('panel-container');
  735. msgCenter = document.createElement('div');
  736. msgCenter.innerHTML = msgCnt;
  737. msgCenter.className = 'panel';
  738. panelContainer.appendChild(msgCenter);
  739.  
  740. $('#FEmsg .close-panel').on('click', function(event) {
  741. event.preventDefault();
  742. freedit_message_center_remove();
  743. });
  744.  
  745. $('#freedit-want-edit').on('click', function(event) {
  746. event.preventDefault();
  747.  
  748. $.get(fe_l('register_freedit', {'state': 1, 'editor': Fe_me.userName, 'freedit': freedit_id}), {}, function(data) {
  749. if (data.error == 0) {
  750. if (typeof data.msg !== 'undefined') {
  751. alert(data.msg);
  752. }
  753.  
  754. if (typeof data.state !== 'undefined') {
  755. FE_data[freedit_id].state = data.state;
  756. }
  757.  
  758. FE_data[freedit_id].editor = Fe_me.userName;
  759. freedit_message_center(freedit_id);
  760. }
  761. else {
  762. alert(data.msg);
  763. }
  764. }, 'json');
  765. });
  766.  
  767. $('#FEmsg button').on('click', function(event) {
  768. event.preventDefault();
  769.  
  770. $.get($('#FEmsg .controls-container').attr('data-freedit-href'), {actualState: $('#FEmsg input[name=actualState]').val(), state: $('input[name=state]:checked').val(), comment: $('#FEmsg textarea').val()}, function(data) {
  771. if (data.error == 0) {
  772. if (typeof data.msg !== 'undefined') {
  773. alert(data.msg);
  774. }
  775.  
  776. if (typeof data.state !== 'undefined') {
  777. FE_data[freedit_id].state = data.state;
  778. }
  779.  
  780. freedit_message_center(freedit_id);
  781. }
  782. else {
  783. alert(data.msg);
  784. }
  785. }, 'json');
  786. });
  787.  
  788. $('#FEmsg .icon-link').on('click', function(event) {
  789. event.preventDefault();
  790.  
  791. var inputmessage = $('#FEmsg textarea');
  792. var curPermalink = null;
  793. for (var i = 0;i < freedit_div_perma.children.length;i++) {
  794. if (freedit_div_perma.children[i].className == "icon-link" || freedit_div_perma.children[i].className == "fa fa-link") {
  795. curPermalink = freedit_div_perma.children[i].href;
  796. break;
  797. }
  798. }
  799. inputmessage.val(inputmessage.val() + ' ' + curPermalink);
  800. window.setTimeout(freedit_set_focus_on_inputs_message, 100);
  801. });
  802.  
  803. $('#FEmsg .fe-msg-permalink').on('click', function(event) {
  804. linkData = $(this);
  805. event.preventDefault();
  806.  
  807. lon = parseFloat(linkData.attr('data-link-lon'));
  808. lat = parseFloat(linkData.attr('data-link-lat'));
  809. zoom = parseInt(linkData.attr('data-link-zoom'));
  810. segments = linkData.attr('data-link-segments') == 'null' ? null : linkData.attr('data-link-segments').split(",");
  811. nodes = linkData.attr('data-link-nodes') == 'null' ? null : linkData.attr('data-link-nodes').split(",");
  812.  
  813. freedit_jump_to({lon:lon, lat:lat, zoom:zoom, segments:segments, nodes:nodes, venues:null, mapUpdateRequest:null});
  814. });
  815. }, 'json');
  816. }
  817.  
  818.  
  819. function freedit_set_focus_on_inputs_message() {
  820. $('#FEmsg textarea').focus();
  821. }
  822.  
  823. function freedit_message_center_comment(statusChange, nick, date, comment) {
  824. htmlComment = '<li class="comment">'
  825. + '<div class="comment-content' + (statusChange ? ' reporter' : '') + ' ">'
  826. + '<div class="comment-title">'
  827. + '<span class="username">' + nick + '</span> '
  828. + '<span class="date">' + date + '</span>'
  829. + '</div>'
  830. + '<div class="text">' + freedit_return_msg_with_permalink(comment) + '</div>'
  831. + '</div>'
  832. + '</li>';
  833.  
  834. return htmlComment;
  835. }
  836.  
  837. function freedit_message_center_remove() {
  838. $('#panel-container').empty();
  839. }
  840.  
  841. function freedit_make_modal_window(content) {
  842. $('<div id="fe-modal-window-background" />').appendTo('body');
  843. $('<div id="fe-modal-window" />').appendTo('body');
  844. $('#fe-modal-window').html(content);
  845.  
  846. $('.fe-close-modal-window').on('click', function(event) {
  847. event.preventDefault();
  848. freedit_close_modal_window();
  849. });
  850. }
  851.  
  852. function freedit_close_modal_window() {
  853. $('#fe-modal-window-background').remove();
  854. $('#fe-modal-window').remove();
  855. }
  856.  
  857. function freedit_add_new() {
  858. actualLon = getActualGpsLon();
  859. actualLat = getActualGpsLat();
  860.  
  861. $.get('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + actualLat + ',' + actualLon, function(data) {
  862. cityEdit = '';
  863. countryEdit = '';
  864. countryEdit2 = ''; // kraj
  865.  
  866. for (var i in data.results[1].address_components) {
  867. if (data.results[1].address_components[i].types[0] == 'locality' && data.results[1].address_components[i].types[1] == 'political') {
  868. cityEdit = data.results[1].address_components[i].long_name;
  869. }
  870. else if (data.results[1].address_components[i].types[0] == 'administrative_area_level_2' && data.results[1].address_components[i].types[1] == 'political') {
  871. countryEdit2 = data.results[1].address_components[i].long_name;
  872. }
  873. else if (data.results[1].address_components[i].types[0] == 'administrative_area_level_1' && data.results[1].address_components[i].types[1] == 'political') {
  874. countryEdit = data.results[1].address_components[i].long_name;
  875. break;
  876. }
  877. }
  878.  
  879. $.get(fe_l('add_new', {'name': cityEdit, 'link': prepareLinkForSend(returnWazeLink(actualLon, actualLat, getActualZoom())), 'region': countryEdit, 'district': countryEdit2, 'added_by': Fe_me.userName}), function(data) {
  880. freedit_make_modal_window(data);
  881. freedit_form_translator();
  882.  
  883. $('#add-new-freedit').on('submit', function(event) {
  884. event.preventDefault();
  885.  
  886. $.post($(this).attr('action'), $(this).serialize(), function(data) {
  887. if (data.error) {
  888. alert(fe_t('add_new_form_error'));
  889. }
  890. else {
  891. alert(fe_t('add_new_form_success'));
  892. freedit_close_modal_window();
  893. }
  894. }, 'json');
  895. });
  896. });
  897. }, 'json');
  898. }
  899.  
  900. function freedit_form_translator() {
  901. $('#fe-modal-window *[data-fe-translate]').each(function() {
  902. $(this).empty().text(fe_t($(this).attr('data-fe-translate')));
  903. });
  904. }
  905.  
  906. function freedit_get_first_permalink(str) {
  907. for (var i = 0;i < FE_baseURLs.length;i++) {
  908. var start = str.search(FE_baseURLs[i]);
  909. if (start == -1) {
  910. continue;
  911. }
  912. var end = start + 1;
  913. while (end < str.length && str.charAt(end) != " " && str.charAt(end) != "\n") {
  914. end++;
  915. }
  916. return {start:start, end:end, permalink:str.substring(start, end)};
  917. }
  918. return null;
  919. }
  920.  
  921. function freedit_get_jump_set_from_permalink(permalink) {
  922. var lon = permalink.match(/lon=([\-]?[0-9]*[.]?[0-9]*)/);
  923. var lat = permalink.match(/lat=([\-]?[0-9]*[.]?[0-9]*)/);
  924. var zoom = permalink.match(/zoom=([0-9]+)/);
  925. var segments = permalink.match(/segments=(([0-9]+[,]?)+)+/);
  926. var nodes = permalink.match(/nodes=(([0-9]+[,]?)+)+/);
  927. var venues = permalink.match(/venues=(([0-9|\.|\-]+[,]?)+)+/);
  928. var mapUpdateRequest = permalink.match(/mapUpdateRequest=([0-9]*)/);
  929. return {lon:lon == null ? null : lon.length == 2 ? parseFloat(lon[1]) : null, lat:lat == null ? null : lat.length == 2 ? parseFloat(lat[1]) : null, zoom:zoom == null ? null : zoom.length == 2 ? parseFloat(zoom[1]) : null, segments:segments ? segments[1].split(",") : null, nodes:nodes ? nodes[1].split(",") : null, venues:venues ? venues[1].split(",") : null, mapUpdateRequest:mapUpdateRequest ? mapUpdateRequest[1].split(",") : null};
  930. }
  931.  
  932. function freedit_return_msg_with_permalink(msg) {
  933. var pos = 0;
  934. var remainigMessage = msg;
  935.  
  936. while (remainigMessage.length > 0) {
  937. var permalink = freedit_get_first_permalink(remainigMessage);
  938. if (permalink) {
  939. var details = freedit_get_jump_set_from_permalink(permalink.permalink);
  940. if (details.lon && details.lat) {
  941. var elements = 0;
  942. var elType = "";
  943. if (details.segments != null) {
  944. elements = details.segments.length;
  945. elType = "segment" + (elements > 1 ? "s" : "");
  946. } else {
  947. if (details.nodes != null) {
  948. elements = details.nodes.length;
  949. elType = "node" + (elements > 1 ? "s" : "");
  950. } else {
  951. if (details.venues != null) {
  952. elements = details.venues.length;
  953. elType = "venue" + (elements > 1 ? "s" : "");
  954. }
  955. }
  956. }
  957.  
  958. linkData = freedit_get_jump_set_from_permalink(permalink.permalink);
  959. msg = msg.replace(permalink.permalink, '<a href="#" class="fe-msg-permalink" data-link-lat="' + linkData.lat + '" data-link-lon="' + linkData.lon + '" data-link-zoom="' + linkData.zoom + '" data-link-segments="' + linkData.segments + '" data-link-nodes="' + linkData.nodes + '" data-link-venues="' + linkData.venues + '" data-link-mapUpdateRequest="' + linkData.mapUpdateRequest + '"><i class="crosshair fa fa-crosshairs icon-screenshot"></i></a>');
  960. remainigMessage = remainigMessage.substring(permalink.end);
  961. continue;
  962. } else {
  963. // Bad permalink: no lon or lat
  964. }
  965. }
  966. remainigMessage = remainigMessage.substring(1);
  967. }
  968. msg = msg.replace(/(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/g, function(match, contents, offset, s) {
  969. return '<a target="_blank" href="' + (match.indexOf("://") != -1 ? match : "http://" + match) + '">' + match + "</a>";
  970. });
  971.  
  972. return msg;
  973. }
  974.  
  975. function freedit_jump_to(jumpSet) {
  976. Waze.selectionManager.unselectAll();
  977. if (typeof ChatJumper !== "undefined") {
  978. if (ChatJumper.isLast) {
  979. } else {
  980. var c = Waze.map.getCenter();
  981. var zoom = Waze.map.getZoom();
  982. ChatJumper.last = [c.lon, c.lat];
  983. ChatJumper.zoom = zoom;
  984. ChatJumper.isLast = true;
  985. ChatJumper.saveLS();
  986. ChatJumper.showButton();
  987. }
  988. }
  989. freedit_select_dataWaitForMergeEnd = false;
  990. if (jumpSet.segments || jumpSet.nodes || jumpSet.venues || jumpSet.mapUpdateRequest) {
  991. currentJumpSet = jumpSet;
  992. Waze.model.events.register("freedit_mergestart", null, freedit_mergestart);
  993. }
  994. var xy = OpenLayers.Layer.SphericalMercator.forwardMercator(jumpSet.lon, jumpSet.lat);
  995. if (jumpSet.zoom) {
  996. Waze.map.setCenter(xy, jumpSet.zoom);
  997. } else {
  998. Waze.map.setCenter(xy);
  999. }
  1000. if (jumpSet.segments || jumpSet.nodes || jumpSet.venues || jumpSet.mapUpdateRequest) {
  1001. window.setTimeout(freedit_get_function_with_args(freedit_select_data, [jumpSet]), 500);
  1002. }
  1003. }
  1004.  
  1005. function freedit_mergestart() {
  1006. try {
  1007. freedit_select_dataWaitForMergeEnd = true;
  1008. Waze.model.events.unregister("freedit_mergestart", null, freedit_mergestart);
  1009. Waze.model.events.register("freedit_mergeend", null, freedit_mergeend);
  1010. } catch (e) {
  1011. console.log("Error:", e);
  1012. }
  1013. }
  1014. function freedit_mergeend() {
  1015. try {
  1016. Waze.model.events.unregister("freedit_mergeend", null, freedit_mergeend);
  1017. freedit_select_dataWaitForMergeEnd = false;
  1018. freedit_select_data(currentJumpSet);
  1019. } catch (e) {
  1020. console.log("Error:", e);
  1021. }
  1022. }
  1023. function freedit_select_data(jumpSet) {
  1024. if (freedit_select_dataWaitForMergeEnd == true) {
  1025. console.log("waiting for data...");
  1026. return;
  1027. }
  1028. Waze.model.events.unregister("freedit_mergestart", null, freedit_mergestart);
  1029. Waze.model.events.unregister("freedit_mergeend", null, freedit_mergeend);
  1030. var success = true;
  1031. var notFound = [];
  1032. var elements = 0;
  1033. if (jumpSet.segments) {
  1034. var segs = [];
  1035. for (var i = 0;i < jumpSet.segments.length;i++) {
  1036. var segId = parseInt(jumpSet.segments[i]);
  1037. if (typeof Waze.model.segments.objects[segId] === "undefined") {
  1038. success = false;
  1039. notFound.push(segId);
  1040. } else {
  1041. segs.push(Waze.model.segments.objects[segId]);
  1042. }
  1043. }
  1044. elements = jumpSet.segments.length;
  1045. Waze.selectionManager.select(segs);
  1046. }
  1047. if (jumpSet.nodes) {
  1048. var nodes = [];
  1049. for (var i = 0;i < jumpSet.nodes.length;i++) {
  1050. var nodeId = parseInt(jumpSet.nodes[i]);
  1051. if (typeof Waze.model.nodes.objects[nodeId] === "undefined") {
  1052. success = false;
  1053. notFound.push(nodeId);
  1054. } else {
  1055. nodes.push(Waze.model.nodes.objects[nodeId]);
  1056. }
  1057. }
  1058. elements = jumpSet.nodes.length;
  1059. Waze.selectionManager.select(nodes);
  1060. }
  1061. if (jumpSet.venues) {
  1062. Waze.map.landmarkLayer.setVisibility(true);
  1063. var venues = [];
  1064. for (var i = 0;i < jumpSet.venues.length;i++) {
  1065. var venueId = jumpSet.venues[i];
  1066. if (typeof Waze.model.venues.objects[venueId] === "undefined") {
  1067. success = false;
  1068. notFound.push(venueId);
  1069. } else {
  1070. venues.push(Waze.model.venues.objects[venueId]);
  1071. }
  1072. }
  1073. elements = jumpSet.venues.length;
  1074. Waze.selectionManager.select(venues);
  1075. }
  1076. if (jumpSet.mapUpdateRequest && jumpSet.mapUpdateRequest.length >= 1 && !jumpSet.segments && !jumpSet.nodes && !jumpSet.venues) {
  1077. var mp = Waze.model.problems.objects[parseInt(jumpSet.mapUpdateRequest[0])];
  1078. var tp = null;
  1079. if (mp == null) {
  1080. tp = Waze.model.turnProblems.objects[parseInt(jumpSet.mapUpdateRequest[0])];
  1081. }
  1082. if (mp != null) {
  1083. problemsControl.selectProblem(mp);
  1084. success = true;
  1085. }
  1086. if (tp != null) {
  1087. problemsControl.selectProblem(tp);
  1088. success = true;
  1089. }
  1090. }
  1091. if (!success) {
  1092. if (jumpSet.hasOwnProperty("attempt") && jumpSet.attempt >= 2) {
  1093. if (confirm("Some elements can't be found.\nSelection: " + Waze.selectionManager.selectedItems.length + "/" + elements + "\nNot found: " + (notFound.length != 0 ? "Elements ids: " + notFound.join(", ") + "\n" : "") + "Try again to select elements?")) {
  1094. window.setTimeout(freedit_get_function_with_args(freedit_select_data, [jumpSet]), 500);
  1095. }
  1096. return;
  1097. }
  1098. if (jumpSet.hasOwnProperty("attempt")) {
  1099. jumpSet.attempt++;
  1100. } else {
  1101. jumpSet.attempt = 0;
  1102. }
  1103. window.setTimeout(freedit_get_function_with_args(freedit_select_data, [jumpSet]), 500);
  1104. } else {
  1105. console.log("Data selected...:", jumpSet);
  1106. }
  1107. }
  1108. function freedit_get_function_with_args(func, args) {
  1109. return function() {
  1110. var json_args = JSON.stringify(args);
  1111. return function() {
  1112. var args = JSON.parse(json_args);
  1113. func.apply(this, args);
  1114. };
  1115. }();
  1116. }
  1117.  
  1118. //fce záložka obsah
  1119. function freedit_init() {
  1120. localStorage.setItem('FE_controllorKey', FE_controllorKey);
  1121. $(FE_styles).appendTo('head');
  1122. freedit_make_tab();
  1123.  
  1124. $('#freedit-add-new').on('click', function(event) {
  1125. event.preventDefault();
  1126. freedit_add_new();
  1127. });
  1128.  
  1129. $('.freedit-register').on('click', function(event) {
  1130. event.preventDefault();
  1131. freedit_register_editing($(this));
  1132. });
  1133.  
  1134. $('.freedit-to-control').on('click', function(event) {
  1135. event.preventDefault();
  1136. freedit_send_to_control($(this));
  1137. });
  1138.  
  1139. $('.freedit-control-message').on('click', function(event) {
  1140. event.preventDefault();
  1141. freedit_control_message($(this));
  1142. });
  1143.  
  1144. $('.freedit-link').on('click', function(event) {
  1145. if (!checkCtrlPress()) { // pokud pri kliknuti nedrzel control
  1146. event.preventDefault();
  1147. event.stopPropagation();
  1148. href = $(this).attr('href');
  1149.  
  1150. freedit_jump_to({lon:parseFloat(getUrlParameter('lon', href)), lat:parseFloat(getUrlParameter('lat', href)), zoom:getUrlParameter('zoom', href), segments:null, nodes:null, venues:null, mapUpdateRequest:null});
  1151. freedit_message_center($(this).attr('data-freedit-id'));
  1152. }
  1153. });
  1154.  
  1155. $('#freedit-switch-on-off').on('click', function(event) {
  1156. event.preventDefault();
  1157. if (FE_status == "on") {
  1158. localStorage.setItem('FE_status', 'off');
  1159. } else {
  1160. localStorage.setItem('FE_status', 'on');
  1161. }
  1162. window.location.reload();
  1163. });
  1164.  
  1165. $('.freedit-turn-off-controlor').on('click', function(event) {
  1166. event.preventDefault();
  1167. localStorage.setItem('FE_controllorKeyEnable', '0');
  1168. alert('Refreshni prohlížeč.');
  1169. });
  1170.  
  1171. $('.freedit-turn-on-controlor').on('click', function(event) {
  1172. event.preventDefault();
  1173. localStorage.setItem('FE_controllorKeyEnable', '');
  1174. alert('Refreshni prohlížeč.');
  1175. });
  1176.  
  1177. var mapFooter = getElementsByClassName("WazeControlPermalink");
  1178. if (mapFooter.length == 0) {
  1179. console.log("error: can't find permalink container");
  1180. } else {
  1181. freedit_div_perma = mapFooter[0];
  1182. }
  1183. }
  1184.  
  1185. //fce wait co volá freedit_init
  1186. function freedit_wait() {
  1187. if (!window.Waze.map || typeof map === 'undefined' || typeof Waze.loginManager.user === 'undefined' || Waze.loginManager.user == null) {
  1188. setTimeout(freedit_wait, 500);
  1189. return ;
  1190. }
  1191.  
  1192. hasStates = Waze.model.hasStates();
  1193. freedit_after_load_data();
  1194. }
  1195.  
  1196. function freedit_after_load_data() {
  1197. if (FE_dataLoad) {
  1198. console.log('WME Freedit: Start showing layer');
  1199.  
  1200. if (FE_allowLanguage.indexOf(I18n.locale) != -1) {
  1201. FE_language = I18n.locale;
  1202. }
  1203.  
  1204. Fe_me = Waze.loginManager.user;
  1205. freedit_init();
  1206. InitMapRaidOverlay();
  1207. }
  1208. else {
  1209. setTimeout(freedit_after_load_data, 500);
  1210. }
  1211. }
  1212.  
  1213. //volání fce a samotný script
  1214. freedit_bootstrap();
  1215.  
  1216. /*--------------------------------------------------------------------------------------
  1217. poznámky pod čarou :D
  1218. */