Mele,
Here is my tested solution:
define([
'dojo/_base/declare',
'jimu/BaseWidget',
'jimu/PanelManager',
'jimu/dijit/Message',
'dojo/aspect',
'dojo/_base/lang'
],
function(
declare,
BaseWidget,
PanelManager,
Message,
aspect,
lang
) {
//To create a widget, you need to derive from BaseWidget.
return declare([BaseWidget], {
// Custom widget code goes here
baseClass: 'jimu-widget-customwidget',
//this property is set by the framework when widget is loaded.
name: 'CheckClose',
label: 'Check Before Close',
editor: null,
//methods to communication with app container:
postCreate: function() {
this.inherited(arguments);
console.log('postCreate');
},
startup: function() {
this.inherited(arguments);
console.log('startup');
aspect.before(this, 'onClose', function(){
if (!this.editor){
var qMessage = new Message({
type: 'question',
titleLabel: 'Problem',
message: 'Must set station/shift',
buttons: [{
label: 'OK',
onClick: lang.hitch(this, lang.hitch(this, function () {
qMessage.close();
var pm = PanelManager.getInstance();
pm.openPanel(this.id + '_panel');
}))
}]
});
}
});
},
onOpen: function(){
console.log('onOpen');
},
onClose: function(){
console.log('onClose');
}
});
});