UNPKG

4.5 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { body } from "@pnp/queryable";
3import { _SPCollection, spInvokableFactory, _SPInstance, deleteable, } from "../spqueryable.js";
4import { defaultPath } from "../decorators.js";
5import { spPost, spPostMerge } from "../operations.js";
6import { encodePath } from "../utils/encode-path-str.js";
7let _Views = class _Views extends _SPCollection {
8 /**
9 * Adds a new view to the collection
10 *
11 * @param title The new views's title
12 * @param personalView True if this is a personal view, otherwise false, default = false
13 * @param additionalSettings Will be passed as part of the view creation body
14 */
15 async add(Title, PersonalView = false, additionalSettings = {}) {
16 const data = await spPost(this, body({
17 PersonalView,
18 Title,
19 ...additionalSettings,
20 }));
21 return {
22 data,
23 view: this.getById(data.Id),
24 };
25 }
26 /**
27 * Gets a view by guid id
28 *
29 * @param id The GUID id of the view
30 */
31 getById(id) {
32 return View(this).concat(`('${id}')`);
33 }
34 /**
35 * Gets a view by title (case-sensitive)
36 *
37 * @param title The case-sensitive title of the view
38 */
39 getByTitle(title) {
40 return View(this, `getByTitle('${encodePath(title)}')`);
41 }
42};
43_Views = __decorate([
44 defaultPath("views")
45], _Views);
46export { _Views };
47export const Views = spInvokableFactory(_Views);
48export class _View extends _SPInstance {
49 constructor() {
50 super(...arguments);
51 this.delete = deleteable();
52 }
53 get fields() {
54 return ViewFields(this);
55 }
56 /**
57 * Updates this view intance with the supplied properties
58 *
59 * @param properties A plain object hash of values to update for the view
60 */
61 async update(props) {
62 const data = await spPostMerge(this, body(props));
63 return {
64 data,
65 view: this,
66 };
67 }
68 // : any = this._update<IViewUpdateResult, ITypedHash<any>>("SP.View", data => ({ data, view: <any>this }));
69 /**
70 * Returns the list view as HTML.
71 *
72 */
73 renderAsHtml() {
74 return View(this, "renderashtml")();
75 }
76 /**
77 * Sets the view schema
78 *
79 * @param viewXml The view XML to set
80 */
81 setViewXml(viewXml) {
82 return spPost(View(this, "SetViewXml"), body({ viewXml }));
83 }
84}
85export const View = spInvokableFactory(_View);
86let _ViewFields = class _ViewFields extends _SPCollection {
87 /**
88 * Gets a value that specifies the XML schema that represents the collection.
89 */
90 getSchemaXml() {
91 return ViewFields(this, "schemaxml")();
92 }
93 /**
94 * Adds the field with the specified field internal name or display name to the collection.
95 *
96 * @param fieldTitleOrInternalName The case-sensitive internal name or display name of the field to add.
97 */
98 add(fieldTitleOrInternalName) {
99 return spPost(ViewFields(this, `addviewfield('${encodePath(fieldTitleOrInternalName)}')`));
100 }
101 /**
102 * Moves the field with the specified field internal name to the specified position in the collection.
103 *
104 * @param field The case-sensitive internal name of the field to move.
105 * @param index The zero-based index of the new position for the field.
106 */
107 move(field, index) {
108 return spPost(ViewFields(this, "moveviewfieldto"), body({ field, index }));
109 }
110 /**
111 * Removes all the fields from the collection.
112 */
113 removeAll() {
114 return spPost(ViewFields(this, "removeallviewfields"));
115 }
116 /**
117 * Removes the field with the specified field internal name from the collection.
118 *
119 * @param fieldInternalName The case-sensitive internal name of the field to remove from the view.
120 */
121 remove(fieldInternalName) {
122 return spPost(ViewFields(this, `removeviewfield('${encodePath(fieldInternalName)}')`));
123 }
124};
125_ViewFields = __decorate([
126 defaultPath("viewfields")
127], _ViewFields);
128export { _ViewFields };
129export const ViewFields = spInvokableFactory(_ViewFields);
130export var ViewScope;
131(function (ViewScope) {
132 ViewScope[ViewScope["DefaultValue"] = 0] = "DefaultValue";
133 ViewScope[ViewScope["Recursive"] = 1] = "Recursive";
134 ViewScope[ViewScope["RecursiveAll"] = 2] = "RecursiveAll";
135 ViewScope[ViewScope["FilesOnly"] = 3] = "FilesOnly";
136})(ViewScope || (ViewScope = {}));
137//# sourceMappingURL=types.js.map
\No newline at end of file