Question

I have that js function

    function searchRequest(months){
    //base url
    var protocol = window.location.protocol;
    var siteUrl = window.location.host;
    //get months and years 4 link
    var yearToUrl = months.toString().substring(0,4);
    var monthsToUrl = months.toString().substr(-2);
    //calculating months days
    var yearForDays = parseInt(yearToUrl);
    var monthsForDays = parseInt(monthsToUrl);
    var daysToUrl = 33 - new Date(yearForDays, monthsForDays-1, 33).getDate();
    //add months days and year to link
    var lastUrlPart = 'invoices/#_form=42422b080fbce04ec7f431ad4abe6f6495d8f7bf&view=search&predefined_search=2&invoice_date_from=01%2F' + monthsToUrl + '%2F' + yearToUrl + '&invoice_date_to=' + daysToUrl + '%2F' + monthsToUrl + '%2F' + yearToUrl;
    //creating link
    var redirectUrl = protocol + '//' + siteUrl + '/' + lastUrlPart;
    window.location.href = redirectUrl;
}

With that link at other page of site should enabled search. But after redirect it didn't work. Also when i setup my cursour to browser addres string with that url and click enter on keyboard search work normally with that link. How i can fix that? I need results after redirect. Thanks.

That is my output from function link http://actamedical.loc/invoices/#_form=42422b080fbce04ec7f431ad4abe6f6495d8f7bf&view=search&predefined_search=2&invoice_date_from=01%2F09%2F2012&invoice_date_to=30%2F09%2F2012

Was it helpful?

Solution 2

Okay. After some broke brains i found that in the progect use grid system where we can setup active grid or unactive. My redirect didnt work cos target page have 3 search types (live, advanced and predefined). I take like example link from predefined search but that search was not added to grid system and grid cant set active by using get request. Like says 'fast' i should trigger page reload. I find that to making some greed i should use cookies. I rewrite template function for my request and take link from advanced search.

function openGridTab(el)
{
var url = $(el).attr('href') ? $(el).attr('href') : el;
var place = url.split('/#', 2)[0].split('//')[1].split('/').reverse().shift();
var tab = url.split('#', 2)[1].split('&', 2)[0].split('=', 2)[1];
var search_form_name = $(el).attr('rel') ? $(el).attr('rel') : '42422b080fbce04ec7f431ad4abe6f6495d8f7bf';

switch(place)
{
    case 'tasks':
    {
        //var cookieName = tasksInterface.options['tabs_cookie'];
        var cookieName = 'tsk_flt';
        break;
    }
    case 'requests':
    {
        //var cookieName = requestsInterface.options['tabs_cookie'];
        var cookieName = 'req_flt';
        break;
    }
    case 'invoices':
    {
        //var cookieName = invoicesInterface.options['tabs_cookie'];
        var cookieName = 'inv_flt';
        break;
    }
    default:
    {
        return false;
    }
}

$.cookie(cookieName, tab);

if (tab == 'search')
{
    var params = url.split('&');
    params.shift();

    var form = '<form action="'+ url.split('#')[0] +'" method="get">' +
    '<input type="hidden" name="_form" value="'+ search_form_name +'"/>' +
    '<input type="hidden" name="view" value="search"/>' +
    '<input type="hidden" name="reload" value="1"/>';
    for (var i = 0; i < params.length; i++) {
        var param = params[i].split('=', 2);
        form += '<input type="hidden" name="'+ param[0]  +'" value="'+ param[1]  +'"/>';
    }
    form += '</form>';
    $(form).appendTo('body')[0].submit();
}
else
{
    window.location = url;
}

return false;

}

and rewrite my script function... Change url and use my function

var lastUrlPart = 'invoices/#view=search&invoice_num=&invoice_amount_from=&invoice_amount_to=&invoice_law=&invoice_report_type=&req_experts_nb=&invoice_patient=&invoice_company=&invoice_client=&invoice_state=&invoice_transaction_date_from=01%2F' + monthsToUrl + '%2F' + yearToUrl + '&invoice_transaction_date_to=' + daysToUrl + '%2F' + monthsToUrl + '%2F' + yearToUrl + '&req_without_appointments=0&invoice_create_date_from=&invoice_create_date_to=&specs_change_request=0&attr_billed=1&attr_paid=0&attr_subtraction=0';
    //creating link
    var redirectUrl = protocol + '//' + siteUrl + '/' + lastUrlPart;
    openGridTab(redirectUrl);

Also i was thinking what there more easy answer for my question with some js function. Thanks for help.

OTHER TIPS

try

window.location.reload()

after changing the url (hope this does not re-change it)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top