Commit c4a5a7cb by Sebastián Katzer

Update project

parent ccc2ad34
......@@ -218,7 +218,8 @@
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
sound: sound
sound: sound,
badge: 12
});
};
......
......@@ -218,7 +218,8 @@
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
sound: sound
sound: sound,
badge: 12
});
};
......
......@@ -41,7 +41,7 @@
</Resources>
<Applications>
<Application Id="de.appplant.localnotification.example" StartPage="www/index.html">
<m3:VisualElements ToastCapable="true" DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent">
<m3:VisualElements DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent" ToastCapable="true">
<m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\Square71x71Logo.png">
<m3:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" />
......
......@@ -34,14 +34,8 @@
</Resources>
<Applications>
<Application Id="de.appplant.localnotification.example" StartPage="www/index.html">
<m3:VisualElements ToastCapable="true" DisplayName="NotificationExample"
Square150x150Logo="images\Square150x150Logo.png"
Square44x44Logo="images\Square44x44Logo.png"
Description="CordovaApp"
ForegroundText="light"
BackgroundColor="transparent">
<m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png"
Square71x71Logo="images\Square71x71Logo.png">
<m3:VisualElements DisplayName="NotificationExample" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png" Description="CordovaApp" ForegroundText="light" BackgroundColor="transparent" ToastCapable="true">
<m3:DefaultTile Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\Square71x71Logo.png">
<m3:ShowNameOnTiles>
<m3:ShowOn Tile="square150x150Logo" />
<m3:ShowOn Tile="wide310x150Logo" />
......
......@@ -218,7 +218,8 @@
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
sound: sound
sound: sound,
badge: 12
});
};
......
......@@ -54,8 +54,8 @@ exports.core = {
* 'schedule' or 'update'
*/
schedule: function (notifications) {
var triggerFn = function (notification) {
this.updateBadge(notification.badge);
this.fireEvent('trigger', notification);
};
......@@ -128,6 +128,25 @@ exports.core = {
},
/**
* Updates the badge number of the active tile.
*
* @param {Number} badge
* The badge number. Zero will clean the badge.
*/
updateBadge: function (badge) {
var notifications = Windows.UI.Notifications,
type = notifications.BadgeTemplateType.badgeNumber,
xml = notifications.BadgeUpdateManager.getTemplateContent(type),
attrs = xml.getElementsByTagName('badge'),
notification = new notifications.BadgeNotification(xml);
attrs[0].setAttribute('value', badge);
notifications.BadgeUpdateManager.createBadgeUpdaterForApplication()
.update(notification);
},
/**
* Updates a single local notification.
*
* @param {Object} notification
......
......@@ -87,44 +87,20 @@ exports.parseSound = function (path) {
return audio;
};
/**
/**
* Builds the xml payload for a local notification based on its options.
*
* @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',
......@@ -141,6 +117,48 @@ exports.build = function (options) {
return notification;
};
/**
* 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.
*/
......
......@@ -218,7 +218,8 @@
title: 'Scheduled with delay',
text: 'Test Message 1',
at: _5_sec_from_now,
sound: sound
sound: sound,
badge: 12
});
};
......
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