77// ---- Embed Code ----------------------------------------------------
88
99function _Embed_BasicEmbed ( ) {
10+ // Get models. models contains enums that can be used.
11+ var models = window [ 'powerbi-client' ] . models ;
12+
1013 // Read embed application token from textbox
1114 var txtAccessToken = $ ( '#txtAccessToken' ) . val ( ) ;
1215
@@ -16,9 +19,9 @@ function _Embed_BasicEmbed() {
1619 // Read report Id from textbox
1720 var txtEmbedReportId = $ ( '#txtEmbedReportId' ) . val ( ) ;
1821
19- // Get viewMode
20- var checkd = $ ( '#viewMode:checked' ) . val ( ) ;
21- var viewMode = checkd ? 1 : 0 ;
22+ // Embed report in View mode or Edit mode based or checkbox value.
23+ var checked = $ ( '#viewMode:checked' ) . val ( ) ;
24+ var viewMode = checked ? models . ViewMode . Edit : models . ViewMode . View ;
2225
2326 // Embed configuration used to describe the what and how to embed.
2427 // This object is used when calling powerbi.embed.
@@ -29,15 +32,15 @@ function _Embed_BasicEmbed() {
2932 accessToken : txtAccessToken ,
3033 embedUrl : txtEmbedUrl ,
3134 id : txtEmbedReportId ,
32- permissions : 3 /* All*/,
35+ permissions : 3 /*models.Permissions. All gives maximum permissions */,
3336 viewMode : viewMode ,
3437 settings : {
3538 filterPaneEnabled : true ,
3639 navContentPaneEnabled : true
3740 }
3841 } ;
3942
40- // Grab the reference to the div HTML element that will host the report.
43+ // Get a reference to the embedded report HTML element
4144 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
4245
4346 // Embed the report and display it within the div container.
@@ -107,20 +110,19 @@ function _Embed_Create() {
107110 // Create report
108111 var report = powerbi . createReport ( reportContainer , embedCreateConfiguration ) ;
109112
110- // Report.off removes a given event handler if it exists.
111- report . off ( "loaded" ) ;
113+ // // Report.off removes a given event handler if it exists.
114+ // report.off("loaded");
112115
113- // Report.on will add an event handler which prints to Log window.
114- report . on ( "loaded" , function ( ) {
115- Log . logText ( "Loaded" ) ;
116- } ) ;
116+ // // Report.on will add an event handler which prints to Log window.
117+ // report.on("loaded", function() {
118+ // Log.logText("Loaded");
119+ // });
117120}
118121
119122// ---- Report Operations ----------------------------------------------------
120123
121124function _Report_GetId ( ) {
122-
123- // Grab the reference to the div HTML element that will host the report.
125+ // Get a reference to the embedded report HTML element
124126 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
125127
126128 // Get a reference to the embedded report.
@@ -139,7 +141,7 @@ function _Report_UpdateSettings() {
139141 filterPaneEnabled : false
140142 } ;
141143
142- // Grab the reference to the div HTML element that will host the report.
144+ // Get a reference to the embedded report HTML element
143145 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
144146
145147 // Get a reference to the embedded report.
@@ -156,7 +158,7 @@ function _Report_UpdateSettings() {
156158}
157159
158160function _Report_GetPages ( ) {
159- // Grab the reference to the div HTML element that will host the report.
161+ // Get a reference to the embedded report HTML element
160162 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
161163
162164 // Get a reference to the embedded report.
@@ -177,7 +179,7 @@ function _Report_GetPages() {
177179}
178180
179181function _Report_SetPage ( ) {
180- // Grab the reference to the div HTML element that will host the report.
182+ // Get a reference to the embedded report HTML element
181183 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
182184
183185 // Get a reference to the embedded report.
@@ -205,7 +207,7 @@ function _Report_SetPage() {
205207}
206208
207209function _Report_GetFilters ( ) {
208- // Grab the reference to the div HTML element that will host the report.
210+ // Get a reference to the embedded report HTML element
209211 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
210212
211213 // Get a reference to the embedded report.
@@ -234,7 +236,7 @@ function _Report_SetFilters() {
234236 values : [ "Lindseys" ]
235237 } ;
236238
237- // Grab the reference to the div HTML element that will host the report.
239+ // Get a reference to the embedded report HTML element
238240 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
239241
240242 // Get a reference to the embedded report.
@@ -252,7 +254,7 @@ function _Report_SetFilters() {
252254}
253255
254256function _Report_RemoveFilters ( ) {
255- // Grab the reference to the div HTML element that will host the report.
257+ // Get a reference to the embedded report HTML element
256258 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
257259
258260 // Get a reference to the embedded report.
@@ -269,7 +271,7 @@ function _Report_RemoveFilters() {
269271}
270272
271273function _Report_PrintCurrentReport ( ) {
272- // Grab the reference to the div HTML element that will host the report.
274+ // Get a reference to the embedded report HTML element
273275 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
274276
275277 // Get a reference to the embedded report.
@@ -286,7 +288,7 @@ function _Report_PrintCurrentReport() {
286288}
287289
288290function _Report_Reload ( ) {
289- // Grab the reference to the div HTML element that will host the report.
291+ // Get a reference to the embedded report HTML element
290292 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
291293
292294 // Get a reference to the embedded report.
@@ -303,7 +305,7 @@ function _Report_Reload() {
303305}
304306
305307function _Report_FullScreen ( ) {
306- // Grab the reference to the div HTML element that will host the report.
308+ // Get a reference to the embedded report HTML element
307309 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
308310
309311 // Get a reference to the embedded report.
@@ -314,7 +316,7 @@ function _Report_FullScreen() {
314316}
315317
316318function _Report_ExitFullScreen ( ) {
317- // Grab the reference to the div HTML element that will host the report.
319+ // Get a reference to the embedded report HTML element
318320 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
319321
320322 // Get a reference to the embedded report.
@@ -325,7 +327,7 @@ function _Report_ExitFullScreen() {
325327}
326328
327329function _Report_switchModeEdit ( ) {
328- // Grab the reference to the div HTML element that will host the report.
330+ // Get a reference to the embedded report HTML element
329331 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
330332
331333 // Get a reference to the embedded report.
@@ -336,7 +338,7 @@ function _Report_switchModeEdit() {
336338}
337339
338340function _Report_switchModeView ( ) {
339- // Grab the reference to the div HTML element that will host the report.
341+ // Get a reference to the embedded report HTML element
340342 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
341343
342344 // Get a reference to the embedded report.
@@ -347,7 +349,7 @@ function _Report_switchModeView() {
347349}
348350
349351function _Report_save ( ) {
350- // Grab the reference to the div HTML element that will host the report.
352+ // Get a reference to the embedded report HTML element
351353 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
352354
353355 // Get a reference to the embedded report.
@@ -360,18 +362,13 @@ function _Report_save() {
360362 report . off ( "saved" ) ;
361363
362364 // report.on will add an event handler which prints to Log window.
363- report . on ( "saved" , function ( ) {
364- var reportObjectId = event . detail . reportObjectId ;
365- var isSaveAs = event . detail . saveAs ;
366- var name = event . detail . reportName ;
367- Log . logText ( "Report name " + name ) ;
368- Log . logText ( "Save Report Completed, reportObjectId: " + reportObjectId ) ;
369- Log . logText ( "Is saveAs: " + isSaveAs . toString ( ) ) ;
365+ report . on ( "saved" , function ( event ) {
366+ Log . log ( event . detail ) ;
370367 } ) ;
371368}
372369
373370function _Report_saveAs ( ) {
374- // Grab the reference to the div HTML element that will host the report.
371+ // Get a reference to the embedded report HTML element
375372 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
376373
377374 // Get a reference to the embedded report.
@@ -388,39 +385,15 @@ function _Report_saveAs() {
388385 report . off ( "saved" ) ;
389386
390387 // report.on will add an event handler which prints to Log window.
391- report . on ( "saved" , function ( ) {
392- var reportObjectId = event . detail . reportObjectId ;
393- var isSaveAs = event . detail . saveAs ;
394- var name = event . detail . reportName ;
395- Log . logText ( "Report name " + name ) ;
396- Log . logText ( "Save Report Completed, new reportObjectId: " + reportObjectId ) ;
397- Log . logText ( "Is saveAs: " + isSaveAs . toString ( ) ) ;
388+ report . on ( "saved" , function ( event ) {
389+ Log . log ( event . detail ) ;
398390 } ) ;
399391}
400392
401- function _Report_setAccessToken ( ) {
402- // Grab the reference to the div HTML element that will host the report.
403- var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
404-
405- // Get a reference to the embedded report.
406- report = powerbi . get ( reportContainer ) ;
407-
408- // New AccessToken
409- var newAccessToken = "newAccessToken" ;
410-
411- // Set new AccessToken
412- report . setAccessToken ( newAccessToken ) . then ( function ( result ) {
413- Log . log ( "AccessToken set" ) ;
414- } )
415- . catch ( function ( errors ) {
416- Log . log ( errors ) ;
417- } ) ;
418- }
419-
420393// ---- Page Operations ----------------------------------------------------
421394
422395function _Page_SetActive ( ) {
423- // Grab the reference to the div HTML element that will host the report.
396+ // Get a reference to the embedded report HTML element
424397 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
425398
426399 // Get a reference to the embedded report.
@@ -439,7 +412,7 @@ function _Page_SetActive() {
439412}
440413
441414function _Page_GetFilters ( ) {
442- // Grab the reference to the div HTML element that will host the report.
415+ // Get a reference to the embedded report HTML element
443416 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
444417
445418 // Get a reference to the embedded report.
@@ -462,7 +435,7 @@ function _Page_GetFilters() {
462435}
463436
464437function _Page_SetFilters ( ) {
465- // Grab the reference to the div HTML element that will host the report.
438+ // Get a reference to the embedded report HTML element
466439 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
467440
468441 // Get a reference to the embedded report.
@@ -498,7 +471,7 @@ function _Page_SetFilters() {
498471}
499472
500473function _Page_RemoveFilters ( ) {
501- // Grab the reference to the div HTML element that will host the report.
474+ // Get a reference to the embedded report HTML element
502475 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
503476
504477 // Get a reference to the embedded report.
@@ -523,7 +496,7 @@ function _Page_RemoveFilters() {
523496// ---- Event Listener ----------------------------------------------------
524497
525498function _Events_PageChanged ( ) {
526- // Grab the reference to the div HTML element that will host the report.
499+ // Get a reference to the embedded report HTML element
527500 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
528501
529502 // Get a reference to the embedded report.
@@ -545,7 +518,7 @@ function _Events_PageChanged() {
545518}
546519
547520function _Events_DataSelected ( ) {
548- // Grab the reference to the div HTML element that will host the report.
521+ // Get a reference to the embedded report HTML element
549522 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
550523
551524 // Get a reference to the embedded report.
@@ -567,7 +540,7 @@ function _Events_DataSelected() {
567540}
568541
569542function _Events_SaveAsTriggered ( ) {
570- // Grab the reference to the div HTML element that will host the report.
543+ // Get a reference to the embedded report HTML element
571544 var reportContainer = $ ( '#reportContainer' ) [ 0 ] ;
572545
573546 // Get a reference to the embedded report.
@@ -578,11 +551,10 @@ function _Events_SaveAsTriggered() {
578551
579552 // Report.on will add an event listener.
580553 report . on ( "saveAsTriggered" , function ( event ) {
581- var eventType = event . type ;
582- Log . logText ( "Event Triggered: " + eventType ) ;
554+ Log . log ( event ) ;
583555 } ) ;
584556
585- // Select Run and change to a different page .
557+ // Select Run and then run SaveAs .
586558 // You should see an entry in the Log window.
587559
588560 Log . logText ( "Run SaveAs to see events in Log window." ) ;
0 commit comments