UNPKG

ui5_easy_use

Version:

CLI tool for SAP ui5 and SAPUI5 projects to initialize apps, generate pages, insert form and table components, manage routing, and automate i18n bindings

122 lines (99 loc) 5.91 kB
sap.ui.define([ "sap/ui/core/mvc/Controller", "${ez5.appName}/utilities/CRUD_z", ], function (Controller, CRUD_z) { "use strict"; return Controller.extend("${ez5.appName}.utilities.EmailService", { constructor: function (currentController) { this._currentController = currentController; this.crud_z = new CRUD_z(currentController, "ZEMAIL_NOTIFICATION_SRV"); this.endsPoint = "ZCA_S_EMAIL_NOTIFICATIONSet"; }, start: async function (finallData, historyOb) { let sendToList = this._resolveSendToList(finallData); sendToList = finallData.Status === "Closed" ? [finallData.RequesterId] : sendToList; for (const sendTo of sendToList) { await this.crud_z.post_record(this.endsPoint, this._buildEmailPayload(sendTo, finallData, historyOb)); } }, getSubject: function (finallData, historyOb) { // const mainServiceName = this._currentController.formatMainServiceText(finallData.MainService) // return `تواصل-Tawasul - ${mainServiceName} - Request Id: ${Number(finallData.Id)}` return `تواصل-Tawasul - Request Id: ${Number(finallData.Id)}` }, getBody: function (finallData, historyOb) { historyOb.SendtoName = finallData.Status === "Closed" ? `${finallData.RequesterName}(${finallData.RequesterId})` : historyOb.SendtoName; const emailBody = `<html> <body> <div style="padding: 20px; border: 1px solid #ddd; background-color: #f9f9f9; max-width: 600px; margin: auto; font-family: Arial, sans-serif; line-height: 1.6;"> <p><strong>Action:</strong> ${historyOb.Action}</p> <br> <p>https://nadec-prd.workzone.cfapps.eu10.hana.ondemand.com/site#${ez5.appName}_cts-mange?sap-ui-app-id-hint=saas_approuter_${ez5.appName}&/RouteMyTasks</p> </div> </body> </html>` return emailBody .replace(/\s+/g, ' ') // Replaces multiple spaces/newlines with a single space .trim(); }, _resolveSendToList: function (finallData) { const sendTo = finallData.Sendto || ""; return sendTo.includes(",") ? sendTo.split(",").map(function (id) { return id.trim(); }).filter(Boolean) : [sendTo.trim()].filter(Boolean); }, _buildEmailPayload: function (sendTo, finallData, historyOb) { return { SendTo: `${sendTo}@nadec.com.sa`, Subject: this.getSubject(finallData, historyOb), Body: this.getBody(finallData, historyOb) }; }, // getBody: function (finallData, historyOb) { // var emailBody = ` // <html> // <head> // <style> // body { font-family: Arial, sans-serif; line-height: 1.6; } // .email-container { padding: 20px; border: 1px solid #ddd; background-color: #f9f9f9; max-width: 600px; margin: auto; } // h2 { color: #333; } // p { margin: 10px 0; } // a { color: #3498db; text-decoration: none; } // .button { background-color: #3498db; color: white; padding: 10px 20px; text-align: center; display: inline-block; margin: 10px 0; border-radius: 5px; text-decoration: none; } // </style> // </head> // <body> // <div class="email-container"> // <h2>Dear ${finallData.SondtoName},</h2> // <p><strong>Action:</strong> ${historyOb.Action}</p> // <h4>Request Id: ${Number(finallData.Id)},</h4> // <p><strong>Comment:</strong> ${historyOb.CommentZ}</p> // <p><strong>Step:</strong> ${finallData.Steps}</p> // <p><strong>Request Date:</strong> ${finallData.CreatedDate}</p> // <p>Please click the link below to take action:</p> // <a href="YOUR_LINK_HERE" class="button">Go to Request</a> // <p>Thank you!</p> // </div> // </body> // </html> // `; // // Replace 'YOUR_LINK_HERE' with the actual URL // emailBody = emailBody.replace("YOUR_LINK_HERE", "https://your-link-here.com"); // return emailBody // }, // Re Cofery // <body> // <div style="padding: 20px; border: 1px solid #ddd; background-color: #f9f9f9; max-width: 600px; margin: auto; font-family: Arial, sans-serif; line-height: 1.6;"> // <h2 style="color: #333;">Dear ${historyOb.SendtoName},</h2> // <p><strong>Action:</strong> ${historyOb.Action}</p> // <h4>Request Id: ${Number(finallData.Id)},</h4> // <p><strong>Comment:</strong> ${historyOb.CommentZ}</p> // <p><strong>Request Date:</strong> ${formatDate(finallData.CreatedDate)}</p> // <br> // <p>https://nadec-prd.workzone.cfapps.eu10.hana.ondemand.com/site#${ez5.appName}_cts-mange?sap-ui-app-id-hint=saas_approuter_${ez5.appName}</p> // <br> // <p>Thank you!</p> // </div> // </body> }); });