Get calendar quick-add working with Ralf's changes to open an etemplate in a dialog (c63784d7e8), fix buttons from those etemplates weren't adopted

This commit is contained in:
nathan 2023-07-11 17:07:51 -06:00
parent d21eb1c1e6
commit 50e3a1b204
4 changed files with 26 additions and 43 deletions

View File

@ -948,7 +948,7 @@ export class Et2Dialog extends Et2Widget(SlotMixin(SlDialog))
_adoptTemplateButtons()
{
// Check for something with buttons slot set
let search_in = <HTMLElement>(this._template_widget?.DOMContainer || this._contentNode);
let search_in = <HTMLElement>(this._template_widget?.DOMContainer ?? this._contentNode);
if(!search_in)
{
return;
@ -1022,7 +1022,7 @@ export class Et2Dialog extends Et2Widget(SlotMixin(SlDialog))
get _contentNode() : HTMLElement
{
return this.querySelector('.dialog_content');
return this.querySelector('.dialog_content') ?? this.querySelector("*");
}
_setupMoveResize()

View File

@ -1617,7 +1617,14 @@ export class etemplate2
uniqueId = data.DOMNodeID.replace('.', '-') + '-' + data['open_target'];
}
const et2 = new etemplate2(node, data.data.menuaction, uniqueId);
return et2.load(data.name, data.url, data.data, null, null, null, data['fw-target']);
return et2.load(data.name, data.url, data.data, null, null, null, data['fw-target'])
.then(() =>
{
if(dialog)
{
dialog._adoptTemplateButtons();
}
});
}
else
{

View File

@ -2061,45 +2061,21 @@ export class CalendarApp extends EgwApp
this.quick_add = options;
// Open dialog to use as target
let add_dialog = Et2Dialog.show_dialog(null, '', 'Add new event', null, [], Et2Dialog.PLAIN_MESSAGE, "", this.egw);
add_dialog.id = "quick_add";
// Position by the event
if(event)
{
add_dialog.config = {...add_dialog.config, referenceNode: event.getDOMNode()};
}
let add_dialog;
// Call the server, get it into the dialog
options = jQuery.extend({menuaction: 'calendar.calendar_uiforms.ajax_add', template: 'calendar.add'}, options);
this.egw.json(
this.egw.link('/json.php', options),
[options],
function(data)
(data) =>
{
if(data.type)
if(Array.isArray(data) && typeof data[0] === 'string')
{
return false;
}
var content = {
html: data[0],
js: ''
};
egw_seperateJavaScript(content);
// Check for right template in the response
if(content.html.indexOf('calendar-add') <= 0)
{
return false;
}
// Insert the content into the correct place
add_dialog._contentNode.replaceChildren();
add_dialog._contentNode.insertAdjacentHTML("beforeend", content.html);
let template = add_dialog.querySelector("[id='calendar-add']");
if(template)
{
template.addEventListener("load", add_dialog._adoptTemplateButtons);
jQuery(data[0]).appendTo(document.body);
}
add_dialog = document.body.querySelector("et2-dialog");
add_dialog.id = "quick-add";
}
).sendRequest();
@ -2162,7 +2138,7 @@ export class CalendarApp extends EgwApp
if(invalid.filter((widget) => widget).length == 0)
{
// Close the dialog, if everything is OK
(<Et2Dialog><unknown>document.querySelector('et2-dialog#quick_add')).hide();
(<Et2Dialog><unknown>document.querySelector('et2-dialog')).hide();
}
});

View File

@ -26,7 +26,7 @@
</grid>
<et2-button statustext="saves the changes made" label="Save" id="button[save]" image="save" onclick="return app.calendar.add_dialog_save(ev, widget); " slot="footer" default="true"></et2-button>
<et2-button statustext="Full edit dialog" label="Edit" id="button[edit]" image="edit" onclick="return app.calendar.add_dialog_edit(ev, widget);" slot="footer"></et2-button>
<et2-button statustext="Close the window" label="Cancel" id="button[cancel]" onclick="document.querySelector('et2-dialog#quick_add').hide()" image="cancel" slot="footer"></et2-button>
<et2-checkbox label="Always use full edit dialog" id="new_event_dialog" statustext="Always use the full edit dialog, not this little dialog" onchange="egw.set_preference('calendar',widget.id,widget.get_value() ? 'edit' : 'add');" slot="footer"></et2-checkbox>
<et2-button statustext="Close the window" label="Cancel" id="button[cancel]" onclick="document.querySelector('et2-dialog').hide()" image="cancel" slot="footer"></et2-button>
<et2-checkbox label="Always use full edit dialog" id="new_event_dialog" statustext="Always use the full edit dialog, not this little dialog" onchange="egw.set_preference('calendar',widget.id,widget.get_value() ? 'edit' : 'add');" slot="footer" align="right"></et2-checkbox>
</template>
</overlay>