I have created a page that is a list of nodes. I want each node to link to another page that is a list of nodes RELATED to the clicked node.

For instance, let's say I had a list of car company:

Ford
Chevy
Honda
Toyota

If I click on a link in this list (for instance Honda) I would get a list of models, for instance:

Civic
CRV
Accord

This list of models is linked from the car company list as an entity reference that is filtered by contextual filter in a view, like so:

http://www.cars.com/models/Ford

How do I pass an argument to pageshow like this?:

'models_by_company':{
'title':'Models',
'page_callback':'my_model_by_company_page',
'pageshow':'my_model_by_company_page_pageshow',
'pageshow_arguments':'company'
}

function my_model_by_company_page_pageshow(company) {
drupalgap.views_datasource.call({
'path':'models/company'

Comments

mastermindg’s picture

Issue summary: View changes
tyler.frankenstein’s picture

Status: Active » Needs review

Try this:

function my_module_menu() {
  var items = {};
  items['models_by_company/%'] = {
    title: 'Models',
    page_callback: 'my_model_by_company_page',
    pageshow: 'my_model_by_company_page_pageshow',
    page_arguments: [1]
  };
  return items;
}

function my_model_by_company_page(company) {
  // make an empty jQM item list with a unique ID
  // the ID should contain the company name for uniqness
}

function my_model_by_company_page_pageshow(company) {
drupalgap.views_datasource.call({
'path':'models/' + company
...
mastermindg’s picture

Thanks for the quick response! I'm getting the following error:

menu_execute_active_handler(404/models_by_company/Ford) - TypeError: Cannot read property 'page_callback' of undefined

Here's my code:

function my_module_menu() {
  var items = {
   'stores':{
   'title':'Cars',
   'page_callback':'my_cars_page',
   'pageshow':'my_cars_page_pageshow'
    },
   'models_by_company/%':{
   'title':'Car Models',
   'page_callback':'my_model_by_company_page',
   'pageshow':'my_model_by_company_page_pageshow',
   'page_arguments':[1]
    }
  };
  return items;
}


function my_model_by_company_page(company) {
  return {
    'car_models_list':{
      'theme':'jqm_item_list',
      'title':'Car Models',
      'items':[],
      'attributes':{'id':'car_models' + company},
    }
  };
}

function my_model_by_company_page_pageshow(company) {
  drupalgap.views_datasource.call({
  'path':'deals_per_store/' + company,
  'success':function(data){
        if (data.nodes.length > 0) {
          var items = [];
          $.each(data.nodes, function(index, object){
              var node = object.node;
              items.push(l(node.title, 'node/' + node.nid));
          });
          drupalgap_item_list_populate("#car_models" + company, items);
        }
      }
  });
}
tyler.frankenstein’s picture

Hmmm, that code looks fine. Are you using the latest development snapshot of the mobile application development kit and the latest development snapshot of the Drupal module?

Also, how are you navigating to "models_by_company/Ford"?

What happens if you navigate to "models_by_company"? (with no argument)

Either way, try the latest snapshots and let me know how that goes.

mastermindg’s picture

I updated the module to the latest snapshot but I can't seem to figure out how to build the snapshot of the development kit. I tried a few times and everything seems to be OK but I'm not getting anything in Ripple. I'm trying with branch 7.x-1.x-alpha-issue-199 since this has the most recent commits.

Besides this I've tried with the latest snapshot of the module and the latest stable release and am still seeing the same issue. I'm curious as why the url is being mixed up, though :

404/models_by_company/Ford

tyler.frankenstein’s picture

I would not recommend using the 7.x-1.x-alpha-issue-199 because it is very bleeding edge at the moment, and doesn't have much documentation for how to deploy it.

The latest recommended release of the app dev kit isn't recommended right now. Instead, use the 7.x-1.x-alpha snapshot (https://github.com/signalpoint/DrupalGap/archive/7.x-1.x-alpha.zip) and the 7.x-1.x-dev snapshot (http://ftp.drupal.org/files/projects/drupalgap-7.x-1.x-dev.zip).

Be sure to uninstall the DrupalGap module, re-install it, then flush all of your Drupal cache's.

Let me know how the 7.x-1.x-alpha snapshot goes, that should work.

Also for debugging, I find it helpful to place this line at the top of your settings.js file if it isn't already there:

window.localStorage().clear();

mastermindg’s picture

Like 99% of the issues that I have...this one was due to 2 characters:

'path':'deals_per_store/' + company,

should be

'path':'deals-per-store/' + company,

Thanks so much for all the help. I look forward to an enriching experience with Drupalgap!

mastermindg’s picture

Status: Needs review » Closed (fixed)
anybody’s picture

Hello tyler.frankenstein,

thanks a lot for your help. I was just searching for the same method and I could not find it in the "pages" or menu section of the DrupalGap Documentation.

Anyway I think it's essential and could help many people. Could you perhaps add such a snippet for dynamic paths there? That would be very nice.

Thank you so much for you unbelievable work in DrupalGap! It's great, you are a hero!

d16_dylan’s picture

I was wondering how to pass multiple arguments in this case, Say for a URL

'models_by_company/abc/efg'

I tried

    items['models_by_company/%/%'] = {
    title: 'Models',
    page_callback: 'my_model_by_company_page',
    pageshow: 'my_model_by_company_page_pageshow',
    page_arguments: [1,2]
    };

but i get 404 error

tyler.frankenstein’s picture

@d16_dylan, that's the correct syntax.

d16_dylan’s picture

@tyler

Using the above menu i get 404 not found error on the URL: models_by_company/14/modelspage,

My page function is

function my_model_by_company_page(company,pageid) {
  console.log(company);
  console.log(pageid);
  return {
    'br_models_list':{
      'theme':'jqm_item_list',
      //'title':'Models',
      'items':[],
      'attributes':{'id':'br_models' + company},
    }
  };
}

both of the 'console.log' statements don't print, so i'm assuming this page function is not called at all

Everything seems to work fine with single argument

tyler.frankenstein’s picture

Hmmm, looks like you may have found a bug there.

You can try using a single argument and a query string:

l('Foo', 'models_by_company/14?page_id=modelspage');

Then you can extract the query string value:

var page_id = _GET('page_id');

That's probably the quickest way around it, otherwise please file a new bug report on GitHub if you have time.