123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- if(!dojo._hasResource["dojox.widget.SortList"]){
- dojo._hasResource["dojox.widget.SortList"] = true;
- dojo.provide("dojox.widget.SortList");
- dojo.experimental("dojox.widget.SortList");
- dojo.require("dijit.layout._LayoutWidget");
- dojo.require("dijit._Templated");
- dojo.declare("dojox.widget.SortList",
- [dijit.layout._LayoutWidget, dijit._Templated],
- {
-
-
-
-
-
-
- title: "",
-
-
-
-
-
- heading: "",
-
-
- descending: true,
-
-
- selected: null,
-
-
- sortable: true,
-
- store: "",
- key: "name",
-
- baseClass: "dojoxSortList",
- templateString: dojo.cache("dojox.widget", "SortList/SortList.html", "<div class=\"sortList\" id=\"${id}\">\n\t\t<div class=\"sortListTitle\" dojoAttachPoint=\"titleNode\">\n\t\t<div class=\"dijitInline sortListIcon\"> </div>\n\t\t<span dojoAttachPoint=\"focusNode\">${title}</span>\n\t\t</div>\n\t\t<div class=\"sortListBodyWrapper\" dojoAttachEvent=\"onmouseover: _set, onmouseout: _unset, onclick:_handleClick\" dojoAttachPoint=\"bodyWrapper\">\n\t\t<ul dojoAttachPoint=\"containerNode\" class=\"sortListBody\"></ul>\n\t</div>\n</div>\n"),
- _addItem: function(item){
- dojo.create("li", {
- innerHTML: this.store.getValue(item, this.key).replace(/</g, "<")
- }, this.containerNode);
- },
- postCreate: function(){
- if(this.store){
- this.store = dojo.getObject(this.store);
- var props = {
- onItem: dojo.hitch(this, "_addItem"),
- onComplete: dojo.hitch(this, "onSort")
- };
- this.store.fetch(props);
- }else{ this.onSort(); }
- this.inherited(arguments);
- },
- startup: function(){
- this.inherited(arguments);
- if(this.heading){
- this.setTitle(this.heading);
- this.title = this.heading;
- }
-
- setTimeout(dojo.hitch(this,"resize"), 5);
- if(this.sortable){ this.connect(this.titleNode,"onclick", "onSort"); }
- },
- resize: function(){
-
- this.inherited(arguments);
-
-
-
-
-
- var offset = ((this._contentBox.h) - (dojo.style(this.titleNode,"height")))-10;
- this.bodyWrapper.style.height = Math.abs(offset) + "px";
- },
-
- onSort: function(/* Event */e){
-
- var arr = dojo.query("li",this.domNode);
- if (this.sortable){
- this.descending = !this.descending;
- dojo.addClass(this.titleNode,((this.descending)?"sortListDesc":"sortListAsc"));
- dojo.removeClass(this.titleNode,((this.descending)?"sortListAsc":"sortListDesc"));
- arr.sort(this._sorter);
- if(this.descending){ arr.reverse(); }
- }
- var i=0;
- dojo.forEach(arr,function(item){
- dojo[(i++) % 2 === 0 ? "addClass" : "removeClass"](item,"sortListItemOdd");
- this.containerNode.appendChild(item);
- },this);
- },
-
- _set: function(/* Event */e){
-
- if(e.target !== this.bodyWrapper){
- dojo.addClass(e.target,"sortListItemHover");
- }
- },
- _unset: function(/* Event */e){
-
- dojo.removeClass(e.target,"sortListItemHover");
- },
- _handleClick: function(/* Event */e){
-
-
- dojo.toggleClass(e.target,"sortListItemSelected");
- e.target.focus();
- this._updateValues(e.target.innerHTML);
- },
- _updateValues: function(){
- this._selected = dojo.query("li.sortListItemSelected", this.containerNode);
- this.selected = [];
- dojo.forEach(this._selected, function(node){
- this.selected.push(node.innerHTML);
- }, this);
- this.onChanged(arguments);
- },
- _sorter: function(a,b){
-
- var aStr = a.innerHTML;
- var bStr = b.innerHTML;
- if(aStr>bStr){ return 1; }
- if(aStr<bStr){ return -1; }
- return 0;
- },
- setTitle: function(/* String */title){
-
- this.focusNode.innerHTML = this.title = title;
- },
- onChanged: function(){
-
- }
-
- });
- }
|