app.js 46 KB

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