@@ -9,7 +9,7 @@ const EmbedCreateMode = "create";
99const runEmbedCodeTimeout = 500 ;
1010const interactTooltipTimeout = 2000 ;
1111
12- const defualtTokenType = 1 ;
12+ const defaultTokenType = 1 ;
1313const defaultQnaQuestion = "This year sales by store type by postal code as map" ;
1414const defaultQnaMode = "Interactive" ;
1515
@@ -255,11 +255,6 @@ function showEmbedSettings(mode, entityType, tokenType)
255255 }
256256}
257257
258- function SetEmbedTypeToEmbedToken ( tokenType )
259- {
260- SetSession ( SessionKeys . TokenType , tokenType ) ;
261- }
262-
263258function OpenEmbedMode ( mode , entityType , tokenType )
264259{
265260 if ( entityType == EntityType . Report )
@@ -413,6 +408,74 @@ function ToggleQuestionBox(enabled) {
413408 }
414409}
415410
411+ function OnTokenTypeRadioClicked ( tokenType ) {
412+ SetSession ( SessionKeys . TokenType , tokenType ) ;
413+ const entityType = GetSession ( SessionKeys . EntityType ) ;
414+
415+ if ( tokenType == 0 /* AAD Token */ ) {
416+ $ ( '.inputLine input' ) . each ( function ( ) {
417+ $ ( this ) . val ( "" ) ;
418+ let onChangeFunc = $ ( this ) . attr ( "onchange" ) ;
419+ if ( onChangeFunc ) {
420+ // Change 'this' to button's identifier
421+ onChangeFunc = onChangeFunc . replace ( "this" , "'input#" + $ ( this ) . attr ( 'id' ) + "'" ) ;
422+ eval ( onChangeFunc ) ;
423+ }
424+ } ) ;
425+
426+ } else {
427+ // Moving to embed token will reload the sample
428+ ReloadSample ( entityType ) ;
429+ }
430+ }
431+
432+ function ReloadSample ( entityType ) {
433+ const mode = GetSession ( SessionKeys . EmbedMode ) ;
434+ SetIsSample ( true ) ;
435+
436+ if ( entityType == EntityType . Report )
437+ {
438+ if ( mode == EmbedCreateMode )
439+ {
440+ LoadSampleDatasetIntoSession ( ) . then ( function ( response ) {
441+ SetTextBoxesFromSessionOrUrlParam ( "#txtCreateAccessToken" , "#txtCreateReportEmbed" , "#txtEmbedDatasetId" ) ;
442+ } ) ;
443+ }
444+ else
445+ {
446+ LoadSampleReportIntoSession ( ) . then ( function ( response ) {
447+ SetTextBoxesFromSessionOrUrlParam ( "#txtAccessToken" , "#txtReportEmbed" , "#txtEmbedReportId" ) ;
448+ } ) ;
449+ }
450+ }
451+ else if ( entityType == EntityType . Visual )
452+ {
453+ LoadSampleVisualIntoSession ( ) . then ( function ( response ) {
454+ SetTextBoxesFromSessionOrUrlParam ( "#txtAccessToken" , "#txtReportEmbed" , "#txtEmbedReportId" ) ;
455+ SetTextboxFromSessionOrUrlParam ( SessionKeys . PageName , "#txtPageName" ) ;
456+ SetTextboxFromSessionOrUrlParam ( SessionKeys . VisualName , "#txtVisualName" ) ;
457+ } ) ;
458+ }
459+ else if ( entityType == EntityType . Dashboard )
460+ {
461+ LoadSampleDashboardIntoSession ( ) . then ( function ( response ) {
462+ SetTextBoxesFromSessionOrUrlParam ( "#txtAccessToken" , "#txtDashboardEmbed" , "#txtEmbedDashboardId" ) ;
463+ } ) ;
464+ }
465+ else if ( entityType == EntityType . Tile )
466+ {
467+ LoadSampleTileIntoSession ( ) . then ( function ( response ) {
468+ SetTextBoxesFromSessionOrUrlParam ( "#txtAccessToken" , "#txtTileEmbed" , "#txtEmbedTileId" , "#txtEmbedDashboardId" ) ;
469+ } ) ;
470+ }
471+ else if ( entityType == EntityType . Qna )
472+ {
473+ LoadSampleQnaIntoSession ( ) . then ( function ( response ) {
474+ SetTextBoxesFromSessionOrUrlParam ( "#txtAccessToken" , "#txtQnaEmbed" , "#txtDatasetId" ) ;
475+ } ) ;
476+ }
477+ }
478+
416479function EmbedAreaDesktopView ( ) {
417480 if ( $ ( ".desktop-view" ) . hasClass ( active_class ) ) {
418481 return ;
@@ -504,7 +567,7 @@ function updateRunFuncSessionParameters(runFunc) {
504567
505568 let code = BodyCodeOfFunction ( runFunc ) ;
506569 let tokenType = GetSession ( SessionKeys . TokenType ) ;
507- tokenType = tokenType ? tokenType : defualtTokenType ;
570+ tokenType = ( tokenType != undefined ) ? tokenType : defaultTokenType ;
508571 code = code . replace ( "$('#txtAccessToken').val()" , accessToken )
509572 . replace ( "$('input:radio[name=tokenType]:checked').val()" , tokenType ) ;
510573
0 commit comments