Retrieve values from db using JS

Hello!
I'm my list "Pedidos de Or?amento" I have a php button which, when clicked, inserts into my "Or?amentos" list the respective row values (which are quotation requests and in the moment the button is pressed, they become quotations too). This button also creates a new dir and a new excel file inside of it in a specific path (moldes/Molde_{table_name___id}/Orcamento161.xlsm). Every quotation request excel file path is stored in my list "Settings" which has some elements: "file_name", "file_path" and an inner join with the "Pedidos de Or?amento" ... etc.
In the list "Or?amentos" I have another php button with an excel logo that allows, when clicked, to open the excel file using JS:

Code:
jQuery.each(rows, function(rowid, row) {
  window.open('../'+row.fzmms_settings___file_path+'/'+row.fzmms_settings___file_name);
})

The problem is, I can't seem to retrieve the values of that list. Using this I can only retrieve the values of the list "Or?amentos"... When I do this that you're seeing, the path becomes "unavailable/unavailable". How can I retrieve those values from the db and use them in the link?
 
JavaScript:
requirejs(['fab/fabrik'], function() {
    Fabrik.addEvent('fabrik.list.loaded', function(list) {
        var data = list.options.data;
        // data is an array of groups, each group is an object of rows, each row has a data object, each data object has a  __pk_val item which will have the row id
        data.each(function (group) {
            group.each(function (row) {
                // do whatever you need with row.data.__pk_val
                console.log(row.data.__pk_val); //row id
            });
        });
    });
});
 
JavaScript:
requirejs(['fab/fabrik'], function() {
    Fabrik.addEvent('fabrik.list.loaded', function(list) {
        var data = list.options.data;
        // data is an array of groups, each group is an object of rows, each row has a data object, each data object has a  __pk_val item which will have the row id
        data.each(function (group) {
            group.each(function (row) {
                // do whatever you need with row.data.__pk_val
                console.log(row.data.__pk_val); //row id
            });
        });
    });
});
So if I want to call the window.open method all I need to do is:


JavaScript:
requirejs(['fab/fabrik'], function() {
    Fabrik.addEvent('fabrik.list.loaded', function(list) {
        var data = list.options.data;
        data.each(function (group) {
            group.each(function (row) {
                console.log(row.data.__pk_val); 
                window.open();
            });
        });
    });
});

But, what do I put inside my window.open() method? Sorry, I'm noob in Fabrik ahah
 
Maybe:
JavaScript:
window.open('../'+row.data.fzmms_settings___file_path+'/'+row.data.fzmms_settings___file_name);
 
I have a php button in my list called "Pedidos de Or?amento". That php button basically sends to my list "Settings" a value (path of a file "moldes/moldes_x/orcamento.xlsm"). The values stay stored in that "Settings" list.
In other list that I have, called "Or?amentos", I have another php button which basically allows the user to open the path that was stored in Settings previously. How can I open that path that is stored in "Settings" using window.open() when clicking in that php button that I have in "Or?amentos"?
 
Use js plugin instead php plugin.
Create your js file and select from plugin.
In js file write ajax query to retrieve datas from your db.
Get Selected row id:
JavaScript:
var selected_row_id;
jQuery.each(rows, function(rowid, row) {
  console.log(rowid);
selected_row_id = rowid;
})
JavaScript:
var url = "index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=get_file_data&row_id=" + selected_row_id;
new Request({url:url,
    dataType:'json',
    onComplete:function(r){
        console.log('result: ', r);
        var file_name = r.file_name;
        var file_path = r.file_path;
        //format your result then create your url
        var url = ....;
        window.open(url);
    }  
}).send();
In user_ajax.php create your function to get file data.
For example:
PHP:
    public function get_file_data()
    {
        $db = FabrikWorker::getDbo();
        $app = JFactory::getApplication();
        $input = $app->input;
        $row_id = $input->get('row_id, '');
        $query = "SELECT `file_path`,`file_name` FROM `YOUR_TABLE` WHERE `id` = "  . $db->quote($row_id);
        $db->setQuery($query);
        $result = $db->loadObjectList();
        //echo '<pre>' . var_export($result, true) . '</pre>';
        echo json_encode($result);
}
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top