Author Topic: Bug Fix for Entourage Form variable limits  (Read 87 times)


  • M&F Dev Team
  • Sr. Member
  • *****
  • Posts: 3011
  • Karma: +105/-52
    • View Profile
Bug Fix for Entourage Form variable limits
« on: March 01, 2017, 11:31:36 PM »
See the initial bug report here,5906.0.html

So what is this then? I thought I would do a quick write up of how I resolved this bug (pretending it passes Andrews testing) to help those whom may want to contribute, but are unsure how. First thing you will need to do is to fork the code on Github under your own account, since for whatever reason Tom has locked down creating branches on the master repository. If people need help doing this or understanding git and Github, let me know and I will do a quick tut. Once that was done and I had cloned my new fork repository onto my computer I was ready to find the issue.

Now I had some advantage in that I am familiar with Symfony, which is the PHP framework M&F uses, and the code base in general from having helped prepare some test cases early in M&F's development. So I knew we would be dealing with the HTML templated as starting point and magically knew I could find them in  src\BM2\SiteBundle\Resources\views. Since we did not have this particular problem with the Soldier form, which only encountered the issue if you were issues large amounts of orders, I figured comparing it to entourage would be a good start. The relevant files are can be found in src\BM2\SiteBundle\Resources\views\Character\entourage.html.twig and src\BM2\SiteBundle\Resources\views\Character\soliders.html.twig.

So what are these files? They are HTML templates using the Twig templating system. Basically they are a way of defining a HTML page that imports the relevant data from the M&F database. So the entourage file was simple enough, I could see the bulk of the code for the page and importantly the HTML table and submit button code. However the Soldier file has none of this, instead it imports BM2SiteBundle:element:soldierslist.html.twig. Why? Simply because the solider table is used in two places, the character soldier control and the settlement militia control. Both those pages import the code from the soldierlist element, so that if the solider list needs to change, we only have to change the code in one place. So the code we really want to compare to the entourage form is \src\BM2\SiteBundle\Resources\views\element\soliderlist.html.twig.

Now there is a fair bit of code difference to sift through here, soldiers have far more functionality like groups, group actions, resupply etc. But the important part I found was this

        $("#soldiers tr[has_changed='false']").remove();

This is a simple Javascript/jQuery routine that catches the onclick event for the HTML object with the ID field of do_submit, and then performs some actions. $("#do_submit") is the jQuery selector that grabs the HTML object/s that have the ID of do_submit, which if we look at the code is the ID for the form submit button. This code is pretty simple.It prevents the standard event function, ie prevents the form being submitted. It replaces the HTML element with the class of actionbar with some text saying loading, it hides the submit button. The important part is the last two lines though, it removed from the submit data all table rows from the soldier table that have no changes. $("#soldiers tr[has_changed='false']") is jQuery for select rows (tr) from HTML object with the ID soldiers, which in this case is our table, that have not changed. The code then submits the form.

So fixing the issue is as easy as adding this code to the entourage page. I changed all references to soldier classes and IDs to entourage. Further things I had to do were
  • The entourage table didn't have a ID field, I added one so that our jQuery code can find it
  • The submit button didn't have an ID, so again I added on called do_submit.
Job done I committed the changed code to my fork, advised Andrew that there was some code to be tested and now I wait for the code to be tested and added to the primary fork.
He who was once known as Blackfyre