MediaWiki:Gadget-dosage-calculator.js
Note : après avoir enregistré vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
/* This modal dialog displays a tool for drug dosage calculations. */
console.log("Loading dosage calculator ...");
/*
@param string dose (ex: 90, 1,5)
@param string unit (ex: mg, mcg)
@param string frequency (ex: DIE, BID, q12h)
*/
drugKgDosageCalculator = function(dose, unit, frequency)
{
// Lazy load the following librairies
$.when( mw.loader.using( [ 'mediawiki.api', 'oojs-ui-core', 'oojs-ui-windows' ] )).then( function() {
var dialog = new OO.ui.MessageDialog();
// Create and append a window manager.
var windowManager = new OO.ui.WindowManager();
$( 'body' ).append( windowManager.$element );
// Add the dialog to the window manager.
windowManager.addWindows( [ dialog ] );
dialog.getActionProcess = function(action) // Set the cookie and close the dialog when the user clicks the button.
{
document.cookie = "wikimedica-skip-welcome-message=1; expires=Thu, 18 Dec 2030 12:00:00 UTC; path=/";
this.close();
return OO.ui.MessageDialog.super.prototype.getActionProcess.call( this, action );
}
// Configure the message dialog when it is opened with the window manager's openWindow() method.
windowManager.openWindow( dialog, {
title: new OO.ui.HtmlSnippet('Calculateur de dose'),
message: new OO.ui.HtmlSnippet('Amoxiciline 90 mg/kg/j'),
verbose: true,
size: 'medium',
actions: [
{
action: 'accept',
label: "Fermer le calculateur",
flags: 'primary'
}
]
});
});
};
/********************************** TEST **********************************/
// Example: Creating and opening a process dialog window.
// Subclass DosageDialog.
function DosageDialog( config ) {
DosageDialog.super.call( this, config );
}
OO.inheritClass( DosageDialog, OO.ui.ProcessDialog );
// Specify a name for .addWindows()
DosageDialog.static.name = 'dosageDialog';
// Specify a static title and actions.
DosageDialog.static.title = 'Calculateur de dose';
DosageDialog.static.actions = [
{
action: 'save',
label: 'Fermer',
flags: 'primary'
}
];
// Use the initialize() method to add content to the dialog's $body,
// to initialize widgets, and to set up event handlers.
/*DosageDialog.prototype.initialize = function () {
DosageDialog.super.prototype.initialize.apply( this, arguments );
this.content = new OO.ui.PanelLayout( {
padded: true,
expanded: false
} );
this.content.$element.append( '<p>Amoxiciline 90 mg/kg/j</p>' );
this.$body.append( this.content.$element );
};
*/
DosageDialog.prototype.initialize = function () {
DosageDialog.super.prototype.initialize.call( this );
this.panel = new OO.ui.PanelLayout( {
padded: true,
expanded: true
} );
// HorizontalLayout
this.content = new OO.ui.HorizontalLayout( {
} );
this.weightInputFieldset = new OO.ui.FieldsetLayout();
this.weightInput = new OO.ui.TextInputWidget();
this.weightInputField = new OO.ui.FieldLayout( this.weightInput, {
label: 'Poids du patient:',
align: 'left'
} );
this.weightInputFieldset.addItems( [ this.weightInputField ] );
this.unitRadioInput = new OO.ui.LabelWidget( { label: 'RADIO UNIT' } ),
this.content.addItems([this.weightInputFieldset, this.unitRadioInput]);
this.panel.$element.append( this.content.$element );
this.$body.append( this.panel.$element );
//this.urlInput.connect( this, { 'change': 'onUrlInputChange' } );
};
// Use the getActionProcess() method to specify a process to handle the
// actions (for the 'save' action, in this example).
DosageDialog.prototype.getActionProcess = function ( action ) {
var dialog = this;
if ( action ) {
return new OO.ui.Process( function () {
dialog.close( {
action: action
} );
} );
}
// Fallback to parent handler.
return DosageDialog.super.prototype.getActionProcess.call( this, action );
};
/*
// Get dialog height.
DosageDialog.prototype.getBodyHeight = function () {
return this.content.$element.outerHeight( true );
};
*/
// Create and append the window manager.
var windowManager = new OO.ui.WindowManager();
$( document.body ).append( windowManager.$element );
// Create a new dialog window.
var dosageDialog = new DosageDialog({
size: 'big'
});
// Add windows to window manager using the addWindows() method.
windowManager.addWindows( [ dosageDialog ] );
// Open the window.
windowManager.openWindow( dosageDialog );