【问题标题】:Computer Availability (UI form validation)计算机可用性(UI 表单验证)
【发布时间】:2013-09-20 19:10:38
【问题描述】:

我创建了一个表格,用于跟踪在特定日期注册计算机实验室的学生人数。我的问题是当个人开始注册并且学生人数超过可用计算机数量时,我希望表单生成一条消息,无论是个人还是与该特定日期已经注册的人数相结合.

如果没有填满,我还希望它告诉他们实验室中还剩下多少个位置。

我的问题是,当太多人注册实验室时,我想知道我会添加什么代码来创建消息。我不知道从哪里开始或如何去做

现在我所做的只是跟踪注册人数。

//Create the GUI form

function doGet() {
  var app = UiApp.createApplication().setTitle('DHS: Kurzweil Calendar');

  //Create a panel which holds all the form elelemnts
  var vertMainPanel = app.createVerticalPanel().setId('vertMainPanel');

  //Create the form elelemnts
  var lblTeacherName = app.createLabel('Teacher Name:');
  var txtTeacherName = app.createTextBox().setName('txtTeacherName');

  var lblExt = app.createLabel('Ext:');
  var txtExt = app.createTextBox().setName('txtExt');

  var lblDate = app.createLabel('Date:');
  var boxDate = app.createDateBox().setId('boxDate').setName('boxDate');

  var lbxSubject = app.createListBox().setId('lbxSubject').setName('lbxSubject');
        lbxSubject.setVisibleItemCount(5);
        lbxSubject.addItem('-- Select One --');
        lbxSubject.addItem('Algebra I (OCS)');
        lbxSubject.addItem('Algebra II');
        lbxSubject.addItem('Algebra II (Honors)');
        lbxSubject.addItem('Agriscience Applications');
        lbxSubject.addItem('Agriscience Applications (OCS)');
        lbxSubject.addItem('Anatomy and Physiology');
        lbxSubject.addItem('Anatomy and Physiology (Honors)');
        lbxSubject.addItem('Animal Science');
        lbxSubject.addItem('American Sign Language II');
        lbxSubject.addItem('Apparel I');
        lbxSubject.addItem('Art History (AP)');
        lbxSubject.addItem('Advanced Functions and Modeling');
        lbxSubject.addItem('Automotive Computer System Diagnostics');
        lbxSubject.addItem('Automotive Brakes');
        lbxSubject.addItem('Automotive Service');
        lbxSubject.addItem('Automotive Service (OCS)'); 
        lbxSubject.addItem('Benchmarks');
        lbxSubject.addItem('Bible History');
        lbxSubject.addItem('Biology');
        lbxSubject.addItem('Biology (AP)');
        lbxSubject.addItem('Biology (Honors)');
        lbxSubject.addItem('Biology (OCS)');
        lbxSubject.addItem('Biomedical Technology');
        lbxSubject.addItem('Biotechnology and Agriscience');
        lbxSubject.addItem('Calculus AB (AP)');
        lbxSubject.addItem('Calculus BC (AP)');
        lbxSubject.addItem('Carpentry I');
        lbxSubject.addItem('Carpentry I (OCS)');
        lbxSubject.addItem('Carpentry III');
        lbxSubject.addItem('Chemistry');
        lbxSubject.addItem('Chemistry (AP)');
        lbxSubject.addItem('Chemistry (Honors)');
        lbxSubject.addItem('Choral Arts (Beginning)');
        lbxSubject.addItem('Civics and Economics');
        lbxSubject.addItem('Civics and Economics (Honors)');
        lbxSubject.addItem('Computer Programming I');
        lbxSubject.addItem('Computer Science (AP)');
        lbxSubject.addItem('Computer Technology');
        lbxSubject.addItem('Concert Band II (Beginning)');        
        lbxSubject.addItem('Concert Band II (Proficient)');
        lbxSubject.addItem('Core and Sustainable Construction');
        lbxSubject.addItem('Core and Sustainable Construction (OCS)');
        lbxSubject.addItem('Digital Media I');
        lbxSubject.addItem('Digitial Media I (OCS)');
        lbxSubject.addItem('Digital Media II');
        lbxSubject.addItem('Discrete Mathematics');
        lbxSubject.addItem('Drafting I');
        lbxSubject.addItem('Drafting Architecture II (Honors)');
        lbxSubject.addItem('Drafting Architecture III (Honors)');
        lbxSubject.addItem('Earth and Environmental Science');
        lbxSubject.addItem('Earth and Environmental Sceince (AP)');
        lbxSubject.addItem('Earth and Environmental Science (Honors)');
        lbxSubject.addItem('Early Childhood Ed I');
        lbxSubject.addItem('eCommerce I (Honors)');
        lbxSubject.addItem('English I');
        lbxSubject.addItem('English I (Honors)');
        lbxSubject.addItem('English II');        
        lbxSubject.addItem('English II (Honors)');
        lbxSubject.addItem('English II (OCS)');
        lbxSubject.addItem('English III');
        lbxSubject.addItem('English III (Honors)');
        lbxSubject.addItem('English III (OCS)');
        lbxSubject.addItem('English IV');
        lbxSubject.addItem('English IV (Honors)');
        lbxSubject.addItem('English IV (OCS)');
        lbxSubject.addItem('English Lang and Comp (AP)');
        lbxSubject.addItem('English Language Arts II');
        lbxSubject.addItem('English Language Arts III');
        lbxSubject.addItem('Engish Literature (AP)');
        lbxSubject.addItem('European History (AP)');
        lbxSubject.addItem('Fashion Merchandising');
        lbxSubject.addItem('Financial Management (OCS)');
        lbxSubject.addItem('Foods I');
        lbxSubject.addItem('Foods I (OCS)');
        lbxSubject.addItem('Foods II - Enterprise');
        lbxSubject.addItem('Foods II - Advanced (OCS)');
        lbxSubject.addItem('French I');
        lbxSubject.addItem('French II');
        lbxSubject.addItem('French III (Honors)');
        lbxSubject.addItem('Functional Finances');
        lbxSubject.addItem('Geometry'); 
        lbxSubject.addItem('Geometry (Honors)');
        lbxSubject.addItem('German I');
        lbxSubject.addItem('German II');
        lbxSubject.addItem('German III (Honors)');
        lbxSubject.addItem('Health and Physical Education');
        lbxSubject.addItem('Health Sciences (Advanced Studies)');
        lbxSubject.addItem('Health Team Relations');
        lbxSubject.addItem('Human Geography (AP)');
        lbxSubject.addItem('Holocaust and Peace Studies');
        lbxSubject.addItem('Horticulture I');
        lbxSubject.addItem('Horticulture I (OCS)');
        lbxSubject.addItem('Horticulture II');
        lbxSubject.addItem('Horticulture II (OCS)');
        lbxSubject.addItem('Integrated Math I');
        lbxSubject.addItem('Interior Design I');
        lbxSubject.addItem('Introduction to Math');
        lbxSubject.addItem('Japanese I');
        lbxSubject.addItem('JROTC I');
        lbxSubject.addItem('JROTC II');
        lbxSubject.addItem('JROTC III');
        lbxSubject.addItem('JROTC IV');
        lbxSubject.addItem('Latin I');
        lbxSubject.addItem('Latim II');
        lbxSubject.addItem('Latin III (Honors)');
        lbxSubject.addItem('Leadership Development');
        lbxSubject.addItem('Marketing Management');
        lbxSubject.addItem('Masonry I');
        lbxSubject.addItem('Masonry I (OCS)');
        lbxSubject.addItem('Masonry III');
        lbxSubject.addItem('Microsoft Excel and Access');
        lbxSubject.addItem('Microsoft Word PowerPoint and Publisher');
        lbxSubject.addItem('Multimedia and Webpage Design');
        lbxSubject.addItem('Music Business and Recording (Beginning)');
        lbxSubject.addItem('Occupational Preparations I');
        lbxSubject.addItem('Occupational Preparations II');
        lbxSubject.addItem('Occupational Preparations III');
        lbxSubject.addItem('Occupational Preparations IV');
        lbxSubject.addItem('Parent and Child Development');        
        lbxSubject.addItem('Parent and Child Development (OCS)');
        lbxSubject.addItem('Personal Finance');        
        lbxSubject.addItem('Personal Finance (OCS)');
        lbxSubject.addItem('Physical Science');
        lbxSubject.addItem('Physics (Honors)');
        lbxSubject.addItem('Pre-Calculus (Honors)');
        lbxSubject.addItem('Professional Management and Leadership I');
        lbxSubject.addItem('Professional Management and Leadership II');
        lbxSubject.addItem('Psychology');
        lbxSubject.addItem('Physcology (AP)');
        lbxSubject.addItem('Psychology (Honors)');
        lbxSubject.addItem('SAT Preparation');
        lbxSubject.addItem('Science and Technical Visualization I');
        lbxSubject.addItem('Science and Technical Visualization II');
        lbxSubject.addItem('Social Studies (OCS)');
        lbxSubject.addItem('Spanish I');
        lbxSubject.addItem('Spanish II');
        lbxSubject.addItem('Spanish III (Honors)');
        lbxSubject.addItem('Spanish IV (Honors)');
        lbxSubject.addItem('Special Topics of Mathematics');
        lbxSubject.addItem('Symphonic Band II (Beginning)');
        lbxSubject.addItem('Symphonic Band II (Intermediate)');
        lbxSubject.addItem('Symphonic Band II (Proficient)');
        lbxSubject.addItem('Technology Engineering and Design');
        lbxSubject.addItem('Theatre Arts (Beginning)');
        lbxSubject.addItem('Theatre Arts (Intermediate)');
        lbxSubject.addItem('US History');
        lbxSubject.addItem('US History (AP)');
        lbxSubject.addItem('US History (Honors)');
        lbxSubject.addItem('Visual Arts (Beginning)');
        lbxSubject.addItem('Visual Arts (Intermediate)');
        lbxSubject.addItem('Visual Arts (Proficient)');
        lbxSubject.addItem('Visual Arts (Advanced)');
        lbxSubject.addItem('Visual Arts Specialization in Ceramics (Advanced)');
        lbxSubject.addItem('Vocal Ensemble (Intermediate)');
        lbxSubject.addItem('Vocal Ensemble (Proficient)');
        lbxSubject.addItem('Wind Ensemble II (Intermediate)');
        lbxSubject.addItem('Wind Ensemble II (Proficient)');
        lbxSubject.addItem('Wind Ensemble II (Advanced)');
        lbxSubject.addItem('World Geography');
        lbxSubject.addItem('World History');
        lbxSubject.addItem('World History');
        lbxSubject.addItem('World History (Honors)');

  var lbxPeriod = app.createListBox().setId('lbxPeriod').setName('lbxPeriod');
        lbxSubject.setVisibleItemCount(1);
        lbxPeriod.addItem('-- Select One --');
        lbxPeriod.addItem('1st Period');
        lbxPeriod.addItem('2nd Period');
        lbxPeriod.addItem('3rd Period');
        lbxPeriod.addItem('4th Period');

  var lblStudentNum = app.createLabel('Number of Students:');
  var txtStudentNum = app.createTextBox().setName('txtStudentNum');

  var radSource1 = app.createRadioButton('group1', 'Hard-Copy').setFormValue('Hard-Copy').setName('Hard-Copy').setId('Hard-Copy');
  var radSource2 = app.createRadioButton('group1', 'Electronic-Copy').setFormValue('Electronic-Copy').setName('Electronic-Copy').setId('Electronic-Copy');

  var radSource3 = app.createRadioButton('group2', 'Teacher-Made Exam').setFormValue('Teacher-Made Exam').setName('Teacher-Made').setId('Teacher-Made');
  var radSource4 = app.createRadioButton('group2', 'Elements Exam').setFormValue('Elements Exam').setName('Elements').setId('Elements');
  var radSource5 = app.createRadioButton('group2', 'Quia Exam').setFormValue('Quia Exam').setName('Quia').setId('Quia');

  var btnCreate = app.createButton('Create Event');

  //Create handler which will execute 'createEvents(e)' on clicking the button
  var evtHandler = app.createServerClickHandler('createEvents');
      evtHandler.addCallbackElement(vertMainPanel);
  //Add this handler to the button
      btnCreate.addClickHandler(evtHandler);

  //Add all the elemnts to the panel 
  vertMainPanel.add(lblTeacherName)
       .add(txtTeacherName)
       .add(lblExt)
       .add(txtExt)
       .add(lblDate)
       .add(boxDate)
       .add(lbxSubject)
       .add(lbxPeriod)
       .add(lblStudentNum)
       .add(txtStudentNum)
       .add(radSource1)
       .add(radSource2)
       .add(radSource3)
       .add(radSource4)
       .add(radSource5)
       .add(btnCreate);

  //Add this panel to the application
  app.add(vertMainPanel);

  //Return the application
  return app;
}

function createEvents(e){

  //Get the active application
  var app = UiApp.getActiveApplication();

  try{
    //Get the entries
    var ssTeacher = e.parameter.txtTeacherName;
    var ssExt = e.parameter.txtExt;
    var ssSubject = e.parameter.lbxSubject;
    var ssPeriod = e.parameter.lbxPeriod;
    var ssStudentNum = e.parameter.txtStudentNum;
    var ssSource = "";
    var ssType = "";
    var eventDate = e.parameter.boxDate;
    var eventCalSubject = ssPeriod + ": " + ssTeacher + " (" + ssStudentNum + ")";
    var eventCalDetails = "Extension: " + ssExt + "\n" +
          "Subject: " + ssSubject + "\n\n" +
          "Source: " + ssSource + "\n" +
          "Type: " + ssType + "\n";

    //Get the calendar
    var cal = CalendarApp.getCalendarById('davie.k12.nc.us_d2mv2eb8aspuant1vb5j6r3sis@group.calendar.google.com');//Change the calendar id
    //Create the events
    cal.createAllDayEvent(eventCalSubject, Utilities.formatDate(eventDate, 'EST', 'MM/DD/YYYY'), {description:eventCalDetails});

    //Log the entries in a spreadsheet
    var ss = SpreadsheetApp.openById('0Aur3owCpuUY-dGJIOGZ1LXhqT2FNMGVXSGNJazFnUmc#gid=0');//Change the spreadhseet key to yours
    var sheet = ss.getSheets()[0];
    sheet.getRange(sheet.getLastRow()+1, 1, 1, 10).setValues([[new Date(), eventDate, ssTeacher, ssExt, ssSubject, ssPeriod, ssSource, ssType, ssStudentNum, 'Event created']]);

    //Show the confirmation message
    app.add(app.createLabel('Kurzweil Calendar Event created successfully...'));
    //Make the form panel invisible
    app.getElementById('vertMainPanel').setVisible(false);
    return app;
  }

  //If an error occurs, show it on the panel
  catch(e){
    app.add(app.createLabel('Error occured: '+ e));
    return app;
  }
}

【问题讨论】:

  • 您的问题是什么?您能否分享您已经拥有的代码,显示您实现上述要求的探针?
  • 我已经在上面添加了我的代码并试图澄清我的问题......
  • 您在执行此任务时遇到的具体问题或困难是什么?您是否尝试过无法正常工作的东西?
  • 我不知道如何才能让这种类型的验证正确编码并且找不到代码资源。从那以后,我实际上重新编码了页面并更新了上面的源代码......我想知道如何将验证编码到不允许我安排超过 20 台计算机的表单中。

标签: validation google-apps-script tracking google-sites


【解决方案1】:

这应该不难获得...您只需将订阅数量存储在处理程序函数中的某个位置(例如在 scriptProperties 中),如果达到最大数量,则只需禁用提交按钮,以便不再验证表单。

在您的 doGet 函数中,根据您定义的相关 scriptProperty 很容易setEnable(boolean) 提交按钮,并显示一个解释订阅关闭原因的标签。

如果您将限制设置为 20,那么您将获得最多 21 个(考虑到有 1 台计算机/预留),但如果您将其设置为 19,那么您将获得 20 个。

【讨论】:

  • 你能给我举个例子吗...听起来这将根据表单提交的时间起作用。但是,有没有办法根据给定日期电子表格中列出的学生总数来使其工作?学生每天会按不同的班级列出,因此需要有一个截止日期。
  • 在不知道您的数据的情况下,很难给出一个有效的例子......我想你很清楚你如何组织你的活动,但对我来说不是......:)
  • 学生可以订阅每个不同的科目吗?和时期?你需要如何计算它们?标准是什么?
  • 该表格供教师填写以安排计算机实验室。教师输入某些信息,特别是日期、期间和学生人数。一旦他们点击“提交”,它就会创建一个日历事件,让我可以查看每个课程期间有多少学生注册了实验室,并将数据提交到谷歌电子表格(目前无法正常工作)。 我的问题是如何从数据库中获取基于日期和时间段的学生总数,这样我就不允许老师超额预订我的实验室?
  • 是的...根据您在周末与我分享的内容,我想我可能会有更好的想法。我们将看看情况如何,并希望尽快找到解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多