从其他几个示例中获取组件。我拼凑了以下脚本(可以在这里运行):
var submissionSSKey = '0AhpMXVz35LNCdG1Qa0c2V1hHRnhOUU00SjQ0SEdlRVE';
var Panelstyle = {'background':'#dddddd','padding':'40px','borderStyle':'solid','borderWidth':'10PX','borderColor':'#bbbbbb'}
function doGet() {
var app = UiApp.createApplication().setTitle('PQOT File Upload').setStyleAttribute('padding','50PX');
var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(500, 200);
var title = app.createHTML('<B>File Upload</B>').setStyleAttribute('color','grey').setStyleAttribute('fontSize','25PX');
var grid = app.createGrid(8,4).setId('grid');
var RequestID = app.createTextBox().setWidth('250px').setName('reqID');
var unix = app.createTextBox().setWidth('250px').setName('unix');
var upLoad = app.createFileUpload().setName('uploadedFile');
var submitButton = app.createSubmitButton('<B>Upload</B>');
var warning = app.createHTML('Please fill in all fields')
.setStyleAttribute('background','#ff6262')
.setStyleAttribute('fontSize','18px');
var uploadtracker = app.createTextBox().setVisible(false);
var cliHandler2 = app.createClientHandler()
.validateLength(RequestID, 5, 5)
.validateInteger(RequestID)
.validateLength(unix, 1, 12)
.validateMatches(uploadtracker, 'selected')
.forTargets(submitButton).setEnabled(true)
.forTargets(warning).setHTML('File upload ready')
.setStyleAttribute('background','#99FF99')
.setStyleAttribute('fontSize','18px');
var cliHandler3 = app.createClientHandler()
.forTargets(uploadtracker)
.setText('selected')
grid.setWidget(0, 1, title)
.setText(1, 0, 'PQOT Request # (5 digits):')
.setWidget(1, 1, RequestID.addKeyUpHandler(cliHandler2))
.setText(2, 0, 'Enter Unix ID:')
.setWidget(2, 1, unix.addKeyUpHandler(cliHandler2))
.setText(3, 0, 'Select File:')
.setWidget(3, 1, upLoad.addChangeHandler(cliHandler3).addChangeHandler(cliHandler2))
.setText(5, 0, 'Completion Check:')
.setWidget(5, 1, warning)
.setWidget(6, 3, submitButton)
.setWidget(7,0,uploadtracker).addClickHandler(cliHandler2);
var cliHandler = app.createClientHandler()
.forTargets(warning).setHTML('FILE UPLOADING...')
.setStyleAttribute('background','#FEFE22')
.setStyleAttribute('fontSize','18px')
.setVisible(true);
submitButton.addMouseUpHandler(cliHandler)
.setEnabled(false);
panel.add(grid);
app.add(panel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
var reqID = e.parameter.reqID;
var unix = e.parameter.unix;
var fileBlob = e.parameter.uploadedFile;
var doc = DocsList.createFile(fileBlob);
var timestamp = Utilities.formatDate(new Date(), "PST", "MM-dd-yyyy HH:mm:ss");
var description = 'Requestor Unix: '+ unix + ' PQOT Request ID: ' + reqID + ' Timestamp: ' + timestamp
doc.setDescription(description)
var folder = DocsList.getFolder ('PQOT Upload')
doc.addToFolder(folder);
var sheet = SpreadsheetApp.openById(submissionSSKey).getSheetByName('Sheet1');
var lastRow = sheet.getLastRow();
var targetRange = sheet.getRange(lastRow+1, 1, 1, 3).setValues([[reqID,unix,doc.getUrl()]]);
var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(500, 200);
var label = app.createLabel('Thank you! Your file was uploaded successfully. To submit another, please refresh your browser: (windows - F5, mac - ⌘ + r). ');
label.setStyleAttribute("color", "green")
.setStyleAttribute("fontSize", "large");
label.setStyleAttribute("text-align","left");
label.setSize(300,200);
panel.add(label);
app.add(panel)
return app;
}
一切都很好,但是我注意到中间消息“文件上传...”没有显示。本节:
var cliHandler = app.createClientHandler()
.forTargets(warning).setHTML('FILE UPLOADING...')
.setStyleAttribute('background','#FEFE22')
.setStyleAttribute('fontSize','18px')
.setVisible(true);
我验证了该错误也发生在类似的脚本中。我认为这与第三次点击处理程序的引入有关。无论如何,这部分代码似乎没有运行,或者由于某种原因小部件不可见。