Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 138.34 KB | None | 0 0
  1. /*******************************************************/
  2. /*********** Structure du document **************/
  3. /*
  4.  
  5. #region Fonctions de la variable Ajax
  6. - parseEvents : gestion du json récupéré pour le parser sur la listview
  7. - parseGuests : gestion du json récupéré pour le parser sur la listview
  8. - parsePrestations : gestion du json récupéré pour le parser sur la listview
  9. - getEventsList : récupère la liste des évènements (ajax)
  10. - getGuestslist : récupère la liste des invités (ajax)
  11. - blockui : overlay avec le message chargement
  12. - blockuiNoMsg : overlay sans message
  13.  
  14. #region ONSEN UI
  15.  
  16. #region backbutton
  17. - Fonctions permettant de gérer les clicks du bouton back sur ANDROID
  18.  
  19. #region Fonctions utilitaires
  20. - checkTokenValidity
  21. - offlineMode
  22. - openBarcodeScan
  23.  
  24. #region MainPage
  25.  
  26. #region eventsPage
  27.  
  28. #region prestationsPage
  29.  
  30. #region guestsPage
  31. #subregion GUEST LIST OPTION PANEL
  32. - Qr Code
  33. - #search
  34. - #importBase
  35. #subregion infoGuestPage
  36.  
  37. #region LOCAL
  38. - Gestions des pages du mode hors ligne:
  39. #subregion prestationsPageLocal
  40. #subregion guestsPageLocal
  41. #subregion Export
  42. - Fonctions permettant l'export des données vers les APIs
  43. #subregion Check presence
  44. - Validation de la présence d'un invité hors ligne
  45. #subregion infoGuestPageLocal
  46. #subregion LOCAL GUEST LIST OPTION PANEL
  47.  
  48.  
  49. #region Lazy Loading
  50. - Chargement des listes d'invités en mode lazy loading pour éviter la surchage des listviews
  51.  
  52. #region Swipe
  53. - Fonctions permettant de gérer la navigation du swipe right de l'écran
  54.  
  55. /*******************************************************/
  56.  
  57. var app = {
  58. // Application Constructor
  59. initialize: function() {
  60. this.bindEvents();
  61. },
  62. // Bind Event Listeners
  63. //
  64. // Bind any events that are required on startup. Common events are:
  65. // 'load', 'deviceready', 'offline', and 'online'.
  66. bindEvents: function() {
  67. document.addEventListener('deviceready', this.onDeviceReady, false);
  68. },
  69. // deviceready Event Handler
  70. //
  71. // The scope of 'this' is the event. In order to call the 'receivedEvent'
  72. // function, we must explicitly call 'app.receivedEvent(...);'
  73. onDeviceReady: function() {
  74. }
  75. };
  76.  
  77. var url = 'http://recette.apiagora.com/api/';
  78.  
  79. var requestConnection = false;
  80.  
  81. // Variables locales
  82. var guestsList = {
  83. id : null,
  84. eventId: null,
  85. prestationId: null,
  86. prestationName: null,
  87. prestation: false,
  88. list : null,
  89. listSearch: null,
  90. row : null,
  91. nbRecord: 0,
  92. startRecord : 0,
  93. eventName : null,
  94. nbParticipants: 0,
  95. nbPresents: 0,
  96. tablette: false,
  97. dialog : 0,
  98. // 0 = aucune, 1 = search, 2 = searchLocal, 3 = authLocal, 4 = optionPanelPresta, 5 = optionPanel, 6 = searchFilter
  99. // 7 = optionPanelPrestaLocal, 8 = optionPanelLocal, 9 = Scan, 10 = ScanLocal
  100. qrCode : 0,
  101. statusPar : ["Inconnu", "Potentiel", "Pr\351vu", "Pr\351sent", "Factur\351", "Pay\351", "Non Inscrit", "Groupe", "Absent"],
  102. }
  103.  
  104. var ApiToken = null;
  105. var rememberMe = "false";
  106.  
  107. $( document ).ready(function() {
  108.  
  109. /*
  110. var deviceType = (navigator.userAgent.match(/iPad/i)) == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "null";
  111. if(deviceType == "iPad" || deviceType == "iPhone"){
  112. document.body.style.webkitTransform = 'translate3d(0, 20px, 0)';
  113. }*/
  114.  
  115. if($(window).width() > 700){
  116. document.getElementsByClassName("guestsPageView")[1].parentNode.removeChild(document.getElementsByClassName("guestsPageView")[1]);
  117. document.getElementsByClassName("guestsPageView")[1].parentNode.removeChild(document.getElementsByClassName("guestsPageView")[1]);
  118.  
  119. document.getElementsByClassName("guestsPageViewLocal")[1].parentNode.removeChild(document.getElementsByClassName("guestsPageViewLocal")[1]);
  120. document.getElementsByClassName("guestsPageViewLocal")[1].parentNode.removeChild(document.getElementsByClassName("guestsPageViewLocal")[1]);
  121. guestsList.tablette = true;
  122. }else{
  123. document.getElementsByClassName("guestsPageView")[0].parentNode.removeChild(document.getElementsByClassName("guestsPageView")[0]);
  124. document.getElementsByClassName("guestsPageViewLocal")[0].parentNode.removeChild(document.getElementsByClassName("guestsPageViewLocal")[0]);
  125. }
  126.  
  127. // Gestion des différentes bases de données
  128. var currentDatabase = window.localStorage.getItem("database");
  129. if(currentDatabase == null)
  130. currentDatabase = "#000";
  131.  
  132. document.getElementById("database").value = currentDatabase;
  133.  
  134. switch(currentDatabase) {
  135. case "#000":
  136. url = "http://recette.apiagora.com/api/";
  137. break;
  138. case "#001":
  139. url = "http://bnp.apiagora.com/api/";
  140. break;
  141. case "#002":
  142. url = "https://agora.orange.com/api/";
  143. break;
  144. case "#999":
  145. url = "http://localhost:60814/api/";
  146. break;
  147. default:
  148. url = "http://recette.apiagora.com/api/";
  149. }
  150. });
  151.  
  152. // Centrage de l'overlay block ui
  153. $.fn.center = function () {
  154. this.css("position","absolute");
  155. this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
  156. this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
  157. return this;
  158. }
  159.  
  160. // REGEX pour récupérer les paramètres url
  161. // Exemple http://recette.agoraevent.fr/api?id=2
  162. // getParameterByName(url, id) return 2
  163. function getParameterByName(url, name) {
  164. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  165. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  166. results = regex.exec(url);
  167. return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  168. }
  169.  
  170. //Callback for notification plugin alert
  171. function alertDismissed() {
  172. // do something
  173. }
  174.  
  175. //CallBack Confirm
  176. function onConfirmQuitApp(buttonIndex) {
  177. if(buttonIndex == 2){
  178. navigator.app.exitApp();
  179. }
  180. }
  181.  
  182. /*************************/
  183. /* #region ONSEN UI */
  184. /*************************/
  185. var dialogLoginExport;
  186. var dialogSearch;
  187.  
  188. var module = angular.module('app', ['onsen']);
  189.  
  190. module.controller('AppController', function($scope) {
  191. ons.createDialog('loginExport.html').then(function(dialog) {
  192. dialogLoginExport = dialog;
  193. });
  194.  
  195. ons.createDialog('search.html').then(function(dialog) {
  196. dialogSearch = dialog;
  197. });
  198. });
  199.  
  200. /**********************************************/
  201. /***** #region Fonctions de la variable Ajax */
  202. /*********************************************/
  203. // Appels ajax + utilitaires
  204. var ajax = {
  205. parseEvents:function(result){
  206. $('#eventsList').empty();
  207. var monthsInYear= new Array("janvier", "f\351vrier", "mars", "avril", "mai", "juin", "juillet", "ao\373t", "septembre", "octobre", "novembre", "d\351cembre");
  208. $.each(result, function(i, row) {
  209. var date = new Date(row.StartDate);
  210. var endDate = new Date(row.EndDate);
  211. var today = new Date();
  212. if(endDate < today){
  213. $('#eventsList').append('<li><a href="" data-id="' + row.ID + '"><i class="fa fa-calendar-o fa-3x calendarIcon"></i><h3>' + row.Title + '</h3><p>' + date.getDate() + " " + monthsInYear[date.getMonth()] + " " + date.getFullYear() + '</p></a></li>');
  214. }else{
  215. $('#eventsList').append('<li><a href="" data-id="' + row.ID + '"><i class="fa fa-calendar fa-3x calendarIcon"></i><h3>' + row.Title + '</h3><p>' + date.getDate() + " " + monthsInYear[date.getMonth()] + " " + date.getFullYear() + '</p></a></li>');
  216. }
  217. });
  218. $('#eventsList').listview('refresh');
  219. },
  220. parseGuests:function(result){
  221. $('#guestsList').empty();
  222. if(guestsList.prestations){
  223. $.each(result, function(i, row) {
  224. $('#guestsList').append('<li><a href="" data-id="' +
  225. row.ID + '"><h3><i class="fa fa-user fa-2x"></i>' + row.LastName + '<p>' + row.FirstName + '</p></h3></a></li>');
  226. });
  227. }else{
  228. $.each(result, function(i, row) {
  229. $('#guestsList').append('<li><a href="" data-id="' +
  230. row.ID + '"><h3><i class="fa fa-user fa-2x"></i>' + row.LastName + '<p>' + row.FirstName + '</p></h3></a></li>');
  231. });
  232. }
  233. },
  234. parsePrestations:function(result){
  235. $('#prestationsList').empty();
  236.  
  237. fullURLCount = 'methods/MobileApp/CountParticipants?id=' + guestsList.eventId;
  238. $.ajax({
  239. type: 'GET',
  240. url: url + fullURLCount,
  241. crossDomain: true,
  242. headers: {'AgoraEvent-Token': ApiToken},
  243. success: function (resultCount) {
  244. var text0 = ' invit\351';
  245. if(resultCount[0] > 0){
  246. text0 = ' invit\351s';
  247. }
  248.  
  249. var text1 = ' pr\351sent';
  250. if(resultCount[1] > 0){
  251. text1 = ' pr\351sents';
  252. }
  253.  
  254. $('#prestationsList').append('<li><a href="" data-id="0" style="color: green;"><i class="fa fa-home fa-3x homePrestation"></i><h3>Accueil Principal</h3><p>' + resultCount[0] + text0 +'</p><span class="statusListView">' + resultCount[1] + '/' + resultCount[0] + ' ' + text1 + '</span></a></li>');
  255.  
  256. $.each(result, function(i, row) {
  257.  
  258. var nb_inscrits = row.PLACE_DISPO - row.PLACE_RESTANTE;
  259. var text1 = ' inscrit sur ';
  260. var text2 = ' place disponible';
  261. if(isNaN(nb_inscrits)){
  262. text1 = "";
  263. text2 = "";
  264. nb_inscrits = "";
  265. row.PLACE_DISPO = "";
  266. }else{
  267. if(nb_inscrits > 0){
  268. text1 = ' inscrits sur ';
  269. }
  270. if(row.PLACE_DISPO > 0){
  271. text2 = ' places disponibles';
  272. }
  273. }
  274.  
  275. var text3 = ' pr\351sent';
  276. if(row.NB_PRESENT > 0){
  277. text3 = ' pr\351sents';
  278. }
  279. $('#prestationsList').append('<li><a href="" data-id="' + row.ID + '"><i class="fa fa-ticket fa-3x"></i><h3>' + row.LIBELLE + '</h3><p>' + nb_inscrits + text1 + row.PLACE_DISPO + text2 + '</p><span class="statusListView">' + row.NB_PRESENT + '/' + nb_inscrits + ' ' + text3 + '</span></a></li>');
  280. });
  281. $('#prestationsList').listview('refresh');
  282. $.unblockUI();
  283. },
  284. error: function (request,error) {
  285. $.unblockUI();
  286. }
  287. });
  288. },
  289. getEventsList: function(){
  290. $.ajax({
  291. type: 'GET',
  292. url: url + 'methods/MobileApp/GetEventsList',
  293. crossDomain: true,
  294. headers: {'AgoraEvent-Token': ApiToken},
  295. async: false,
  296. success: function (result) {
  297. ajax.parseEvents(result);
  298. $.unblockUI();
  299. },
  300. error: function (request, error) {
  301. $.unblockUI();
  302. if(request.status == 401){
  303. // Unauthorized
  304. navigator.notification.alert(
  305. "Votre session a expir\351, veuillez-vous identifier \340 nouveau", // message
  306. alertDismissed, // callback
  307. "Notification", // title
  308. "Ok" // buttonName
  309. );
  310.  
  311. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  312. }
  313.  
  314. navigator.notification.alert(
  315. "Erreur lors de la r\351cup\351ration des \351v\350nements",
  316. alertDismissed,
  317. "Notification",
  318. "Ok"
  319. );
  320. }
  321. });
  322. },
  323. getGuestslist: function(prestation){
  324. guestsList.startRecord = 0;
  325. var fullURLGet = "";
  326. var fullURLCount = "";
  327. if(prestation){
  328. document.getElementById("guestsPageTitle").innerHTML = guestsList.prestationName;
  329. fullURLGet = 'methods/MobileApp/GetParticipants?id=' + guestsList.prestationId + '&idManif=' + guestsList.eventId + '&Prestation=true&StartRecord=' + guestsList.startRecord + '&RecordsCount=100';
  330. fullURLCount = 'methods/MobileApp/CountParticipants?id=' + guestsList.prestationId + '&idManif=' + guestsList.eventId + '&Prestation=true';
  331. }else{
  332. document.getElementById("guestsPageTitle").innerHTML = guestsList.eventName;
  333. fullURLGet = 'methods/MobileApp/GetParticipants?id=' + guestsList.eventId + '&StartRecord=' + guestsList.startRecord + '&RecordsCount=100';
  334. fullURLCount = 'methods/MobileApp/CountParticipants?id=' + guestsList.eventId;
  335. }
  336.  
  337. ajax.blockui();
  338.  
  339. $.ajax({
  340. type: 'GET',
  341. url: url + fullURLGet,
  342. crossDomain: true,
  343. headers: {'AgoraEvent-Token': ApiToken},
  344. success: function (result) {
  345. guestsList.list = result;
  346. ajax.parseGuests(result);
  347. guestsList.startRecord += 100;
  348. //COUNT NB PARTICIPANTS
  349. $.ajax({
  350. type: 'GET',
  351. url: url + fullURLCount,
  352. crossDomain: true,
  353. headers: {'AgoraEvent-Token': ApiToken},
  354. success: function (result) {
  355. guestsList.nbParticipants = result[0];
  356. guestsList.nbPresents = result[1];
  357. var text0 = ' r\351sultat';
  358. if(result[0] > 0){
  359. text0 = ' r\351sultats';
  360. }
  361. document.getElementById("guestsPageNbResults").innerHTML = result[0] + text0;
  362.  
  363. var text1 = ' pr\351sent';
  364. if(result[1] > 0){
  365. text1 = ' pr\351sents';
  366. }
  367. document.getElementById("guestsPageNbPresents").innerHTML = result[1] + text1;
  368.  
  369. $.mobile.changePage( "#guestsPage", { transition: "slide", changeHash: false });
  370. $('#guestsList').listview('refresh');
  371. $.unblockUI();
  372. },
  373. error: function (request,error) {
  374. $.unblockUI();
  375. navigator.notification.alert(
  376. "Erreur lors de la r\351cup\351ration du nombre de r\351sultats",
  377. alertDismissed,
  378. "Notification",
  379. "Ok"
  380. );
  381. }
  382. });
  383. },
  384. error: function (request,error) {
  385. $.unblockUI();
  386. if(request.status == 401){
  387. // Unauthorized
  388. navigator.notification.alert(
  389. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  390. alertDismissed,
  391. "Notification",
  392. "Ok"
  393. );
  394.  
  395. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  396. }
  397.  
  398. navigator.notification.alert(
  399. "Erreur lors de la r\351cup\351ration des invit\351s",
  400. alertDismissed,
  401. "Notification",
  402. "Ok"
  403. );
  404. }
  405. });
  406. },
  407. blockui: function(){
  408. $.blockUI({ css: {
  409. width: '250px',
  410. centerX: true,
  411. centerY: true,
  412. allowBodyStretch: true,
  413. border: 'none',
  414. backgroundColor: '#000',
  415. '-webkit-border-radius': '10px',
  416. '-moz-border-radius': '10px',
  417. opacity: .5,
  418. color: '#fff'
  419. },
  420. message: '<h2>Chargement...</h2>'
  421. });
  422.  
  423. $('.blockUI.blockMsg').center();
  424. },
  425. blockuiNoMsg: function(){
  426. $.blockUI({ css: {
  427. width: '250px',
  428. centerX: true,
  429. centerY: true,
  430. allowBodyStretch: true,
  431. border: 'none',
  432. backgroundColor: '#000',
  433. '-webkit-border-radius': '10px',
  434. '-moz-border-radius': '10px',
  435. opacity: .5,
  436. color: '#fff'
  437. },
  438. message: ''
  439. });
  440. },
  441. blockuiCustomMsg: function(text){
  442. $.blockUI({ css: {
  443. width: '250px',
  444. centerX: true,
  445. centerY: true,
  446. allowBodyStretch: true,
  447. border: 'none',
  448. backgroundColor: '#000',
  449. '-webkit-border-radius': '10px',
  450. '-moz-border-radius': '10px',
  451. opacity: .5,
  452. color: '#fff'
  453. },
  454. message: '<div style="padding: 10px;"><p id="blockUiMessage">' + text + '</p></div>'
  455. });
  456. $('.blockUI.blockMsg').center();
  457. }
  458. }
  459.  
  460. /*************************/
  461. /* #region backbutton */
  462. /*************************/
  463. /*********** Gestion des clicks sur le bouton back ANDROID **************/
  464. document.addEventListener("backbutton", function(e){
  465. e.preventDefault();
  466.  
  467. if(guestsList.qrCode == 1){
  468. // DONT CLOSE
  469. }
  470. else if(guestsList.dialog > 0 && !($.mobile.activePage.is('#scanPage'))){
  471. // 0 = aucune, 1 = search, 2 = searchLocal, 3 = authLocal, 4 = optionPanelPresta, 5 = optionPanel, 6 = searchFilter
  472. // 7 = optionPanelPrestaLocal, 8 = optionPanelLocal
  473. if(guestsList.dialog == 1 || guestsList.dialog == 2){
  474. setTimeout(function(){ dialogSearch.hide(); }, 50);
  475. }
  476. else if(guestsList.dialog == 3){
  477. setTimeout(function(){ dialogLoginExport.hide(); }, 50);
  478. }
  479. else if(guestsList.dialog == 4){
  480. $("#moreOptionOverlayDivPrestationPage").click();
  481. }
  482. else if(guestsList.dialog == 5){
  483. $("#moreOptionOverlayDivGuestsPageLocal").click();
  484. }
  485. else if(guestsList.dialog == 6){
  486. $('#guestsPageSearchFilter').fadeOut("slow");
  487. }
  488. else if(guestsList.dialog == 7){
  489. $('#moreOptionOverlayDivPrestationPageLocal').fadeOut("slow");
  490. }
  491. else if(guestsList.dialog == 8){
  492. $('#moreOptionOverlayDivGuestsPageLocal').fadeOut("slow");
  493. }
  494. guestsList.dialog = 0;
  495. }
  496. else if($.mobile.activePage.is('#mainPage')){
  497. navigator.notification.confirm(
  498. "Etes-vous s\373r de vouloir quitter l'application?", // message
  499. onConfirmQuitApp, // callback to invoke with index of button pressed
  500. "Notification", // title
  501. ['Annuler','Oui'] // buttonLabels
  502. );
  503. }
  504. else if($.mobile.activePage.is('#eventsPage')){
  505. importedBase = window.localStorage.getItem("importedBase");
  506. if(importedBase == "true"){
  507. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  508. }
  509. }
  510. else if($.mobile.activePage.is('#prestationsPage')){
  511. $.mobile.changePage( "#eventsPage", { transition: "slide", reverse: true, changeHash: false });
  512. }
  513. else if($.mobile.activePage.is('#guestsPage')){
  514. if(guestsList.prestations || (!guestsList.prestations && guestsList.prestationId == 0)){
  515. $.mobile.changePage( "#prestationsPage", { transition: "slide", reverse: true, changeHash: false });
  516. }
  517. else
  518. {
  519. $.mobile.changePage( "#eventsPage", { transition: "slide", reverse: true, changeHash: false });
  520. }
  521. }
  522. else if($.mobile.activePage.is('#infoGuestPage')){
  523. $.mobile.changePage( "#guestsPage", { transition: "slide", reverse: true, changeHash: false });
  524. }
  525. else if($.mobile.activePage.is('#prestationsPageLocal')){
  526. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  527. }
  528. else if($.mobile.activePage.is('#guestsPageLocal')){
  529. if(guestsList.prestations){
  530. $.mobile.changePage( "#prestationsPageLocal", { transition: "slide", reverse: true, changeHash: false });
  531. }
  532. else {
  533. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  534. }
  535. }
  536. else if($.mobile.activePage.is('#infoGuestPageLocal')){
  537. $.mobile.changePage( "#guestsPageLocal", { transition: "slide", reverse: true, changeHash: false });
  538. }
  539. else if($.mobile.activePage.is('#scanPage')){
  540. if(guestsList.dialog == 9){
  541. $.mobile.changePage("#guestsPage", { transition: "fade", changeHash: false });
  542. }
  543. else if(guestsList.dialog == 10){
  544. $.mobile.changePage("#guestsPageLocal", { transition: "fade", changeHash: false });
  545. }
  546. guestsList.dialog = 0;
  547. }
  548.  
  549. $.unblockUI();
  550. }, false);
  551.  
  552. /************************************************/
  553. /****** #region Fonctions utilitaires *******/
  554. /**********************************************/
  555. function checkTokenValidity(){
  556. if(window.localStorage.getItem("tokenDate") != null && window.localStorage.getItem("token") != null){
  557. var tokenDate = new Date(window.localStorage.getItem("tokenDate"));
  558. var today = new Date();
  559.  
  560. if((today-tokenDate) < 7200000) // inférieur à 2h
  561. {
  562. ApiToken = window.localStorage.getItem("token");
  563. return true;
  564. }
  565. }
  566. requestConnection = false;
  567. return false;
  568. }
  569.  
  570. function offlineMode(){
  571. importedBase = window.localStorage.getItem("importedBase");
  572. if(importedBase != "true"){
  573. //Si aucune base importé alors on redirige directement vers la page de connexion
  574. navigator.notification.alert(
  575. "Aucune liste d'invit\351s n'a \351t\351 t\351l\351charg\351e au pr\351alable",
  576. alertDismissed,
  577. "Notification",
  578. "Ok"
  579. );
  580. }
  581. else{
  582. ajax.blockui();
  583. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  584.  
  585. prestations = window.localStorage.getItem("prestations");
  586. if(prestations == "true"){
  587. db.transaction(function(tx) {
  588. $('#prestationsLocalList').empty();
  589. tx.executeSql("select count(*) as cnt from A09_PARTICIPANT;", [], function(tx, res2) {
  590. var text0 = ' invit\351';
  591. if(res2.rows.item(0).cnt > 0){
  592. text0 = ' invit\351s';
  593. }
  594. $('#prestationsLocalList').append('<li><a href="" data-id="0" style="color: green;"><i class="fa fa-home fa-3x homePrestation"></i><h3>Accueil Principal</h3><p>' + res2.rows.item(0).cnt + text0 +'</p></a></li>');
  595. });
  596.  
  597. tx.executeSql("select * from A10_PRESTATION;", [], function(tx, res) {
  598. for (i = 0; i < res.rows.length; i++) {
  599. var nb_inscrits = parseInt(res.rows.item(i).PLACE_DISPO) - parseInt(res.rows.item(i).PLACE_RESTANTE);
  600. var text1 = ' inscrit sur ';
  601. var text2 = ' place disponible';
  602.  
  603. if(isNaN(nb_inscrits)){
  604. nb_inscrits = "";
  605. text1 = "";
  606. text2 = "";
  607. res.rows.item(i).PLACE_DISPO = "";
  608. }else{
  609. if(nb_inscrits > 0){
  610. text1 = ' inscrits sur ';
  611. }
  612. if(parseInt(res.rows.item(i).PLACE_DISPO) > 0){
  613. text2 = ' places disponibles';
  614. }
  615. }
  616.  
  617. $('#prestationsLocalList').append('<li><a href="" data-id="' +
  618. res.rows.item(i).ID + '"><i class="fa fa-ticket fa-3x"></i><h3>' + res.rows.item(i).LIBELLE + '</h3><p>' + nb_inscrits + text1 + res.rows.item(i).PLACE_DISPO + text2 + '</p></a></li>');
  619. }
  620.  
  621. setTimeout(function(){
  622. $.mobile.changePage( "#prestationsPageLocal", { transition: "slide", changeHash: false });
  623. $('#prestationsLocalList').listview('refresh');
  624.  
  625. $.unblockUI();
  626. }, 500);
  627. });
  628. });
  629.  
  630. }else{
  631. parseGuestsListLocal("false");
  632. }
  633. }
  634. }
  635.  
  636. function openBarcodeScan(viewInfo, callback) {
  637. var scanner = cordova.plugins.barcodeScanner;
  638. scanner.scan(function (result) {
  639. if (!result.cancelled) {
  640. callback(result);
  641. }
  642. }, function (error) {
  643. navigator.notification.alert(
  644. "Erreur lors de l'ouverture du plugin barcodeScanner : " + error,
  645. alertDismissed,
  646. "Notification",
  647. "Ok"
  648. );
  649. });
  650. }
  651.  
  652.  
  653. /************************************************/
  654. /****** #region MainPage ********/
  655. /**********************************************/
  656.  
  657. $(document).on('vclick', '#btnNoWifi', function(){
  658. offlineMode();
  659. });
  660.  
  661. $(document).on('pagebeforeshow', '#mainPage', function(){
  662. $('#authenticationForm').on('submit', function(event) {
  663. event.preventDefault();
  664. setTimeout(function() {
  665. $('#btnConnexion').trigger( 'click' );
  666. }, 50);
  667. return false;
  668. });
  669.  
  670. rememberMe = window.localStorage.getItem("rememberMe");
  671. if(rememberMe == "true"){
  672. $('#checkboxRememberMe').prop('checked', true).checkboxradio('refresh');
  673. document.getElementById("username").value = window.localStorage.getItem("username");
  674. document.getElementById("password").value = window.localStorage.getItem("password");
  675. }
  676.  
  677. $('#checkboxRememberMe').change(function() {
  678. if($(this).is(":checked")) {
  679. window.localStorage.setItem("rememberMe", "true");
  680. }else{
  681. window.localStorage.setItem("rememberMe", "false");
  682. }
  683. });
  684. });
  685.  
  686. $( document ).on('vclick', '#btnConnexion', function(e){
  687. e.preventDefault();
  688. if(e.handled !== true && requestConnection == false) // This will prevent event triggering more then once
  689. {
  690. requestConnection = true;
  691. e.handled = true;
  692. var form = $("#authenticationForm");
  693. var username = $("#username", form).val();
  694. var password = $("#password", form).val();
  695.  
  696. //Stockage local si on a coché se souvenir de moi
  697. if(window.localStorage.getItem("rememberMe") == "true"){
  698. var username = document.getElementById("username").value;
  699. var password = document.getElementById("password").value;
  700. window.localStorage.setItem("username", username);
  701. window.localStorage.setItem("password", password);
  702. }
  703.  
  704. var currentDatabase = document.getElementById("database").value
  705. window.localStorage.setItem("database", currentDatabase);
  706.  
  707. switch(currentDatabase) {
  708. case "#000":
  709. url = "http://recette.apiagora.com/api/";
  710. break;
  711. case "#001":
  712. url = "http://bnp.apiagora.com/api/";
  713. break;
  714. case "#002":
  715. url = "https://agora.orange.com/api/";
  716. break;
  717. case "#999":
  718. url = "http://localhost:60814/api/";
  719. break;
  720. default:
  721. url = "http://recette.apiagora.com/api/";
  722. }
  723.  
  724. if(username != "" && password != "") {
  725. // Blocage de l'interface
  726. ajax.blockui();
  727. setTimeout(function () {
  728. $.ajax({
  729. type: 'POST',
  730. url: url + 'authentication/authenticate',
  731. crossDomain: true,
  732. data: {login: username, password : password},
  733. dataType: 'json',
  734. async: false,
  735. success: function (result) {
  736. $.unblockUI();
  737. requestConnection = false;
  738. //Récupération du token d'authentification
  739. ApiToken = result;
  740.  
  741. window.localStorage.setItem("token", ApiToken);
  742. window.localStorage.setItem("tokenDate", new Date().toString());
  743.  
  744. $.mobile.changePage( "#eventsPage", { transition: "slide", changeHash: false });
  745. },
  746. error: function (request,error) {
  747. $.unblockUI();
  748. if(request.status == 401){
  749. navigator.notification.alert(
  750. "Combinaison identifiants / mot de passe invalide",
  751. alertDismissed,
  752. "Notification",
  753. "Ok"
  754. );
  755. }else if(request.status == 404){
  756. navigator.notification.alert(
  757. "Impossible d'accéder au serveur distant",
  758. alertDismissed,
  759. "Notification",
  760. "Ok"
  761. );
  762. }else{
  763. navigator.notification.alert(
  764. "Erreur serveur distant code: " + request.status,
  765. alertDismissed,
  766. "Notification",
  767. "Ok"
  768. );
  769. }
  770. requestConnection = false;
  771. }
  772. });
  773. }, 200);
  774. }
  775. else {
  776. //if the email and password is empty
  777. navigator.notification.alert(
  778. "Veuillez renseigner les champs d'authentification",
  779. alertDismissed,
  780. "Notification",
  781. "Ok"
  782. );
  783. }
  784. }
  785. });
  786.  
  787. /***************************************/
  788. /* #region eventsPage *****/
  789. /***************************************/
  790. $(document).on('pagebeforeshow', '#eventsPage', function(){
  791. importedBase = window.localStorage.getItem("importedBase");
  792. if(importedBase == "true"){
  793. document.getElementById("backtoLoginButton").style.display = "inline";
  794. }
  795. ajax.getEventsList();
  796. });
  797.  
  798. $(document).on('vclick', '#backtoLoginButton', function(){
  799. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  800. });
  801.  
  802. $(document).on('pagebeforeshow', '#prestationsPage', function(){
  803. $('#prestationsList').listview('refresh');
  804. ajax.getEventsList();
  805. });
  806.  
  807. $(document).on('vclick', '#prestationsPageFooterBtnActualiser', function(){
  808. loadEventList();
  809. });
  810.  
  811. $(document).on('vclick', '#eventsList li a', function(){
  812. var id = $(this).attr('data-id');
  813. guestsList.eventId = id;
  814. guestsList.eventName = this.getElementsByTagName("h3")[0].innerHTML;
  815. guestsList.prestationId = null;
  816. loadEventList();
  817. });
  818.  
  819. $(document).on('vclick', '#moreOptionEventsPage', function(){
  820. setTimeout(function(){
  821. document.getElementById("moreOptionOverlayDivEventsPage").style.display="block";
  822. }, 50);
  823. document.getElementById("moreOptionDivEventsPage").style.display="block";
  824. });
  825.  
  826. $(document).on('vclick', '#moreOptionOverlayDivEventsPage', function(){
  827. document.getElementById("moreOptionDivEventsPage").style.display="none";
  828. setTimeout(function(){
  829. document.getElementById("moreOptionOverlayDivEventsPage").style.display="none";
  830. }, 50);
  831. });
  832.  
  833. $(document).on('vclick', '#eventsPageBtnAccueil', function(){
  834. document.getElementById("moreOptionDivEventsPage").style.display="none";
  835. setTimeout(function(){
  836. document.getElementById("moreOptionOverlayDivEventsPage").style.display="none";
  837. }, 50);
  838.  
  839. $.mobile.changePage( "#eventsPage", { transition: "slide", reverse: true, changeHash: false });
  840. });
  841.  
  842. $(document).on('vclick', '#disconnect', function(){
  843. requestConnection = false;
  844. window.localStorage.removeItem("token");
  845. window.localStorage.removeItem("tokenDate");
  846.  
  847. document.getElementById("moreOptionDivEventsPage").style.display="none";
  848. setTimeout(function(){
  849. document.getElementById("moreOptionOverlayDivEventsPage").style.display="none";
  850. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  851. }, 50);
  852. });
  853.  
  854. function loadEventList(){
  855. // CHECK IF THERE ARE PRESTATIONS
  856. ajax.blockui();
  857. setTimeout(function(){
  858. $.ajax({
  859. type: 'GET',
  860. url: url + 'methods/MobileApp/GetPrestations/' + guestsList.eventId,
  861. crossDomain: true,
  862. headers: {'AgoraEvent-Token': ApiToken},
  863. success: function (result) {
  864. if(result.length > 0)
  865. {
  866. guestsList.prestations = true;
  867. ajax.parsePrestations(result);
  868.  
  869. document.getElementById("PrestationsPageTitle").innerHTML = guestsList.eventName;
  870. $.mobile.changePage( "#prestationsPage", { transition: "slide", changeHash: false });
  871. }
  872. else
  873. {
  874. guestsList.prestations = false;
  875. ajax.getGuestslist(false);
  876. }
  877. },
  878. error: function (request,error) {
  879. $.unblockUI();
  880. if(request.status == 401){
  881. // Unauthorized
  882. navigator.notification.alert(
  883. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  884. alertDismissed,
  885. "Notification",
  886. "Ok"
  887. );
  888.  
  889. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  890. }
  891. navigator.notification.alert(
  892. "Erreur lors de la r\351cup\351ration des prestations en ligne",
  893. alertDismissed,
  894. "Notification",
  895. "Ok"
  896. );
  897. }
  898. });
  899. }, 50);
  900. }
  901.  
  902. /***************************************/
  903. /****** #region prestationsPage ***/
  904. /***************************************/
  905. $(document).on('vclick', '#backBtnPrestationsPage', function(){
  906. $.mobile.changePage( "#eventsPage", { transition: "slide", reverse: true, changeHash: false });
  907. });
  908.  
  909.  
  910. $(document).on('vclick', '#prestationsList li a', function(){
  911. guestsList.prestationName = $(this)[0].querySelector("h3").textContent;
  912. guestsList.prestationId = $(this).attr('data-id');
  913. if(guestsList.prestationId == 0 || guestsList.prestationId == null){
  914. ajax.getGuestslist(false);
  915. guestsList.prestations = false;
  916. }else{
  917. ajax.getGuestslist(true);
  918. guestsList.prestations = true;
  919. }
  920. });
  921.  
  922. $(document).on('vclick', '#moreOptionPrestationPage', function(){
  923. guestsList.dialog = 4;
  924. $.mobile.silentScroll(0);
  925. setTimeout(function(){
  926. document.getElementById("moreOptionOverlayDivPrestationPage").style.display="block";
  927. }, 50);
  928. document.getElementById("moreOptionDivPrestationPage").style.display="block";
  929. });
  930.  
  931. $(document).on('vclick', '#moreOptionOverlayDivPrestationPage', function(){
  932. guestsList.dialog = 0;
  933. document.getElementById("moreOptionDivPrestationPage").style.display="none";
  934. setTimeout(function(){
  935. document.getElementById("moreOptionOverlayDivPrestationPage").style.display="none";
  936. }, 50);
  937. });
  938.  
  939. $(document).on('vclick', '#prestationsPageFooterBtnAccueil', function(){
  940. document.getElementById("moreOptionDivPrestationPage").style.display="none";
  941. setTimeout(function(){
  942. document.getElementById("moreOptionOverlayDivPrestationPage").style.display="none";
  943. }, 50);
  944.  
  945. importedBase = window.localStorage.getItem("importedBase");
  946. if(importedBase == "true"){
  947. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  948. }
  949. else{
  950. $.mobile.changePage( "#eventsPage", { transition: "slide", reverse: true, changeHash: false });
  951. }
  952. });
  953.  
  954. $(document).on('vclick', '#prestationsPageFooterBtnImport', function(){
  955. document.getElementById("moreOptionDivPrestationPage").style.display="none";
  956. setTimeout(function(){
  957. document.getElementById("moreOptionOverlayDivPrestationPage").style.display="none";
  958. }, 50);
  959.  
  960. importBase(true);
  961. });
  962.  
  963. $(document).on('vclick', '#prestationsPageFooterBtnHorsLigne', function(){
  964. document.getElementById("moreOptionDivPrestationPage").style.display="none";
  965. setTimeout(function(){
  966. document.getElementById("moreOptionOverlayDivPrestationPage").style.display="none";
  967. }, 50);
  968.  
  969. offlineMode();
  970. });
  971.  
  972. /***************************************/
  973. /****** #region guestsPage ****/
  974. /***************************************/
  975. function emptyGuestData(){
  976. $('#guestData').empty();
  977. $('#guestDataPrestationsList').empty();
  978.  
  979. document.getElementById("infoGuestPageName").innerHTML = "Nom Pr\351nom";
  980. document.getElementById("infoGuestPageCategory").innerHTML = "Cat\351gorie";
  981.  
  982. $('#guestData').append(
  983. '<strong>Soci\351t\351: </strong><br/>' +
  984. '<strong>Email: </strong><br/>' +
  985. '<strong>T\351l\351phone: </strong><br/>'
  986. );
  987. }
  988.  
  989. $(document).on('pagebeforeshow', '#guestsPage', function(){
  990. emptyGuestData();
  991. $('#guestsList').listview('refresh');
  992. });
  993.  
  994. $(document).on('vclick', '#guestsPageBackButton', function(){
  995. if(guestsList.prestations || (!guestsList.prestations && guestsList.prestationId == 0)){
  996. $.mobile.changePage( "#prestationsPage", { transition: "slide", reverse: true, changeHash: false });
  997. }
  998. else
  999. {
  1000. $.mobile.changePage( "#eventsPage", { transition: "slide", reverse: true, changeHash: false });
  1001. }
  1002. });
  1003.  
  1004. $(document).on('vclick', '#moreOptionGuestsPage', function(){
  1005. $.mobile.silentScroll(0);
  1006. setTimeout(function(){
  1007. document.getElementById("moreOptionOverlayDivGuestsPage").style.display="block";
  1008. }, 50);
  1009. document.getElementById("moreOptionDivGuestsPage").style.display="block";
  1010. });
  1011.  
  1012. $(document).on('vclick', '#moreOptionOverlayDivGuestsPage', function(){
  1013. document.getElementById("moreOptionDivGuestsPage").style.display="none";
  1014. setTimeout(function(){
  1015. document.getElementById("moreOptionOverlayDivGuestsPage").style.display="none";
  1016. }, 50);
  1017. });
  1018.  
  1019. $(document).on('vclick', '#guestsList li a', function(){
  1020. ajax.blockui();
  1021. guestsList.id = $(this).attr('data-id');
  1022.  
  1023. setTimeout(function(){
  1024. if(guestsList.tablette){
  1025. loadParticipantPresenceInfos();
  1026. }else{
  1027. $.mobile.changePage( "#infoGuestPage", { transition: "slide", changeHash: false });
  1028. }
  1029. }, 150);
  1030. });
  1031.  
  1032. $(document).on('vclick', '#infoGuestPageEbillet', function(){
  1033. var fileObject;
  1034. var path;
  1035.  
  1036. window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) {
  1037. dir.getFile("ebillet.pdf", {create: true, exclusive: false},
  1038. gotFileEntry, fail);
  1039. });
  1040.  
  1041. function gotFileEntry(fileEntry) {
  1042. fileObject = fileEntry;
  1043. saveFileContent();
  1044. }
  1045.  
  1046. function saveFileContent() {
  1047. fileObject.createWriter(success, fail);
  1048. }
  1049.  
  1050. function success(writer) {
  1051. ajax.blockui();
  1052.  
  1053. var fullURL = "";
  1054.  
  1055. if(guestsList.prestations){
  1056. fullURL = 'methods/MobileApp/GetEbillet?id=' + guestsList.id + '&Prestation=true';
  1057. }else
  1058. {
  1059. fullURL = 'methods/MobileApp/GetEbillet?id=' + guestsList.id;
  1060. }
  1061.  
  1062. $.ajax({
  1063. type: 'GET',
  1064. url: url + fullURL,
  1065. crossDomain: true,
  1066. async: false,
  1067. dataType: 'binary',
  1068. headers: {'AgoraEvent-Token': ApiToken},
  1069. success: function (result) {
  1070. //Saving file
  1071. writer.write(result);
  1072. alert("path: " + fileObject.nativeURL);
  1073. //Opening file
  1074. cordova.plugins.fileOpener2.open(
  1075. fileObject.nativeURL,
  1076. 'application/pdf',
  1077. {
  1078. error : function(e) {
  1079. alert('Error status: ' + e.status + ' - Error message: ' + e.message);
  1080. },
  1081. success : function () {
  1082. }
  1083. }
  1084. );
  1085.  
  1086. $.unblockUI();
  1087. },
  1088. error: function (request, error) {
  1089. $.unblockUI();
  1090. navigator.notification.alert(
  1091. "Erreur lors du t\351l\351chargement du E-Billet",
  1092. alertDismissed,
  1093. "Notification",
  1094. "Ok"
  1095. );
  1096. }
  1097. });
  1098. };
  1099.  
  1100. function fail(error){
  1101. alert(error.target);
  1102. }
  1103. });
  1104.  
  1105. /********** #subregion GUEST LIST OPTION PANEL *********/
  1106. function scanQrCode(){
  1107. guestsList.dialog = 9;
  1108. openBarcodeScan("scan", function (barcode) {
  1109. var id = getParameterByName(barcode.text, "IdA09");
  1110. guestsList.id = id;
  1111.  
  1112. if(id != ""){
  1113. ajax.blockui();
  1114.  
  1115. setTimeout(function(){
  1116. var fullURL;
  1117. if(guestsList.prestations){
  1118. fullURL = 'methods/MobileApp/SetPresenceInscription?id=' + id + '&ebillet=true&idPrestation=' + guestsList.prestationId;
  1119. }
  1120. else{
  1121. fullURL = 'methods/MobileApp/SetPresence/' + id;
  1122. }
  1123.  
  1124. $.ajax({
  1125. type: 'POST',
  1126. url: url + fullURL,
  1127. crossDomain: true,
  1128. async: false,
  1129. headers: {'AgoraEvent-Token': ApiToken},
  1130. success: function (result) {
  1131. guestsList.id = result[0];
  1132.  
  1133. // Mise à jour du nombre de présents
  1134. guestsList.nbPresents ++;
  1135.  
  1136. var text0 = " pr\351sent";
  1137. if(guestsList.nbPresents > 1){
  1138. text0 = " pr\351sents";
  1139. }
  1140. document.getElementById("guestsPageNbPresents").innerHTML = guestsList.nbPresents + " pr\351sents";
  1141.  
  1142. document.getElementById("scanResultText").innerHTML = "ok";
  1143. document.getElementById("scanPage").style.backgroundColor = "rgb(133, 229, 55)";
  1144. document.getElementById("scanPageLinkGuest").style.display = "block";
  1145. document.getElementById("scanPageTitle1").innerHTML = "Billet valide";
  1146.  
  1147. // FILL PARTICIPANT INFOS
  1148. document.getElementById("scanPageTitle2").innerHTML = result[1] + " " + result[2];
  1149.  
  1150. document.getElementById("scanPageMessage").innerHTML = "Pr\351sence valid\351e";
  1151. document.getElementById("scanPageLinkBack").onclick = function(){
  1152. $.mobile.changePage("#guestsPage", { transition: "fade", changeHash: false });
  1153. };
  1154. document.getElementById("scanPageContent").onclick = scanAgain;
  1155.  
  1156. document.getElementById("scanPageLinkGuest").onclick = moreInfoScan;
  1157.  
  1158. setTimeout(function(){
  1159. $.mobile.changePage( "#scanPage", { transition: "fade", changeHash: false });
  1160. $.unblockUI();
  1161. }, 50);
  1162. navigator.notification.vibrate(500);
  1163. },
  1164. error: function (request, error) {
  1165. $.unblockUI();
  1166. navigator.notification.vibrate(500);
  1167. if(request.status == 404 || request.status == 401){
  1168. document.getElementById("scanResultText").innerHTML = "X";
  1169. document.getElementById("scanPage").style.backgroundColor = "rgb(254,0,0)";
  1170. document.getElementById("scanPageLinkGuest").style.display = "none";
  1171.  
  1172. document.getElementById("scanPageTitle1").innerHTML = "Billet non valide";
  1173. document.getElementById("scanPageTitle2").innerHTML = "Erreur:";
  1174. document.getElementById("scanPageMessage").innerHTML = "Impossible d'identifier le num\351ro du billet, veuillez v\351rifier les informations de celui-ci";
  1175.  
  1176. document.getElementById("scanPageContent").onclick = scanAgain;
  1177. document.getElementById("scanPageLinkBack").onclick = function(){
  1178. $.mobile.changePage( "#guestsPage", { transition: "fade", changeHash: false });
  1179. };
  1180.  
  1181. setTimeout(function(){
  1182. $.mobile.changePage( "#scanPage", { transition: "fade", changeHash: false });
  1183. }, 50);
  1184. }
  1185. else if(request.status == 403){
  1186. document.getElementById("scanResultText").innerHTML = "X";
  1187. document.getElementById("scanPage").style.backgroundColor = "rgb(236,101,0)";
  1188. document.getElementById("scanPageLinkGuest").style.display = "block";
  1189.  
  1190. document.getElementById("scanPageTitle1").innerHTML = "Billet d\351j\340 enregistr\351";
  1191. document.getElementById("scanPageTitle2").innerHTML = "Alerte:";
  1192. document.getElementById("scanPageMessage").innerHTML = "Le num\351ro du billet a d\351j\340 \351t\351 scann\351 auparavant";
  1193.  
  1194. document.getElementById("scanPageContent").onclick = scanAgain;
  1195. document.getElementById("scanPageLinkBack").onclick = function(){
  1196. $.mobile.changePage( "#guestsPage", { transition: "fade", changeHash: false });
  1197. };
  1198.  
  1199. setTimeout(function(){
  1200. $.mobile.changePage( "#scanPage", { transition: "fade", changeHash: false });
  1201. }, 50);
  1202. }
  1203. else{
  1204. navigator.notification.alert(
  1205. "Erreur lors de la validation d'un invit\351 par QRCode",
  1206. alertDismissed,
  1207. "Notification",
  1208. "Ok"
  1209. );
  1210. }
  1211. }
  1212. });
  1213. }, 200);
  1214. }
  1215. else{
  1216. $.unblockUI();
  1217. document.getElementById("scanResultText").innerHTML = "X";
  1218. document.getElementById("scanPage").style.backgroundColor = "rgb(254,0,0)";
  1219. document.getElementById("scanPageLinkGuest").style.display = "none";
  1220.  
  1221. document.getElementById("scanPageTitle1").innerHTML = "Billet non valide";
  1222. document.getElementById("scanPageTitle2").innerHTML = "Erreur:";
  1223. document.getElementById("scanPageMessage").innerHTML = "Impossible d'identifier le num\351ro du billet, veuillez v\351rifier les informations de celui-ci";
  1224.  
  1225. document.getElementById("scanPageContent").onclick = scanAgain;
  1226. document.getElementById("scanPageLinkBack").onclick = function(){
  1227. $.mobile.changePage( "#guestsPage", { transition: "fade", changeHash: false });
  1228. };
  1229.  
  1230. setTimeout(function(){
  1231. $.mobile.changePage( "#scanPage", { transition: "fade", changeHash: false });
  1232. }, 50);
  1233. }
  1234. });
  1235. }
  1236.  
  1237. $(document).on('vclick', '#guestsListFooterBtnQrcode', function(){
  1238. scanQrCode();
  1239. });
  1240.  
  1241. function moreInfoScan(){
  1242. if(guestsList.tablette){
  1243. $.mobile.changePage("#guestsPage", { transition: "fade", changeHash: false });
  1244. }
  1245. else{
  1246. $.mobile.changePage( "#infoGuestPage", { transition: "slide", changeHash: false });
  1247. }
  1248. }
  1249.  
  1250. function scanAgain(){
  1251. setTimeout(function(){
  1252. scanQrCode();
  1253. }, 50);
  1254. }
  1255.  
  1256. $(document).on('vclick', '#guestsListFooterBtnAccueil', function(){
  1257. document.getElementById("moreOptionDivGuestsPage").style.display="none";
  1258. setTimeout(function(){
  1259. document.getElementById("moreOptionOverlayDivGuestsPage").style.display="none";
  1260. }, 50);
  1261.  
  1262. importedBase = window.localStorage.getItem("importedBase");
  1263. if(importedBase == "true"){
  1264. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1265. }
  1266. else{
  1267. $.mobile.changePage( "#eventsPage", { transition: "slide", reverse: true, changeHash: false });
  1268. }
  1269. });
  1270.  
  1271. $(document).on('vclick', '#guestsListFooterBtnImport', function(){
  1272. document.getElementById("moreOptionDivGuestsPage").style.display="none";
  1273. setTimeout(function(){
  1274. document.getElementById("moreOptionOverlayDivGuestsPage").style.display="none";
  1275. }, 50);
  1276.  
  1277. if(guestsList.prestations || (!guestsList.prestations && guestsList.prestationId == 0)){
  1278. importBase(true);
  1279. }
  1280. else{
  1281. importBase(false);
  1282. }
  1283. });
  1284.  
  1285. $(document).on('vclick', '#guestsListFooterBtnActualiser', function(){
  1286. if(guestsList.prestationId == 0 || guestsList.prestationId == null){
  1287. ajax.getGuestslist(false);
  1288. guestsList.prestations = false;
  1289. }else{
  1290. ajax.getGuestslist(true);
  1291. guestsList.prestations = true;
  1292. }
  1293. });
  1294.  
  1295.  
  1296. $(document).on('vclick', '#guestsListFooterBtnSearch', function(){
  1297. $.mobile.silentScroll(0);
  1298. setTimeout(function(){ dialogSearch.show(); }, 50);
  1299. guestsList.dialog = 1;
  1300.  
  1301.  
  1302. $('#searchForm').on('submit', function(event) {
  1303. event.preventDefault();
  1304. $('#searchField').blur();
  1305.  
  1306. setTimeout(function() {
  1307. $('#btnSearch').trigger( 'click' );
  1308. }, 50);
  1309. return false;
  1310. });
  1311. });
  1312.  
  1313. //#search
  1314. $(document).on('vclick', '#btnSearch', function(){
  1315. var activePage = $.mobile.pageContainer.pagecontainer("getActivePage");
  1316. var searchText = document.getElementById("searchField").value;
  1317.  
  1318. if(searchText != ""){
  1319. if (activePage[0].id == "guestsPage") {
  1320. var id = guestsList.eventId;
  1321. setTimeout(function(){ dialogSearch.hide(); }, 50);
  1322. ajax.blockui();
  1323. setTimeout(function(){
  1324. if(guestsList.prestations && guestsList.prestationId != 0){
  1325. var fullURL = 'methods/MobileApp/GetParticipants?id=' + guestsList.prestationId + '&Prestation=true&Query=' + searchText;
  1326. }else{
  1327. var fullURL = 'methods/MobileApp/GetParticipants?id=' + id + '&Query=' + searchText;
  1328. }
  1329.  
  1330. $.ajax({
  1331. type: 'GET',
  1332. url: url + fullURL,
  1333. crossDomain: true,
  1334. async: false,
  1335. headers: {'AgoraEvent-Token': ApiToken},
  1336. success: function (result) {
  1337. guestsList.listSearch = result;
  1338. ajax.parseGuests(result);
  1339.  
  1340. var text0 = " r\351sultat";
  1341. if(guestsList.listSearch.length > 0){
  1342. text0 = " r\351sultats";
  1343. }
  1344. document.getElementById("guestsPageNbResults").innerHTML = guestsList.listSearch.length + text0;
  1345.  
  1346. $('#guestsList').listview('refresh');
  1347.  
  1348. $('#guestsPageSearchFilter').fadeIn("slow");
  1349.  
  1350. $('#deleteBtnSearchFilter')[0].innerHTML = searchText;
  1351. guestsList.dialog = 6;
  1352. $.unblockUI();
  1353. },
  1354. error: function (request, error) {
  1355. $.unblockUI();
  1356. if(request.status == 401){
  1357. // Unauthorized
  1358. navigator.notification.alert(
  1359. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  1360. alertDismissed,
  1361. "Notification",
  1362. "Ok"
  1363. );
  1364.  
  1365. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1366. }
  1367. navigator.notification.alert(
  1368. "Erreur lors de la recherche d'un invit\351",
  1369. alertDismissed,
  1370. "Notification",
  1371. "Ok"
  1372. );
  1373. }
  1374. });
  1375. }, 500);
  1376. }else if(activePage[0].id == "guestsPageLocal"){
  1377.  
  1378. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  1379. setTimeout(function(){ dialogSearch.hide(); }, 50);
  1380. guestsList.dialog = 0;
  1381.  
  1382. setTimeout(function(){
  1383. db.transaction(function(tx) {
  1384. if(prestations == "true" && guestsList.prestationId != 0){
  1385. tx.executeSql("select a.*, b.ID_STATUT_A39 from A09_PARTICIPANT as a left join A07_INSCRIPTION as b on a.ID=b.ID_PARTICIPANT where PRESTATION_A10=? and (LastName like ? or FirstName like ? ) limit 100;", [guestsList.prestationId, "%" + searchText + "%", "%" + searchText + "%"], function(tx, res) {
  1386.  
  1387. $('#guestsListLocal').empty();
  1388. for (i = 0; i < res.rows.length; i++) {
  1389. $('#guestsListLocal').append('<li><a href="" data-id="' +
  1390. res.rows.item(i).ID + '"><h3>' + res.rows.item(i).LastName + '</h3><p>' + res.rows.item(i).FirstName + '</p></a></li>');
  1391. }
  1392. document.getElementById("guestsPageLocalNbResults").innerHTML = res.rows.length + " r\351sultat(s)";
  1393. $("#guestsListLocal").listview("refresh");
  1394.  
  1395. document.getElementById("deleteBtnLocalSearchFilter").innerHTML = searchText;
  1396. $('#guestsPageLocalSearchFilter').fadeIn("slow");
  1397. $.unblockUI();
  1398. });
  1399. }
  1400. else{
  1401. var query = "select * from A09_PARTICIPANT where (LastName like ? or FirstName like ?) limit 100;";
  1402. tx.executeSql(query, ["%" + searchText + "%", "%" + searchText + "%"], function(tx, res) {
  1403. $('#guestsListLocal').empty();
  1404. for (i = 0; i < res.rows.length; i++) {
  1405. $('#guestsListLocal').append('<li><a href="" data-id="' +
  1406. res.rows.item(i).ID + '"><h3>' + res.rows.item(i).LastName + '</h3><p>' + res.rows.item(i).FirstName + '</p></a></li>');
  1407. }
  1408. document.getElementById("guestsPageLocalNbResults").innerHTML = res.rows.length + " r\351sultat(s)";
  1409. $("#guestsListLocal").listview("refresh");
  1410.  
  1411. document.getElementById("deleteBtnLocalSearchFilter").innerHTML = searchText;
  1412. $('#guestsPageLocalSearchFilter').fadeIn("slow");
  1413. $.unblockUI();
  1414. });
  1415. }
  1416. });
  1417. }, 500);
  1418. }
  1419. }else{
  1420. navigator.notification.alert(
  1421. "Veuillez renseigner le champ de recherche!",
  1422. alertDismissed,
  1423. "Notification",
  1424. "Ok"
  1425. );
  1426. }
  1427. });
  1428.  
  1429. $(document).on('vclick', '#deleteBtnSearchFilter', function() {
  1430. $('#guestsPageSearchFilter').fadeOut("slow");
  1431. guestsList.dialog = 0;
  1432. setTimeout(function(){
  1433. $("#guestsList").empty();
  1434. ajax.parseGuests(guestsList.list);
  1435. $('#guestsList').listview('refresh');
  1436. document.getElementById("guestsPageNbResults").innerHTML = guestsList.nbParticipants + " r\351sultat(s)";
  1437. }, 200);
  1438. });
  1439.  
  1440. //Import de la base en hors ligne
  1441. $(document).on('vclick', '#guestsListFooterBtnHorsLigne', function(){
  1442. document.getElementById("moreOptionDivGuestsPage").style.display="none";
  1443. setTimeout(function(){
  1444. document.getElementById("moreOptionOverlayDivGuestsPage").style.display="none";
  1445. }, 50);
  1446.  
  1447. /*
  1448. var askImport = confirm("Voulez-vous importer la liste d'invit\351s avant de passer en mode hors ligne?");
  1449.  
  1450. if(askImport){
  1451. importBase(false);
  1452. }
  1453. */
  1454. offlineMode();
  1455. });
  1456.  
  1457. // #importBase
  1458. function importBase(prestations){
  1459. ajax.blockui();
  1460. setTimeout(function(){
  1461. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  1462.  
  1463. db.transaction(function(tx) {
  1464. tx.executeSql('DROP TABLE IF EXISTS A10_PRESTATION');
  1465. tx.executeSql('DROP TABLE IF EXISTS A07_INSCRIPTION');
  1466. tx.executeSql('DROP TABLE IF EXISTS CHANGE_LIST_INSCRIPTION');
  1467.  
  1468. if(prestations){
  1469. tx.executeSql('CREATE TABLE IF NOT EXISTS A10_PRESTATION (ID integer, LIBELLE text, NUMERO_MANIFESTATION integer, PLACE_DISPO integer, PLACE_RESTANTE integer)');
  1470. tx.executeSql('CREATE TABLE IF NOT EXISTS A07_INSCRIPTION (ID integer, ID_PARTICIPANT integer, PRESTATION_A10 integer, ID_STATUT_A39 integer, DatePresence date, A10_LIBELLE text)');
  1471. tx.executeSql('CREATE TABLE IF NOT EXISTS CHANGE_LIST_INSCRIPTION (ID integer, ID_STATUT_A39 integer)');
  1472. }
  1473.  
  1474. tx.executeSql('DROP TABLE IF EXISTS A09_PARTICIPANT');
  1475. tx.executeSql('CREATE TABLE IF NOT EXISTS A09_PARTICIPANT (ID integer, LastName text, FirstName text, Email text, StatusID integer, Societe text, Tel text, DatePresence date, Category text)');
  1476.  
  1477. tx.executeSql('DROP TABLE IF EXISTS CHANGE_LIST');
  1478. tx.executeSql('CREATE TABLE IF NOT EXISTS CHANGE_LIST (ID integer, StatusID integer)');
  1479.  
  1480. tx.executeSql('DROP TABLE IF EXISTS I42_INV_DATES_PRESENCE');
  1481. tx.executeSql('CREATE TABLE IF NOT EXISTS I42_INV_DATES_PRESENCE (ID_PART_A09 integer, DATE_PRESENCE date, NUMERO_MANIFESTATION integer, STATUTPART_A09 integer)');
  1482.  
  1483. tx.executeSql('DROP TABLE IF EXISTS CHANGE_LIST_I42_INV_DATES_PRESENCE');
  1484. tx.executeSql('CREATE TABLE IF NOT EXISTS CHANGE_LIST_I42_INV_DATES_PRESENCE (ID_PART_A09 integer, DATE_PRESENCE date, NUMERO_MANIFESTATION integer, STATUTPART_A09 integer)');
  1485.  
  1486. var id = guestsList.eventId;
  1487.  
  1488.  
  1489. // RECUPERATION DES PARTICIPANTS
  1490. fullURLCount = 'methods/MobileApp/CountParticipants?id=' + id;
  1491. $.ajax({
  1492. type: 'GET',
  1493. url: url + fullURLCount,
  1494. crossDomain: true,
  1495. async: false,
  1496. headers: {'AgoraEvent-Token': ApiToken},
  1497. success: function (result) {
  1498. guestsList.nbParticipants = result[0];
  1499. var nbTimes = 0;
  1500. nbTimes = result[0] / 50;
  1501. var start = 0;
  1502. var record = 49;
  1503. var i = 0;
  1504. nbTimes = Math.ceil(nbTimes);
  1505.  
  1506. for(i = 0; i < nbTimes; i++){
  1507. var current = i + 1;
  1508.  
  1509. $.ajax({
  1510. type: 'GET',
  1511. url: url + 'methods/MobileApp/GetParticipantsLocal?id=' + id + '&StartRecord=' + start + '&RecordsCount=' + record,
  1512. crossDomain: true,
  1513. async: false,
  1514. headers: {'AgoraEvent-Token': ApiToken},
  1515. success: function (result2) {
  1516. start += 50;
  1517. $.each(result2, function(i, row) {
  1518. tx.executeSql("INSERT INTO A09_PARTICIPANT (ID, LastName, FirstName, Email, StatusID, Societe, Tel, DatePresence, Category) VALUES (?,?,?,?,?,?,?,?,?)", [row.ID, row.LastName, row.FirstName, row.Email, row.StatusID, row.Societe, row.Tel, row.DatePresence, row.Category], function(tx, res) {});
  1519. });
  1520. },
  1521. error: function (request, error) {
  1522. if(request.status == 401){
  1523. // Unauthorized
  1524. navigator.notification.alert(
  1525. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  1526. alertDismissed,
  1527. "Notification",
  1528. "Ok"
  1529. );
  1530.  
  1531. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1532. }
  1533. navigator.notification.alert(
  1534. "Erreur lors de l'import des \351v\350nements hors ligne: nb - " + start + " " +request.statusText,
  1535. alertDismissed,
  1536. "Notification",
  1537. "Ok"
  1538. );
  1539. }
  1540. });
  1541. }
  1542.  
  1543. },
  1544. error: function (request,error) {
  1545. navigator.notification.alert(
  1546. "Erreur lors de la r\351cup\351ration du nombre de r\351sultats",
  1547. alertDismissed,
  1548. "Notification",
  1549. "Ok"
  1550. );
  1551. }
  1552. });
  1553.  
  1554. // RECUPERATION DES PRESENCES
  1555. $.ajax({
  1556. type: 'GET',
  1557. url: url + 'methods/MobileApp/GetInvDatePresence/' + id,
  1558. crossDomain: true,
  1559. async: false,
  1560. headers: {'AgoraEvent-Token': ApiToken},
  1561. success: function (result) {
  1562. $.each(result, function(i, row) {
  1563. tx.executeSql("INSERT INTO I42_INV_DATES_PRESENCE (ID_PART_A09, DATE_PRESENCE, NUMERO_MANIFESTATION, STATUTPART_A09) VALUES (?,?,?,?)", [row.ID_PART_A09, row.DATE_PRESENCE, id, row.STATUS_PART_A09], function(tx, res) {});
  1564. });
  1565. },
  1566. error: function (request,error) {
  1567. if(request.status == 401){
  1568. // Unauthorized
  1569. navigator.notification.alert(
  1570. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  1571. alertDismissed,
  1572. "Notification",
  1573. "Ok"
  1574. );
  1575.  
  1576. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1577. }
  1578. navigator.notification.alert(
  1579. "Erreur lors de la r\351cup\351ration des dates de pr\351sence",
  1580. alertDismissed,
  1581. "Notification",
  1582. "Ok"
  1583. );
  1584. }
  1585. });
  1586.  
  1587. window.localStorage.setItem("prestations", "false");
  1588.  
  1589. //RECUPERATION DES PRESTATIONS
  1590. if(prestations){
  1591. window.localStorage.setItem("prestations", "true");
  1592. $.ajax({
  1593. type: 'GET',
  1594. url: url + 'methods/MobileApp/GetPrestations/' + id,
  1595. crossDomain: true,
  1596. async: false,
  1597. headers: {'AgoraEvent-Token': ApiToken},
  1598. success: function (result) {
  1599. $.each(result, function(i, row) {
  1600. tx.executeSql("INSERT INTO A10_PRESTATION (ID, LIBELLE, NUMERO_MANIFESTATION, PLACE_DISPO, PLACE_RESTANTE) VALUES (?,?,?,?,?)", [row.ID, row.LIBELLE, row.NUMERO_MANIFESTATION, row.PLACE_DISPO, row.PLACE_RESTANTE], function(tx, res) {});
  1601. });
  1602. },
  1603. error: function (request,error) {
  1604. if(request.status == 401){
  1605. // Unauthorized
  1606. navigator.notification.alert(
  1607. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  1608. alertDismissed,
  1609. "Notification",
  1610. "Ok"
  1611. );
  1612.  
  1613. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1614. }
  1615. navigator.notification.alert(
  1616. "Erreur lors de la r\351cup\351ration des prestations hors ligne",
  1617. alertDismissed,
  1618. "Notification",
  1619. "Ok"
  1620. );
  1621. }
  1622. });
  1623.  
  1624. $.ajax({
  1625. type: 'GET',
  1626. url: url + 'methods/MobileApp/GetInscriptions/' + id,
  1627. crossDomain: true,
  1628. async: false,
  1629. headers: {'AgoraEvent-Token': ApiToken},
  1630. success: function (result) {
  1631. $.each(result, function(i, row) {
  1632. tx.executeSql("INSERT INTO A07_INSCRIPTION (ID, ID_PARTICIPANT, PRESTATION_A10, ID_STATUT_A39, DatePresence, A10_LIBELLE) VALUES (?,?,?,?,?,?)", [row.ID, row.ID_PARTICIPANT, row.PRESTATION_A10, row.ID_STATUT_A39, row.DatePresence, row.A10_LIBELLE], function(tx, res) {});
  1633. });
  1634. },
  1635. error: function (request,error) {
  1636. if(request.status == 401){
  1637. // Unauthorized
  1638. navigator.notification.alert(
  1639. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  1640. alertDismissed,
  1641. "Notification",
  1642. "Ok"
  1643. );
  1644.  
  1645. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1646. }
  1647. navigator.notification.alert(
  1648. "Erreur lors de la r\351cup\351ration des prestations",
  1649. alertDismissed,
  1650. "Notification",
  1651. "Ok"
  1652. );
  1653. }
  1654. });
  1655. }
  1656.  
  1657. window.localStorage.setItem("importedBase", "true");
  1658. window.localStorage.setItem("importedBaseName", guestsList.eventName);
  1659. window.localStorage.setItem("eventId", guestsList.eventId);
  1660.  
  1661. setTimeout(function(){
  1662. navigator.notification.alert(
  1663. "Import termin\351!",
  1664. alertDismissed,
  1665. "Notification",
  1666. "Ok"
  1667. );
  1668. $.unblockUI();
  1669. }, 300);
  1670.  
  1671. }, function(e) {
  1672. console.log("ERROR: " + e.message);
  1673. });
  1674. }, 300);
  1675. }
  1676.  
  1677. /****** #subregion infoGuestPage *******/
  1678. $(document).on('pagebeforeshow', '#infoGuestPage', function(){
  1679. loadParticipantPresenceInfos();
  1680. });
  1681.  
  1682. function loadParticipantPresenceInfos(){
  1683. $('#guestData').empty();
  1684. $('#guestDataPrestationsList').empty();
  1685. var monthsInYear= new Array("janvier", "f\351vrier", "mars", "avril", "mai", "juin", "juillet", "ao\373t", "septembre", "octobre", "novembre", "d\351cembre");
  1686.  
  1687. // RECUPERATION DES INFORMATIONS DE L'INVITE
  1688. ajax.blockui();
  1689. var fullUrl = 'methods/MobileApp/GetParticipantInfos?id=' + guestsList.id;
  1690. if(guestsList.prestations){
  1691. var fullUrl = 'methods/MobileApp/GetParticipantInfos?id=' + guestsList.id + '&Prestation=true';
  1692. }
  1693. $.ajax({
  1694. type: 'GET',
  1695. url: url + fullUrl,
  1696. crossDomain: true,
  1697. async: false,
  1698. headers: {'AgoraEvent-Token': ApiToken},
  1699. success: function (result) {
  1700. document.getElementById("infoGuestPageName").innerHTML = result.FirstName + " " + result.LastName;
  1701. document.getElementById("infoGuestPageCategory").innerHTML = result.Category;
  1702.  
  1703. $('#guestData').append(
  1704. '<strong>Soci\351t\351: </strong>' + result.Societe + '<br/>' +
  1705. '<strong>Email: </strong>' + result.Email + '<br/>' +
  1706. '<strong>T\351l\351phone: </strong>' + result.Tel + '<br/>'
  1707. );
  1708. },
  1709. error: function (request,error) {
  1710. if(request.status == 401){
  1711. // Unauthorized
  1712. navigator.notification.alert(
  1713. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  1714. alertDismissed,
  1715. "Notification",
  1716. "Ok"
  1717. );
  1718.  
  1719. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1720. }
  1721. navigator.notification.alert(
  1722. "Erreur lors de la r\351cup\351ration des informations d'un invit\351",
  1723. alertDismissed,
  1724. "Notification",
  1725. "Ok"
  1726. );
  1727. }
  1728. });
  1729.  
  1730. // APPEND LA LISTE DES PRESENCES A L'INVITE
  1731. var fullUrl = 'methods/MobileApp/GetParticipantPresence?id=' + guestsList.id;
  1732. if(guestsList.prestations){
  1733. var fullUrl = 'methods/MobileApp/GetParticipantPresence?id=' + guestsList.id + '&Prestation=true';
  1734. }
  1735. $.ajax({
  1736. type: 'GET',
  1737. url: url + fullUrl,
  1738. crossDomain: true,
  1739. async: false,
  1740. headers: {'AgoraEvent-Token': ApiToken},
  1741. success: function (result) {
  1742. var tmpText = '<li><i class="fa fa-home homePrestation"></i><h3>Accueil Principal</h3>' +
  1743. '<span class="infoGuestStatus status' + result[0].STATUS_PART_A09 + '">[' + guestsList.statusPar[result[0].STATUS_PART_A09] + ']</span>';
  1744. $.each(result, function(i, row) {
  1745. var date = new Date(row.DATE_PRESENCE);
  1746. if(date.getFullYear() < 2000){
  1747. tmpText += '<p>Date de validation:</p>';
  1748. }else{
  1749. tmpText += '<p>Date de validation: ' + date.getDate() + " " + monthsInYear[date.getMonth()] + " " + date.getFullYear() + '</p>';
  1750. }
  1751. });
  1752. tmpText += '</li>';
  1753. $('#guestDataPrestationsList').append(tmpText);
  1754.  
  1755. $('#guestDataPrestationsList').listview("refresh");
  1756. },
  1757. error: function (request,error) {
  1758. if(request.status == 401){
  1759. // Unauthorized
  1760. navigator.notification.alert(
  1761. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  1762. alertDismissed,
  1763. "Notification",
  1764. "Ok"
  1765. );
  1766.  
  1767. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1768. }
  1769. navigator.notification.alert(
  1770. "Erreur lors de la r\351cup\351ration des pr\351sences d'un invit\351",
  1771. alertDismissed,
  1772. "Notification",
  1773. "Ok"
  1774. );
  1775. }
  1776. });
  1777.  
  1778. // APPEND LA LISTE DES PRESTATIONS A L'INVITE
  1779. ajax.blockui();
  1780. fullUrl = 'methods/MobileApp/GetParticipantInscriptions?id=' + guestsList.id;
  1781. if(guestsList.prestations){
  1782. fullUrl = 'methods/MobileApp/GetParticipantInscriptions?id=' + guestsList.id + '&Prestation=true';
  1783. }
  1784. $.ajax({
  1785. type: 'GET',
  1786. url: url + fullUrl,
  1787. crossDomain: true,
  1788. headers: {'AgoraEvent-Token': ApiToken},
  1789. success: function (result) {
  1790. $.each(result, function(i, row2) {
  1791. var date2 = new Date(row2.DatePresence);
  1792. if(date2.getFullYear() < 2000){
  1793. $('#guestDataPrestationsList').append('<li><i class="fa fa-ticket"></i><h3>' + row2.A10_LIBELLE + '</h3>' +
  1794. '<span class="infoGuestStatus status' + row2.ID_STATUT_A39 + '">[' + guestsList.statusPar[row2.ID_STATUT_A39] + ']</span>' +
  1795. '<p>Date de validation: </p></li>');
  1796. }else{
  1797. $('#guestDataPrestationsList').append('<li><i class="fa fa-ticket"></i><h3>' + row2.A10_LIBELLE +
  1798. '</h3><span class="infoGuestStatus status' + row2.ID_STATUT_A39 + '">[' + guestsList.statusPar[row2.ID_STATUT_A39] + ']</span>' +
  1799. '<p>Date de validation: ' + date2.getDate() + " " + monthsInYear[date2.getMonth()] + " " + date2.getFullYear() + '</p></li>');
  1800. }
  1801. });
  1802. $('#guestDataPrestationsList').listview("refresh");
  1803. $.unblockUI();
  1804. },
  1805. error: function (request,error) {
  1806. $.unblockUI();
  1807. if(request.status == 401){
  1808. // Unauthorized
  1809. navigator.notification.alert(
  1810. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  1811. alertDismissed,
  1812. "Notification",
  1813. "Ok"
  1814. );
  1815.  
  1816. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1817. }
  1818. navigator.notification.alert(
  1819. "Erreur lors de la r\351cup\351ration des prestations d'un invit\351",
  1820. alertDismissed,
  1821. "Notification",
  1822. "Ok"
  1823. );
  1824. }
  1825. });
  1826. }
  1827.  
  1828. $(document).on('vclick', '#infoGuestPageBackButton', function(){
  1829. $.mobile.changePage( "#guestsPage", { transition: "slide", reverse: true, changeHash: false });
  1830. });
  1831.  
  1832. function validateGuest(id){
  1833. ajax.blockui();
  1834.  
  1835. var fullURL;
  1836. if(guestsList.prestations){
  1837. fullURL = 'methods/MobileApp/SetPresenceInscription?id=' + id;
  1838. }
  1839. else{
  1840. fullURL = 'methods/MobileApp/SetPresence/' + id;
  1841. }
  1842.  
  1843. $.ajax({
  1844. type: 'POST',
  1845. url: url + fullURL,
  1846. crossDomain: true,
  1847. headers: {'AgoraEvent-Token': ApiToken},
  1848. success: function (result) {
  1849. loadParticipantPresenceInfos();
  1850.  
  1851. guestsList.nbPresents ++;
  1852. var text0 = " pr\351sent";
  1853. if(guestsList.nbPresents > 1){
  1854. text0 = " pr\351sents";
  1855. }
  1856. document.getElementById("guestsPageNbPresents").innerHTML = guestsList.nbPresents + " pr\351sents";
  1857. navigator.notification.vibrate(500);
  1858. $.unblockUI();
  1859. },
  1860. error: function (request, error) {
  1861. $.unblockUI();
  1862. navigator.notification.vibrate(500);
  1863. if(request.status == 401){
  1864. // Unauthorized
  1865. navigator.notification.alert(
  1866. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  1867. alertDismissed,
  1868. "Notification",
  1869. "Ok"
  1870. );
  1871.  
  1872. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1873. }
  1874. else if(request.status == 404){
  1875. navigator.notification.alert(
  1876. "Attention: veuillez v\351rifier que le participant fait partie de la liste d'invit\351",
  1877. alertDismissed,
  1878. "Notification",
  1879. "Ok"
  1880. );
  1881. }
  1882. else if(request.status == 403){
  1883. navigator.notification.alert(
  1884. "Attention: le participant a d\351j\340 \351t\351 enregistr\351 aujourd'hui",
  1885. alertDismissed,
  1886. "Notification",
  1887. "Ok"
  1888. );
  1889. }
  1890. else{
  1891. navigator.notification.alert(
  1892. "Erreur lors de la validation d'un invit\351 en ligne",
  1893. alertDismissed,
  1894. "Notification",
  1895. "Ok"
  1896. );
  1897. }
  1898. }
  1899. });
  1900. }
  1901.  
  1902.  
  1903. $(document).on('vclick', '#infoGuestFooterBtnCheck', function(){
  1904. var id = guestsList.id;
  1905. validateGuest(id);
  1906. });
  1907.  
  1908. /***************************************/
  1909. /****** #region LOCAL *******/
  1910. /***************************************/
  1911.  
  1912. /****** #subregion prestationsPageLocal *****/
  1913. $(document).on('pagebeforeshow', '#prestationsPageLocal', function(){
  1914. document.getElementById("PrestationsPageLocalTitle").innerHTML = "Mode hors ligne: " + window.localStorage.getItem("importedBaseName");
  1915. });
  1916.  
  1917. $(document).on('vclick', '#prestationsPageLocalFooterBtnExport', function(){
  1918. btnExportClick();
  1919. });
  1920.  
  1921. $(document).on('vclick', '#backBtnPrestationsPageLocal', function(){
  1922. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1923. });
  1924.  
  1925. $(document).on('vclick', '#prestationsLocalList li a', function(){
  1926. guestsList.prestationName = $(this)[0].querySelector("h3").textContent;
  1927. guestsList.prestationId = $(this).attr('data-id');
  1928. $('#guestsListLocal').empty();
  1929.  
  1930. if(guestsList.prestationId == 0 || guestsList.prestationId == null){
  1931. parseGuestsListLocal("false");
  1932. guestsList.prestations = false;
  1933. }else{
  1934. parseGuestsListLocal("true");
  1935. guestsList.prestations = true;
  1936. }
  1937. });
  1938.  
  1939. $(document).on('vclick', '#moreOptionPrestationPageLocal', function(){
  1940. $.mobile.silentScroll(0);
  1941. guestsList.dialog = 7;
  1942. setTimeout(function(){
  1943. document.getElementById("moreOptionOverlayDivPrestationPageLocal").style.display="block";
  1944. }, 50);
  1945. document.getElementById("moreOptionDivPrestationPageLocal").style.display="block";
  1946. });
  1947.  
  1948. $(document).on('vclick', '#moreOptionOverlayDivPrestationPageLocal', function(){
  1949. guestsList.dialog = 0;
  1950. document.getElementById("moreOptionDivPrestationPageLocal").style.display="none";
  1951. setTimeout(function(){
  1952. document.getElementById("moreOptionOverlayDivPrestationPageLocal").style.display="none";
  1953. }, 50);
  1954. });
  1955.  
  1956. $(document).on('vclick', '#prestationsPageLocalFooterBtnAccueil', function(){
  1957. document.getElementById("moreOptionDivPrestationPage").style.display="none";
  1958. setTimeout(function(){
  1959. document.getElementById("moreOptionOverlayDivPrestationPage").style.display="none";
  1960. }, 50);
  1961.  
  1962. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  1963. });
  1964.  
  1965. /****** #subregion guestsPageLocal *****/
  1966. function parseGuestsListLocal(prestations){
  1967. ajax.blockui();
  1968. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  1969. $('#guestsListLocal').empty();
  1970. if(prestations == "true"){
  1971. document.getElementById("guestsPageLocalTitle").innerHTML = "Mode hors ligne: " + guestsList.prestationName;
  1972.  
  1973. db.transaction(function(tx) {
  1974. tx.executeSql("select a.*, b.ID_STATUT_A39, b.ID as ID_A07 from A09_PARTICIPANT as a left join A07_INSCRIPTION as b on a.ID=b.ID_PARTICIPANT where PRESTATION_A10=? limit 100;", [guestsList.prestationId], function(tx, res) {
  1975. for (i = 0; i < res.rows.length; i++) {
  1976. $('#guestsListLocal').append('<li><a href="" data-id="' +
  1977. res.rows.item(i).ID_A07 + '"><h3><i class="fa fa-user fa-2x"></i>' + res.rows.item(i).LastName + '<p>' + res.rows.item(i).FirstName + (res.rows.item(i).ID_STATUT_A39 == '3'? '<br/><span style="color: green;">Présent<span>' : '') +'</p></h3></a></li>');
  1978. }
  1979. guestsList.startRecord = 100;
  1980. guestsList.nbRecord = res.rows.length;
  1981.  
  1982. });
  1983. tx.executeSql("select count(*) as cnt from A09_PARTICIPANT as a left join A07_INSCRIPTION as b on a.ID=b.ID_PARTICIPANT where PRESTATION_A10=?;", [guestsList.prestationId], function(tx, res) {
  1984. guestsList.nbParticipants = res.rows.item(0).cnt;
  1985. var text0 = " r\351sultat";
  1986. if(guestsList.nbParticipants > 0){
  1987. text0 = " r\351sultats";
  1988. }
  1989. document.getElementById("guestsPageLocalNbResults").innerHTML = guestsList.nbParticipants + text0;
  1990. });
  1991. });
  1992. }
  1993. else
  1994. {
  1995. db.transaction(function(tx)
  1996. {
  1997. tx.executeSql("select * from A09_PARTICIPANT limit 100;", [], function(tx, res) {
  1998. for (i = 0; i < res.rows.length; i++) {
  1999. $('#guestsListLocal').append('<li><a href="" data-id="' +
  2000. res.rows.item(i).ID + '"><h3><i class="fa fa-user fa-2x"></i>' + res.rows.item(i).LastName + '<p>' + res.rows.item(i).FirstName + (res.rows.item(i).StatusID == '3'? '<br/><span style="color: green;">Présent<span>' : '') + '</p></h3></a></li>');
  2001. }
  2002. guestsList.startRecord = 100;
  2003. guestsList.nbRecord = res.rows.length;
  2004.  
  2005. });
  2006. tx.executeSql("select count(*) as cnt from A09_PARTICIPANT;", [], function(tx, res) {
  2007. guestsList.nbParticipants = res.rows.item(0).cnt;
  2008. document.getElementById("guestsPageLocalTitle").innerHTML = "Mode hors ligne: " + window.localStorage.getItem("importedBaseName");
  2009. var text0 = " r\351sultat";
  2010. if(guestsList.nbParticipants > 0){
  2011. text0 = " r\351sultats";
  2012. }
  2013. document.getElementById("guestsPageLocalNbResults").innerHTML = guestsList.nbParticipants + text0;
  2014. });
  2015. });
  2016. }
  2017. setTimeout(function(){
  2018. $.mobile.changePage( "#guestsPageLocal", { transition: "slide", changeHash: false });
  2019. $('#guestsListLocal').listview('refresh');
  2020. $.unblockUI();
  2021. }, 1000);
  2022. }
  2023.  
  2024. function emptyGuestDataLocal(){
  2025. $('#guestDataLocal').empty();
  2026. $('#guestDataPrestationsListLocal').empty();
  2027.  
  2028. document.getElementById("infoGuestPageLocalName").innerHTML = "Nom Pr\351nom";
  2029. document.getElementById("infoGuestPageLocalCategory").innerHTML = "Cat\351gorie";
  2030.  
  2031. $('#guestDataLocal').append(
  2032. '<strong>Soci\351t\351: </strong><br/>' +
  2033. '<strong>Email: </strong><br/>' +
  2034. '<strong>T\351l\351phone: </strong><br/>'
  2035. );
  2036. }
  2037.  
  2038. $(document).on('pagebeforeshow', '#guestsPageLocal', function(){
  2039. $('#guestsListLocal').listview('refresh');
  2040. emptyGuestDataLocal();
  2041. });
  2042.  
  2043. $(document).on('vclick', '#guestsPageLocalBackButton', function(){
  2044. $("#guestsListLocal").empty();
  2045.  
  2046. if(guestsList.prestations || (!guestsList.prestations && guestsList.prestationId == 0)){
  2047. $.mobile.changePage( "#prestationsPageLocal", { transition: "slide", reverse: true, changeHash: false });
  2048. }
  2049. else
  2050. {
  2051. $.mobile.changePage("#mainPage", { transition: "slide", reverse: true, changeHash: false });
  2052. }
  2053. });
  2054.  
  2055. $(document).on('vclick', '#guestsListLocal li a', function(){
  2056. guestsList.id = $(this).attr('data-id');
  2057. loadParticipantInfo();
  2058. if(!guestsList.tablette){
  2059. setTimeout(function(){
  2060. $.mobile.changePage( "#infoGuestPageLocal", { transition: "slide", changeHash: false });
  2061. }, 10);
  2062. }
  2063. });
  2064.  
  2065. $(document).on('vclick', '#moreOptionGuestsPageLocal', function(){
  2066. $.mobile.silentScroll(0);
  2067. guestsList.dialog = 8;
  2068. setTimeout(function(){
  2069. document.getElementById("moreOptionOverlayDivGuestsPageLocal").style.display="block";
  2070. }, 50);
  2071. document.getElementById("moreOptionDivGuestsPageLocal").style.display="block";
  2072. });
  2073.  
  2074. $(document).on('vclick', '#moreOptionOverlayDivGuestsPageLocal', function(){
  2075. guestsList.dialog = 0;
  2076. document.getElementById("moreOptionDivGuestsPageLocal").style.display="none";
  2077. setTimeout(function(){
  2078. document.getElementById("moreOptionOverlayDivGuestsPageLocal").style.display="none";
  2079. }, 50);
  2080. });
  2081.  
  2082. $(document).on('vclick', '#guestsListLocalFooterBtnAccueil', function(){
  2083. document.getElementById("moreOptionDivGuestsPageLocal").style.display="none";
  2084. setTimeout(function(){
  2085. document.getElementById("moreOptionOverlayDivGuestsPageLocal").style.display="none";
  2086. }, 50);
  2087.  
  2088. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  2089. });
  2090.  
  2091. $(document).on('vclick', '#infoGuestPageLocalBackButton', function(){
  2092. $.mobile.changePage( "#guestsPageLocal", { transition: "slide", reverse: true, changeHash: false });
  2093. });
  2094.  
  2095. /*********** #subregion Export **************/
  2096. $(document).on('vclick', '#guestsListLocalFooterBtnExport', function(){
  2097. btnExportClick();
  2098. });
  2099.  
  2100. function btnExportClick(){
  2101. $.mobile.silentScroll(0);
  2102.  
  2103. setTimeout(function(){ dialogLoginExport.show(); }, 50);
  2104.  
  2105. guestsList.dialog = 3;
  2106.  
  2107. var rememberMe = window.localStorage.getItem("rememberMe");
  2108. if(rememberMe == "true"){
  2109. document.getElementById("usernameExport").value = window.localStorage.getItem("username");
  2110. document.getElementById("passwordExport").value = window.localStorage.getItem("password");
  2111. }
  2112.  
  2113. $('#authenticationFormExport').on('submit', function(event) {
  2114. event.preventDefault();
  2115. $('#passwordExport').blur();
  2116. setTimeout(function() {
  2117. $('#btnConnexionExport').trigger('click');
  2118. }, 50);
  2119. });
  2120. }
  2121.  
  2122. $(document).on('vclick', '#btnConnexionExport', function(){
  2123. setTimeout(function(){ dialogLoginExport.hide(); }, 50)
  2124.  
  2125. guestsList.dialog = 0;
  2126.  
  2127. var form = $("#authenticationFormExport");
  2128. var username = $("#usernameExport", form).val();
  2129. var password = $("#passwordExport", form).val();
  2130.  
  2131. if(username != "" && password != "") {
  2132. // Blocage de l'interface
  2133. ajax.blockui();
  2134. $.ajax({
  2135. type: 'POST',
  2136. url: url + 'authentication/authenticate',
  2137. crossDomain: true,
  2138. data: {login: username, password : password},
  2139. dataType: 'json',
  2140. success: function (result) {
  2141. ajax.blockui();
  2142. //Récupération du token d'authentification
  2143. ApiToken = result;
  2144.  
  2145. window.localStorage.setItem("token", ApiToken);
  2146. window.localStorage.setItem("tokenDate", new Date().toString());
  2147.  
  2148. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  2149.  
  2150. db.transaction(function(tx) {
  2151. tx.executeSql("select * from CHANGE_LIST;", [], function(tx, res) {
  2152. var idList = [];
  2153. for (i = 0; i < res.rows.length; i++) {
  2154. idList.push(res.rows.item(i).ID);
  2155. }
  2156.  
  2157. var tmp = JSON.stringify(idList);
  2158.  
  2159. $.ajax({
  2160. type: 'POST',
  2161. url: url + 'methods/MobileApp/SetPresenceList/',
  2162. crossDomain: true,
  2163. headers: {'AgoraEvent-Token': ApiToken},
  2164. data: tmp,
  2165. dataType: 'json',
  2166. contentType: "application/json; charset=utf-8",
  2167. success: function (result) {
  2168. navigator.notification.alert(
  2169. "Export termin\351!",
  2170. alertDismissed,
  2171. "Notification",
  2172. "Ok"
  2173. );
  2174.  
  2175. try{
  2176. tx.executeSql("Delete from CHANGE_LIST;", [], function(tx, res) {});
  2177. }
  2178. catch(err){
  2179. console.log(err);
  2180. }
  2181.  
  2182. $.unblockUI();
  2183. },
  2184. error: function (request,error) {
  2185. $.unblockUI();
  2186. navigator.notification.alert(
  2187. "Erreur lors de l'export des fichiers",
  2188. alertDismissed,
  2189. "Notification",
  2190. "Ok"
  2191. );
  2192. }
  2193. });
  2194. });
  2195.  
  2196. tx.executeSql("select * from CHANGE_LIST_INSCRIPTION;", [], function(tx, res) {
  2197. var idList = [];
  2198. for (i = 0; i < res.rows.length; i++) {
  2199. idList.push(res.rows.item(i).ID);
  2200. }
  2201.  
  2202. var tmp = JSON.stringify(idList);
  2203.  
  2204. $.ajax({
  2205. type: 'POST',
  2206. url: url + 'methods/MobileApp/SetPresenceListInscription/',
  2207. crossDomain: true,
  2208. headers: {'AgoraEvent-Token': ApiToken},
  2209. data: tmp,
  2210. dataType: 'json',
  2211. contentType: "application/json; charset=utf-8",
  2212. success: function (result) {
  2213. try{
  2214. tx.executeSql("Delete from CHANGE_LIST_INSCRIPTION;", [], function(tx, res) {});
  2215. }
  2216. catch(err){
  2217. console.log(err);
  2218. }
  2219. },
  2220. error: function (request,error) {
  2221. $.unblockUI();
  2222. navigator.notification.alert(
  2223. "Erreur lors de l'export des fichiers",
  2224. alertDismissed,
  2225. "Notification",
  2226. "Ok"
  2227. );
  2228. }
  2229. });
  2230. });
  2231.  
  2232. tx.executeSql("select * from CHANGE_LIST_I42_INV_DATES_PRESENCE;", [], function(tx, res) {
  2233. var list = [];
  2234. for (i = 0; i < res.rows.length; i++) {
  2235. var date = new Date(res.rows.item(i).DATE_PRESENCE.toString());
  2236. res.rows.item(i).DATE_PRESENCE = "#" + date.getDate() + "/" + date.getMonth() + "/" + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes() + "#";
  2237. list.push(res.rows.item(i));
  2238. }
  2239. var tmp = JSON.stringify(list);
  2240.  
  2241. $.ajax({
  2242. type: 'POST',
  2243. url: url + 'methods/MobileApp/SetInv_Dates_PresenceList/',
  2244. crossDomain: true,
  2245. headers: {'AgoraEvent-Token': ApiToken},
  2246. data: tmp,
  2247. dataType: 'json',
  2248. contentType: "application/json; charset=utf-8",
  2249. success: function (result) {
  2250. try{
  2251. tx.executeSql("Delete from CHANGE_LIST_I42_INV_DATES_PRESENCE;", [], function(tx, res) {});
  2252. }
  2253. catch(err){
  2254. console.log(err);
  2255. }
  2256. },
  2257. error: function (request,error) {
  2258. $.unblockUI();
  2259. navigator.notification.alert(
  2260. "Erreur lors de l'export des fichiers",
  2261. alertDismissed,
  2262. "Notification",
  2263. "Ok"
  2264. );
  2265. }
  2266. });
  2267. });
  2268. });
  2269. },
  2270. error: function (request,error) {
  2271. $.unblockUI();
  2272. navigator.notification.alert(
  2273. "Combinaison identifiants / mot de passe invalide",
  2274. alertDismissed,
  2275. "Notification",
  2276. "Ok"
  2277. );
  2278. }
  2279. });
  2280. }
  2281. else {
  2282. //if the email and password is empty
  2283. navigator.notification.alert(
  2284. "Veuillez renseigner les champs d'authentification",
  2285. alertDismissed,
  2286. "Notification",
  2287. "Ok"
  2288. );
  2289. }
  2290. });
  2291.  
  2292. /*********** #subregion Check presence **************/
  2293. $(document).on('vclick', '#infoGuestLocalFooterBtnCheck', function(){
  2294. validateLocal();
  2295. });
  2296.  
  2297. function goToGuestPageLocal(){
  2298. $.mobile.changePage( "#guestsPageLocal", { transition: "fade", changeHash: false });
  2299. }
  2300.  
  2301. function showErrorScanPageLocal(){
  2302. document.getElementById("scanResultText").innerHTML = "X";
  2303. document.getElementById("scanPage").style.backgroundColor = "rgb(254,0,0)";
  2304. document.getElementById("scanPageLinkGuest").style.display = "none";
  2305. document.getElementById("scanPageTitle1").innerHTML = "Billet non valide";
  2306. document.getElementById("scanPageTitle2").innerHTML = "Erreur:";
  2307.  
  2308. $("#scanPageLinkBack").unbind("click");
  2309. $("#scanPageContent").unbind("click");
  2310.  
  2311. $("#scanPageContent").click(scanAgainLocal);
  2312. $("#scanPageLinkBack").click(goToGuestPageLocal);
  2313.  
  2314. document.getElementById("scanPageMessage").innerHTML = "Impossible d'identifier le num\351ro du billet, veuillez v\351rifier les informations de celui-ci";
  2315.  
  2316. $.mobile.changePage( "#scanPage", { transition: "fade", changeHash: false });
  2317. guestsList.qrCode = 0;
  2318. }
  2319.  
  2320. function showAlreadyScanPageLocal(){
  2321. document.getElementById("scanResultText").innerHTML = "X";
  2322. document.getElementById("scanPage").style.backgroundColor = "rgb(236,101,0)";
  2323. document.getElementById("scanPageLinkGuest").style.display = "block";
  2324.  
  2325. $("#scanPageLinkGuest").unbind("click");
  2326. $("#scanPageLinkBack").unbind("click");
  2327. $("#scanPageContent").unbind("click");
  2328.  
  2329. $("#scanPageLinkGuest").click(moreInfoScanLocal);
  2330. $("#scanPageContent").click(scanAgainLocal);
  2331. $("#scanPageLinkBack").click(goToGuestPageLocal);
  2332.  
  2333. document.getElementById("scanPageTitle1").innerHTML = "Billet d\351j\340 enregistr\351";
  2334. document.getElementById("scanPageTitle2").innerHTML = "Alerte:";
  2335. document.getElementById("scanPageMessage").innerHTML = "Le num\351ro du billet a d\351j\340 \351t\351 scann\351 auparavant";
  2336.  
  2337. $.mobile.changePage( "#scanPage", { transition: "fade", changeHash: false });
  2338. guestsList.qrCode = 0;
  2339. }
  2340.  
  2341. function showOkScanPageLocal(lastName, firstName){
  2342. document.getElementById("scanResultText").innerHTML = "ok";
  2343. document.getElementById("scanPage").style.backgroundColor = "rgb(133, 229, 55)";
  2344. document.getElementById("scanPageLinkGuest").style.display = "block";
  2345.  
  2346. document.getElementById("scanPageTitle1").innerHTML = lastName;
  2347. document.getElementById("scanPageTitle2").innerHTML = firstName;
  2348.  
  2349. document.getElementById("scanPageMessage").innerHTML = "";
  2350.  
  2351. $("#scanPageLinkGuest").unbind("click");
  2352. $("#scanPageLinkBack").unbind("click");
  2353. $("#scanPageContent").unbind("click");
  2354.  
  2355. $("#scanPageLinkBack").click(goToGuestPageLocal);
  2356. $("#scanPageLinkGuest").click(moreInfoScanLocal);
  2357. $("#scanPageContent").click(scanAgainLocal);
  2358.  
  2359. $.mobile.changePage( "#scanPage", { transition: "fade", changeHash: false });
  2360. guestsList.qrCode = 0;
  2361. }
  2362.  
  2363. function validateLocalPrestation(){
  2364. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  2365. db.transaction(function(tx) {
  2366. tx.executeSql("select * from A07_INSCRIPTION WHERE ID=?;", [guestsList.id], function(tx, res) {
  2367. if(res.rows.length == 0){
  2368. if(guestsList.qrCode == 1){
  2369. showErrorScanPageLocal();
  2370. }
  2371. else{
  2372. navigator.notification.alert(
  2373. "Impossible d'identifier le participant",
  2374. alertDismissed,
  2375. "Notification",
  2376. "Ok"
  2377. );
  2378. }
  2379. }
  2380. else if(res.rows.item(0).ID_STATUT_A39 != 3){
  2381. ajax.blockuiNoMsg();
  2382.  
  2383. db.transaction(function(tx) {
  2384. tx.executeSql("INSERT INTO CHANGE_LIST_INSCRIPTION (ID, ID_STATUT_A39) VALUES (?,?)", [guestsList.id, 3], function(tx, res) {
  2385. });
  2386.  
  2387. var today = new Date();
  2388. tx.executeSql("UPDATE A07_INSCRIPTION set ID_STATUT_A39=3, DatePresence=? WHERE ID =?", [today, guestsList.id], function(tx, res) {
  2389. });
  2390.  
  2391. $("#guestsListLocal").listview("refresh");
  2392.  
  2393. if(guestsList.qrCode == 1){
  2394. tx.executeSql("select LastName, FirstName from A09_PARTICIPANT as a left join A07_INSCRIPTION as b on a.ID=b.ID_PARTICIPANT WHERE b.ID=?;", [guestsList.id], function(tx, res) {
  2395. showOkScanPageLocal(res.rows.item(0).LastName, res.rows.item(0).FirstName);
  2396. });
  2397. }else{
  2398. loadParticipantInfo();
  2399. }
  2400.  
  2401. setTimeout(function(){
  2402. $.unblockUI();
  2403. }, 200);
  2404. }, function(e) {
  2405. console.log("ERROR: " + e.message);
  2406. });
  2407. }else if(res.rows.item(0).ID_STATUT_A39 == 3){
  2408. if(guestsList.qrCode == 1){
  2409. showAlreadyScanPageLocal();
  2410. }
  2411. else{
  2412. navigator.notification.alert(
  2413. "Le participant est d\351j\340 pr\351sent",
  2414. alertDismissed,
  2415. "Notification",
  2416. "Ok"
  2417. );
  2418. }
  2419. }
  2420. });
  2421.  
  2422. });
  2423. }
  2424.  
  2425. function validateLocal(){
  2426. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  2427. if(guestsList.prestations){
  2428. db.transaction(function(tx) {
  2429. // SI on scan un QRcode alors l'id récupéré est un ID_PARTICIPANT et non un ID de A07_INSCRIPTION
  2430. // On va donc faire un select pour obtenir cet id
  2431. if(guestsList.qrCode == 1){
  2432. tx.executeSql("select ID from A07_INSCRIPTION WHERE ID_PARTICIPANT=?;", [guestsList.id], function(tx, res) {
  2433. if(res.rows.length == 0){
  2434. if(guestsList.qrCode == 1){
  2435. showErrorScanPageLocal();
  2436. }
  2437. }else{
  2438. guestsList.id = res.rows.item(0).ID;
  2439. validateLocalPrestation();
  2440. }
  2441. });
  2442. }
  2443. else{
  2444. validateLocalPrestation();
  2445. }
  2446. });
  2447. }
  2448. else{
  2449. db.transaction(function(tx) {
  2450. tx.executeSql("select FirstName, LastName, StatusID from A09_PARTICIPANT where ID=?;", [guestsList.id], function(tx, res) {
  2451. if(res.rows.length == 0){
  2452. if(guestsList.qrCode == 1){
  2453. showErrorScanPageLocal();
  2454. }
  2455. else{
  2456. navigator.notification.alert(
  2457. "Impossible d'identifier le participant",
  2458. alertDismissed,
  2459. "Notification",
  2460. "Ok"
  2461. );
  2462. }
  2463. }
  2464. else{
  2465. var firstname = res.rows.item(0).FirstName;
  2466. var lastname = res.rows.item(0).LastName;
  2467. db.transaction(function(tx) {
  2468. tx.executeSql("select * from I42_INV_DATES_PRESENCE where ID_PART_A09=?;", [guestsList.id], function(tx, res) {
  2469. var today = new Date();
  2470. if(res.rows.length == 0){
  2471. ajax.blockuiNoMsg();
  2472. var eventID = window.localStorage.getItem("eventId", guestsList.eventId);
  2473. tx.executeSql("INSERT INTO CHANGE_LIST (ID, StatusID) VALUES (?,?)", [guestsList.id, 3], function(tx, res) {
  2474. });
  2475.  
  2476. tx.executeSql("INSERT INTO I42_INV_DATES_PRESENCE (ID_PART_A09, DATE_PRESENCE, NUMERO_MANIFESTATION, STATUTPART_A09) VALUES (?,?,?,?)", [guestsList.id, today, eventID, 3], function(tx, res) {
  2477. });
  2478.  
  2479. tx.executeSql("INSERT INTO CHANGE_LIST_I42_INV_DATES_PRESENCE (ID_PART_A09, DATE_PRESENCE, NUMERO_MANIFESTATION, STATUTPART_A09) VALUES (?,?,?,?)", [guestsList.id, today, eventID, 3], function(tx, res) {
  2480. });
  2481.  
  2482. tx.executeSql("UPDATE A09_PARTICIPANT set StatusID=3 WHERE ID =?", [guestsList.id], function(tx, res) {
  2483. });
  2484.  
  2485. tx.executeSql("UPDATE A09_PARTICIPANT set DatePresence=? WHERE ID =?", [today ,guestsList.id], function(tx, res) {
  2486. });
  2487.  
  2488. $("#guestsListLocal").listview("refresh");
  2489.  
  2490. if(guestsList.qrCode == 1){
  2491. showOkScanPageLocal(lastname, firstname);
  2492. }else{
  2493. loadParticipantInfo();
  2494. }
  2495.  
  2496. setTimeout(function(){
  2497. $.unblockUI();
  2498. }, 200);
  2499. }
  2500. else{
  2501. var datePresence = new Date(res.rows.item(0).DATE_PRESENCE);
  2502. if (datePresence.getDate() != today.getDate() || datePresence.getMonth() != today.getMonth() || datePresence.getFullYear() != today.getFullYear()){
  2503. ajax.blockuiNoMsg();
  2504. var eventID = window.localStorage.getItem("eventId", guestsList.eventId);
  2505.  
  2506. tx.executeSql("INSERT INTO CHANGE_LIST (ID, StatusID) VALUES (?,?)", [guestsList.id, 3], function(tx, res) {
  2507. });
  2508.  
  2509. tx.executeSql("INSERT INTO I42_INV_DATES_PRESENCE (ID_PART_A09, DATE_PRESENCE, NUMERO_MANIFESTATION, STATUTPART_A09) VALUES (?,?,?,?)", [guestsList.id, today, eventID, 3], function(tx, res) {
  2510. });
  2511.  
  2512. tx.executeSql("INSERT INTO CHANGE_LIST_I42_INV_DATES_PRESENCE (ID_PART_A09, DATE_PRESENCE, NUMERO_MANIFESTATION, STATUTPART_A09) VALUES (?,?,?,?)", [guestsList.id, today, eventID, 3], function(tx, res) {
  2513. });
  2514.  
  2515. $("#guestsListLocal").listview("refresh");
  2516. if(guestsList.qrCode == 1){
  2517. showOkScanPageLocal(lastname, firstname);
  2518. }else{
  2519. loadParticipantInfo();
  2520. }
  2521.  
  2522. setTimeout(function(){
  2523. $.unblockUI();
  2524. }, 200);
  2525. }else{
  2526. if(guestsList.qrCode == 1){
  2527. showAlreadyScanPageLocal();
  2528. }
  2529. else{
  2530. navigator.notification.alert(
  2531. "Le participant est d\351j\340 pr\351sent",
  2532. alertDismissed,
  2533. "Notification",
  2534. "Ok"
  2535. );
  2536. }
  2537. }
  2538. }
  2539. });
  2540. });
  2541. }
  2542. });
  2543. });
  2544. }
  2545. navigator.notification.vibrate(500);
  2546. }
  2547.  
  2548. function moreInfoScanLocal(){
  2549. if(guestsList.tablette){
  2550. $.mobile.changePage( "#guestsPageLocal", { transition: "slide", changeHash: false });
  2551. }else{
  2552. $.mobile.changePage( "#infoGuestPageLocal", { transition: "slide", changeHash: false });
  2553. }
  2554. }
  2555.  
  2556. function scanAgainLocal(){
  2557. setTimeout(function(){
  2558. scanQrCodeLocal();
  2559. guestsList.qrCode = 1;
  2560. guestsList.dialog = 10;
  2561. }, 50);
  2562. }
  2563.  
  2564. function scanQrCodeLocal(){
  2565. guestsList.qrCode = 1;
  2566. guestsList.dialog = 10;
  2567. openBarcodeScan("scan", function (barcode) {
  2568. guestsList.id = getParameterByName(barcode.text, "IdA09");
  2569. if(guestsList.id != ""){
  2570. validateLocal();
  2571. }else{
  2572. navigator.notification.vibrate(500);
  2573. showErrorScanPageLocal();
  2574. }
  2575. });
  2576. }
  2577.  
  2578. $(document).on('vclick', '#guestsListLocalFooterBtnQrcode', function(){
  2579. scanQrCodeLocal();
  2580. });
  2581.  
  2582. /****** #subregion infoGuestPageLocal *****/
  2583. function loadParticipantInfo(){
  2584. $('#guestDataLocal').empty();
  2585.  
  2586. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  2587. var monthsInYear= new Array("janvier", "f\351vrier", "mars", "avril", "mai", "juin", "juillet", "ao\373t", "septembre", "octobre", "novembre", "d\351cembre");
  2588.  
  2589. if(guestsList.prestations){
  2590. db.transaction(function(tx) {
  2591. tx.executeSql("select *, ID_STATUT_A39 from A09_PARTICIPANT as a left join A07_INSCRIPTION as b on a.ID=b.ID_PARTICIPANT where b.ID=?;", [guestsList.id], function(tx, res) {
  2592. document.getElementById("infoGuestPageLocalName").innerHTML = res.rows.item(0).FirstName + " " + res.rows.item(0).LastName;
  2593. document.getElementById("infoGuestPageLocalCategory").innerHTML = res.rows.item(0).Category;
  2594.  
  2595. $('#guestDataLocal').append(
  2596. '<strong>Soci\351t\351: </strong>' + res.rows.item(0).Societe + '<br/>' +
  2597. '<strong>Email: </strong>' + res.rows.item(0).Email + '<br/>' +
  2598. '<strong>T\351l\351phone: </strong>' + res.rows.item(0).Tel + '<br/>'
  2599. );
  2600. $('#guestDataPrestationsListLocal').empty();
  2601. var statusID = res.rows.item(0).StatusID;
  2602. var participantID = res.rows.item(0).ID;
  2603. db.transaction(function(tx) {
  2604. tx.executeSql("select count(*) as cnt from I42_INV_DATES_PRESENCE where ID_PART_A09=?;", [participantID], function(tx, res) {
  2605. if(res.rows.item(0).cnt == 0){
  2606. $('#guestDataPrestationsListLocal').append('<li><i class="fa fa-home homePrestation"></i><h3>Accueil Principal</h3>' +
  2607. '<span class="infoGuestStatusLocal status' + statusID + '">[' + guestsList.statusPar[statusID] + ']</span>'+
  2608. '<p>Date de validation:</p></li>');
  2609. }else{
  2610. db.transaction(function(tx) {
  2611. tx.executeSql("select * from I42_INV_DATES_PRESENCE where ID_PART_A09=?;", [participantID], function(tx, res) {
  2612. var tmpText = '<li><i class="fa fa-home homePrestation"></i><h3>Accueil Principal</h3>' +
  2613. '<span class="infoGuestStatusLocal status' + res.rows.item(res.rows.length-1).STATUS_PART_A09 + '">[' + guestsList.statusPar[res.rows.item(res.rows.length-1).STATUTPART_A09] + ']</span>';
  2614. for (i = 0; i < res.rows.length; i++) {
  2615. var date = new Date(res.rows.item(i).DATE_PRESENCE);
  2616. if(date.getFullYear() < 2000){
  2617. tmpText += '<p>Date de validation:</p>';
  2618. }else{
  2619. tmpText += '<p>Date de validation: ' + date.getDate() + " " + monthsInYear[date.getMonth()] + " " + date.getFullYear() + '</p>';
  2620. }
  2621. }
  2622. tmpText += '</li>';
  2623. $('#guestDataPrestationsListLocal').append(tmpText);
  2624. });
  2625. });
  2626. }
  2627. });
  2628. });
  2629. });
  2630.  
  2631. tx.executeSql("select * from A07_INSCRIPTION where ID=?;", [guestsList.id], function(tx, res) {
  2632. var id = res.rows.item(0).ID_PARTICIPANT;
  2633.  
  2634. db.transaction(function(tx) {
  2635. tx.executeSql("select * from A07_INSCRIPTION as a left join A10_PRESTATION as b on a.PRESTATION_A10=b.ID where a.ID_PARTICIPANT=?;", [id], function(tx, res) {
  2636. for (i = 0; i < res.rows.length; i++) {
  2637. var date2 = new Date(res.rows.item(i).DatePresence);
  2638. if(date2.getFullYear() < 2000){
  2639. $('#guestDataPrestationsListLocal').append('<li><i class="fa fa-ticket"></i><h3>' + res.rows.item(i).LIBELLE + '</h3>' +
  2640. '<span class="infoGuestStatusLocal status' + res.rows.item(i).ID_STATUT_A39 + '">[' + guestsList.statusPar[res.rows.item(i).ID_STATUT_A39] + ']</span>' +
  2641. '<p>Date de validation: </p></li>');
  2642.  
  2643. }else{
  2644. $('#guestDataPrestationsListLocal').append('<li><i class="fa fa-ticket"></i><h3>' + res.rows.item(i).LIBELLE + '</h3>' +
  2645. '<span class="infoGuestStatusLocal status' + res.rows.item(i).ID_STATUT_A39 + '">[' + guestsList.statusPar[res.rows.item(i).ID_STATUT_A39] + ']</span>' +
  2646. '<p>Date de validation: ' + date2.getDate() + " " + monthsInYear[date2.getMonth()] + " " + date2.getFullYear() + '</p></li>');
  2647. }
  2648. }
  2649. $('#guestDataPrestationsListLocal').listview("refresh");
  2650. });
  2651. });
  2652. });
  2653. });
  2654. }
  2655. else{
  2656. db.transaction(function(tx) {
  2657. tx.executeSql("select * from A09_PARTICIPANT WHERE ID=?;", [guestsList.id], function(tx, res) {
  2658. $('#guestDataLocal').empty();
  2659. document.getElementById("infoGuestPageLocalName").innerHTML = res.rows.item(0).FirstName + " " + res.rows.item(0).LastName;
  2660. document.getElementById("infoGuestPageLocalCategory").innerHTML = res.rows.item(0).Category;
  2661.  
  2662.  
  2663. $('#guestDataLocal').append(
  2664. '<strong>Soci\351t\351: </strong>' + res.rows.item(0).Societe + '<br/>' +
  2665. '<strong>Email: </strong>' + res.rows.item(0).Email + '<br/>' +
  2666. '<strong>T\351l\351phone: </strong>' + res.rows.item(0).Tel + '<br/>'
  2667. );
  2668.  
  2669. var statusID = res.rows.item(0).StatusID;
  2670.  
  2671. $('#guestDataPrestationsListLocal').empty();
  2672.  
  2673. tx.executeSql("select count(*) as cnt from I42_INV_DATES_PRESENCE where ID_PART_A09=?;", [guestsList.id], function(tx, res) {
  2674. if(res.rows.item(0).cnt == 0){
  2675. $('#guestDataPrestationsListLocal').append('<li><i class="fa fa-home homePrestation"></i><h3>Accueil Principal</h3>' +
  2676. '<span class="infoGuestStatusLocal status' + statusID + '">[' + guestsList.statusPar[statusID] + ']</span>'+
  2677. '<p>Date de validation:</p></li>');
  2678. }else{
  2679. tx.executeSql("select distinct * from I42_INV_DATES_PRESENCE where ID_PART_A09=?;", [guestsList.id], function(tx, res) {
  2680. var tmpText = '<li><i class="fa fa-home homePrestation"></i><h3>Accueil Principal</h3>' +
  2681. '<span class="infoGuestStatusLocal status' + res.rows.item(res.rows.length-1).STATUTPART_A09 + '">[' + guestsList.statusPar[res.rows.item(res.rows.length-1).STATUTPART_A09] + ']</span>';
  2682. for (i = 0; i < res.rows.length; i++) {
  2683. var date = new Date(res.rows.item(i).DATE_PRESENCE);
  2684. if(date.getFullYear() < 2000){
  2685. tmpText += '<p>Date de validation:</p>';
  2686. }else{
  2687. tmpText += '<p>Date de validation: ' + date.getDate() + " " + monthsInYear[date.getMonth()] + " " + date.getFullYear() + '</p>';
  2688. }
  2689. }
  2690. tmpText += '</li>';
  2691. $('#guestDataPrestationsListLocal').append(tmpText);
  2692. });
  2693. }
  2694.  
  2695. tx.executeSql("select * from A07_INSCRIPTION as a left join A10_PRESTATION as b on a.PRESTATION_A10=b.ID where a.ID_PARTICIPANT=?;", [guestsList.id], function(tx, res) {
  2696. for (i = 0; i < res.rows.length; i++) {
  2697. var date2 = new Date(res.rows.item(i).DatePresence);
  2698. if(date2.getFullYear() < 2000){
  2699. $('#guestDataPrestationsListLocal').append('<li><i class="fa fa-ticket"></i><h3>' + res.rows.item(i).LIBELLE + '</h3>' +
  2700. '<span class="infoGuestStatusLocal status' + res.rows.item(i).ID_STATUT_A39 + '">[' + guestsList.statusPar[res.rows.item(i).ID_STATUT_A39] + ']</span>' +
  2701. '<p>Date de validation: </p></li>');
  2702.  
  2703. }else{
  2704. $('#guestDataPrestationsListLocal').append('<li><i class="fa fa-ticket"></i><h3>' + res.rows.item(i).LIBELLE + '</h3>' +
  2705. '<span class="infoGuestStatusLocal status' + res.rows.item(i).ID_STATUT_A39 + '">[' + guestsList.statusPar[res.rows.item(i).ID_STATUT_A39] + ']</span>' +
  2706. '<p>Date de validation: ' + date2.getDate() + " " + monthsInYear[date2.getMonth()] + " " + date2.getFullYear() + '</p></li>');
  2707. }
  2708. }
  2709. $('#guestDataPrestationsListLocal').listview("refresh");
  2710. });
  2711. });
  2712. });
  2713. });
  2714. }
  2715. }
  2716.  
  2717. /********** #subregion LOCAL GUEST LIST OPTION PANEL *********/
  2718. $(document).on('vclick', '#guestsListLocalFooterBtnSearch', function(){
  2719. $.mobile.silentScroll(0);
  2720. setTimeout(function(){ dialogSearch.show(); }, 50);
  2721. guestsList.dialog = 2;
  2722.  
  2723.  
  2724. $('#searchForm').on('submit', function(event) {
  2725. event.preventDefault();
  2726.  
  2727. $('#searchField').blur();
  2728.  
  2729. setTimeout(function() {
  2730. $('#btnSearch').trigger( 'click' );
  2731. }, 50);
  2732. return false;
  2733. });
  2734. });
  2735.  
  2736. $(document).on('vclick', '#deleteBtnLocalSearchFilter', function() {
  2737. $('#guestsPageLocalSearchFilter').fadeOut("slow");
  2738. setTimeout(function(){
  2739. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  2740.  
  2741. if(prestations == "true" && guestsList.prestationId != 0){
  2742. db.transaction(function(tx) {
  2743. tx.executeSql("select a.*, b.ID_STATUT_A39 from A09_PARTICIPANT as a left join A07_INSCRIPTION as b on a.ID=b.ID_PARTICIPANT where PRESTATION_A10=? limit 100;", [guestsList.prestationId], function(tx, res) {
  2744. $("#guestsListLocal").empty();
  2745.  
  2746. for (i = 0; i < res.rows.length; i++) {
  2747. $('#guestsListLocal').append('<li><a href="" data-id="' +
  2748. res.rows.item(i).ID + '"><h3><i class="fa fa-user fa-2x"></i>' + res.rows.item(i).LastName + '</h3><p>' + res.rows.item(i).FirstName + '</p></a></li>');
  2749. }
  2750. guestsList.startRecord = 100;
  2751. guestsList.nbRecord = res.rows.length;
  2752.  
  2753. });
  2754. tx.executeSql("select count(*) as cnt from A09_PARTICIPANT as a left join A07_INSCRIPTION as b on a.ID=b.ID_PARTICIPANT where PRESTATION_A10=? limit 100;", [guestsList.prestationId], function(tx, res) {
  2755. guestsList.nbParticipants = res.rows.item(0).cnt;
  2756. document.getElementById("guestsPageLocalNbResults").innerHTML = guestsList.nbParticipants + " r\351sultat(s)";
  2757. });
  2758. setTimeout(function(){
  2759. $("#guestsListLocal").listview("refresh");
  2760. }, 50);
  2761. });
  2762. }
  2763. else
  2764. {
  2765. db.transaction(function(tx) {
  2766. tx.executeSql("select * from A09_PARTICIPANT limit 100;" + guestsList.startRecord + ";", [], function(tx, res) {
  2767. $("#guestsListLocal").empty();
  2768. for (i = 0; i < res.rows.length; i++) {
  2769. $('#guestsListLocal').append('<li><a href="" data-id="' +
  2770. res.rows.item(i).ID + '"><h3><i class="fa fa-user fa-2x"></i>' + res.rows.item(i).LastName + '<p>' + res.rows.item(i).FirstName + '</p></h3></a></li>');
  2771. }
  2772. $("#guestsListLocal").listview("refresh");
  2773. document.getElementById("guestsPageLocalNbResults").innerHTML = guestsList.nbParticipants + " r\351sultat(s)";
  2774. });
  2775. });
  2776. }
  2777. }, 200);
  2778. });
  2779.  
  2780. /***********************************************/
  2781. /********* #region Lazy Loading ********/
  2782. /***********************************************/
  2783. function addMore(page) {
  2784. if(page[0].id == "guestsPage" && guestsList.dialog != 6){
  2785. if(guestsList.list.length == guestsList.startRecord){
  2786. $.mobile.loading("show", {
  2787. text: "Chargement...",
  2788. textVisible: true,
  2789. theme: "b"
  2790. });
  2791.  
  2792. guestsList.startRecord++;
  2793. if(guestsList.prestations){
  2794. var fullURLGet = 'methods/MobileApp/GetParticipants?id=' + guestsList.prestationId + '&idManif=' + guestsList.eventId + '&Prestation=true&StartRecord=' + guestsList.startRecord + '&RecordsCount=100';
  2795.  
  2796. $.ajax({
  2797. type: 'GET',
  2798. url: url + fullURLGet,
  2799. crossDomain: true,
  2800. headers: {'AgoraEvent-Token': ApiToken},
  2801. success: function (result) {
  2802. guestsList.startRecord += 100;
  2803. guestsList.list = guestsList.list.concat(result);
  2804.  
  2805. $.each(result, function(i, row) {
  2806. $('#guestsList').append('<li><a href="" data-id="' +
  2807. row.ID + '"><h3><i class="fa fa-user fa-2x"></i>' + row.LastName + '<p>' + row.FirstName +
  2808. '<span class="statusListView status' + row.StatusID + ' ">[' + guestsList.statusPar[row.StatusID] + ']</span></p></h3></a></li>');
  2809. });
  2810. $('#guestsList').listview('refresh');
  2811. $.mobile.loading("hide");
  2812. },
  2813. error: function (request,error) {
  2814. $.mobile.loading("hide");
  2815. if(request.status == 401){
  2816. // Unauthorized
  2817. navigator.notification.alert(
  2818. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  2819. alertDismissed,
  2820. "Notification",
  2821. "Ok"
  2822. );
  2823. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  2824. }
  2825. navigator.notification.alert(
  2826. "Erreur lors du chargement des invit\351s",
  2827. alertDismissed,
  2828. "Notification",
  2829. "Ok"
  2830. );
  2831. }
  2832. });
  2833. }
  2834. else{
  2835. $.ajax({
  2836. type: 'GET',
  2837. url: url + 'methods/MobileApp/GetParticipants?id=' + guestsList.eventId + '&StartRecord=' + guestsList.startRecord + '&RecordsCount=100',
  2838. crossDomain: true,
  2839. headers: {'AgoraEvent-Token': ApiToken},
  2840. success: function (result) {
  2841. guestsList.startRecord += 100;
  2842. guestsList.list = guestsList.list.concat(result);
  2843.  
  2844. $.each(result, function(i, row) {
  2845. $('#guestsList').append('<li><a href="" data-id="' +
  2846. row.ID + '"><h3><i class="fa fa-user fa-2x"></i>' + row.LastName + '<p>' + row.FirstName +
  2847. '<span class="statusListView status' + row.StatusID + ' ">[' + guestsList.statusPar[row.StatusID] + ']</span></p></h3></a></li>');
  2848. });
  2849. $('#guestsList').listview('refresh');
  2850. $.mobile.loading("hide");
  2851. },
  2852. error: function (request,error) {
  2853. $.mobile.loading("hide");
  2854. if(request.status == 401){
  2855. // Unauthorized
  2856. navigator.notification.alert(
  2857. "Votre session a expir\351, veuillez-vous identifier \340 nouveau",
  2858. alertDismissed,
  2859. "Notification",
  2860. "Ok"
  2861. );
  2862.  
  2863. $.mobile.changePage( "#mainPage", { transition: "slide", reverse: true, changeHash: false });
  2864. }
  2865. navigator.notification.alert(
  2866. "Erreur lors du chargement des invit\351s",
  2867. alertDismissed,
  2868. "Notification",
  2869. "Ok"
  2870. );
  2871. }
  2872. });
  2873. }
  2874.  
  2875. }
  2876. }
  2877. else if(page[0].id == "guestsPageLocal" && guestsList.dialog != 6){
  2878. if(guestsList.nbRecord == guestsList.startRecord){
  2879. $.mobile.loading("show", {
  2880. text: "Chargement...",
  2881. textVisible: true,
  2882. theme: "b"
  2883. });
  2884.  
  2885. var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 2, createFromLocation: 1});
  2886.  
  2887. if(guestsList.prestations){
  2888. db.transaction(function(tx) {
  2889. tx.executeSql("select *, ID_STATUT_A39 from A09_PARTICIPANT as a left join A07_INSCRIPTION as b on a.ID=b.ID_PARTICIPANT where PRESTATION_A10=? limit " + guestsList.nbRecord + ", 100;", [guestsList.prestationId], function(tx, res) {
  2890. for (i = 0; i < res.rows.length; i++) {
  2891. $('#guestsListLocal').append('<li><a href="" data-id="' +
  2892. res.rows.item(i).ID + '"><h3><i class="fa fa-user fa-2x"></i>' + res.rows.item(i).LastName + '<p>' + res.rows.item(i).FirstName +
  2893. (res.rows.item(i).ID_STATUT_A39 == '3'? '<br/><span style="color: green;">Présent<span>' : '') + '</p></h3></a></li>');
  2894. }
  2895. $("#guestsListLocal").listview("refresh");
  2896. guestsList.startRecord += 100;
  2897. guestsList.nbRecord += res.rows.length;
  2898.  
  2899. $.mobile.loading("hide");
  2900. });
  2901. });
  2902. }
  2903. else{
  2904. db.transaction(function(tx) {
  2905. tx.executeSql("select * from A09_PARTICIPANT limit " + guestsList.nbRecord + ", 100;", [], function(tx, res) {
  2906. for (i = 0; i < res.rows.length; i++) {
  2907. $('#guestsListLocal').append('<li><a href="" data-id="' +
  2908. res.rows.item(i).ID + '"><h3><i class="fa fa-user fa-2x"></i>' + res.rows.item(i).LastName + '<p>' + res.rows.item(i).FirstName +
  2909. (res.rows.item(i).StatusID == '3'? '<br/><span style="color: green;">Présent<span>' : '')
  2910. + '</p></h3></a></li>');
  2911. }
  2912.  
  2913. $("#guestsListLocal").listview("refresh");
  2914. guestsList.startRecord += 100;
  2915. guestsList.nbRecord += res.rows.length;
  2916.  
  2917. $.mobile.loading("hide");
  2918. });
  2919. });
  2920. }
  2921. }
  2922. }
  2923. }
  2924.  
  2925. /* scroll event */
  2926. $(document).on("scrollstop", function (e) {
  2927. var activePage = $.mobile.pageContainer.pagecontainer("getActivePage"),
  2928. screenHeight = $.mobile.getScreenHeight(),
  2929. contentHeight = $(".ui-content", activePage).outerHeight(),
  2930. scrolled = $(window).scrollTop(),
  2931. header = $(".ui-header", activePage).hasClass("ui-header-fixed") ? $(".ui-header", activePage).outerHeight() - 1 : $(".ui-header", activePage).outerHeight(),
  2932. footer = $(".ui-footer", activePage).hasClass("ui-footer-fixed") ? $(".ui-footer", activePage).outerHeight() - 1 : $(".ui-footer", activePage).outerHeight(),
  2933. scrollEnd = contentHeight - screenHeight + header + footer;
  2934. if ((activePage[0].id == "guestsPage" || activePage[0].id == "guestsPageLocal") && scrolled >= scrollEnd) {
  2935. addMore(activePage);
  2936. }
  2937. });
  2938.  
  2939. /***********************************************/
  2940. /*********** #region Swipe ******************/
  2941. /***********************************************/
  2942. $("#mainPage").swiperight(function() {
  2943. $.mobile.changePage("#mainPage", { transition: "slide", reverse: true, changeHash: false });
  2944. });
  2945.  
  2946. $("#infoGuestPage").swiperight(function() {
  2947. $.mobile.changePage("#guestsPage", { transition: "slide", reverse: true, changeHash: false });
  2948. });
  2949.  
  2950. $("#eventsPage").swiperight(function() {
  2951. $.mobile.changePage("#mainPage", { transition: "slide", reverse: true, changeHash: false });
  2952. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement