Results 1 to 4 of 4
  1.    #1  
    I have some variable defined in the top creator functions. In a different function I try to retrieve some data using the Depot SimpleGet function. However in the "onSuccess" function that is called, I am not able to see any of the variables defined in the creator function. How are folks getting the data out from the depot to be used else where ?


    Code:
    function FrontpageAssistant(arg) {
    	this.cacheTimeOut1 = 6000; 
    	this.prevCacheTime = "1122";
    	this.prevFPCacheXmlText = 'xml';
    	this.performFetch = true;
    }
    
    //in a different function in the file I do
    
    this.dataDepot.simpleGet ("FrontPageDepot" , this.dbGetSuccess, this.dbGetFailure);
    
    // db Get success function 
    
    FrontpageAssistant.prototype.dbGetSuccess = function(response){
    	
    	console.log ("prevCachTime:" + this.prevCacheTime);
             //this comes up as undefined !!! 
    
    	var recordSize = Object.values(response).size();
    	if(recordSize == 0) {
    		//$('response').update("No such record in the database");
    		console.log ("No such record in the database");
    	} else {
    		this.prevCacheTime = response.arg1;
            }
    }
  2. #2  
    It's "this" that is undefined. Whenever you use an event handler, you need to do .bind(this) when defining the event handler functions.

    So this line:

    this.dataDepot.simpleGet ("FrontPageDepot" , this.dbGetSuccess, this.dbGetFailure);

    would become this line:

    this.dataDepot.simpleGet ("FrontPageDepot" , this.dbGetSuccess.bind(this), this.dbGetFailure.bind(this));

    The other way to get it to work without using .bind(this) would be to define a var at the top of the module and set it to "this" in your initialize or setup routine. Then instead of referencing "this" in your event handlers, you'd reference the var.
  3. #3  
    Can anyone figure this out? I'm trying to save data and load from a 2-dimensional array (this.items) into the Depot. IT appears to save OK but I can't seem to load the data back into the variable

    function MainAssistant(){
    this.hasinternet = 0;

    this.label = new Array(55)
    this.items = new Array(55)
    for (i = 0; i < 55; i++) {
    this.items[i] = new Array(200)
    }
    this.feeds = new Feeds()
    this.feeds.loadFeedDb();
    .....

    Then I have this at the bottom from of the same .jsjsjs


    var Feeds = Class.create ({
    loadFeedDb: function() {

    // Open the database to get the most recent feed list
    // DEBUG - replace is true to recreate db every time; false for release
    this.db = new Mojo.Depot(
    {name:"feedDB", version:1, estimatedSize:100000, replace: false},
    this.loadFeedDbOpenOk.bind(this),
    function(transaction, result) {
    Mojo.Log.warn("Can't open feed database: ", result.message);
    Mojo.Controller.errorDialog("Cant open Database")
    }
    );
    },

    // dbOpenOK - Callback for successful db request in setup. Get stored db or
    // fallback to using default list
    loadFeedDbOpenOk: function() {
    Mojo.Log.info("Database opened OK");
    this.db.get("feedList", this.loadFeedDbGetSuccess.bind(this), this.loadFeedDbUseDefault.bind(this));
    },

    // loadFeedDbGetSuccess - successful retrieval of db. Call
    // useDefaultList if the feedlist empty or null or initiate an update
    // to the list by calling updateFeedList.
    loadFeedDbGetSuccess: function(fl) {

    Mojo.Log.info("Database size: " , Object.values(fl).size());

    if (Object.toJSON(fl) == "{}" || fl === null) {
    Mojo.Log.warn("Retrieved empty or null list from DB");
    Mojo.Controller.errorDialog("Cant open table");

    } else {
    Mojo.Log.info("Retrieved feedlist from DB");
    this.items = fl;
    return f1;

    }


    },

    // storeFeedDb() - writes contents of Feeds.list array to feed database depot
    storeFeedDb: function(transport) {
    Mojo.Log.info("FeedList save started");
    this.db.add("feedList", transport,
    //function() {Mojo.Log.info("FeedList saved OK");},
    //Mojo.Controller.errorDialog("Saved LIST OK"),
    //Mojo.Controller.errorDialog(transport),

    this.storeFeedDBFailure);
    },


    // storeFeedDbFailure(transaction, result) - handles save failure, usually an out
    // of memory error
    storeFeedDbFailure: function(transaction,result) {
    Mojo.Log.warn("Database save error: ", result.message);
    /* if (result.message == News.dbOutOfMemoryError) {
    // replace contents of text bodies with the summaries and try again
    for (var i = 0; i < this.list.length; i++) {
    var stories = this.list[i].stories
    for (var j=0; j<stories.length; j++ ) {
    stories[j].text = stories[j].summary;
    }
    }
    }
    }
    */
    }

    });
  4. #4  
    Never mind. Started over from scratch and got it to work. Here's some working code for anyone to look at: OpenME saves the data and LoadME is called to load in the data

    MainAssistant.prototype.dbOpenME = function(){
    db = new Mojo.Depot({
    name: "feedDB",
    version: 1,
    estimatedSize: 750000,
    replace: false
    }, this.dbOpenOK.bind(this), this.dbOpenFail.bind(this));
    }

    MainAssistant.prototype.dbOpenOK = function() {
    this.feednumber=1;
    this.feedmultipler=this.feedUpdateInterval+1
    this.feedmultipler=this.feedmultipler*100000;
    this.feedmax = 15;
    while (this.feednumber <= this.feedmax) {
    this.dlc=this.feednumber*10
    db.add(this.feedmultipler , this.items[this.feedUpdateInterval][0], this.feednumber = this.feednumber , this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+0;
    db.add(this.ljc, this.items[this.feedUpdateInterval][this.dlc+0], this.feednumber = this.feednumber, this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+1;
    db.add(this.ljc, this.items[this.feedUpdateInterval][this.dlc+1], this.feednumber = this.feednumber, this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+2;
    db.add(this.ljc, this.items[this.feedUpdateInterval][this.dlc+2], this.feednumber = this.feednumber, this.dbfailure.bind(this))
    //this.ljc=this.feedmultipler+this.dlc+3;
    //db.add(this.ljc, 'test', this.feednumber = this.feednumber, this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+4;
    db.add(this.ljc, this.items[this.feedUpdateInterval][this.dlc+4], this.feednumber = this.feednumber, this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+5;
    db.add(this.ljc, this.items[this.feedUpdateInterval][this.dlc+5], this.feednumber = this.feednumber, this.dbfailure.bind(this))

    this.feednumber++;
    }
    //this.dbcont(this)
    };

    MainAssistant.prototype.dbcont = function(){
    this.feednumber=1;
    this.feedmultipler=this.feedUpdateInterval+1
    this.feedmultipler=this.feedmultipler*100000;
    this.feedmax = 15;
    //this.items = new Array(55)
    //for (i = 0; i < 55; i++) {
    // this.items[i] = new Array(200)
    // }
    while (this.feednumber <= this.feedmax) {
    this.dlc=this.feednumber*10
    db.get(this.feedmultipler, this.dbfailure.bind(this,'99',this.dlc), this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+0;
    db.get(this.ljc, this.dbfailure.bind(this,'0',this.dlc), this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+1;
    db.get(this.ljc, this.dbfailure.bind(this,'1',this.dlc), this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+2;
    db.get(this.ljc, this.dbfailure.bind(this,'2',this.dlc), this.dbfailure.bind(this))
    //this.ljc=this.feedmultipler+this.dlc+3;
    //db.get(this.ljc, this.dbfailure.bind(this,'3',this.dlc), this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+4;
    db.get(this.ljc, this.dbfailure.bind(this,'4',this.dlc), this.dbfailure.bind(this))
    this.ljc=this.feedmultipler+this.dlc+5;
    db.get(this.ljc, this.dbfailure.bind(this,'5',this.dlc), this.dbfailure.bind(this))

    this.feednumber++
    }



    }

    MainAssistant.prototype.dbfailure = function(re,jo,la){
    //event=re-this.feedmultipler-jo
    if (re == '99') { this.items[this.feedUpdateInterval][0] = la;
    //Mojo.Controller.errorDialog(this.items[this.feedUpdateInterval][0]);
    }
    if (re == '0') { this.items[this.feedUpdateInterval][jo] = la;
    //Mojo.Controller.errorDialog(this.items[this.feedUpdateInterval][10]);
    }
    if (re == '1') { this.items[this.feedUpdateInterval][jo+1] = la;
    //Mojo.Controller.errorDialog(this.items[this.feedUpdateInterval][jo+1]);
    }
    if (re == '2') { this.items[this.feedUpdateInterval][jo+2] = la;
    //Mojo.Controller.errorDialog(this.items[this.feedUpdateInterval][jo+2]);
    }
    //if (re == '3') { this.items[this.feedUpdateInterval][jo+3] = la;
    //Mojo.Controller.errorDialog(this.items[this.feedUpdateInterval][jo+3]);
    //}
    if (re == '4') { this.items[this.feedUpdateInterval][jo+4] = la;
    //Mojo.Controller.errorDialog(this.items[this.feedUpdateInterval][jo+4]);
    }
    if (re == '5') { this.items[this.feedUpdateInterval][jo+5] = la;
    //Mojo.Controller.errorDialog(this.items[this.feedUpdateInterval][jo+5]);
    }
    //Mojo.Controller.errorDialog(this.items[this.feedUpdateInterval][0]);
    if (re == '5' && jo == 150){
    if (this.refreshswitch == 1){this.refreshswitch =0;this.items[this.feedUpdateInterval][0]=0;}
    var dt=new Date()
    var lj = parseInt(dt.getTime())
    var yp = lj-parseInt(this.items[this.feedUpdateInterval][0])
    //Mojo.Controller.errorDialog(yp)
    var yp=yp/1000;
    if (!this.rfinterval[this.feedUpdateInterval] || this.rfinterval[this.feedUpdateInterval] == 0){this.rfinterval[this.feedUpdateInterval]=3;}
    if (yp < 3600*this.rfinterval[this.feedUpdateInterval])
    {
    var dt=new Date(this.items[this.feedUpdateInterval][0]);
    var dt=dt.toTimeString();
    var dt=dt.substr(0,8);
    this.controller.get('updated').update("POWERSAVER: DISC-Cached from "+dt+"");
    this.cacheswitch=2;
    this.handleAgree(this.feedUpdateInterval);
    }else{
    this.sendContinue(this.feedUpdateInterval);
    }
    }
    }


    MainAssistant.prototype.dbOpenFail = function(transaction, result) {
    Mojo.Log.warn("Can't open feed database (#", result.message, "). All feeds will be reloaded.");
    Mojo.Controller.errorDialog("Can't open feed database (#" + result.message + "). All feeds will be reloaded.");
    };


    MainAssistant.prototype.dbLoadME = function(){
    db = new Mojo.Depot({
    name: "feedDB",
    version: 1,
    estimatedSize: 750000,
    replace: false
    }, this.dbcont.bind(this), this.dbOpenFail.bind(this));
    }

Posting Permissions