2/28: Seems the Go uri is only if you create your own persisten layer. I'm going to try and use a link on my form to do this. If I can figure out how to find the form_id of the current form.
Original Question:
I'm trying to restrict who can delete a form instance. It seems if people can get to the form-runner summary page, they can click the delete button and delete a form (even if they are not allowed to do any "/orbeon/fr/hr/expense-report/edit/*" options.
Anyone found a way around this issue. I wonder if we could use the GO button on the form /edit/ view to build our own delete feature.
If I look at the page source from the hr/expense-report/edit/f36b446c3ddbf7c63ec033d5c6fa7ce4 view, that the from does have the details to the actual form instance.
Example:
form id="xforms-form" class="xforms-form xforms-initially-hidden xforms-layout-nospan" action="/orbeon/fr/Test/Hidden_Search/edit/f36b446c3ddbf7c63ec033d5c6fa7ce4"
I wonder if that information could be passed to the "GO" button, if I have that on my page?
Right now, if users can access the Form Runner summary page, they can also access the "delete" button. Showing the "delete" button on the summary page for some users but not others, requires a change to Form Runner, which shouldn't very complicated.
For instance, if you only want the "delete" button to be shown for users with the role can-delete, on this xforms:bind of fr/summary/view.xhtml add the attribute:
relevant="xxforms:is-user-in-role('can-delete')"
Related
(Rail 5 beta 3)
I have a table on an index page (action) of a view with around 15 columns. Some of them are for text and some of them are for integers only. Every entry of this list (table) will be filled out by a 'form_for' form (in new or edit action).
For editing or deleting there are links with each list entry in the index view leading to the corresponding show, edit or destroy actions. This all works well. Some of these entries are entered by a select with pulldown on the new or edit view. This works well, too.
But if one of these selects should be changed for more than one entry in the list it takes too much time to click on 'edit', change the select and click on submit at each list item. To make this a better user experience I would like to be able to change the selects in the list (table) directly. It would be good to have the select/pulldown in place. The change of the state or choosen entry should than be saved in place as well or with an extra button ("save changes") above/below the table.
To say it in short:
I want to update multiple entries in a table in an index view without editig each single entry via edit view. The dates will be changed by a select and the data should be saved by a submit button on this page
Has anybody an idea how I can solve this?
Try best_in_place gem. It can solve the problem you have quoted. here are some links to it
https://github.com/bernat/best_in_place
http://railscasts.com/episodes/302-in-place-editing?view=asciicast
Your original text wasn't that confusing to me...
You want what's called a bulk edit feature. Easiest way would be to set up a new target at the controller level specifically to handle this request. I'll give you the pseudocode and it should be easy enough to fill in the blanks, but essentially:
Create a "bulk edit" form (the drop down select menu above the table)
Create a controller method to handle the bulk edit (controller#bulk)
Update routes.rb to direct a URL to that new method
Handle the bulk update in the controller and redirect back to index upon completion (cheap way of updating the page after editing is done).
Note: I'm assuming your model name is "Resource" because you did not specify what it actually was
On your index page, you want HTML like:
<form method="POST" action="/resources/bulk">
<select name="bulk_value">...</select>
</form>
On change/form submit/whatever, submit that form.
If you're using resourceful routing, you can hook this into config.rb via:
resources :resources do
post :bulk, on: :collection
end
Otherwise, hook the route however you see fit.
Then, in your controller:
def bulk
value = params[:bulk_value]
Resource.update_all value: value
redirect_to {resources_path}
end
Now, you said index view, so I am assuming you want all. But if you just want a subset, you can pass the preferred IDs along with the form as a hidden field, then use a where clause to filter, i.e.
Resource.where(id: parmas[:id_array]).update_all(value: value)
Anyway, that should get you down the right path.
I'm using ExpressionEngine and SafeCracker along with Ajax (plugin: jquery.form.js - http://jquery.malsup.com/form/).
Best I can tell, SafeCracker will only allow for updating a single entry at a time. However, the UI / UX necessitates that a list be displayed. I've proof of concept'ed an entry by entry on-demand form. That is, click a particular edit link next to each entry and a snippet of jquery creates a form along with displaying a submit button. Click submit and that single entry updates. The inputs don't exist until the Update link is clicked
What I would prefer to do, if possible, is to create the non-form and form versions of each entry as the page is renbered and use some sort of toggle to display one or the other. Again, doable. Then, when I click the Edit link I'd add the necessary attributes to the input so that entry's form elements will be read but the other (display: none) elements for the other entries will be ignored. I'm thinking (out loud) that if I add the attr("name", some-value) that would work. That is, an input with no name will be ignored.
Yes, I can test this and I will. However, even if it works I'm not sure if it's a best practice and/or there's a more ideal way of accomplishing my ends. I'm here looking for validation and/or additional expertise and input.
Thanks in advance.
Just set disabled property to inputs and they will excluded from Form submission, whatever input fields are hidden or visible. Different jQuery methods, like submit() and serialize() follow specification of HTML 4 and exclude all disabled controls of a forms. So one way is to set
$('your_input').prop('disabled', true);
or ,
$('your_input').attr('disabled', 'disabled');
Check following link:
http://www.w3.org/TR/html401/interact/forms.html#successful-controls
Also, you may use a general button instead of a submit, as result you can handle click event on it and within that event you can make exclusion, validation, manipulation on values and what ever you like.
You can put a disabled attribute on them server side or set the property via jQuery:
$(".hidden input").prop("disabled", true);
I have the following relation in my model:
A user can have several consumers
According to that, I call several actions from different controllers that depend on that consumer_id in the URL. So, I do stuff like:
/:consumer_id/products/all
/:consumer_id/locals/all?params...
I want to be able to given that I am in a particular view, let's say /3/products/all, be able to refresh, redirect or whatever is the best to /4/products/all, with a form that shows the different consumers attached to that user.
I know how to display the form, but I fail to see which action should I put given that I want to load the current controller, current action and the current params, except that I want to change the params[:consumer_id] and the session[:consumer_id] to the one chosen by the user in the form of the view.
What's the best or appropriate way of doing so?
This is a link to the same page with the same parameters and one additional parameter:
<%= link_to "Show more results", url_for(params.merge(:per => 100)) %>
If you want to modify a parameter rather than add a new one, you can modify the params hash just as you would modify any hash, and use url_for again.
Inside the view you can access both the current controller using controller_name and the current action using action_name
Your question is not clear. You want to choose consumer_id from your form, then use that consumer id inside the same page or for links to other pages?
If you want to use the consumer id for the current page, you need to use javascript or JQuery to update all attributes of the current page.
If you want to use that consumer id for links,
you may also use JQuery to update all links on your page
Or, you can submit the form to the server with new consumer_id.
I am looking for the best way to create ajax enabled subforms from items in a list with MVC 3. A static list of values should be generated, but with an "edit" link/button next to every item, to toggle inline edits.
I did follow the tutorial at this link
http://blog.janjonas.net/2011-07-24/asp_net-mvc_3-ajax-form-jquery-validate-supporting-unobtrusive-client-side-validation-and-server-side-validation [1]
However it is based on the form edit fields always being visible
I'd like to show a static list with field values, but let the user activate an edit field by clicking "edit" (e.g. button)
I did modify the example at [1] by creating a default partial view with a form with submit button only. When posting the data by ajax the edit form will show. It looks like it is working, (I only need to hide validation errors on the first POST - which does not send real data).
Update:
An even better solution would probably be to leave out all forms in the static view, just have a single css class button/link next to each item, and let jquery fetch the relevant view for the clicked item. I am not sure how to do that with MVC 3+jQuery though.
Another update:
I discovered Ajax.Actionlink, which did exactly what I wanted!
I found out how to do it, and it turned out to be real simple!
I created two partial views.
One for rendering each static item. I used used Ajax.ActionLink with InsertionMode "replace", and set the parent of the item as the target
The second for rendering the form. Here I used Ajax.Beginform with similar options.
On successfully saved data, I returned the static view, on failure, I returned the partial view with the ajax form again.
I'm happy I found a MVC-centric way to do it (although it is fun creating custom stuff with jQuery)
It sounds like you need an inline editing plugin for jQuery. I would try jEditable. I have not used it myself but appears to have extensive docs.
this entry might help: code + video + explanation ;)
http://ricardocovo.wordpress.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/
-covo
I'm new at ruby on rails, and I wanted to accomplish the following:
I've got a list with check boxes(one per row) and I'd like to have a link button(not a common button or submit) so when I click it I call an action from a controller.
My questions are:
How can I call a controller action with the link_to?
How do I get the checkboxes values(which of them are checked) and fields' values so I can know to whom apply the action? I'm used to work with C#, and there the lists have an ItemDataBound method in where you can get easily every row lets say, but I can't figure anything similar here.
If it's not clear enough, I'm going to put an example:
Let's say I've got the following "screen":
Delete(link)
Article ID | Article Name
chkbox 1111 t-shirt
chkbox 2222 pants
chkbox 3333 boots
Now, let's say I'd like to delete the pants and boots. So I'll check their check boxes and then I'll press Delete. Now, I'd like to have at my Articles controller, at the method delete_article(for example) and then get the id and name for those checked articles, and delete them.
Thanks,
Brian
I would wrap the checkboxes in a form and then submit this form using the link (either with javascript or change the link to a form button and style as a link).
Rails assumes a RESTful approach out of the box, so a straight link will always hit a GET accessible action on your controller (generally index or show). GET actions should always be idempotent.
You can use link_to the standard way, check out the rails documentation on 'link_to'.
The values from checkboxes can be get from the params hash.
Just look out for the documentation.