Today I've been asked to create a link to delete record. In Rails it's quite simple to do it, even there is an example on the documentation. For example,
link_to "Delete Me", {:action => "delete_me", :id => @dm.id}, :confirm => "Are you sure?", :method => :delete
This means to pop-up confirm box with message "Are you sure?" after click the link.
But sometimes, we want the user to enter some text first just to make sure the confirmation or to prevent deletion because of wrong selection by user.
So, instead of confirm I use the prompt box that have a text box. But rails don't have the helper/parameter to do it.
Then I make two links, one is for handle the prompt and user input and the other one to handle the request. So the code is become,
link_to_function "Delete Me", "function_that_handle_user_input"
link_to "Delete Me", {:action => "delete_me", :id => @dm.id}, :method => :delete, :style => "display:none"
Yes, the second link is a hidden link. And the prompt box is inside the function that should handle the user input, example
if(prompt('Enter YES to continue') == 'YES'){
$(this).next().onclick();
}
For the javascript function, you could write based on your need or just use your imagination.
That's it for now and thanks. Just write a comment if there is another solution or if you want to ask me.
February 12, 2010
Table sorter javascript plugin
I was assigned a task to provide table sort by client-side. So I find table sorter for javascript and I found several plugin that meet my needs.
This is not a judgement which plugin is the best or worse, I know that plugin is not created for all circumstances. The best plugin is the one that most fit to your circumstances, style, and conditions.
I've try 3 table sorter plugin that most simple and suitable for my circumstances, this time I will explain them
1. TabOrderer (1 JS file. Mini: +/- 9KB, normal: +/- 22KB)
Dependency: prototype
+. This plugin have search, filter, and pagination feature.
+. I think it's simple, easy to use and quite fast.
-. It's only accept data in JSON format, need to customize the table first.
2. TableFilter (3 JS files. Mini: +/- 25KB, normal +/- 67KB)
Dependency: jquery, jquery.cookies, jquery.truemouseout, json, daemachTools
+. This plugin have filter and pagination feature.
+. I think it's simple and easy to use.
+. Can change per-page setting on the fly.
+. Can sort multiple columns.
+. It accept data from ordinary table.
-. Lot's of dependency files, which make it bigger size.
3. TinyTable (1 JS file. Mini & normal: < 3KB)
Dependency: prototype
+. Tiny file size.
+. This plugin have pagination feature.
+. I think it's simple and easy to use.
-. Must add pagination control by ourself.
These three are the most fit to my conditions.
Note: My conditions is to sort table from search result, can be small to big data, should have pagination feature and no need to edit the row.
There are still a lot of plugins that I've not tried, if you want you can see it here,
ThePixelArt
Tympanus
This is not a judgement which plugin is the best or worse, I know that plugin is not created for all circumstances. The best plugin is the one that most fit to your circumstances, style, and conditions.
I've try 3 table sorter plugin that most simple and suitable for my circumstances, this time I will explain them
1. TabOrderer (1 JS file. Mini: +/- 9KB, normal: +/- 22KB)
Dependency: prototype
+. This plugin have search, filter, and pagination feature.
+. I think it's simple, easy to use and quite fast.
-. It's only accept data in JSON format, need to customize the table first.
2. TableFilter (3 JS files. Mini: +/- 25KB, normal +/- 67KB)
Dependency: jquery, jquery.cookies, jquery.truemouseout, json, daemachTools
+. This plugin have filter and pagination feature.
+. I think it's simple and easy to use.
+. Can change per-page setting on the fly.
+. Can sort multiple columns.
+. It accept data from ordinary table.
-. Lot's of dependency files, which make it bigger size.
3. TinyTable (1 JS file. Mini & normal: < 3KB)
Dependency: prototype
+. Tiny file size.
+. This plugin have pagination feature.
+. I think it's simple and easy to use.
-. Must add pagination control by ourself.
These three are the most fit to my conditions.
Note: My conditions is to sort table from search result, can be small to big data, should have pagination feature and no need to edit the row.
There are still a lot of plugins that I've not tried, if you want you can see it here,
ThePixelArt
Tympanus
January 15, 2010
How to work with the preexisting project
This is not an official guide, this is just from my personal experience.
In a preexisting project there are some point to consider:
I hope this could be a help to someone.
In a preexisting project there are some point to consider:
- In the first time or even after a while, for me learning the workflow is the hardest part especially when the project is vast(It's not your style of coding so it will take some time to understand it).
- When you made a change, then consider this:
- If you made an addition to the code, then you must focus on that part or the workflow that will be affected by that.
- If you made an edit or delete to the code, then you must find all part that would be deleted(for example, do a grep) and make sure that the change won't affect other part to become a defect.
- Always talk or discuss with other team member or client whenever possible, with this you can learn others mindset about this project, this is could also help you to understand the code faster.
- Don't too easily judge the existing code is bad or wrong, sometimes there is a good reason/explanation behind it.
- Don't forget to try to understand the client better, because it directly or indirectly, our client will compare with the previous one.
I hope this could be a help to someone.
Subscribe to:
Posts (Atom)