app.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  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 computeDateFTTH = function() {
  457. if(!$scope.results.ftth) {return;}
  458. // A date already exists
  459. if($scope.results.ftth.DATE_OUV_SERVICE_REEL || $scope.results.ftth.DATE_OUV_SERVICE_PREV) {
  460. $scope.results.ftth.date = $scope.results.ftth.DATE_OUV_SERVICE_REEL || $scope.results.ftth.DATE_OUV_SERVICE_PREV;
  461. return;
  462. }
  463. else if($scope.results.ftth.DATE_FIN_TRAV_PREV) {
  464. // Compute Date
  465. var momentDate = moment($scope.results.ftth.DATE_FIN_TRAV_PREV, 'DD/MM/YY');
  466. momentDate.add(nbJoursFTTH, 'days');
  467. $scope.results.ftth.date = momentDate.format('DD/MM/YYYY');
  468. }
  469. };
  470. var computeFullAddress = function() {
  471. return $scope.result.eligibilite.complement_addresse;
  472. };
  473. var formatDate = function(value) {
  474. return moment(value, 'DD/MM/YY');
  475. };
  476. var getFullAddress = function(callback) {
  477. if($scope.magicKey) {
  478. var findURL = 'http://api-adresse.data.gouv.fr/search/?';
  479. var url = findURL + "q=" + $scope.address;
  480. $.get(
  481. url,
  482. function(data, status) {
  483. var next = function(record) {
  484. reverseLocation($scope.geoCode, null, function(string, address) {
  485. if(record) {
  486. address.StreetNumber = record.housenumber;
  487. address.Match_addr = $scope.address;
  488. }
  489. callback(null, address);
  490. });
  491. };
  492. if(data && data.features && data.features[0] && data.features[0].properties) {
  493. next(data.features[0].properties);
  494. }
  495. else {
  496. next();
  497. }
  498. });
  499. }
  500. else {
  501. reverseLocation($scope.geoCode, null, function(string, address) {
  502. callback(null, address);
  503. });
  504. }
  505. };
  506. var getRecordsFor = function(identifier, coordinates) {
  507. var records = [];
  508. _.each($scope.data[identifier], function(record) {
  509. _.some(record._polygons, function(polygon) {
  510. if(isInside(polygon, coordinates)) {
  511. records.push(record);
  512. return true;
  513. }
  514. });
  515. });
  516. // Debug
  517. var debug = false;
  518. if (debug) {
  519. var colors = ['red', 'green', 'blue', 'black', 'silver', 'yellow'];
  520. var marker = L.marker([coordinates.y, coordinates.x]).addTo(map);
  521. var Lpolygons = [];
  522. _.each(records, function(record, i) {
  523. var style = {
  524. color : colors[i],
  525. fillColor: colors[i],
  526. weight : 4
  527. };
  528. _.each(record._polygons, function(polygon) {
  529. Lpolygons.push(L.polygon(polygon, style).bindPopup($scope.getHtmlContent(identifier, record)));
  530. });
  531. });
  532. L.layerGroup(Lpolygons).addTo(map);
  533. }
  534. return records;
  535. };
  536. var getResults = function() {
  537. $scope.results = {};
  538. $.ajax({
  539. method : "POST",
  540. url : "ajax/oracle.php",
  541. data : $scope.geoCode
  542. })
  543. .error(function(err) {
  544. console.error('Oracle issue', err);
  545. //[{"ID_ZAPM_PARTIELLE":"119CP0","DATE_OUV_SERVICE_REEL":null,"DATE_OUV_SERVICE_PREV":null,"DATE_FIN_TRAV_PREV":null}]
  546. // Debug without Oracle access
  547. 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}');
  548. })
  549. .done(function( msg ) {
  550. onResults(msg);
  551. });
  552. var onResults = function(results) {
  553. try {
  554. $scope.results = JSON.parse(results);
  555. $scope.results.address = $scope.address;
  556. $scope.results.ftth = parseResults($scope.results.ftth);
  557. $scope.results.adsl = parseResults($scope.results.adsl);
  558. $scope.results.mimo = parseResults($scope.results.mimo);
  559. computeDateFTTH();
  560. }
  561. catch(e) {
  562. console.error(e);
  563. alert('Probleme de connexion à la base de donnée Oracle.');
  564. $scope.hideResultPane();
  565. /*
  566. 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}');
  567. */
  568. }
  569. //console.log('$scope.results', results, '=>', $scope.results);
  570. $scope.$apply();
  571. };
  572. $scope.$evalAsync();
  573. };
  574. var init = function() {
  575. var stlo = [49.1154686, -1.0828136000000086];
  576. var map = L.map('map', {zoomControl:false}).setView(stlo, 9);
  577. map.on('dblclick', function(e) {
  578. var p = e.latlng;
  579. //console.log('click', e.latlng); // e is an event object (MouseEvent in this case)
  580. $scope.geoCode = {
  581. x: p.lng,
  582. y: p.lat
  583. };
  584. addCurrentMarker(true);
  585. $scope.showResultPane();
  586. getResults();
  587. });
  588. var maps = {
  589. "carte" : 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
  590. "satellite" : 'http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'
  591. };
  592. var cLayer = L.tileLayer(maps.satellite, {
  593. 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>',
  594. maxZoom: 18
  595. }).addTo(map);
  596. var styleOpts = {
  597. color : 'red',
  598. fillColor: 'red',
  599. weight : 8
  600. };
  601. $scope.data = {};
  602. $scope.colors = {
  603. "ftth": "#8cc474", // green
  604. "mimo": "#f9b256", // orange
  605. "adsl": "#76a7fa" // blue
  606. };
  607. $http({method: 'POST', url: 'data/dictionary.json'}).success(function(data) {
  608. $scope.dictionary = data;
  609. });
  610. $http({method: 'POST', url: 'data/Contour_Manche.json'}).success(function(data) {
  611. var style = {
  612. color : 'blue',
  613. fillColor: 'blue',
  614. weight : 2
  615. };
  616. $scope.data.manche = [{
  617. _polygons : [data.features[0].geometry.coordinates[0]],
  618. _style : style,
  619. _properties : {
  620. name : {string: 'Manche'}
  621. }
  622. }];
  623. 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
  624. _.each(mancheCoordinates, function(c, i) {
  625. mancheCoordinates[i] = [c[1], c[0]];
  626. });
  627. // Rectangle coordinates around Manche
  628. //var mancheCoordinates = [[49.732307856286, -1.97117692088061],[48.4, -1.75],[48.4, -0.5],[49.732307856286, -1.2]];
  629. // Debug: show manche limits
  630. //L.polygon(mancheCoordinates, {color: 'blue', fillColor: 'blue',weight: 8}).addTo(map);
  631. searchExtent = {
  632. "xmin" : _.max(_.map(mancheCoordinates, function(c) {return c[1];})),
  633. "ymin" : _.max(_.map(mancheCoordinates, function(c) {return c[0];})),
  634. "xmax" : _.min(_.map(mancheCoordinates, function(c) {return c[1];})),
  635. "ymax" : _.min(_.map(mancheCoordinates, function(c) {return c[0];})),
  636. "spatialReference" : {"wkid" : 84}
  637. };
  638. var suggestURL = 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest?f=pjson&searchExtent=' + JSON.stringify(searchExtent);
  639. var i = 0, j = 0;
  640. $scope.suggestLocation = function(val) {
  641. //console.log('__suggestLocation', val);
  642. $scope.suggestionsReady = false;
  643. i++;
  644. return $http.get(suggestURL, {
  645. params: {
  646. text: val
  647. }
  648. }).then(function(response) {
  649. if(val === $scope.address) { // Very important to debounce queries
  650. $scope.suggestionsReady = response.data.suggestions.length !== 0;
  651. $scope.suggestions = _.cloneDeep(response.data.suggestions);
  652. }
  653. return response.data.suggestions.map(function(item){
  654. return item.text;
  655. });
  656. });
  657. };
  658. });
  659. //console.time('FTTH data');
  660. $http({method: 'POST', url: 'data/FTTH_zapm_partielle.json'}).success(function(data) {
  661. var style = {
  662. color : $scope.colors.ftth,
  663. fillColor: $scope.colors.ftth,
  664. weight : 2
  665. };
  666. var properties = {
  667. name : {key: 'ATD'},
  668. hidden: ['ID_PM', 'MARCHE', 'ID_FT_ADSL', 'ID_FTTH_MN_ZAPM_PARTIELLE', 'ID_ZAPM_PARTIELLE', 'ID_ZAPM'],
  669. position: ['DATE_DEB_TRAV_PREV']
  670. };
  671. parseData('ftth', data, style, properties);
  672. //console.timeEnd('FTTH data');
  673. //console.debug('Data for FTTH are ready', data);
  674. if($scope.data.mimo && $scope.data.adsl && $scope.data.ftth) {
  675. $scope.loaded = true;
  676. }
  677. $scope.$evalAsync();
  678. });
  679. //console.time('ADSL data');
  680. $http({method: 'POST', url: 'data/TEL_FT_ADSL.json'}).success(function(data) {
  681. var style = {
  682. color : $scope.colors.adsl,
  683. fillColor: $scope.colors.adsl,
  684. weight : 2
  685. };
  686. var properties = {
  687. name : {key: 'LEGENDE'},
  688. hidden: ['NATURE', 'NRA_CETE', 'NRA_TMP', 'NRA_DPT', 'ID_FT_ADSL']
  689. };
  690. parseData('adsl', data, style, properties);
  691. //console.timeEnd('ADSL data');
  692. //console.debug('Data for ADSL are ready', data);
  693. if($scope.data.mimo && $scope.data.adsl && $scope.data.ftth) {
  694. $scope.loaded = true;
  695. }
  696. $scope.$evalAsync();
  697. });
  698. //console.time('MiMo data');
  699. $http({method: 'POST', url: 'data/Couverture_mimo.json'}).success(function(data) {
  700. var style = {
  701. color : $scope.colors.mimo,
  702. fillColor: $scope.colors.mimo,
  703. weight : 2
  704. };
  705. var properties = {
  706. name : {string: 'Couverture MiMo'},
  707. hidden: ['ID_MIMO_COUVERTURE']
  708. };
  709. parseData('mimo', data, style, properties);
  710. //console.timeEnd('MiMo data');
  711. //console.debug('Data for MIMO are ready', data);
  712. if($scope.data.mimo && $scope.data.adsl && $scope.data.ftth) {
  713. $scope.loaded = true;
  714. }
  715. $scope.$evalAsync();
  716. });
  717. window.map = map;
  718. $scope.mapType = 'Satellite';
  719. $scope.view = {};
  720. $scope.isShown = {};
  721. };
  722. var isDate = function(value) {
  723. return (value.toString().length === 8 && value.toString().substr(2, 1) === "/" && value.toString().substr(5,1) === "/");
  724. };
  725. var isInside = function(polygon, point) {
  726. // ray-casting algorithm based on
  727. // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
  728. var y = point.x ? point.x : point[0],
  729. x = point.y ? point.y : point[1];
  730. var inside = false;
  731. for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
  732. var xi = polygon[i][0], yi = polygon[i][1];
  733. var xj = polygon[j][0], yj = polygon[j][1];
  734. var intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
  735. if (intersect) {
  736. inside = !inside;
  737. }
  738. }
  739. return inside;
  740. };
  741. var parseData = function(identifier, data, style, properties) {
  742. var getPolygonsCoord = function(type, coord) {
  743. var result = [];
  744. if(type === 'Polygon') {
  745. result.push(_.map(coord[0], function(r) {return [r[1], r[0]];}));
  746. }
  747. if(type === 'MultiPolygon') {
  748. var p = [];
  749. _.each(coord, function(c) {
  750. result.push(_.map(c[0], function(r) {return [r[1], r[0]];}));
  751. });
  752. }
  753. return result;
  754. };
  755. var records = [];
  756. _.each(data.features, function(r) {
  757. var record = r.properties;
  758. var polygons = getPolygonsCoord(r.geometry.type, r.geometry.coordinates);
  759. record._coordinates = r.geometry.coordinates;
  760. record._type = r.geometry.type;
  761. record._polygons = polygons;
  762. record._style = style;
  763. record._properties = properties;
  764. records.push(record);
  765. });
  766. $scope.data[identifier] = records;
  767. };
  768. var parseResults = function(records) {
  769. if(!records || !records.length) {
  770. return null;
  771. }
  772. if(records.length === 1) {
  773. return records[0];
  774. }
  775. var result = records[0];
  776. return result;
  777. };
  778. var reverseLocation = function(geoCode, address, callback) {
  779. var reverseGeo = 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=pjson&distance=300';
  780. var url = reverseGeo + '&location=' + (geoCode ? $scope.geoCode.x + ',' + $scope.geoCode.y : address) ;
  781. $.get(
  782. url,
  783. function(data, status) {
  784. data = JSON.parse(data);
  785. var adresse = data && data.address && data.address.Match_addr;
  786. if(data && data.address && data.address.Address) {
  787. var i = 0;
  788. var num = '';
  789. while(!isNaN(parseInt(data.address.Address[i], 10))) {
  790. num += data.address.Address[i];
  791. i++;
  792. }
  793. data.address.StreetNumber = num;
  794. data.address.Address = data.address.Address.substr(num.length).trim();
  795. var typeVoie = data.address.Address.substring(0, data.address.Address.indexOf(' ')).toLowerCase();
  796. type = _.find(catTypeVoie, function(c){
  797. if(c.id === typeVoie || c.name.toLowerCase() === typeVoie) {
  798. return true;
  799. }
  800. });
  801. if(type) {
  802. data.address.StreetType = type.id;
  803. data.address.Address = data.address.Address.substr(typeVoie.length).trim();
  804. }
  805. }
  806. //console.debug('Reverse', geoCode, address, '=>', adresse, data.address);
  807. callback(adresse, data.address);
  808. $scope.$evalAsync();
  809. });
  810. };
  811. $scope.changeMap = function(value) {
  812. //console.log('Goto', value);
  813. map.removeLayer(cLayer);
  814. cLayer = L.tileLayer(maps[value], {
  815. 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>',
  816. maxZoom: 18
  817. }).addTo(map);
  818. };
  819. $scope.closeRight = function() {
  820. $mdSidenav('right').close().then(function(){});
  821. };
  822. $scope.computeLayer = function(identifier) {
  823. var Lpolygons = [];
  824. _.each($scope.data[identifier], function(record) {
  825. _.each(record._polygons, function(polygon) {
  826. Lpolygons.push(L.polygon(polygon, record._style).bindPopup($scope.getHtmlContent(identifier, record)));
  827. });
  828. });
  829. layer[identifier] = L.layerGroup(Lpolygons);
  830. };
  831. $scope.formatDateFTTH = function(date) {
  832. if(!date || date === "Invalid date") {return;}
  833. var momentDate = moment(date, 'DD/MM/YYYY');
  834. 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>';
  835. return $sce.trustAsHtml(result);
  836. };
  837. $scope.formatResults = function(identifier, results) {
  838. return $sce.trustAsHtml($scope.getHtmlContent(identifier, results));
  839. };
  840. $scope.getGeoCode = function(address, magicKey, callback) {
  841. var findURL = 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find?f=pjson&searchExtent=' + JSON.stringify(searchExtent);
  842. getGeoCodeInProgress = true;
  843. var url = findURL + "&text=" + address + ((magicKey) ? ("&magicKey=" + magicKey) : ', Basse-Normandie, France');
  844. //console.log('url', url);
  845. $.get(
  846. url,
  847. function(data, status) {
  848. data = JSON.parse(data);
  849. console.debug('address, magicKey', address, magicKey, data);
  850. if (status === 'success' && data.locations[0]) {
  851. if(data.locations[0].extent.xmax < searchExtent.xmin &&
  852. data.locations[0].extent.xmax > searchExtent.xmax &&
  853. data.locations[0].extent.xmin > searchExtent.xmax &&
  854. data.locations[0].extent.xmin > searchExtent.xmax) {
  855. getGeoCodeInProgress = false;
  856. //console.debug('getGeoCode', address, magicKey, '=>', data);
  857. return callback(null, data);
  858. }
  859. getGeoCodeInProgress = false;
  860. //console.debug('getGeoCode', address, magicKey, '=>', 'No result');
  861. callback('No result for ' + address);
  862. } else {
  863. getGeoCodeInProgress = false;
  864. //console.debug('getGeoCode', address, magicKey, '=>', 'No result');
  865. callback(status !== 'success' ? status : 'No result for ' + address);
  866. }
  867. });
  868. };
  869. $scope.getHtmlContent = function(identifier, record) {
  870. //var title = record._properties.name.string ? record._properties.name.string : record[record._properties.name.key];
  871. // Tooltip content
  872. var tooltip = '';
  873. _.each(record, function(value, property) {
  874. if(property.charAt(0) === '_' ||
  875. (property === 'date' && identifier === 'ftth') ||
  876. value === null ||
  877. typeof value === 'undefined') {
  878. return;
  879. }
  880. var label = $scope.dictionary[property] || property;
  881. value = $scope.dictionary[value] || value;
  882. var date;
  883. if(property.substring(0, 5) === 'DATE_' && !$scope.dictionary[value] && isDate(value)) {
  884. date = formatDate(value);
  885. }
  886. 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>';
  887. });
  888. if(identifier === 'adsl') {
  889. tooltip = '<a style="float: right;" href="http://www.ariase.com/fr/eligibilite/test.html" target="_blank">Tester mon éligibilité ADSL avec Ariase.com</a>';
  890. }
  891. return tooltip;
  892. };
  893. $scope.hideLayer = function(identifier) {
  894. map.removeLayer(layer[identifier]);
  895. };
  896. $scope.hideResultPane = function() {
  897. if(!$('#result').height()) {return;}
  898. $('#result').animate({height: 0}, 1000);
  899. $('#map').animate({
  900. height: $('body').height(),
  901. }, 1000, function() {
  902. // Animation complete.
  903. map.invalidateSize();
  904. var centerPoint = $scope.geoCode ? new L.LatLng($scope.geoCode.y, $scope.geoCode.x) : stlo;
  905. map.setView(centerPoint, 14);
  906. });
  907. };
  908. $scope.initPopup = function() {
  909. //console.log('initPopup', $scope.geoCode);
  910. $scope.postForm = null;
  911. getFullAddress(function(err, address) {
  912. if(err) {console.error(err);}
  913. //console.log('add', address);
  914. $scope.result = {eligibilite: {}, autres: {}};
  915. // Debug
  916. // $scope.result.eligibilite.prenom = 'Francois';
  917. // $scope.result.eligibilite.nom = 'Beaufils';
  918. // $scope.result.eligibilite.email = 'francoisbeaufils@zeno-labs.com';
  919. // $scope.result.eligibilite.vous_etes = 'locataire';
  920. // $scope.result.eligibilite.ce_logement_est = 'residence_principale';
  921. // $scope.result.eligibilite.info_et_libertes = true;
  922. // $scope.result.eligibilite.accord = 'avec_souscription';
  923. $scope.result.eligibilite.geo_code = JSON.stringify($scope.geoCode);
  924. $scope.result.eligibilite.code_postal = address.Postal;
  925. $scope.result.eligibilite.complement_addresse = address.Match_addr;
  926. $scope.result.eligibilite.nom_voie = address.Address;
  927. $scope.result.eligibilite.numero_voie = address.StreetNumber;
  928. $scope.result.eligibilite.type_voie = address.StreetType;
  929. $scope.result.eligibilite.ville = address.City;
  930. });
  931. };
  932. $scope.isFormValid = function() {
  933. if(!$scope.result || !$scope.result.eligibilite) {return;}
  934. var isValid = true;
  935. _.each($scope.formulaires.eligibilite.sections, function(section) {
  936. _.each(section.lines, function(line) {
  937. _.each(line.ctrls, function(ctrl) {
  938. ctrl.invalid = false;
  939. if(ctrl.require && !ctrl.isValid($scope.result.eligibilite[ctrl.id], $scope.result.autres[ctrl.id])) {
  940. isValid = false;
  941. ctrl.invalid = true;
  942. }
  943. });
  944. });
  945. });
  946. return isValid;
  947. };
  948. $scope.isInscriptionOpen = function() {
  949. if(!$scope.results.ftth || !$scope.results.ftth.DATE_DEB_ETUDES_PREV) {return false;}
  950. var dateDebEtudes = moment($scope.results.ftth.DATE_DEB_ETUDES_PREV, 'DD/MM/YY');
  951. var now = moment();
  952. var diffDays = now.diff(dateDebEtudes) / 1000 / 3600 / 24;
  953. return diffDays > nbJoursInscription;
  954. };
  955. $scope.onSubmitAddress = function($item, $model, $label) {
  956. // console.log('onSubmitAddress address', $scope.address);
  957. // console.log('onSubmitAddress $item', $item);
  958. // console.log('onSubmitAddress $model', $model);
  959. // console.log('onSubmitAddress $label', $label);
  960. // Get magic key
  961. var item = _.find($scope.suggestions, {text: $item});
  962. if(!item) {
  963. item = $scope.suggestions[0];
  964. $scope.address = item.text;
  965. }
  966. $scope.magicKey = item.magicKey;
  967. //console.log('onSubmitAddress -_-item', item, '=>', $scope.magicKey);
  968. $scope.getGeoCode($scope.address, $scope.magicKey, function(err, data) {
  969. $scope.geoCode = data && data.locations && data.locations[0] && data.locations[0].feature.geometry;
  970. if(err) {console.error('Geocode error', err);}
  971. var toast = toast || {
  972. template: '<md-toast><i class = " md-error"></i> Oups! Aucun résultat trouvé dans la Manche pour: ' + $scope.address + '</md-toast>',
  973. hideDelay: 3000,
  974. position: 'bottom right'
  975. };
  976. // $mdToast.simple()
  977. // .template(')
  978. // .position('bottom right')
  979. // .hideDelay(3000);
  980. if(err || !$scope.geoCode) {
  981. $scope.hideResultPane();
  982. $mdToast.show(toast);
  983. }
  984. //console.log('Addresses found for', $scope.address, '=>', data, '=> Geocode:', $scope.geoCode);
  985. if($scope.geoCode) {
  986. addCurrentMarker();
  987. $scope.showResultPane();
  988. getResults();
  989. }
  990. });
  991. };
  992. $scope.postFormEl = function() {
  993. $scope.postForm = {inProgress: true};
  994. // Add ID_ZAPM_PARTIELLE
  995. $scope.result.eligibilite.id_zapm_partielle = $scope.results.ftth.ID_ZAPM_PARTIELLE;
  996. _.each($scope.result.autres, function(value, key) {
  997. $scope.result.eligibilite[key] = value;
  998. });
  999. //console.log('postForm', $scope.result.eligibilite);
  1000. $scope.$evalAsync();
  1001. function mysql_real_escape_string (str) {
  1002. if(typeof str !== 'string') {return str;}
  1003. return str.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function (char) {
  1004. switch (char) {
  1005. case "\0":
  1006. return "\\0";
  1007. case "\x08":
  1008. return "\\b";
  1009. case "\x09":
  1010. return "\\t";
  1011. case "\x1a":
  1012. return "\\z";
  1013. case "\n":
  1014. return "\\n";
  1015. case "\r":
  1016. return "\\r";
  1017. case "\"":
  1018. case "'":
  1019. case "\\":
  1020. case "%":
  1021. return "\\"+char; // prepends a backslash to backslash, percent,
  1022. // and double/single quotes
  1023. }
  1024. });
  1025. }
  1026. var keys = '';
  1027. var values = '';
  1028. _.each($scope.result.eligibilite, function(value, key) {
  1029. keys += '`' + key + '`, ';
  1030. if(value === 'undefined' || value === undefined) {
  1031. value = '';
  1032. }
  1033. if(typeof value === 'boolean') {
  1034. values += value + ', ';
  1035. }
  1036. else {
  1037. values += "'" + mysql_real_escape_string(value) + "', ";
  1038. }
  1039. });
  1040. var dateTime = (new Date ((new Date((new Date(new Date())).toISOString() )).getTime() - ((new Date()).getTimezoneOffset()*60000))).toISOString().slice(0, 19).replace('T', ' ');
  1041. var query = "INSERT INTO `eligibilite`.`demandes` (`date`," + keys.substring(0, keys.length -2) + ") VALUES ('" + dateTime + "', " + values.substring(0, values.length -2) + ");";
  1042. console.log('query', query);
  1043. $.ajax({
  1044. method : "POST",
  1045. url : "ajax/datastores.php",
  1046. data : {query: query}
  1047. })
  1048. .done(function( msg ) {
  1049. if(!isNaN(msg)) {
  1050. $scope.postForm = {ok: true};
  1051. //var template = $templateCache.get('nameOfTemplate.html');
  1052. var numDemande = moment().format('YYYYMMDD') + msg;
  1053. var body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  1054. body += '<html><body style="font-size: 14px; font-family: calibri;">' +
  1055. 'Bonjour ' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + ', <br>' +
  1056. 'Nous vous confirmons votre demande de pré-raccordement FTTH. <br><br>' +
  1057. 'Cette demande porte le numéro: ' +
  1058. '<span style="color: #31708f;font-size:17px; font-weight:bold;">' + numDemande + '</span><br><br>' +
  1059. 'Voici le détail de votre demande:' +
  1060. '<div bgColor="#d9edf7" BORDERCOLOR="#bce8f1" style="color: #31708f;background-color: #d9edf7;border-color: #bce8f1;padding: 10px;margin: 1em;font-size:14px;">' +
  1061. '<table style="line-height: 40px;" bgColor="#d9edf7">';
  1062. // _.each($scope.result.eligibilite, function(value, key) {
  1063. // body += '<tr>';
  1064. // body += '<th style="text-align:left;">' + key + '</th>';
  1065. // body += '<td>' + value + '</td>';
  1066. // body += '</tr>';
  1067. // });
  1068. // Numero demande
  1069. body += '<tr>';
  1070. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Numéro demande</th>';
  1071. body += '<td>' + numDemande + '</td>';
  1072. body += '</tr>';
  1073. // Date demande
  1074. body += '<tr>';
  1075. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Date</th>';
  1076. body += '<td>' + moment().lang('fr').format('LLLL') + '</td>';
  1077. body += '</tr>';
  1078. // Demandeur
  1079. body += '<tr>';
  1080. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Demandeur</th>';
  1081. body += '<td>' + $scope.result.eligibilite.prenom + ' ' + $scope.result.eligibilite.nom + '</td>';
  1082. body += '</tr>';
  1083. // Email
  1084. body += '<tr>';
  1085. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Email</th>';
  1086. body += '<td>' + $scope.result.eligibilite.email + '</td>';
  1087. body += '</tr>';
  1088. // Adresse
  1089. body += '<tr>';
  1090. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Adresse</th>';
  1091. body += '<td>' + computeFullAddress() + '</td>';
  1092. body += '</tr>';
  1093. // Vous etes
  1094. var cat = _.find(catVousEtes, {id: $scope.result.eligibilite.vous_etes});
  1095. var res = cat && cat.name ? cat.name : $scope.result.eligibilite.vous_etes;
  1096. body += '<tr>';
  1097. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Vous êtes</th>';
  1098. body += '<td>' + res + '</td>';
  1099. body += '</tr>';
  1100. // Ce logement est
  1101. var cat2 = _.find(catCeLogementEst, {id: $scope.result.eligibilite.ce_logement_est});
  1102. var res2 = cat2 && cat2.name ? cat2.name : $scope.result.eligibilite.ce_logement_est;
  1103. body += '<tr>';
  1104. body += '<th style="text-align: left;white-space: nowrap;height: 40px;color: #666;">Ce logement est</th>';
  1105. body += '<td>' + res2 + '</td>';
  1106. body += '</tr>';
  1107. //console.log('$scope.result', $scope.result);
  1108. body += '</table></div><br><br>';
  1109. 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>' +
  1110. '<table style="">' +
  1111. ' <tr>' +
  1112. ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Email</th><td>' + siteEmail + '</td>' +
  1113. ' </tr><tr>' +
  1114. ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Adresse</th><td>' + siteAddresse + '</td>' +
  1115. ' </tr><tr>' +
  1116. ' <th style="text-align: left;white-space: nowrap;height: 30px;color: #666;">Tel</th><td>' + siteTel + '</td>' +
  1117. ' </tr>' +
  1118. '</table><br><br>';
  1119. body += 'A bientôt sur: <a href="' + siteUrl + '">' + siteName + '</a></body></html>';
  1120. console.log('body', body);
  1121. var mail = {
  1122. to : $scope.result.eligibilite.email,
  1123. sujet : 'Votre demande de pré-raccordement FTTH n° ' + numDemande,
  1124. message: body
  1125. };
  1126. $.ajax({
  1127. method : "POST",
  1128. url : "ajax/datastores.php",
  1129. data : {
  1130. siteEmail: siteEmail,
  1131. mail : mail}
  1132. })
  1133. .done(function( msg ) {
  1134. console.log('Mail result', msg);
  1135. });
  1136. $scope.result.eligibilite = {};
  1137. $scope.autres = {};
  1138. $scope.address = null;
  1139. $scope.magicKey = null;
  1140. }
  1141. else {
  1142. $scope.postForm = {error: msg};
  1143. }
  1144. $scope.hideResultPane();
  1145. $scope.$apply();
  1146. });
  1147. };
  1148. $scope.showLayer = function(identifier) {
  1149. map.addLayer(layer[identifier]);
  1150. };
  1151. $scope.showResultPane = function() {
  1152. var bodyHeight = $('body').height();
  1153. var height = Math.max(300, bodyHeight / 3);
  1154. var heightMap = bodyHeight - height;
  1155. $('#result').animate({height: height + 'px'}, 1000);
  1156. $('#map').animate({
  1157. height: heightMap + 'px',
  1158. }, 1000, function() {
  1159. // Animation complete.
  1160. map.invalidateSize();
  1161. map.setView(new L.LatLng($scope.geoCode.y, $scope.geoCode.x), 14);
  1162. });
  1163. };
  1164. $scope.toggleResultPane = function() {
  1165. if($('#result').height()) {
  1166. return $scope.hideResultPane();
  1167. }
  1168. if($scope.results && $scope.results.ftth) {
  1169. return $scope.showResultPane();
  1170. }
  1171. };
  1172. $scope.toggleRight = function() {
  1173. $mdSidenav('right').toggle()
  1174. .then(function(){});
  1175. };
  1176. $scope.$watch('view', function(view) {
  1177. if(_.isEmpty(view)) {return;}
  1178. $('#layer-loading').removeClass('force-hidden').find('.md-inner').show();
  1179. setTimeout(function() {
  1180. _.each(view, function(value, key) {
  1181. if($scope.isShown[key] !== value) {
  1182. if(value) {
  1183. if(typeof $scope.isShown[key] !== 'undefined') {
  1184. $scope.showLayer(key);
  1185. $('#layer-loading').find('.md-inner').hide();
  1186. }
  1187. else {
  1188. $timeout(function() {
  1189. $scope.computeLayer(key);
  1190. $scope.showLayer(key);
  1191. $('#layer-loading').find('.md-inner').hide();
  1192. }, 500);
  1193. }
  1194. }
  1195. else {
  1196. $scope.hideLayer(key);
  1197. setTimeout(function() {
  1198. $('#layer-loading').find('.md-inner').hide();
  1199. }, 1000);
  1200. }
  1201. $scope.isShown[key] = value;
  1202. }
  1203. });
  1204. });
  1205. }, true);
  1206. $(window).resize(function() {
  1207. if(!$('#result').height()) {return;}
  1208. $scope.showResultPane();
  1209. });
  1210. init();
  1211. /*
  1212. $scope.toto = 'FB SA RAXCE';
  1213. var templateUrl = $sce.getTrustedResourceUrl('html/emailTemplate.html');
  1214. $templateRequest(templateUrl).then(function(template) {
  1215. // template is the HTML template as a string
  1216. // Let's put it into an HTML element and parse any directives and expressions
  1217. // in the code. (Note: This is just an example, modifying the DOM from within
  1218. // a controller is considered bad style.)
  1219. var factory = angular.element(template);
  1220. //factory.html();
  1221. $compile(factory)($scope);
  1222. // get the interpolated HTML asynchronously after the interpolation happens
  1223. $timeout(function () {
  1224. factory.append('<div></div>');
  1225. html = factory.html();
  1226. console.log('template', html);
  1227. // ... do whatever you need with the interpolated HTML
  1228. });
  1229. }, function() {
  1230. // An error has occurred
  1231. });
  1232. */
  1233. });