[app/settings][s]: add support for app settings.
* Only settings is datahub api key * Store in local storage * Modal dialog to set
This commit is contained in:
parent
028dfca859
commit
19ff6c7183
@ -105,11 +105,17 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href=".js-share-and-embed-dialog" data-toggle="modal">
|
||||
<a href=".js-share-and-embed-dialog" data-toggle="modal">
|
||||
Share and Embed
|
||||
<i class="icon-share icon-white"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href=".js-settings" data-toggle="modal">
|
||||
Settings
|
||||
<i class="icon-cog icon-white" style="margin-top: 1px;"></i>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -229,6 +235,27 @@
|
||||
<textarea class="view-embed" style="width: 100%; height: 200px;"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade in js-settings" style="display: none;">
|
||||
<div class="modal-header">
|
||||
<a class="close" data-dismiss="modal">×</a>
|
||||
<h3>Settings</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<label class="control-label">DataHub API Key</label>
|
||||
<div class="controls">
|
||||
<input type="text" name="datahub_api_key" value="" />
|
||||
<p class="help-block"><strong>Getting your API key:</strong> Register/Login to <a href="http://datahub.io/">http://datahub.io/</a> and then visit your user home page (click on the link at the top right). On your home page your API key is located at the top of the page in the section showing your main user details.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">Save »</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -8,7 +8,8 @@ var ExplorerApp = Backbone.View.extend({
|
||||
events: {
|
||||
'click .nav .js-load-dialog-url': '_onLoadURLDialog',
|
||||
'submit form.js-load-url': '_onLoadURL',
|
||||
'submit .js-load-dialog-file form': '_onLoadFile'
|
||||
'submit .js-load-dialog-file form': '_onLoadFile',
|
||||
'submit .js-settings form': '_onSettingsSave'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
@ -46,6 +47,7 @@ var ExplorerApp = Backbone.View.extend({
|
||||
if (dataset) {
|
||||
this.createExplorer(dataset, state);
|
||||
}
|
||||
this._initializeSettings();
|
||||
},
|
||||
|
||||
viewHome: function() {
|
||||
@ -212,6 +214,28 @@ var ExplorerApp = Backbone.View.extend({
|
||||
},
|
||||
options
|
||||
);
|
||||
},
|
||||
|
||||
_getSettings: function() {
|
||||
var settings = localStorage.getItem('dataexplorer.settings');
|
||||
settings = JSON.parse(settings) || {};
|
||||
return settings;
|
||||
},
|
||||
|
||||
_initializeSettings: function() {
|
||||
var settings = this._getSettings();
|
||||
$('.modal.js-settings form input[name="datahub_api_key"]').val(settings.datahubApiKey);
|
||||
},
|
||||
|
||||
_onSettingsSave: function(e) {
|
||||
var self = this;
|
||||
e.preventDefault();
|
||||
var $form = $(e.target);
|
||||
$('.modal.js-settings').modal('hide');
|
||||
var datahubKey = $form.find('input[name="datahub_api_key"]').val();
|
||||
var settings = this._getSettings();
|
||||
settings.datahubApiKey = datahubKey;
|
||||
localStorage.setItem('dataexplorer.settings', JSON.stringify(settings));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user