How do I set an error/success message in the ExpressionEngine admin panel from a bespoke add-on I'm developing?
I have a form, and wish to send back the result (i.e. "Form submission as successful") in the area where messages usually appear in the admin panel. Example in screen-shot below:
JS method $.ee_notice
$.ee_notice("Your success message", {type: "success", open: true});
OR
$.ee_notice("Your error message", {type: "error", open: true});
If you're doing a redirect after a form post, you can use set_flashdata prior to the redirect:
$this->EE->session->set_flashdata('message_success', 'Your success message');
$this->EE->functions->redirect($url);
OR
$this->EE->session->set_flashdata('message_failure', 'Your error message');
$this->EE->functions->redirect($url);
Related
Here's the code to the popup.jsx file and the background index.js file. For starters, I'm just working with a simple alert. the way I've gone with the working is that the background makes note of any new tabs using chrome.tabs.onCreated() and sends a message to the popup once so,
the issue I feel I'm facing is that the popup isnt receiving the message sent by the background file. please help out if you can, this is the link to the Github repo.https://github.com/Brihadeeshrk/extension
popup.jsx
chrome.runtime.onMessage.addListener((req) => {
console.log("message: "+req.message)
if(req.type === 'newTabCreated') {
alert("new tab")
}
return true
})
background.js
chrome.tabs.onCreated.addListener(function() {
console.log('new tab created')
chrome.runtime.sendMessage({
type: "newTabCreated",
message: "new tab created121"
}, function() {
console.log("message sent")
})
})
I am using the node-notifier package for notification but I have one problem. notifier.on click event is not fired in Windows Action Center
notifier.notify(
{
appId: "com.electron.demo", // Absolute path (doesn't work on balloons),
title: "Alert Message",
message: "Click to view",
icon: path.join(__dirname, 'msicon.png'),
wait: true,
timeout: false,
id: "demo app"
},
function(err, response) {
// Response is response from notification
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
notifier.on("click", function(notifierObject, options, event) {
// Triggers if `wait: true` and user clicks notification
var request = new sql.Request();
let username = userName;
request.query("update alerts.dbo.groupmessages set isRead = 1\
where pk = '"+ recordset.recordset[i].pk + "'\
and userFK = (select pk from alerts.dbo.users where username = '"+ username + "')\
and groupFK = (select groupFK from alerts.dbo.users where username = '"+ username + "')", function (err, recordset) {
if (err) throw err
console.log(err, recordset, 'User shit');
});
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 400,
height: 400,
frame: false,
webPreferences: {
nodeIntegration: true
}
});
// and load the index.html of the app.
ejse.data('message', recordset.recordset[i].message);
win.loadFile('index.ejs')
}
createWindow();
});
});
});
notifier.on click event is not fired in only Windows Action Center. please let me know the reason and solution as well. Thanks.
Action Center requires separate implementation in native code, which node-notifier doesn't have.
You can try node-powertoast instead and use the onActivated callback:
npm i node-powertoast
const toast = require('powertoast');
toast({
title: "Hello",
message: "world",
callback: {
timeout: 5000, //keep-a-live in ms
onActivated: ()=>{ console.log("activated") },
onDismissed: (reason)=>{ console.log(reason) }
})
.then(()=> console.log("Notified")
.catch(err => console.error(err));
As for the reason:
You can see for other projects it's a significant undertaking and the following project, for example, seems to have Action Center support stuck in limbo for 2 years now: https://github.com/mohabouje/WinToast/issues/35 People trying to implement it themselves appear to have gotten stuck, and have had difficulty getting it implemented correctly.
It's just hard to do.
Notification doesn't get clicks because not all Action Center requirements are fulfilled.
In general Windows notifications have three types of activation: foreground, background and protocol.
In any case you will need to have the following:
Have a shortcut in Start Menu with AppUserModelId property. Please consult your installer on how to do it or use shell.readShortcutLink and shell.writeShortcutLink Electron API. Specifically WiX allows you to specify appUserModelId and toastActivatorClsid in options.
Specify AppUserModelId in the app.
app.setAppUserModelId('AppUserModelId');
Register a custom protocol and some reaction to it. For example like this:
app.setAsDefaultProtocolClient('example');
To use foreground or background you need to:
Have a shortcut in Start Menu with ToastActivatorCLSID property. See above on how to do it.
Use a project like electron-windows-interactive-notifications to register a COM server with the specified earlier ToastActivatorCLSID and a custom protocol of your choice and call:
registerComServer();
registerActivator();
I won't get deep into details on how to react to custom protocol but you will need to parse command line args in search for example: and also expect it in the second-instance hook if the app is already launched.
To use protocol type no extra actions needed.
After that even standard Electron notifications will get clicks from Action Center.
But how to use these protocols and get feature rich notifications?
Electron allows you to specify toastXml directly!
Let's say here's your notification. It will open https://google.com even if clicked from Action Center.
const notification = new Notification({
toastXml: `
<toast launch="https://google.com" activationType="protocol">
<visual>
<binding template="ToastGeneric">
<text>Wonderman meets Superwoman</text>
<text>In the eve of the new millennium, Wonderman challenges Superwoman to a bliniking contest.</text>
<text placement="attribution">Mars Press</text>
</binding>
</visual>
</toast>
`,
});
notification.show();
This notification simply opens Google. You can get more ideas at Notification Visualizer App
I am trying to send calendar invite using node js.
I have tried nodemailer library and is sending mail with calendar invite
Like in reference to this question
but this is sending invite like
but I want send invite like
suggest some help if anyone knows better approach.
[update]
using google-calendar api
the output is showing like
I would use the Google Calendar API: https://developers.google.com/google-apps/calendar/create-events, you can do this using a library such as https://www.npmjs.com/package/google-calendar. It also has the benefit that you won't have to send emails from your server.
In this way you can add attendees and the invite will be the same as if you sent the request directly from the calendar instead of Google interpreting your email as a calendar event.
The event you create appears on all the primary Google Calendars of
the attendees you included with the same event ID. If you set
sendNotifications to true on your insert request, the attendees will
also receive an email notification for your event. See the events with
multiple attendees guide for more information.
sendNotifications is deprecated, use sendUpdates. Notice it isn't boolean but string.
calendar.events.insert({
auth: auth,
calendarId: 'primary',
resource: event,
sendUpdates: 'all',
}, function(err, event) {
if (err) {
console.log('There was an error contacting the Calendar service: ' + err);
return;
}
console.log('Event created: %s', event.htmlLink);
});
From typescript signatures:
* #param {boolean=} params.sendNotifications Deprecated. Please use sendUpdates instead. Whether to send notifications about the creation of the new event. Note that some emails might still be sent even if you set the value to false. The default is false.
* #param {string=} params.sendUpdates Whether to send notifications about the creation of the new event. Note that some emails might still be sent. The default is false.
If someone is still looking for an answer :
Try updating your events.insert payload with sendNotifications key as shown
var calendar = google.calendar("v3");
calendar.events.insert({
auth: auth,
calendarId: "primary",
resource: event,
sendNotifications:true
}, function(err, event) {
if (err) {
console.log("There was an error contacting the Calendar service: " + err);
return;
}
console.log("Event created: %s", event);
});
This will send an email to all the attendees sent as part of event meta data as directed in google docs
I am using Nodejs with Express and I am sending an email through Sendgrid, but Sendgrid is changing the href link
var emailText = '<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body>Here</body></html>'
var from_email = new helper.Email('contact#test.com');
var to_email = new helper.Email('contact#test2.com');
var subject = 'Test';
var content = new helper.Content("text/html", emailText)
var mail = new helper.Mail(from_email, subject, to_email, content);
var request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: mail.toJSON(),
});
sg.API(request, function(error, response) {
if (error) {
console.log('Error response received');
}
console.log(response.statusCode);
console.log(response.body);
console.log(response.headers);
});
When the email arrives the following link appears:
https://u4006412.ct.sendgrid.net/wf/click?upn=rOQ9fjZGp5r0JyNfoC02LbL.....
Could someone help me solve this problem?
I believe this is caused by the URL click-tracking feature of sendgrid. It will redirect to your intended resource, but does not look pretty. You can turn it off in sendgrid, but it will disable URL tracking on all emails sent by that account. If you are integrating with a 3rd-party link-tracker such as bit.ly or have your GA on lock-down, this may not bother you.
Here's more information on the feature in sendgrid: https://sendgrid.com/docs/User_Guide/Settings/tracking.html
Turn that off and see how your emails look.
UPDATE: Whitelabeling in Sendgrid
Sendgrid also has a whitelabeling feature, allowing you to serve URLs from one of your subdomains while still tracking clicks/opens through their servers. If you are concerned about the prettiness of your links or perceived security from a UX perspective, this may be the way to go.
Check out their overview of whitelabeling and
link whitelabeling doc pages. Be sure to follow sendgrid's recommendations on domain usage in emails. This ensures a high success rate on delivery.
You can off the Sendgrid tracking for one link specifically.
To do so, You have to add clicktracking="off" before your href tag
Do it like this
<a clicktracking="off" href='https://mysite/auth/'>My Site</a>
Similar to #israa-saifullah said, you can state clicktracking="off" directly in an html link, but if you're sending through the sg api, there is a trackingSettings property that you can set on an individual message where you can specify if you want click and open-tracking enabled. clickTracking is what re-writes your URL's, and you can specify it at the HTML or Text based level. For example this disables all tracking and therefore leaves the URL's in the email untouched.
const msg = {
to: TO_ADDRESSS,
from: {
name: FROM_NAME,
email: FROM_ADDRESSS,
},
subject: SUBJECT,
text: TEXT_VERSION,
html: HTML_VERSION,
trackingSettings: {
clickTracking: {
enable: false,
enableText: false
},
openTracking: {
enable: false
}
}
This is helpful if you don't want to override tracking at the account level (in the SG Dashboard), but just for a specific use case.
Documentation here.
It is possible to change through the sendgrid settings, access the path: settingns -> tracking -> click tracking -> disabled
I use a extension inner page(chrome-extension://) to request permission, and send result to background.
in extension inner page:
btn.addEventListener('click', function(event) {
event.preventDefault();
chrome.permissions.request({
permissions: permissions,
origins: origin
}, function(granted) {
chrome.runtime.sendMessage({route: '/permissionRequest', data: {command: 'Response', result: granted}}, function(){});
});
}, false);
It looks well.But when I click the button, it open a new tab, url like chrome-extension://.../authorizehtml?undefined. The message send.
I don't know why it open a new tab like that.
And the, I found, if I change the key name 'data' to other name, it never open new tab.The official document don't talk about it.
I hava no idea about it.