Fix overwriting editor changes when switching profile tabs
This commit is contained in:
parent
07425148ee
commit
c94a530f49
1 changed files with 28 additions and 11 deletions
|
|
@ -28,6 +28,8 @@ BR.Profile = L.Evented.extend({
|
||||||
var button = evt.target || evt.srcElement;
|
var button = evt.target || evt.srcElement;
|
||||||
|
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
|
this.editor.markClean();
|
||||||
this._setValue('');
|
this._setValue('');
|
||||||
|
|
||||||
this.fire('clear');
|
this.fire('clear');
|
||||||
|
|
@ -98,8 +100,7 @@ BR.Profile = L.Evented.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_buildCustomProfile: function() {
|
_buildCustomProfile: function(profileText) {
|
||||||
var profileText = this.cache[this.profileName];
|
|
||||||
document.querySelectorAll('#profile_params input, #profile_params select').forEach(function(input) {
|
document.querySelectorAll('#profile_params input, #profile_params select').forEach(function(input) {
|
||||||
var name = input.name;
|
var name = input.name;
|
||||||
var value;
|
var value;
|
||||||
|
|
@ -122,7 +123,7 @@ BR.Profile = L.Evented.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
_save: function(evt) {
|
_save: function(evt) {
|
||||||
var profileText = this._buildCustomProfile();
|
var profileText = this._buildCustomProfile(this.editor.getValue());
|
||||||
var that = this;
|
var that = this;
|
||||||
this.fire('update', {
|
this.fire('update', {
|
||||||
profileText: profileText,
|
profileText: profileText,
|
||||||
|
|
@ -135,16 +136,26 @@ BR.Profile = L.Evented.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_setValue: function(profileText, profileEditorActivated) {
|
_setValue: function(profileText) {
|
||||||
profileText = profileText || '';
|
profileText = profileText || '';
|
||||||
|
|
||||||
if (L.DomUtil.get('profile_editor').classList.contains('active')) {
|
var clean = this.editor.isClean();
|
||||||
// Set value of the full editor and exit
|
|
||||||
this.editor.setValue(profileText);
|
// Always set value of the full editor, even if not active.
|
||||||
|
// Full editor is master, the parameter form always gets the text from it (not cache).
|
||||||
|
this.editor.setValue(profileText);
|
||||||
|
|
||||||
|
// keep dirty state (manually modified; setValue also sets dirty)
|
||||||
|
if (clean) {
|
||||||
this.editor.markClean();
|
this.editor.markClean();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._isParamsFormActive()) {
|
||||||
|
this._buildParamsForm(profileText);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_buildParamsForm: function(profileText) {
|
||||||
if (!profileText) return;
|
if (!profileText) return;
|
||||||
|
|
||||||
// Otherwise, create user friendly form
|
// Otherwise, create user friendly form
|
||||||
|
|
@ -280,11 +291,17 @@ BR.Profile = L.Evented.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_isParamsFormActive: function() {
|
||||||
|
return L.DomUtil.get('profile_params_container').classList.contains('active');
|
||||||
|
},
|
||||||
|
|
||||||
_activateSecondaryTab: function() {
|
_activateSecondaryTab: function() {
|
||||||
if (L.DomUtil.get('profile_params_container').classList.contains('active')) {
|
var profileText = this.editor.getValue();
|
||||||
this._setValue(this.editor.getValue());
|
|
||||||
|
if (this._isParamsFormActive()) {
|
||||||
|
this._buildParamsForm(profileText);
|
||||||
} else {
|
} else {
|
||||||
this._setValue(this._buildCustomProfile());
|
this._setValue(this._buildCustomProfile(profileText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue