{"version":3,"file":"Document.min.js","sources":["EncompassWebServices/Controls/Document.js"],"sourcesContent":["\"use strict\";\r\n\r\nconst BC_Document = function (EWS) {\r\n this.EWS = EWS;\r\n this.CurrentDocument = \"\";\r\n};\r\n\r\nBC_Document.prototype.CreateTinyMceDocument = function (dashboardItemID, ContentList, RefDocumentID, folder, type, title, callback, global) {\r\n const data = new FormData();\r\n data.append(\"Type\", type);\r\n data.append(\"DashboardItemID\", dashboardItemID);\r\n data.append(\"ContentList\", JSON.stringify(ContentList));\r\n data.append(\"RefDocumentID\", RefDocumentID);\r\n data.append(\"Global\", global ? \"True\" : \"False\");\r\n\r\n if (!EC_Fmt.isNull(folder)) {\r\n data.append(\"Folder\", folder);\r\n }\r\n\r\n if (!EC_Fmt.isNull(title)) {\r\n data.append(\"Title\", title);\r\n }\r\n\r\n ECP.Dialog.ShowLoading();\r\n\r\n const me = this;\r\n ECP.Tools.Ajax(\"api?APICommand=Document_CreateDocument\", {\r\n method: \"POST\",\r\n body: data\r\n }).then((response) => {\r\n response.json().then((result) => {\r\n ECP.Dialog.HideLoading();\r\n\r\n if (result.status === \"success\") {\r\n if (!EC_Fmt.isNull(callback)) {\r\n callback(me, result.document, result.langDocumentId);\r\n }\r\n } else {\r\n ECP.Dialog.Alert(result.message);\r\n }\r\n }).catch((err) => {\r\n ECP.Dialog.HideLoading();\r\n throw err;\r\n });\r\n }).catch((err) => {\r\n ECP.Dialog.HideLoading();\r\n throw err;\r\n });\r\n};\r\n\r\nBC_Document.prototype.Create = function (folder, type, title, callback) {\r\n const data = new FormData();\r\n data.append(\"Type\", type);\r\n\r\n if (!EC_Fmt.isNull(folder)) {\r\n data.append(\"Folder\", folder);\r\n }\r\n\r\n if (!EC_Fmt.isNull(title)) {\r\n data.append(\"Title\", title);\r\n }\r\n\r\n ECP.Dialog.ShowLoading();\r\n\r\n const me = this;\r\n\r\n ECP.Tools.Ajax(\"api?APICommand=Document_Create\", {\r\n method: \"POST\",\r\n body: data\r\n }).then((response) => {\r\n response.json().then((result) => {\r\n ECP.Dialog.HideLoading();\r\n if (result.status === \"success\") {\r\n if (!EC_Fmt.isNull(callback)) {\r\n callback(me, result.document.id, result.document);\r\n }\r\n } else {\r\n ECP.Dialog.Alert(result.message);\r\n }\r\n }).catch((err) => {\r\n ECP.Dialog.HideLoading();\r\n throw err;\r\n });\r\n }).catch((err) => {\r\n ECP.Dialog.HideLoading();\r\n throw err;\r\n });\r\n};\r\n\r\nBC_Document.prototype.Edit = function (documentID, callback, title, global) {\r\n const me = this;\r\n if (!EC_Fmt.isNull(documentID) && documentID > 0) {\r\n ECP.Tools.Ajax(`api?APICommand=Document_GetDocument&DocumentID=${documentID}&Global=${global ? \"True\" : \"False\"}`, {\r\n method: \"GET\"\r\n }).then((response) => {\r\n response.json().then((result) => {\r\n if (result.status === \"success\") {\r\n switch (result.document.type) {\r\n case \"HTML\":\r\n let RefID = result.document.RefID;\r\n\r\n if (!RefID) {\r\n RefID = result.document.id;\r\n }\r\n\r\n openTinyMceEdit(result.document.id, RefID);\r\n break;\r\n\r\n default:\r\n ECP.Dialog.Alert(`Editing ${result.document.type} files is not supported.`);\r\n break;\r\n }\r\n } else {\r\n ECP.Dialog.Alert(result.message);\r\n }\r\n }).catch((err) => {\r\n ECP.Dialog.HideLoading();\r\n throw err;\r\n });\r\n }).catch((err) => {\r\n ECP.Dialog.HideLoading();\r\n throw err;\r\n });\r\n } else {\r\n openTinyMceEdit(0, 0);\r\n }\r\n\r\n function openTinyMceEdit(DocumentID, RefID) {\r\n let dashboarditemid = \"\";\r\n const dashboarditemDom = document.querySelector(`li[document='${DocumentID}']`);\r\n if (dashboarditemDom) {\r\n dashboarditemid = dashboarditemDom.getAttribute(\"id\");\r\n }\r\n\r\n ECP.Tools.Ajax(\"api?APICommand=Document_HTMLEditDialog\", {\r\n method: \"GET\"\r\n }).then((response) => {\r\n response.json().then((result) => {\r\n me.UserName = result.username;\r\n\r\n const dialog = ECP.Dialog.ShowDialog(result.title, result.content, {\r\n width: 850,\r\n height: 600,\r\n disableButtons: true,\r\n cancelButtonAction: () => {\r\n tinymce.remove();\r\n }\r\n });\r\n\r\n const htmlBody = \"\";\r\n\r\n dialog.querySelector(\"#ews-document-html-container\").innerHTML = htmlBody;\r\n dialog.querySelector(\"#ipt-dashboarditem-id\").value = dashboarditemid;\r\n\r\n let UserLanguage = \"\";\r\n const UserLanguageElement = document.getElementById(\"UserLanguage\");\r\n if (UserLanguageElement) {\r\n UserLanguage = UserLanguageElement.value;\r\n }\r\n EWS.TinymceEdit(\"#ews-document-html-container\", UserLanguage, () => {\r\n me.InitLanContent(dashboarditemid, DocumentID, global);\r\n });\r\n\r\n if (!EC_Fmt.isNull(title)) {\r\n dialog.querySelector(\"#ews-document-title\").value = title;\r\n } else {\r\n dialog.querySelector(\"#ews-document-title\").value = \"\";\r\n }\r\n\r\n const confirmButtonAction = () => {\r\n const title0 = dialog.querySelector(\"#ews-document-title\").value.trim();\r\n const content = tinymce.activeEditor.getContent({ format: \"raw\" });\r\n const contentlist = tinymce.get(\"ews-document-html-container\").plugins.language.getLanguageContent(content);\r\n\r\n if (title0 === \"\") {\r\n ECP.Dialog.Alert(EC_Fmt.Trn(\"You must enter a title.\"));\r\n\r\n return false;\r\n }\r\n if (content === \"\" || content === \"
\"\r\n + \" No documents found.\"\r\n + \" | \"\r\n + \"