Retour à la documentation
define(
[
"dojo/_base/declare","dijit/_WidgetBase", "dojox/layout/FloatingPane",
"dojo/_base/lang", "dojo/dom-construct", "dojo/dom-style",
"spw/api/SpwViewer", "dojo/dnd/move", "dojo/dom-class",
"dojo/dom-geometry", "spw/api/FloatingContainer",
"dijit/layout/ContentPane", "dijit/TooltipDialog",
"dijit/form/DropDownButton", "dijit/DropDownMenu",
"dojo/_base/array", "dojo/window", "dojo/on", "spw/api/SpwPopupItem"
],
function(declare, _WidgetBase, FloatingPane, lang, domConstruct, domStyle, SpwViewer,
move, domClass, domGeom, FloatingContainer, ContentPane, TooltipDialog, DropDownButton,
DropDownMenu, array, win, on, SpwPopupItem) {
return declare("spw.api.SpwBaseWidget", [_WidgetBase], /** @lends spw.api.SpwBaseWidget.prototype */{
/**
* Titre du widget
* @type String
*/
widgetTitle: null,
/**
* Détermine si le widget est activé ou non lors de chargement du GeoViewer
* @type Boolean
*/
activated: false,
/**
* Permet de définir l'ordre du widget au sein d'une même région (propriété "position").
* @type Number
*/
orderInRegion: 1,
/**
* Permet de définir si le widget sera celui sélectionné par défaut dans une même région contenant plusieurs widgets.
* @type Boolean
*/
defaultSelected: false,
/**
* Permet de définir le positionnement du widget. Les régions possibles sont : "none", "left", "right", "top", "bottom", "map", "panel", "panel-light", "floating", "toolbar", "left-top", "left-bottom", "right-top", "right-bottom", "top-left", "top-right", "bottom-left", "bottom-right", "center".
* @type String
*/
position: 'none',
/*if position == panel OR panel-light only*/
panelConfig:null,
//{
// style:{...}
// }
/**
* [pré-requis : position = panel OR panel-light]. Largeur de la fenêtre. Exemple : "300px" ou "50%".
* @type String
*/
width: "300px",
/**
* [pré-requis : position = panel OR panel-light]. Hauteur de la fenêtre. Exemple : "300px" ou "50%".
* @type String
*/
height: "250px",
/**
* [pré-requis : position = panel OR panel-light]. Distance par rapport au dessus du container. Exemple : "300px" ou "50%".
* @type String
*/
top: null,
/**
* [pré-requis : position = panel OR panel-light]. Distance par rapport à la gauche du container. Exemple : "300px" ou "50%".
* @type String
*/
left: null,
/**
* [pré-requis : position = panel OR panel-light]. Indique si la fenêtre est redimensionnable par l'utilisateur.
* @type Boolean
*/
resizable: false,
/**
* [pré-requis : position = panel OR panel-light]. Indique si la fenêtre est maximizable par l'utilisateur (prends toute la taille du container).
* @type Boolean
*/
maxable: false,
/**
* [pré-requis : position = panel OR panel-light]. Indique si la fenêtre est maximizée.
* @type Boolean
*/
maximized: false,
dockable: false,
/**
* [pré-requis : position = panel OR panel-light]. Indique si la fenêtre est "réactive". Dans ce cas, la fenêtre est légèrement transparente et devient opaque lorsque l'utilisateur passe son curseur au dessus.
* @type Boolean
*/
reactive: false,
/*END if position == panel OR panel-light only*/
/*if position == map only*/
/**
* [pré-requis : position = map]. Positionne le widget sur la carte.
* @property mapPosition.top {String} distance par rapport au dessus de la carte
* @property mapPosition.bottom {String} distance par rapport au bas de la carte
* @property mapPosition.left {String} distance par rapport à la gauche de la carte
* @property mapPosition.right {String} distance par rapport à la droite de la carte
* @type Object
*/
mapPosition: null,//exemple : { bottom: "", top: "", left: "", right: "" }
/*END if position == map only*/
/*if position == floating only*/
/**
* [pré-requis : position = floating]. Positionne le widget sur la carte.
* @property floatingConfig.open {String} distance par rapport au dessus de la carte
* @property floatingConfig.width {String} distance par rapport au dessus de la carte
* @property floatingConfig.minWidth {String} distance par rapport au dessus de la carte
* @property floatingConfig.pinned {String} distance par rapport au dessus de la carte
* @property floatingConfig.pinnable {String} distance par rapport au dessus de la carte
* @property floatingConfig.unpinnedCloseTimeout {String} distance par rapport au dessus de la carte
* @type Object
*/
floatingConfig: null,
/*END if position == floating only*/
/**
* Détermine si le widget a un bouton d'activation/désactivation dans la toolbar.
* @type Boolean
*/
inToolbar: false,
/*if inToolBar == true only*/
/**
* [pré-requis : inToolbar = true]. Détermine si la widget est uniquement activable et non désactivable.
* @type Boolean
*/
isOneShot: false,
/**
* [pré-requis : inToolbar = true]. Détermine si l'activation de ce widget désactive les autres widgets actif de la toolbar.
* @type Boolean
*/
solitary: false,
/**
* [pré-requis : inToolbar = true]. Classe css de l'icone à appliquer pour ce widget dans la toolbar (propriété background-image, dimension image 16px*16px).
* @type String
*/
iconClass: null,
/*END if inToolBar == true only*/
/** COMMON WIDGET CONFIG (widgets.json) **/
/**
* [pré-requis : position = panel OR panel-light]. Référence vers l'objet "fenêtre".
* @type dojox/layout/FloatingPane
*/
_panel: null,
/**
* Indique si la fenêtre contenant le widget s'ouvre lors de l'activation de ce dernier.
* @type Boolean
*/
openPanelOnActivate: true,
/**
* Indique si la le widget s'affiche lors de l'activation de ce dernier. Ne fonctionne pas avec la position "panel", voir openPanelOnActivate.
* Il est alors à la charge du widget de s'afficher via l'appel à la méthode "show()".
* @type Boolean
*/
showOnActivate: true,
/**
* Référence vers le bouton dans la toolbar.
* @type dijit/form/ToggleButton
*/
toolBarButton: null,
/**
* Index d'ordre d'affichage du bouton dans la toolbar.
* @type Number
*/
toolBarIndex: null,
/**
* Lien vers le répertoire "images" du widget. Ce dossier doit se trouver dans le même répertoire que le fichier du widget.
*/
imagesPath: null,
labels: null,
/**
* Indique si le widget peut être fermé par l'utilisateur.
* @type Boolean
*/
closable: true,
/**
* Référence vers l'instance unique du Viewer.
* @type spw.api.SpwViewer
*/
spwViewer: null,
/**
* Référence vers le loader du widget.
* @type dijit/layout/ContentPane
*/
_loadingPane: null,
/**
* Contenu de la bulle d'aide en HTML, null si aucune aide ne doit être affichée
* @type String
*/
helpContent: null,
/**
* Permet d'afficher le titre du widget (widgetTitle) dans la région (left ou right) si ce dernier est seul et si widgetTitle est défini.
* @type String
*/
showTitleInRegion: false,
takeMapPosition: false,
sizeLimit: '75vh',
_shown: false,
_floatingContainer: null,
baseOffset: 40,
minSpace: 10,
cptWidgetsAtSamePlace: 0,
/**
* @classdesc Classe de base de tous les widgets du GeoViewer. Il s'agit de la classe à hériter pour un nouveau widget.
* @constructs
*/
constructor: function(config) {
var bundle = this.declaredClass.substr(0, this.declaredClass.lastIndexOf(".")).replace(".", "/");
this.imagesPath = require.toUrl(bundle) + "/images/";
this.widgetId = this.declaredClass.split('.').pop() + 'Id';
},
/**
* Appelé après la création du widget
*/
postCreate: function(){
this.overrideForMultipleScreens();
this.inToolbar = this.inToolbar == null ? this.integrated : this.inToolbar;
this._displayHelp(this.domNode, {
hasCloseButton: this.position === 'panel' || this.position === 'panel-light' || this.position === 'floating' || this.hasCloseButton,
hasPadding: this.inToolbar
});
this._handleMobile();
if (this.inToolbar) {
domClass.add(this.domNode, 'integrated');
}
if (this.activated) {
this.onActivate(this.get('defaultSelected'));
}
if(this.position == "floating" && this.floatingConfig && this.floatingConfig.activateOnOpen === true){
this.displayInFloating();
}
},
_handleMobile: function() {
if (this.spwViewer == null || !this.spwViewer.mobile) {
return;
}
this.solitary = true;
this.spwViewer.addToSidePanel(this);
},
/**
* Appelé à la destruction du widget
*/
destroy: function() {
if (this.spwViewer && this.spwViewer.mobile) {
this.spwViewer.removeMobileWidget(this);
}
if (this._floatingContainer) {
this._floatingContainer.destroy();
}
this.inherited(arguments);
},
/**
* Méthode appelée à l'activation du widget. C'est dans cette méthode que s'effectue le positionnement du widget en fonction de son attribut "position".
* De plus, elle maintient l'état de la propriété "ativated" et gère l'affichage du bouton dans la toolbar si applicable.
* @param {Boolean} selected détermine si le widget doit être sélectionné si plusieurs widget sont présents dans la même région.
*/
onActivate: function(selected){
this.overrideForMultipleScreens();
var forceSelect = typeof(selected) == 'undefined' ? true : selected;
this.set("activated", true);
if (this.spwViewer.mobile) {
this._show(true);
return;
}
if(this.position == 'floating'){
// this._floatingContainer.set('open', true);
} else {
if(this.toolBarButton){
this.toolBarButton.set("checked", true);
}
if(this.showOnActivate){
this._show(forceSelect);
}
}
this.spwViewer.trackEvent(this.declaredClass,"onActivate", (this._activationDate = new Date()).toString());
},
/**
* Configuration particulière pour le mode double écran
*/
overrideForMultipleScreens: function(){
if(this.configMainScreen && this.spwViewer.hasSideWindow()){
for(var k in this.configMainScreen){
this["__" + k + "__"] = this[k];
this[k] = this.configMainScreen[k];
}
} else if(this.configSecondScreen && this.spwViewer.isSideWindow()){
for(var k in this.configSecondScreen){
this["__" + k + "__"] = this[k];
this[k] = this.configSecondScreen[k];
}
}
},
/**
* Débloque la fermeture du widget
*/
unblockClosing: function(unselect) {
if (this.oldCloseFuncs == null || this.oldCloseFuncs.length === 0) {
return;
}
this.oldCloseFuncs.reverse();
var parent = this.getParent(); // SpwPopupItem
var menu = lang.getObject('spwParentMenu', false, parent); // Premier dropdown
while (menu) {
if (menu._closePopup) {
menu._closePopup = this.oldCloseFuncs.pop();
menu._setSelected = function(selected) {
domClass.toggle(this.domNode, "dijitMenuItemSelected", selected);
};
if (unselect) {
menu._setSelected(false);
}
}
else if (menu.closeDropDown) {
menu.closeDropDown = this.oldCloseFuncs.pop();
}
parent = menu.getParent();
menu = lang.getObject('spwParentMenu', false, parent);
}
this.oldCloseFuncs = null;
},
/**
* Bloque la fermeture du widget
*/
blockClosing: function() {
var parent = this.getParent(); // SpwPopupItem
if (!(parent instanceof SpwPopupItem)) {
return;
}
var menu = lang.getObject('spwParentMenu', false, parent); // Premier dropdown
this.oldCloseFuncs = [];
while (menu) {
if (menu._closePopup) {
this.oldCloseFuncs.push(menu._closePopup);
menu._setSelected = function(selected) {
// domClass.toggle(this.domNode, "dijitMenuItemSelected", selected);
};
menu._closePopup = function() {};
}
else if (menu.closeDropDown) {
this.oldCloseFuncs.push(menu.closeDropDown);
menu.closeDropDown = function() {};
}
parent = menu.getParent();
menu = lang.getObject('spwParentMenu', false, parent);
}
},
_show: function(forceSelect){
if(!this._shown){
this._shown = true;
if (this.solitary) {
var tmpQuery = undefined;
if (this.solitary !== true) {
var tmpQuery = {solitary: this.solitary};
}
array.forEach(this.spwViewer.get('spwWidgetsManager').getWidgets(tmpQuery), lang.hitch(this, function(wgt) {
if (wgt == null || wgt.get == null) {
return;
}
if (wgt == this) {
return;
}
if (wgt._closeOnSolitary !== true) {
return;
}
if (wgt.get('activated')) {
if (wgt.unblockClosing) {
wgt.unblockClosing();
}
if (wgt.closeWidget) {
wgt.closeWidget();
}
wgt.onDeactivate();
}
}));
}
if (this.spwViewer.mobile && this.position && ['integrated', 'map', 'none', 'center'].indexOf(this.position) < 0) {
this.spwViewer.showMobileWidget(this);
return;
}
switch(this.position)
{
case "none":
break;
case "left":
this.spwViewer.showWidget(this, 'left', 'center', forceSelect);
break;
case "right":
this.spwViewer.showWidget(this, 'right', 'center', forceSelect);
break;
case "top":
this.spwViewer.showWidget(this, 'top', 'center', forceSelect);
break;
case "center":
this.spwViewer.showWidget(this, 'center', 'center', forceSelect);
break;
case "bottom":
this.spwViewer.showWidget(this, 'bottom', 'center', forceSelect);
break;
case "left-top":
this.spwViewer.showWidget(this, 'left', 'top', forceSelect);
break;
case "left-bottom":
this.spwViewer.showWidget(this, 'left', 'bottom', forceSelect);
break;
case "right-top":
this.spwViewer.showWidget(this, 'right', 'top', forceSelect);
break;
case "right-bottom":
this.spwViewer.showWidget(this, 'right', 'bottom', forceSelect);
break;
case "top-left":
this.spwViewer.showWidget(this, 'top', 'left', forceSelect);
break;
case "top-right":
this.spwViewer.showWidget(this, 'top', 'right', forceSelect);
break;
case "bottom-left":
this.spwViewer.showWidget(this, 'bottom', 'left', forceSelect);
break;
case "bottom-right":
this.spwViewer.showWidget(this, 'bottom', 'right', forceSelect);
break;
case "map":
domStyle.set(this.domNode, 'display', 'block');
this.spwViewer.addWidgetOnMap(this);
break;
case "panel":
case "panel-light":
this.displayInPanel();
break;
case "floating":
this.displayInFloating();
break;
case "toolbar":
domStyle.set(this.domNode, {display: "inline-block"});
this.spwViewer.addWidgetInToolbar(this);
break;
default:
this.position = 'panel-light';
this.displayInPanel();
}
}
},
adjustWidgetPositionIfPlacementNodeIsDefined: function(value, position) {
if (this.spwViewer.placementNode) {
var viewerContainer = document.getElementById(this.spwViewer.placementNode);
if (viewerContainer) {
var containerPosition = domGeom.position(viewerContainer);
var containerWidth = viewerContainer.offsetWidth;
var containerHeight = viewerContainer.offsetHeight;
var documentHeight = document.body.offsetHeight;
var documentWidth = document.body.offsetWidth;
var numberValue = value.substring(0, value.indexOf('px'));
var isPercentage = false;
if (value.indexOf('%') > -1) {
numberValue = value.substring(0, value.indexOf('%'));
isPercentage = true;
}
try {
numberValue = parseInt(numberValue);
if (isPercentage) {
switch (position) {
case 'top':
case 'bottom':
numberValue = ((containerHeight * numberValue) / 100);
break;
case 'left':
case 'right':
numberValue = ((containerWidth * numberValue) / 100);
break;
}
}
} catch (e) {
return value;
}
var adjustedNumberValue = value;
switch (position) {
case 'top':
adjustedNumberValue = containerPosition.y + numberValue;
break;
case 'left':
adjustedNumberValue = containerPosition.x + numberValue;
break;
case 'right':
adjustedNumberValue = (documentWidth - containerPosition.x - containerPosition.w) + numberValue;
break;
case 'bottom':
adjustedNumberValue = (documentHeight - containerPosition.y - containerPosition.h) + numberValue;
break;
}
}
return adjustedNumberValue + 'px';
}
return value;
},
/**
* Affiche le widget dans une fenêtre.
*/
displayInPanel: function() {
var isNew = false;
var vs = win.getBox();
if (this._panel) {
var dns = this._panel.domNode.style;
if (parseFloat(dns.height) >= vs.h || parseFloat(dns.width) >= vs.w) {
this.top = dns.top;
this.left = dns.left;
this.bottom = dns.bottom;
this.right = dns.right;
this._panel.destroy();
this._panel = null;
}
}
if(this._panel == null) {
isNew = true;
var panelDiv = domConstruct.create("div", {}, this.spwViewer.get('placementNode'));
//this._panel.placeAt(this.spwViewer.get('placementNode'));
var style = "position:absolute;visibility:hidden;width:"+this.width+";height:"+this.height+";";
if(!this.top && !this.bottom && !this.left && !this.right){
this.top = "150px";
this.left = "320px";
}
if(this.top) { style += "top:"+ this.adjustWidgetPositionIfPlacementNodeIsDefined(this.top, 'top')+";"}
if(this.bottom) { style += "bottom:"+this.adjustWidgetPositionIfPlacementNodeIsDefined(this.bottom, 'bottom')+";"}
if(this.left) { style += "left:"+this.adjustWidgetPositionIfPlacementNodeIsDefined(this.left, 'left')+";"}
if(this.right) { style += "right:"+this.adjustWidgetPositionIfPlacementNodeIsDefined(this.right, 'right')+";"}
if (this.top && parseFloat(this.top) > this.h) {
this.top = (this.h / 2) + 'px';
}
if (this.bottom && parseFloat(this.bottom) > this.h) {
this.bottom = (this.h / 2) + 'px';
}
if (this.left && parseFloat(this.left) > this.w) {
this.left = (this.w / 2) + 'px';
}
if (this.right && parseFloat(this.right) > this.w) {
this.right = (this.w / 2) + 'px';
}
this._panel = new FloatingPane({
title: this.widgetTitle ? this.widgetTitle : "",
resizable: this.resizable,
dockable: this.dockable,
dockTo: this.spwViewer.get('dock'),
maxable: this.maxable,
content: this,
doLayout: true,
style:style,
close: lang.hitch(this, this.onClose)
}, panelDiv);
if(this.height == "auto" || this.height == "initial"){
domClass.add(this._panel.domNode, "auto-height");
}
if(this.reactive){
domClass.add(this._panel.domNode, "reactive");
}
if(!this.closable){
domClass.add(this._panel.domNode, "unclosable");
}
if(this.position == "panel-light"){
domClass.add(this._panel.domNode, "light");
}
this.sizeLimit && domStyle.set(this.domNode, 'max-height', this.sizeLimit);
this.sizeLimit && domStyle.set(this.domNode, 'overflow', 'auto');
this._panel.moveable = new move.parentConstrainedMoveable(this._panel.domNode, { handle: this._panel.focusNode, area: "content", within: true });
this._panel.closeNode.title = "Fermer";
this._panel.maxNode.title = "Maximiser";
this._panel.restoreNode.title = "Restaurer";
this._panel.dockNode.title = "Minimiser";
//this._panel.startup();
}
//
// this._panel.focusNode.ondragenter = lang.hitch(this, function(evt) {
// console.log('ondragenter');
// });
// this._panel.focusNode.ondragstart = lang.hitch(this, function(evt) {
// console.log('ondragstart');
// });
// this._panel.focusNode.ondrag = lang.hitch(this, function(evt) {
// console.log('ondrag');
// });
// this._panel.focusNode.ondragover = lang.hitch(this, function(evt) {
// console.log('ondragover');
// });
//
// this._panel.resize = lang.hitch(this, function(args) {
// if (args && args['_firstCall'] == null) {
// var _resize = this._panel.resize;
// args['_firstCall'] = false;
// _resize(args);
// }
// var constraint = this._panel.moveable.constraints();
// var widgetPosition = domGeom.position(this._panel.domNode);
// var horizontal = widgetPosition.x + widgetPosition.w;
// var vertical = widgetPosition.y + widgetPosition.h;
// if (horizontal > constraint.w) {
// if (this.right) {
// domStyle.set(this._panel.domNode, 'left', '');
// domStyle.set(this._panel.domNode, 'right', this.right);
// }
// } else if (vertical > constraint.h) {
// console.log('widget must be verticaly repositioned');
// }
// });
// A panel widget can never be higher than its container
// var placementNode = this.spwViewer.getPlacementNode();
// var clientHeight = placementNode.clientHeight;
// this._panel.domNode.style.maxHeight = clientHeight + 'px';
if(this.openPanelOnActivate){
this.show();
if(isNew && this.maxable && this.maximized) {
this._panel.maximize();
}
}
if(this.panelConfig && this.panelConfig.style){
domStyle.set(this._panel.domNode, this.panelConfig.style);
}
},
/**
* Affiche le widget dans un conteneur flottant
*/
displayInFloating: function(){
if(!this._floatingContainer){
this._floatingContainer = new FloatingContainer(lang.mixin({
content:this,
containerTitle:this.widgetTitle
}, this.floatingConfig), domConstruct.create('div', {}, this.spwViewer.get('placementNode')));
}
},
_displayHelp: function(domNode, opts) {
if (this.helpContent == null) {
return;
}
opts = opts || {hasCloseButton: true};
var style = null;
if (!this.spwViewer.mobile) {
if (opts.hasCloseButton) {
style = 'top: 9px; right: 31px;';
}
else {
style= 'top: 9px; right: 10px;'
}
if (opts.hasPadding && this.widgetTitle) {
style = 'top: -5px; right: -5px;';
}
else if (opts.hasPadding) {
style = "top: -15px; right: -15px;";
}
}
if (/^(http|https|www)/.test(this.helpContent)) {
if (!/^(http|https)/.test(this.helpContent)) {
this.helpContent = 'http://' + this.helpContent;
}
this._helpButton = domConstruct.create('a', {
'class': 'helpIcon',
style: style,
href: this.helpContent,
target: '_blank'
}, domNode, 'last');
return;
}
var contentPaneHelp = new ContentPane({
content: this.helpContent
});
var toolTipHelp = new TooltipDialog({
content: contentPaneHelp
});
var helpButton = new DropDownButton({
dropDown: toolTipHelp,
'class': 'helpIcon',
style: style
});
domConstruct.place(helpButton.domNode, domNode, 'last');
this._helpButton = helpButton.domNode;
},
close: function(){},
/**
* Méthode callback appelée à la fermeture de la fenêtre. Par défaut, cache la fenêtre et appel la méthode deactivate() du widget.
*/
onClose: function(){
if(this._panel) this._panel.hide();
this.onDeactivate();
},
/**
* Méthode appelée à la désactivation du widget. Elle maintient l'état de la propriété "activated", synchronise le bouton dans la toolbar si applicable et retire le widget du viewer.
*/
onDeactivate: function(){
this.unblockClosing(true);
this.set("activated", false);
if(this.position == 'floating' && this._floatingContainer){
//this._floatingContainer.set('open', false);
} else {
if(this.toolBarButton){
this.toolBarButton.set("checked", false);
}
this.hide();
}
if(this._activationDate){
var interval = new Date().getTime() - this._activationDate.getTime();
this.spwViewer.trackEvent(this.declaredClass,"onDeactivate", (interval/1000) + " s.");
}
},
/**
* Permet de cacher la fenêtre contenant le widget sans pour autant la fermer et désactiver le widget.
*/
hide: function(){
this.cptWidgetsAtSamePlace = 0;
if(this._shown){
this._shown = false;
if (this._panel && /panel/.test(this.position)) {
this._panel.hide();
} else if(this.closable && this.get('position') != 'map'){
if (this.domNode && !(this.getParent() instanceof DropDownMenu)) {
this.spwViewer.hideWidget(this);
}
} else if(this.get('position') == 'map' && this.domNode) {
domStyle.set(this.domNode, 'display', 'none');
}
}
},
/**
* Montre la fenêtre contenant le widget et l'amène au premier plan.
* @param {Boolean} forceSelect détermine si le widget doit être sélectionné si plusieurs widget sont présents dans la même région.
*/
show:function(forceSelect){
if(this._panel) {
this._shown = true;
var widgets = this.spwViewer.get('spwWidgetsManager').getWidgets({
activated: true
});
var newTop = null;
var newLeft = null;
var multiplier = 1;
var vs = win.getBox();
var thisTop = parseFloat(domStyle.get(this._panel.domNode, 'top'));
var thisLeft = parseFloat(domStyle.get(this._panel.domNode, 'left'));
if (thisTop === 0) {
var bottom = parseFloat(this.bottom);
var h = parseFloat(this.height);
if (bottom && !isNaN(h)) {
thisTop = vs.h - h - bottom;
}
}
if (thisLeft === 0) {
var right = parseFloat(this.right);
var w = parseFloat(this.width);
if (right && !isNaN(w)) {
thisLeft = vs.w - w - right;
}
}
array.some(widgets, lang.hitch(this, function(w) {
if (w.widgetId === this.widgetId) {
return false;
}
if (['panel', 'panel-light'].indexOf(w.position) < 0) {
return false;
}
var wTop = parseFloat(domStyle.get(w._panel.domNode, 'top'));
var wLeft = parseFloat(domStyle.get(w._panel.domNode, 'left'));
var cmpTop = newTop || thisTop;
var cmpLeft = newLeft || thisLeft;
if (Math.abs(cmpTop - wTop) < this.minSpace && Math.abs(cmpLeft - wLeft) < this.minSpace) {
w.cptWidgetsAtSamePlace = (w.cptWidgetsAtSamePlace ? w.cptWidgetsAtSamePlace + 1 : 1);
multiplier = w.cptWidgetsAtSamePlace;
newTop = cmpTop + (multiplier * this.baseOffset) + (cmpTop - wTop);
var h = parseFloat(this.height);
if (!isNaN(h) && newTop + h > vs.h) {
newTop = cmpTop - (multiplier * this.baseOffset) + (cmpTop - wTop);
}
newLeft = cmpLeft + (multiplier * this.baseOffset) + (cmpLeft - wLeft);
var w = parseFloat(this.width);
if (!isNaN(w) && newLeft + w > vs.w) {
newLeft = cmpLeft - (multiplier * this.baseOffset) + (cmpLeft - wLeft);
}
return true;
}
return false;
}));
if (newTop) {
domStyle.set(this._panel.domNode, 'top', newTop + 'px');
}
if (newLeft) {
domStyle.set(this._panel.domNode, 'left', newLeft + 'px');
}
this._panel.show();
this._panel.startup();
this._panel.bringToTop();
} else {
this._show(forceSelect);
}
},
_setPositionAttr: function(value) {
if (this._panel) {
this._panel.destroy();
this._panel = null;
}
this.position = value;
},
_setWidgetTitleAttr: function(value) {
this.widgetTitle = value;
if(this._panel){
this._panel.set('title', value);
}
if(this.toolBarButton){
this.toolBarButton.set('label', value);
}
},
_setIconClassAttr: function(value) {
this.iconClass = value;
if(this.toolBarButton){
this.toolBarButton.set("iconClass", value);
}
},
/**
* Crée le contentPane contenant le loader du widget.
* @private
*/
_createLoadingPane: function(){
this._loadingPane = dijit.layout.ContentPane({style:"position:absolute;top:0px;left:0;bottom:0;right:0;"});
this._loadingPane.set("content","<div style='position:absolute;top:0px;left:0;bottom:0;right:0;background-color:black;opacity:0.05;filter: alpha(opacity = 5);'></div><table style='width:100%;height:100%;text-align:center;'><tr style='height:auto'><td></td></tr><tr><td><img src='"+this.get('imagesPath')+"/ajax-loader.gif'></td></tr><tr style='height:auto'><td></td></tr></table>");
this._loadingPane.startup();
},
/**
* Affiche le loader du widget.
*/
showLoading : function(node){
if(this._loadingPane == null){
this._createLoadingPane();
}
if (node == null) {
domConstruct.place(this._loadingPane.domNode,this.domNode);
}
else {
domConstruct.place(this._loadingPane.domNode, node);
}
domStyle.set(this._loadingPane.domNode,"display","");
},
/**
* Cache le loader du widget.
*/
hideLoading : function(){
if(this._loadingPane != null){
domStyle.set(this._loadingPane.domNode,"display","none");
}
},
_setInToolbarAttr: function(value){
this.inToolbar = value;
if(!value && this.toolBarButton){
this.toolBarButton.domNode.style.display = "none";
} else if(this.toolBarButton){
this.toolBarButton.domNode.style.display = "";
}
}
});
});