Forum for discussing general topics related to Couch.
4 posts Page 1 of 1
Hello,

I'm trying to create an SPA using CouchCMS and one of the Mobile Frameworks. The structure I am after is as follows

- Country
-- City
--- Suburb
---- Company
----- Department

I would like to get a list of countries which when one country is clicked leads to cities in that country and when a city s clicked the leads suburbs in that city and when a suburb is clicked a list of companies are listed and when a company is clicked it lists the departments in that company.

I tried using folders for country, city and suburb but somehow it did seem to work the way I wanted, maybe my coding was not right.

I also tried relationship and it seems to be working right but I can't seem to get the list as I describe above. I also would like to obtain a count of the number of departments in a company as well as the count of companies in a suburb, city and country, which is why I opted to use relationship.

I created templates for country, city, suburb, company and department. Used the related_pages code but had issues listing the subsequent list based on the clicked item, for example I set up the country list to obtain the city list but was not getting the city list and so forth

Basically, would using relationship work better for what I wold like to achieve or folders or nested pages.

Thanks & Regards
Said
Hi Said,

I would like to get a list of countries which when one country is clicked leads to cities in that country and when a city s clicked the leads suburbs in that city and when a suburb is clicked a list of companies are listed and when a company is clicked it lists the departments in that company.

This part can be pulled off using either folders or nested-pages or relations.

I also would like to obtain a count of the number of departments in a company

ditto. Can be done using any of the three ways.

as well as the count of companies in a suburb, city and country,

This is where things will get complicated - if we use relations, 'company' would be directly related to only 'suburbs' i.e. there would be no direct relationship between 'companies' and 'country' or 'city'. So using simple cms:related_pages won't cut it - it will require formulating custom queries.

With folders (or nested_pages), getting the count would be straightforward as both show counts of nested children. However, using either folders or nested-pages enforces some restrictions on your solution. Namely -
With folders - only the last entity of the tree (departments in this case) will be 'pages' i.e will have custom fields). The upper-levels are all folders and so cannot have custom fields beyond the description and image.

Nested-pages, as you know, are optimised to work with only smaller number of pages. So if you plan to input several thousands of entities (or more), this solution won't scale.

So, there is no straight-forward solution I am afraid.
I think the folders approach would be a better fit as I think the country, city and suburb are not likely to need custom-fields.
If the company also can do without custom-fields, this would be the perfect solution and nothing else needs to be done - just create 'departments' as cloned-pages and make all the rest as its folders.

If, however, both company and departments require custom-fields, you can create 'company' as cloned-pages with country, city and suburb as folders.
Create departments as cloned-pages using another template and relate them with companies.

This way we can easily navigate (and get counts) from top to companies. From there use cms:related_pages to get to the departments.

As I said, it is not a straightforward scenario to handle :)
Hope this helps.
Hi KK

I think I know where I went wrong with the initial folder approach, I created a template (locations.php) with custom fields then created 3 folders for that template - country, city and suburb and then used pages to create each country, city and suburb assigning a folder to the item accordingly.

My reservations about using folders is that the suburbs will get to be quite a lot and so will departments (I meant branches/outlets) which could be about 200+ branches per company and each city can on average have 50 companies that's 1000 branches/city.

Few questions with the folders approach:
1. Would it be better to make the folders hierarchical or flat.?
2. And would it matter if I made Country, City and Suburbs as a parent folders than added each sub-folder accordingly?

Thanks KK

Regards
Said
Hi KK,

I've managed to get the Folder method running and as I've used it with JQuery mobile it worked great. However, as JQuery mobile is very resource intensive and slow on mobile, I'm going with a different framework Chocolatechip UI. The one caveat with this framework is it requires all screens/panels to be on a single page as an example below

Panel One
Code: Select all
<nav class="current">
    <h1>Page Name</h1>
  </nav>
  <article id="main" class="current">
    <section>
      <ul class='list' role='list'>
        <li class='comp' data-goto="people">
          <div>
            <h3>People</h3>
          </div>
          <aside>
            <span class='nav'></span>
          </aside>
        </li>
        <li class='comp' data-goto="places">
          <div>
            <h3>Places</h3>
          </div>
          <aside>
            <span class='nav'></span>
          </aside>
        </li>
</ul>
</section>
</article>

Panel Two
Code: Select all
 <nav class='next'>
    <a href='#' class='button back'>Navigation</a>
    <h1>People</h1>
  </nav>
  <article id="people" class='next'>
    <section>
      <h2>This is a detail page about people.</h2>
      <ul class='list' >
        <li>
          <h3>People, what they do</h3>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
          <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
        </li>
      </ul>
      <p>The summary of what people do for you and those you care about.</p>
    </section>
  </article>


Basically the navigation is handled by the data-goto tag, which will then reference the second panel via the article ID.

Getting the initial goto-data=<cms:show k_folder_name /> or <cms:show k_page_name /> is easy enough, but because its all on the same page getting the second panel to grab/capture the selected/clicked folder and loading the child of that folder is doing my head in :)

Its something like this
Code: Select all
<!-- PANEL 1 -->
<article id="country">
<section>
<ul>
<li data-goto="cities">Country 1</li>
<li data-goto="cities">Country 2</li>
<li data-goto="cities">Country 3</li>
<li data-goto="cities">Country 4</li>
</ul>
</section>
</article>

-----------------------

<!-- PANEL 2 -->
<article id="cities">
<section>
<ul>
<li data-goto="suburbs">City 1</li>
<li data-goto="suburbs">City 2</li>
<li data-goto="suburbs">City 3</li>
<li data-goto="suburbs">City 4</li>
</ul>
</section>
</article>

-----------------------

<!-- PANEL 3 -->
<article id="suburbs">
<section>
<ul>
<li data-goto="companies">Branch 1</li>
<li data-goto="companies">Branch 2</li>
<li data-goto="companies">Branch 3</li>
<li data-goto="companies">Branch 4</li>
</ul>
</section>
</article>

-----------------------

<!-- PANEL 4 -->
<article id="companies">
<section>
<ul>
<li data-goto="branch">Branch & Company Detail 1</li>
<li data-goto="branch">Branch & Company Detail 2</li>
<li data-goto="branch">Branch & Company Detail 3</li>
<li data-goto="branch">Branch & Company Detail 4</li>
</ul>
</section>
</article>

-----------------------

<!-- PANEL 5 -->
<article id="branch">
<section>
<ul>
<li>Branch 1 Detail</li>
<li>Branch 2 Detail </li>
<li>Branch 3 Detail </li>
<li>Branch 4 Detail </li>
</ul>
</section>
</article>



The way I've done the structure in couch is

Country = Folder
City = Folder
Suburb = Folder
Company = Template
Branch = Template relationship to Company

The folders are hierarchical

Hope the outline is clear.

Thanks & Regards
Said
4 posts Page 1 of 1