Important
You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.
See our Release Process documentation for more information on the currently supported and upcoming releases.
Items Manager¶
Components¶
Backbone collection for storing list of items
itemsManagerEditor - [jQuery-UI widget] for binding html inputs to the item
itemsManagerTable - [jQuery-UI widget] for rendering list of items
Example:
Define Backbone.Model for an item:
1 var ItemModel = Backbone.Model.extend({
2 defaults: {
3 name : null,
4 label: null,
5 func: null,
6 sorting: null
7 }
8 });
Define Backbone.Collection for the item list:
1 var ItemCollection = Backbone.Collection.extend({
2 model: ItemModel
3 });
Define html for itemsManagerEditor:
1 <div id="editor">
2 <input name="name"></input>
3 <input name="label"></input>
4 <input name="func"></input>
5 <input name="sorting"></input>
6 <button class="add-button"></button>
7 <button class="save-button"></button>
8 <button class="cancel-button"></button>
9 </div>
Define html for itemsManagerTable:
1 <table>
2 <thead>
3 <tr>
4 <th>Name</th>
5 <th>Label</th>
6 <th>Function</th>
7 <th>Sorting</th>
8 <th>Actions</th>
9 </tr>
10 </thead>
11 <tbody class="item-container">
12 </tbody>
13 </table>
Define template file templates/item.html for the item on the list:
1 <tr data-cid="<%= cid %>">
2 <td><%= name %></td>
3 <td><%= label %></td>
4 <td><%= func %></td>
5 <td><%= sorting %></td>
6 <td class="action-cell">
7 <a href="#" data-collection-action="edit" role="button" title="_.__('Edit')">
8 <span class="fa-pencil-square-o hide-text" aria-hidden="true"></span>
9 </a>
10 <a href="#" data-collection-action="delete" role="button" title="_.__('Delete')"
11 data-message="Delete?">
12 <span class="fa-trash-o hide-text" aria-hidden="true"></span>
13 </a>
14 </td>
15 </tr>
Instantiate item collection:
1 var items = new ItemCollection([
2 {
3 "name": "a",
4 "label": "A",
5 // ...
6 },
7 {
8 "name": "b",
9 "label": "B",
10 // ...
11 },
12 {
13 "name": "c",
14 "label": "C",
15 // ...
16 },
17 ]);
Apply itemsManagerEditor widget on div#editor:
1 $('div#editor').itemsManagerEditor({
2 collection: items
3 });
Apply itemsManagerTable widget to tbody.item-container:
1import itemTemplate from 'tpl-loader!templates/item.html';
2
3$('tbody.item-container').itemsManagerTable({
4 itemTemplate: itemTemplate,
5 collection: items
6});
See also