UNPKG

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