app.js 44 KB

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