module/alpha.js
/**
 * Display the entity template dialog.
 *
 * Helper function to display a dialog if there are multiple template
 * types defined for the entity type.
 * TODO: Refactor in 0.7.x to play more nicely with the
 * Entity.createDialog method
 *1
 * @param {EntityCollection} entityType - The sidebar tab
 * @param {MouseEvent} event - Triggering event
 */
Display the entity template dialog.
Helper function to display a dialog if there are multiple template
types defined for the entity type.
TODO: Refactor in 0.7.x to play more nicely with the
Entity.createDialog method
1
@param {EntityCollection} entityType - The sidebar tab
@param {MouseEvent} event - Triggering event
Display the entity template dialog . Helper function to display a dialog if there are multiple template types defined for the entity type . TODO : Refactor in 0 . 7 . x to play more nicely with the Entity . createDialog method 1 @param { EntityCollection } entityType - The sidebar tab @param { MouseEvent } event - Triggering event
async function _simpleDirectoryTemplates(collection, event)
{
    const entityCollection = collection.tabName === "actors" ?
          game.actors : game.items;
    const cls = collection.tabName === "actors" ? Actor : Item;
    let templates = entityCollection.filter(
        a => a.getFlag("alpha", "isTemplate"));
    let ent = game.i18n.localize(cls.config.label);
    let type = collection.tabName === "actors" ? 'character' : 'item';
    let createData = {
        name: `${game.i18n.localize("SIMPLE.New")} ${ent}`,
        type: type,
        folder: event.currentTarget.dataset.folder
    };
    if ( !templates.length ) return cls.create(createData, {renderSheet: true});
    let types = [{
        value: null,
        label: game.i18n.localize("SIMPLE.NoTemplate")
    }].concat(templates.map(a => { return { value: a.id, label: a.name } }));
    const templateData = {upper: ent, lower: ent.toLowerCase(), types: types};
    const dlg = await renderTemplate(
        `systems/alpha/templates/sidebar/entity-create.html`,
        templateData);
    return Dialog.confirm({
        title: `${game.i18n.localize("SIMPLE.Create")} ${createData.name}`,
        content: dlg,
        yes: html => {
            const form = html[0].querySelector("form");
            const template = entityCollection.get(form.type.value);
            if ( template ) {
                createData = mergeObject(template.data, createData,
                                         {inplace: false});
                createData.type = template.data.type;
                delete createData.flags.alpha.isTemplate;
            }
            createData.name = form.name.value;
            return cls.create(createData, {renderSheet: true});
        },
        no: () => {},
        defaultYes: false
    });
}
async function _simpleDirectoryTemplates ( collection , event ) { const entityCollection = collection . tabName === "actors" ? game . actors : game . items ; const cls = collection . tabName === "actors" ? Actor : Item ; let templates = entityCollection . filter ( a => a . getFlag ( "alpha" , "isTemplate" ) ) ; let ent = game . i18n . localize ( cls . config . label ) ; let type = collection . tabName === "actors" ? 'character' : 'item' ; let createData = { name : ` ${ game . i18n . localize ( "SIMPLE.New" ) } ${ ent } ` , type : type , folder : event . currentTarget . dataset . folder } ; if ( ! templates . length ) return cls . create ( createData , { renderSheet : true } ) ; let types = [ { value : null , label : game . i18n . localize ( "SIMPLE.NoTemplate" ) } ] . concat ( templates . map ( a => { return { value : a . id , label : a . name } } ) ) ; const templateData = { upper : ent , lower : ent . toLowerCase ( ) , types : types } ; const dlg = await renderTemplate ( ` ` , templateData ) ; return Dialog . confirm ( { title : ` ${ game . i18n . localize ( "SIMPLE.Create" ) } ${ createData . name } ` , content : dlg , yes : html => { const form = html [ 0 ] . querySelector ( "form" ) ; const template = entityCollection . get ( form . type . value ) ; if ( template ) { createData = mergeObject ( template . data , createData , { inplace : false } ) ; createData . type = template . data . type ; delete createData . flags . alpha . isTemplate ; } createData . name = form . name . value ; return cls . create ( createData , { renderSheet : true } ) ; } , no : ( ) => { } , defaultYes : false } ) ; }
Display the entity template dialog.
Display the entity template dialog .
// Retrieve the collection and find any available templates // Setup default creation data // Build an array of types for the form, including an empty default. // Render the confirmation dialog window