Add Export/Import feature
This commit is contained in:
parent
86e98ca0a3
commit
5b1ed81828
2 changed files with 70 additions and 2 deletions
65
inc/myco.js
65
inc/myco.js
|
@ -887,6 +887,68 @@ on_click_sync_btn=function(e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**************************
|
||||||
|
* Export/Import all
|
||||||
|
**************************/
|
||||||
|
|
||||||
|
on_export_all_btn_click=function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
navbar_collapse_hide();
|
||||||
|
var blob=new Blob([JSON.stringify(groups.export(),null,2)],{type: 'text/plain'});
|
||||||
|
var a=$('<a download="myco-export.json">download</a>');
|
||||||
|
a.attr('href',window.URL.createObjectURL(blob));
|
||||||
|
a.css('display','none');
|
||||||
|
$('body').append(a);
|
||||||
|
a[0].click();
|
||||||
|
a.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
on_import_all_btn_click=function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
navbar_collapse_hide();
|
||||||
|
myconfirm(
|
||||||
|
"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",
|
||||||
|
function() {
|
||||||
|
var input=$('<input type="file"/>');
|
||||||
|
input.css('display','none');
|
||||||
|
$('body').append(input);
|
||||||
|
input[0].click();
|
||||||
|
input.bind('change',{'input': input},function(e) {
|
||||||
|
pleaseWaitShow();
|
||||||
|
var file=input.prop('files')[0];
|
||||||
|
if (file) {
|
||||||
|
var reader = new FileReader();
|
||||||
|
$(reader).bind('load',function(e) {
|
||||||
|
try {
|
||||||
|
var data=JSON.parse(e.target.result);
|
||||||
|
if (jQuery.type(data)!='object') {
|
||||||
|
alert("Fichier invalide !");
|
||||||
|
pleaseWaitHide();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var backup=groups.export();
|
||||||
|
try {
|
||||||
|
groups.import(data);
|
||||||
|
groups.save();
|
||||||
|
view_home();
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
groups.import(backup);
|
||||||
|
alert("Une erreur est survenue durant l'importation des données.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
alert("Une erreur est survenue durant le parsing du contenu du fichier.");
|
||||||
|
}
|
||||||
|
pleaseWaitHide();
|
||||||
|
});
|
||||||
|
reader.readAsText(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* User menu
|
* User menu
|
||||||
*/
|
*/
|
||||||
|
@ -1084,6 +1146,9 @@ $( document ).ready( function() {
|
||||||
$('#view-group-categories span.input-group-addon').bind('click',on_categories_group_add_btn_click);
|
$('#view-group-categories span.input-group-addon').bind('click',on_categories_group_add_btn_click);
|
||||||
$('#view-group-categories form').bind('submit',on_categories_group_add_btn_click);
|
$('#view-group-categories form').bind('submit',on_categories_group_add_btn_click);
|
||||||
$("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);
|
$("#view-group-categories button.go-back-group").bind('click',on_categories_go_back_group_btn_click);
|
||||||
|
|
||||||
|
$('#export_all_btn').bind('click',on_export_all_btn_click);
|
||||||
|
$('#import_all_btn').bind('click',on_import_all_btn_click);
|
||||||
|
|
||||||
view_home();
|
view_home();
|
||||||
pleaseWaitHide();
|
pleaseWaitHide();
|
||||||
|
|
|
@ -172,10 +172,13 @@ span.cat-color {
|
||||||
<div class="collapse navbar-collapse" id="navbar-groupe-collapse">
|
<div class="collapse navbar-collapse" id="navbar-groupe-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class='glyphicon glyphicon-th-list'></span> Groupe <b class="caret"></b></a>
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class='glyphicon glyphicon-th-list'></span> Groupes <b class="caret"></b></a>
|
||||||
<ul id="group-choice" class="dropdown-menu">
|
<ul id="group-choice" class="dropdown-menu">
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
<li><a id='add_group_btn'><span class='glyphicon glyphicon-plus'><span> Nouveau</a></li>
|
<li><a id='add_group_btn'><span class='glyphicon glyphicon-plus'></span> Nouveau</a></li>
|
||||||
|
<li class="divider"></li>
|
||||||
|
<li><a id='export_all_btn'><span class='glyphicon glyphicon-download'></span> Exporter au format JSON</span></a></li>
|
||||||
|
<li><a id='import_all_btn'><span class='glyphicon glyphicon-upload'></span> Importer depuis un fichier JSON</span></a></li>
|
||||||
<li><a id='clear_local_data'><span class='glyphicon glyphicon-trash'></span> Purger les données locales</a></li>
|
<li><a id='clear_local_data'><span class='glyphicon glyphicon-trash'></span> Purger les données locales</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in a new issue