app.js 47 KB

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