fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.7 KiB

import { ButtonGroup } from "@/base";
import { ListLoader } from "./loader.list";
import { Layout, shortcut, Widget, extend, emptyFn, Controller, createWidget, Events, each, stripEL } from "@/core";
7 years ago
/**
* Created by GUY on 2016/4/29.
*
* @class SortList
* @extends Widget
7 years ago
*/
@shortcut()
export class SortList extends Widget {
static xtype = "bi.sort_list";
7 years ago
static EVENT_CHANGE = "EVENT_CHANGE";
7 years ago
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-sort-list",
isDefaultInit: true, // 是否默认初始化数据
7 years ago
// 下面是button_group的属性
7 years ago
el: {
type: ButtonGroup.xtype,
7 years ago
},
items: [],
itemsCreator: emptyFn,
onLoaded: emptyFn,
7 years ago
// 下面是分页信息
7 years ago
count: false,
next: {},
hasNext: emptyFn,
7 years ago
// containment: this.element,
// connectWith: ".bi-sort-list",
});
}
7 years ago
_init() {
super._init(...arguments);
const o = this.options;
this.loader = createWidget({
type: ListLoader.xtype,
7 years ago
element: this,
isDefaultInit: o.isDefaultInit,
el: o.el,
items: this._formatItems(o.items),
itemsCreator(op, callback) {
o.itemsCreator(op, items => {
callback(this._formatItems(items));
7 years ago
});
},
onLoaded: o.onLoaded,
count: o.count,
next: o.next,
hasNext: o.hasNext,
7 years ago
});
this.loader.on(Controller.EVENT_CHANGE, (...args) => {
const [type, value, obj] = args;
this.fireEvent(Controller.EVENT_CHANGE, ...args);
if (type === Events.CLICK) {
this.fireEvent(SortList.EVENT_CHANGE, value, obj);
7 years ago
}
});
this.loader.element.sortable({
containment: o.containment || this.element,
connectWith: o.connectWith || ".bi-sort-list",
items: ".sort-item",
cursor: o.cursor || "drag",
tolerance: o.tolerance || "intersect",
placeholder: {
element($currentItem) {
const holder = createWidget({
type: Layout.xtype,
7 years ago
cls: "bi-sortable-holder",
height: $currentItem.outerHeight(),
7 years ago
});
holder.element.css({
"margin-left": $currentItem.css("margin-left"),
"margin-right": $currentItem.css("margin-right"),
"margin-top": $currentItem.css("margin-top"),
"margin-bottom": $currentItem.css("margin-bottom"),
margin: $currentItem.css("margin"),
7 years ago
});
return holder.element;
},
update() {},
7 years ago
},
start(event, ui) {},
stop: (event, ui) => {
this.fireEvent(SortList.EVENT_CHANGE);
7 years ago
},
over(event, ui) {},
7 years ago
});
}
7 years ago
_formatItems(items) {
each(items, (i, item) => {
item = stripEL(item);
item.cls = item.cls ? `${item.cls} sort-item` : "sort-item";
7 years ago
item.attributes = {
sorted: item.value,
7 years ago
};
});
7 years ago
return items;
}
7 years ago
hasNext() {
7 years ago
return this.loader.hasNext();
}
7 years ago
addItems(items) {
7 years ago
this.loader.addItems(items);
}
7 years ago
populate(items) {
7 years ago
if (items) {
arguments[0] = this._formatItems(items);
}
this.loader.populate(...arguments);
}
7 years ago
empty() {
7 years ago
this.loader.empty();
}
7 years ago
setNotSelectedValue() {
this.loader.setNotSelectedValue(...arguments);
}
7 years ago
getNotSelectedValue() {
7 years ago
return this.loader.getNotSelectedValue();
}
7 years ago
setValue() {
this.loader.setValue(...arguments);
}
7 years ago
getValue() {
7 years ago
return this.loader.getValue();
}
7 years ago
getAllButtons() {
7 years ago
return this.loader.getAllButtons();
}
7 years ago
getAllLeaves() {
7 years ago
return this.loader.getAllLeaves();
}
7 years ago
getSelectedButtons() {
7 years ago
return this.loader.getSelectedButtons();
}
7 years ago
getNotSelectedButtons() {
7 years ago
return this.loader.getNotSelectedButtons();
}
7 years ago
getIndexByValue(value) {
7 years ago
return this.loader.getIndexByValue(value);
}
7 years ago
getNodeById(id) {
7 years ago
return this.loader.getNodeById(id);
}
7 years ago
getNodeByValue(value) {
7 years ago
return this.loader.getNodeByValue(value);
}
7 years ago
getSortedValues() {
return this.loader.element.sortable("toArray", {
attribute: "sorted",
});
7 years ago
}
}