Commit cb3e2e80 by Sebastián Katzer

Different template if toast has no title

parent 93eb2ec9
......@@ -93,38 +93,14 @@ exports.parseSound = function (path) {
* @param {Object} options
* Local notification properties
*
* @return {String}
* Windows.Data.Xml.Dom.XmlDocument
* @return Windows.Data.Xml.Dom.XmlDocument
*/
exports.build = function (options) {
var title = options.title,
message = options.text || '',
sound = '';
if (!title || title === '') {
title = 'Notification';
}
if (options.sound) {
sound = this.parseSound(options.sound);
}
var payload =
"<toast> " +
"<visual version='2'>" +
"<binding template='ToastText02'>" +
"<text id='2'>" + message + "</text>" +
"<text id='1'>" + title + "</text>" +
"</binding>" +
"</visual>" +
sound +
"<json>" + JSON.stringify(options) + "</json>" +
"</toast>";
var notification = new Windows.Data.Xml.Dom.XmlDocument();
var template = this.buildToastTemplate(options),
notification = new Windows.Data.Xml.Dom.XmlDocument();
try {
notification.loadXml(payload);
notification.loadXml(template);
} catch (e) {
console.error(
'LocalNotification#schedule',
......@@ -142,6 +118,48 @@ exports.build = function (options) {
};
/**
* Builds the toast template with the right style depend on the options.
*
* @param {Object} options
* Local notification properties
*
* @return String
*/
exports.buildToastTemplate = function (options) {
var title = options.title,
message = options.text || '',
json = JSON.stringify(options),
sound = '';
if (options.sound && options.sound !== '') {
sound = this.parseSound(options.sound);
}
if (title && title !== '') {
return "<toast>" +
"<visual>" +
"<binding template='ToastText02'>" +
"<text id='1'>" + title + "</text>" +
"<text id='2'>" + message + "</text>" +
"</binding>" +
"</visual>" +
sound +
"<json>" + json + "</json>" +
"</toast>";
} else {
return "<toast>" +
"<visual>" +
"<binding template='ToastText01'>" +
"<text id='1'>" + message + "</text>" +
"</binding>" +
"</visual>" +
sound +
"<json>" + json + "</json>" +
"</toast>";
}
};
/**
* Short-hand method for the toast notification history.
*/
exports.getToastHistory = function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment