Got it figured out... Here is the code that works..
Create Modal
_labRequestService.createOrEdit(labRequest
).done(function (data) {
abp.notify.info(app.localize('SavedSuccessfully'));
_modalManager.close();
abp.event.trigger('app.createOrEditLabRequestModalSaved', { id: data });
}).always(function () {
_modalManager.setBusy(false);
});
Event subscription and action
//Event Bus Registration
abp.event.on('app.createOrEditLabRequestModalSaved',
function (data) {
if (data !== -1) {
// View lab request for print
_viewLabRequestModal.open({ id: data.id });
}
});
I I have from the MVC project folder.
dnard82, thanks for the answer. I have tried to return just a number both from the Create() method and the modal. The Id value never gets passed through the event bus back to the subscribers.
here is the CreateOrEdit and Create methods
public async Task<int> CreateOrEdit(CreateOrEditLabRequestDto input)
{
int labRequestId;
if(input.Id == null){
labRequestId = await Create(input);
}
else{
await Update(input);
labRequestId = -1;
}
return labRequestId;
;
}
[AbpAuthorize(AppPermissions.Pages_LabRequest_Create)]
private async Task<int> Create(CreateOrEditLabRequestDto input)
{
var labRequest = ObjectMapper.Map<LabRequest>(input);
if (AbpSession.TenantId != null)
{
labRequest.TenantId = (int?) AbpSession.TenantId;
}
await _labRequestRepository.InsertAndGetIdAsync(labRequest);
return labRequest.Id;
}
I will keep working on this for now and post back if I find a solution
Version 7.0.0 MVCCore & JQuery
I need to pass the ID of a newly created record through the event bus so I can take action inside the subscribers. I get the ID using the InsertAndGetIdAsync method of the repository and that works fine. When I try to insert the id value to the event trigger I an Object [object ] error. on the subscription side I get ID: undefined Here is my code.
Note: newLabRequestId is an Object [object] data.Id is undefined
<br> AppService returns newly inserted record ID or -1
public async Task<int> CreateOrEdit(CreateOrEditLabRequestDto input)
{
int labRequestId;
if(input.Id == null){
labRequestId = await Create(input);
}
else{
await Update(input);
labRequestId = -1;
}
return labRequestId;
;
}
Create record in modal view. EventBus triggers but does not and pass the new through to the subscribers
var newLabRequestId = _labRequestService.createOrEdit( labRequest
).done(function () {
abp.notify.info(app.localize('SavedSuccessfully'));
_modalManager.close();
abp.event.trigger('app.createOrEditLabRequestModalSaved', { Id: newLabRequestId });
}).always(function () {
_modalManager.setBusy(false);
});
Eventbus subscription
//Event Bus Registration
abp.event.on('app.createOrEditLabRequestModalSaved',
function (data) {
if (data.Id !== -1) {
// View lab request for print
//window.location.href = "/LabRequest/ViewLabRequestModal/" + data.Id;
}
});
Here is how I solved this issue for me.. Seems a bit hacky, but working on a better solution
So I ended up getting the print modal feature to work by doing the following..
Created a partial view ModalFooterWithPrintAndClose then added the class save-button to the print button
<div class="modal-footer">
<!-- Using the Save Button until I can determine how use print-button -->
<button type="button" id="PrintModalButton" class="btn btn-secondary save-button"><i class="fa fa-save"></i> <span>@L("Print")</span></button>
<button type="button" class="btn btn-primary close-button" data-dismiss="modal">@L("Cancel")</button>
</div>
Added the Print and Close partial view to all modals that needed printing
@await Html.PartialAsync("~/Areas/App/Views/Common/Modals/_ModalFooterWithPrintAndClose.cshtml")
Modified my ViewModal.js file to add the print functionality into the save fucntion
this.save = function () {
$('.modal-body').printThis({
loadCSS: "metronic/common/css/invoice-1.css"
});
};
This works for now, seems like a hack. I am still looking for a more permanent solution on how to register a button click event on a modal in this framework.
So I created a separate modal footer called _ModalWithPrintAndClose.cshtml as shown
<div class="modal-footer">
<!-- Using the Save Button until I can determine how use print-button -->
<button type="button" id="PrintModalButton" class="btn btn-secondary print-button"><i class="fa fa-save"></i> <span>@L("Print")</span></button>
<button type="button" class="btn btn-primary close-button" data-dismiss="modal">@L("Cancel")</button>
</div>
Added it to the Modal
@await Html.PartialAsync("~/Areas/App/Views/Common/Modals/_ModalFooterWithPrintAndClose.cshtml")
Implemented the onOpen as you demonstrated
var modalOptions = {};
var onOpen = function () {
$('#PrintModalButton').click(function () {
$('.modal-content').printThis();
});
};
var onClose = function () { };
var _createOrEditModal = new app.ModalManager({
viewUrl: abp.appPath + 'App/LabRequest/CreateOrEditModal',
scriptUrl: abp.appPath + 'view-resources/Areas/App/Views/LabRequest/_CreateOrEditModal.js',
modalClass: 'CreateOrEditLabRequestModal'
});
Here is a hack that seems to be working for now, but seems a bit unstable... I use the same modal-footer partial view and change the class on the print button to include save-button, This code within the modal script fileworks and allows me to print
<br>
(function ($) {
app.modals.ViewLabRequestModal = function () {
var _modalManager;
this.init = function (modalManager) {
_modalManager = modalManager;
var modal = _modalManager.getModal();
};
this.save = function () {
//TODO: Add option afterPrint and call abpnotification
$('.modal-content').printThis({
loadCSS: "metronic/themes/theme11/css/style.bundle.css"
});
};
};
})(jQuery);
Thoughts?
AspnetZero 7.0.0 MVC Core & JQuery
I would like to add some additional commands to some modals, say a print button on a modal detail view. I have done this in the past on different projects using a really convenient library called printThis on github.
$('#PrintModalButton').click(function(){ $('.modal-content').printThis(); });
How can i access the click event on a button I add to an abp modal form?
Thanks for the explaination..
Ok so the install page is loading, but not sure which account and password to use
Under the connection string there is no field to enter a user name associated with the password, so is it the SA account ?