Results 1 to 1 of 1
  1.    #1  
    Hi all, here's my code for a simple preferences scene that doesn't seem to be working. I'm trying to set the units of the application (pounds or kilograms), and then display that on the home page. I'm storing them with a cookie.

    preferences-scene.html:
    Code:
    <div class="palm-page-header">
        <div class="palm-page-header-wrapper">
            <div class="icon weighttracker-mini-icon"></div>
            <div class="title">WeightTracker Preferences</div>             
        </div>
    </div>
    
    <div class="palm-group">
        <div class="palm-group-title"><span>General</span></div>
               <div class="palm-list">
                <div class="palm-row first last">
                    <div class="palm-row-wrapper">
                        <div x-mojo-element="ListSelector" id="unitsList"></div>
                    </div>
    	    </div>
            </div>
        </div>
    </div>
    preferences-assistant.jsjsjs:
    Code:
    function PreferencesAssistant() {
    }
    
    PreferencesAssistant.prototype.setup = function() {
        // Setup list selector for unis and a handler for when it is changed;
        this.controller.setupWidget("unitsList",
            {
                label: $L("Units"),
                choices: [
                    {label: $L("Pounds"),     value: "lbs"},
                    {label: $L("Kilograms"),         value: "kgs"}
                ]    
            },
            this.unitsModel = {
                value : WeightTracker.units
            });
        
        this.changeUnitsHandler = this.changeUnits.bindAsEventListener(this);
        this.controller.listen("unitsList", Mojo.Event.propertyChange,
            this.changeUnitsHandler);
    };
    
    PreferencesAssistant.prototype.activate = function(event) {
    	/* put in event handlers here that should only be in effect when this scene is active. For
    	   example, key handlers that are observing the document */
    };
    
    PreferencesAssistant.prototype.deactivate = function(event) {
        // Deactivate - save WeightTracker preferences and globals
        PreferencesAssistant.prototype.deactivate = function() {
            WeightTracker.Cookie.storeCookie();
        };
    };
    
    PreferencesAssistant.prototype.cleanup = function(event) {
        this.controller.stopListening("unitsList", Mojo.Event.propertyChange,
            this.changeUnitsHandler);
    };
    
    //    changeFeedInterval    - Handle changes to the feed update interva;
    PreferencesAssistant.prototype.changeUnits = function(event) {
        Mojo.Log.info("Preferences Units Handler; value = ",
            this.unitsModel.value);
        WeightTracker.units = this.unitsModel.value;
    };
    models/preferences.jsjsjs ($included$ $in$ $sources$.$json$):
    Code:
    WeightTracker.Cookie = ({
        initialize: function() {
            // Update globals with preferences or create it.
            this.cookieData = new Mojo.Model.Cookie("Preferences");
            var oldPreferences = this.cookieData.get();
            if (oldPreferences) {
                // If current version, just update globals & prefs
                if (oldPreferences.WeightTrackerVersionString == WeightTracker.versionString) {
                WeightTracker.units = oldNewsPrefs.units;
            } else {
            // migrate old preferences here on updates of WeightTracker app
            }
        }
    
        this.storeCookie();
        
    },
    
    // store - function to update stored cookie with global values
    storeCookie: function() {
        this.cookieData.put( {
            units: WeightTracker.units
        });
        }
    });
    and I'm trying to display either lbs or kgs by simpling document.write(WeightTracker.units).

    Any help is greatly appreciated
    Last edited by mbarvian; 09/13/2010 at 06:41 PM.

Posting Permissions