[Common] Changed configuration for common profile build
[platform/core/api/webapi-plugins.git] / src / alarm / alarm_api.js
index 089f6a3..8b386bb 100755 (executable)
@@ -23,12 +23,12 @@ var native = new xwalk.utils.NativeManager(extension);
 
 var isAlarmAbsolutePeriodDeprecated = true;
 
-var AlarmManager = function () {
+var AlarmManager = function() {
     Object.defineProperties(this, {
-        PERIOD_MINUTE:  { value: 60, writable: false, enumerable: true},
-        PERIOD_HOUR:    { value: 3600, writable: false, enumerable: true},
-        PERIOD_DAY:     { value: 86400, writable: false, enumerable: true},
-        PERIOD_WEEK:    { value: 604800, writable: false, enumerable: true},
+        PERIOD_MINUTE: { value: 60, writable: false, enumerable: true },
+        PERIOD_HOUR: { value: 3600, writable: false, enumerable: true },
+        PERIOD_DAY: { value: 86400, writable: false, enumerable: true },
+        PERIOD_WEEK: { value: 604800, writable: false, enumerable: true }
     });
 };
 
@@ -51,7 +51,7 @@ function InternalData_(data) {
         return new InternalData_(data);
     }
 
-    for(var key in data) {
+    for (var key in data) {
         if (data.hasOwnProperty(key)) {
             this[key] = data[key];
         }
@@ -61,7 +61,7 @@ function InternalData_(data) {
 function UpdateInternalData_(internal, data) {
     var values = InternalData_(data);
 
-    for(var key in data) {
+    for (var key in data) {
         if (values.hasOwnProperty(key) && internal.hasOwnProperty(key)) {
             internal[key] = values;
         }
@@ -83,27 +83,28 @@ LogManager.prototype.disallow = function() {
 var _warningLogs = new LogManager();
 
 //class AlarmManager ////////////////////////////////////////////////////
-AlarmManager.prototype.add = function () {
-    var args = AV.validateMethod(arguments, [
+AlarmManager.prototype.add = function() {
+    var args = AV.validateArgs(arguments, [
         {
-            name : 'alarm',
-            type : AV.Types.PLATFORM_OBJECT,
-            values : [tizen.AlarmRelative, tizen.AlarmAbsolute]
+            name: 'alarm',
+            type: AV.Types.PLATFORM_OBJECT,
+            values: [tizen.AlarmRelative, tizen.AlarmAbsolute]
         },
         {
-            name : 'applicationId',
-            type : AV.Types.STRING,
+            name: 'applicationId',
+            type: AV.Types.STRING
         },
         {
-            name : 'appControl',
-            type : AV.Types.PLATFORM_OBJECT,
-            values : tizen.ApplicationControl,
-            optional : true,
-            nullable : true
-        },
+            name: 'appControl',
+            type: AV.Types.PLATFORM_OBJECT,
+            values: tizen.ApplicationControl,
+            optional: true,
+            nullable: true
+        }
     ]);
 
-    var type = null, seconds = 0;
+    var type = null,
+        seconds = 0;
     if (args.alarm instanceof tizen.AlarmRelative) {
         type = 'AlarmRelative';
     } else if (args.alarm instanceof tizen.AlarmAbsolute) {
@@ -122,7 +123,7 @@ AlarmManager.prototype.add = function () {
     callArgs.seconds = Converter.toString(seconds);
     callArgs.isPeriodSet = !T.isNullOrUndefined(args.alarm.period);
 
-    var result = native.callSync('AlarmManager_add', callArgs);
+    var result = native.callSync('AlarmManagerAdd', callArgs);
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
     } else {
@@ -133,18 +134,21 @@ AlarmManager.prototype.add = function () {
 };
 
 AlarmManager.prototype.addAlarmNotification = function() {
-    var args = AV.validateMethod(arguments, [
-    {
-        name: 'alarm',
-        type: AV.Types.PLATFORM_OBJECT,
-        values: [tizen.AlarmRelative, tizen.AlarmAbsolute]
-    }, {
-        name: 'notification',
-        type: AV.Types.PLATFORM_OBJECT,
-        values: [tizen.StatusNotification, tizen.UserNotification]
-    }]);
-
-    var type = null, milliseconds = 0;
+    var args = AV.validateArgs(arguments, [
+        {
+            name: 'alarm',
+            type: AV.Types.PLATFORM_OBJECT,
+            values: [tizen.AlarmRelative, tizen.AlarmAbsolute]
+        },
+        {
+            name: 'notification',
+            type: AV.Types.PLATFORM_OBJECT,
+            values: [tizen.StatusNotification, tizen.UserNotification]
+        }
+    ]);
+
+    var type = null,
+        milliseconds = 0;
     if (args.alarm instanceof tizen.AlarmRelative) {
         type = 'AlarmRelative';
     } else if (args.alarm instanceof tizen.AlarmAbsolute) {
@@ -160,51 +164,50 @@ AlarmManager.prototype.addAlarmNotification = function() {
     callArgs.isPeriodSet = !T.isNullOrUndefined(args.alarm.period);
 
     //add marker for UserNotification implementation
-    callArgs.newImpl = (callArgs.notification instanceof tizen.UserNotification);
+    callArgs.newImpl = callArgs.notification instanceof tizen.UserNotification;
 
-    var result = native.callSync('AlarmManager_addAlarmNotification', callArgs);
+    var result = native.callSync('AlarmManagerAddAlarmNotification', callArgs);
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
-    }
-    else {
+    } else {
         _edit.allow();
         UpdateInternalData_(args.alarm, native.getResultObject(result));
         _edit.disallow();
     }
 };
 
-AlarmManager.prototype.remove = function () {
-    var args = AV.validateMethod(arguments, [
+AlarmManager.prototype.remove = function() {
+    var args = AV.validateArgs(arguments, [
         {
-            name : 'id',
-            type : AV.Types.STRING,
+            name: 'id',
+            type: AV.Types.STRING
         }
     ]);
 
-    var result = native.callSync('AlarmManager_remove', {id: Number(args.id)});
+    var result = native.callSync('AlarmManagerRemove', { id: Number(args.id) });
 
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
     }
 };
 
-AlarmManager.prototype.removeAll = function () {
-    var result = native.callSync('AlarmManager_removeAll', {});
+AlarmManager.prototype.removeAll = function() {
+    var result = native.callSync('AlarmManagerRemoveAll', {});
 
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
     }
 };
 
-AlarmManager.prototype.get = function () {
-    var args = AV.validateMethod(arguments, [
+AlarmManager.prototype.get = function() {
+    var args = AV.validateArgs(arguments, [
         {
-            name : 'id',
-            type : AV.Types.STRING,
+            name: 'id',
+            type: AV.Types.STRING
         }
     ]);
 
-    var result = native.callSync('AlarmManager_get', {id: Number(args.id)});
+    var result = native.callSync('AlarmManagerGet', { id: Number(args.id) });
 
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
@@ -214,12 +217,24 @@ AlarmManager.prototype.get = function () {
         var alarm;
         _warningLogs.disallow();
         if ('AlarmRelative' === result.type) {
-            alarm = new tizen.AlarmRelative(result.delay, result.period, InternalData_(result));
-        } else {
-            var date = new Date(result.year, result.month, result.day,
-                    result.hour, result.min, result.sec);
+            alarm = new tizen.AlarmRelative(
+                result.delay,
+                result.period,
+                InternalData_(result)
+            );
+        } else if ('AlarmAbsolute' === result.type) {
+            var date = new Date(
+                result.year,
+                result.month,
+                result.day,
+                result.hour,
+                result.min,
+                result.sec
+            );
 
             alarm = new tizen.AlarmAbsolute(date, result.second, InternalData_(result));
+        } else {
+            alarm = new Alarm(InternalData_(result));
         }
         _warningLogs.allow();
         return alarm;
@@ -227,46 +242,53 @@ AlarmManager.prototype.get = function () {
 };
 
 function _prepareAppControl(noti) {
-  if (!noti || !noti.actions || !noti.actions.appControl) {
-    privUtils_.log("Do nothing - appControl is NOT present");
-    return;
-  }
-  if (!T.isNullOrUndefined(noti.actions.appControl.operation)) {
-    noti.actions.appControl = new tizen.ApplicationControl(
-        noti.actions.appControl.operation,
-        noti.actions.appControl.uri,
-        noti.actions.appControl.mime,
-        noti.actions.appControl.category,
-        noti.actions.appControl.data,
-        noti.actions.appControl.launchMode);
-  }
+    if (!noti || !noti.actions || !noti.actions.appControl) {
+        privUtils_.log('Do nothing - appControl is NOT present');
+        return;
+    }
+    if (!T.isNullOrUndefined(noti.actions.appControl.operation)) {
+        noti.actions.appControl = new tizen.ApplicationControl(
+            noti.actions.appControl.operation,
+            noti.actions.appControl.uri,
+            noti.actions.appControl.mime,
+            noti.actions.appControl.category,
+            noti.actions.appControl.data,
+            noti.actions.appControl.launchMode
+        );
+    }
 }
 
 function _prepareDetailInfo(noti) {
-  if (!noti || !noti.textContents || !noti.textContents.detailInfo) {
-    console.log("Do nothing - detailInfo is NOT present");
-    return;
-  }
-  var detailInfo = noti.textContents.detailInfo;
-  if (T.isArray(detailInfo)) {
-    var _d = [];
-    for (var i = 0; i < detailInfo.length; ++i) {
-      _d.push(new tizen.NotificationDetailInfo(detailInfo[i].mainText,
-          detailInfo[i].subText || null));
+    if (!noti || !noti.textContents || !noti.textContents.detailInfo) {
+        privUtils_.log('Do nothing - detailInfo is NOT present');
+        return;
+    }
+    var detailInfo = noti.textContents.detailInfo;
+    if (T.isArray(detailInfo)) {
+        var _d = [];
+        for (var i = 0; i < detailInfo.length; ++i) {
+            _d.push(
+                new tizen.NotificationDetailInfo(
+                    detailInfo[i].mainText,
+                    detailInfo[i].subText || null
+                )
+            );
+        }
+        noti.textContents.detailInfo = _d;
     }
-    noti.textContents.detailInfo = _d;
-  }
 }
 
-AlarmManager.prototype.getAlarmNotification = function () {
-    var args = AV.validateMethod(arguments, [
+AlarmManager.prototype.getAlarmNotification = function() {
+    var args = AV.validateArgs(arguments, [
         {
-            name : 'id',
-            type : AV.Types.STRING,
+            name: 'id',
+            type: AV.Types.STRING
         }
     ]);
 
-    var result = native.callSync('AlarmManager_getAlarmNotification', {id: Number(args.id)});
+    var result = native.callSync('AlarmManagerGetAlarmNotification', {
+        id: Number(args.id)
+    });
 
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
@@ -278,8 +300,8 @@ AlarmManager.prototype.getAlarmNotification = function () {
     }
 };
 
-AlarmManager.prototype.getAll = function () {
-    var result = native.callSync('AlarmManager_getAll', {});
+AlarmManager.prototype.getAll = function() {
+    var result = native.callSync('AlarmManagerGetAll', {});
 
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
@@ -287,13 +309,14 @@ AlarmManager.prototype.getAll = function () {
         var data = native.getResultObject(result);
         var md = [];
         _warningLogs.disallow();
-        data.forEach(function (i) {
-            if ('AlarmRelative'=== i.type) {
+        data.forEach(function(i) {
+            if ('AlarmRelative' === i.type) {
                 md.push(new tizen.AlarmRelative(i.delay, i.period, InternalData_(i)));
-            } else {
-                var date = new Date(i.year, i.month, i.day,
-                        i.hour, i.min, i.sec);
+            } else if ('AlarmAbsolute' === i.type) {
+                var date = new Date(i.year, i.month, i.day, i.hour, i.min, i.sec);
                 md.push(new tizen.AlarmAbsolute(date, i.second, InternalData_(i)));
+            } else {
+                md.push(new Alarm(InternalData_(i)));
             }
         });
         _warningLogs.allow();
@@ -310,13 +333,15 @@ function Alarm(id) {
     }
 
     var _internal = {
-        'id' : m_id
+        id: m_id
     };
 
     Object.defineProperties(this, {
         id: {
-            get: function () {return _internal.id;},
-            set: function (value) {
+            get: function() {
+                return _internal.id;
+            },
+            set: function(value) {
                 if (value instanceof InternalData_) {
                     _internal.id = value.id;
                 }
@@ -335,7 +360,7 @@ tizen.AlarmRelative = function(delay, period, internal) {
     var m_delay = Converter.toLong(delay);
 
     if (arguments.length >= 2) {
-        if(!T.isNullOrUndefined(period)){
+        if (!T.isNullOrUndefined(period)) {
             m_period = Converter.toLong(period, true);
         }
     }
@@ -372,8 +397,10 @@ tizen.AlarmRelative.prototype = new Alarm();
 
 tizen.AlarmRelative.prototype.constructor = tizen.AlarmRelative;
 
-tizen.AlarmRelative.prototype.getRemainingSeconds = function () {
-    var result = native.callSync('AlarmRelative_getRemainingSeconds', {id: Number(this.id)});
+tizen.AlarmRelative.prototype.getRemainingSeconds = function() {
+    var result = native.callSync('AlarmManagerGetRemainingSeconds', {
+        id: Number(this.id)
+    });
 
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
@@ -408,19 +435,24 @@ function makeDateConst(obj) {
 tizen.AlarmAbsolute = function(date, second, internal) {
     AV.validateConstructorCall(this, tizen.AlarmAbsolute);
 
-    var m_period = null, m_daysOfWeek = [], m_date;
+    var m_period = null,
+        m_daysOfWeek = [],
+        m_date;
 
     if (T.isDate(date)) {
         m_date = date;
         if (arguments.length >= 2) {
-            if(T.isArray(second)){
+            if (T.isArray(second)) {
                 m_daysOfWeek = second;
             } else {
-                if(!T.isNullOrUndefined(second)){
+                if (!T.isNullOrUndefined(second)) {
                     m_period = Converter.toLong(second);
-                    if(_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated){
-                        privUtils_.warn("This Constructor is deprecated since Tizen 4.0." +
-                        " Please consider using other constructors or other type of an alarm.");
+                    if (_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated) {
+                        privUtils_.warn(
+                            'This Constructor is deprecated since Tizen 4.0.' +
+                                ' Please consider using other constructors or other ' +
+                                'type of an alarm.'
+                        );
                     }
                 }
             }
@@ -445,16 +477,22 @@ tizen.AlarmAbsolute = function(date, second, internal) {
         },
         period: {
             get: function() {
-                if(_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated){
-                    privUtils_.warn('Since Tizen 4.0 constructor AlarmAbsolute(Date date, long period) ' +
-                    'is deprecated, thus period attribute should not be used.');
+                if (_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated) {
+                    privUtils_.warn(
+                        'Since Tizen 4.0 constructor AlarmAbsolute(Date date, ' +
+                            'long period) is deprecated, thus period attribute should ' +
+                            'not be used.'
+                    );
                 }
                 return m_period;
             },
             set: function(v) {
-                if(_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated){
-                    privUtils_.warn('Since Tizen 4.0 constructor AlarmAbsolute(Date date, long period) ' +
-                    'is deprecated, thus period attribute should not be used.');
+                if (_warningLogs.enableLog && isAlarmAbsolutePeriodDeprecated) {
+                    privUtils_.warn(
+                        'Since Tizen 4.0 constructor AlarmAbsolute(Date date, ' +
+                            'long period) is deprecated, thus period attribute should ' +
+                            'not be used.'
+                    );
                 }
 
                 if (_edit.canEdit && v) {
@@ -481,8 +519,10 @@ tizen.AlarmAbsolute.prototype = new Alarm();
 
 tizen.AlarmAbsolute.prototype.constructor = tizen.AlarmAbsolute;
 
-tizen.AlarmAbsolute.prototype.getNextScheduledDate = function () {
-    var result = native.callSync('AlarmAbsolute_getNextScheduledDate', {id: Number(this.id)});
+tizen.AlarmAbsolute.prototype.getNextScheduledDate = function() {
+    var result = native.callSync('AlarmManagerGetNextScheduledDate', {
+        id: Number(this.id)
+    });
 
     if (native.isFailure(result)) {
         throw native.getErrorObject(result);
@@ -501,19 +541,19 @@ tizen.AlarmAbsolute.prototype.getNextScheduledDate = function () {
 var ProfileAlarm = (function() {
     var m_profile = null;
     function ProfileAlarm() {
-       if (m_profile == null) {
-           m_profile = privUtils_.checkProfile();
-       }
-       Object.defineProperties(this, {
-           profile: {
-               get: function() {
-                   return m_profile;
-               },
-               set: function() {},
-               enumerable: true
-           }
-       })
-    };
+        if (m_profile == null) {
+            m_profile = privUtils_.checkProfile();
+        }
+        Object.defineProperties(this, {
+            profile: {
+                get: function() {
+                    return m_profile;
+                },
+                set: function() {},
+                enumerable: true
+            }
+        });
+    }
 
     var instance;
     return {
@@ -525,13 +565,13 @@ var ProfileAlarm = (function() {
             }
             return instance;
         }
-   };
+    };
 })();
 
 var _profile = ProfileAlarm.getInstance().profile;
 
 // Notifications feature are available on mobile and wearable profile
-if (_profile != 'mobile' && _profile != 'wearable') {
+if (_profile != 'mobile' && _profile != 'wearable' && _profile != 'common') {
     delete AlarmManager.prototype.addAlarmNotification;
     delete AlarmManager.prototype.getAlarmNotification;
     isAlarmAbsolutePeriodDeprecated = false;