-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.html
928 lines (811 loc) · 45.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
<!DOCTYPE HTML>
<!--
*******************************************************************
* WebSqlApp is a local WebSQL DB (SQLite) CRUD application using jQuery Mobile for the UI.
* It also use WebSqlSync to sync to a server. This part is under development.
* Thanks to Adobe article (Store data in the HTML5 SQLite database) for the initial minimalist script. http://cookbooks.adobe.com/post_Store_data_in_the_HTML5_SQLite_database-19115.html
* Thanks to Samuel Michelot for webSqlSync.js https://github.com/orbitaloop/WebSqlSync
******************************************************************/
Usage: https://github.com/abeauseigle/webSqlApp
Copyright (c) 2013, Alain Beauseigle of AffairesUP.com (R&D tax credit expert in QC, Canada)
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<head>
<title>HTML5 WebSQLApp</title>
<!-- Fonctionnal but the jtsage calendar doesn't work -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<link rel="stylesheet" href="css/jquery.ui.datepicker.mobile.css" />
<link rel="apple-touch-icon-precomposed" href="media/images/apple-touch-icon-precomposed.png" />
<!-- Bon pour Apple et aussi sur Android à notre grand plaisir -->
<!-- ToTry: Pour afficher son application en plein écran :
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-touch-fullscreen" content="yes">
<!-- ToTry: Pour choisir le style de la barre de statut sur iPhone :
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!-- ToTry: Pour utiliser une image de chargement :
<link rel="apple-touch-startup-image" href="startup.png" />
-->
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript" src="lib/webSqlSync.js"></script>
<script type="text/javascript" src="mySyncData.js"></script>
<!-- <script type="text/javascript" src="mySyncScript.js"></script> -->
<!-- <script src="lib/jQuery.ui.datepicker.js"></script>
<script src="lib/jquery.ui.datepicker.mobile.js"></script> -->
<link rel="stylesheet" href="media/themes/Redtheme.min.css" />
<style type="text/css"> @import "media/css/table.css"; </style>
</head>
<body>
<!-- <form name="myForm" > -->
<div id="Liste">
<div data-role="header" >
<a href="#" onclick="return hideShow('Ajout','Liste');" data-role="button" data-icon="plus" data-iconpos="notext" data-mini="true" data-inline="true" data-theme="a"></a>
<h1>Liste des activités</h1>
<a href="#" onclick="loadFiltreParam();" data-role="button" data-icon="search" data-iconpos="notext" data-mini="true" data-inline="true" data-theme="a"></a>
</div>
<table id="datatables" class="display">
<thead>
<tr class="odd">
<th>Edit</th>
<th>FirstName</th>
<th>Date de réalisation</th>
<th>LastName</th>
<th>CheckBox</th>
<th>Qty (0.00)</th>
<th>RadioButton ABC</th>
<th>UnitID</th>
<!-- <th>Delete</th> -->
</tr>
</thead>
<tbody id="listeItem"> </tbody>
<!-- <table id="listeItem"> </table> -->
</table>
<div id="uiProgress"> </div>
<div id="syncPushOnlyTestResponse"> syncPushOnlyTest: </div>
<div id="syncPullOnlyTestResponse"> syncPullOnlyTest: </div>
<div id="syncPushPingTestResponse"> syncPushPingTest: </div>
<div id="syncPushPullTestResponse"> syncPushPullTest: </div>
<div id="syncUploadUnitsResponse"> syncUploadUnits : </div>
<div data-role="footer" >
<a href="#" onclick="loadLoginParam();" data-role="button" data-icon="gear" data-iconpos="left" data-mini="true" data-inline="true" data-theme="a">Paramètres</a>
<a href="#" onclick="dropTables();" data-role="button" data-icon="delete" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a">Drop tables</a>
<a href="#" onclick="syncPushOnlyTest();" data-role="button" data-icon="refresh" data-iconpos="left" data-mini="true" data-inline="true" data-theme="a">SyncPushOnlyTest</a>
<a href="#" onclick="syncPullOnlyTest();" data-role="button" data-icon="refresh" data-iconpos="left" data-mini="true" data-inline="true" data-theme="a">SyncPullOnlyTest</a>
<a href="#" onclick="syncPushPingTest();" data-role="button" data-icon="refresh" data-iconpos="left" data-mini="true" data-inline="true" data-theme="a">SyncPushPingTest</a>
<a href="#" onclick="syncPushPullTest();" data-role="button" data-icon="refresh" data-iconpos="left" data-mini="true" data-inline="true" data-theme="a">SyncPushPullTest</a>
<a href="#" onclick="sqlWebSyncTest();" data-role="button" data-icon="refresh" data-iconpos="left" data-mini="true" data-inline="true" data-theme="a">sqlWebSyncTest</a>
</div>
</div>
<div id="Ajout" style="display:none">
<div data-role="header">
<a href="#" onclick="return hideShow('Liste','Ajout');" data-role="button" data-icon="home" data-inline="true" data-iconpos="notext" data-theme="a" ></a>
<h1>Activité - Ajout </h1>
</div><!-- /header -->
<div data-role="content">
<input type="hidden" id="idAdd"/>
First name:<input type="text" name="firstNameAdd" id="firstNameAdd"/>
Last name:<input type="text" name="lastNameAdd" id="lastNameAdd"/>
Quantité: <input type="text" name="qteAdd" id="qteAdd"/>
Unité: <select name="uniteIdAdd" id="uniteSelectAdd" value=""> </select>
<label for="MaJdateAdd">Date:</label>
<!-- <input type="date" name="MaJdate" id="MaJdate" data-role="datebox" data-options='{"mode":"calbox", "calStartDay": 1, "highDays": [6,5]}' value="" /> -->
<!-- <input type="text" name="MaJdateAdd" id="MaJdateAdd" data-role="datebox" > data-options="{"mode":"calbox"}" class="ui-input-text ui-body-d ui-corner-all ui-icon-datebox" -->
<input type="date" name="MaJdateAdd" id="MaJdateAdd" value="" > <!-- data-options="{"mode":"calbox"}" class="ui-input-text ui-body-d ui-corner-all ui-icon-datebox" -->
<label><input type="checkbox" name="cbFaitAdd" id="cbFaitAdd" value="" /> Fait </label>
<fieldset data-role="controlgroup" data-type="horizontal"> <!-- "vertical" -->
<legend>Radio ABC:</legend>
<input type="radio" name="rbABCAdd" id="rbABCAdd1" value="A" /> <!-- checked="checked" -->
<label for="rbABCAdd1">A</label>
<input type="radio" name="rbABCAdd" id="rbABCAdd2" value="B" />
<label for="rbABCAdd2">B</label>
<input type="radio" name="rbABCAdd" id="rbABCAdd3" value="C" />
<label for="rbABCAdd3">C</label>
</fieldset>
</div><!-- /content -->
<div data-role="footer" >
<a href="#" onClick="insertContact();" data-role="button" data-icon="plus" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a">Ajouter</a>
<a href="#" onClick="resetForm();" data-role="button" data-icon="minus" data-iconpos="right" data-mini="true" data-inline="true" data-theme="a">Reset Form</a>
</div>
</div>
<div id="Edit" style="display:none">
<div data-role="header">
<a href="#" onclick="return hideShow('Liste','Edit');" data-role="button" data-icon="home" data-inline="true" data-iconpos="notext" data-theme="a"></a>
<h1>Activité - Edit </h1>
</div><!-- /header -->
<div data-role="content">
<input type="hidden" id="idEdit"/>
First name:<input type="text" name="firstNameEdit" id="firstNameEdit"/>
Last name:<input type="text" name="lastNameEdit" id="lastNameEdit"/>
Quantité: <input type="text" name="qteEdit" id="qteEdit"/>
Unité: <select name="uniteIdEdit" id="uniteSelectEdit" > </select>
Date: <input type="date" name="MaJdateEdit" id="MaJdateEdit"/>
<!-- Fait: <input type="checkbox" name="cbFaitEdit" id="cbFaitEdit" checked="" value="">Cochez si réalisé -->
<label><input type="checkbox" name="cbFaitEdit" id="cbFaitEdit" checked="" value="" /> Fait </label>
<fieldset data-role="controlgroup" data-type="vertical">
<legend>Radio ABC:</legend>
<input type="radio" name="rbABCEdit" id="rbABCEdit1" value="A" />
<label for="rbABCEdit1">A</label>
<input type="radio" name="rbABCEdit" id="rbABCEdit2" value="B" />
<label for="rbABCEdit2">B</label>
<input type="radio" name="rbABCEdit" id="rbABCEdit3" value="C" />
<label for="rbABCEdit3">C</label>
</fieldset>
<div data-role="footer" >
<a href="#" onClick="updateContact();" data-role="button" data-icon="plus" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a">Modifier</a>
<a href="#" onClick="dropTables();" data-role="button" data-icon="minus" data-iconpos="right" data-mini="true" data-inline="true" data-theme="a">Reset Form</a>
</div>
</div>
</div>
<div id="Filtre" style="display:none">
<div data-role="header">
<a href="#" onclick="return hideShow('Liste','Filtre');" data-role="button" data-icon="home" data-inline="true" data-iconpos="notext" data-theme="a" ></a>
<h1>Activité - Filtre </h1>
</div><!-- /header -->
<div data-role="content">
First name:<input type="text" name="firstNameFiltre" id="firstNameFiltre"/>
Last name:<input type="text" name="lastNameFiltre" id="lastNameFiltre"/>
Quantité: <input type="text" name="qteFiltre" id="qteFiltre"/>
Unité: <select name="uniteIdFiltre" id="uniteSelectFiltre" > </select>
<label for="MaJdateFiltre">Date:</label>
<input type="date" name="MaJdateFiltre" id="MaJdateFiltre" value"" />
<label><input type="checkbox" name="cbFaitFiltre" id="cbFaitFiltre" value="" /> Fait </label>
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>Radio ABC:</legend>
<input type="radio" name="rbABCFiltre" id="rbABCFiltre0" value="" />
<label for="rbABCFiltre0">None</label>
<input type="radio" name="rbABCFiltre" id="rbABCFiltre1" value="A" />
<label for="rbABCFiltre1">A</label>
<input type="radio" name="rbABCFiltre" id="rbABCFiltre2" value="B" />
<label for="rbABCFiltre2">B</label>
<input type="radio" name="rbABCFiltre" id="rbABCFiltre3" value="C" />
<label for="rbABCFiltre3">C</label>
</fieldset>
<div data-role="footer" >
<a href="#" onClick="updateFiltreParam();" data-role="button" data-icon="plus" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a">Filtrer</a>
<a href="#" onClick="dropTables();" data-role="button" data-icon="delete" data-iconpos="right" data-mini="true" data-inline="true" data-theme="a">Reset Form</a>
</div>
</div>
</div>
<div id="LoginParamEdit" style="display:none">
<div data-role="header">
<a href="#" onclick="return hideShow('Liste','LoginParamEdit');" data-role="button" data-icon="home" data-inline="true" data-iconpos="notext" data-theme="a"></a>
<h1>Login - Parameters </h1>
</div><!-- /header -->
<div data-role="header">
<p>Modify your connexion parameters to the server</p>
</div><!-- /header -->
<div data-role="content">
<input type="hidden" id="idUser"/>
User ID : <input type="text" name="userIdEdit" id="userIdEdit"/>
Password: <input type="password" name="userPasswordEdit" id="userPasswordEdit"/>
Email : <input type="email" name="userEmailEdit" id="userEmailEdit"/>
<div data-role="footer" >
<a href="#" onClick="updateLoginParam();" data-role="button" data-icon="plus" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a">Modifier</a>
</div>
</div>
</div>
<!-- </form> -->
</body>
<script>
function hideShow(shown, hidden) {
document.getElementById(shown).style.display='block';
document.getElementById(hidden).style.display='none';
return false;
}
var liste = document.getElementById('liste');
var idAdd = document.getElementById('idAdd');
var firstNameAdd = document.getElementById('firstNameAdd');
var lastNameAdd = document.getElementById('lastNameAdd');
var qteAdd = document.getElementById('qteAdd');
var currentDate = new Date(); // pour que l'objet MaJdate soit de type date pour JS
var currentDateISO = currentDate.toISOString().substring(0, 10); // converts a Date object into a string, using the ISO-8601 and the format is: YYYY-MM-DDTHH:mm:ss.sssZ
document.getElementById("MaJdateAdd").value=currentDateISO; // populate le HTML5 INPUT date de Ajout avec la date d'aujourd'hui
var MaJdateEdit = new Date(); // pour que l'objet MaJdateEdit soit de type date pour JS
var MaJdateFiltre = new Date(); // pour que l'objet MaJdateFiltre soit de type date pour JS
var MaJdateFiltreNew = "";
var cbFaitAdd = document.getElementById("cbFaitAdd").checked=false; //
var cbFaitEdit = "";
var cbFaitFiltre = "";
var rbABCAdd = new Array();
var rbABCEdit = new Array(); //utile?
//var rbABCEditSel = new Array(); //Alone
var rbABCFiltre = new Array();
var uniteIdAdd = document.getElementById('uniteSelectAdd'); // Déclare unitIdAdd servant à obtenir l'option sélectionnée du sélect
var uniteIdEdit = document.getElementById('uniteSelectEdit'); //
var uniteIdFiltre = document.getElementById('uniteSelectFiltre'); //
var sqlCreateTableUnites = "CREATE TABLE IF NOT EXISTS Unites (UniteID INTEGER PRIMARY KEY AUTOINCREMENT, UniteSymbol TEXT)";
var sqlCreateTableContacts = "CREATE TABLE IF NOT EXISTS Contacts (id INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT, lastName TEXT, qte TEXT, MaJdate TEXT, cbFait TEXT, rbABC TEXT, UniteID INTEGER)";
var sqlCreateTableFiltreParam = "CREATE TABLE IF NOT EXISTS FiltreParam (id INTEGER PRIMARY KEY AUTOINCREMENT, firstNameFP TEXT, lastNameFP TEXT, qteFP TEXT, MaJdateFP TEXT, cbFaitFP TEXT, rbABCFP TEXT, uniteIdFP INTEGER)";
var sqlCreateTableUserParam = "CREATE TABLE IF NOT EXISTS UserParam (id INTEGER PRIMARY KEY AUTOINCREMENT, userId TEXT, password TEXT, email TEXT)";
var sqlSelectAllContacts = "SELECT * FROM Contacts";
var sqlSelectFilteredContacts = "";
var sqlSelectFiltreParam = "SELECT * FROM FiltreParam"; //not used
var sqlSelectAllUnites = "SELECT * FROM Unites"; //not used
var sqlInsertContact = "INSERT INTO Contacts (firstName, lastName, qte, MaJdate, cbFait, rbABC, UniteID) VALUES (?, ?, ?, ?, ?, ?)";
var sqlUpdateContact = "UPDATE Contacts SET firstName = ?, lastName = ?, qte = ?, MaJdate = ?, cbFait = ?, rbABC = ?, UniteID = ? WHERE id = ?";
var sqlUpdateFiltreParam = "UPDATE FiltreParam SET firstNameFP = ?, lastNameFP = ?, qteFP = ?, MaJdateFP = ?, cbFaitFP = ?, rbABCFP = ?, uniteIdFP = ? WHERE id = 1";
var sqlUpdateUserParam = "UPDATE UserParam SET userId = ?, password = ?, email = ? WHERE id = 1";
var deleteContact = "DELETE FROM Contacts WHERE id=?";
var sqlDropContact = "DROP TABLE Contacts";
var sqlDropUnites = "DROP TABLE Unites";
var sqlDropFiltreParam = "DROP TABLE FiltreParam";
var sqlDropUserParam = "DROP TABLE UserParam";
var sqlDrop_new_elem = "DROP TABLE new_elem";
var sqlDrop_sync_info = "DROP TABLE sync_info";
var dataset;
var mywebdb = openDatabase("AddressBook", "1.0", "Address Book", 2 * 1024 * 1024);
createTable(); // To create all tables for the web app
// This function is for the first sync. It create the new_elem and the sync_info tables
// It uses mySyncData to feed the parameters, but not le database object parameter,
// because, it doesn't work via SYNCDATA.database that seems require a string.
// syncFirst(); // To initialyse the tables to sync with webSqlSync.js // After, go to syncFirst to do the first sync to the server to populate web app tables.
//DBSYNC.initSync(SYNCDATA.tableToSync, SYNCDATA.database, SYNCDATA.sync_info, SYNCDATA.url, function(result){ // SYNCDATA.database seems not working // Parameters are defined in mySyncData.js
syncDownloadUnits(); // It will insert a row with a -1 id to have a first id to 0 like MySQL.
mywebdb.transaction(function(tx) {
tx.executeSql("DELETE FROM Unites WHERE UniteID= -1"); // We must insert at least one row in the DB. Strange! Then we can delete our -1 row.
});
/*
DBSYNC.initSync(SYNCDATA.tableToSync, mywebdb, SYNCDATA.sync_info, SYNCDATA.url, function(result) { // Parameters are defined in mySyncData.js
//syncFirst();
if (result.syncOK === true) {
alert("first initSync done successfully");
}
});
*/
loadUniteSelect();
loadUniteSelectEdit();
loadUniteSelectFiltre();
function onError(tx, error) {
alert(error.message);
}
function showContacts() {
listeItem.innerHTML = '';
mywebdb.transaction(function(tx) {
tx.executeSql(sqlSelectAllContacts, [], function(tx, result) {
dataset = result.rows;
for (var i = 0, item = null; i < dataset.length; i++) {
item = dataset.item(i);
listeItem.innerHTML +=
'<tr>'
// + '<td><a href="#" onclick="loadContact('+i+')" data-role="button" data-icon="arrow-r" data-mini="true" data-inline="true" data-iconpos="notext" data-theme="b" ></a></td>'
+ '<td><a href="#" onclick="loadContact(' + i + ')" data-role="button" data-icon="arrow-r">Edit</a></td>'
+ '<td>' + item['firstName'] + '</td>'
+ '<td>' + item['MaJdate'] + '</td>'
+ '<td>' + item['lastName'] + '</td>'
+ '<td>' + item['cbFait'] + '</td>'
+ '<td>' + item['qte'] + '</td>'
+ '<td>' + item['rbABC'] + '</td>'
+ '<td>' + item['UniteID'] + '</td>'
// + '<td><a href="#" onclick="deleteRecord('+item['id']+')" data-role="button" data-icon="minus" data-mini="true" data-inline="true" data-iconpos="notext" data-theme="b" ></a></td>'
+ '</tr>';
}
});
});
}
/* Trial to generalize the 3 following functions
// Usage: SbId = id of the selectbox in the form EX: "ClientSelectboxAdd", "ClientSelectboxEdit", or "ClientSelectboxFilter"
// SbQuery = A string for the DB query to use for this select Ex: "SELECT ClientId, ClientName FROM Clients"
// SbChooseOption = A string for a "Choose" line Ex: -- Choose an options --
// TableIndexField = A string for the table index to store in the DB Ex: "ClientId"
// SbOptionsDbField1 = A string for a DB column to show in the option line Ex: "ClientName"
// SbOptionsDbField2 (optionnal) = A string for the 2nd DB column to show in the option line Ex: "ProjectName"
// SbOptionsDbField3 (optionnal) = A string for the 3rd DB column to show in the option line Ex: "RessourceName"
function loadSelectbox(SbId, SbQuery, DbIndex, SbChooseOption, SbOptionsDbField1, SbOptionsDbField2, SbOptionsDbField3) {
mywebdb.transaction(function (tx) {
//populate drop down for unites
tx.executeSql('SbQuery', [], function (tx, results) {
var len = results.rows.length;
var i=0;
if (SbChooseOption == "") {txt="";} else {var txt="<option value='0'>" + SbChooseOption + "</option>";}
for (i = 0; i < len; i++){
??? DbField1 = results.rows.item(i).[SbOptionsDbField1] // how to do this???
??? DbField2 = results.rows.item(i).[SbOptionsDbField2] // how to do this???
??? DbField3 = results.rows.item(i).[SbOptionsDbField3] // how to do this???
??? txt += "<option value=" + TableIndexField + ">" + DbField1 + " - " + DbField2 + " - " + DbField3 + "</option>";
//to replace: txt += "<option value=" + results.rows.item(i).UniteID + ">" + results.rows.item(i).UniteID + " " + "Catégorie" + " - " + results.rows.item(i).UniteSymbol + "</option>";
}
document.getElementById(SbId).innerHTML=txt;
}, null);
});
}
*/
function loadUniteSelect() {
mywebdb.transaction(function (tx) {
//populate drop down for unites
tx.executeSql('SELECT * FROM Unites', [], function (tx, results) {
var len = results.rows.length;
var i=0;
//var txt="";
var txt="<option value='0'>--Choisir une unité--</option>";
for (i = 0; i < len; i++){
txt=txt + "<option value=" + results.rows.item(i).UniteID + ">" + results.rows.item(i).UniteID + " " + "Catégorie" + " - " + results.rows.item(i).UniteSymbol + "</option>";
}
document.getElementById("uniteSelectAdd").innerHTML=txt;
}, null);
});
}
function loadUniteSelectEdit() {
mywebdb.transaction(function (tx) {
//populate drop down for unites
tx.executeSql('SELECT * FROM Unites', [], function (tx, results) {
var len = results.rows.length;
var i=0;
var txt="";
for (i = 0; i < len; i++){
txt=txt + "<option value=" + results.rows.item(i).UniteID + ">" + results.rows.item(i).UniteID + " " + "Catégorie" + " - " + results.rows.item(i).UniteSymbol + "</option>";
}
document.getElementById("uniteSelectEdit").innerHTML=txt;
}, null);
});
}
function loadUniteSelectFiltre() {
mywebdb.transaction(function (tx) {
//populate drop down for unites
tx.executeSql('SELECT * FROM Unites', [], function (tx, results) {
var len = results.rows.length;
var i=0;
var txt="";
var txt="<option value='0'>--Toutes les unités--</option>";
for (i = 0; i < len; i++){
txt=txt + "<option value=" + results.rows.item(i).UniteID + ">" + results.rows.item(i).UniteID + " " + "Catégorie" + " - " + results.rows.item(i).UniteSymbol + "</option>";
}
document.getElementById("uniteSelectFiltre").innerHTML=txt;
}, null);
});
}
function getRadioVal(radioName) {
var rads = document.getElementsByName(radioName);
for(var rad in rads) {
if(rads[rad].checked)
return rads[rad].value;
}
return null;
}
function loadFiltreParam() {
mywebdb.transaction(function (tx) {
tx.executeSql('SELECT * FROM FiltreParam WHERE id=?', [1], function (tx, FPresult) {
//tx.executeSql('SELECT TOP 1 FROM FiltreParam', [], function (tx, FPresult) {
var lenFParam = FPresult.rows.length;
FPdataset = FPresult.rows;
FPitem = FPdataset.item(0);
firstNameFiltre.value = FPitem['firstNameFP'];
lastNameFiltre.value = FPitem['lastNameFP'];
qteFiltre.value = FPitem['qteFP'];
if (FPitem['MaJdateFP']!="" || FPitem['MaJdateFP']!="0001-01-01" ){ // How to empty the date field to not filter on date?
MaJdateStringFiltre = FPitem['MaJdateFP'];
//alert('MaJdateStringFiltre = ' + MaJdateStringFiltre ); // we get 2013-05-09, the filter date in the DB.
MaJdateFiltre = new Date(MaJdateStringFiltre); //
//alert('MaJdateFiltre = ' + MaJdateFiltre ); // we get a long date in ISO format.
MaJdateISOFiltre = MaJdateFiltre.toISOString().substring(0, 10);
//alert('MaJdateISOFiltre = ' + MaJdateISOFiltre );
document.getElementById("MaJdateFiltre").value=MaJdateISOFiltre; //
//alert('document.getElementById("MaJdateFiltre").value = ' + document.getElementById("MaJdateFiltre").value );
}
else {
document.getElementById("MaJdateFiltre").value=""; //
//alert('document.getElementById("MaJdateFiltre").value = ' + document.getElementById("MaJdateFiltre").value );
}
cbFaitFiltre = FPitem['cbFaitFP'];
if(cbFaitFiltre=="1"){ document.getElementById("cbFaitFiltre").checked=true;}
$('#cbFaitFiltre').checkboxradio('refresh');
rbABCFiltre = FPitem['rbABCFP'];
var eleFiltre = document.getElementsByName("rbABCFiltre");
for(var i=0;i<eleFiltre.length;i++){
if(eleFiltre[i].value == rbABCFiltre) { eleFiltre[i].checked = true; }
//alert('eleFiltre i value = ' + eleFiltre[i].value + 'eleFiltre = ' + eleFiltre);
}
$('#rbABCFiltre').checkboxradio('refresh');
//uniteSelectFiltre.value = FPitem['uniteIdFP'];
var uniteSelectFiltre = $("#uniteSelectFiltre");
uniteSelectFiltre.val(FPitem['uniteIdFP']).attr('selected', true).siblings('option').removeAttr('selected');
uniteSelectFiltre.selectmenu('refresh');
$('#uniteSelectFiltre').selectmenu('refresh');
document.getElementById('Filtre').style.display='block';
document.getElementById('Liste').style.display='none';
}) // for tx.executeSql
}) // for mywebdb.transaction
}
function updateFiltreParam() {
MaJdateFiltreNew=document.getElementById("MaJdateFiltre").value; // It records the new date in string formet like "2013-05-01"
//alert('MaJdateFiltreNew=document.getElementById("MaJdateFiltre").value = ' + document.getElementById("MaJdateFiltre").value ); // On obtient la nouvelle date 2013-05-01 OU? ""
// If we erase the date to not filter on the date.
if (document.getElementById("MaJdateFiltre").value=="" || document.getElementById("MaJdateFiltre").value == "0001-01-01")
{ MaJdateFiltreNew = "0001-01-01";}
else
{ MaJdateFiltreNew = document.getElementById("MaJdateFiltre").value;}
if(document.getElementById("cbFaitFiltre").checked){cbFaitFiltre="1";} else {cbFaitFiltre="0";} // Ça enregistre 1 si true et 0 si false dans la BD.
var rbABCFiltre = getRadioVal("rbABCFiltre");
var uniteIdFiltre=document.getElementById("uniteSelectFiltre").value;
mywebdb.transaction(function(tx) {
tx.executeSql(sqlUpdateFiltreParam, [firstNameFiltre.value, lastNameFiltre.value, qteFiltre.value, MaJdateFiltreNew, cbFaitFiltre, rbABCFiltre, uniteIdFiltre], filterRecords, onError);
});
//alert('MaJdateFiltreNew = ' + MaJdateFiltreNew.value );
}
function filterRecords() {
sqlSelectFilteredContacts = 'SELECT * FROM Contacts WHERE 1 = 1';
if (firstNameFiltre.value==""){ sqlSelectFilteredContacts += " AND 1 = 1 ";}
else{sqlSelectFilteredContacts += ' AND firstName = "' + firstNameFiltre.value +'"';}
if (lastNameFiltre.value==""){ sqlSelectFilteredContacts += " AND 1 = 1 ";}
else{sqlSelectFilteredContacts += ' AND lastName = "' + lastNameFiltre.value +'"';}
if (qteFiltre.value==""){ sqlSelectFilteredContacts += " AND 1 = 1 ";}
else{sqlSelectFilteredContacts += ' AND qte = ' + qteFiltre.value;}
// if (MaJdateFiltreNew.value=="0001-01-01"){ sqlSelectFilteredContacts += " AND 1 = 1 ";}
// else{sqlSelectFilteredContacts += ' AND MaJdate = "' + MaJdateFiltreNew +'"';} // Bug: It takes the today's date, how to desactivate the filter
if (uniteIdFiltre.value=="0"){ sqlSelectFilteredContacts += " AND 1 = 1 ";}
else{sqlSelectFilteredContacts += ' AND UniteID = "' + uniteIdFiltre.value +'"';}
if (document.getElementById("cbFaitFiltre").checked){sqlSelectFilteredContacts += ' AND cbFait = 1 ';}
else{ sqlSelectFilteredContacts += " AND 1 = 1 ";}
if (getRadioVal("rbABCFiltre")==""){ sqlSelectFilteredContacts += " AND 1 = 1 ";} //
else{sqlSelectFilteredContacts += ' AND rbABC = "' + getRadioVal("rbABCFiltre") +'"';}
alert('sqlSelectFilteredContacts = ' + sqlSelectFilteredContacts );
showFilteredRecords();
}
function showFilteredRecords() {
listeItem.innerHTML = '';
mywebdb.transaction(function(tx) {
tx.executeSql(sqlSelectFilteredContacts, [], function(tx, result) {
dataset = result.rows;
for (var i = 0, item = null; i < dataset.length; i++) {
item = dataset.item(i);
listeItem.innerHTML +=
'<tr>'
// + '<td><a href="#" onclick="loadContact('+i+')" data-role="button" data-icon="arrow-r" data-mini="true" data-inline="true" data-iconpos="notext" data-theme="b" ></a></td>'
+ '<td><a href="#" onclick="loadContact(' + i + ')" data-role="button" data-icon="arrow-r">Edit</a></td>'
+ '<td>' + item['firstName'] + '</td>'
+ '<td>' + item['MaJdate'] + '</td>'
+ '<td>' + item['lastName'] + '</td>'
+ '<td>' + item['cbFait'] + '</td>'
+ '<td>' + item['qte'] + '</td>'
+ '<td>' + item['rbABC'] + '</td>'
+ '<td>' + item['UniteID'] + '</td>'
// + '<td><a href="#" onclick="deleteRecord('+item['id']+')" data-role="button" data-icon="minus" data-mini="true" data-inline="true" data-iconpos="notext" data-theme="b" ></a></td>'
+ '</tr>';
}
});
});
hideShow('Liste','Filtre');
}
function insertContact() {
var dateStringAdd = document.getElementById("MaJdateAdd").value;
//alert(getRadioVal("rbABCAdd"));
var rbABCAdd = getRadioVal("rbABCAdd"); // to replace eventualy
//$('input[@name="rbABCAdd"]:checked').val(); // en jQuery, to try et enlever la fonction getRadioVal.
if(document.getElementById("cbFaitAdd").checked){cbFaitAdd="1";} else {cbFaitAdd="0";}; // Ça enregistre i si true et 0 si false dans la BD
var uniteIdAdd=document.getElementById("uniteSelectAdd").value; // Ça marche
mywebdb.transaction(function(tx) {
tx.executeSql("INSERT INTO Contacts (firstName, lastName, qte, MaJdate, cbFait, rbABC, uniteId) VALUES (?, ?, ?, ?, ?, ?, ?);",
[firstNameAdd.value, lastNameAdd.value, qteAdd.value, dateStringAdd, cbFaitAdd, rbABCAdd, uniteIdAdd], resetFormAndShow, onError);
});
hideShow('Liste','Ajout');
}
function resetFormAndShow(){
resetForm();
showContacts();
}
function resetForm(){
idAdd.value = '';
firstNameAdd.value = '';
lastNameAdd.value = '';
qteAdd.value = '';
var currentDate = new Date(); // to be sure that the object MaJdate could be a JS date type
var currentDateISO = currentDate.toISOString().substring(0, 10); // converts a Date object into a string, using the ISO-8601 and the format is: YYYY-MM-DDTHH:mm:ss.sssZ
document.getElementById("MaJdateAdd").value=currentDateISO; // populate the HTML5 INPUT date of Ajout with the today's date
$('#cbFaitAdd').attr('checked', false).checkboxradio('refresh');
//$("#cbFaitEdit").prop("checked", false).checkboxradio("refresh" );
//document.getElementById("cbFait").checked=false;
//document.getElementById("cbFaitEdit").checked=false;
var rbElem = document.getElementsByName("rbABCAdd");
for(var i=0;i<rbElem.length;i++){ // put all bottons to false, if not, we will have many radio buttons to true
var rbIdN = "rbABCAdd";
var IdN = i + 1;
rbIdN += IdN;
$('#' + rbIdN).prop('checked', false).checkboxradio("refresh"); //Since the radio buttons are decorated by jQuery Mobile you need to refresh it if you change them
}
document.getElementById("uniteSelectAdd").options[0].selected=true;
}
function loadContact(i) {
var itemSel = dataset.item(i);
idEdit.value = itemSel['id'];
firstNameEdit.value = itemSel['firstName'];
lastNameEdit.value = itemSel['lastName'];
qteEdit.value = itemSel['qte'];
MaJdateStringEdit = itemSel['MaJdate'];
MaJdateEdit = new Date(MaJdateStringEdit); //
MaJdateISOEdit = MaJdateEdit.toISOString().substring(0, 10);
document.getElementById("MaJdateEdit").value=MaJdateISOEdit; //
cbFaitEdit = itemSel['cbFait'];
if(cbFaitEdit=="1"){ $('#cbFaitEdit').prop('checked',true).checkboxradio('refresh');}
else{ $('#cbFaitEdit').prop('checked',false).checkboxradio('refresh');}
var rbABCdbValue = itemSel['rbABC'];
var rbElem = document.getElementsByName("rbABCEdit");
for(var i=0;i<rbElem.length;i++){ // Put all bottons to false
var rbIdN = "rbABCEdit";
var IdN = i + 1;
rbIdN += IdN;
if(rbElem[i].value == rbABCdbValue) {
$('#' + rbIdN).prop('checked', true).checkboxradio("refresh"); //Since the radio buttons are decorated by jQuery Mobile you need to refresh it if you change them
}
else {
$('#' + rbIdN).prop('checked', false).checkboxradio("refresh"); //Since the radio buttons are decorated by jQuery Mobile you need to refresh it if you change them
}
}
var uniteSelectEdit = $("#uniteSelectEdit");
uniteSelectEdit.val(itemSel['UniteID']).attr('selected', true).siblings('option').removeAttr('selected');
uniteSelectEdit.selectmenu('refresh');
$('#uniteSelectEdit').selectmenu('refresh');
hideShow('Edit','Liste');
}
// ref: http://www.intelligrape.com/blog/2012/09/23/dynamically-changing-select-value-of-jquery-mobile-select-box/
/*
function setOptionValue(value){
var reminderSettings = $("#reminderSettings");
reminderSettings.val(value).attr('selected', true).siblings('option').removeAttr('selected');
}
*/
function updateContact() {
var MaJdateEdit=document.getElementById("MaJdateEdit").value; // Ça enregistre la nouvelle date en formet string "2013-05-02"
//var dateStringEdit = document.getElementById("MaJdate").value; // inutile???
if(document.getElementById("cbFaitEdit").checked){cbFaitEdit="1";} else {cbFaitEdit="0";} // Ça enregistre 1 si true et 0 si false dans la BD. :-)
var rbABCEdit = getRadioVal("rbABCEdit");
//$('input[@name="rbABCEdit"]:checked').val(); // in jQuery. to try and remove the fonction getRadioVal.
var uniteIdEdit=document.getElementById("uniteSelectEdit").value;
mywebdb.transaction(function(tx) {
tx.executeSql(sqlUpdateContact, [firstNameEdit.value, lastNameEdit.value, qteEdit.value, MaJdateEdit, cbFaitEdit, rbABCEdit, uniteIdEdit, idEdit.value], resetFormAndShow, onError);
});
hideShow('Liste','Edit');
}
function loadLoginParam() {
mywebdb.transaction(function (tx) {
// To try: tx.executeSql('SELECT TOP 1 FROM UserParam', [], function (tx, UPresult) {
tx.executeSql('SELECT * FROM UserParam WHERE id=?', [1], function (tx, UPresult) {
// var lenUParam = UPresult.rows.length;
dataset = UPresult.rows;
loginParam = dataset.item(0);
userIdEdit.value = loginParam['userId'];
userPasswordEdit.value = loginParam['password'];
userEmailEdit.value = loginParam['email'];
}) // for tx.executeSql
}); // for mywebdb.transac
hideShow('LoginParamEdit','Liste');
}
function updateLoginParam() {
mywebdb.transaction(function(tx) {
//tx.executeSql(sqlUpdateUserParam, [userIdEdit.value, passwordEdit.value, emailEdit.value], hideShow('Liste','Edit'), onError);
tx.executeSql(sqlUpdateUserParam, [userIdEdit.value, userPasswordEdit.value, userEmailEdit.value]);
});
hideShow('Liste','LoginParamEdit');
}
function deleteRecord(id) {
mywebdb.transaction(function(tx) {
tx.executeSql(deleteContact, [id], showContacts, onError);
});
resetForm();
}
// test to know if the server accept a json from the webSqlApp
// using an Ajax request (just to know if the server config is OK)
function syncPushOnlyTest() {
myURL = 'http://www.mysite.com/webSqlApp/syncPushOnlyTest.php'; //___________
myObject = '{"result":"OK","message":"this is a positive reply","sync_date":1371753757,"data":[{"UniteID":"0","UniteSymbol":"h"},{"UniteID":"1","UniteSymbol":"km"},{"UniteID":"2","UniteSymbol":"$"},{"UniteID":"3","UniteSymbol":"U$"},{"UniteID":"4","UniteSymbol":"\u20ac"},{"UniteID":"5","UniteSymbol":"$P"}]}';
var str_json = JSON.stringify(myObject)
var request= new window.XMLHttpRequest();
request.overrideMimeType = 'application/json;charset=UTF-8';
request.open("POST", myURL,true);
request.setRequestHeader("Content-type", "application/json");
request.send(str_json);
$('#syncPushOnlyTestResponse').html("SyncPushOnlyTest done ");
alert("SyncPush is a Success " + myObject);
}
// test to know if the server can send a json to the webSqlApp using webSyncHandler.php
// syncPullOnlyTest.php return a json that the data comes from a mySQL query
// It uses jQuery to request the json (just to know if the server config is OK)
function syncPullOnlyTest() {
$.getJSON('http://www.mywebsite.com/webSqlApp/syncPullOnlyTest.php',
function(myJsonObject) {
alert(myJsonObject.result);
alert(myJsonObject.message);
alert(myJsonObject.sync_date);
alert(myJsonObject.data[2].UniteID);
alert(myJsonObject.data[2].UniteSymbol);
$('#syncPullOnlyTestResponse').append(myJsonObject.data[4].UniteSymbol);
}
);
//alert("SyncPull is a Success " + myJsonObject.data[4].UniteSymbol); // this line doesn't works.
}
// test to know if the server accept a json from the webSqlApp and if it return a json from a MySQL query
// using an Ajax request (just to know if the server config is OK)
function syncPushPingTest() {
myURL = 'http://www.mywebsite.com/webSqlApp/syncPushOnlyTest.php'; //___________
myObject = '{"result":"OK","message":"this is a positive reply","sync_date":1371753757,"data":[{"UniteID":"0","UniteSymbol":"h"},{"UniteID":"1","UniteSymbol":"km"},{"UniteID":"2","UniteSymbol":"$"},{"UniteID":"3","UniteSymbol":"U$"},{"UniteID":"4","UniteSymbol":"\u20ac"},{"UniteID":"5","UniteSymbol":"$P"}]}';
var str_json = JSON.stringify(myObject)
var request= new window.XMLHttpRequest();
request.overrideMimeType = 'application/json;charset=UTF-8';
request.open("POST", myURL,true);
request.setRequestHeader("Content-type", "application/json");
request.send(str_json);
$('#syncPushPingTestResponse').html("syncPushPingTest done, ");
//alert("SyncPush is a Success ");
// get feedback proving that the server got the data: get the sent data from the server
$.getJSON('http://www.mywebsite.com/webSqlApp/syncPullOnlyTest.php',
function(myJsonObject) {
alert(myJsonObject.result);
alert(myJsonObject.message);
alert(myJsonObject.sync_date);
alert(myJsonObject.data[2].UniteID);
alert(myJsonObject.data[2].UniteSymbol);
$('#syncPushPingTestResponse').append(myJsonObject.message); // if you receive the right server answer, the json bridge works fine.
}
);
}
/*
// test to know if the server accept a json from the webSqlApp data coming from webSqlSync and if it return a json from a MySQL query
function syncPushDataTest() {
myURL = 'http://www.mywebsite.com/webSqlApp/syncPushDataTest.php'; //___________
//myJsonSent = '{"result":"OK","message":"this is a positive reply","sync_date":1371753757,"data":[{"UniteID":"0","UniteSymbol":"h"},{"UniteID":"1","UniteSymbol":"km"},{"UniteID":"2","UniteSymbol":"$"},{"UniteID":"3","UniteSymbol":"U$"},{"UniteID":"4","UniteSymbol":"\u20ac"},{"UniteID":"5","UniteSymbol":"$P"}]}';
//Client data to send
mySentJson = '{
"result":"OK",
"message":"this is a positive reply",
"sync_date":1371753757,
"info": {
"userEmail": "alainb@gmail.com",
"appName": "myWebSqlApp",
"lastSyncDate": 1326553035406,
"userAgent": "Chrome27.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7",
"myApp_version": "0.1 (webSqlApp)",
"lng": "fr",
"device_uuid": "1234567890"
},
"data": {
"Unite": [{
"UniteID": 100330,
"UniteNom": "Yen",
"UniteSymbol": "Y$",
"nbOK": 1,
"nbKO": 0
},
{
"UniteID": 100330,
"UniteNom": "Yen",
"UniteSymbol": "Y$",
"nbOK": 1,
"nbKO": 0
},
{ }]
}
}';
DBSYNC._sendDataToServer (mySentJson, function(serverAnswer) {
*/
/* Old way to send a json string (replaced by the webSqlSync.js method
var str_json = JSON.stringify(myObject)
var request= new window.XMLHttpRequest();
request.overrideMimeType = 'application/json;charset=UTF-8';
request.open("POST", myURL,true);
request.setRequestHeader("Content-type", "application/json");
request.send(str_json);
*/
/* $('#syncPushPingTestResponse').html("syncPushPingTest done, ");
//alert("SyncPush is a Success ");
// get feedback proving that the server got the data: get the sent data from the server
$.getJSON('http://www.mywebsite.com/webSqlApp/syncPullOnlyTest.php',
function(myJsonObject) {
alert(myJsonObject.result);
alert(myJsonObject.message);
alert(myJsonObject.sync_date);
alert(myJsonObject.data[2].UniteID);
alert(myJsonObject.data[2].UniteSymbol);
$('#syncPushPingTestResponse').append(myJsonObject.message); // if you receive the right server answer, the json bridge works fine.
}
);
}
*/
// test to know if the server accept a json from the webSqlApp and if it return a json from a MySQL query
function syncPushInDbTest() {
myURL = 'http://www.mywebsite.com/webSqlApp/syncPushInDbTest.php'; //___________
myObject = '{"result":"OK","message":"this is a positive reply","sync_date":1371753757,"data":[{"UniteID":"0","UniteSymbol":"h"},{"UniteID":"1","UniteSymbol":"km"},{"UniteID":"2","UniteSymbol":"$"},{"UniteID":"3","UniteSymbol":"U$"},{"UniteID":"4","UniteSymbol":"\u20ac"},{"UniteID":"5","UniteSymbol":"$P"}]}';
var str_json = JSON.stringify(myObject)
var request= new window.XMLHttpRequest();
request.overrideMimeType = 'application/json;charset=UTF-8';
request.open("POST", myURL,true);
request.setRequestHeader("Content-type", "application/json");
request.send(str_json);
$('#syncPushInDbTestResponse').html("syncPushInDbTest done, ");
//alert("SyncPush is a Success ");
$.getJSON('http://www.mywebsite.com/webSqlApp/syncPullDataTest.php',
function(myJsonObject) {
alert(myJsonObject.result);
alert(myJsonObject.message);
alert(myJsonObject.sync_date);
alert(myJsonObject.data[2].UniteID);
alert(myJsonObject.data[2].UniteSymbol);
$('#syncPushPingTestResponse').append(myJsonObject.message); // if you receive the right server answer, the json bridge works fine.
}
);
}
function syncDownloadUnits(){ // Fonctionnal but not totally: The 2 tables for the sync are created.
//mySyncURL = 'http://www.mywebsite.com/webSqlApp/syncPullOnlyTest.php'; //___________
mySyncURL = 'http://www.mywebsite.com/webSqlApp/sqlSyncHandlerTest.php'; //___________
//myObject = '{"result":"OK","message":"this is a positive reply","sync_date":1371753757,"data":[{"UniteID":"0","UniteSymbol":"h"},{"UniteID":"1","UniteSymbol":"km"},{"UniteID":"2","UniteSymbol":"$"},{"UniteID":"3","UniteSymbol":"U$"},{"UniteID":"4","UniteSymbol":"\u20ac"},{"UniteID":"5","UniteSymbol":"$P"}]}';
unitsTableToSync = [
{tableName: 'Unites', idName: 'UniteID'}
];
DBSYNC.initSync(unitsTableToSync, mywebdb, SYNCDATA.sync_info, mySyncURL, function(result){ //Parameters are defined in mySyncData.js
DBSYNC.syncNow(callBackProgress, function(result) {
if (result.syncOK === true) {
alert("mySync Success "); //Synchronized successfully
}
else {
alert("mySync Not dones"); //Synchronized error
}
}); // to close the syncNow
}); // to close the iniytSynnc
}
// test to know if the server accept a json from the webSqlApp, if it create a INSERT INTO to MySQL from the json //and if it return a json from a MySQL query
function syncUploadUnits() {
myURL = 'http://www.mywebsite.com/webSqlApp/syncUploadUnits.php'; //___________
$.getJSON(myURL,
function(myJsonObject) {
DBSYNC.syncNow(callBackProgress, function(result) {
if (result.syncOK === true) {
alert("mySync Success "); //Synchronized successfully
}
else {
alert("mySync Not dones"); //Synchronized error
}
});
}
); // to close the jQuery.getJSON
}
// message, persent and msgKey comes from syncNow of webSqlSync.js line 128 and 136
// Ex: message= "mon message", percent= 20, msgKey= "sendData"
function callBackProgress (message, percent, msgKey) {
$('#uiProgress').html(message+' ('+percent+'%)');
}
function createTable() {
mywebdb.transaction(function(tx) {
tx.executeSql(sqlCreateTableContacts, [], showContacts, onError); // Create Contacts table
//tx.executeSql(sqlCreateTableUnites, []);
tx.executeSql("UPDATE SQLITE_SEQUENCE SET seq = -1 WHERE name = 'Contacts'"); //, []); //ne marche pas
tx.executeSql("INSERT INTO Contacts (firstName, lastName, qte, MaJdate, cbFait, rbABC, uniteId) VALUES (?, ?, ?, ?, ?, ?, ?);", ['Z', 'Z', '9', '2013-05-09', '1', 'C', '1']);
tx.executeSql("CREATE TABLE IF NOT EXISTS Unites (UniteID INTEGER PRIMARY KEY, UniteSymbol TEXT)"); // AUTOINCREMENT removed to have an id not starting with 1
tx.executeSql("UPDATE SQLITE_SEQUENCE SET seq = -1 WHERE name = 'Unites'"); //, []); //It does'nt works if the primary key is AUTOINCREMENT
tx.executeSql("INSERT INTO Unites(UniteID, UniteSymbol) VALUES(?, ?)", [-1,'C$']); // It insert a row with an ID of -1 to have the next id to 0 like MySQL
// tx.executeSql("INSERT INTO Unites(UniteSymbol) VALUES(?)", ['hours']);
//tx.executeSql("DELETE FROM Unites WHERE UniteID= -1"); // To have a first id to 0, we must insert at least one row in the DB. Strange! Then we can delete our -1 row.
// tx.executeSql("INSERT INTO Unites(UniteSymbol) VALUES(?)", ['miles']);
// tx.executeSql("INSERT INTO Unites(UniteSymbol) VALUES(?)", ['U$']);
// Note: The sync should add 5 other units
tx.executeSql(sqlCreateTableFiltreParam, [], showContacts, onError); // Create FiltreParam pour enregistrer les paramètres de filtrage de Activites
tx.executeSql("INSERT INTO FiltreParam (firstNameFP, lastNameFP, qteFP, MaJdateFP, cbFaitFP, rbABCFP, uniteIdFP) VALUES (?, ?, ?, ?, ?, ?, ?);", ['Z', 'ZZ', '1', '2013-06-01', '1', 'A', '1']);
tx.executeSql(sqlCreateTableUserParam, [], showContacts, onError); // Create UserParam pour enregistrer les paramètres de connexion au serveur Php-MySQL
tx.executeSql("INSERT INTO UserParam (userId, password, email) VALUES (?, ?, ?);", ['alan', 'alan', 'a@abc.com']);
});
}
function dropTables() {
mywebdb.transaction(function(tx) {
tx.executeSql(sqlDropContact, [], showContacts, onError);
tx.executeSql(sqlDropUnites, [], showContacts, onError);
tx.executeSql(sqlDropFiltreParam, [], showContacts, onError);
tx.executeSql(sqlDropUserParam, [], showContacts, onError);
tx.executeSql(sqlDrop_new_elem, [], showContacts, onError);
tx.executeSql(sqlDrop_sync_info, [], showContacts, onError);
});
resetForm();
}
</script>
</html>