how to set single file in ng-flow - javascript

I need to use the single-file attribute in the ng-flow, i have to use it because this attribute other than limits the nuber of file to send, substitute the file thate was added until the upload event, see this:
singleFile Enable single file upload. Once one file is uploaded,
second file will overtake existing one, first one will be canceled. (Default: false)
this is the documentation taken from flow.js git repository.
What i really need to do is to put this attribute in the factory, because i need to set this for all my input file field. I have try to search it in the ng-flow documentation, but it lack of a lot of explanaion, anyone know how to do this? Otherwise anyone know where to find a complete good docummentation of this module?

Or using a tag like this:
<div flow-init="{target: '/upload', singleFile: true}"></div>

You could try setting it like this:
.config(['flowFactoryProvider', function (flowFactoryProvider) {
flowFactoryProvider.defaults = {
singleFile: true
};
}])

Related

How to write path to files in Magento? File is not found, even when I set the absolute path

everyone!
I try to create custom application sending (to emails) form the site on Magento.
For doing it, I call post.php file in this way:
$('form#send-profile').submit(function(event) {
event.preventDefault();
var output = true,
array = $(this).serialize();
if (output) {
$.post('post.php', array, function(data) {
$('input[type="text"], textarea').val('');
});
};
});
I`ve placed post.php into the root folder (and tried it with different folders too).
But I had this result in any conditions:
POST http://vescorte.com/post.php 404 (Not Found)
Maybe Magento has some special way to set paths? Tell me please, if you know how to cope with this problem.
First of all , which version of magento do you use ?
Next, if you want to development any new function , you need create a module
try this link magento-2-module-development
In the template file in which you mentioned JS code, you can mention the Magento base URL function to get full base URL like below:
$.post('<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>post.php', array, function(data) {
$('input[type="text"], textarea').val('');
});
Still if you face issue then try to remove all the code from post.php and run with simple text to check file request complete or not.

Get filename in dropzone using jQuery

hy guys I try like this, my quetion is how I can grab filename or name..?
console.log(myDropzone.files);
myDropzone.files returns an array of File objects. You could access specific file properties using index.
Eg.
console.log(myDropzone.files[1].name);//Getting second file name
Go to dropzone.js and find
Dropzone.prototype._finished() function and alert this
responseText.success
you will get the file name

using capybara, i'm unable to read custom data- attribute from an href

I have some HTML that looks generally like:
X
it's a delete link and i'm encoding the ID of the item being deleted in the href.
Then I have some javascript that looks generally like:
$('.myclass').click(function(){
var id = $(this).data('id');
$.ajax({ url: 'correct_url', data: {id: id}, type: 'DELETE'});
}
and this all works fine when I'm using the app.
However, I'm trying to test it with capybara (capybara-webkit driver)
and it falls apart: the DELETE request goes to the server without the id field! not only is there no value for it, it just isn't sent. However the request is made, so it seems the js is being executed, just minus the lines that use this and include the extra data hash.
any ideas? It needs to be a variable because there's really a list of things and each one needs its own delete link. Am I missing a better pattern for accomplishing this whole thing? Is capybara busted? thanks...
It's a limitation of QtWebkit - see https://github.com/thoughtbot/capybara-webkit/issues/427 - If you're not using the Qt 5.5.1 with capybara-webkit, theres a possibility support may have been added, so you might want to try upgrading.

Get name of deleted image

I just started to work with fine-uploader because it looks really great.
But of course that i have a problem. I would like to send 1 more parameter when you click on DELETE button. This parameter should be the name of the image that will be deleted.
What i don't know is how to get that name. i Tried to add onclick event as a parameter in html element but there is a problem with timing because of async.
In code i found only this:
where {filename} represents name of the image, but i have no idea, how to add it here:
Any help will be appreciated
To add parameters to the delete file request dynamically (per-file or for all files) use the setDeleteFileParams API method. For example:
callbacks: {
onSubmitDelete: function(fileId) {
var fileName = this.getName(fileId);
this.setDeleteFileParams({fileName: fileName}, fileId);
}
}
try this to get file name
//Using jQuery
$("#fineUploader").on("onSubmitDelete", function(event,id,name){
file_name = $(this).fineUploader("getName", id);
})

How to override variable parameter loaded from another script

I have a script that loads the code dynamically. It is kind of a search engine. When I press a search button, the action gets triggered and a new page opens with many parameters.
I want to override one of the parameters generated with the script in the new URL. JS code is quite big and hard to read, but I have found the important part in the Firebug DOM editor.
This is the pattern of the URL generated when you perform the search:
http://www.example.com/...?ParameterOne=123&ParameterTwo=Two&ThisParameter=Sth&ParameterFour=Four...
What I want to edit is "ThisParameter" and change its value. This is the part edited in the DOM that does what I want:
Foobar = {
_options: [],
...
var options = {"ParameterOne":123,"ParameterTwo":"Two","ThisParameter":"ABC","ParameterFour":Four,...}
...
And this is the output of "ThisParameter" when you choose "Copy path" in Firebug's DOM tab:
_options[0].ThisParameter
I am wondering it this is possible at all. What makes me think that it is, is the fact that I can change this parameter in Firebug and it works perfectly. So, if Firebug can edit it, there should be a way to influence it with another script.
Looking forward to any suggestions, thank you in advance!
Since you cannot edit the dynamic script you have the following options:
You have to try to give the script the correct input and hope it uses your value.
Add a script to the results page which will read the url and arguments, change it and redirect, as we discussed here. (If you put everything in functions it should not conflict with the dynamic script if the functions are uniquely named.)
You could try adding something like this jQuery code to the page with the search button:
$('input[name=search_button_name]').click(function(e) {
e.preventDefault();
var form_search = $('#search_form_id');
$('<input>').attr({
type: 'hidden',
name: 'ThisParameter',
value: 'SomethingElse'
}).appendTo(form_search);
f.submit();
});
You can override any js function and method, or wrap you code around it. The easiest thing would be to look at the code you get and once it gets loaded, you re-declare a method with your own functionality.
I you are trying to replace a parameter in a specific jquery request, you can even wrap around the jquerys ajax method:
var jquery_ajax = $.ajax
$.ajax = function(options){
// parse only a specific occurence
if(options.url.indexOf("example.com") > -1) {
// change the url/params object - depending on where the parameter is
options.params.ThisParameter = "My Custom value"
}
// call the original jquery ajax function
jquery_ajax(options);
}
But it would be a lot cleaner to override the method that builds the ajax request rather than the ajax request itself.
I would investigate further on the scope of the variable options (var options), is it global? i.e. if you type 'options' in the Firebug console, does it display its properties?
If so, you could then access it via your own script and change is value, e.g.
options.ThisParameter = 'my-own-value';
You might hook your script to the click event of the search button.
I hope this helps, it could be more specific maybe if you have some sample code somewhere.

Categories

Resources