Retour à la documentation
define(["dojo/_base/declare", "dijit/_WidgetBase", "dojox/widget/Toaster", "dojo/topic", "dojo/dom-geometry", "dojo/domReady!"],
function(declare, _WidgetBase, DojoToaster, topic, domGeom){
var Toaster = null;
Toaster = declare("spw.api.Toaster", [_WidgetBase], /** @lends spw.api.Toaster.prototype */{
toaster : null,
messageClass : null,
/**
* @constructs
* @classdesc Cette classe est un wrapper pour la classe "dojox.widget.Toaster". Elle surcharge ce widget dojo en ajoutant la possibilité de définir une position centrée. (center-up ; center-down ; center-right ; center-left).
*/
constructor : function(params){
this.inherited(arguments);
this.messageClass = 'toasterMsg';
this.toaster = new DojoToaster({
separator:"",
positionDirection:Toaster.positions.CENTER_DOWN,
messageTopic:"toasterTopic"
});
//Modified placeClip to accept "center" value
this.toaster._placeClip = this.placeClipWithCenter();
this.toaster.placeAt(params.targetElement);
},
/**
* Définit la position du toaster
* @param posDir la position à appliquer
*/
setPositionDirection: function(posDir){
if(posDir){
this.toaster.positionDirection = posDir;
}
},
/**
* Centre le toaster
*/
placeClipWithCenter : function () {
var _this = this;
return function(){
var _12 = domGeom.position(_this.targetElement);
var _13 = domGeom.getMarginBox(this.containerNode);
var _14 = this.clipNode.style;
_14.height = _13.h + "px";
_14.width = _13.w + "px";
var pd = this.positionDirection;
if(pd.match(/center/)){
_14.top = ((_12.h/2) - (_13.h/2)) + "px";
_14.left = ((_12.w/2) - (_13.w/2)) + "px";
}
if (pd.match(/^t/)) {
_14.top = _12.t + "px";
} else {
if (pd.match(/^b/)) {
_14.top = _12.h - _13.h - 2 + _12.t + "px";
}
}
if (pd.match(/^[tb]r-/)) {
_14.left = _12.w - _13.w - 1 - _12.l - 30 + "px";
} else {
if (pd.match(/^[tb]l-/)) {
_14.left = "0px";
}
}
_14.clip = "rect(0px, " + _13.w + "px, " + _13.h + "px, 0px)";
if (dojo.isIE) {
if (!this.bgIframe) {
this.clipNode.id = dijit.getUniqueId("dojox_widget_Toaster_clipNode");
this.bgIframe = new dijit.BackgroundIframe(this.clipNode);
}
var _15 = this.bgIframe.iframe;
if (_15) {
_15.style.display = "block";
}
}
};
},
/**
* Permet de créer un message d'erreur à l'intention de l'utilisateur
* @param title le titre du message d'erreur
* @param msg le message d'erreur
* @param duration la durée d'affichage du message en milliseconde
*/
notifyError: function(title, msg, duration){
topic.publish("toasterTopic", {
message : "<div class='toasterMsgWrapper'><div class='toasterMsg toasterError'><div class='toasterMsgTitle'>"+title+"</div><div>"+msg+"</div></div></div>",
type : 'warning',
duration : duration
});
},
/**
* Permet de créer un message d'avertissement à l'intention de l'utilisateur
* @param title le titre du message d'avertissement
* @param msg le message d'avertissement
* @param duration la durée d'affichage du message en milliseconde
*/
notifyWarning: function(title, msg, duration){
topic.publish("toasterTopic", {
message : "<div class='toasterMsgWrapper'><div class='toasterMsg toasterWarning'><div class='toasterMsgTitle'>"+title+"</div><div>"+msg+"</div></div></div>",
type : 'warning',
duration : duration
});
},
/**
* Permet de créer un message d'information à l'intention de l'utilisateur
* @param title le titre du message d'information
* @param msg le message d'information
* @param duration la durée d'affichage du message en milliseconde
*/
notifyInfo: function(title, msg, duration){
topic.publish("toasterTopic", {
message : "<div class='toasterMsgWrapper'><div class='toasterMsg toasterInfo'><div class='toasterMsgTitle'>"+title+"</div><div>"+msg+"</div></div></div>",
type : 'warning',
duration : duration
});
}
});
Toaster.positions = {
"CENTER_DOWN": "center-down",
"CENTER_LEFT": "center-left",
"CENTER_RIGHT": "center-right",
"CENTER_TOP": "center-top",
"BOTTOM_LEFT_DOWN": "bl-down",
"BOTTOM_LEFT_LEFT": "bl-left",
"BOTTOM_LEFT_RIGHT": "bl-right",
"BOTTOM_LEFT_TOP": "bl-top",
"BOTTOM_RIGHT_DOWN": "br-down",
"BOTTOM_RIGHT_LEFT": "br-left",
"BOTTOM_RIGHT_RIGHT": "br-right",
"BOTTOM_RIGHT_TOP": "br-top",
"TOP_LEFT_DOWN": "tl-down",
"TOP_LEFT_LEFT": "tl-left",
"TOP_LEFT_RIGHT": "tl-right",
"TOP_LEFT_TOP": "tl-top",
"TOP_RIGHT_DOWN": "tr-down",
"TOP_RIGHT_LEFT": "tr-left",
"TOP_RIGHT_RIGHT": "tr-right",
"TOP_RIGHT_TOP": "tr-top"
};
return Toaster;
});