2013-10-17 2 views
2

Google Apps Script (및 StackOverFlow 너무 : D)를 처음 사용하며 문제가 있으며 이유를 모르겠 음 :/ 문제가 내 ServerClickHandler에있는 것 같습니다. Google에서 문제를 해결할 수 없습니다 :/ 내 앱을 실행하고 버튼을 제출할 때 오류 메시지가 '오류 발생 : 필수 : ​​필수'입니다. 왜 이런 일이 발생하는지 알고 있습니까?"오류가 발생했습니다 : 필수 : ​​필수"

var User = new Object(), 
Url = new Object(); 
// Startet die Web-App 
function doGet() { 
User.email = Session.getActiveUser().getEmail(); 

var app = UiApp.createApplication(); 
var panel = app.createVerticalPanel();//Create a panel which will hold all the elements 
var longUrlLabel = app.createLabel('lange E-Mail hier eingeben - Kurzlink wird dann per E-Mail zugesendet'); 
var longUrlBox = app.createTextBox().setName('longUrl') 
            .setText('http://www.'); 
var longUrlLabelInfo = app.createLabel().setId('shortUrlLabelInfo').setVisible(false); 
var button = app.createButton('Ausführen'); 


var handler = app.createServerClickHandler('buttonOnClickListener');//createHandler for the Button-onClick-Event. 
handler.addCallbackElement(panel); 
button.addClickHandler(handler); //Add this handler to the button 

//Add all the UI elements to the panel 
panel.add(longUrlLabel) 
    .add(longUrlBox) 
    .add(button); 
app.add(panel);//Add the panel to the application 
return app; 
} 

function buttonOnClickListener(eventInfo) { 
var app; 
Url.long = eventInfo.parameter.longUrl.toString(); 
Url.short = UrlShortener.Url.insert(UrlShortener.newUrl().setLongUrl(Url.short)); 
sendMail(); 
app = UiApp.getActiveApplication(); 
app.getElementById('longUrlLabelInfo').setVisible(true).setText(Url.short); 

return app; 
} 

function sendMail() { 
GmailApp.sendEmail(User.email, "UrlShortener", Url.long+" -> "+Url.short); 
} 

답변

0

은 다음과 같이 시도 : (편집 : 나는 UI 좀 얻을 좀 더 명확하고 읽기 값 +가 영어로 번역하는 이메일 레이아웃 ;-) 미안 개선했지만 내 독일어는 매우 좋지 않습니다. (;-)

var User = new Object(), 
Url = new Object(); 
User.email = Session.getActiveUser().getEmail(); 

function doGet() { 
    var app = UiApp.createApplication(); 
    var panel = app.createVerticalPanel().setStyleAttributes({'padding':'40px','backgroundColor':'#fafacc'}); 
    var longUrlLabel = app.createLabel('Enter the long url starting with http:// you will receive an email with the short url immediately.'); 
    var longUrlBox = app.createTextBox().setName('longUrl').addClickHandler(app.createClientHandler().forEventSource().setText('')) 
    .setText('http://').setWidth('500'); 
    var shortUrlLabel = app.createHTML().setId('shortUrlLabel').setVisible(false); 


    var handler = app.createServerHandler('buttonOnClickListener').addCallbackElement(panel); 
    var button = app.createButton('SUBMIT',handler).setStyleAttributes({'border-radius':'5px'}); 

    var grid = app.createGrid(8,1).setId('grid') 
    .setWidget(0,0,longUrlLabel) 
    .setWidget(2,0,longUrlBox) 
    .setWidget(4,0,button) 
    .setWidget(6,0,shortUrlLabel); 

    return app.add(panel.add(grid)); 
} 

function buttonOnClickListener(eventInfo) { 
    var app =UiApp.getActiveApplication(); 
    var toShorten = UrlShortener.newUrl().setLongUrl(eventInfo.parameter.longUrl); 
    var shortened = UrlShortener.Url.insert(toShorten); 
    Url.short = UrlShortener.Url.insert(toShorten); 
    Url.long = eventInfo.parameter.longUrl; 
    sendMail(); 
    app = UiApp.getActiveApplication(); 
    app.getElementById('shortUrlLabel').setVisible(true).setHTML('<li>Short url = <b>'+Url.short.id+'</b></li><li>Mail sent ...</li>'); 
    app.getElementById('grid').setWidget(7,0,app.createAnchor('test (with redirect warning)', Url.short.id)); 

    return app; 
} 

function sendMail() { 
    GmailApp.sendEmail(User.email, "UrlShortener", 'Long url (original) = '+Url.long+"\n\n\nShort url = "+Url.short.id); 
} 

enter image description here

+0

User.email는 클릭 처리기에서 초기화되지 않았습니다. 전역은 단지 각 콜백 중에 라이브가 아니기 때문에 doget 외부에 초기화하십시오 –

+0

그게 내가 한 일입니다 ... –

+0

작품, 고마워요! :) * 편집 * 문제점 : 앱을 사용하는 사용자가 전자 메일을받지는 않지만 항상 저를받습니다. 그래서 GmailApp.sendEmail (User.email, All-Script Admin (me)의 전자 메일로 이동 :(앱을 게시 할 때 올바른 설정을했기 때문에 이해가 안됩니다.) – phip1611

관련 문제