SHOW:
|
|
- or go back to the newest paste.
1 | // Script-as-app template. | |
2 | function doGet() { | |
3 | var app = UiApp.createApplication(); | |
4 | ||
5 | var button = app.createButton('Click Me'); | |
6 | app.add(button); | |
7 | ||
8 | var label = app.createLabel('The button was clicked.') | |
9 | .setId('statusLabel') | |
10 | .setVisible(false); | |
11 | app.add(label); | |
12 | ||
13 | var handler = app.createServerHandler('myClickHandler'); | |
14 | handler.addCallbackElement(label); | |
15 | button.addClickHandler(handler); | |
16 | ||
17 | return app; | |
18 | } | |
19 | ||
20 | function myClickHandler(e) { | |
21 | var app = UiApp.getActiveApplication(); | |
22 | var label = app.getElementById('statusLabel'); | |
23 | label.setVisible(true); | |
24 | ||
25 | app.close(); | |
26 | return app; | |
27 | } | |
28 | - | var ss = SpreadsheetApp.openById('[INSERT SPREADHSEET KEY HERE]');//Put your spreadsheet key here |
28 | + | var ss = SpreadsheetApp.openById('INSERT SPREADHSEET KEY HERE');//Put your spreadsheet key here |
29 | var sh1 = ss.getSheetByName('StudentGrades');//Meta sheet name | |
30 | var logsheet = ss.getSheetByName('logsheet'); | |
31 | var data = sh1.getDataRange().getValues(); | |
32 | var user = Session.getEffectiveUser() | |
33 | Logger.log(user) | |
34 | ||
35 | ||
36 | function doGet() { | |
37 | var app = UiApp.createApplication().setTitle('Your Grades');//App title | |
38 | if(!getcol(user)){ | |
39 | var warn = app.createLabel().setWidth('500').setText("Your results are not available or your instructor has the wrong email address. Please contact your instructor ASAP.");// if user is not in the list, warning + return | |
40 | app.add(warn) | |
41 | return app | |
42 | } | |
43 | var grid = app.createGrid(data.length, 2).setWidth('300px').setBorderWidth(1).setCellPadding(0).setCellSpacing(0).setStyleAttribute('borderCollapse','collapse').setId('grid');//Overall table styling | |
44 | var text = app.createLabel(user).setWidth('300px'); | |
45 | var col = getcol(user) | |
46 | grid.setWidget(0,1,text).setText(0, 0, 'Results for'); | |
47 | grid.setStyleAttribute('textAlign','center') | |
48 | for(n=1;n<data.length;++n){ | |
49 | grid.setText(n, 0, string(data[n][0])); | |
50 | grid.setText(n, 1, string(data[n][col])); | |
51 | grid.setStyleAttributes(n-1, 0, {'fontWeight':'bold','background':'#fff','border':'1px solid #000'});//left column css attributes | |
52 | grid.setStyleAttributes(n-1, 1, {'fontWeight':'bold','background':'#fff','border':'1px solid #000'});//right column css attributes | |
53 | } | |
54 | app.add(grid); | |
55 | return app | |
56 | } | |
57 | ||
58 | function string(value){ | |
59 | Logger.log(typeof(value)) | |
60 | if (typeof(value)=='string'){return value};// if string then don't do anything | |
61 | if (typeof(value)=='number'){return Utilities.formatString('%.1f',value)};// if number then format with 1 decimal | |
62 | if (typeof(value)=='object'){return Utilities.formatDate(value, Session.getTimeZone(), "MM-dd")};//object >> date in this case, format month/day | |
63 | return 'error' | |
64 | } | |
65 | ||
66 | ||
67 | function getcol(mail){ | |
68 | if(data[0].toString().indexOf(mail.toString())!=-1){ | |
69 | for(zz=1;zz<data[0].length;++zz){ | |
70 | if(data[0][zz] == mail){var colindex=zz;break} | |
71 | } | |
72 | return colindex | |
73 | } | |
74 | return false | |
75 | } |