diff --git a/bower.json b/bower.json index d87c023..bcfadf7 100644 --- a/bower.json +++ b/bower.json @@ -28,7 +28,8 @@ "font-awesome": "^4.7.0", "bootstrap-select": "hugdx/bootstrap-select#patch-1", "leaflet-sidebar-v2": "nrenner/leaflet-sidebar-v2#dev", - "leaflet.editable": "^1.1.0" + "leaflet.editable": "^1.1.0", + "codemirror": "^5.35.0" }, "overrides": { "leaflet": { diff --git a/css/style.css b/css/style.css index 703f4ef..0b64efc 100644 --- a/css/style.css +++ b/css/style.css @@ -133,7 +133,7 @@ footer { } /* track messages (data tab) */ -#tab_data, #profile_upload { +#tab_data, .CodeMirror { font-size: x-small; } @@ -314,3 +314,13 @@ table.dataTable.display tbody tr.even:hover { .leaflet-sidebar-tabs > ul:last-child { display: none; } + + +/* + * CodeMirror + */ + +.CodeMirror { + height: 100%; + border: 1px solid #ddd; +} diff --git a/js/control/Profile.js b/js/control/Profile.js index 9704ea8..e4ff1f5 100644 --- a/js/control/Profile.js +++ b/js/control/Profile.js @@ -2,9 +2,12 @@ BR.Profile = L.Evented.extend({ cache: {}, initialize: function () { + var textArea = L.DomUtil.get('profile_upload'); + this.editor = CodeMirror.fromTextArea(textArea, {}); + L.DomUtil.get('upload').onclick = L.bind(this._upload, this); L.DomUtil.get('clear').onclick = L.bind(this.clear, this); - this.ele = L.DomUtil.get('profile_upload'); + this.message = new BR.Message('profile_message', { alert: true }); @@ -14,8 +17,7 @@ BR.Profile = L.Evented.extend({ var button = evt.target || evt.srcElement; evt.preventDefault(); - this.ele.value = null; - this.ele.defaultValue = null; + this._setValue(""); this.fire('clear'); button.blur(); @@ -24,11 +26,11 @@ BR.Profile = L.Evented.extend({ update: function(options) { var profileName = options.profile, profileUrl, - ele = this.ele, - dirty = ele.defaultValue !== ele.value; + empty = !this.editor.getValue(), + clean = this.editor.isClean(); this.profileName = profileName; - if (profileName && BR.conf.profilesUrl && (!ele.value || !dirty)) { + if (profileName && BR.conf.profilesUrl && (empty || clean)) { if (!(profileName in this.cache)) { profileUrl = BR.conf.profilesUrl + profileName + '.brf'; BR.Util.get(profileUrl, L.bind(function(err, profileText) { @@ -41,20 +43,22 @@ BR.Profile = L.Evented.extend({ // don't set when option has changed while loading if (!this.profileName || this.profileName === profileName) { - ele.value = profileText; - ele.defaultValue = ele.value; + this._setValue(profileText); } }, this)); } else { - ele.value = this.cache[profileName]; - ele.defaultValue = ele.value; + this._setValue(this.cache[profileName]); } } }, + show: function() { + this.editor.refresh(); + }, + _upload: function(evt) { var button = evt.target || evt.srcElement, - profile = this.ele.value; + profile = this.editor.getValue(); this.message.hide(); $(button).button('uploading'); @@ -67,5 +71,10 @@ BR.Profile = L.Evented.extend({ $(button).blur(); } }); + }, + + _setValue: function(profileText) { + this.editor.setValue(profileText); + this.editor.markClean(); } }); diff --git a/js/index.js b/js/index.js index 354e44c..ebc4a77 100644 --- a/js/index.js +++ b/js/index.js @@ -221,6 +221,7 @@ sidebar = BR.sidebar({ listeningTabs: { + 'tab_profile': profile, 'tab_data': trackMessages } }).addTo(map);