Add field for each file in fine-uploader - custom-fields

Trying to implement Fine-Uploader for first time.
There's a way I can add a text-field for each file pending uploading?
I want the user to comment the content of each file and than save these informations.
Thanks for explanations.
Dario.

If you want to add an input text field next to each file represented in the UI (I'm assuming you are using FineUploader mode), you can do the following:
Set the autoUpload option to false. This seems obvious, but I thought I should list it anyway. If you don't set this to false, files will be uploaded immediately after the user selects them. I'm guessing this would not fit into your workflow.
Define an onSubmitted callback handler. In this handler, you can use the id parameter to get a handler on the associated getItemByFileId API method.
Once you have the element that represents the file in the UI, you can add an input field next to it. Perhaps you should add a data attribute or a css class that you can later use to associate this field with the file.
I assume you intend to create a button that a user will click when they are ready to start uploading all selected files, presumably after they have filled out any text fields associated with these files. So, you can add a click handler to this button that calls the uploadStoredFiles API method.
You will also need to contribute an onUpload callback handler. When your handler is invoked (once for each file, before it is uploaded), grab the value from the associated text field and then use the setParams API method to send this value with the upload (POST) request for this file as a parameter. Don't forget to include the file ID as the last parameter when you call setParams.

Related

web2py pass parameters to controler and download a file

I have the following problem
On my page user can select date from and date to. This dates are to be send to controller on button click, which creates an excel file and user receives that file?
Any suggestions ??
Thank you
def excel_file():
form = SQLFORM.factory(Field('start_date', 'date'),
Field('end_date', 'date'))
if form.process(session=None).accepted:
excel_file = create_excel_file(form.vars.start_date, form.vars.end_date)
return response.stream(excel_file, filename='name_of_file.xlsx',
attachment=True)
return dict(form=form)
Note, the above sets session=None in the call to .process() in order to disable use of the _formkey hidden field (otherwise, you would only be able to submit the form once and would have to manually reload the page for a second submission). This means there is no CSRF protection, but that shouldn't be a problem here, as the form submission is just being used to request data rather than make any changes. If you need CSRF protection, you will have to implement it manually.
Also, note that excel_file can be a file-like object (such as StringIO), an open file object, or a string representing a full file path.
Alternatively, in the browser, you could add an event handler via Javascript to capture the button click and instead of allowing the form to post, call window.open() with a web2py URL that will create and serve the file (you would have to pass the values of the start and end dates from the form via the query string of the URL). You could optionally blank out the form fields after the submission.

rails: enforce validation check with form with multiple submit buttons

I have a form with multiple submit buttons that trigger different functionality in controller action. One submit button allows user to save csv with format. Another submit button allows user to load csv file with specified format from dropdown. Then a final submit button allows user to save actual formatted records to database. In order to save records, the user must either save csv format first or load a csv format. How can I enforce this validation check? How can I determine one of the other two submit buttons were triggered before the create call?
The problem with using session variable will be if I add a boolean in session after one button submitted, then when they import another csv file, that value still will be in session and give false positive.

How to send file from action to next action

I'm new in RoR.
I want to make that logic:
User upload xml or csv file from /home (static_pages#home) and send it to elms#el_select
If file is xml and file contain more than one element I want to show page to user so him choose which element he want to show
If file is csv or xml with one element I want to show result page
So here is two use-cases:
- choose file - view results
- choose file - choose element - view results
In second case I upload file in static_pages#home, send it to elms#el_select and I don't know how to send it from elms#el_select to result page.
In first case I don't know how to skip page rendering and send file to another controller
Controllers do not store files for up/download or any other data. They just manipulating with instances of their models (with their behaviour). So, if I have understand your question in the right way, the order may be next:
StatiPagesController take the file from user and store it somewhere (/tmp or smth.) if the file is valid;
ElmsController take the file from storage and render the proper view (or redirect_to proper view if such already exist).
Finally, I've found answer on my question:
#key = SecureRandom.uuid
Rails.cache.write(#key, #file)

ModX: Execute a php code when any Resource is created

I am working on a website created in ModX. I need to know the way I could execute a php code when any resource is created and also edit template variable associated to the created resource.
You can do this using a plugin, set to run on the OnDocFormSave event. This event has a mode property which will be set to new when the document being saved has just been created - you can do a simple check for this to prevent the plugin being run every time a document is saved.
To set a TV value for the current resource, do this:
// get the required TV object by name (or id)
$tv = $modx->getObject('modTemplateVar',array('name'=>'tvName'));
// set the new value and save it
$tv->setValue($modx->resource->get('id'), $newValue);
$tv->save();
The answer by okyanet is correct, but I've added details for those unfamiliar with MODX.
Create a plugin, and configure it to execute on the two system events 'onBeforeDocFormSave' and 'onDocFormSave'. The two events are fired just before and just after a resource is saved. When a resource is saved, the $mode variable is available to your plugin, and if it is a new resource it's value is modSystemEvent::MODE_NEW and if an update its value is modSystemEvent:MODE_UPD
I've written a gist that includes the full code with examples:
https://gist.github.com/2768300
This example shows you how to target either event through a switch statement, and how to further target the 'new' or 'update' status of the action. For intercepting and changing resource fields, its quite easy using the onBeforeDocFormSave event as you can simply change any resource fieldname with $resource->set('yourFieldname'). There is no $resource->save() required as this happens automatically after this event.
It's apparently much more difficult to save a tv using the onBeforeDocFormSave event, because of the way tvs are processed, so therefore the example shows how to update a tv using the system event 'onDocFormSave'. Again there is no $resource->save() required as tvs are saved immediately when you call 'setValue' on them.
A plugin could be made to function requiring only one of the system events, but as there are advantages to using both states as shown above, and to help explain, I have used both.

how to return url in form file in strut

hai all,
i have one problem regarding to return the form file value is validation fail. i have one form that have a few field to be fullfil by the user and one attachment field.if one of the field is blank the system will give the error when submit the form..my problem is, all the field will have the value that we entered before this but for form file it disappear.
Let's see if I understand your issue: You have a form with several input fields, and among them a <input type=file> for uploading some file content. In case of validation error, you return to that page (with struts2 result = INPUT, I guess) and the content of the previously filled fields appears, except for the FILE field.
This makes sense, if you understand how the other fields are "refilled" in Struts2 in this scenario (just from the action, which has typically mapped the parameters to properties). The server doesnt know the (clientside) fullpath of the file, it is not sent along the http request (it would be a privacy issue), it's the content of the file what is uploaded (and perhaps the filename without path). You can't escape that.
Anyway, I think this a case in which validation should signal an error early (in javascript, in the client side). Think about it: the user is uploading a file (potentially large) together with other info, and AFTER uploading it the server checks the fields and instructs the user to refill the fields and retry (including the upload). This can be unacceptable. My advise is, then, to include client-side validation (and if it pass, and the server validation fails, then the user must resign to refill the FILE field). If the file is large, one could split the input form in two pages, a first one to fill the several fields, and afterwards another to upload the file.

Resources