<% Global.HopObject.prototype.loop %>
generic macro that loops over the childobjects and renders a specified skin for each of them

  • Parameter Object:
    providing the following properties: skin: the skin to render for each item (required) collection: the collection containing the items limit: max. number of items per page (req.data.page determines the page number) sort: property name to use for sorting order: sort order (either "asc" or "desc")
Sourcecode in /home/hannes/helma/modules/core/HopObject.js:
83:   HopObject.prototype.loop_macro = function(param) {
84:       if (!param.skin) {
85:           return;
86:       }
87:       var items = param.collection ? this[param.collection] : this;
88:       if (!items || !items.size || items.size() < 1) {
89:           return;
90:       }
91:       // set default values
92:      var min = 0, max = items.size();
93:      var pagesize = max;
94:      if (param.limit) {
95:          var n = parseInt(param.limit, 10);
96:          if (!isNaN(n)) {
97:              pagesize = n;
98:          }
99:          var pagenr = parseInt(req.data.page, 10);
100:          if (isNaN(pagenr)) {
101:              pagenr = 0;
102:          }
103:          min = Math.min(max, pagenr * pagesize);
104:          max = Math.min(max, min + pagesize);
105:      }
106:      if (param.sort) {
107:          var allitems = items.list();
108:          var test = allitems[0][param.sort];
109:          if (!test || isNaN(test)) {
110:              var Sorter = String.Sorter;
111:          } else {
112:              var Sorter = Number.Sorter;
113:          }
114:          allitems.sort(new Sorter(param.sort, Sorter[param.order.toUpperCase()]));
115:          var itemlist = allitems.slice(min, max);
116:      } else {
117:          var itemlist = items.list(min, max);
118:      }
119:      var skinParam = {};
120:      for (var i=0; i<itemlist.length; i+=1) {
121:          skinParam.index = pagenr * pagesize + i + 1;
122:          itemlist[i].renderSkin(param.skin, skinParam);
123:      }
124:      return;
125:  }