Simple popup or dialog box in Google Apps Script - popup

I'm looking for simple code that adds a popup in my Google Apps Script Ui that comes up when I hit a submit button. The popup box would display a message and have a button to close the popup.
I've looked all over the place - everything seems so complicated and does way more than I need it to do.
This is the current code I have for the submit button.
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;
}

Since UiApp is depreciated, HTMLService should be used to create custom user interfaces.
To prompt simple popup to display a message, use alert method of Ui class
var ui = DocumentApp.getUi();
ui.alert('Hello world');
will prompt simple popup with hello world and an ok button.
To display customized html template in Dialog, use HTMLService to create template and then pass it to showModalDialog method of Ui Class
var html = HtmlService.createHtmlOutput("<div>Hello world</div>").setSandboxMode(HtmlService.SandboxMode.IFRAME);
DocumentApp.getUi().showModalDialog(html, "My Dialog");
HtmlService.createHtmlOutputFromFile allows you to display html that is in a separate file. see the documentation

Have you tried using zIndex? It places the panel above all of your other panels...
var popupPanel = app.createVerticalPanel().setId('popupPanel')
.setVisible(false)
.setStyleAttribute('left', x)
.setStyleAttribute('top', y)
.setStyleAttribute('zIndex', '1')
.setStyleAttribute('position', 'fixed');
x = panel position from the left portion of your app
y = panel position from the top portion of your app
zIndex = the 'layer' your panel will appear on. You can stack panels using '1', '2', '3' etc.
position = your panel will be in a fixed position denoted by (x,y)
Visibility is set to false until you click submit, then have a client handler for your submit button make the popupPanel visible. When you click the button on your popupPanel, have the client handler set visibility to false once again and it will disappear.
One more thing, I noticed you get the active app and then create a new app. You do not need to create a new app...just new panels inside your app.
Hope this helps!

You can use a dialogbox to popup.
Add a button to the dialog-box. Add a client handler that sets the dialog box invisible,once you click the button.
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);
This should help.
EDIT
Added "()" after .createClientHandler. That should remove issues related to TypeError: Cannot find function createDialogBox in object function createApplication() {/* */}

Popup - use something like this:
var table = app.createFlexTable();
table.setStyleAttribute("position", "absolute");
table.setStyleAttribute("background", "white");
add items to the table and hide and show as needed.

Related

In NativeScript, how do I change page/view in a modal page?

I would like to create a multiple step modal dialog - like a wizard. A series of screens that follow on from one another.
I'm using the code from NativeScript's site to display a modal (https://docs.nativescript.org/core-concepts/navigation#modal-pages)
var modalPageModule = "./modal-views-demo/login-page";
var context = "some custom context";
var fullscreen = true;
mainPage.showModal(modalPageModule, context, function closeCallback(username, password) {
// Log the user in...
}, fullscreen);
The code works, but I'm unsure how to change the modalPageModule once the modal is displayed.
Possible duplicate
Nativescript: How to use navigation in modals
https://github.com/NativeScript/NativeScript/issues/3753

Press, hide button in ChartContainerContent in UI5 fiori

Hi all SAP UI5 and FIORI positive,
I have ChartContainer with button for graph and button for table. It is defined in xml file as:
<suite:ChartContainerContent id="idButtonChart"
icon = "sap-icon://bar-chart"
title = "Chart"
>
<suite:ChartContainerContent id="idButtonTable"
icon = "sap-icon://table-view"
title = "{i18n>table}">
<suite:content>
Let's say I want to hide some of these buttons which are placed inside ChartContainer. I have tried (in controller.js part):
this.getView().byId("idButtonChart").setVisible(false);
or
this.getView().byId("idButtonChart").setVisible(false);
But this code, hided graph but not button. Please, do you have any idea how to hide button? Or to trigger click event on button idButtonTable?
Thanks for any advices.
Have you found any good solution for this issue? I've been checking the SDK and I can't find a way to get those buttons in an straight way.
Anyway, you could do it using the following code -
var chartContainerContent = this.getView().byId('your chart id');
var chartContainer = chartContainerContent.getParent();
var aToolbarButtons = chartContainer._oToolBar.getContent();
var segmentedButton;
for(var i=0; i<aToolbarButtons.length; i++){
var button = aToolbarButtons[i];
if(button.getMetadata()._sClassName === "sap.m.SegmentedButton"){
segmentedButton = button;
break;
}
}
//segmentedButton.getButtons()
Once you get the buttons you can setVisible(false) to the one you want.
Of course this is not the best, but the chartContainer doesn't provide any public function to get the buttons of the chart.
I try to understand the issue. You define 2 charts in your example.
The buttons are usually used to switch the display to the corresponding chart.
How are you going to switch between the 2 charts if you hide the corresponding button?
A little late but I guess an .updateChartContainer() after the .setVisible should do the trick:
this.getView().byId("idButtonChart").setVisible(false);
this.getView().byId("<NAME OF THE CONTENT CONTAINER>").updateChartContainer();

How to have an Apps Script Gadget display results directly in the UI

On my Google Site I've inserted an Apps Script Gadget (by pasting the URL of an Apps Script that I published as a service). This Apps Script allows the user to enter a value (their 'Blow Number') and view the corresponding data (based on API calls to my Google Fusion tables).
Right now, the script returns 3 hyperlinks:
Click here for a table of Blow Number 1
Click here for a chart of Blow Number 1
Click here for a map of Blow Number 1
This is because my script function getblowdetails has 3 app.createAnchor variables. Instead of having the script return 3 hyperlinks (that the user has to click on and view the resulting URL in a new window), I would like for the script to automatically invoke the 3 URLs and display the table, chart, and map in panels on the same page.
So the user would enter their Blow Number and press enter. They would then view the table, chart, and map directly below the text box on the same web page.
Please see the Code that I've included below and advise...Thanks for the help- I'm an apps-script novice so a thorough and understand-able response is greatly appreciated!
Code
Note: I've removed the URLs from the createAnchor variables because I'm only allowed to include 2 links in the post, but you can see them by going to www.OnSiteBAC.com/ViewMyBlows and entering Blow Number = 1...then click on the hyperlinks.
function doGet() {
var app = UiApp.createApplication();
// Create input boxes, buttons, labels, and links
var textBoxA = app.createTextBox().setId('textBoxA').setName('textBoxA').setFocus(true);
var buttonA = app.createButton('Get Blow Details').setEnabled(false);
var label = app.createLabel('Please enter your Blow Number here');
var link = app.createAnchor('where can I find my Blow Number?', 'http://www.onsitebac.com');
// Create a handler to call the getblowdetails function.
// A validation is added to this handler so that it will only invoke 'getblowdetails' if textBoxA contains a number
var handler = app.createServerClickHandler('getblowdetails').validateNumber(textBoxA).addCallbackElement(textBoxA);
// Create a handler to enable the button if all input is legal
var onValidInput = app.createClientHandler().validateNumber(textBoxA).forTargets(buttonA).setEnabled(true).forTargets(label, link).setVisible(false);
// Create a handler to mark invalid input in textBoxA and disable the button
var onInvalidInput1 = app.createClientHandler().validateNotNumber(textBoxA).forTargets(buttonA).setEnabled(false).forTargets(textBoxA).setStyleAttribute("color", "red").forTargets(label, link).setVisible(true);
// Create a handler to mark the input in textBoxA as valid
var onValidInput1 = app.createClientHandler().validateNumber(textBoxA).forTargets(textBoxA).setStyleAttribute("color", "black");
// only fire ServerHandler for onKeyUp if it passes validation
var textBoxHandler = app.createServerHandler('textBoxHandlerFunction');
// Add all the handlers to be called when the user types in the text boxes
textBoxHandler.addCallbackElement(textBoxA);
textBoxA.addKeyUpHandler(onInvalidInput1);
textBoxA.addKeyUpHandler(onValidInput1);
textBoxA.addKeyUpHandler(onValidInput);
textBoxA.addKeyUpHandler(textBoxHandler);
buttonA.addClickHandler(handler);
app.add(textBoxA);
app.add(buttonA);
app.add(label);
app.add(link);
return app;
}
function textBoxHandlerFunction(e) {
var app = UiApp.getActiveApplication();
if (e.parameter.keyCode == 13)
{
app = getblowdetails(e);
}
return app;
}
function getblowdetails(e) {
var app = UiApp.getActiveApplication();
var panel2 = app.createVerticalPanel();
var link2 = app.createAnchor ().setStyleAttribute("color", "green");
var panel3 = app.createVerticalPanel();
var link3 = app.createAnchor ();
var panel4 = app.createVerticalPanel();
var link4 = app.createAnchor ();
panel3.add(link3);
app.add(panel3);
panel4.add(link4);
app.add(panel4);
return app;
}
I don't think you'll be able to actually download the result and show it. So, there's no easy solution.
But you can build that table and chart on Apps Script easily (assuming you can already fetch the info from tables using its API).
The last issue is the map. On Apps Script you can only create static maps, meaning, an image. You can add custom markers and polygons, set the zoom, etc. But in the end it's a photo. The user will not be able to drag it around or use the map as an embedded google map as one would expect.

Hide/Show UI elements by MouseOut/MouseOver client handlers

The goal is to mutually replace two elements with each-other by MouseOut/MouseOver events. Specifically the elements are a label and a listbox. There are some UI arrangement in which the implementation works acceptably in Chrome, however it always fails in IE(9). The problem occurs during a selection from the listbox as per browsers ignor the dropped down area as part of the listbox, it triggers the mouseOut handler and hides the listbox.
Is there any solution forcing browsers to consider the listbox together with its dropped down area?
app.createListBox() .setId('listBox');
app.createLabel('Item1') .setId('label')
.addMouseOverHandler(app.createClientHandler()
.forEventSource().setVisible(false)
.forTargets(app.getElementById('listBox')).setVisible(true));
app.getElementById('listBox')
.addItem('Item1')
.addItem('Item2')
.setVisible(false)
.addMouseOutHandler(app.createClientHandler()
.forEventSource().setVisible(false)
.forTargets(app.getElementById('label')).setVisible(true));
Many Thanks
there is a possible workaround using a server handler to hide the listBox. From my tests it behaves quite similarly (if not better ) - you can test it here
function doGet() {
var app = UiApp.createApplication().setStyleAttribute('padding','100px');
var p = app.createVerticalPanel();
var serverHandler = app.createServerHandler('handler').addCallbackElement(p)
var listBox = app.createListBox() .setId('listBox').setName('listBox').addChangeHandler(serverHandler);
var label = app.createLabel('Item1').setId('label')
.addMouseOverHandler(app.createClientHandler()
.forEventSource().setVisible(false)
.forTargets(listBox).setVisible(true));
listBox.addItem('Item1').addItem('Item2').addItem('Item3').addItem('Item4')
.setVisible(false)
p.add(listBox).add(label)
app.add(p)
return app
}
function handler(e){
var app = UiApp.getActiveApplication();
var listBox = app.getElementById('listBox')
var label = app.getElementById('label')
listBox.setVisible(false)
label.setVisible(true).setText(e.parameter.listBox)
return app
}

Whats the best way to programatically open a pane inside Dijit AccordionContainer

I am trying open & close accordion panes programatically. Here is the simplified version of my code. Even though I set the first pane's selected to false and and second pane's selected to true, only the first pane opens when it loads on the browser (FF3).
var accordionContainer = new dijit.layout.AccordionContainer().placeAt("test");
var accordPane = new dijit.layout.ContentPane({"title": "test", "content":"hello"});
var accordPane2 = new dijit.layout.ContentPane({"title": "test1", "content":"hello1"});
accordionContainer.addChild(accordPane);
accordionContainer.addChild(accordPane2, 1);
accordPane.startup();
accordPane2.startup();
//accordionContainer.selectChild(accordPane2);
accordionContainer.startup();
accordPane.selected = false;
accordPane2.selected = true;
You can do it like this:
accordionContainer.selectChild( accordPane2 );
Assuming you are using dojo 1.3.
dijit.layout.AccordionContainer is a subclass of dijit.layout.StackContainer, which has selectChild defined.
I set up a demo page where you can see this code in action
If you were calling selectChild before startup, that could cause the error you were seeing since the widget wasn't in a 'complete' state. (Sorry, missed the commneted out code before I posted original answer)