I have written a quite complex script which calls a server handler to refresh elements in a grid at the press of a button.
For code re-use and consistent behaviour, I am wanting to call that server handler directly during the initial painting of the grid.
When the server handler gets called by clicking on the button, all expected widgets are available and can be queried with e.parameter.widget etc.
When I call the function directly and pass it the panel variable, the value of e is just 'AbsolutePanel'.
Is there some way I can emulate the addCallbackElement way of passing the entire panel and all widgets it contains to the function?
Or a way of automatically firing a server handler on script start?
Please forgive any syntax errors below, I have pruned 500 lines of code down to the pertinent bits!
Thanks
Tony
function doGet() {
var app = UiApp.createApplication();
var mainPanel = app.createAbsolutePanel();
var monthsAbbr = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.'];
var Dates = Array();
var period = 5;
var dateHidden = Array();
var dayOfMonth = new Date(((period * 28) + 15887) * 86400000);
var dateString = '';
var dayOfWeek = 0;
for (var i=0; i<84; i++) {
dateString = dayOfMonth.getDate() + ' ' + monthsAbbr[dayOfMonth.getMonth()] + ' ' + (dayOfMonth.getFullYear() - 2000);
Dates [i] = dateString;
dateHidden[i] = app.createHidden('dates'+i, dateString).setId('dates'+i);
mainPanel.add(dateHidden[i]);
dayOfMonth = new Date(dayOfMonth.getTime() + 86400000);
}
var buttonReset = app.createButton('Reset').setId('buttonReset');
var handlerChange = app.createServerHandler('myHandlerChange');
handlerChange.addCallbackElement(mainPanel);
mainPanel.add(buttonReset.addChangeHandler(handlerChange));
app.add(mainPanel);
myHandlerChange(mainPanel);
return app;
}
function myHandlerChange(e) {
var app = UiApp.getActiveApplication();
Logger.log('Here are the widgets passed into the function: ' + Utilities.jsonStringify(e));
return app;
}