Added local storage import/export capabilities
This commit is contained in:
parent
94a0f30856
commit
3fada0c5e5
@ -814,11 +814,12 @@ define([
|
||||
applyTheme(this.value);
|
||||
});
|
||||
|
||||
// Import settings
|
||||
$(".action-import-settings").click(function(e) {
|
||||
$("#input-file-import-settings").click();
|
||||
// Import docs and settings
|
||||
$(".action-import-docs-settings").click(function(e) {
|
||||
$("#input-file-import-docs-settings").click();
|
||||
});
|
||||
$("#input-file-import-settings").change(function(evt) {
|
||||
var newLocalStorage = undefined;
|
||||
$("#input-file-import-docs-settings").change(function(evt) {
|
||||
var files = (evt.dataTransfer || evt.target).files;
|
||||
$(".modal-settings").modal("hide");
|
||||
_.each(files, function(file) {
|
||||
@ -827,23 +828,34 @@ define([
|
||||
return function(e) {
|
||||
var content = e.target.result;
|
||||
try {
|
||||
JSON.parse(content);
|
||||
newLocalStorage = JSON.parse(content);
|
||||
if(!newLocalStorage.version) {
|
||||
throw 1;
|
||||
}
|
||||
$('.modal-import-docs-settings').modal('show');
|
||||
}
|
||||
catch(e) {
|
||||
eventMgr.onError(importedFile.name + " is not a valid JSON file.");
|
||||
eventMgr.onError("Wrong format: " + importedFile.name);
|
||||
return;
|
||||
}
|
||||
localStorage.settings = content;
|
||||
window.location.reload();
|
||||
};
|
||||
})(file);
|
||||
var blob = file.slice(0, IMPORT_FILE_MAX_CONTENT_SIZE);
|
||||
reader.readAsText(blob);
|
||||
reader.readAsText(file);
|
||||
});
|
||||
});
|
||||
$(".action-import-docs-settings-confirm").click(function(e) {
|
||||
localStorage.clear();
|
||||
var allowedKeys = /^file\.|^focusMode$|^folder\.|^publish\.|^settings$|^sync\.|^theme$|^version$|^welcomeTour$/;
|
||||
_.each(newLocalStorage, function(value, key) {
|
||||
if(allowedKeys.test(key)) {
|
||||
localStorage[key] = value;
|
||||
}
|
||||
});
|
||||
window.location.reload();
|
||||
});
|
||||
// Export settings
|
||||
$(".action-export-settings").click(function(e) {
|
||||
utils.saveAs(JSON.stringify(settings), "StackEdit Settings.json");
|
||||
$(".action-export-docs-settings").click(function(e) {
|
||||
utils.saveAs(JSON.stringify(localStorage), "StackEdit local storage.json");
|
||||
});
|
||||
|
||||
$(".action-default-settings").click(function() {
|
||||
|
@ -1016,18 +1016,6 @@
|
||||
your own extension...</a></span>
|
||||
</div>
|
||||
<div class="tab-pane" id="tabpane-settings-utils">
|
||||
<div class="tab-pane-button-container">
|
||||
<a href="#"
|
||||
class="btn btn-block btn-primary action-import-settings"><i
|
||||
class="icon-wrench icon-white"></i> Import settings</a> <a href="#"
|
||||
class="btn btn-block btn-primary action-export-settings"
|
||||
data-dismiss="modal"><i class="icon-wrench icon-white"></i>
|
||||
Export settings</a> <a href="#"
|
||||
class="btn btn-block btn-primary action-default-settings"
|
||||
data-dismiss="modal"><i class="icon-wrench icon-white"></i>
|
||||
Load default settings</a> <input type="file"
|
||||
id="input-file-import-settings" class="hide">
|
||||
</div>
|
||||
<div class="tab-pane-button-container">
|
||||
<a href="#" class="btn btn-block btn-primary action-welcome-file"
|
||||
data-dismiss="modal"><i class="icon-help-circled icon-white"></i>
|
||||
@ -1037,7 +1025,19 @@
|
||||
class="icon-help-circled icon-white"></i> Welcome tour</a>
|
||||
</div>
|
||||
<div class="tab-pane-button-container">
|
||||
<a href="#" class="btn btn-block btn-primary"
|
||||
<a href="#"
|
||||
class="btn btn-block btn-primary action-import-docs-settings"><i
|
||||
class="icon-cog-alt icon-white"></i> Import docs & settings</a> <a href="#"
|
||||
class="btn btn-block btn-primary action-export-docs-settings"
|
||||
data-dismiss="modal"><i class="icon-cog-alt icon-white"></i>
|
||||
Export docs & settings</a> <input type="file"
|
||||
id="input-file-import-docs-settings" class="hide">
|
||||
</div>
|
||||
<div class="tab-pane-button-container">
|
||||
<a href="#"
|
||||
class="btn btn-block btn-primary action-default-settings"
|
||||
data-dismiss="modal"><i class="icon-wrench icon-white"></i>
|
||||
Load default settings</a> <a href="#" class="btn btn-block btn-primary"
|
||||
data-dismiss="modal" data-toggle="modal"
|
||||
data-target=".modal-app-reset"><i
|
||||
class="icon-fire icon-white"></i> Reset application</a>
|
||||
@ -1117,5 +1117,26 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="modal modal-import-docs-settings">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title">Import documents and settings</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>This will delete all existing local documents.</p>
|
||||
<blockquote>Are you sure?</blockquote>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-default" data-dismiss="modal">Cancel</a>
|
||||
<a href="#" class="btn btn-primary action-import-docs-settings-confirm"
|
||||
data-dismiss="modal">OK</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="lock-ui hide"></div>
|
||||
<div id="dropboxjs" data-app-key="x0k2l8puemfvg0o"></div>
|
@ -203,7 +203,7 @@ a {
|
||||
* Input
|
||||
********************/
|
||||
|
||||
// Fix form-inline broken since v3
|
||||
// Fix form-inline broken since Bootstrap v3
|
||||
.form-inline {
|
||||
.col-lg-1 { width: percentage((1 / @grid-columns)); }
|
||||
.col-lg-2 { width: percentage((2 / @grid-columns)); }
|
||||
|
Loading…
Reference in New Issue
Block a user