Archive for May, 2010


Damn sometimes… Sometimes we have bugs that seem just impossible. Well I’ve just had one, I solved I just can’t resist posting it here. Guys I have to tell you it’s the most stupid bug I’ve sold, I laugh so much when I understood what happend. Ahhh life’s funny sometimes 😉

Here it is.

I’m querying a JsonRestStore that sends back this data :

[{“id”:”15″,”item_id”:”1″,”item_type”:”lunches”,”user_id”:”17″,”object”:”T”,”date”:”0000-00-00″,”child_of”:”0″,”TG”:””,”TD”:”Yes”,”TP”:””,”TA”:”Connect”,”TAD”:””,”D”:”0000-00-00″,”NC”:””},{“id”:”1″,”item_id”:”1″,”item_type”:”opportunities”,”user_id”:”17″,”object”:”T”,”date”:”2010-02-08″,”child_of”:”0″,”TG”:”re”,”TD”:”Yes”,”TP”:”2″,”TA”:”Older”,”TAD”:”v”,”D”:”0000-00-00″,”NC”:””},
{“id”:”3″,”item_id”:”1″,”item_type”:”opportunities”,”user_id”:”17″,”object”:”T”,”date”:”2010-02-08″,”child_of”:”0″,”TG”:”re”,”TD”:”Yes”,”TP”:”2″,”TA”:”Older”,”TAD”:”v”,”D”:”0000-00-00″,”NC”:””},
{“id”:”2″,”item_id”:”1″,”item_type”:”opportunities”,”user_id”:”17″,”object”:”T”,”date”:”2010-02-08″,”child_of”:”0″,”TG”:”re”,”TD”:”Yes”,”TP”:”2″,”TA”:”Older”,”TAD”:”v”,”D”:”0000-00-00″,”NC”:””}]

Well I removed the content of the data but that’s of no importance. Note that I had about 25 records sent from the JsonRestStore that looked pretty much the same except one field : item_type was for item 1 “lunches” and for all the rest “opportunities”.

Then my code, inside a dojo widget I’m fetching the JsonRestStore and getting the items. Except I want to order items using the field item_type.


// Fetch the objects
this.store.fetch({

query: {object:"Task"},
sort: sortKeys, // Order by... date DESC
onComplete: dojo.hitch(this, function(items,request){

opportunities="";
lunches="";

// Now format each element
for (var i = 0; i < items.length; i++){

var item=items[i];

if(item.item_type="lunches"){

lunches += '

';
//console.log(item.item_type + item.id);
}
else if (item.item_type="opportunities"){

lunches += '

';
}
}

// Add titles to the elements
if(lunches !=""){

lunches = "

Lunches

" + lunches ;
}
if(opportunities !=""){

opportunities = "

Opportunities

" + opportunities ;
}

this.TaskList.innerHTML = lunches + opportunities ;

dojo.parser.parse(this.domNode);

Guess what happend… All my items went on the lunches category. But WHY WHY WHY ???
You’ll find out I’m sure, and laugh a lot, hopefully 😉

Advertisements

Still working on my Tree, irc’s magic chamber (#dojo) gave me a solution I tend to forget from times to times related to extending some of dojo’s functions (credits dmachi, thanks man 😉

Here it is :

myStore = new dojox.data.JsonRestStore({target:"/objects/", labelAttribute:"Task_Action"});

myModel = new dijit.tree.ForestStoreModel({
store: myStore,
deferItemLoadingUntilExpand: true,
query: {object:'Task'},
rootLabel:'test test'

});

dojo.extend(dijit.Tree, {_createTreeNode: function(args){

console.log("this is cool stuff");
console.log("_createTreeNode: ", args);
return new dijit._TreeNode(args);

}}
);

myTree = new dijit.Tree({
id: "myTree",
model: myModel,
persist: false,
label:'test'
});

dojo.byId("container").appendChild(myTree.domNode);
myTree.startup();

Here’s a good idea : make a new widget that will display charts related to a page. I had a few problems building this since the template must have set some parameters like style, width and height otherwise your chart wont’ display and you’ll get a wierd error. I’ll give you a very simple example on how to start building this idea.

Here’s my template :

Statistics


Note that the style=”width …” *must* be there otherwise the chart won’t display.
Let’s continue …

dojo.provide("mywidget.stats");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dojox.charting.Chart2D");

dojo.declare("mywidget.stats",
[dijit._Widget,dijit._Templated],
{

widgetsInTemplate:true,

templatePath: dojo.moduleUrl("mywidget","templates/Stats.html"),

postMixInProperties: function(){

},

postCreate: function(){

var chart1 = new dojox.charting.Chart2D("test");
chart1.addPlot("default", {type: "Pie"});
chart1.addAxis("x");
chart1.addAxis("y", {vertical: true});
chart1.addSeries("Series 1", [1, 2, 2, 3, 4, 5, 5, 7]);
chart1.render();

},

startup: function(){

},

}
);

Well nothing big here but it works 😉
I’m trying actually to develop multiple statitics that I’ll probably end putting in tabs. We’ll see, maybe later if I have good results I’ll post somehting here 😉

See ya guys !