« MediaWiki:Gadget-dosage-calculator.js » : différence entre les versions

De Wikimedica
(Trying Process dialog...)
(Added Radio Input for Units)
Ligne 103 : Ligne 103 :
} );
} );
// HorizontalLayout
// Initialize Medication Label
this.content = new OO.ui.HorizontalLayout( {
this.medicationLabel =  new OO.ui.LabelWidget( { label: 'Amoxiciline 90 mg/kg/j' } ),
// Initialize Horizontal Layout
this.horizontalLayout = new OO.ui.HorizontalLayout( {
} );
} );
// Initialize Weight Input Field Set
this.weightInputFieldset = new OO.ui.FieldsetLayout();
this.weightInputFieldset = new OO.ui.FieldsetLayout();
 
// Initialize Weight Input
this.weightInput = new OO.ui.TextInputWidget();
this.weightInput = new OO.ui.TextInputWidget();
 
// Set Weight Input Field
this.weightInputField = new OO.ui.FieldLayout( this.weightInput, {  
this.weightInputField = new OO.ui.FieldLayout( this.weightInput, {  
label: 'Poids du patient:',  
label: 'Poids du patient:',  
align: 'left'  
align: 'left'  
} );
} );
 
// Add Weight Input Field to Weight Input Field Set
this.weightInputFieldset.addItems( [ this.weightInputField ] );
this.weightInputFieldset.addItems( [ this.weightInputField ] );
this.unitRadioInput = new OO.ui.LabelWidget( { label: 'RADIO UNIT' } ),
// Initialize Unit Radio Input
this.optionKg = new OO.ui.RadioOptionWidget( {
        data: 'kg',
        label: 'Kg'
    } ),
    this.optionLbs = new OO.ui.RadioOptionWidget( {
        data: 'lbs',
        label: 'Lbs'
    } );
    this.unitRadioInput = new OO.ui.RadioSelectWidget( {
        items: [ this.optionKg, this.optionLbs ]
    } );
// Select 'option Kg' using the RadioSelectWidget's selectItem() method.
this.unitRadioInput.selectItem( this.optionKg );
// Set Elements to Horizontal Layout
this.horizontalLayout.addItems([this.weightInputFieldset, this.unitRadioInput]);
this.content.addItems([this.weightInputFieldset, this.unitRadioInput]);
// Add Medication Label and Horizontal Input to Panel
this.panel.$element.append( this.content.$element );
this.panel.$element.append( this.medicationLabel.$element );
this.panel.$element.append( this.horizontalLayout.$element );
// Add Panel to Body
this.$body.append( this.panel.$element );
this.$body.append( this.panel.$element );



Version du 12 janvier 2023 à 23:24

/* 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 
	} );
	
	// Initialize Medication Label
	this.medicationLabel =  new OO.ui.LabelWidget( { label: 'Amoxiciline 90 mg/kg/j' } ),
	
	// Initialize Horizontal Layout
	this.horizontalLayout = new OO.ui.HorizontalLayout( {
	} );
	
	// Initialize Weight Input Field Set
	this.weightInputFieldset = new OO.ui.FieldsetLayout();
	// Initialize Weight Input
	this.weightInput = new OO.ui.TextInputWidget();
	// Set Weight Input Field
	this.weightInputField = new OO.ui.FieldLayout( this.weightInput, { 
		label: 'Poids du patient:', 
		align: 'left' 
	} );
	// Add Weight Input Field to Weight Input Field Set
	this.weightInputFieldset.addItems( [ this.weightInputField ] );
	
	// Initialize Unit Radio Input
	this.optionKg = new OO.ui.RadioOptionWidget( {
	        data: 'kg',
	        label: 'Kg'
	    } ),
	    this.optionLbs = new OO.ui.RadioOptionWidget( {
	        data: 'lbs',
	        label: 'Lbs'
	    } );
	    this.unitRadioInput = new OO.ui.RadioSelectWidget( {
	        items: [ this.optionKg, this.optionLbs ]
	    } );
	
	// Select 'option Kg' using the RadioSelectWidget's selectItem() method.
	this.unitRadioInput.selectItem( this.optionKg );
	
	
	// Set Elements to Horizontal Layout
	this.horizontalLayout.addItems([this.weightInputFieldset, this.unitRadioInput]);
	
	// Add Medication Label and Horizontal Input to Panel
	this.panel.$element.append( this.medicationLabel.$element );
	this.panel.$element.append( this.horizontalLayout.$element );
	// Add Panel to Body
	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 );