|
1 | | -/* |
2 | | - * Copyright (c) 2016-2018 LabKey Corporation |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 |
5 | | - */ |
6 | | -var shared = require("TriggerTestModule/EmployeeLib"); |
7 | 1 | var console = require("console"); |
8 | | - |
| 2 | + |
| 3 | +function managedColumns() { |
| 4 | + return { |
| 5 | + insert: ["boomerang", "employeeId"], |
| 6 | + update: ["boomerang", "company", "employeeId"], |
| 7 | + ignored: ["notes"], |
| 8 | + }; |
| 9 | +} |
| 10 | + |
9 | 11 | function init(event, errors) { |
10 | 12 | console.log("init got triggered with event: " + event); |
11 | | - console.log(shared.sampleFunc("this is from the shared function")); |
12 | 13 | } |
13 | 14 |
|
14 | 15 | function beforeInsert(row, errors) { |
15 | 16 | console.log("list: beforeInsert: row is: " + row); |
16 | | - if(row.name == "Emp 2") |
| 17 | + if (row.name === "Emp 2") |
17 | 18 | row.company = "Inserting Single"; |
18 | | - else if(row.name == "Emp 5") |
| 19 | + else if (row.name === "Emp 5") |
19 | 20 | row.company = "Importing TSV"; |
20 | | - else if(row.name == "Emp 6") |
| 21 | + else if (row.name === "Emp 6") |
21 | 22 | row.company = "API BeforeInsert"; |
| 23 | + else if (row.name === "Managed Insert") |
| 24 | + row.employeeId = "EMP-INS"; |
| 25 | + else if (row.name === "Managed Struct") { |
| 26 | + row.employeeId = "EMP-STRUCT"; |
| 27 | + row.undeclaredCol = "bad"; |
| 28 | + } |
| 29 | + else if (row.name === "Managed Struct Remove") { |
| 30 | + row.employeeId = "EMP-STRUCT-REM"; |
| 31 | + delete row.SSN; |
| 32 | + } |
| 33 | + |
| 34 | + if (!row.employeeId) { |
| 35 | + row.employeeId = "EMP-INS1"; |
| 36 | + } |
| 37 | + |
| 38 | + row.notes = "This is a note"; |
| 39 | + |
| 40 | + if (row.SSN !== "-123") { |
| 41 | + row.boomeRANG = "Back at ya!"; |
| 42 | + } |
22 | 43 | console.log("list: edited row is: " + row); |
23 | | - console.log(shared.sampleFunc("list: this is from the shared function")); |
24 | 44 | } |
25 | 45 |
|
26 | 46 | function beforeUpdate(row, oldRow, errors) { |
27 | 47 | console.log("list: beforeUpdate: row is: " + row); |
28 | | - if(row.name == "Emp 3" || row.name == "Emp 8" ) |
| 48 | + if (row.company === "Company Up") |
29 | 49 | row.company = "Before Update changed me"; |
| 50 | + else if (row.name === "Managed Update") { |
| 51 | + row.company = "Managed Co"; |
| 52 | + row.employeeId = "EMP-UPD"; |
| 53 | + } |
| 54 | + else if (row.name === "Managed Struct") { |
| 55 | + row.company = "Struct Co"; |
| 56 | + row.employeeId = "EMP-STRUCT"; |
| 57 | + row.undeclaredCol = "bad"; |
| 58 | + } |
| 59 | + else if (row.name === "Managed Struct Remove") { |
| 60 | + row.company = "Struct Remove Co"; |
| 61 | + row.employeeId = "EMP-STRUCT-REM"; |
| 62 | + delete row.SSN; |
| 63 | + } |
| 64 | + |
| 65 | + if (!row.employeeId) { |
| 66 | + row.employeeId = "EMP-UPD1"; |
| 67 | + } |
| 68 | + |
| 69 | + row.notes = "This is a note"; |
| 70 | + |
| 71 | + if (row.SSN !== "-123") { |
| 72 | + row.boomeRANG = "Back at me!"; |
| 73 | + } |
30 | 74 | console.log("list: old row is: " + oldRow); |
31 | | - console.log(shared.sampleFunc("list: this is from the shared function")); |
32 | 75 | } |
33 | 76 |
|
34 | 77 | function beforeDelete(row, errors) { |
35 | 78 | console.log("list: beforeDelete: row is: " + row); |
36 | | - if(row.company == "Inserting Single" || row.company == "DeleteMe") |
| 79 | + if (row.company === "Inserting Single" || row.company === "DeleteMe") |
37 | 80 | errors[null] = "This is the Before Delete Error"; |
38 | | - |
39 | | - console.log(shared.sampleFunc("list: this is from the shared function")); |
40 | 81 | } |
41 | 82 |
|
42 | 83 | function afterInsert(row, errors) { |
43 | 84 | console.log("list: afterInsert: row is: " + row); |
44 | 85 |
|
45 | | - if(row.name == "Emp 1") |
| 86 | + if (row.name === "Emp 1") |
46 | 87 | errors[null] = "This is the After Insert Error"; |
47 | | - |
48 | | - console.log(shared.sampleFunc("list: this is from the shared function")); |
49 | 88 | } |
50 | 89 |
|
51 | 90 | function afterUpdate(row, oldRow, errors) { |
52 | 91 | console.log("list: afterUpdate: row is: " + row); |
53 | 92 |
|
54 | | - if(row.name == "Emp 2" || row.name == "Emp 6" ) |
| 93 | + if (row.company === "Company After Update Error") |
55 | 94 | errors[null] = "This is the After Update Error"; |
56 | | - //throw new Error("This is the After Update Error"); |
57 | 95 |
|
58 | 96 | console.log("list: old row is: " +oldRow); |
59 | | - console.log(shared.sampleFunc("list: this is from the shared function")); |
60 | 97 | } |
61 | 98 |
|
62 | 99 | function afterDelete(row, errors) { |
63 | 100 | console.log("list: afterDelete: row is: " + row); |
64 | 101 |
|
65 | | - if(row.company == "Before Update changed me") |
| 102 | + if (row.company === "Before Update changed me") |
66 | 103 | errors[null] = "This is the After Delete Error"; |
67 | | - |
68 | | - console.log(shared.sampleFunc("list: this is from the shared function")); |
69 | 104 | } |
70 | 105 |
|
71 | 106 | function complete(event, errors) { |
72 | 107 | console.log("list: complete got triggered with event: " + event); |
73 | | - console.log(shared.sampleFunc("list: this is from the shared function")); |
74 | 108 | } |
0 commit comments