serge_insas

answer sto 26 sept

Sep 26th, 2013
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function doGet() {
  2.   var app = UiApp.createApplication().setTitle('DHS: Kurzweil Calendar');
  3.  
  4.   //Create a panel which holds all the form elelemnts
  5.   var vertMainPanel = app.createVerticalPanel().setId('vertMainPanel').setStyleAttribute('padding','30px');
  6.  
  7.   //Create the form elelemnts
  8.   var lblTeacherName = app.createLabel('Teacher Name:');
  9.   var txtTeacherName = app.createTextBox().setName('txtTeacherName');
  10.  
  11.   var lblExt = app.createLabel('Ext:');
  12.   var txtExt = app.createTextBox().setName('txtExt');
  13.  
  14.   var lblDate = app.createLabel('Date:');
  15.   var boxDate = app.createDateBox().setId('boxDate').setName('boxDate').setFormat(UiApp.DateTimeFormat.DATE_SHORT);
  16.  
  17.   var lbxSubject = app.createListBox().setId('lbxSubject').setName('lbxSubject');
  18.   var lstSubjItems = ['-- Select One --','Algebra I (OCS)','Algebra II','Algebra II (Honors)','Agriscience Applications','Agriscience Applications (OCS)','Anatomy and Physiology',
  19.                       'Anatomy and Physiology (Honors)','Animal Science','American Sign Language II','Apparel I','Art History (AP)','Advanced Functions and Modeling',
  20.                       'Automotive Computer System Diagnostics','Automotive Brakes','Automotive Service','Automotive Service (OCS)', 'Benchmarks','Bible History','Biology','Biology (AP)',
  21.                       'Biology (Honors)','Biology (OCS)','Biomedical Technology','Biotechnology and Agriscience','Calculus AB (AP)','Calculus BC (AP)','Carpentry I','Carpentry I (OCS)',
  22.                       'Carpentry III','Chemistry','Chemistry (AP)','Chemistry (Honors)','Choral Arts (Beginning)','Civics and Economics','Civics and Economics (Honors)','Computer Programming I',
  23.                       'Computer Science (AP)','Computer Technology','Concert Band II (Beginning)',        'Concert Band II (Proficient)','Core and Sustainable Construction',
  24.                       'Core and Sustainable Construction (OCS)','Digital Media I','Digitial Media I (OCS)','Digital Media II','Discrete Mathematics','Drafting I','Drafting Architecture II (Honors)',
  25.                       'Drafting Architecture III (Honors)','Earth and Environmental Science','Earth and Environmental Sceince (AP)','Earth and Environmental Science (Honors)','Early Childhood Ed I',
  26.                       'eCommerce I (Honors)','English I','English I (Honors)','English II','English II (Honors)','English II (OCS)','English III','English III (Honors)',
  27.                       'English III (OCS)','English IV','English IV (Honors)','English IV (OCS)','English Lang and Comp (AP)','English Language Arts II','English Language Arts III',
  28.                       'Engish Literature (AP)','European History (AP)','Fashion Merchandising','Financial Management (OCS)','Foods I','Foods I (OCS)','Foods II - Enterprise',
  29.                       'Foods II - Advanced (OCS)','French I','French II','French III (Honors)','Functional Finances','Geometry', 'Geometry (Honors)','German I','German II','German III (Honors)',
  30.                       'Health and Physical Education','Health Sciences (Advanced Studies)','Health Team Relations','Human Geography (AP)','Holocaust and Peace Studies','Horticulture I',
  31.                       'Horticulture I (OCS)','Horticulture II','Horticulture II (OCS)','Integrated Math I','Interior Design I','Introduction to Math','Japanese I','JROTC I','JROTC II',
  32.                       'JROTC III','JROTC IV','Latin I','Latim II','Latin III (Honors)','Leadership Development','Marketing Management','Masonry I','Masonry I (OCS)','Masonry III',
  33.                       'Microsoft Excel and Access','Microsoft Word PowerPoint and Publisher','Multimedia and Webpage Design','Music Business and Recording (Beginning)','Occupational Preparations I',
  34.                       'Occupational Preparations II','Occupational Preparations III','Occupational Preparations IV','Parent and Child Development','Parent and Child Development (OCS)',
  35.                       'Personal Finance',        'Personal Finance (OCS)','Physical Science','Physics (Honors)','Pre-Calculus (Honors)','Professional Management and Leadership I',
  36.                       'Professional Management and Leadership II','Psychology','Physcology (AP)','Psychology (Honors)','SAT Preparation','Science and Technical Visualization I',
  37.                       'Science and Technical Visualization II','Social Studies (OCS)','Spanish I','Spanish II','Spanish III (Honors)','Spanish IV (Honors)','Special Topics of Mathematics',
  38.                       'Symphonic Band II (Beginning)','Symphonic Band II (Intermediate)','Symphonic Band II (Proficient)','Technology Engineering and Design','Theatre Arts (Beginning)',
  39.                       'Theatre Arts (Intermediate)','US History','US History (AP)','US History (Honors)','Visual Arts (Beginning)','Visual Arts (Intermediate)','Visual Arts (Proficient)',
  40.                       'Visual Arts (Advanced)','Visual Arts Specialization in Ceramics (Advanced)','Vocal Ensemble (Intermediate)','Vocal Ensemble (Proficient)','Wind Ensemble II (Intermediate)',
  41.                       'Wind Ensemble II (Proficient)','Wind Ensemble II (Advanced)','World Geography','World History','World History','World History (Honors)'];
  42.       lstSubjItems.sort();
  43.  
  44.       for (var l = 0; l < lstSubjItems.length; l++) {
  45.         lbxSubject.addItem(lstSubjItems[l]);
  46.       }
  47.  
  48.   var lbxPeriod = app.createListBox().setId('lbxPeriod').setName('lbxPeriod');
  49.   var lstPrdItems = ['-- Select One --','1st Period','2nd Period','3rd Period','4th Period'];
  50.       lstPrdItems.sort();
  51.  
  52.       for (var l = 0; l < lstPrdItems.length; l++) {
  53.         lbxPeriod.addItem(lstPrdItems[l]);
  54.       }
  55.  
  56.   var lblStudentNum = app.createLabel('Number of Students:');
  57.   var txtStudentNum = app.createTextBox().setName('txtStudentNum');
  58.  
  59.   var txtRadioGrp1 = app.createTextBox().setName('txtRadioGrp1').setVisible(false);
  60.   var txtRadioGrp2 = app.createTextBox().setName('txtRadioGrp2').setVisible(false);
  61.   var txtElementsID = app.createTextBox().setName('txtElementsID');
  62.   var txtQuiaLink = app.createTextBox().setName('txtQuiaLink');
  63.   var txtElementsIDP = app.createHorizontalPanel().add(app.createLabel('enter a value')).add(txtElementsID).setVisible(false);
  64.   var txtQuiaLinkP = app.createHorizontalPanel().add(app.createLabel('enter a value')).add(txtQuiaLink).setVisible(false);
  65.   var txtQuiaPass = app.createTextBox().setName('txtQuiaPass').setVisible(false);
  66.   //Create Source Radio Button Group
  67.   var radSource1 = app.createRadioButton('group1', 'Hard-Copy').setFormValue('Hard-Copy').addClickHandler(app.createClientHandler().forTargets(txtRadioGrp1).setText('Hard-Copy'));
  68.   var radSource2 = app.createRadioButton('group1', 'Electronic-Copy').setFormValue('Electronic-Copy').addClickHandler(app.createClientHandler().forTargets(txtRadioGrp1).setText('Electronic-Copy'));
  69.   //Create Type Radio Button Group
  70.   var radSource3 = app.createRadioButton('group2', 'Teacher-Made Exam').setFormValue('Teacher-Made Exam').addClickHandler(app.createClientHandler().forTargets(txtRadioGrp2).setText('Teacher-Made Exam'));
  71.   var radSource4 = app.createRadioButton('group2', 'Elements Exam').setFormValue('Elements Exam').addClickHandler(app.createClientHandler().forTargets(txtRadioGrp1).setText('Elements Exam'));
  72.   var radSource5 = app.createRadioButton('group2', 'Quia Exam').setFormValue('Quia Exam').addClickHandler(app.createClientHandler().forTargets(txtRadioGrp1).setText('Quia Exam'));
  73.  
  74.   var btnCreate = app.createButton('Create Event');
  75.  
  76.   //Client Handlers for textBoxes
  77.   var showTxtElementHandler = app.createClientHandler().forTargets(txtElementsIDP).setVisible(true);
  78.   var hideTxtElementHandler = app.createClientHandler().forTargets(txtElementsIDP).setVisible(false);
  79.   radSource4.addClickHandler(showTxtElementHandler);
  80.   radSource3.addClickHandler(hideTxtElementHandler);
  81.   radSource5.addClickHandler(hideTxtElementHandler);
  82.  
  83.   var showtxtQuiaLinkHandler = app.createClientHandler().forTargets(txtQuiaLinkP).setVisible(true);
  84.   var hidetxtQuiaLinkHandler = app.createClientHandler().forTargets(txtQuiaLinkP).setVisible(false);
  85.   radSource5.addClickHandler(showtxtQuiaLinkHandler);
  86.   radSource3.addClickHandler(hidetxtQuiaLinkHandler);
  87.   radSource4.addClickHandler(hidetxtQuiaLinkHandler);
  88.  
  89.   //Create handler which will execute 'createEvents(e)' on clicking the button
  90.   var evtHandler = app.createServerClickHandler('createEvents');
  91.       evtHandler.addCallbackElement(vertMainPanel);
  92.   //Add this handler to the button
  93.       btnCreate.addClickHandler(evtHandler);
  94.  
  95.   //Add all the elemnts to the panel
  96.   vertMainPanel.add(lblTeacherName)
  97.        .add(txtTeacherName)
  98.        .add(lblExt)
  99.        .add(txtExt)
  100.        .add(lblDate)
  101.        .add(boxDate)
  102.        .add(lbxSubject)
  103.        .add(lbxPeriod)
  104.        .add(lblStudentNum)
  105.        .add(txtStudentNum)
  106.        .add(radSource1)
  107.        .add(radSource2)
  108.        .add(txtRadioGrp1)
  109.        .add(radSource3)
  110.        .add(radSource4)
  111.        .add(txtElementsIDP)
  112.        .add(radSource5)
  113.        .add(txtQuiaLinkP)
  114.        .add(txtQuiaPass)
  115.        .add(txtRadioGrp2)
  116.        .add(btnCreate)
  117.  
  118.   //Add this panel to the application
  119.   app.add(vertMainPanel);
  120.  
  121.   //Return the application
  122.   return app;
  123. }
  124.  
  125. function createEvents(e){
  126.  
  127.   //Get the active application
  128.   var app = UiApp.getActiveApplication();
  129.  
  130.   try{
  131.     //Get the entries
  132.     var ssTeacher = e.parameter.txtTeacherName;
  133.     var ssExt = e.parameter.txtExt;
  134.     var ssSubject = e.parameter.lbxSubject;
  135.     var ssPeriod = e.parameter.lbxPeriod;
  136.     var ssStudentNum = e.parameter.txtStudentNum;
  137.     var ssSource = e.parameter.txtRadioGrp1;
  138.     var ssType = e.parameter.txtRadioGrp2;
  139.     var eventDate = e.parameter.boxDate;
  140.     var eventCalSubject = ssPeriod + ": " + ssTeacher + " (" + ssStudentNum + ")";
  141.     var eventCalDetails = "Extension: " + ssExt + "\n" +
  142.           "Subject: " + ssSubject + "\n\n" +
  143.           "Source: " + ssSource + "\n" +
  144.           "Type: " + ssType + "\n";
  145.  
  146.     //Get the calendar
  147.     var cal = CalendarApp.getCalendarById('davie.k12.nc.us_d2mv2eb8aspuant1vb5j6r3sis@group.calendar.google.com');//Change the calendar id
  148.     //Create the events
  149.     cal.createAllDayEvent(eventCalSubject, eventDate, {description:eventCalDetails});
  150.  
  151.     //Log the entries in a spreadsheet
  152.     var sheet = SpreadsheetApp.openById('0Aur3owCpuUY-dGJIOGZ1LXhqT2FNMGVXSGNJazFnUmc#gid=0').getActiveSheet();//Change the spreadhseet key to yours
  153.     var lastRow = sheet.getLastRow();
  154.     var targetRange = sheet.getRange(lastRow+1, 1, 1, 10).setValues([[new Date(),eventDate,ssTeacher,ssExt,ssSubject,ssPeriod,ssSource,ssType,ssStudentNum,'Event created']]);
  155.     return app;
  156.  
  157.     //Show the confirmation message
  158.     app.add(app.createLabel('Kurzweil Calendar Event created successfully...'));
  159.     //Make the form panel invisible
  160.     app.getElementById('vertMainPanel').setVisible(false);
  161.     return app;
  162.   }
  163.  
  164.   //If an error occurs, show it on the panel
  165.   catch(e){
  166.     app.add(app.createLabel('Error occured: '+ e));
  167.     return app;
  168.   }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment