Benjamin Renard commited on 2016-09-12 22:19:47
Showing 2 changed files, with 70 additions and 2 deletions.
| ... | ... |
@@ -887,6 +887,68 @@ on_click_sync_btn=function(e) {
|
| 887 | 887 |
} |
| 888 | 888 |
} |
| 889 | 889 |
|
| 890 |
+/************************** |
|
| 891 |
+ * Export/Import all |
|
| 892 |
+ **************************/ |
|
| 893 |
+ |
|
| 894 |
+on_export_all_btn_click=function(e) {
|
|
| 895 |
+ e.preventDefault(); |
|
| 896 |
+ navbar_collapse_hide(); |
|
| 897 |
+ var blob=new Blob([JSON.stringify(groups.export(),null,2)],{type: 'text/plain'});
|
|
| 898 |
+ var a=$('<a download="myco-export.json">download</a>');
|
|
| 899 |
+ a.attr('href',window.URL.createObjectURL(blob));
|
|
| 900 |
+ a.css('display','none');
|
|
| 901 |
+ $('body').append(a);
|
|
| 902 |
+ a[0].click(); |
|
| 903 |
+ a.remove(); |
|
| 904 |
+} |
|
| 905 |
+ |
|
| 906 |
+on_import_all_btn_click=function(e) {
|
|
| 907 |
+ e.preventDefault(); |
|
| 908 |
+ navbar_collapse_hide(); |
|
| 909 |
+ myconfirm( |
|
| 910 |
+ "Voulez-vous vraiment inporter des données à partir d'un fichier externe ?<br/><strong>Important : cela écrasera l'ensemble des données actuellement présente dans l'application.</strong", |
|
| 911 |
+ function() {
|
|
| 912 |
+ var input=$('<input type="file"/>');
|
|
| 913 |
+ input.css('display','none');
|
|
| 914 |
+ $('body').append(input);
|
|
| 915 |
+ input[0].click(); |
|
| 916 |
+ input.bind('change',{'input': input},function(e) {
|
|
| 917 |
+ pleaseWaitShow(); |
|
| 918 |
+ var file=input.prop('files')[0];
|
|
| 919 |
+ if (file) {
|
|
| 920 |
+ var reader = new FileReader(); |
|
| 921 |
+ $(reader).bind('load',function(e) {
|
|
| 922 |
+ try {
|
|
| 923 |
+ var data=JSON.parse(e.target.result); |
|
| 924 |
+ if (jQuery.type(data)!='object') {
|
|
| 925 |
+ alert("Fichier invalide !");
|
|
| 926 |
+ pleaseWaitHide(); |
|
| 927 |
+ } |
|
| 928 |
+ else {
|
|
| 929 |
+ var backup=groups.export(); |
|
| 930 |
+ try {
|
|
| 931 |
+ groups.import(data); |
|
| 932 |
+ groups.save(); |
|
| 933 |
+ view_home(); |
|
| 934 |
+ } |
|
| 935 |
+ catch(e) {
|
|
| 936 |
+ groups.import(backup); |
|
| 937 |
+ alert("Une erreur est survenue durant l'importation des données.");
|
|
| 938 |
+ } |
|
| 939 |
+ } |
|
| 940 |
+ } |
|
| 941 |
+ catch(e) {
|
|
| 942 |
+ alert("Une erreur est survenue durant le parsing du contenu du fichier.");
|
|
| 943 |
+ } |
|
| 944 |
+ pleaseWaitHide(); |
|
| 945 |
+ }); |
|
| 946 |
+ reader.readAsText(file); |
|
| 947 |
+ } |
|
| 948 |
+ }); |
|
| 949 |
+ }); |
|
| 950 |
+} |
|
| 951 |
+ |
|
| 890 | 952 |
/* |
| 891 | 953 |
* User menu |
| 892 | 954 |
*/ |
| ... | ... |
@@ -1085,6 +1147,9 @@ $( document ).ready( function() {
|
| 1085 | 1147 |
$('#view-group-categories form').bind('submit',on_categories_group_add_btn_click);
|
| 1086 | 1148 |
$("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);
|
| 1087 | 1149 |
|
| 1150 |
+ $('#export_all_btn').bind('click',on_export_all_btn_click);
|
|
| 1151 |
+ $('#import_all_btn').bind('click',on_import_all_btn_click);
|
|
| 1152 |
+ |
|
| 1088 | 1153 |
view_home(); |
| 1089 | 1154 |
pleaseWaitHide(); |
| 1090 | 1155 |
|
| ... | ... |
@@ -172,10 +172,13 @@ span.cat-color {
|
| 172 | 172 |
<div class="collapse navbar-collapse" id="navbar-groupe-collapse"> |
| 173 | 173 |
<ul class="nav navbar-nav"> |
| 174 | 174 |
<li class="dropdown"> |
| 175 |
- <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class='glyphicon glyphicon-th-list'></span> Groupe <b class="caret"></b></a> |
|
| 175 |
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class='glyphicon glyphicon-th-list'></span> Groupes <b class="caret"></b></a> |
|
| 176 | 176 |
<ul id="group-choice" class="dropdown-menu"> |
| 177 | 177 |
<li class="divider"></li> |
| 178 |
- <li><a id='add_group_btn'><span class='glyphicon glyphicon-plus'><span> Nouveau</a></li> |
|
| 178 |
+ <li><a id='add_group_btn'><span class='glyphicon glyphicon-plus'></span> Nouveau</a></li> |
|
| 179 |
+ <li class="divider"></li> |
|
| 180 |
+ <li><a id='export_all_btn'><span class='glyphicon glyphicon-download'></span> Exporter au format JSON</span></a></li> |
|
| 181 |
+ <li><a id='import_all_btn'><span class='glyphicon glyphicon-upload'></span> Importer depuis un fichier JSON</span></a></li> |
|
| 179 | 182 |
<li><a id='clear_local_data'><span class='glyphicon glyphicon-trash'></span> Purger les données locales</a></li> |
| 180 | 183 |
</ul> |
| 181 | 184 |
</li> |
| 182 | 185 |