Skip to content

Commit

Permalink
Work for surveyjs/survey-creator#4726 - Themes - Confirmation dialog …
Browse files Browse the repository at this point in the history
…is needed (reset button)
  • Loading branch information
tsv2013 committed Oct 19, 2023
1 parent 1defd63 commit 5ca363d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type ISurveyEnvironment = {
stylesSheetsMountContainer: HTMLElement,
}
const document = globalThis.document;
const defaultEnvironment: ISurveyEnvironment = <ISurveyEnvironment> (!!document ? {
const defaultEnvironment: ISurveyEnvironment = <ISurveyEnvironment>(!!document ? {
root: document,

_rootElement: document.body,
Expand Down Expand Up @@ -510,8 +510,8 @@ export var settings = {
* @param message A message to be displayed in the confirm dialog window.
* @param callback A callback function that should be called with `true` if a user confirms an action or `false` otherwise.
*/
confirmActionAsync: function (message: string, callback: (res: boolean) => void): boolean {
return showConfirmDialog(message, callback);
confirmActionAsync: function (message: string, callback: (res: boolean) => void, applyTitle?: string): boolean {
return showConfirmDialog(message, callback, applyTitle);
},
/**
* A minimum width value for all survey elements.
Expand Down Expand Up @@ -596,7 +596,7 @@ export var settings = {
displayMode?: "popup" | "overlay"
) => any
>undefined,
showDialog: < (options: IDialogOptions, rootElement?: HTMLElement) => any >undefined,
showDialog: <(options: IDialogOptions, rootElement?: HTMLElement) => any>undefined,
supportCreatorV2: false,
showDefaultItemsInCreatorV2: true,
/**
Expand Down
30 changes: 15 additions & 15 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ function confirmAction(message: string): boolean {

function confirmActionAsync(message: string, funcOnYes: () => void, funcOnNo?: () => void): void {
const callbackFunc = (res: boolean): void => {
if(res) funcOnYes();
else if(!!funcOnNo) funcOnNo();
if (res) funcOnYes();
else if (!!funcOnNo) funcOnNo();
};

if(!!settings && !!settings.confirmActionAsync) {
if(settings.confirmActionAsync(message, callbackFunc)) return;
if (!!settings && !!settings.confirmActionAsync) {
if (settings.confirmActionAsync(message, callbackFunc)) return;
}

callbackFunc(confirmAction(message));
Expand Down Expand Up @@ -151,7 +151,7 @@ function findScrollableParent(element: HTMLElement): HTMLElement {
}

function scrollElementByChildId(id: string) {
const environment : ISurveyEnvironment = settings.environment;
const environment: ISurveyEnvironment = settings.environment;
if (!environment) return;
const { root } = environment;
const el = root.getElementById(id);
Expand Down Expand Up @@ -241,21 +241,21 @@ export function unwrap<T>(value: T | (() => T)): T {
// }

export function getRenderedSize(val: string | number): number {
if(typeof val == "string") {
if(!isNaN(Number(val))) {
if (typeof val == "string") {
if (!isNaN(Number(val))) {
return Number(val);
}
else if(val.includes("px")) {
else if (val.includes("px")) {
return parseFloat(val);
}
}
if(typeof val == "number") {
if (typeof val == "number") {
return val;
}
return undefined;
}
export function getRenderedStyleSize(val: string | number): string {
if(getRenderedSize(val) !== undefined) {
if (getRenderedSize(val) !== undefined) {
return undefined;
}
return val as string;
Expand Down Expand Up @@ -348,8 +348,8 @@ function isContainerVisible(el: HTMLElement) {

function getFirstVisibleChild(el: HTMLElement) {
let result;
for(let index = 0; index < el.children.length; index++) {
if(!result && getComputedStyle(el.children[index]).display !== "none") {
for (let index = 0; index < el.children.length; index++) {
if (!result && getComputedStyle(el.children[index]).display !== "none") {
result = el.children[index];
}
}
Expand Down Expand Up @@ -407,9 +407,9 @@ export class Logger {
}
}

export function showConfirmDialog(message: string, callback: (res: boolean) => void): boolean {
export function showConfirmDialog(message: string, callback: (res: boolean) => void, applyTitle?: string): boolean {
const locStr = new LocalizableString(undefined);
const popupViewModel:PopupBaseViewModel = settings.showDialog(<IDialogOptions>{
const popupViewModel: PopupBaseViewModel = settings.showDialog(<IDialogOptions>{
componentName: "sv-string-viewer",
data: { locStr: locStr, locString: locStr, model: locStr }, //TODO fix in library
onApply: () => {
Expand All @@ -430,7 +430,7 @@ export function showConfirmDialog(message: string, callback: (res: boolean) => v
const cancelBtn = toolbar.getActionById("cancel");
cancelBtn.title = surveyLocalization.getString("cancel");
cancelBtn.innerCss = "sv-popup__body-footer-item sv-popup__button sd-btn sd-btn--small";
applyBtn.title = surveyLocalization.getString("ok");
applyBtn.title = applyTitle || surveyLocalization.getString("ok");
applyBtn.innerCss = "sv-popup__body-footer-item sv-popup__button sv-popup__button--danger sd-btn sd-btn--small sd-btn--danger";
popupViewModel.width = "452px";
return true;
Expand Down

0 comments on commit 5ca363d

Please sign in to comment.