Discussion (7)0
Log in or sign up to continue

Hi Pravin,

When I checked out the documentation, it said I would have to use the dataBag API. Do you know if there is any place that has a couple of lines of Cache related code using the dataBag API? If the dataBag API is completely outside of Cache, is this API relevantly explored in Ruby or Chef documentation?

Thanks,

Bob Harris

Hi Bob,

The databag API is what the Zen MVC uses internally, you shouldn't have to worry about it.

Here's some sample code modifying the ZENTest.SVGSpriteTest sample page to display data from a datacontroller:

ClientMethod initializeCanvas() [ Language = javascript ]
{
var canvas zenPage.getComponentById('svgCanvas');
if ((!canvas) || !canvas.document) {
// ensure we don't execute code before the SVG document has been fully loaded
setTimeout('zenPage.initializeCanvas();',10);
return;
}

var inspector this.getComponentById('objectInspector');
inspector.setCurrObject(canvas);

var controller zenPage.getComponentById('spriteController');
controller.setModelId(1);
// create initial set of sprites & connectors
var sprite new Array();

sprite[0] canvas.createSprite('sprite',200,100);
sprite[0].setProperty('onclick','zenPage.selectSprite(zenThis);');
sprite[0].setProperty('caption', controller.getDataByName("sprite1"));

sprite[1] canvas.createSprite('sprite',200,300);
sprite[1].setProperty('caption', controller.getDataByName("sprite2"));
sprite[2] canvas.createSprite('sprite',400,100);
sprite[2].setProperty('caption', controller.getDataByName("sprite3"));
sprite[3] canvas.createSprite('sprite',400,300);
sprite[3].setProperty('caption', controller.getDataByName("sprite4"));

var connect canvas.createConnector('connector');
connect.addOutput(sprite[0],1);
//connect.addOutput(sprite[2],1);
connect.addInput(sprite[1],0);
//connect.addInput(sprite[3],0);

// turn off layout; turn on edit mode
canvas.setProperty('layout','');
canvas.setProperty('editMode','drag');
}

Hi Bob,

For this to work you also need to define the data controller element in the page contents. For example, you could add the following element to the XData:

<dataController id="spriteController" modelClass="User.SpriteDataModel" modelId="1"/> 

If you have a data model class defined called "User.SpriteDataModel".

I recommend taking a look at the "ZENMVC.MVCForm" class in the SAMPLES namespace if you'd like an example of defining a data controller and data model.

Hi Pravin,

Thanks for your help.

I got the code working and can print out a single line caption on a sprite.

My last question: Do you happen to know if it is possible to print out more than one line of text on a sprite? I've been looking into displaying multiple lines of text in a <svgFrame> and multiple data fields, but I'm not sure how extensively Cache supports the <text> tab from the svg specifications in Zen, at this time, even in a custom component.

I know how to reformat text to fit a given space, but getting the <svgFrame> to auto-expand...if you happen to already know of some ways to do this, that would be great, but you've already been quite helpful, so thanks.

Best,

Bob Harris