gApps スクリプトの使用を開始したばかりで、タスクの処理中に送信ボタンを無効にするように UI を設定しようとしているときに、コード (以下) で 2 つの問題が発生しました。
スクリプトを読み込もうとすると、「エラーが発生しました: 予期しないエラーが発生しました」というエラーが表示されることがあります。このエラーは、スクリプトを更新するだけで読み込まれるという点で一貫性がありません。コードをまったく変更していないのに、機能する場合と機能しない場合があるのは本当に気になります。
最後の 3 行目
//button_submit.setEnabled(true);
のコメントを外すと、スクリプトを読み込もうとするたびにエラーが発生します。
何が問題なのかを理解しようとしているときに、getElementById() が送信ボタンに正しい UI タイプを割り当てていないように見えることに気付きました。これが問題の原因かどうかはわかりませんが、単純な基盤から問題を再現できるかどうかを確認するために作成したテスト スクリプトで同じ動作が見られたため、そうではないと思われます。
この問題の原因についてフィードバックをお寄せいただければ幸いです。
ありがとう
クリスBP
Logging output
populate_assign_list spinner.getId():spinner
populate_assign_list spinner.getType():Image
populate_assign_list button_submit.getId():button_submit
populate_assign_list button_submit.getType():Generic
doGet button_submit.getId():spinner
doGet button_submit.getType():Image
doGet button_submit.getId():button_submit
doGet button_submit.getType():SubmitButton
.
//define global script property variables
var prop_home_folder_id; //String - Contains the home folder's ID string
var prop_subject_folder_names; //Array of Strings - Listing of folder names
var prop_subject_folder_ids; //Array of Strings - Listing of folder IDs associated with folder names
var prop_submisison_ss_ids; //Array of Strings - Losting of sumission spreadsheet IDs
var prop_allow_anon_submit; //Flag - Allow manual entry of email address (ie. non domain access) Default to FALSE
function save_script_prop_(home_folder_id, subject_folder_names, subject_folder_ids, submisison_ss_ids, allow_anon_submit) {
//array values must be sent to this function as comma separated strings ie <array>.join(',')
if (home_folder_id != null) ScriptProperties.setProperty("home_folder_id", home_folder_id);
if (subject_folder_names != null) ScriptProperties.setProperty("subject_folder_names", subject_folder_names);
if (subject_folder_ids != null) ScriptProperties.setProperty("subject_folder_ids", subject_folder_ids);
if (submisison_ss_ids != null) ScriptProperties.setProperty("submisison_ss_ids", submisison_ss_ids);
if (allow_anon_submit != null) ScriptProperties.setProperty("allow_anon_submit", allow_anon_submit);
}
function load_script_prop_() {
/*
prop_home_folder_id = ScriptProperties.getProperty("home_folder_id");
prop_subject_folder_names = ScriptProperties.getProperty("subject_folder_names").split(",");
prop_subject_folder_ids = ScriptProperties.getProperty("subject_folder_ids").split(",");
prop_submisison_ss_ids = ScriptProperties.getProperty("submisison_ss_ids").split(",");
prop_allow_anon_submit = ScriptProperties.getProperty("allow_anon_submit");
//*/
prop_home_folder_id = "";
prop_subject_folder_names = ["1","2","3"];
prop_subject_folder_ids = ["1","2","3"];
prop_submisison_ss_ids = ["a","b","c"];
prop_allow_anon_submit = false;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
app.add(app.createLabel("Form submitted"));
return app;
}
function doGet() {
load_script_prop_();
var testing_message = "";
//create ui app and panels
var app = UiApp.createApplication().setTitle("Assignment Submission");
var v_panel = app.createVerticalPanel();
v_panel.setSpacing(20);
var layout_grid = app.createGrid(5,2);
var form_panel = app.createFormPanel();
var tab_panel_upload = app.createTabPanel().setId("tab_panel_upload");
var v_panel_upload_file = app.createVerticalPanel().setTag(0); //Tag refrenced the number of upload elements currently in the tab
var v_panel_upload_gdoc = app.createVerticalPanel().setTag(0); //Tag refrenced the number of gdoc elements currently in the tab
//create menu objects
var spinner = app.createImage("http://www.worldmsday.org/1000-faces/images/whatami/spinner.gif").setVisible(false).setId("spinner");
var datebox_submission = app.createDateBox().setId("submission_datebox").setValue(new Date()).setEnabled(false);
var textbox_user = app.createTextBox().setId("textbox_user").setName("textbox_user").setValue(Session.getUser().getEmail()).setEnabled(false);
var lb_subject_folder = app.createListBox().setId("lb_subject_folder").setName("lb_subject_folder");
lb_subject_folder.setVisibleItemCount(1);
for (var i in prop_subject_folder_names) lb_subject_folder.addItem(prop_subject_folder_names[i], i);
lb_subject_folder.setSelectedIndex(0);
var lb_assign_list = app.createListBox().setId("lb_assign_list").setName("lb_assign_list");
lb_assign_list.setVisibleItemCount(1);
populate_assign_list();
lb_assign_list.setSelectedIndex(0);
var button_submit = app.createSubmitButton("Submit").setId("button_submit");
Logger.log("doGet button_submit.getId():"+spinner.getId());
Logger.log("doGet button_submit.getType():"+spinner.getType());
Logger.log("doGet button_submit.getId():"+button_submit.getId());
Logger.log("doGet button_submit.getType():"+button_submit.getType());
//button_submit.setEnabled(false);
//button_submit.setEnabled(true);
var upload_1 = app.createFileUpload().setName("upload_1");
var gdoc_1 = app.createLabel("Not Yet Implemented");
//create menu handlers
var handler_lb_subject_folder_spinner = app.createClientHandler().forTargets(spinner).setVisible(true);
handler_lb_subject_folder_spinner.forTargets([lb_assign_list, tab_panel_upload]).setVisible(false);
handler_lb_subject_folder_spinner.forTargets(button_submit).setEnabled(false);
var handler_lb_subject_folder = app.createServerHandler("populate_assign_list").addCallbackElement(v_panel);
lb_subject_folder.addChangeHandler(handler_lb_subject_folder_spinner);
lb_subject_folder.addChangeHandler(handler_lb_subject_folder);
//need to add an onchange handler for subject folder listbox which updates the assignment selection listbox.
//add ui objects to ui
layout_grid.setText(0,0, "Date: ");
layout_grid.setWidget(0, 1, datebox_submission);
layout_grid.setText(1,0, "Name: ");
//layout_grid.setWidget(1, 1, "");
layout_grid.setText(2,0, "Email Address: ");
layout_grid.setWidget(2, 1, textbox_user);
layout_grid.setText(3,0, "Course: ");
layout_grid.setWidget(3, 1, lb_subject_folder);
layout_grid.setText(4,0, "Assignment: ");
layout_grid.setWidget(4, 1, lb_assign_list);
v_panel.add(layout_grid);
v_panel.add(spinner);
v_panel_upload_file.add(upload_1);
tab_panel_upload.add(v_panel_upload_file, "Upload File");
v_panel_upload_file.add(gdoc_1);
tab_panel_upload.add(v_panel_upload_gdoc, "Share gDoc");
tab_panel_upload.selectTab(0);
v_panel.add(tab_panel_upload);
v_panel.add(button_submit);
form_panel.add(v_panel);
app.add(form_panel);
var testing_label = app.createLabel("No Test Output").setStyleAttribute("textAlign", "center");
if (testing_message != "") debug_label.setText(testing_label);
app.add(testing_label);
return(app);
}
function populate_assign_list(e) {
load_script_prop_();
if (e == null) subject_id=0;
else subject_id = e.parameter.lb_subject_folder;
var app = UiApp.getActiveApplication();
var lb_assign_list = app.getElementById("lb_assign_list");
lb_assign_list.clear();
var assign_list = ["x","y","z" ];
for (var i = 1; i < assign_list.length; i++) {
lb_assign_list.addItem(assign_list[i] );
}
lb_assign_list.setVisible(true);
var spinner = app.getElementById("spinner").setVisible(false);
Logger.log("populate_assign_list spinner.getId():" + spinner.getId());
Logger.log("populate_assign_list spinner.getType():" + spinner.getType());
app.getElementById("tab_panel_upload").setVisible(true);
var button_submit = app.getElementById("button_submit");
Logger.log("populate_assign_list button_submit.getId():"+button_submit.getId());
Logger.log("populate_assign_list button_submit.getType():"+button_submit.getType());
//button_submit.setEnabled(true);
return app;
}