diff --git a/dist/restform.js b/dist/restform.js index 37d5e9b..b146c37 100644 --- a/dist/restform.js +++ b/dist/restform.js @@ -417,7 +417,7 @@ var setupForm = function ($el, Schema, dataCallback) { if (window.brutusin) { // assign new object to prevent unexpected changes - var schema = Object.assign({}, Schema) + var schema = JSON.parse(JSON.stringify(Schema)) // start Brutusin JSON forms var BrutusinForms = brutusin['json-forms'] var Bf = BrutusinForms.create(schema) diff --git a/dist/restform.min.js b/dist/restform.min.js index 2a5a8fa..188ff0a 100644 --- a/dist/restform.min.js +++ b/dist/restform.min.js @@ -5,4 +5,4 @@ * @author E-Com Club * @license MIT */ -!function(t){"use strict";var p={},h=function(t){var e=t.opt,s=e.host+Restform.parseEndpoint(e.endpoint,e.params);return t.url=s},v=function(t,e,s){p[t].opt.reqBody=e;var a=!!s;b(t,null,a,!a)},b=function(t,e,s,a){var n,o=p[t],r=o.opt;if(n=e?{res:e}:{req:r.reqBody,res:r.resBody},!s){var i=o.bodyEditor;for(var l in i)if(!e||"req"!==l){var c=i[l];if("function"==typeof c)if(n[l])try{c(JSON.stringify(n[l],null,r.indentationSpaces))}catch(t){console.error("Invalid request body",t)}else c("")}}a||"function"!=typeof o.bodyForm||o.bodyForm(n.req)};t.fn.restform=function(t){var e,s,a,i=this.data("restform");i||(a=Date.now(),p[a]={opt:{title:"API Console",host:"https://api.e-com.plus/v1",endpoint:"/products/{_id}.json",method:"GET",params:[{key:"_id",value:"123",description:"Resource ID",required:!0}],reqHeaders:{"Content-Type":"application/json"},schema:null,reqBody:null,statusCode:200,resHeaders:{"Content-Type":"application/json"},resBody:null,aceTheme:"",indentationSpaces:4,chageHeadersCallback:null},liveResponse:{},url:""},i=a,s=!0);var n,o,r,l,c=p[i],d=c.opt;if("object"==typeof t&&t&&Object.assign(d,t),s){var u=Restform.layout(i);c.Layout=u,setTimeout(function(){var t=function(t){v(i,t,!0)},e={req:u.$reqBody,res:u.$resBody};for(var s in c.bodyEditor={},e){var a,n=e[s];if(n)"res"===s&&(a=!0),c.bodyEditor[s]=Restform.setupAce(n,a,d.aceTheme,t)}b(i)},400),u.cbSend(function(){var r=u.$loading,t=function(t,e){var s,a,n,o;s=t,a=e,(o=p[n=i]).liveResponse.status=s,o.liveResponse.body=a,b(n,a),o.Layout.setStatusCode(s),r.fadeOut("slow")};setTimeout(function(){Restform.send(c.url,d.method,d.reqHeaders,d.reqBody,t)},100),r.fadeIn()}),u.cbSwitchResponse(function(t){var e,s;s=t?(e=c.liveResponse.status,c.liveResponse.body):(e=d.statusCode,d.resBody),u.setStatusCode(e),b(i,s)}),u.cbParams(function(t){d.params=t,u.setUrl(h(c))}),u.cbHeaders(function(t){d.reqHeaders=t,"function"==typeof d.chageHeadersCallback&&d.chageHeadersCallback(t)}),e=u.$layout,c.$app=e;var m=u.$nav,f=m.outerHeight();e.css("padding-top",f).on("show.bs.modal",function(){m.fadeIn()}).on("hide.bs.modal",function(){m.fadeOut()}),m.hide().css("opacity",1),this.data("restform",i).html(e)}else e=c.$app,c.liveResponse={},b(i);o=p[n=i],r=o.opt,(l=o.Layout).setTitle(r.title),l.setHost(r.host,r.endpoint),l.setUrl(h(o)),l.setMethod(r.method),l.setParams(r.params),l.setReqHeaders(r.reqHeaders),l.setResHeaders(r.resHeaders),l.setStatusCode(r.statusCode),r.schema&&(l.$reqForm&&(o.bodyForm=Restform.setupBrutusin(l.$reqForm,r.schema,function(t){v(n,t)})),l.setSchema(JSON.stringify(r.schema,null,r.indentationSpaces)),window.twbschema&&l.$attributes.html(twbschema.doc(null,r.schema))),e.modal("show")},window.Restform={}}(jQuery),function(){"use strict";window.Restform.setupAce=function(t,e,s,a){if(window.ace){var n=t.attr("id"),o=t.closest("section").find('[aria-controls="'+t.parent().attr("id")+'"]'),r=ace.edit(n);s&&""!==s||(s="dawn"),r.setTheme("ace/theme/"+s),r.session.setMode("ace/mode/json"),e?r.setReadOnly(!0):r.on("blur",function(){var t;try{t=JSON.parse(r.session.getValue())}catch(t){return}a(t)});var i=function(){setTimeout(function(){r.focus(),r.renderer.updateFull()},200)};return t.click(i),o.click(i),function(t){r.session.setValue(t)}}return null}}(),function(){"use strict";window.Restform.setupBrutusin=function(e,t,s){if(window.brutusin){var a=Object.assign({},t),n=brutusin["json-forms"],o=n.create(a);n.postRender=function(t){e.find("input,select").change(function(){s(t.getData())})};var r=e[0];return function(t){e.html(""),Object.assign({},o).render(r,t)}}return null}}(),function(B){"use strict";window.Restform.layout=function(b){b="restform-"+b+"-";var e=B("
",{class:"restform-title"}),s=B("",{class:"restform-endpoint"}),a=B("",{class:"input-group-text",type:"text"}),n=B("",{class:"form-control",type:"text",readonly:!0,click:function(){B(this).select()}}),o=B("