Voici un petit extrait que j'ai créé précisément pour cette raison. Il utilise cependant un gestionnaire de serveur ...
function MsgBox(message, title, id, buttons, handler, modal, autoHide){
this.message=message;
this.title=title;
this.id=id;
this.buttons=buttons;
this.handler=handler;
this.modal=(modal)?true:false;//Default is false
this.autoHide=(autoHide)?new Boolean(autoHide):true;//Default is true
this.position={};
this.position.top=100;
this.position.left=550;
this.position.width=400;
this.button={};
this.button.ok={name:"Ok",id:"OK_BTN"};
this.button.yes={name:"Yes",id:"YES_BTN"};
this.button.no={name:"No",id:"NO_BTN"};
this.button.cancel={name:"Cancel",id:"CANCEL_BTN"};
this.button.retry={name:"Retry",id:"RETRY_BTN"};
this.addButton=function(btn){
try{
if(this.buttons==undefined){this.buttons=[];}
if(typeof btn=="string"){btn=this.button[btn.toLowerCase()];}//If a string, convert to the intended object
if(btn.name==undefined){return this;}//Check if we've actualy got one of the buttons by checking one of it's properties. Exit if not.
this.buttons.push(btn);
}catch(err){
Logger.log(err.message);
}
return this;
};
this.show=function(e, app){
if(app==undefined){app=UiApp.getActiveApplication();}
if(this.buttons==undefined){this.buttons=[this.button.ok];}//The default is one 'Ok' button
var dialog=app.createDialogBox(true,true).setId(this.id).setText(this.title);
dialog.setPopupPosition(this.position.left,this.position.top);
dialog.setGlassEnabled(this.modal);
dialog.setAutoHideEnabled(this.autoHide);
var basePanel=app.createVerticalPanel().setWidth(this.position.width+"");
basePanel.add(app.createLabel(this.message).setWordWrap(true).setStyleAttribute("padding", "10px"));//Add message
var buttonPanel=app.createHorizontalPanel().setId("ButtonPanel");
basePanel.add(buttonPanel.setStyleAttribute("display", "block").setStyleAttribute("margin-left", "auto").setStyleAttribute("margin-right", "auto"));
var btnHandler=app.createServerHandler("msgBox_close").addCallbackElement(buttonPanel);
for(var i=0;i<this.buttons.length;i++){
var btn=app.createButton(this.buttons[i].name, btnHandler).setId(this.buttons[i].id).setTag(this.id);
if(this.handler!=undefined){btn.addClickHandler(this.handler);}
buttonPanel.add(btn);
}
dialog.add(basePanel).show();
return app;
};
}
function msgBox_close(e, app){
if(app==undefined){app=UiApp.getActiveApplication();}
var dialogId=e.parameter[e.parameter.source+"_tag"];
app.getElementById(dialogId).hide();
return app;
}
Voici un petit exemple pour l'utiliser.
var msgBox=new MsgBox("Testing 123...", "This is a test", "MyMsgBox");
msgBox.show(e, app);
En utilisant le paramètre « _tag » pour faire référence à son propre ID vous faire un aller-retour propre avec peu de tracas.
Vous pouvez ajouter des boutons standard en appelant la fonction .addButton(). Exemple:
msgBox.addButton("yes").addButton("no");
En passant votre propre gestionnaire, vous pouvez appeler vos propres fonctions. Exemple:
function myOwnHandler(e, app){
if(app==undefined){app=UiApp.getActiveApplication();}
if(e.parameter.source.indexOf("YES_BTN")!=-1){
}
return app;
}
Avez-vous essayé une recherche sur ce forum? voici le résultat qui pourrait vous intéresser: http: //stackoverflow.com/search? q =% 5Bgoogle-apps-script% 5Ddialogbox –
Lorsque vous posez une question ici, il est préférable de montrer votre travail. Bien sûr, vous avez utilisé la méthode show() - mais le fait que cela ne fonctionne pas vous dit que vous avez fait quelque chose de mal. Peut-être que vous avez oublié de retourner une instance d'interface utilisateur [comme ce gars] (http://stackoverflow.com/questions/17764814/google-script-unable-to-update-web-page/17788550#17788550). Peut-être que vous avez fait quelque chose d'autre qu'un autre groupe d'yeux pouvait voir. Comment saurions-nous jamais? – Mogsdad