wolf.ui extension add capacity for pop-up dialogs in an easy way.
the extensionadds the next three dialogs functions to wolf.js object:
All dialogs on the library uses a very similar way of usage:
wolf.dialog(<app-element>,<modal>,<dialog-data>,[buttons-definition],[controller],[creation-callback(<dialog-instance>)],[close-callback(<button-pressed>)]);
This gives a lot of ways to define a dialog and the associated logic.
The easyest way to call a dialog is creating a HTML with all the content of the dialog, and call the wolf.dialog pasing the url string in the dialog-data parameter.
wolf.dialog(element.getApplication(),true,"dialogs/car-editor.html",{
onClose:{text:"close",cancel:true},
onSave:{text:"save"}
},{
onSave:(element,event,dialog){
saveData(getDataFrom(dialog)); //saveData and getDataFrom are not wolf nor wolf.ui framework methods.
dialog.close();
}
});
this can be defined also without controller:
wolf.dialog(element.getApplication(),true,"dialogs/car-editor.html",{
onClose:{text:"close"},
onSave:{
text:"save",
click:(element,event,dialog) {
saveData(getDataFrom(dialog)); //saveData and getDataFrom are not wolf.js nor wolf.ui framework methods.
dialog.close();
}
}
});
When defining a dialog controller, all events defined with event:... inside the HTML are handled by the dialog controller.
Intended to use simple text messages without the need of create an HTML page or advanced wolf.js UI template data.
wolf.messageDialog(element.getApplication(),true,"Sure to delete car information?",{
onNo:{text:"no",cancel:true},
onYes:{
text:"yes",
click:(element,event,dialog) {
deleteCar(id); //deleteCar and id parameter are not wolf.js nor wolf.ui framework methods.
dialog.close();
}
})
Or using the result callback the dialog gets closed automatically.
wolf.messageDialog(element.getApplication(),true,"Sure to delete car information?",{
onNo:{text:"no",cancel:true},
onYes:{text:"yes"},null,null,button=>{if (button=="onYes") deleteCar(id)});
If no buttons are defined a simple button with a cross icon named close will be defined by default.
wolf.messageDialog(element.getApplication(),true,"Car information deleted");
UI dialog is similar to the HTML variant wolf.dialog but passing wolf.js UI template information to the dialog.data, meant to be used as advanced dialog content definition.
The dialog button definition is an object that define button id, content, function and stylish, can be defined in object notation as:
{
<button-id>:{
text:<text-in-the-button>,
icon:<icon-of-the-button>,
cancel:<boolean-to-show-cancel-stlye>,
default:<boolean-to-show-default-style>,
click:<function-definition>
}
}
Multiple buttons can be defined in the definition object.