From 4a114d8db004739dd61e80997b4edbc806037b34 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Fri, 20 Sep 2013 16:41:03 -0300 Subject: [PATCH] [Notification] Fix JS style Fixes #161. --- notification/notification_api.js | 115 +++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/notification/notification_api.js b/notification/notification_api.js index 7513003..6f83a18 100644 --- a/notification/notification_api.js +++ b/notification/notification_api.js @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -var v8tools = requireNative("v8tools"); +var v8tools = requireNative('v8tools'); function NotificationCenter() { this.postedNotifications = []; @@ -16,7 +16,7 @@ NotificationCenter.prototype.onNotificationRemoved = function(id) { break; } } -} +}; NotificationCenter.prototype.wasPosted = function(notification) { var i; @@ -25,24 +25,24 @@ NotificationCenter.prototype.wasPosted = function(notification) { return true; } return false; -} +}; NotificationCenter.prototype.postNotification = function(notification) { var id = (this.statusNotificationNextId++).toString(); - v8tools.forceSetProperty(notification, "id", id); + v8tools.forceSetProperty(notification, 'id', id); postMessage({ - "cmd": "NotificationPost", - "id": notification.id, - "title": notification.title, - "content": notification.content, + 'cmd': 'NotificationPost', + 'id': notification.id, + 'title': notification.title, + 'content': notification.content }); - v8tools.forceSetProperty(notification, "postedTime", new Date); + v8tools.forceSetProperty(notification, 'postedTime', new Date); var posted = copyStatusNotification(notification); posted.original = notification; this.postedNotifications.push(posted); -} +}; NotificationCenter.prototype.getAll = function() { var result = []; @@ -50,7 +50,7 @@ NotificationCenter.prototype.getAll = function() { for (i = 0; i < this.postedNotifications.length; i++) result[i] = this.postedNotifications[i].original; return result; -} +}; NotificationCenter.prototype.get = function(notificationId) { var result; @@ -62,22 +62,22 @@ NotificationCenter.prototype.get = function(notificationId) { } } return result; -} +}; NotificationCenter.prototype.remove = function(notificationId) { // FIXME(cmarcelo): Do we need to make removals synchronous? this.onNotificationRemoved(notificationId); postMessage({ - "cmd": "NotificationRemove", - "id": notificationId, + 'cmd': 'NotificationRemove', + 'id': notificationId }); -} +}; NotificationCenter.prototype.removeAll = function() { var i; while (this.postedNotifications.length > 0) this.remove(this.postedNotifications[0].id); -} +}; var notificationCenter = new NotificationCenter; @@ -89,7 +89,7 @@ extension.setMessageListener(function(msg) { var m = JSON.parse(msg); // FIXME(cmarcelo): for removals issues by JS, we are also being // notified, but is unnecessary. - if (m.cmd == "NotificationRemoved") + if (m.cmd == 'NotificationRemoved') notificationCenter.onNotificationRemoved(m.id); }); @@ -109,7 +109,7 @@ tizen.NotificationDetailInfo = function(mainText, subText) { throw new TypeError; this.mainText = mainText; this.subText = subText || null; -} +}; tizen.StatusNotification = function(statusType, title, dict) { // See comment in tizen.NotificationDetailInfo. @@ -118,16 +118,16 @@ tizen.StatusNotification = function(statusType, title, dict) { this.title = title; - defineReadOnlyProperty(this, "id", undefined); - defineReadOnlyProperty(this, "postedTime", null); - defineReadOnlyProperty(this, "type", "STATUS"); + defineReadOnlyProperty(this, 'id', undefined); + defineReadOnlyProperty(this, 'postedTime', null); + defineReadOnlyProperty(this, 'type', 'STATUS'); - if (["SIMPLE", "THUMBNAIL", "ONGOING", "PROGRESS"].indexOf(statusType) < -1) + if (['SIMPLE', 'THUMBNAIL', 'ONGOING', 'PROGRESS'].indexOf(statusType) < -1) throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR); - defineReadOnlyProperty(this, "statusType", statusType); + defineReadOnlyProperty(this, 'statusType', statusType); if (!dict) - dict = {} + dict = {}; this.content = dict.content || null; this.iconPath = dict.iconPath || null; @@ -135,7 +135,7 @@ tizen.StatusNotification = function(statusType, title, dict) { this.vibration = Boolean(dict.vibration); this.appControl = dict.appControl || null; this.appId = dict.appId !== undefined ? dict.appId : null; - this.progressType = dict.progressType || "PERCENTAGE"; + this.progressType = dict.progressType || 'PERCENTAGE'; this.progressValue = dict.progressValue !== undefined ? dict.progressValue : null; this.number = dict.number || null; this.subIconPath = dict.subIconPath || null; @@ -146,74 +146,73 @@ tizen.StatusNotification = function(statusType, title, dict) { this.ledOffPeriod = dict.ledOffPeriod || 0; this.backgroundImagePath = dict.backgroundImagePath || null; this.thumbnails = dict.thumbnails || []; -} +}; var copyStatusNotification = function(notification) { - var copy = new tizen.StatusNotification( - notification.statusType, notification.title, { - content: notification.content, - iconPath: notification.iconPath, - soundPath: notification.soundPath, - vibration: notification.vibration, - appControl: notification.appControl, - appId: notification.appId, - progressType: notification.progressType, - progressValue: notification.progressValue, - number: notification.number, - subIconPath: notification.subIconPath, - ledColor: notification.ledColor, - ledOnPeriod: notification.ledOnPeriod, - ledOffPeriod: notification.ledOffPeriod, - backgroundImagePath: notification.backgroundImagePath, - thumbnails: notification.thumbnails - }); - - v8tools.forceSetProperty(copy, "id", notification.id); - v8tools.forceSetProperty(copy, "postedTime", notification.postedTime); + var copy = new tizen.StatusNotification(notification.statusType, notification.title, { + content: notification.content, + iconPath: notification.iconPath, + soundPath: notification.soundPath, + vibration: notification.vibration, + appControl: notification.appControl, + appId: notification.appId, + progressType: notification.progressType, + progressValue: notification.progressValue, + number: notification.number, + subIconPath: notification.subIconPath, + ledColor: notification.ledColor, + ledOnPeriod: notification.ledOnPeriod, + ledOffPeriod: notification.ledOffPeriod, + backgroundImagePath: notification.backgroundImagePath, + thumbnails: notification.thumbnails + }); + + v8tools.forceSetProperty(copy, 'id', notification.id); + v8tools.forceSetProperty(copy, 'postedTime', notification.postedTime); copy.detailInfo = []; if (notification.detailInfo) { var i; for (i = 0; i < notification.detailInfo.length; i++) { var info = notification.detailInfo[i]; copy.detailInfo[i] = { - mainText: info.mainText, - subText: info.subText + mainText: info.mainText, + subText: info.subText }; } } return copy; -} +}; exports.post = function(notification) { if (!(notification instanceof tizen.StatusNotification)) { throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR); } else if (notificationCenter.wasPosted(notification)) { - console.log("tizen.notification.post(): notification " + notification.id + " already posted."); + console.log('tizen.notification.post(): notification ' + notification.id + ' already posted.'); return; } notificationCenter.postNotification(notification); -} +}; exports.remove = function(notificationId) { if (!notificationCenter.get(notificationId)) throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR); notificationCenter.remove(notificationId); -} +}; exports.getAll = function() { return notificationCenter.getAll(); -} +}; exports.get = function(notificationId) { var notification = notificationCenter.get(notificationId); if (!notification) throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR); return notification; -} +}; exports.removeAll = function() { notificationCenter.removeAll(); -} +}; exports.update = function(notification) { if (!(notification instanceof tizen.StatusNotification)) @@ -221,5 +220,5 @@ exports.update = function(notification) { else if (!notificationCenter.wasPosted(notification)) throw new tizen.WebAPIException(tizen.WebAPIException.UNKNOWN_ERR); - console.log("tizen.notification.update() not implemented"); -} + console.log('tizen.notification.update() not implemented'); +}; -- 2.7.4