2012-08-22 39 views
3

我正在尋找簡單的代碼,在我點擊提交按鈕時出現的Google Apps腳本Ui中添加了一個彈出窗口。彈出框會顯示一條消息,並有一個關閉彈出窗口的按鈕。Google Apps腳本中的簡單彈出式窗口或對話框

我已經看遍了所有的地方 - 一切似乎都如此複雜,並且做得比我需要做得更多。

這是我用於提交按鈕的當前代碼。

 function doGet() { 
     var app = UiApp.createApplication(); 
     app.setTitle("My Logbook"); 

     var hPanel_01 = app.createHorizontalPanel(); 
     var vPanel_01 = app.createVerticalPanel(); 
     var vPanel_02 = app.createVerticalPanel(); 
     var vPanel_03 = app.createVerticalPanel(); 

     var submitButton = app.createButton("Submit"); 

     //Create click handler 
     var clickHandler = app.createServerHandler("submitData"); 
     submitButton.addClickHandler(clickHandler); 
     clickHandler.addCallbackElement(hPanel_01); 


     ////Test PopUp Panel 
     var app = UiApp.getActiveApplication(); 
     var app = UiApp.createApplication; 
     var dialog = app.createDialogBox(); 
     var closeHandler = app.createClientHandler().forTargets(dialog).setVisible(false); 
     submitButton.addClickHandler(closeHandler); 

     var button= app.createButton('Close').addClickHandler(closeHandler); 

     dialog.add(button); 
     app.add(dialog); 
     ////// 



     return app; 
    } 

回答

2

您是否嘗試過使用zIndex?它把上述所有的其它面板的面板從...應用程式 Y =面板位置的從應用程式 zIndex的=的「層」的頂部左側部分

var popupPanel = app.createVerticalPanel().setId('popupPanel') 
    .setVisible(false)  
    .setStyleAttribute('left', x) 
    .setStyleAttribute('top', y)   
    .setStyleAttribute('zIndex', '1') 
    .setStyleAttribute('position', 'fixed'); 

X =面板位置您的面板將顯示在上面。您可以使用'1','2','3'等堆疊面板。 position =您的面板將位於由(x,y)表示的固定位置

可見性設置爲false,直到您單擊提交,然後爲您的提交按鈕設置一個客戶端處理程序,使popupPanel可見。當您單擊popupPanel上的按鈕時,讓客戶端處理程序再次將可見性設置爲false,並且它將消失。

還有一件事,我注意到你得到了活動的應用程序,然後創建一個新的應用程序。你不需要創建一個新的應用程序......只需在你的應用程序內新面板。

希望這會有所幫助!

+0

謝謝特雷弗!我不知道那件事。 – sbaden 2013-01-22 22:41:42

+0

沒有概率...我經常使用它在一些應用程序中有多個分層面板。這可能相當有效。 – 2013-01-30 01:11:30

0

彈出 - 用這樣的:

 var table = app.createFlexTable(); 
     table.setStyleAttribute("position", "absolute"); 
     table.setStyleAttribute("background", "white");  

項目添加到表和隱藏和顯示需要。

2

您可以使用對話框彈出。 在對話框中添加一個按鈕。添加一個客戶端處理程序,將對話框設置爲不可見,一旦您單擊該按鈕。

var app = UiApp.createApplication; 
var dialog = app.createDialogBox(); 
var closeHandler = app.createClientHandler().forTargets(dialog).setVisible(false); 

var button= app.createButton('Close').addClickHandler(closeHandler); 

dialog.add(button); 
app.add(dialog); 

這應該有所幫助。

編輯

添加 「()」 後.createClientHandler。這應該刪除與相關的問題TypeError:在對象函數createApplication(){/ * * /}中找不到函數createDialogBox

+0

如果我已經有var app = UiApp.createApplication;在我的腳本中,我添加另一個對話框? – sbaden 2012-08-22 19:52:22

+0

如何將其連接到我的提交按鈕,以便在點擊提交按鈕時變爲可見? – sbaden 2012-08-22 19:55:25

+0

如果你已經有了var app,那麼使用var app = UiApp.getActiveApplication();並提交按鈕,只需添加submitButton.addClickHandler(closeHandler); – balajiboss 2012-08-23 08:38:46

2

由於UiApp已折舊,因此應使用HTMLService來創建自定義用戶界面。

要提示簡單彈出顯示消息,使用Ui class

alert方法將提示與世界你好和OK按鈕簡單彈出。

要在對話框中顯示自定義HTML模板,使用HTMLService創建模板,然後將它傳遞給UI類的showModalDialog方法

var html = HtmlService.createHtmlOutput("<div>Hello world</div>").setSandboxMode(HtmlService.SandboxMode.IFRAME); 
DocumentApp.getUi().showModalDialog(html, "My Dialog"); 

HtmlService.createHtmlOutputFromFile允許您顯示HTML是在一個單獨的文件。請參閱documentation

相關問題