Skip to content

Commit

Permalink
Merge pull request #308 from gunjandatta/gdatta
Browse files Browse the repository at this point in the history
Updates & Bug Fixes
  • Loading branch information
gunjandatta authored Aug 16, 2023
2 parents 16db3cb + c295a7f commit c4f0e2b
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 57 deletions.
13 changes: 8 additions & 5 deletions @types/helper/listForm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ export interface IListForm {

/**
* Method to show the file dialog.
* @param info - The list form information.
* @param onSave - The save event triggered when a file is uploaded to the item.
* @param accept - The acceptable file extensions to allow.
*/
showFileDialog(): PromiseLike<IListFormAttachmentInfo>;
showFileDialog(accept?: string[]): PromiseLike<IListFormAttachmentInfo>;

/**
* Method to show the file dialog.
* @param accept - The acceptable file extensions to allow.
* @param info - The list form information.
* @param onSave - The save event triggered when a file is uploaded to the item.
*/
showFileDialog(info: IListFormResult, onSave?: (IListFormAttachmentInfo) => void): PromiseLike<IListFormResult>;
showFileDialog(accept?: string[], info?: IListFormResult, onSave?: (IListFormAttachmentInfo) => void): PromiseLike<IListFormResult>;
}

/**
Expand All @@ -77,6 +77,9 @@ export interface IListFormAttachmentInfo {

/** The name of the file */
name: string;

/** The source file */
src: any;
}

/**
Expand All @@ -94,7 +97,7 @@ export interface IListFormDisplay {
*/
export interface IListFormDisplayProps {
/** The element to render the form to. */
el?: Element;
el?: HTMLElement;

/** The fields to exclude from the form. */
excludeFields?: Array<string>;
Expand Down
8 changes: 4 additions & 4 deletions @types/helper/sp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,19 @@ export interface ICalloutOptions {
beakOrientation?: string;

/** */
boundingBox?: Element;
boundingBox?: HTMLElement;

/** The html to be displayed in the callout. */
content?: string;

/** Element to be displayed in the callout. */
contentElement?: Element;
contentElement?: HTMLElement;

/** The width in pixels. Default - 350px */
contentWidth?: number;

/** The element to apply the callout to. */
launchPoint: Element;
launchPoint: HTMLElement;

/** Event triggered after the callout is closed. */
onClosedCallback?(callout: ICallout);
Expand Down Expand Up @@ -329,7 +329,7 @@ export interface IDialogOptions {
height?: number;

/** An html element to display in the dialog. If both html and url are specified, url takes precedence. Either url or html must be specified. */
html?: Element;
html?: HTMLElement;

/** A Boolean value that specifies whether the Close button appears on the dialog. */
showClose?: boolean;
Expand Down
6 changes: 6 additions & 0 deletions @types/helper/spCfg.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export interface IFieldInfo {
/** True, to allow deletion of the field. */
allowDeletion?: boolean;

/** The JSON property for applying a custom format to the field. */
customFormatter?: object;

/** The default value of the field. */
defaultValue?: string;

Expand Down Expand Up @@ -223,6 +226,9 @@ export interface IFieldInfoNote extends IFieldInfoText {

/** The number of lines */
numberOfLines?: number;

/** Allow unlimited length for document libraries. */
unlimited?: boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion @types/lib/hubSites.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface IHubSites {
* Creates an instance of the user profile library.
* @param targetInfo - (Optional) The target information.
*/
(targetInfo?: ITargetInfoProps): IHubSiteCollection;
(targetInfo?: ITargetInfoProps): IBaseExecution<IHubSiteCollection>;

/**
* A static method to see if the current user can create a hub site.
Expand Down
6 changes: 6 additions & 0 deletions @types/lib/web.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ export interface IWeb {
* @param requestUrl - The absolute url of the remote web.
*/
getRemoteWeb(requestUrl: string): IBaseExecution<SP.RemoteWeb>;

/**
* Method to get the web url from a page url. (SPO Only)
* @param pageUrl - The absolute url of the page.
*/
getWebUrlFromPageUrl(pageUrl: string): IBaseExecution<{ GetWebUrlFromPageUrl: string }>;
}
5 changes: 5 additions & 0 deletions @types/rest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export interface IREST {
*/
DefaultRequestToHostFl: boolean;

/**
* Use this api to get the web url from a page url.
*/
GetWebUrlFromPageUrl: (pageUrl: string) => IBaseExecution<{ GetWebUrlFromPageUrl: string }>

/**
* Use this api to interact with the Graph API. (Still In Development)
*/
Expand Down
40 changes: 30 additions & 10 deletions dist/gd-sprest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ declare module 'gd-sprest/rest' {
*/
DefaultRequestToHostFl: boolean;

/**
* Use this api to get the web url from a page url.
*/
GetWebUrlFromPageUrl: (pageUrl: string) => IBaseExecution<{ GetWebUrlFromPageUrl: string }>

/**
* Use this api to interact with the Graph API. (Still In Development)
*/
Expand Down Expand Up @@ -1313,7 +1318,7 @@ declare module 'gd-sprest/lib/hubSites' {
* Creates an instance of the user profile library.
* @param targetInfo - (Optional) The target information.
*/
(targetInfo?: ITargetInfoProps): IHubSiteCollection;
(targetInfo?: ITargetInfoProps): IBaseExecution<IHubSiteCollection>;

/**
* A static method to see if the current user can create a hub site.
Expand Down Expand Up @@ -1944,6 +1949,12 @@ declare module 'gd-sprest/lib/web' {
* @param requestUrl - The absolute url of the remote web.
*/
getRemoteWeb(requestUrl: string): IBaseExecution<SP.RemoteWeb>;

/**
* Method to get the web url from a page url. (SPO Only)
* @param pageUrl - The absolute url of the page.
*/
getWebUrlFromPageUrl(pageUrl: string): IBaseExecution<{ GetWebUrlFromPageUrl: string }>;
}
}

Expand Down Expand Up @@ -2329,17 +2340,17 @@ declare module 'gd-sprest/helper/listForm' {

/**
* Method to show the file dialog.
* @param info - The list form information.
* @param onSave - The save event triggered when a file is uploaded to the item.
* @param accept - The acceptable file extensions to allow.
*/
showFileDialog(): PromiseLike<IListFormAttachmentInfo>;
showFileDialog(accept?: string[]): PromiseLike<IListFormAttachmentInfo>;

/**
* Method to show the file dialog.
* @param accept - The acceptable file extensions to allow.
* @param info - The list form information.
* @param onSave - The save event triggered when a file is uploaded to the item.
*/
showFileDialog(info: IListFormResult, onSave?: (IListFormAttachmentInfo) => void): PromiseLike<IListFormResult>;
showFileDialog(accept?: string[], info?: IListFormResult, onSave?: (IListFormAttachmentInfo) => void): PromiseLike<IListFormResult>;
}

/**
Expand All @@ -2351,6 +2362,9 @@ declare module 'gd-sprest/helper/listForm' {

/** The name of the file */
name: string;

/** The source file */
src: any;
}

/**
Expand All @@ -2368,7 +2382,7 @@ declare module 'gd-sprest/helper/listForm' {
*/
export interface IListFormDisplayProps {
/** The element to render the form to. */
el?: Element;
el?: HTMLElement;

/** The fields to exclude from the form. */
excludeFields?: Array<string>;
Expand Down Expand Up @@ -2947,19 +2961,19 @@ declare module 'gd-sprest/helper/sp' {
beakOrientation?: string;

/** */
boundingBox?: Element;
boundingBox?: HTMLElement;

/** The html to be displayed in the callout. */
content?: string;

/** Element to be displayed in the callout. */
contentElement?: Element;
contentElement?: HTMLElement;

/** The width in pixels. Default - 350px */
contentWidth?: number;

/** The element to apply the callout to. */
launchPoint: Element;
launchPoint: HTMLElement;

/** Event triggered after the callout is closed. */
onClosedCallback?(callout: ICallout);
Expand Down Expand Up @@ -3017,7 +3031,7 @@ declare module 'gd-sprest/helper/sp' {
height?: number;

/** An html element to display in the dialog. If both html and url are specified, url takes precedence. Either url or html must be specified. */
html?: Element;
html?: HTMLElement;

/** A Boolean value that specifies whether the Close button appears on the dialog. */
showClose?: boolean;
Expand Down Expand Up @@ -3417,6 +3431,9 @@ declare module 'gd-sprest/helper/spCfg' {
/** True, to allow deletion of the field. */
allowDeletion?: boolean;

/** The JSON property for applying a custom format to the field. */
customFormatter?: object;

/** The default value of the field. */
defaultValue?: string;

Expand Down Expand Up @@ -3598,6 +3615,9 @@ declare module 'gd-sprest/helper/spCfg' {

/** The number of lines */
numberOfLines?: number;

/** Allow unlimited length for document libraries. */
unlimited?: boolean;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/gd-sprest.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gd-sprest.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gd-sprest",
"version": "7.5.0",
"version": "7.6.6",
"description": "An easy way to develop against the SharePoint REST API.",
"author": "Gunjan Datta <[email protected]> (https://gunjandatta.github.io)",
"license": "MIT",
Expand All @@ -24,7 +24,7 @@
},
"homepage": "https://dattabase.com",
"dependencies": {
"gd-sprest-def": "^1.3.0"
"gd-sprest-def": "^1.3.3"
},
"devDependencies": {
"@babel/core": "^7.18.10",
Expand Down
2 changes: 2 additions & 0 deletions src/helper/fieldSchemaXML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export const FieldSchemaXML = (fieldInfo: IFieldInfo, targetWebUrl?: string): Pr
if (fieldInfo.noteType == SPTypes.FieldNoteType.EnhancedRichText || fieldInfo.noteType == SPTypes.FieldNoteType.RichText) { props["RichText"] = "TRUE"; }
if (fieldInfo.noteType == SPTypes.FieldNoteType.EnhancedRichText) { props["RichTextMode"] = "FullHtml"; }
if (fieldInfo.numberOfLines > 0) { props["NumLines"] = fieldInfo.numberOfLines; }
if (fieldInfo.unlimited) { props["UnlimitedLengthInDocumentLibrary"] = "TRUE"; }

// Generate the schema
schemaXml = "<Field " + toString(props) + " />";
Expand Down Expand Up @@ -433,6 +434,7 @@ export const FieldSchemaXML = (fieldInfo: IFieldInfo, targetWebUrl?: string): Pr

// Set the optional properties
if (typeof (fieldInfo.allowDeletion) !== "undefined") { props["AllowDeletion"] = fieldInfo.allowDeletion ? "TRUE" : "FALSE"; }
if (typeof (fieldInfo.customFormatter) !== "undefined") { props["CustomFormatter"] = JSON.stringify(fieldInfo.customFormatter).replace(/"/g, "&quot;"); }
if (typeof (fieldInfo.description) !== "undefined") { props["Description"] = fieldInfo.description; }
if (typeof (fieldInfo.enforceUniqueValues) !== "undefined") { props["EnforceUniqueValues"] = fieldInfo.enforceUniqueValues ? "TRUE" : "FALSE"; }
if (typeof (fieldInfo.group) !== "undefined") { props["Group"] = fieldInfo.group; }
Expand Down
14 changes: 7 additions & 7 deletions src/helper/listForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,13 +603,13 @@ export const ListForm: IListForm = {
},

// Method to show a file dialog
showFileDialog: (info?: IListFormResult, onSave?: (fileInfo: IListFormAttachmentInfo) => void): PromiseLike<any> => {
showFileDialog: (accept?: string[], info?: IListFormResult, onSave?: (fileInfo: IListFormAttachmentInfo) => void): PromiseLike<any> => {
// Return a promise
return new Promise((resolve, reject) => {
// Method to add an attachment
let addAttachment = (name, data) => {
let addAttachment = (name, data, src) => {
// Call the save event
onSave ? onSave({ name, data }) : null;
onSave ? onSave({ name, data, src }) : null;

// Get the list
info.list
Expand Down Expand Up @@ -641,23 +641,22 @@ export const ListForm: IListForm = {

// Set the file loaded event
reader.onloadend = (ev: any) => {
let attachment = null;

let ext = srcFile.name.split(".") as any;
ext = ext[ext.length - 1].toLowerCase();

// See if the info exists
if (info) {
// Add the attachment
addAttachment(srcFile.name, ev.target.result);
addAttachment(srcFile.name, ev.target.result, srcFile);
} else {
// Remove the element
document.body.removeChild(el);

// Resolve the promise with the file information
resolve({
data: ev.target.result,
name: srcFile.name
name: srcFile.name,
src: srcFile
});
}
}
Expand All @@ -682,6 +681,7 @@ export const ListForm: IListForm = {
el = document.createElement("input");

// Set the properties
el.accept = accept ? accept.join(',') : null;
el.id = "listform-attachment";
el.type = "file";
el.hidden = true;
Expand Down
Loading

0 comments on commit c4f0e2b

Please sign in to comment.