gistfile1.txt define(function (require) { var ScrollActionTypeManager = require("commonclass/scrollactiontypemanager"); var DataTableSettingManager = require("./../base/datatablemanager"); var UUID = require("commonclass/uuid"); var DataGri
gistfile1.txt
define(function (require) {
var ScrollActionTypeManager = require("commonclass/scrollactiontypemanager");
var DataTableSettingManager = require("./../base/datatablemanager");
var UUID = require("commonclass/uuid");
var DataGrid = require("./../base/datatable");
var actionmap = require("./../base/actionmap");
var DataTableRowActionManager = require("./../base/datatablerowactionmanager");
ScrollActionTypeManager.RegistActionType("DataTable", function (parm) {
if (parm.SubItem.BlockStruct) {
//$("#" + parm.Container).append(parm.SubItem.BlockStruct);
parm.SubItem.BlockStruct.show();
if (parm.SubItem.DataGrid) {
parm.SubItem.DataGrid.refresh();
}
parm.ScrollControl.Refresh();
} else
{
if(typeof parm.SubItem.Title!="undefined"){
parm.SubItem.Name=parm.SubItem.Name+">"+parm.SubItem.Title;
}
var div = $('
');
var toolbar = $('
' + '
' + '
' + parm.NavItem.Name + '
>
' + parm.SubItem.Name + '
' + '
' +
'
' + '
' + '
' + '
' +
'
' + '
' + '
' + //'
' + '
' +
'
');
var search = $('
');
toolbar.append(search);
div.append(toolbar);
var buttongroup = toolbar.find(".buttongroup");
var tablesetting = DataTableSettingManager.GetDataTable(parm.SubItem.Id);
var bts = tablesetting;
if (!bts) {
return;
}
if (bts.toolbar && bts.toolbar.buttons) {
var barr;
if (typeof bts.toolbar.buttons == "function") {
barr = bts.toolbar.buttons(parm);
}
for (var i = 0; i < barr.length; i++) {
if(barr[i].Sort && typeof barr[i].Sort!==undefined){
buttongroup.prepend($('").click({
parm: parm,
item: barr[i]
}, function (event) {
event.data.item.OnClick({
parm: parm,
item: barr[i]
});
}))
}
else{
buttongroup.append($('").click({
parm: parm,
item: barr[i]
}, function (event) {
event.data.item.OnClick({
parm: parm,
item: barr[i]
});
}))
}
}
}
var datagridcontainer = $("");
datagridcontainer.attr("id", "I-" + parm.SubItem.Id);
div.append(datagridcontainer);
div.attr("id", "nav-" + parm.SubItem.Id);
$("#" + parm.Container).append(div);
//tablesetting.Columns = $.extend(true, [], DataTableSettingManager.GetDataTable(parm.SubItem.Id).Columns);
tablesetting.Id = UUID.generate();
tablesetting.Container = parm.SubItem.Id;
//tablesetting.editable = DataTableSettingManager.GetDataTable(parm.SubItem.Id).editable;
// tablesetting.pager = DataTableSettingManager.GetDataTable(parm.SubItem.Id).pager;
tablesetting.pager = {};
if (tablesetting.pager) {
div.append($(""))
}
tablesetting.view = tablesetting.view || "datatable"; // DataTableSettingManager.GetDataTable(parm.SubItem.Id).view ? DataTableSettingManager.GetDataTable(parm.SubItem.Id).view : "datatable";
tablesetting.Select = "cell";
tablesetting.minHeight = 32;
tablesetting.Multiselect = true;
tablesetting.Blockselect = true;
tablesetting.Areaselect = true;
tablesetting.OnCanCheck = tablesetting.OnCanCheck || function () {
return true;
};
//tablesetting.on = $.extend(DataTableSettingManager.GetDataTable(parm.SubItem.Id).on, {
tablesetting.on = $.extend(tablesetting.on, {
onBeforeLoad: function () {
toolbar.find(".reloaddata").addClass("disabled");
this.showOverlay("数据加载中...");
},
onAfterLoad: function () {
toolbar.find(".reloaddata").removeClass("disabled");
this.hideOverlay();
}
});
tablesetting.url = $.extend({},{
$proxy: true,
load: function (view, callback, details) {
if (!details && this.defaultdetails) {
if (typeof this.defaultdetails === "function") {
details = this.defaultdetails(view.getTag());
} else {
details = this.defaultdetails;
}
}
details = details || {};
if (typeof this.extendparm === "function") {
this.extendparm(details);
}
if (!callback instanceof Array) {
callback = [callback];
}
var conf = actionmap[parm.SubItem.Id];
return parm.DataManager.Request(conf, details, parm).done(function (option, responsedata) {
if (view && view.data && view.data.driver)
view.data.driver.child = tablesetting.Child;
if (responsedata && responsedata.length != 0 && tablesetting.Child) {
for (var i = 0; i < responsedata.length; i++) {
responsedata[i].$top = true;
if (responsedata[i] && tablesetting.Child && responsedata[i]["" + tablesetting.Child + ""]) {
for (var j = 0; j < responsedata[i]["" + tablesetting.Child + ""].length; j++) {
responsedata[i]["" + tablesetting.Child + ""][j].$top = true;
}
}
}
}
if (callback && callback.length > 0) {
for (var i = 0; i < callback.length; i++) {
if (callback[i]) {
var before = callback[i].before;
if (before)
before.call(view, responsedata);
}
}
for (var i = 0; i < callback.length; i++) { //there can be multiple callbacks
if (callback[i]) {
var method = (callback[i].success || callback[i]);
if (method && method.call)
method.call(view, responsedata);
}
}
}
if (!responsedata || responsedata.length == 0) {
view.showOverlay("暂无数据");
}
}).fail(function (option, err) {
for (var i = 0; i < callback.length; i++) { //there can be multiple callbacks
if (callback[i]) {
var method = (callback[i].error || callback[i]);
if (method && method.call)
method.call(view, err.message);
}
}
view.showOverlay(err.message);
});
}
},tablesetting.url);
//tablesetting.scrollX = true;
var dg = new DataGrid(tablesetting);
var actions = tablesetting.Columns && tablesetting.Columns.length && tablesetting.Columns[tablesetting.Columns.length - 1].actiontype
//"rowdataoperate"
if (actions) {
for (var i = 0; i < actions.length; i++) {
dg.on_click(actions[i], function (action) {
return function (event, id, trigger) {
var func = DataTableRowActionManager.GetDataTableRowAction(parm.SubItem.Id + "_" + action);
if (typeof func === "function") {
func({
actionid: parm.SubItem.Id + "_" + action,
actionproperty: actionmap[parm.SubItem.Id + "_" + action],
row: dg.get_item(id.row),
datatable: dg,
event: event,
data: id,
trigger: trigger,
navitem: parm.NavItem,
subitem: parm.SubItem,
ActionType: action
});
}
}
}(actions[i]))
}
}
toolbar.find("input").bind("input propertychange", function () {
dg.filter($(this).val());
});
parm.SubItem.DataGrid = dg;
toolbar.find(".reloaddata").click(function () {
dg.table.clearAll();
dg.table.load(tablesetting.url, "json", { time: new Date().getTime() });
})
toolbar.find(".headermenu").click(function (event) {
var menu = dg.table.config.headermenu;
$$(menu).show(event);
});
toolbar.find("button.search").click(function () {
search.toggle();
})
parm.SubItem.BlockStruct = div;
}
});
return true;
});