dojox/dtl/filter/lists.js

  • Provides:

    • dojox.dtl.filter.lists
  • Requires:

    • dojox.dtl._base in common
  • dojox.dtl.filter.lists._dictsort

    • type
      Function
    • parameters:
      • a: (typeof )
      • b: (typeof )
    • source: [view]
        if(a[0] == b[0]){
         return 0;
        }
        return (a[0] < b[0]) ? -1 : 1;
    • summary
  • dojox.dtl.filter.lists.dictsort

    • type
      Function
    • parameters:
      • value: (typeof )
      • arg: (typeof )
    • source: [view]
        if(!arg){
         return value;
        }


        var i, item, items = [];
        if(!dojo.isArray(value)){
         var obj = value, value = [];
         for(var key in obj){
          value.push(obj[key]);
         }
        }
        for(i = 0; i < value.length; i++){
         items.push([new dojox.dtl._Filter('var.' + arg).resolve(new dojox.dtl._Context({ 'var' : value[i]})), value[i]]);
        }
        items.sort(dojox.dtl.filter.lists._dictsort);
        var output = [];
        for(i = 0; item = items[i]; i++){
         output.push(item[1]);
        }
        return output;
    • summary
      Takes a list of dicts, returns that list sorted by the property given in the argument.
  • dojox.dtl.filter.lists.dictsortreversed

    • type
      Function
    • parameters:
      • value: (typeof )
      • arg: (typeof )
    • source: [view]
        if(!arg) return value;


        var dictsort = dojox.dtl.filter.lists.dictsort(value, arg);
        return dictsort.reverse();
    • summary
      Takes a list of dicts, returns that list sorted in reverse order by the property given in the argument.
  • dojox.dtl.filter.lists.first

    • type
      Function
    • parameters:
      • value: (typeof )
    • source: [view]
        return (value.length) ? value[0] : "";
    • summary
      Returns the first item in a list
  • dojox.dtl.filter.lists.join

    • type
      Function
    • parameters:
      • value: (typeof )
      • arg: (typeof )
    • source: [view]
        return value.join(arg || ",");
    • summary
      Joins a list with a string, like Python's ``str.join(list)``
    • description
      Django throws a compile error, but JS can't do arg checks
      so we're left with run time errors, which aren't wise for something
      as trivial here as an empty arg.
  • dojox.dtl.filter.lists.length

    • type
      Function
    • parameters:
      • value: (typeof )
    • source: [view]
        return (isNaN(value.length)) ? (value + "").length : value.length;
    • summary
      Returns the length of the value - useful for lists
  • dojox.dtl.filter.lists.length_is

    • type
      Function
    • parameters:
      • value: (typeof )
      • arg: (typeof )
    • source: [view]
        return value.length == parseInt(arg);
    • summary
      Returns a boolean of whether the value's length is the argument
  • dojox.dtl.filter.lists.random

    • type
      Function
    • parameters:
      • value: (typeof )
    • source: [view]
        return value[Math.floor(Math.random() * value.length)];
    • summary
      Returns a random item from the list
  • dojox.dtl.filter.lists.slice

    • type
      Function
    • parameters:
      • value: (typeof )
      • arg: (typeof )
    • source: [view]
        arg = arg || "";
        var parts = arg.split(":");
        var bits = [];
        for(var i = 0; i < parts.length; i++){
         if(!parts[i].length){
          bits.push(null);
         }else{
          bits.push(parseInt(parts[i]));
         }
        }


        if(bits[0] === null){
         bits[0] = 0;
        }
        if(bits[0] < 0){
         bits[0] = value.length + bits[0];
        }
        if(bits.length < 2 || bits[1] === null){
         bits[1] = value.length;
        }
        if(bits[1] < 0){
         bits[1] = value.length + bits[1];
        }

        
        return value.slice(bits[0], bits[1]);
    • summary
      Returns a slice of the list.
    • description
      Uses the same syntax as Python's list slicing; see
      http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slice
      for an introduction.
      Also uses the optional third value to denote every X item.
  • dojox.dtl.filter.lists._unordered_list

    • type
      Function
    • parameters:
      • value: (typeof )
      • tabs: (typeof )
    • source: [view]
        var ddl = dojox.dtl.filter.lists;
        var i, indent = "";
        for(i = 0; i < tabs; i++){
         indent += "\t";
        }
        if(value[1] && value[1].length){
         var recurse = [];
         for(i = 0; i < value[1].length; i++){
          recurse.push(ddl._unordered_list(value[1][i], tabs + 1))
         }
         return indent + "
    • " + value[0] + "\n" + indent + "
        \n" + recurse.join("\n") + "\n" + indent + "
      \n" + indent + "
    • ";
        }else{
         return indent + "
    • " + value[0] + "
    • ";
        }
  • summary
  • dojox.dtl.filter.lists.unordered_list

    • type
      Function
    • parameters:
      • value: (typeof )
    • source: [view]
        return dojox.dtl.filter.lists._unordered_list(value, 1);
    • summary
      Recursively takes a self-nested list and returns an HTML unordered list --
      WITHOUT opening and closing &lt;ul&gt; tags.
    • description
      The list is assumed to be in the proper format. For example, if ``var`` contains
      ``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``,
      then ``{{ var|unordered_list }}`` would return::
      
      	<li>States
      	<ul>
      		<li>Kansas
      		<ul>
      			<li>Lawrence</li>
      			<li>Topeka</li>
      		</ul>
      		</li>
      		<li>Illinois</li>
      	</ul>
      	</li>
  • dojox.dtl.filter.lists

    • type
      Object
    • summary
  • dojox.dtl.filter

    • type
      Object
    • summary
  • dojox.dtl

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary