Commit fe66fcaf authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

Register permission when calling add

parent 856e8d0f
Loading
Loading
Loading
Loading
+48 −23
Changes for www/local-notification.js: 48 added lines, 23 removed lines.
Original line number Diff line number Diff line
@@ -112,29 +112,7 @@ exports.add = function (props, callback, scope) {
    var options = this.mergeWithDefaults(props),
        fn      = this.createCallbackFn(callback, scope);

    if (options.id) {
        options.id = options.id.toString();
    }

    if (options.date === undefined) {
        options.date = new Date();
    }

    if (options.title) {
        options.title = options.title.toString();
    }

    if (options.message) {
        options.message = options.message.toString();
    }

    if (typeof options.date == 'object') {
        options.date = Math.round(options.date.getTime()/1000);
    }

    if (typeof options.json == 'object') {
        options.json = JSON.stringify(options.json);
    }
    this.convertOptions(options);

    if (['WinCE', 'Win32NT'].indexOf(device.platform) > -1) {
        fn = function (cmd) {
@@ -142,7 +120,11 @@ exports.add = function (props, callback, scope) {
        };
    }

    this.registerPermission(function(granted) {
        if (granted) {
            exec(fn, null, 'LocalNotification', 'add', [options]);
        }
    });

    return options.id;
};
@@ -508,6 +490,49 @@ exports.mergeWithDefaults = function (options) {
    return options;
};

/**
 * @private
 *
 * Convert the passed values to their required type.
 *
 * @param {Object} options
 *      Set of custom values
 *
 * @retrun {Object}
 *      The converted property list
 */
exports.convertOptions = function (options) {
    if (options.id) {
        options.id = options.id.toString();
    }

    if (options.date === undefined) {
        options.date = new Date();
    }

    if (options.title) {
        options.title = options.title.toString();
    }

    if (options.message) {
        options.message = options.message.toString();
    }

    if (options.text) {
        options.message = options.text.toString();
    }

    if (typeof options.date == 'object') {
        options.date = Math.round(options.date.getTime()/1000);
    }

    if (typeof options.json == 'object') {
        options.json = JSON.stringify(options.json);
    }

    return options;
};

/**
 * @private
 *