Editor - Using 'Edit' to make new rows on separate table

Editor - Using 'Edit' to make new rows on separate table

TooManyTablesTooManyTables Posts: 23Questions: 7Answers: 1
edited June 2018 in Editor

I will freely admit, I expect this is a silly question. I don't have any expectation that DataTables would (or should) cater to the scenario it involves. Frankly, DT already goes above and beyond the call of duty in so many places, that expecting it to do this would simply be churlish. Having already worked out what I am going to do, I'm asking simply out of technical curiousity - is there actually any way of using DT to do this?

Disclaimers out of the way, question follows:

User A submits a request to use X number of item Y for a certain amount of time. That request goes on to the Requests table, where it is later approved by User B, who is the owner of item Y. Once approved, the request is turned into a Record on the Bookings table, where User B can edit it as they please, being the lord and master over all the items they survey.

User A, however, cannot directly edit their own booking. Should they want X number of item Y for longer, or X+3 of it, they must submit a request to User B to adjust the booking accordingly. This will go to the Requests table, linked to the original booking, so that when User B approves the change, the original booking can be updated.

In terms of interface design, it would be ideal if User A could able to click 'Edit' on their Booking record, have little form appear pre-filled with the existed values to be adjusted, without actually editing that table. Instead, they would be putting a record on the Requests table and returning little messages to say "Hey, you've put in a request for an edit, User B will look at it soon." or "Hey, you can't book that much of item Y!" etc without touching the data in Bookings.

Now, obviously, the whole point of DataTables is to edit the table you've populated it with. Clicking on a row, pressing edit and ending up not doing anything at all to said row is a bit outside the comfort zone. But, like I said, curious.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    What you are looking for absolutely show be possible with DataTables and Editor, but the business logic of the application is not something that the software we provide would handle. What you would need to do is use the basic hooks and event handlers to trigger the actions requird.

    For example, your form for edit, could act like a normal edit form, but submit to the server for the request table. Have the server side return the original data from the booking table (instead of the new request table), possibly with a left join to indicate that a request has been put in.

    Aside from the generic API reference and events on the client-side, custom buttons and server-side events are probably the two most important concepts in DataTables to use for this sort of thing.

    Allan

  • TooManyTablesTooManyTables Posts: 23Questions: 7Answers: 1

    Ah, okay. I had considered an approach like that, but wasn't quite sure there was an easy way to handle it on the backend and deal with the response to the frontend afterward. Business logic is fine - I've got most of that made already.

    I'm guessing on the server-side I'd need to use a preEdit event to create the EquipmentRequest record, and have the relevant Bookings fields as '->set(false)' so they don't get changed?

    With those pointers, I think I know where I'm going now - thanks! I'll post the complete code back once it's done, in the hope that some other lost soul might find it helpful.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Yes, using ->set( false ) would be an option. Another would be to point it at a different end point (which will write into the Requests table). If Editor doesn't find an the primary key in the table for an edit request, then it will just do an insert.

    Allan

This discussion has been closed.