Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for importing settings from a local file #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/js/module/stitches.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,34 @@ function($, Modernizr, store, util, templates, fileManager, layoutManager, style
self.updateProgress(1, "success");
}
}
},
importfile: {
"change": function (e) {
var $import = $(e.currentTarget);
var $importGroup = $import.parents(".control-group");
var file = $(e.currentTarget).get(0).files[0];
var reader;
var data;

$importGroup.removeClass("error");

if (file) {
reader = new FileReader();
reader.onload = function (readerEvent) {
try {
data = JSON.parse(readerEvent.target.result);
self.importData(data);
} catch (x) {
$importGroup.addClass("error");
self.$element.trigger("error", [x]);
}
}

reader.readAsText(file);
} else {
self.updateProgress(1, "success");
}
}
}
}
});
Expand Down Expand Up @@ -525,13 +553,15 @@ function($, Modernizr, store, util, templates, fileManager, layoutManager, style
var $navTabs = this.$settings.find("ul.nav-tabs");
var $navFirst = $navTabs.find("li:first-child a");
var $import = this.$settings.find(":input[name=import]");
var $importFile = this.$settings.find(":input[name=importfile]");
var $importGroup = $import.parents(".control-group");

// go back to the first tab
$navFirst.click();

// clear out the import field
$import.val("");
$importFile.val("");
$importGroup.removeClass("error");

if (this.palettes.settings.visible) {
Expand Down Expand Up @@ -810,4 +840,4 @@ function($, Modernizr, store, util, templates, fileManager, layoutManager, style

return Stitches;

});
});
9 changes: 7 additions & 2 deletions src/templates/stitches.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@
</div>
<div class="tab-pane" id="import">
<div class="control-group">
<label class="control-label">Paste import here</label>
<label class="control-label">Select a file</label>
<div class="controls">
<input type="file" name="importfile"/>
</div>
<div class="control-group">
<label class="control-label">or paste import here</label>
<div class="controls">
<textarea name="import" rows="10"></textarea>
</div>
Expand Down Expand Up @@ -251,4 +256,4 @@
<!-- /.stitches-palettes -->
</div>
<!-- /.stitches-drop-box -->
</div>
</div>