1 | import { odataUrlFrom } from "../utils/odata-url-from.js";
|
2 | import { extractWebUrl } from "../utils/extract-web-url.js";
|
3 | import { Web } from "../webs/types.js";
|
4 | import "../lists/web.js";
|
5 | import { _Folder, Folder } from "../folders/types.js";
|
6 | _Folder.prototype.getDefaultColumnValues = async function () {
|
7 | const folderProps = await Folder(this, "Properties").select("vti_x005f_listname")();
|
8 | const { ServerRelativePath: serRelPath } = await this.select("ServerRelativePath")();
|
9 | const web = Web([this, extractWebUrl(odataUrlFrom(folderProps))]);
|
10 | const docLib = web.lists.getById(folderProps.vti_x005f_listname);
|
11 |
|
12 |
|
13 | return (await docLib.getDefaultColumnValues()).filter(v => v.path.toLowerCase() === serRelPath.DecodedUrl.toLowerCase());
|
14 | };
|
15 | _Folder.prototype.setDefaultColumnValues = async function (fieldDefaults, merge = true) {
|
16 |
|
17 | const folderProps = await Folder(this, "Properties").select("vti_x005f_listname")();
|
18 |
|
19 | const web = Web([this, extractWebUrl(odataUrlFrom(folderProps))]);
|
20 | const docLib = web.lists.getById(folderProps.vti_x005f_listname);
|
21 |
|
22 | const folderPath = (await this.select("ServerRelativePath")()).ServerRelativePath.DecodedUrl;
|
23 |
|
24 |
|
25 | const existingDefaults = await docLib.getDefaultColumnValues();
|
26 |
|
27 | const filteredExistingDefaults = merge ? existingDefaults : existingDefaults.filter(f => f.path !== folderPath);
|
28 |
|
29 | fieldDefaults.forEach(d => {
|
30 | const existing = filteredExistingDefaults.find(ed => ed.name === d.name && ed.path === folderPath);
|
31 | if (existing) {
|
32 | existing.value = d.value;
|
33 | }
|
34 | else {
|
35 | filteredExistingDefaults.push({
|
36 | name: d.name,
|
37 | path: folderPath,
|
38 | value: d.value,
|
39 | });
|
40 | }
|
41 | });
|
42 |
|
43 | await docLib.setDefaultColumnValues(filteredExistingDefaults);
|
44 | };
|
45 | _Folder.prototype.clearDefaultColumnValues = async function () {
|
46 | await this.setDefaultColumnValues([], false);
|
47 | };
|
48 |
|
\ | No newline at end of file |