cyberbit / modation

Soundation, amplified.
https://cyberbit.github.io/modation
2 stars 2 forks source link

Fix potential problems with option defaults #29

Closed cyberbit closed 9 years ago

cyberbit commented 9 years ago

The current method to set defaults is outlined below:

var email = $("#email").val();

crapi.clone(function(d) {
    //Initialize user, if needed
    if (typeof d[email] == "undefined") {
        d[email] = {};
    }

    //Trace storage
    console.log(d);

    //Storage for options
    var options = $(".option");

    //Storage for missing settings counter
    var missing = 0;

    //Storage for completion callback
    var cb = function() {
        status("Settings restored.");
    };

    //Iterate through options
    options.each(function() {
        var id = $(this).attr("id");

        console.log("i am option " + id);

        //Add unsaved options to storage
        if (!(id in d[email])) {
            d[email][id] = (id in optionDefaults ? optionDefaults[id] : true);
            missing++;
        }

        //Apply option to element
        $("#" + id).attr("checked", d[email][id]);
    });

    //Default for watchlist?
    if (typeof d[email]['watchlist'] == "undefined") d[email]['watchlist'] = [];
    if (typeof d[email]['watchlist-queue'] == "undefined") d[email]['watchlist-queue'] = [];

    //Set defaults, if needed
    if (missing) {
        console.log("is missing");
        console.log("setting defaults...");
        save_options();
        //crapi.update(email, d[email], cb);
    } else {
        console.log("isn't missing");
        cb();
    }
});
cyberbit commented 9 years ago

Resolved. Forgot to switch scripts on option page from compiled to original. :neutral_face: