app.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. var app = angular.module('application', ['ngMaterial', 'adaptive.detection', 'ui.bootstrap.typeahead']).config([
  2. '$locationProvider',
  3. function($locationProvider) {
  4. $locationProvider.html5Mode({
  5. enabled: true,
  6. requireBase: false
  7. });
  8. }
  9. ]);
  10. app.directive('skrollr', function() {
  11. var directiveDefinitionObject = {
  12. link: function() {
  13. skrollr.init();
  14. }
  15. };
  16. return directiveDefinitionObject;
  17. });
  18. app.controller('mainController', function($scope, $detection, $http, $mdSidenav, $timeout, $sce, $mdToast, $location) {
  19. // Debugging mode
  20. $scope.debug = window.location.hostname === 'localhost' || typeof $location.search().debug !== 'undefined';
  21. if ($scope.debug) {
  22. console.log('***** Debugging mode ****');
  23. }
  24. $scope.title = 'Manche Numerique';
  25. $scope.$sce = $sce;
  26. var getGeoCodeInProgress = false,
  27. nbJoursFTTH = 365,
  28. siteName = 'Eligibilité Manche Numérique',
  29. siteUrl = 'http://eligibilite.manchenumerique.fr',
  30. siteEmail = 'ftth@manchenumerique.fr',
  31. siteAddresse = '235, rue Joseph Cugnot Zone Delta, 50000 SAINT LÔ',
  32. siteTel = '02.33.77.83.60',
  33. layer = {},
  34. currentMarker,
  35. cLayer;
  36. // Coordinates around Manche to limit the extent of the queries
  37. var mancheCoordinates = [[49.732307856286, -1.97117692088061], [48.4, -1.75], [48.4, -0.5], [49.732307856286, -1.2]];
  38. // This limit the search area
  39. var searchExtent = {
  40. xmin: _.max(
  41. _.map(mancheCoordinates, function(c) {
  42. return c[1];
  43. })
  44. ),
  45. ymin: _.max(
  46. _.map(mancheCoordinates, function(c) {
  47. return c[0];
  48. })
  49. ),
  50. xmax: _.min(
  51. _.map(mancheCoordinates, function(c) {
  52. return c[1];
  53. })
  54. ),
  55. ymax: _.min(
  56. _.map(mancheCoordinates, function(c) {
  57. return c[0];
  58. })
  59. ),
  60. spatialReference: { wkid: 84 }
  61. };
  62. var suggestURL =
  63. 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest?f=pjson&searchExtent=' +
  64. JSON.stringify(searchExtent);
  65. var maps = {
  66. carte: 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
  67. satellite: 'http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
  68. };
  69. var catTypeVoie = [
  70. {
  71. name: 'Allée',
  72. id: 'allee'
  73. },
  74. {
  75. name: 'Avenue',
  76. id: 'avenue'
  77. },
  78. {
  79. name: 'Boulevard',
  80. id: 'boulevard'
  81. },
  82. {
  83. name: 'Carrefour',
  84. id: 'carrefour'
  85. },
  86. {
  87. name: 'Chemin',
  88. id: 'chemin'
  89. },
  90. {
  91. name: 'Cité',
  92. id: 'cite'
  93. },
  94. {
  95. name: 'Hammeau',
  96. id: 'hammeau'
  97. },
  98. {
  99. name: 'Impasse',
  100. id: 'impasse'
  101. },
  102. {
  103. name: 'Lieu-dit',
  104. id: 'lieu_dit'
  105. },
  106. {
  107. name: 'Lotissement',
  108. id: 'lotissement'
  109. },
  110. {
  111. name: 'Place',
  112. id: 'place'
  113. },
  114. {
  115. name: 'Résidence',
  116. id: 'residence'
  117. },
  118. {
  119. name: 'Route',
  120. id: 'route'
  121. },
  122. {
  123. name: 'Rue',
  124. id: 'rue'
  125. },
  126. {
  127. name: 'Villa',
  128. id: 'villa'
  129. },
  130. {
  131. name: 'Village',
  132. id: 'village'
  133. }
  134. ];
  135. var catVousEtes = [
  136. {
  137. name: 'Locataire de ce logement',
  138. id: 'locataire'
  139. },
  140. {
  141. name: 'Occupant à titre gratuit de ce logement',
  142. id: 'occupant_gratuit'
  143. },
  144. {
  145. name: 'Propriétaire de ce logement',
  146. id: 'proprietaire'
  147. }
  148. ];
  149. var catCeLogementEst = [
  150. {
  151. name: 'Votre résidence principale',
  152. id: 'residence_principale'
  153. },
  154. {
  155. name: 'Votre résidence secondaire',
  156. id: 'residence_secondaire'
  157. }
  158. ];
  159. var catAccord = [
  160. {
  161. name:
  162. 'J’ai l’intention de souscrire à une offre Très Haut Débit et bénéficier du raccordement de mon logement au tarif préférentiel de 50€',
  163. id: 'avec_souscription'
  164. },
  165. {
  166. name: 'Je n’ai pas l’intention de souscrire à une offre Très Haut Débit',
  167. id: 'sans_souscription'
  168. }
  169. ];
  170. $scope.formulaires = {
  171. eligibilite: {
  172. sections: [
  173. {
  174. name: 'Générale',
  175. visible: false,
  176. lines: [
  177. {
  178. ctrls: [
  179. {
  180. name: 'Prénom',
  181. id: 'prenom',
  182. type: 'text',
  183. width: '50%',
  184. require: true,
  185. isValid: function(value) {
  186. return !!value && value.length > 2;
  187. },
  188. msg: 'Prénom invalide'
  189. },
  190. {
  191. name: 'Nom',
  192. id: 'nom',
  193. type: 'text',
  194. width: '50%',
  195. require: true,
  196. isValid: function(value) {
  197. return !!value && value.length > 2;
  198. },
  199. msg: 'Nom invalide'
  200. }
  201. ]
  202. },
  203. {
  204. ctrls: [
  205. {
  206. name: 'Email',
  207. id: 'email',
  208. type: 'text',
  209. width: null,
  210. require: true,
  211. isValid: function(value) {
  212. function validateEmail(email) {
  213. var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  214. return re.test(email);
  215. }
  216. return validateEmail(value);
  217. },
  218. msg: 'Email invalide.'
  219. }
  220. ]
  221. },
  222. {
  223. ctrls: [
  224. {
  225. name: 'Téléphone fixe',
  226. id: 'telephone_fixe',
  227. type: 'text',
  228. width: '50%',
  229. require: false
  230. },
  231. {
  232. name: 'Téléphone portable',
  233. id: 'telephone_portable',
  234. type: 'text',
  235. width: '50%',
  236. require: false
  237. }
  238. ]
  239. }
  240. ]
  241. },
  242. {
  243. name: 'Adresse',
  244. visible: true,
  245. lines: [
  246. {
  247. ctrls: [
  248. {
  249. name: 'Numero',
  250. id: 'numero_voie',
  251. type: 'text',
  252. width: '80px',
  253. require: false
  254. },
  255. {
  256. name: 'Type voie',
  257. id: 'type_voie',
  258. type: 'select',
  259. width: '106px',
  260. require: false,
  261. options: {
  262. categories: catTypeVoie
  263. }
  264. },
  265. {
  266. name: 'Nom voie',
  267. id: 'nom_voie',
  268. type: 'text',
  269. width: '378px',
  270. require: true,
  271. isValid: function(value) {
  272. return !!value;
  273. },
  274. msg: 'Nom de voie invalide.'
  275. }
  276. ]
  277. },
  278. {
  279. ctrls: [
  280. {
  281. name: 'Complément Adresse',
  282. id: 'complement_addresse',
  283. type: 'textarea',
  284. width: null,
  285. require: false
  286. }
  287. ]
  288. },
  289. {
  290. ctrls: [
  291. {
  292. name: 'Bâtiment',
  293. id: 'batiment',
  294. type: 'text',
  295. width: '50%',
  296. require: false
  297. },
  298. {
  299. name: 'Cage escalier',
  300. id: 'cage_escalier',
  301. type: 'text',
  302. width: '50%',
  303. require: false
  304. }
  305. ]
  306. },
  307. {
  308. ctrls: [
  309. {
  310. name: 'Etage / Niveau',
  311. id: 'etage',
  312. type: 'text',
  313. width: '50%',
  314. require: false
  315. },
  316. {
  317. name: 'Numero appartement / porte',
  318. id: 'numero_appartement',
  319. type: 'text',
  320. width: '50%',
  321. require: false
  322. }
  323. ]
  324. },
  325. {
  326. ctrls: [
  327. {
  328. name: 'Code postal',
  329. id: 'code_postal',
  330. type: 'text',
  331. width: '50%',
  332. require: true,
  333. isValid: function(value) {
  334. if (!value || value.length !== 5 || isNaN(parseInt(value, 10))) {
  335. return false;
  336. }
  337. return true;
  338. },
  339. msg: 'Non valide'
  340. },
  341. {
  342. name: 'Ville',
  343. id: 'ville',
  344. type: 'text',
  345. width: '50%',
  346. require: true,
  347. isValid: function(value) {
  348. return !!value && value.length > 2;
  349. },
  350. msg: 'Ville invalide.'
  351. }
  352. ]
  353. }
  354. ]
  355. },
  356. {
  357. name: 'Logement',
  358. visible: true,
  359. lines: [
  360. {
  361. ctrls: [
  362. {
  363. name: 'Vous êtes',
  364. id: 'vous_etes',
  365. type: 'radio',
  366. width: null,
  367. require: true,
  368. other: true,
  369. options: {
  370. categories: catVousEtes,
  371. alertes: {
  372. locataire:
  373. 'Si vous êtes locataire, vous devez impérativement avertir votre propriétaire que vous souhaitez bénéficier du pré-raccordement à la fibre optique.'
  374. }
  375. },
  376. isValid: function(value, other) {
  377. return (!!value && value !== 'autre') || !!other;
  378. },
  379. msg: 'Choix incomplet.'
  380. }
  381. ]
  382. },
  383. {
  384. ctrls: [
  385. {
  386. name: 'Ce logement est',
  387. id: 'ce_logement_est',
  388. type: 'radio',
  389. width: null,
  390. require: true,
  391. other: true,
  392. options: {
  393. categories: catCeLogementEst
  394. },
  395. isValid: function(value, other) {
  396. return (!!value && value !== 'autre') || !!other;
  397. },
  398. msg: 'Choix incomplet.'
  399. }
  400. ]
  401. }
  402. ]
  403. },
  404. {
  405. name: 'Conditions pour le raccordement final d’abonné dans un immeuble individuel',
  406. visible: true,
  407. lines: [
  408. {
  409. text:
  410. 'Manche Numérique propose aux personnes qui le souhaitent, de manifester d’ores et déjà leur intérêt pour bénéficier d’une offre Très Haut Débit et ainsi raccorder leur logement ou local à usage professionnel, au futur réseau de communications électroniques à Très Haut Débit FTTH. Le montant de ce raccordement s’élèvera à <b>50€</b><sup>1</sup> pour les personnes qui souscriront à une offre Très Haut Débit auprès d’un opérateur dans l’année qui suit l’ouverture officielle du réseau à la commercialisation. <br><br>Les personnes qui ne se seront pas inscrites via ce formulaire en ligne ne pourront pas bénéficier du raccordement de leur habitation au tarif préférentiel de 50 €. Le raccordement sera directement pris en charge par le Fournisseur d’Accès Internet, auprès duquel elles souscriront un abonnement, et c’est lui qui fixera le montant appliqué au raccordement. <b><sup>1</sup> Remarque : Ce raccordement s’appuiera sur vos infrastructures existantes, le coût lié à leur remise en état sera à votre charge en supplément des 50 €.',
  411. ctrls: [
  412. {
  413. name: 'Accord',
  414. id: 'accord',
  415. options: {
  416. categories: catAccord
  417. },
  418. type: 'radio',
  419. width: null,
  420. require: true,
  421. other: false,
  422. isValid: function(value) {
  423. return !!value;
  424. },
  425. msg: 'Choix incorrect.',
  426. note:
  427. 'IMPORTANT : le règlement vous sera demandé par le Fournisseur d’Accès Internet auprès duquel vous aurez souscrit un abonnement à la fibre optique.'
  428. }
  429. ]
  430. }
  431. ]
  432. },
  433. {
  434. name: 'Informatique et libertés',
  435. visible: false,
  436. lines: [
  437. {
  438. ctrls: [
  439. {
  440. name: 'Informatique et libertés',
  441. id: 'info_et_libertes',
  442. libelle:
  443. 'La personne responsable du traitement de la présente demande de pré-inscription est le représentant du Syndicat Mixte Manche Numérique, le Président, Monsieur Serge DESLANDES. Les informations portées sur ce formulaire sont obligatoires. Elles font l’objet d’un traitement informatisé destiné au raccordement final de l’usager à la fibre optique (FTTH) ainsi qu’à l’exploitation du réseau optique. Les destinataires des données sont : le Syndicat Mixte Manche Numérique ainsi que l’exploitant du réseau optique. Les données sont conservées pendant une durée de 3 ans à partir de la date de transmission à l’entreprise en charge des travaux de raccordement. Conformément à la loi "informatique et libertés" du 6 janvier 1978 modifiée, vous bénéficiez d’un droit d’accès, de rectification aux informations qui vous concernent, d’opposition au traitement de vos données personnelles. Si vous souhaitez exercer ce droit et obtenir communication des informations vous concernant, veuillez-vous adresser au Syndicat Mixte Manche Numérique ftth@manchenumerique.fr. Dans l’hypothèse où le présent formulaire est incomplet et/ou illisible, la présente demande de raccordement ne sera pas traitée.',
  444. type: 'checkbox',
  445. width: null,
  446. require: true,
  447. isValid: function(value) {
  448. return !!value;
  449. },
  450. msg: 'Vous devez accepter.'
  451. }
  452. ]
  453. }
  454. ]
  455. }
  456. ]
  457. }
  458. };
  459. var addCurrentMarker = function(withReverse) {
  460. if (currentMarker) {
  461. map.removeLayer(currentMarker);
  462. }
  463. currentMarker = L.marker([$scope.geoCode.y, $scope.geoCode.x], { draggable: true, title: 'Votre addresse' }).addTo(
  464. map
  465. );
  466. // currentMarker.on('add', function(event) {
  467. // map.setZoom(18);
  468. // });
  469. currentMarker
  470. .bindPopup(
  471. "L'adresse que vous nous avez fournie est localisée sur la carte. Il se peut que la position réelle de votre logement soit un peu différente. Dans ce cas, merci de déplacer le pointeur sur la carte pour le positionner à l'emplacement de votre logement."
  472. )
  473. .openPopup();
  474. if (withReverse) {
  475. $scope.magicKey = null;
  476. reverseLocation($scope.geoCode, null, function(address) {
  477. $scope.address = address;
  478. });
  479. }
  480. currentMarker.on('dragend', function(event) {
  481. var p = currentMarker.getLatLng();
  482. $scope.magicKey = null;
  483. $scope.geoCode = {
  484. x: p.lng,
  485. y: p.lat
  486. };
  487. reverseLocation($scope.geoCode, null, function(address) {
  488. $scope.address = address;
  489. getResults();
  490. });
  491. });
  492. };
  493. var checkDoublon = function(formValues, callback) {
  494. var query =
  495. 'SELECT * FROM `eligibilite`.`demandes` WHERE 1' +
  496. ' AND `email` = "' +
  497. mysql_real_escape_string(formValues.email) +
  498. '"' +
  499. ' AND `numero_voie` = "' +
  500. (formValues.numero_voie ? formValues.numero_voie : '') +
  501. '"' +
  502. ' AND `type_voie` = "' +
  503. mysql_real_escape_string(formValues.type_voie) +
  504. '"' +
  505. ' AND `nom_voie` = "' +
  506. mysql_real_escape_string(formValues.nom_voie) +
  507. '"' +
  508. ' AND `code_postal` = "' +
  509. formValues.code_postal +
  510. '"';
  511. $.ajax({
  512. method: 'POST',
  513. url: 'ajax/datastores.php',
  514. data: { query: query }
  515. }).done(function(result) {
  516. var doublon = result && result !== 'null' ? result : null;
  517. callback(doublon);
  518. });
  519. };
  520. var computeDateFTTH = function() {
  521. if (!$scope.results.ftth) {
  522. return;
  523. }
  524. $scope.results.ftth.eligible = false;
  525. var momentDate;
  526. // Already deployed
  527. if ($scope.results.ftth.PHASE_TRAV === 'Perimetre deploye FTTH MT') {
  528. $scope.results.ftth.eligible = true;
  529. }
  530. // Si date de début de travaux réelle est renseignée
  531. if ($scope.results.ftth.DATE_DEB_TRAV_REEL) {
  532. // Compute Date
  533. momentDate = moment($scope.results.ftth.DATE_DEB_TRAV_REEL, 'DD/MM/YY');
  534. momentDate.add(nbJoursFTTH, 'days');
  535. $scope.results.ftth.date = momentDate.format('MM/YYYY');
  536. } else if (
  537. ($scope.results.ftth.PHASE_TRAV === 'Tranche 1 Travaux' ||
  538. $scope.results.ftth.PHASE_TRAV === 'Tranche 1 Travaux completude') &&
  539. $scope.results.ftth.DATE_DEB_TRAV_PREV
  540. ) {
  541. // Si date de début de travaux prévisionnelle est renseignée
  542. // Compute Date
  543. momentDate = moment($scope.results.ftth.DATE_ABONNEMENT_PREV, 'DD/MM/YY');
  544. momentDate.add(nbJoursFTTH, 'days');
  545. var semester = '1er';
  546. if (parseInt(momentDate.format('M'), 10) > 5) {
  547. semester = '2nd';
  548. }
  549. $scope.results.ftth.date = semester + ' semestre ' + momentDate.format('YYYY');
  550. }
  551. };
  552. var computeFullAddress = function() {
  553. return $scope.result.eligibilite.complement_addresse;
  554. };
  555. var formatDate = function(value) {
  556. return moment(value, 'DD/MM/YY');
  557. };
  558. var getFullAddress = function(callback) {
  559. if ($scope.magicKey) {
  560. var findURL = 'http://api-adresse.data.gouv.fr/search/?';
  561. var url = findURL + 'q=' + $scope.address;
  562. $.get(url, function(data, status) {
  563. var next = function(record) {
  564. reverseLocation($scope.geoCode, null, function(string, address) {
  565. if (record) {
  566. address.StreetNumber = record.housenumber;
  567. address.Match_addr = $scope.address;
  568. }
  569. callback(null, address);
  570. });
  571. };
  572. if (data && data.features && data.features[0] && data.features[0].properties) {
  573. next(data.features[0].properties);
  574. } else {
  575. next();
  576. }
  577. });
  578. } else {
  579. reverseLocation($scope.geoCode, null, function(string, address) {
  580. callback(null, address);
  581. });
  582. }
  583. };
  584. var getRecordsFor = function(identifier, coordinates) {
  585. var records = [];
  586. _.each($scope.data[identifier], function(record) {
  587. _.some(record._polygons, function(polygon) {
  588. if (isInside(polygon, coordinates)) {
  589. records.push(record);
  590. return true;
  591. }
  592. });
  593. });
  594. return records;
  595. };
  596. var getResults = function() {
  597. $scope.results = {};
  598. $.ajax({
  599. method: 'POST',
  600. url: 'ajax/oracle.php',
  601. data: $scope.geoCode
  602. })
  603. .error(function(err) {
  604. console.error('Oracle issue', err);
  605. })
  606. .done(function(msg) {
  607. onResults(msg);
  608. });
  609. var onResults = function(results) {
  610. try {
  611. $scope.results = JSON.parse(results);
  612. $scope.results.address = $scope.address;
  613. $scope.results.ftth = parseResults($scope.results.ftth);
  614. $scope.results.adsl = parseResults($scope.results.adsl);
  615. $scope.results.mimo = parseResults($scope.results.mimo);
  616. computeDateFTTH();
  617. console.log('results', $scope.results);
  618. } catch (e) {
  619. // Debugging purpose
  620. if (window.location.hostname === 'localhost') {
  621. onResults(
  622. '{"x":-1.1060984089996,"y":49.119046582,"ftth":[{"ID_ZAPM_PARTIELLE":"203AP0","DATE_OUV_SERVICE_REEL":null,"DATE_OUV_SERVICE_PREV":null,"DATE_FIN_TRAV_PREV":"04/05/16","DATE_DEB_ETUDES_PREV":"01/12/14"}],"adsl":[{"ID_FT_ADSL":"656","LEGENDE":"TV sur ADSL","NATURE":"0 - 37"}],"mimo":[{"ID_MIMO_ANTC_COUVERTURE_6KM": "73", "DATE_OUV_SERVICE_REEL": "10/12/15", "DATE_OUV_SERVICE_PREV": "T4 2015"}]}'
  623. );
  624. } else {
  625. console.error(e);
  626. alert('Probleme de connexion à la base de donnée Oracle.');
  627. $scope.hideResultPane();
  628. }
  629. }
  630. $scope.refreshInscriptionInfo();
  631. $scope.$apply();
  632. };
  633. $scope.$evalAsync();
  634. };
  635. var init = function() {
  636. var stlo = [49.1154686, -1.0828136000000086];
  637. var map = L.map('map', { zoomControl: false }).setView(stlo, 9);
  638. map.on('dblclick', function(e) {
  639. var p = e.latlng;
  640. $scope.geoCode = {
  641. x: p.lng,
  642. y: p.lat
  643. };
  644. addCurrentMarker(true);
  645. $scope.showResultPane();
  646. getResults();
  647. });
  648. cLayer = L.tileLayer(maps.satellite, {
  649. attribution: 'Carte fournie par <a href="http://openstreetmap.org">OpenStreetMap</a>',
  650. maxZoom: 18
  651. }).addTo(map);
  652. var styleOpts = {
  653. color: 'red',
  654. fillColor: 'red',
  655. weight: 8
  656. };
  657. $scope.data = {};
  658. $scope.colors = {
  659. ftth: '#8cc474', // green
  660. mimo: '#f9b256', // orange
  661. adsl: '#76a7fa' // blue
  662. };
  663. $http({ method: 'POST', url: 'data/dictionary.json' }).success(function(data) {
  664. $scope.dictionary = data;
  665. });
  666. // Debug: show manche limits on the map
  667. if ($scope.debug) {
  668. L.polygon(mancheCoordinates, { color: 'blue', fillColor: 'blue', weight: 8 }).addTo(map);
  669. }
  670. window.map = map;
  671. $scope.mapType = 'Satellite';
  672. $scope.view = {};
  673. $scope.isShown = {};
  674. if ($location.search().q) {
  675. $scope.address = $location.search().q;
  676. $scope.suggestLocation($location.search().q);
  677. }
  678. };
  679. var isDate = function(value) {
  680. return (
  681. value.toString().length === 8 && value.toString().substr(2, 1) === '/' && value.toString().substr(5, 1) === '/'
  682. );
  683. };
  684. var isInside = function(polygon, point) {
  685. var y = point.x ? point.x : point[0],
  686. x = point.y ? point.y : point[1];
  687. var inside = false;
  688. for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
  689. var xi = polygon[i][0],
  690. yi = polygon[i][1];
  691. var xj = polygon[j][0],
  692. yj = polygon[j][1];
  693. var intersect = yi > y != yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
  694. if (intersect) {
  695. inside = !inside;
  696. }
  697. }
  698. return inside;
  699. };
  700. var mysql_real_escape_string = function(str) {
  701. if (typeof str !== 'string') {
  702. return str;
  703. }
  704. return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function(char) {
  705. switch (char) {
  706. case '\0':
  707. return '\\0';
  708. case '\x08':
  709. return '\\b';
  710. case '\x09':
  711. return '\\t';
  712. case '\x1a':
  713. return '\\z';
  714. case '\n':
  715. return '\\n';
  716. case '\r':
  717. return '\\r';
  718. case '"':
  719. case "'":
  720. case '\\':
  721. case '%':
  722. return '\\' + char;
  723. }
  724. });
  725. };
  726. var parseData = function(identifier, data, style, properties) {
  727. var getPolygonsCoord = function(type, coord) {
  728. var result = [];
  729. if (type === 'Polygon') {
  730. result.push(
  731. _.map(coord[0], function(r) {
  732. return [r[1], r[0]];
  733. })
  734. );
  735. }
  736. if (type === 'MultiPolygon') {
  737. var p = [];
  738. _.each(coord, function(c) {
  739. result.push(
  740. _.map(c[0], function(r) {
  741. return [r[1], r[0]];
  742. })
  743. );
  744. });
  745. }
  746. return result;
  747. };
  748. var records = [];
  749. _.each(data.features, function(r) {
  750. var record = r.properties;
  751. var polygons = getPolygonsCoord(r.geometry.type, r.geometry.coordinates);
  752. record._coordinates = r.geometry.coordinates;
  753. record._type = r.geometry.type;
  754. record._polygons = polygons;
  755. record._style = style;
  756. record._properties = properties;
  757. records.push(record);
  758. });
  759. $scope.data[identifier] = records;
  760. };
  761. var parseResults = function(records) {
  762. if (!records || !records.length) {
  763. return null;
  764. }
  765. if (records.length === 1) {
  766. return records[0];
  767. }
  768. var result = records[0];
  769. return result;
  770. };
  771. var reverseLocation = function(geoCode, address, callback) {
  772. var reverseGeo =
  773. 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=pjson&distance=300';
  774. var url = reverseGeo + '&location=' + (geoCode ? $scope.geoCode.x + ',' + $scope.geoCode.y : address);
  775. $.get(url, function(data, status) {
  776. data = JSON.parse(data);
  777. var adresse = data && data.address && data.address.Match_addr;
  778. if (data && data.address && data.address.Address) {
  779. var i = 0;
  780. var num = '';
  781. while (!isNaN(parseInt(data.address.Address[i], 10))) {
  782. num += data.address.Address[i];
  783. i++;
  784. }
  785. data.address.StreetNumber = num;
  786. data.address.Address = data.address.Address.substr(num.length).trim();
  787. var typeVoie = data.address.Address.substring(0, data.address.Address.indexOf(' ')).toLowerCase();
  788. type = _.find(catTypeVoie, function(c) {
  789. if (c.id === typeVoie || c.name.toLowerCase() === typeVoie) {
  790. return true;
  791. }
  792. });
  793. if (type) {
  794. data.address.StreetType = type.id;
  795. data.address.Address = data.address.Address.substr(typeVoie.length).trim();
  796. }
  797. }
  798. callback(adresse, data.address);
  799. $scope.$evalAsync();
  800. });
  801. };
  802. $scope.changeMap = function(value) {
  803. map.removeLayer(cLayer);
  804. cLayer = L.tileLayer(maps[value], {
  805. attribution:
  806. 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
  807. maxZoom: 18
  808. }).addTo(map);
  809. };
  810. $scope.closeRight = function() {
  811. $mdSidenav('right')
  812. .close()
  813. .then(function() {});
  814. };
  815. $scope.computeLayer = function(identifier) {
  816. var Lpolygons = [];
  817. _.each($scope.data[identifier], function(record) {
  818. _.each(record._polygons, function(polygon) {
  819. Lpolygons.push(L.polygon(polygon, record._style).bindPopup($scope.getHtmlContent(identifier, record)));
  820. });
  821. });
  822. layer[identifier] = L.layerGroup(Lpolygons);
  823. };
  824. $scope.formatDateFTTH = function(date) {
  825. if (!date || date === 'Invalid date') {
  826. return;
  827. }
  828. var result =
  829. '<div class="popup-line"><div class="box-eligibilite-title">Date prévisionnelle abonnement FTTH</div><div style="font-weight: bold;" class="popup-value">' +
  830. date +
  831. '</div></div>';
  832. return $sce.trustAsHtml(result);
  833. };
  834. $scope.formatResults = function(identifier, results) {
  835. return $sce.trustAsHtml($scope.getHtmlContent(identifier, results));
  836. };
  837. $scope.getGeoCode = function(address, magicKey, callback) {
  838. var findURL =
  839. 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?f=pjson&searchExtent=' +
  840. JSON.stringify(searchExtent);
  841. getGeoCodeInProgress = true;
  842. var url = findURL + '&text=' + address + (magicKey ? '&magicKey=' + magicKey : ', Basse-Normandie, France');
  843. $.get(url, function(data, status) {
  844. data = JSON.parse(data);
  845. if (status === 'success' && data.locations[0]) {
  846. if (
  847. data.locations[0].extent.xmax < searchExtent.xmin &&
  848. data.locations[0].extent.xmax > searchExtent.xmax &&
  849. data.locations[0].extent.xmin > searchExtent.xmax &&
  850. data.locations[0].extent.xmin > searchExtent.xmax
  851. ) {
  852. getGeoCodeInProgress = false;
  853. return callback(null, data);
  854. }
  855. getGeoCodeInProgress = false;
  856. callback('No result for ' + address);
  857. } else {
  858. getGeoCodeInProgress = false;
  859. callback(status !== 'success' ? status : 'No result for ' + address);
  860. }
  861. });
  862. };
  863. $scope.getHtmlContent = function(identifier, record) {
  864. // Tooltip content
  865. var tooltip = '';
  866. _.each(record, function(value, property) {
  867. if (
  868. property.charAt(0) === '_' ||
  869. (property === 'date' && identifier === 'ftth') ||
  870. value === null ||
  871. typeof value === 'undefined'
  872. ) {
  873. return;
  874. }
  875. var label = $scope.dictionary[property] || property;
  876. value = $scope.dictionary[value] || value;
  877. var date;
  878. if (property.substring(0, 5) === 'DATE_' && !$scope.dictionary[value] && isDate(value)) {
  879. date = formatDate(value);
  880. }
  881. if (!date || $scope.debug) {
  882. // Do not show dates to user otherwise
  883. tooltip +=
  884. '<div class="popup-line"><div class="popup-label">' +
  885. label +
  886. '</div><div class="popup-value">' +
  887. (date ? date.locale('fr').format('MMMM YYYY') : value) +
  888. '</div><div class="popup-small-date">' +
  889. (date ? date.locale('fr').fromNow() : '') +
  890. '</div></div>';
  891. }
  892. });
  893. if (identifier === 'adsl') {
  894. tooltip =
  895. '<a style="float: right;" href="http://www.ariase.com/fr/eligibilite/test.html" target="_blank">Tester mon éligibilité ADSL avec Ariase.com</a>';
  896. }
  897. return tooltip;
  898. };
  899. $scope.hideLayer = function(identifier) {
  900. map.removeLayer(layer[identifier]);
  901. };
  902. $scope.hideResultPane = function() {
  903. if (!$('#result').height()) {
  904. return;
  905. }
  906. $('#result').animate({ height: 0 }, 1000);
  907. $('#map').animate(
  908. {
  909. height: $('body').height()
  910. },
  911. 1000,
  912. function() {
  913. // Animation complete.
  914. map.invalidateSize();
  915. var centerPoint = $scope.geoCode ? new L.LatLng($scope.geoCode.y, $scope.geoCode.x) : stlo;
  916. map.setView(centerPoint, 14);
  917. }
  918. );
  919. };
  920. $scope.initPopup = function() {
  921. $scope.postForm = null;
  922. getFullAddress(function(err, address) {
  923. if (err) {
  924. console.error(err);
  925. }
  926. $scope.result = { eligibilite: {}, autres: {} };
  927. $scope.result.eligibilite.geo_code = JSON.stringify($scope.geoCode);
  928. $scope.result.eligibilite.code_postal = address.Postal;
  929. $scope.result.eligibilite.complement_addresse = address.Match_addr;
  930. $scope.result.eligibilite.nom_voie = address.Address;
  931. $scope.result.eligibilite.numero_voie = address.StreetNumber;
  932. $scope.result.eligibilite.type_voie = address.StreetType;
  933. $scope.result.eligibilite.ville = address.City;
  934. });
  935. };
  936. $scope.isFormValid = function() {
  937. if (!$scope.result || !$scope.result.eligibilite) {
  938. return;
  939. }
  940. var isValid = true;
  941. _.each($scope.formulaires.eligibilite.sections, function(section) {
  942. _.each(section.lines, function(line) {
  943. _.each(line.ctrls, function(ctrl) {
  944. ctrl.invalid = false;
  945. if (ctrl.require && !ctrl.isValid($scope.result.eligibilite[ctrl.id], $scope.result.autres[ctrl.id])) {
  946. isValid = false;
  947. ctrl.invalid = true;
  948. }
  949. });
  950. });
  951. });
  952. return isValid;
  953. };
  954. $scope.refreshInscriptionInfo = function() {
  955. if (!$scope.results.ftth) {
  956. return false;
  957. }
  958. var dateDeb = moment($scope.results.ftth.DATE_OUV_BUL_PRERACCO, 'DD/MM/YY');
  959. var dateFin = moment($scope.results.ftth.DATE_FERM_BUL_PRERACCO, 'DD/MM/YY');
  960. var now = moment();
  961. var diffDaysDeb = now.diff(dateDeb) / 1000 / 3600 / 24;
  962. var diffDaysFin = now.diff(dateFin) / 1000 / 3600 / 24;
  963. var message = 'Déploiement prévu ultérieurement.';
  964. var isOpen = diffDaysDeb > 0 && (!$scope.results.ftth.DATE_FERM_BUL_PRERACCO || diffDaysFin < 0);
  965. var cas;
  966. if (isOpen) {
  967. message = $scope.results.ftth.DATE_FERM_BUL_PRERACCO
  968. ? 'L’inscription au pré-raccordement se termine le ' + dateFin.format('LLL')
  969. : '';
  970. cas = 3;
  971. } else if ($scope.results.ftth.DATE_OUV_BUL_PRERACCO && diffDaysDeb < 0) {
  972. message = 'L’inscription au pré-raccordement sera possibe à partir du ' + dateDeb.format('LLL');
  973. cas = 2;
  974. } else if (dateFin && diffDaysFin > 0) {
  975. message =
  976. 'L’inscription au pré-raccordement est terminée. Pour souscrire à une offre internet Très Haut Débit, contactez les fournisseurs d’accès présents sur le réseau:';
  977. cas = 4;
  978. } else if ($scope.results.ftth.DATE_DEB_TRAV_PREV) {
  979. var date = moment($scope.results.ftth.DATE_DEB_TRAV_PREV, 'DD/MM/YY').add(12, 'M');
  980. message = ''; // TODO: should be a semester
  981. cas = 5;
  982. } else {
  983. cas = 1;
  984. }
  985. console.log('Cas ' + cas);
  986. $scope.inscription = {
  987. open: isOpen,
  988. message: message,
  989. cas: cas
  990. };
  991. };
  992. $scope.onSubmitAddress = function($item, $model, $label) {
  993. // Get magic key
  994. var item = _.find($scope.suggestions, { text: $item });
  995. if (!item) {
  996. item = $scope.suggestions[0];
  997. $scope.address = item.text;
  998. }
  999. $scope.magicKey = item.magicKey;
  1000. $scope.getGeoCode($scope.address, $scope.magicKey, function(err, data) {
  1001. $scope.geoCode = data && data.locations && data.locations[0] && data.locations[0].feature.geometry;
  1002. if (err) {
  1003. console.error('Geocode error', err);
  1004. }
  1005. var toast = toast || {
  1006. template:
  1007. '<md-toast><i class = " md-error"></i> Oups! Aucun résultat trouvé dans la Manche pour: ' +
  1008. $scope.address +
  1009. '</md-toast>',
  1010. hideDelay: 3000,
  1011. position: 'bottom right'
  1012. };
  1013. if (err || !$scope.geoCode) {
  1014. $scope.hideResultPane();
  1015. $mdToast.show(toast);
  1016. }
  1017. if ($scope.geoCode) {
  1018. addCurrentMarker();
  1019. $scope.showResultPane();
  1020. getResults();
  1021. }
  1022. });
  1023. };
  1024. $scope.postFormEl = function() {
  1025. $scope.postForm = { inProgress: true };
  1026. // Add ID_ZAPM_PARTIELLE
  1027. $scope.result.eligibilite.id_zapm_partielle = $scope.results.ftth.ID_ZAPM_PARTIELLE;
  1028. _.each($scope.result.autres, function(value, key) {
  1029. $scope.result.eligibilite[key] = value;
  1030. });
  1031. $scope.$evalAsync();
  1032. var keys = '';
  1033. var values = '';
  1034. _.each($scope.result.eligibilite, function(value, key) {
  1035. keys += '`' + key + '`, ';
  1036. if (value === 'undefined' || value === undefined) {
  1037. value = '';
  1038. }
  1039. if (key === 'telephone_fixe' || key === 'telephone_portable') {
  1040. value = value
  1041. .replace(/ /g, '')
  1042. .replace(/\./g, '')
  1043. .replace(/-/g, '');
  1044. }
  1045. if (typeof value === 'boolean') {
  1046. values += value + ', ';
  1047. } else {
  1048. values += "'" + mysql_real_escape_string(value) + "', ";
  1049. }
  1050. });
  1051. var dateTime = new Date(
  1052. new Date(new Date(new Date()).toISOString()).getTime() - new Date().getTimezoneOffset() * 60000
  1053. )
  1054. .toISOString()
  1055. .slice(0, 19)
  1056. .replace('T', ' ');
  1057. checkDoublon($scope.result.eligibilite, function(doublon) {
  1058. if (doublon) {
  1059. $scope.postForm = {
  1060. error:
  1061. 'Une demande de pré-raccordement a déjà été effectuée à cette adresse. Pour tout renseignement merci de contacter les services de Manche Numérique au 02.33.77.83.60'
  1062. };
  1063. return $scope.$apply();
  1064. }
  1065. var query =
  1066. 'INSERT INTO `eligibilite`.`demandes` (`date`,' +
  1067. keys.substring(0, keys.length - 2) +
  1068. ") VALUES ('" +
  1069. dateTime +
  1070. "', " +
  1071. values.substring(0, values.length - 2) +
  1072. ');';
  1073. $.ajax({
  1074. method: 'POST',
  1075. url: 'ajax/datastores.php',
  1076. data: { query: query }
  1077. }).done(function(msg) {
  1078. if (!isNaN(msg)) {
  1079. $scope.postForm = { ok: true };
  1080. var numDemande = moment().format('YYYYMMDD') + msg;
  1081. var body =
  1082. '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  1083. body +=
  1084. '<html><body style="font-size: 14px; font-family: calibri;">' +
  1085. 'Bonjour ' +
  1086. $scope.result.eligibilite.prenom +
  1087. ' ' +
  1088. $scope.result.eligibilite.nom +
  1089. ', <br>' +
  1090. 'Nous vous confirmons votre demande de pré-raccordement FTTH. <br><br>' +
  1091. 'Cette demande porte le numéro: ' +
  1092. '<span style="color: #31708f;font-size:17px; font-weight:bold;">' +
  1093. numDemande +
  1094. '</span><br><br>' +
  1095. 'Voici le détail de votre demande:' +
  1096. '<table WIDTH="100%" style="line-height: 40px;" bgColor="#d9edf7" bordercolor="#bce8f1">';
  1097. // Numero demande
  1098. body += '<tr>';
  1099. body +=
  1100. '<th style="width:180px;text-align: left;white-space: nowrap;height: 40px;color: #666;">Numéro demande</th>';
  1101. body += '<td>' + numDemande + '</td>';
  1102. body += '</tr>';
  1103. // Date demande
  1104. body += '<tr>';
  1105. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Date</th>';
  1106. body +=
  1107. '<td>' +
  1108. moment()
  1109. .lang('fr')
  1110. .format('LLLL') +
  1111. '</td>';
  1112. body += '</tr>';
  1113. // Demandeur
  1114. body += '<tr>';
  1115. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Demandeur</th>';
  1116. body += '<td>' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + '</td>';
  1117. body += '</tr>';
  1118. // Email
  1119. body += '<tr>';
  1120. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Email</th>';
  1121. body += '<td>' + $scope.result.eligibilite.email + '</td>';
  1122. body += '</tr>';
  1123. // Adresse
  1124. body += '<tr>';
  1125. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Adresse</th>';
  1126. body += '<td>' + computeFullAddress() + '</td>';
  1127. body += '</tr>';
  1128. // Vous etes
  1129. var cat = _.find(catVousEtes, { id: $scope.result.eligibilite.vous_etes });
  1130. var res = cat && cat.name ? cat.name : $scope.result.eligibilite.vous_etes;
  1131. body += '<tr>';
  1132. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Vous êtes</th>';
  1133. body += '<td>' + res + '</td>';
  1134. body += '</tr>';
  1135. // Ce logement est
  1136. var cat2 = _.find(catCeLogementEst, { id: $scope.result.eligibilite.ce_logement_est });
  1137. var res2 = cat2 && cat2.name ? cat2.name : $scope.result.eligibilite.ce_logement_est;
  1138. body += '<tr>';
  1139. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Ce logement est</th>';
  1140. body += '<td>' + res2 + '</td>';
  1141. body += '</tr>';
  1142. body += '</table><br><br>';
  1143. body +=
  1144. 'Conformément à la loi "informatique et libertés" du 6 janvier 1978 modifiée, vous bénéficiez d’un droit d’accès, de rectification aux informations qui vous concernent, d’opposition au traitement de vos données personnelles. Si vous souhaitez exercer ce droit et obtenir la communication des informations vous concernant, merci de nous contacter :' +
  1145. '<br>' +
  1146. '<table bgcolor="#ddd" bordercolor="#666">' +
  1147. ' <tr>' +
  1148. ' <th style="width:180px;text-align: left;white-space: nowrap;height: 30px;color: #666;">Email</th><td>' +
  1149. siteEmail +
  1150. '</td>' +
  1151. ' </tr><tr>' +
  1152. ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Adresse</th><td>' +
  1153. siteAddresse +
  1154. '</td>' +
  1155. ' </tr><tr>' +
  1156. ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Tel</th><td>' +
  1157. siteTel +
  1158. '</td>' +
  1159. ' </tr>' +
  1160. '</table><br><br>';
  1161. body += 'A bientôt sur: <a href="' + siteUrl + '">' + siteName + '</a></body></html>';
  1162. var mail = {
  1163. to: $scope.result.eligibilite.email,
  1164. sujet: 'Votre demande de pré-raccordement FTTH n° ' + numDemande,
  1165. message: body
  1166. };
  1167. $.ajax({
  1168. method: 'POST',
  1169. url: 'ajax/datastores.php',
  1170. data: {
  1171. siteEmail: siteEmail,
  1172. mail: mail
  1173. }
  1174. }).done(function(msg) {
  1175. console.log('Email sent', msg);
  1176. });
  1177. $scope.result.eligibilite = {};
  1178. $scope.autres = {};
  1179. $scope.address = null;
  1180. $scope.magicKey = null;
  1181. } else {
  1182. $scope.postForm = { error: msg };
  1183. }
  1184. $scope.hideResultPane();
  1185. $scope.$apply();
  1186. });
  1187. });
  1188. };
  1189. $scope.showLayer = function(identifier) {
  1190. map.addLayer(layer[identifier]);
  1191. };
  1192. $scope.showResultPane = function() {
  1193. var bodyHeight = $('body').height();
  1194. var height = Math.max(300, bodyHeight / 3);
  1195. var heightMap = bodyHeight - height;
  1196. $('#result').animate({ height: height + 'px' }, 1000);
  1197. $('#map').animate(
  1198. {
  1199. height: heightMap + 'px'
  1200. },
  1201. 1000,
  1202. function() {
  1203. // Animation complete.
  1204. map.invalidateSize();
  1205. map.setView(new L.LatLng($scope.geoCode.y, $scope.geoCode.x), 18);
  1206. }
  1207. );
  1208. };
  1209. var i = 0,
  1210. j = 0;
  1211. $scope.suggestLocation = function(val) {
  1212. try {
  1213. var coordinates = JSON.parse(val);
  1214. if (coordinates && coordinates.x) {
  1215. $scope.geoCode = coordinates;
  1216. addCurrentMarker();
  1217. }
  1218. return;
  1219. } catch (e) {
  1220. $scope.suggestionsReady = false;
  1221. i++;
  1222. return $http
  1223. .get(suggestURL, {
  1224. params: {
  1225. text: val
  1226. }
  1227. })
  1228. .then(function(response) {
  1229. if (val === $scope.address) {
  1230. // Very important to debounce queries
  1231. $scope.suggestionsReady = response.data.suggestions.length !== 0;
  1232. $scope.suggestions = _.cloneDeep(response.data.suggestions);
  1233. }
  1234. return response.data.suggestions.map(function(item) {
  1235. return item.text;
  1236. });
  1237. });
  1238. }
  1239. };
  1240. $scope.toggleResultPane = function() {
  1241. if ($('#result').height()) {
  1242. return $scope.hideResultPane();
  1243. }
  1244. if ($scope.results && $scope.results.ftth) {
  1245. return $scope.showResultPane();
  1246. }
  1247. };
  1248. $scope.toggleRight = function() {
  1249. $mdSidenav('right')
  1250. .toggle()
  1251. .then(function() {});
  1252. };
  1253. $scope.$watch(
  1254. 'view',
  1255. function(view) {
  1256. if (_.isEmpty(view)) {
  1257. return;
  1258. }
  1259. $('#layer-loading')
  1260. .removeClass('force-hidden')
  1261. .find('.md-inner')
  1262. .show();
  1263. setTimeout(function() {
  1264. _.each(view, function(value, key) {
  1265. if ($scope.isShown[key] !== value) {
  1266. if (value) {
  1267. if (typeof $scope.isShown[key] !== 'undefined') {
  1268. $scope.showLayer(key);
  1269. $('#layer-loading')
  1270. .find('.md-inner')
  1271. .hide();
  1272. } else {
  1273. $timeout(function() {
  1274. $scope.computeLayer(key);
  1275. $scope.showLayer(key);
  1276. $('#layer-loading')
  1277. .find('.md-inner')
  1278. .hide();
  1279. }, 500);
  1280. }
  1281. } else {
  1282. $scope.hideLayer(key);
  1283. setTimeout(function() {
  1284. $('#layer-loading')
  1285. .find('.md-inner')
  1286. .hide();
  1287. }, 1000);
  1288. }
  1289. $scope.isShown[key] = value;
  1290. }
  1291. });
  1292. });
  1293. },
  1294. true
  1295. );
  1296. $(window).resize(function() {
  1297. if (!$('#result').height()) {
  1298. return;
  1299. }
  1300. $scope.showResultPane();
  1301. });
  1302. init();
  1303. });