guy 8 years ago
parent
commit
3b5e1e3d32
  1. 3
      bi/case.js
  2. 3
      docs/case.js
  3. 347
      src/case/loader/sort.list.js

3
bi/case.js

@ -9138,6 +9138,9 @@ BI.SortList = BI.inherit(BI.Widget, {
}, },
populate: function (items) { populate: function (items) {
if (items) {
arguments[0] = this._formatItems(items);
}
this.loader.populate.apply(this.loader, arguments); this.loader.populate.apply(this.loader, arguments);
}, },

3
docs/case.js

@ -9138,6 +9138,9 @@ BI.SortList = BI.inherit(BI.Widget, {
}, },
populate: function (items) { populate: function (items) {
if (items) {
arguments[0] = this._formatItems(items);
}
this.loader.populate.apply(this.loader, arguments); this.loader.populate.apply(this.loader, arguments);
}, },

347
src/case/loader/sort.list.js

@ -1,173 +1,176 @@
/** /**
* Created by GUY on 2016/4/29. * Created by GUY on 2016/4/29.
* *
* @class BI.SortList * @class BI.SortList
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.SortList = BI.inherit(BI.Widget, { BI.SortList = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.SortList.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.SortList.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-sort-list", baseCls: "bi-sort-list",
isDefaultInit: true,//是否默认初始化数据 isDefaultInit: true,//是否默认初始化数据
//下面是button_group的属性 //下面是button_group的属性
el: { el: {
type: "bi.button_group" type: "bi.button_group"
}, },
items: [], items: [],
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
onLoaded: BI.emptyFn, onLoaded: BI.emptyFn,
//下面是分页信息 //下面是分页信息
count: false, count: false,
next: {}, next: {},
hasNext: BI.emptyFn hasNext: BI.emptyFn
//containment: this.element, //containment: this.element,
//connectWith: ".bi-sort-list", //connectWith: ".bi-sort-list",
}) })
}, },
_init: function () { _init: function () {
BI.SortList.superclass._init.apply(this, arguments); BI.SortList.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.loader = BI.createWidget({ this.loader = BI.createWidget({
type: "bi.list_loader", type: "bi.list_loader",
element: this, element: this,
isDefaultInit: o.isDefaultInit, isDefaultInit: o.isDefaultInit,
el: o.el, el: o.el,
items: this._formatItems(o.items), items: this._formatItems(o.items),
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
o.itemsCreator(op, function (items) { o.itemsCreator(op, function (items) {
callback(self._formatItems(items)); callback(self._formatItems(items));
}); });
}, },
onLoaded: o.onLoaded, onLoaded: o.onLoaded,
count: o.count, count: o.count,
next: o.next, next: o.next,
hasNext: o.hasNext hasNext: o.hasNext
}); });
this.loader.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.loader.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
if (type === BI.Events.CLICK) { if (type === BI.Events.CLICK) {
self.fireEvent(BI.SortList.EVENT_CHANGE, value, obj); self.fireEvent(BI.SortList.EVENT_CHANGE, value, obj);
} }
}); });
this.loader.element.sortable({ this.loader.element.sortable({
containment: o.containment || this.element, containment: o.containment || this.element,
connectWith: o.connectWith || ".bi-sort-list", connectWith: o.connectWith || ".bi-sort-list",
items: ".sort-item", items: ".sort-item",
cursor: o.cursor || "drag", cursor: o.cursor || "drag",
tolerance: o.tolerance || "intersect", tolerance: o.tolerance || "intersect",
placeholder: { placeholder: {
element: function ($currentItem) { element: function ($currentItem) {
var holder = BI.createWidget({ var holder = BI.createWidget({
type: "bi.layout", type: "bi.layout",
cls: "bi-sortable-holder", cls: "bi-sortable-holder",
height: $currentItem.outerHeight() height: $currentItem.outerHeight()
}); });
holder.element.css({ holder.element.css({
"margin-left": $currentItem.css("margin-left"), "margin-left": $currentItem.css("margin-left"),
"margin-right": $currentItem.css("margin-right"), "margin-right": $currentItem.css("margin-right"),
"margin-top": $currentItem.css("margin-top"), "margin-top": $currentItem.css("margin-top"),
"margin-bottom": $currentItem.css("margin-bottom"), "margin-bottom": $currentItem.css("margin-bottom"),
"margin": $currentItem.css("margin") "margin": $currentItem.css("margin")
}); });
return holder.element; return holder.element;
}, },
update: function () { update: function () {
} }
}, },
start: function (event, ui) { start: function (event, ui) {
}, },
stop: function (event, ui) { stop: function (event, ui) {
self.fireEvent(BI.SortList.EVENT_CHANGE); self.fireEvent(BI.SortList.EVENT_CHANGE);
}, },
over: function (event, ui) { over: function (event, ui) {
} }
}); });
}, },
_formatItems: function (items) { _formatItems: function (items) {
BI.each(items, function (i, item) { BI.each(items, function (i, item) {
item = BI.stripEL(item); item = BI.stripEL(item);
item.cls = item.cls ? item.cls + " sort-item" : "sort-item"; item.cls = item.cls ? item.cls + " sort-item" : "sort-item";
item.attributes = { item.attributes = {
sorted: item.value sorted: item.value
}; };
}); });
return items; return items;
}, },
hasNext: function () { hasNext: function () {
return this.loader.hasNext(); return this.loader.hasNext();
}, },
addItems: function (items) { addItems: function (items) {
this.loader.addItems(items); this.loader.addItems(items);
}, },
populate: function (items) { populate: function (items) {
this.loader.populate.apply(this.loader, arguments); if (items) {
}, arguments[0] = this._formatItems(items);
}
empty: function () { this.loader.populate.apply(this.loader, arguments);
this.loader.empty(); },
},
empty: function () {
setNotSelectedValue: function () { this.loader.empty();
this.loader.setNotSelectedValue.apply(this.loader, arguments); },
},
setNotSelectedValue: function () {
getNotSelectedValue: function () { this.loader.setNotSelectedValue.apply(this.loader, arguments);
return this.loader.getNotSelectedValue(); },
},
getNotSelectedValue: function () {
setValue: function () { return this.loader.getNotSelectedValue();
this.loader.setValue.apply(this.loader, arguments); },
},
setValue: function () {
getValue: function () { this.loader.setValue.apply(this.loader, arguments);
return this.loader.getValue(); },
},
getValue: function () {
getAllButtons: function () { return this.loader.getValue();
return this.loader.getAllButtons(); },
},
getAllButtons: function () {
getAllLeaves: function () { return this.loader.getAllButtons();
return this.loader.getAllLeaves(); },
},
getAllLeaves: function () {
getSelectedButtons: function () { return this.loader.getAllLeaves();
return this.loader.getSelectedButtons(); },
},
getSelectedButtons: function () {
getNotSelectedButtons: function () { return this.loader.getSelectedButtons();
return this.loader.getNotSelectedButtons(); },
},
getNotSelectedButtons: function () {
getIndexByValue: function (value) { return this.loader.getNotSelectedButtons();
return this.loader.getIndexByValue(value); },
},
getIndexByValue: function (value) {
getNodeById: function (id) { return this.loader.getIndexByValue(value);
return this.loader.getNodeById(id); },
},
getNodeById: function (id) {
getNodeByValue: function (value) { return this.loader.getNodeById(id);
return this.loader.getNodeByValue(value); },
},
getNodeByValue: function (value) {
getSortedValues: function () { return this.loader.getNodeByValue(value);
return this.loader.element.sortable("toArray", {attribute: "sorted"}); },
}
}); getSortedValues: function () {
BI.SortList.EVENT_CHANGE = "EVENT_CHANGE"; return this.loader.element.sortable("toArray", {attribute: "sorted"});
}
});
BI.SortList.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.sort_list", BI.SortList); BI.shortcut("bi.sort_list", BI.SortList);
Loading…
Cancel
Save