function jsonList_Init(jsonList) {
jsonList_ShowData(jsonList);
jsonList_ShowActions(jsonList);
}
function jsonList_Bind(jsonList, arrItems) {
//used when binding via ajax/json
jsonList.Items = arrItems;
jsonList.selectedIndex = -1;
}
function jsonList_Sort(sColumn, reverse) {
if (jsonList.Items) {
//See: https://stackoverflow.com/questions/979256/sorting-an-array-of-javascript-objects-by-property
var sort_by = function (field, reverse, primer) {
var key = primer ? function (x) { return primer(x[field]) } : function (x) { return x[field] };
reverse = !reverse ? 1 : -1;
return function (a, b) {
return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
}
}
jsonList.Items.sort(sort_by(sColumn, reverse, null));
}
}
function jsonList_HighlightSelected() {
$(".sysListTableData tr").on('click', function () {
$(this).addClass("selected").siblings().removeClass("selected");
});
}
function jsonList_ShowActions(jsonList, bAppend) {
if ((jsonList.actionContainer) && (jsonList.actionContainer.length > 0) && (jsonList.Items)) {
var oItem = jsonList.Items[jsonList.selectedIndex]
var actions = $("#dvActions");
if (actions.length == 0) {
actions = $("
");
$(jsonList.actionContainer).append(actions);
}
var actionlist = actions.find("ul");
if (!bAppend) {
actionlist.empty();
}
var availableActions = null;
if (jsonList.Options) {
if (jsonList.Options['StateValidation']) {
if (!(typeof jsonList.Options['StateValidation'] === "function")) { jsonList.Options['StateValidation'] = window[jsonList.Options['StateValidation']]; }
availableActions = jsonList.Options['StateValidation'](oItem);
}
}
if (jsonList.Actions) {
$.each(jsonList.Actions, function (i, action) {
if (jsonList.selectedIndex >= 0 && (!availableActions || (availableActions && availableActions[action.id] == 1))) {
var li = $("" + action.Label + "");
li.on('click', function () { if (!(typeof action.event === "function")) {action.event = window[action.event];} action.event(jsonList.Items[jsonList.selectedIndex], action, jsonList.selectedIndex); });
actionlist.append(li);
}
});
}
}
}
function jsonList_SelectItem(jsonList, i) {
jsonList.selectedIndex = i;
jsonList_ShowActions(jsonList);
if (jsonList.onSelect) {
if (!(typeof jsonList.onSelect === "function")) { jsonList.onSelect = window[jsonList.onSelect]; }
jsonList.onSelect(jsonList, false);
}
if (jsonList.onDefaultAction) {
if (!(typeof jsonList.onDefaultAction === "function")) { jsonList.onDefaultAction = window[jsonList.onDefaultAction]; }
jsonList.onDefaultAction(jsonList, false);
}
}
function jsonList_Default_Action(jsonList, i) {
if (jsonList.Actions) {
if (!(typeof jsonList.Actions[0].event === "function")) { jsonList.Actions[0].event = window[jsonList.Actions[0].event]; }
jsonList.Actions[0].event(jsonList.Items[jsonList.selectedIndex], jsonList.Actions[0], jsonList.selectedIndex);
}
}
function jsonList_ShowData(jsonList, bAppend) {
var table_header = $("#tblDataHeader");
if (table_header.length == 0) {
table_header = $("");
$(jsonList.listContainer).append(table_header);
var tHead = $("");
var tr = $("
");
tHead.append(tr);
if (jsonList.Headings) {
$.each(jsonList.Headings, function (i, item) {
var sColClass = '';
var sColEvents = '';
var sClasses = '';
if (item.ClassName) {
sClasses += item.ClassName;
}
if ((item.Type == 'DateTime') || (item.Type == 'Numeric')) {
if (sClasses.length > 0) { sClasses += ' ' };
sClasses += "td_" + item.Type;
}
if (sClasses.length > 0) {
sColClass = " class=\"" + sClasses + "\"";
}
if (item.Width) {
sColClass += " style=\"width:" + item.Width + "\"";
}
if (jsonList.ColumnSort) {
sColEvents = " onclick=\"" + jsonList.ColumnSort.toString() + "('" + item.Property.toString() + "',this);\"";
}
var td = $("" + item.Label + " | ");
tr.append(td);
});
}
tr.append($(" | "));
table_header.append(tHead);
}
var table = $("#tblData");
if (table.length == 0) {
table = $("");
$(jsonList.listContainer).append(table);
}
var tablebody = table.find("tbody");
if (!bAppend) {
tablebody.find("tr").remove();
}
//now show any data from our array
if (jsonList.Items) {
$.each(jsonList.Items, function (i, item) {
var tr = $("
");
tr.on('click', function () {
$(this).addClass("selected").siblings().removeClass("selected");
jsonList_SelectItem(jsonList, i);
});
tr.dblclick(function () {
jsonList_Default_Action(jsonList, i);
});
tablebody.append(tr);
RenderRow(jsonList, tr, item);
});
}
//call the onselect so we can toggle any action button behaviour
if (jsonList.onSelect) {
if (!(typeof jsonList.onSelect === "function")) { jsonList.onSelect = window[jsonList.onSelect]; }
jsonList.onSelect(jsonList, false);
}
}
function GetColumnValue(oData, sColType) {
var sData = oData;
if (sData == null) {
sData = '';
}
if (sColType == 'DateTime') {
sData = (new Date(parseInt(sData.substr(6)))).toLocaleString();
}
return sData;
}
function RemoveScript(sData) {
//remove any script blocks
sData = sData.replace(/