#1248 createXMLSample show XML example for parameter
This commit is contained in:
@@ -4,7 +4,9 @@ SwaggerUi.Views.SignatureView = Backbone.View.extend({
|
||||
events: {
|
||||
'click a.description-link' : 'switchToDescription',
|
||||
'click a.snippet-link' : 'switchToSnippet',
|
||||
'mousedown .snippet' : 'snippetToTextArea'
|
||||
'click a.snippet-xml-link' : 'switchToXMLSnippet',
|
||||
'mousedown .snippet_json' : 'jsonSnippetMouseDown',
|
||||
'mousedown .snippet_xml' : 'xmlSnippetMouseDown'
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
@@ -20,12 +22,6 @@ SwaggerUi.Views.SignatureView = Backbone.View.extend({
|
||||
} else {
|
||||
this.switchToSnippet();
|
||||
}
|
||||
|
||||
this.isParam = this.model.isParam;
|
||||
|
||||
if (this.isParam) {
|
||||
$('.notice', $(this.el)).text('Click to set as parameter value');
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
@@ -38,33 +34,59 @@ SwaggerUi.Views.SignatureView = Backbone.View.extend({
|
||||
$('.description', $(this.el)).show();
|
||||
$('.description-link', $(this.el)).addClass('selected');
|
||||
$('.snippet-link', $(this.el)).removeClass('selected');
|
||||
$('.snippet-xml-link', $(this.el)).removeClass('selected');
|
||||
},
|
||||
|
||||
// handler for show sample
|
||||
switchToSnippet: function(e){
|
||||
if (e) { e.preventDefault(); }
|
||||
|
||||
$('.snippet_json', $(this.el)).show();
|
||||
$('.description', $(this.el)).hide();
|
||||
$('.snippet', $(this.el)).show();
|
||||
$('.snippet_xml', $(this.el)).hide();
|
||||
$('.snippet-link', $(this.el)).addClass('selected');
|
||||
$('.description-link', $(this.el)).removeClass('selected');
|
||||
$('.snippet-xml-link', $(this.el)).removeClass('selected');
|
||||
},
|
||||
|
||||
switchToXMLSnippet: function (e) {
|
||||
if (e) { e.preventDefault();}
|
||||
|
||||
$('.snippet_xml', $(this.el)).show();
|
||||
$('.snippet_json', $(this.el)).hide();
|
||||
$('.description', $(this.el)).hide();
|
||||
$('.snippet-xml-link', $(this.el)).addClass('selected');
|
||||
$('.description-link', $(this.el)).removeClass('selected');
|
||||
$('.snippet-link', $(this.el)).removeClass('selected');
|
||||
},
|
||||
|
||||
// handler for snippet to text area
|
||||
snippetToTextArea: function(e) {
|
||||
if (this.isParam) {
|
||||
snippetToTextArea: function(val) {
|
||||
var textArea = $('textarea', $(this.el.parentNode.parentNode.parentNode));
|
||||
|
||||
// Fix for bug in IE 10/11 which causes placeholder text to be copied to "value"
|
||||
if ($.trim(textArea.val()) === '' || textArea.prop('placeholder') === textArea.val()) {
|
||||
textArea.val(val);
|
||||
// TODO move this code outside of the view and expose an event instead
|
||||
if( this.model.jsonEditor && this.model.jsonEditor.isEnabled()){
|
||||
this.model.jsonEditor.setValue(JSON.parse(this.model.sampleJSON));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
jsonSnippetMouseDown: function (e) {
|
||||
if (this.model.isParam) {
|
||||
if (e) { e.preventDefault(); }
|
||||
|
||||
var textArea = $('textarea', $(this.el.parentNode.parentNode.parentNode));
|
||||
this.snippetToTextArea(this.model.sampleJSON);
|
||||
}
|
||||
},
|
||||
|
||||
// Fix for bug in IE 10/11 which causes placeholder text to be copied to "value"
|
||||
if ($.trim(textArea.val()) === '' || textArea.prop('placeholder') === textArea.val()) {
|
||||
textArea.val(this.model.sampleJSON);
|
||||
// TODO move this code outside of the view and expose an event instead
|
||||
if( this.model.jsonEditor && this.model.jsonEditor.isEnabled()){
|
||||
this.model.jsonEditor.setValue(JSON.parse(this.model.sampleJSON));
|
||||
}
|
||||
}
|
||||
xmlSnippetMouseDown: function (e) {
|
||||
if (this.model.isParam) {
|
||||
if (e) { e.preventDefault(); }
|
||||
|
||||
this.snippetToTextArea(this.model.sampleXML);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user