Retour à la documentation
/**
* @class spw.widgets.SpwHtmlContent
*/
define(["dojo/_base/declare", "spw/api/SpwBaseWidget", "dojo/html", "dojo/dom-construct", "dojo/dom-style",
"dojo/_base/lang", "spw/api/MessageManager", "dojo/cookie", "dijit/form/CheckBox"],
function(declare, SpwBaseWidget, html, domConstruct, domStyle, lang, MessageManager, cookie, CheckBox){
return declare("spw.widgets.SpwHtmlContent", [SpwBaseWidget], /** @lends spw.widgets.SpwHtmlContent.prototype */{
/* START from config */
htmlContent: null,
urlContent: null,
openAtStartupId: null,
openAtStartupText: null,
/* END from config */
_chkOpenAtStartup: null,
/**
* @constructs
* @param config
*/
constructor: function(){
},
postMixInProperties: function(){
this.inherited(arguments);
if(!this["class"]) {
this["class"] = "spwHtmlContentClass";
}
if(this.openAtStartupId) {
var widgetCookie = cookie(this.openAtStartupId);
this.set('activated', widgetCookie != "false");
}
},
buildRendering: function(){
this.inherited(arguments);
if(!this.htmlContent && !this.urlContent){
MessageManager.getInstance().notifyWarning("Le widget spw/widgets/SpwHtmlContent n'a pas été créé correctement car sa propriété \"htmlContent\" est manquante ou incorrecte.");
//Avoid activation
this.onActivate = function(){};
} else {
var container = this.domNode;
if(this.openAtStartupText) {
domStyle.set(this.domNode, {position:"relative", width: "100%", height: "100%"});
container = domConstruct.create("div", {"class": this["class"], style: "position:absolute;top:0;left:0;bottom:23px; right:0;overflow:auto;"}, this.domNode);
var footer = domConstruct.create("div", {
'class': 'spwHtmlContentBottom'
}, this.domNode);
this._chkOpenAtStartup = new CheckBox({
checked: cookie(this.openAtStartupId) != "false",
onClick: lang.hitch(this, this.openAtStartupClicked)
}, domConstruct.create("input", null, footer));
domConstruct.create("span", { innerHTML: this.openAtStartupText }, footer);
this["class"] = "";
}
if(this.htmlContent){
html.set(container, this.htmlContent, {parseContent:true, startup: true});
} else {
domStyle.set(this.domNode, {position:"relative", width: "100%", height: "100%", padding: 0, overflow: "hidden"});
domConstruct.create("iframe", {border:0, style:"border: none;width:100%; height:100%;", src: this.urlContent}, container);
}
}
},
openAtStartupClicked: function(e){
cookie(this.openAtStartupId, this._chkOpenAtStartup.checked ? "true" : "false", {expires: "Fri, 31 Dec 9999 23:59:59 GMT"});
}
});
});