@@ -1470,6 +1470,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
14701470 return _ref4 ;
14711471 }
14721472
1473+ OperationView . prototype . invocationUrl = null ;
1474+
14731475 OperationView . prototype . events = {
14741476 'submit .sandbox' : 'submitOperation' ,
14751477 'click .submit' : 'submitOperation' ,
@@ -1554,7 +1556,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
15541556 } ;
15551557
15561558 OperationView . prototype . submitOperation = function ( e ) {
1557- var error_free , form , map , o , opts , val , _i , _j , _k , _len , _len1 , _len2 , _ref5 , _ref6 , _ref7 ;
1559+ var error_free , form , isFileUpload , map , o , opts , val , _i , _j , _k , _len , _len1 , _len2 , _ref5 , _ref6 , _ref7 ;
15581560 if ( e != null ) {
15591561 e . preventDefault ( ) ;
15601562 }
@@ -1578,12 +1580,16 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
15781580 opts = {
15791581 parent : this
15801582 } ;
1583+ isFileUpload = false ;
15811584 _ref5 = form . find ( "input" ) ;
15821585 for ( _i = 0 , _len = _ref5 . length ; _i < _len ; _i ++ ) {
15831586 o = _ref5 [ _i ] ;
15841587 if ( ( o . value != null ) && jQuery . trim ( o . value ) . length > 0 ) {
15851588 map [ o . name ] = o . value ;
15861589 }
1590+ if ( o . type === "file" ) {
1591+ isFileUpload = true ;
1592+ }
15871593 }
15881594 _ref6 = form . find ( "textarea" ) ;
15891595 for ( _j = 0 , _len1 = _ref6 . length ; _j < _len1 ; _j ++ ) {
@@ -1603,14 +1609,94 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
16031609 opts . responseContentType = $ ( "div select[name=responseContentType]" , $ ( this . el ) ) . val ( ) ;
16041610 opts . requestContentType = $ ( "div select[name=parameterContentType]" , $ ( this . el ) ) . val ( ) ;
16051611 $ ( ".response_throbber" , $ ( this . el ) ) . show ( ) ;
1606- return this . model [ "do" ] ( map , opts , this . showCompleteStatus , this . showErrorStatus , this ) ;
1612+ if ( isFileUpload ) {
1613+ return this . handleFileUpload ( map , form ) ;
1614+ } else {
1615+ return this . model [ "do" ] ( map , opts , this . showCompleteStatus , this . showErrorStatus , this ) ;
1616+ }
16071617 }
16081618 } ;
16091619
16101620 OperationView . prototype . success = function ( response , parent ) {
16111621 return parent . showCompleteStatus ( response ) ;
16121622 } ;
16131623
1624+ OperationView . prototype . handleFileUpload = function ( map , form ) {
1625+ var bodyParam , headerParams , o , obj , param , _i , _j , _k , _len , _len1 , _len2 , _ref5 , _ref6 , _ref7 ,
1626+ _this = this ;
1627+ console . log ( "it's a file upload" ) ;
1628+ _ref5 = form . serializeArray ( ) ;
1629+ for ( _i = 0 , _len = _ref5 . length ; _i < _len ; _i ++ ) {
1630+ o = _ref5 [ _i ] ;
1631+ if ( ( o . value != null ) && jQuery . trim ( o . value ) . length > 0 ) {
1632+ map [ o . name ] = o . value ;
1633+ }
1634+ }
1635+ bodyParam = new FormData ( ) ;
1636+ _ref6 = this . model . parameters ;
1637+ for ( _j = 0 , _len1 = _ref6 . length ; _j < _len1 ; _j ++ ) {
1638+ param = _ref6 [ _j ] ;
1639+ if ( param . paramType === 'form' ) {
1640+ bodyParam . append ( param . name , map [ param . name ] ) ;
1641+ }
1642+ }
1643+ headerParams = { } ;
1644+ _ref7 = this . model . parameters ;
1645+ for ( _k = 0 , _len2 = _ref7 . length ; _k < _len2 ; _k ++ ) {
1646+ param = _ref7 [ _k ] ;
1647+ if ( param . paramType === 'header' ) {
1648+ headerParams [ param . name ] = map [ param . name ] ;
1649+ }
1650+ }
1651+ console . log ( headerParams ) ;
1652+ $ . each ( $ ( 'input[type~="file"]' ) , function ( i , el ) {
1653+ return bodyParam . append ( $ ( el ) . attr ( 'name' ) , el . files [ 0 ] ) ;
1654+ } ) ;
1655+ console . log ( bodyParam ) ;
1656+ this . invocationUrl = this . model . supportHeaderParams ( ) ? ( headerParams = this . model . getHeaderParams ( map ) , this . model . urlify ( map , false ) ) : this . model . urlify ( map , true ) ;
1657+ $ ( ".request_url" , $ ( this . el ) ) . html ( "<pre>" + this . invocationUrl + "</pre>" ) ;
1658+ obj = {
1659+ type : this . model . method ,
1660+ url : this . invocationUrl ,
1661+ headers : headerParams ,
1662+ data : bodyParam ,
1663+ dataType : 'json' ,
1664+ contentType : false ,
1665+ processData : false ,
1666+ error : function ( data , textStatus , error ) {
1667+ return _this . showErrorStatus ( _this . wrap ( data ) , _this ) ;
1668+ } ,
1669+ success : function ( data ) {
1670+ return _this . showResponse ( data , _this ) ;
1671+ } ,
1672+ complete : function ( data ) {
1673+ return _this . showCompleteStatus ( _this . wrap ( data ) , _this ) ;
1674+ }
1675+ } ;
1676+ if ( window . authorizations ) {
1677+ window . authorizations . apply ( obj ) ;
1678+ }
1679+ jQuery . ajax ( obj ) ;
1680+ return false ;
1681+ } ;
1682+
1683+ OperationView . prototype . wrap = function ( data ) {
1684+ var o ,
1685+ _this = this ;
1686+ o = { } ;
1687+ o . content = { } ;
1688+ o . content . data = data . responseText ;
1689+ o . getHeaders = function ( ) {
1690+ return {
1691+ "Content-Type" : data . getResponseHeader ( "Content-Type" )
1692+ } ;
1693+ } ;
1694+ o . request = { } ;
1695+ o . request . url = this . invocationUrl ;
1696+ o . status = data . status ;
1697+ return o ;
1698+ } ;
1699+
16141700 OperationView . prototype . getSelectedValue = function ( select ) {
16151701 var opt , options , _i , _len , _ref5 ;
16161702 if ( ! select . multiple ) {
@@ -1744,15 +1830,17 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
17441830 } else if ( contentType . indexOf ( "text/html" ) === 0 ) {
17451831 code = $ ( '<code />' ) . html ( content ) ;
17461832 pre = $ ( '<pre class="xml" />' ) . append ( code ) ;
1833+ } else if ( contentType . indexOf ( "image/" ) === 0 ) {
1834+ pre = $ ( '<img>' ) . attr ( 'src' , data . request . url ) ;
17471835 } else {
17481836 code = $ ( '<code />' ) . text ( content ) ;
17491837 pre = $ ( '<pre class="json" />' ) . append ( code ) ;
17501838 }
17511839 response_body = pre ;
1752- $ ( ".request_url" ) . html ( "<pre>" + data . request . url + "</pre>" ) ;
1840+ $ ( ".request_url" , $ ( this . el ) ) . html ( "<pre>" + data . request . url + "</pre>" ) ;
17531841 $ ( ".response_code" , $ ( this . el ) ) . html ( "<pre>" + data . status + "</pre>" ) ;
17541842 $ ( ".response_body" , $ ( this . el ) ) . html ( response_body ) ;
1755- $ ( ".response_headers" , $ ( this . el ) ) . html ( "<pre>" + JSON . stringify ( data . getHeaders ( ) ) + "</pre>" ) ;
1843+ $ ( ".response_headers" , $ ( this . el ) ) . html ( "<pre>" + JSON . stringify ( data . getHeaders ( ) , null , " " ) . replace ( / \n / g , "<br>" ) + "</pre>" ) ;
17561844 $ ( ".response" , $ ( this . el ) ) . slideDown ( ) ;
17571845 $ ( ".response_hider" , $ ( this . el ) ) . show ( ) ;
17581846 $ ( ".response_throbber" , $ ( this . el ) ) . hide ( ) ;
0 commit comments