List page with simple template

In this lesson we continue changing our existing application; as basis the code at the end of the previous lesson is used. The goal is to display structured data in form of list using a specific format, the listItemMultiLine. (Details of the List element and list columns are described in the API documentation.)

Alternating the TagsPage page

We introduce /mobile/notes/Tags.scolvo script file to encapsulate all TagsPage related logic in one place. We extend the TagsPage page (created in the menuStructure lesson) with a list populated with static data and displayed as simple items.

Definition of the Tags page
 1function displayTagsPage(originId) {
 2  var pageData = getTagsData();
 3  var pageDescriptor = {
 4    "TagsPage": {
 5      "TagsList": pageData
 6    }
 7  };
 8  display(TagsPage, pageDescriptor, originId);
 9}
10
11function getTagsData() {
12  return  [{"title": "First tag"},
13          {"title": "Second tag"}];
14}
15
16page TagsPage {
17  layout: vertical;
18  template: general;
19  settingsVisible: true;
20  scolvoMenuVisible: true;
21
22  list TagsList {
23    template: listVerticalNormal;
24    itemTemplate: listItemMultiLine;
25    span: 0;
26    filterVisible: true;
27
28    actions: []
29    columns: [
30      mainText => title
31    ]
32  }
33}
34
35function onTagsPageLoaded(originId) {}

In order to display TagsPage we have to import /mobile/note/Tags.scolvo in /mobile.scolvo and use the new display function.

Changes in /mobile.scolvo
 1import {
 2  /mobile/note/Notes,
 3  /mobile/note/Tags
 4}
 5
 6// ...
 7
 8function onTag(originId) {
 9  displayTagsPage(originId);
10}
11
12// ...

Expected simple list behavior after compile

After completing this code, while pressing the menu item All we will have a list displaying two note item cards.

Using browser with light theme

../_images/lesson_4_browser_light.png

The result of code in browser with light theme

The final code with listItemMultiLine template

After performing the changes described above, the final form of the scolvo script files should be as defined below:

/mobile.scolvo
 1import {
 2  /mobile/note/Notes,
 3  /mobile/note/Tags
 4}
 5
 6menu defaultItem Notes {
 7  group Notes defaultItem All {
 8    item All,
 9    item Pinned
10 },
11 item Tags
12}
13
14function onAll(originId) {
15  displayNotesPage(originId);
16}
17
18function onPinned(originId) {
19  display(PinnedPage, {}, originId);
20}
21
22function onTags(originId) {
23  displayTagsPage(originId);
24}
25
26page PinnedPage {
27  layout: vertical;
28  template: general;
29  settingsVisible: true;
30  scolvoMenuVisible: true;
31}
32
33function onPinnedPageLoaded(originId) {}
/mobile/note/Notes.scolvo
 1function displayNotesPage(originId) {
 2  var pageData = getData();
 3  var pageDescriptor = {
 4    "NotesPage": {
 5      "NotesList": pageData
 6    }
 7  };
 8  display(NotesPage, pageDescriptor, originId);
 9}
10
11function getData() {
12  return  [{"title": "First title","content": "First content"},
13          {"title": "Second title","content": "Second content"}];
14}
15
16page NotesPage {
17  layout: vertical;
18  template: general;
19  settingsVisible: true;
20  scolvoMenuVisible: true;
21
22  list NotesList {
23    template: listVerticalNormal;
24    itemTemplate: listItemCard;
25    span: 0;
26    filterVisible: true;
27
28    actions: []
29    columns: [
30      title => title,
31      text => content
32    ]
33  }
34}
35
36function onNotesPageLoaded(originId) {}
/mobile/note/Tags.scolvo
 1function displayTagsPage(originId) {
 2  var pageData = getTagsData();
 3  var pageDescriptor = {
 4    "TagsPage": {
 5      "TagsList": pageData
 6    }
 7  };
 8  display(TagsPage, pageDescriptor, originId);
 9}
10
11function getTagsData() {
12  return  [{"title": "First tag"},
13          {"title": "Second tag"}];
14}
15
16page TagsPage {
17  layout: vertical;
18  template: general;
19  settingsVisible: true;
20  scolvoMenuVisible: true;
21
22  list TagsList {
23    template: listVerticalNormal;
24    itemTemplate: listItemMultiLine;
25    span: 0;
26    filterVisible: true;
27
28    actions: []
29    columns: [
30      mainText => title
31    ]
32  }
33}
34
35function onTagsPageLoaded(originId) {}

The content of the dictionary file is as below:

/mobile_dictionary_en.properties
1menu_Notes_label=Notes
2menu_Notes_icon=\ue956
3menu_Notes_All_label=All
4menu_Notes_Pinned_label=Pinned
5menu_Tags_label=Tags
6menu_Tags_icon=\ue93b