dojo.provide("samples.ContentPaneController");

dojo.require("dijit._Widget");

/**
* A simple example controller that modifies the data shown in a content pane on an event.
*/
dojo.declare("samples.ContentPaneController", [dijit._Widget], {


contentPaneID: "", //The content pane ID that this controller controls.

message: "", //The message to append into the content file.

dataAttachPoint: "", //The attach point to tap the message and content into the template.

/**
* Function to refresh the view in the content pane.
*/
setMessage: function()
{
console.log("ContentPaneController: This is the affected view, widget ID: [" + this.id + "]. The view that it manages must be refreshed,");
console.log("ContentPaneController: Content pane: [" + dijit.byId(this.contentPaneID) + "] is affected.");

//Determine whether the insert point can be located.
var msgTag = dojo.byId(this.dataAttachPoint);
if (msgTag) {
this._setText();
}else{
//Content pane has not loaded.
//you must defer setting the
//messageuntil that the onLoad triggers.
var handle = null;
var self = this;
function deferredMessageSet(){
self._setText();
dojo.disconnect(handle);
}
handle = dojo.connect(dijit.byId(this.contentPaneID), "onLoad", deferredMessageSet);
}
},

_setText: function(){
var msgTag = dojo.byId(this.dataAttachPoint);
if(msgTag){
while(msgTag.firstChild){
msgTag.removeChild(msgTag.firstChild)
}
textNode = document.createTextNode(this.message)
msgTag.appendChild(textNode);
}
}
});