Tuesday, 15 April 2014

Editable Select Widget in List View



The default Xataface list view is a read-only table that shows the records of the current table.  Occasionally I get requests to make some of the columns editable by way of a drop-down box.  For example, suppose we have built an issue tracker in Xataface.  The list page for the "issues" table likely has columns like "title", "status", "assignee", etc..  It might be helpful, in this case, if we could change the status of an issue directly in list view without having to go to the edit form (or the update form).  One solution is to change the "status" column to include a drop-down select widget rather than just a read-only string.  This is actually quite easy to do, in Xataface, even though it doesn't have this type of functionality built-in.

The Solution

Our solution has three parts:
  1. Implement the status__renderCell() method in the issues table delegate class to display the <select> list.
  2. Set the noLinkFromListView flag in the fields.ini file definition for the "status" field.
  3. Implement a Javascript handler to save changes via AJAX when the select list value is changed.

Custom cell content with status__renderCell()

The status__renderCell() method should return an string containing HTML.  Xataface looks for this method to populate the content of the "status" method in list view.


In this snippet we have hard-coded the possible status values.  But it would be better to use a Xataface valuelist for these values.  I leave this for you to do as an exercise.  Notice that I added a "data-record-id" attribute to the <select> tag.  We will use this later when we add our Javascript functionality.

If you reload the interface, you should now see a select list appear in the "status" column of each row.  Unfortunately when you click on it, to try to change the value, you will be taken to the details page for that row.  This is because the <select> list is rendered inside of an <a> tag, which Xataface generates for all cells in list view (to make them clickable).  You can disable this by setting the noLinkFromListView flag in the fields.ini file


Now, if you reload the page, you should be able to select different options in your select list without the page changing on you.  It doesn't actually "work" yet, but at least it looks right.  The next step is to add functionality to the drop-down lists.

Adding Save Functionality


In order to add save functionality, we will need to step into the world of Javascript.  Xataface provides a rich set of tools for developing javascript functionality.  Our first order of business is to create an empty Javascript file and have it included in our application at the appropriate time.   
If your application doesn't already have a directory named "js" in its root, create it now. 

Note: It is important that the directory is named "js" because this is where the Dataface_JavascriptTool is preset to look for scripts. 

Try adding a script with a simple "alert()" message, then we'll be able to tell whether the script is included properly in our App.


Including the Javascript File In Our App


To include the js file in our app, let's modify the earlier snippet we created to display the select list:


Notice that we added a call to Dataface_JavascriptTool::import() to import the script we created.  You might be concerned that this piece of code is executed several times per page, and thus many copies of our script will be included in the final HTML page.  No need to worry, though, as the Dataface_Javascript tool import() method checks for duplicates to make sure that the script is only included once.

Before proceeding, you should now try to reload the list view if your app to make sure that the "alert()" message fires.  If it does not, that means that something is wrong so you'll need to back track to figure out why the file is not being included.

If the alert() message fired properly, then we can move on to actually implement our javascript.  I always begin by creating a closure to wrap all of the javascript code.  This way my variables won't bleed into the global namespace.


Importing Javascript Libraries

Another nice thing about the Dataface_Javascript tool is that it provides linking/compiling functionality to be able to include other javascript libraries in a similar manner to the way you would import them in server-side languages like C, Java, Ruby, and Python.  The syntax is easy.  For our purposes here, we'll be using the jQuery library (which is included with Xataface), and the xataface.IO library, which provides convenience methods for reading and writing database records over AJAX.  Therefore, I'll place the following require statements at the beginning of my file.


These "require" statements instruct Xataface to search in the javascript include paths for files named "jquery.packed.js" and "xataface/IO.js" and include the contents of the first match for each of them.  The search paths, by default are {yourapp}/js, {xataface}/js but this can be augmented.

Now for the actual code:


If you're not familiar with jQuery, this code may look daunting.  Have no fear, jQuery is actually quite easy to understand once you have done a 10 minute tutorial.  In this case we are making use of our "status-drop-down" class that we added to the <select> tag in our status__renderCell() method to identify all of the drop-downs.  We then attach a listener to each select's "change" event.

We use the xataface.IO.update() method to actually update the the record.  The update() method expects a Xataface record ID as the first parameter.  This is a unique string that defines a record.  It is composed in the form {tablename}?key1=val1&key2=val2...&keyn=valn.  We don't really need to worry about how it is formed here, because we embedded the key as the <select> tag's data-record-id attribute in the status__renderCell() method so that we can just access it here.





16 comments:

  1. Excellent tutorial, thanks! It seems when using this method to update records, the standard functions don't seem to apply, such as the history tool, beforeSave/afterSave, etc. Is it possible to integrate these functions with this type of inline editing?

    ReplyDelete
    Replies
    1. Get your ex lover back urgently Dr Larry email: assurancesulotionhome@gmail com call him on or whatsapp +2348102316854 immediately
      Life without my husband was a real  mess for me and my children I am so happy to get my Ex back through the  help of Dr Larry the spell caster . My greatest surprise was that 48 hours after the Doctor prepared the spell for me, my husband who has abandoned me for 4 years suddenly called me unexpectedly and am so happy that we have come to become one again through the help of Dr Larry and am so happy to be with my husband once again. Dr Larry is a very wonderful spell caster, you can contact him if you need his assistant because i know he can also help you. contact him through his email: assurancesolutionhome@gmail com call him on or whatsapp +2348102316854 immediately website  http://assurancesolutionhome.website2.me/




      Get your ex lover back urgently Dr Larry email: assurancesulotionhome@gmail com call him on or whatsapp +2348102316854 immediately
      Life without my husband was a real  mess for me and my children I am so happy to get my Ex back through the  help of Dr Larry the spell caster . My greatest surprise was that 48 hours after the Doctor prepared the spell for me, my husband who has abandoned me for 4 years suddenly called me unexpectedly and am so happy that we have come to become one again through the help of Dr Larry and am so happy to be with my husband once again. Dr Larry is a very wonderful spell caster, you can contact him if you need his assistant because i know he can also help you. contact him through his email: assurancesolutionhome@gmail com call him on or whatsapp +2348102316854 immediately website  http://assurancesolutionhome.website2.me/




      Get your ex lover back urgently Dr Larry email: assurancesulotionhome@gmail com call him on or whatsapp +2348102316854 immediately
      Life without my husband was a real  mess for me and my children I am so happy to get my Ex back through the  help of Dr Larry the spell caster . My greatest surprise was that 48 hours after the Doctor prepared the spell for me, my husband who has abandoned me for 4 years suddenly called me unexpectedly and am so happy that we have come to become one again through the help of Dr Larry and am so happy to be with my husband once again. Dr Larry is a very wonderful spell caster, you can contact him if you need his assistant because i know he can also help you. contact him through his email: assurancesolutionhome@gmail com call him on or whatsapp +2348102316854 immediately website  http://assurancesolutionhome.website2.me/

      Delete
    2. URGENT AND EFFECTIVE LOVE SPELL CASTER TO HELP YOU GET BACK YOUR EX LOVER VERY FAST 2019 Contact DR LARRY assurancesolutionhome@gmail. com WhatsApp  +2348102316854 I am Laura Peggy  from (ALABAMA), When I eventually found testimonies about this spell caster Dr Larry, how he helped many people to get their lovers and broken homes back, i contacted him too because I was absolutely desperate to get my lover back. Life without my lover was a real mess for me and my kids. i wanted a dramatic change and I thought love spell could be the solution. After discussing the resolution with Dr Larry, he gave me hope that he will restore my relationship. I felt confident that he will actually make my lover to return home and he did! It’s fantastic what this great spell caster have done for me, his help is priceless! I don't know what I would have done without Dr Larry, He does his job so well he is organized and highly functional, i believe he is the best spell caster i can count on when it comes to all kinds of spell, I am so happy that my lover return back home. If you need help, contact him right now through these details below: Email: assurancesolutionhome@gmail. com WhatsApp +2348102316854 Website: http://assurancesolutionhome.wordpress.com  http://assurancesolutionhome.website2.me/





      URGENT AND EFFECTIVE LOVE SPELL CASTER TO HELP YOU GET BACK YOUR EX LOVER VERY FAST 2019 Contact DR LARRY assurancesolutionhome@gmail. com WhatsApp  +2348102316854 I am Laura Peggy  from (ALABAMA), When I eventually found testimonies about this spell caster Dr Larry, how he helped many people to get their lovers and broken homes back, i contacted him too because I was absolutely desperate to get my lover back. Life without my lover was a real mess for me and my kids. i wanted a dramatic change and I thought love spell could be the solution. After discussing the resolution with Dr Larry, he gave me hope that he will restore my relationship. I felt confident that he will actually make my lover to return home and he did! It’s fantastic what this great spell caster have done for me, his help is priceless! I don't know what I would have done without Dr Larry, He does his job so well he is organized and highly functional, i believe he is the best spell caster i can count on when it comes to all kinds of spell, I am so happy that my lover return back home. If you need help, contact him right now through these details below: Email: assurancesolutionhome@gmail. com WhatsApp +2348102316854 Website: http://assurancesolutionhome.wordpress.com  http://assurancesolutionhome.website2.me/

      Delete
    3. My husband and I have been married for about 7 yrs now. We were happily married with two kids, a boy and a girl. 3 months ago, I started to notice some strange behavior from him and a few weeks later I found out that my husband is seeing someone. He started coming home late from work, he hardly care about me or the kids anymore, Sometimes he goes out and doesn't even come back home for about 2-3 days. I did all I could to rectify this problem but all to no avail. I became very worried and needed help. As I was browsing through the Internet one day, I came across a website that suggested that Dr Great can help solve marital problems, restore broken relationships and so on. So, I felt I should give him a try. I contacted him and he did a spell for me. Two days later, my husband came to me and apologized for the wrongs he did and promise never to do it again. Ever since then, everything has returned back to normal. I and my family are living together happily again.. All thanks to Dr Great . If you need a spell caster that can cast a spell that truly works, I suggest you contact him. He will not disappoint you. This is his E-mail: 

      infinitylovespell@gmail.com or infinitylovespell@yahoo.com

      WhatsApp +2348118829899

      website http://infinitylovespell.website2.me/

      Blog http://infinitylovespell1.blogspot.com







      My husband and I have been married for about 7 yrs now. We were happily married with two kids, a boy and a girl. 3 months ago, I started to notice some strange behavior from him and a few weeks later I found out that my husband is seeing someone. He started coming home late from work, he hardly care about me or the kids anymore, Sometimes he goes out and doesn't even come back home for about 2-3 days. I did all I could to rectify this problem but all to no avail. I became very worried and needed help. As I was browsing through the Internet one day, I came across a website that suggested that Dr Great can help solve marital problems, restore broken relationships and so on. So, I felt I should give him a try. I contacted him and he did a spell for me. Two days later, my husband came to me and apologized for the wrongs he did and promise never to do it again. Ever since then, everything has returned back to normal. I and my family are living together happily again.. All thanks to Dr Great . If you need a spell caster that can cast a spell that truly works, I suggest you contact him. He will not disappoint you. This is his E-mail: 

      infinitylovespell@gmail.com or infinitylovespell@yahoo.com

      WhatsApp +2348118829899

      website http://infinitylovespell.website2.me/

      Blog http://infinitylovespell1.blogspot.com







      My husband and I have been married for about 7 yrs now. We were happily married with two kids, a boy and a girl. 3 months ago, I started to notice some strange behavior from him and a few weeks later I found out that my husband is seeing someone. He started coming home late from work, he hardly care about me or the kids anymore, Sometimes he goes out and doesn't even come back home for about 2-3 days. I did all I could to rectify this problem but all to no avail. I became very worried and needed help. As I was browsing through the Internet one day, I came across a website that suggested that Dr Great can help solve marital problems, restore broken relationships and so on. So, I felt I should give him a try. I contacted him and he did a spell for me. Two days later, my husband came to me and apologized for the wrongs he did and promise never to do it again. Ever since then, everything has returned back to normal. I and my family are living together happily again.. All thanks to Dr Great . If you need a spell caster that can cast a spell that truly works, I suggest you contact him. He will not disappoint you. This is his E-mail: 

      infinitylovespell@gmail.com or infinitylovespell@yahoo.com

      WhatsApp +2348118829899

      website http://infinitylovespell.website2.me/

      Blog http://infinitylovespell1.blogspot.com

      Delete
  2. Standard functions should still apply here. It still runs through the standard workflow (beforeSave/afterSave etc...).

    ReplyDelete
  3. The script is working perfectly in terms of updating the database. The "updated successfully" message appears. There are no errors in the web server log or the browser console. However, nothing appears in the history log, and the beforeSave actions are not occurring for me as they do when the record is edited normally. Any suggestions on what to check?

    ReplyDelete
    Replies
    1. Not sure why this would be happening for you. The xataface.IO.update() method (which is used in this example for saving) uses the ajax_save action to perform the actual save. It just calls the Dataface_Record::save() method, which follows the normal workflow.

      Are you 100% sure that the beforeSave trigger is not called? Can you show some code samples?

      Delete
  4. BlueHost is definitely the best web-hosting company for any hosting plans you might require.

    ReplyDelete
  5. If you need your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (even if they're dating somebody else now) you have to watch this video
    right away...

    (VIDEO) Get your ex CRAWLING back to you...?

    ReplyDelete
  6. Get your ex lover back urgently Dr Larry email: assurancesulotionhome@gmail com call him on or whatsapp +2348102316854 immediately
    Life without my husband was a real  mess for me and my children I am so happy to get my Ex back through the  help of Dr Larry the spell caster . My greatest surprise was that 48 hours after the Doctor prepared the spell for me, my husband who has abandoned me for 4 years suddenly called me unexpectedly and am so happy that we have come to become one again through the help of Dr Larry and am so happy to be with my husband once again. Dr Larry is a very wonderful spell caster, you can contact him if you need his assistant because i know he can also help you. contact him through his email: assurancesolutionhome@gmail com call him on or whatsapp +2348102316854 immediately website  http://assurancesolutionhome.website2.me/



    Get your ex lover back urgently Dr Larry email: assurancesulotionhome@gmail com call him on or whatsapp +2348102316854 immediately
    Life without my husband was a real  mess for me and my children I am so happy to get my Ex back through the  help of Dr Larry the spell caster . My greatest surprise was that 48 hours after the Doctor prepared the spell for me, my husband who has abandoned me for 4 years suddenly called me unexpectedly and am so happy that we have come to become one again through the help of Dr Larry and am so happy to be with my husband once again. Dr Larry is a very wonderful spell caster, you can contact him if you need his assistant because i know he can also help you. contact him through his email: assurancesolutionhome@gmail com call him on or whatsapp +2348102316854 immediately website  http://assurancesolutionhome.website2.me/



    Get your ex lover back urgently Dr Larry email: assurancesulotionhome@gmail com call him on or whatsapp +2348102316854 immediately
    Life without my husband was a real  mess for me and my children I am so happy to get my Ex back through the  help of Dr Larry the spell caster . My greatest surprise was that 48 hours after the Doctor prepared the spell for me, my husband who has abandoned me for 4 years suddenly called me unexpectedly and am so happy that we have come to become one again through the help of Dr Larry and am so happy to be with my husband once again. Dr Larry is a very wonderful spell caster, you can contact him if you need his assistant because i know he can also help you. contact him through his email: assurancesolutionhome@gmail com call him on or whatsapp +2348102316854 immediately website  http://assurancesolutionhome.website2.me/

    ReplyDelete
  7. cheap ray bans sunglasses uk sale, combining elegant style and cutting-edge technology, a variety of styles of replica ray ban clubmaster, the pointer walks between your exclusive taste style.

    ReplyDelete
  8. URGENT AND EFFECTIVE LOVE SPELL CASTER TO HELP YOU GET BACK YOUR EX LOVER VERY FAST 2019 Contact DR LARRY assurancesolutionhome@gmail. com WhatsApp  +2348102316854 I am Laura Peggy  from (ALABAMA), When I eventually found testimonies about this spell caster Dr Larry, how he helped many people to get their lovers and broken homes back, i contacted him too because I was absolutely desperate to get my lover back. Life without my lover was a real mess for me and my kids. i wanted a dramatic change and I thought love spell could be the solution. After discussing the resolution with Dr Larry, he gave me hope that he will restore my relationship. I felt confident that he will actually make my lover to return home and he did! It’s fantastic what this great spell caster have done for me, his help is priceless! I don't know what I would have done without Dr Larry, He does his job so well he is organized and highly functional, i believe he is the best spell caster i can count on when it comes to all kinds of spell, I am so happy that my lover return back home. If you need help, contact him right now through these details below: Email: assurancesolutionhome@gmail. com WhatsApp +2348102316854 Website: http://assurancesolutionhome.wordpress.com  http://assurancesolutionhome.website2.me/





    URGENT AND EFFECTIVE LOVE SPELL CASTER TO HELP YOU GET BACK YOUR EX LOVER VERY FAST 2019 Contact DR LARRY assurancesolutionhome@gmail. com WhatsApp  +2348102316854 I am Laura Peggy  from (ALABAMA), When I eventually found testimonies about this spell caster Dr Larry, how he helped many people to get their lovers and broken homes back, i contacted him too because I was absolutely desperate to get my lover back. Life without my lover was a real mess for me and my kids. i wanted a dramatic change and I thought love spell could be the solution. After discussing the resolution with Dr Larry, he gave me hope that he will restore my relationship. I felt confident that he will actually make my lover to return home and he did! It’s fantastic what this great spell caster have done for me, his help is priceless! I don't know what I would have done without Dr Larry, He does his job so well he is organized and highly functional, i believe he is the best spell caster i can count on when it comes to all kinds of spell, I am so happy that my lover return back home. If you need help, contact him right now through these details below: Email: assurancesolutionhome@gmail. com WhatsApp +2348102316854 Website: http://assurancesolutionhome.wordpress.com  http://assurancesolutionhome.website2.me/

    ReplyDelete
  9. Hi everybody. I recently saw a testimony about chief dr lucky in a blog I visit for relationship and dating counseling problems because i had been having serious issues with my boyfriend and we had been dating for six months, he just suddenly changed, he wasn't returning my calls,he started cheating,he was hurting me in many ways i never thought possible and I just thought I should try it*maybe out of desperation of some sort*..and I contacted chief dr lucky ..At first everything felt dreamy and unbelievable, his consultations and solution was a little bit easy and strange and I was scared a little cause I heard read and heard lots of stories to of fake spell casters,scams and i never really believed in magic..I played along with a little hope and and faith and I sent some few stuffs after everything and it worked like a miracle,everything went to a while new direction,it was and is amazing...I guess it was all good faith that made me read That particular post that faithful day..I hope he could help other people too like he did me...I did a little and I got everything I wanted and wished for*my husband,my family and my life back. E-mail: Cheifdrlucky@gmail.com or contact him on whats App him +2348132777335 Website :http://chiefdrluckysolutionhome.website2.me/  

    ReplyDelete
  10. My husband and I have been married for about 7 yrs now. We were happily married with two kids, a boy and a girl. 3 months ago, I started to notice some strange behavior from him and a few weeks later I found out that my husband is seeing someone. He started coming home late from work, he hardly care about me or the kids anymore, Sometimes he goes out and doesn't even come back home for about 2-3 days. I did all I could to rectify this problem but all to no avail. I became very worried and needed help. As I was browsing through the Internet one day, I came across a website that suggested that Dr Great can help solve marital problems, restore broken relationships and so on. So, I felt I should give him a try. I contacted him and he did a spell for me. Two days later, my husband came to me and apologized for the wrongs he did and promise never to do it again. Ever since then, everything has returned back to normal. I and my family are living together happily again.. All thanks to Dr Great . If you need a spell caster that can cast a spell that truly works, I suggest you contact him. He will not disappoint you. This is his E-mail: 

    infinitylovespell@gmail.com or infinitylovespell@yahoo.com

    WhatsApp +2348118829899

    website http://infinitylovespell.website2.me/

    Blog http://infinitylovespell1.blogspot.com

    ReplyDelete
  11. My husband and I have been married for about 7 yrs now. We were happily married with two kids, a boy and a girl. 3 months ago, I started to notice some strange behavior from him and a few weeks later I found out that my husband is seeing someone. He started coming home late from work, he hardly care about me or the kids anymore, Sometimes he goes out and doesn't even come back home for about 2-3 days. I did all I could to rectify this problem but all to no avail. I became very worried and needed help. As I was browsing through the Internet one day, I came across a website that suggested that Dr Great can help solve marital problems, restore broken relationships and so on. So, I felt I should give him a try. I contacted him and he did a spell for me. Two days later, my husband came to me and apologized for the wrongs he did and promise never to do it again. Ever since then, everything has returned back to normal. I and my family are living together happily again.. All thanks to Dr Great . If you need a spell caster that can cast a spell that truly works, I suggest you contact him. He will not disappoint you. This is his E-mail: 

    infinitylovespell@gmail.com or infinitylovespell@yahoo.com

    WhatsApp +2348118829899

    website http://infinitylovespell.website2.me/

    Blog http://infinitylovespell1.blogspot.com

    ReplyDelete
  12. Did you hear there's a 12 word phrase you can communicate to your partner... that will induce intense emotions of love and impulsive attraction to you buried within his heart?

    Because hidden in these 12 words is a "secret signal" that fuels a man's impulse to love, worship and look after you with all his heart...

    12 Words Will Fuel A Man's Love Instinct

    This impulse is so hardwired into a man's brain that it will make him try harder than before to build your relationship stronger.

    In fact, fueling this dominant impulse is so important to getting the best ever relationship with your man that as soon as you send your man a "Secret Signal"...

    ...You'll instantly find him expose his heart and soul to you in a way he never expressed before and he will distinguish you as the one and only woman in the universe who has ever truly appealed to him.

    ReplyDelete