Sensenet 内容选择器定制
Sensenet Content Picker Customization
我创建了两个自定义内容类型,ProjectContract 和 PaymentRequest。在 PaymentRequest 下,我有一个引用字段 Contract,我想用它来引用 ProjectContract。当我 creating/changing PaymentRequest 时,我需要以下内容:
- 如何初始化内容选择器以显示可用项目合同的 ContractNumber 字段?
- 如何在 ReferenceField Grid 控件下显示选定的 ProjectContract 的 ContractNumber?
SN js代码和mvc contains/returns固定字段值。我没有找到任何可以添加要显示的自定义字段的设置。
首先,那个 SN 包的版本是多少,因为 oData.svc 请求在旧版本上不起作用。它从 6.2 开始可用。
关于oData,这里有一个link:http://wiki.sensenet.com/OData_REST_API
还有一种方法可以解决,但是需要修改已有的SN码。
您需要将 (" /Root/Global/scripts/sn/SN.Picker.js ") 文件复制到具有相同结构的皮肤文件夹中。 (" /Root/Skins/[你的皮肤文件夹]/scripts/sn/SN.ReferenceGrid.js ")
您还需要将 (" /Root/Global/scripts/sn/SN.ReferenceGrid.js ") 文件复制到您的皮肤文件夹中。
不要修改原来的SN文件,因为SN更新后会被覆盖
下一步:将以下代码复制到第 1068 行,在 ("$grid.jqGrid({") 行之前,放入 InitGrid 函数中。
...
var neededTypeName = "ProjectContract";
var neededFieldName = "ContractNumber";
var findField = false;
o2 = (function () {
var result = [];
var itemArray = [];
$.each(o2, function (index, el) {
el.ContentField = "";
result.push(el);
if (el.ContentTypeName == neededTypeName) {
itemArray.push([index, el.Path]);
findField = true;
}
});
if (findField) {
$.each(itemArray, function (itemIndex, itemElArray) {
var itemId = itemElArray[0];
var itemEl = itemElArray[1];
var thisLength = itemEl.length;
var thislastSplash = itemEl.lastIndexOf("/");
var thisPath = itemEl.substring(0, thislastSplash) + "('" + itemEl.substring(thislastSplash + 1, thisLength) + "')";
$.ajax({
url: "/oData.svc" + thisPath + "?metadata=no$select=Path," + neededFieldName,
dataType: "json",
async: false,
success: function (d) {
result[itemId].ContentField = d.d[neededFieldName];
}
});
});
colNames.splice(6, 0, "ContentField");
colModel.splice(6, 0, { index: "ContentField", name: "ContentField", width: 100 });
return result;
}
return o2;
})();
...
$grid.jqGrid({
...
"neededTypeName"可能包含您的内容类型值,"neededFieldName"可能包含您要呈现的字段名称。
另一个将建立网格。
这将修改内容选择器 table.
您需要将此代码添加到 GetResultDataFromRow 函数中,在函数 return 之前的第 660 行。
...
if (rowdata.ContentField != undefined) {
result.ContentField = rowdata.ContentField;
}
...
这会将内容选取器中的所选项目属性添加到引用字段 table。
然后需要打开SNReferenceGrid.js在init函数中"var $grid = $("#" + displayAreaId);
之前添加如下代码
var neededTypeName = "CustomItem2";
var neededFieldName = "Custom2Num";
var findField = false;
var alreadyAdded = false;
var btnAttr = $("#"+addButtonId).attr("onClick");
if (btnAttr.indexOf(neededTypeName) > -1) {
alreadyAdded = true;
colNames[4].width = 150;
colModel[4].width = 150;
colNames.splice(3, 0, "ContentField");
colModel.splice(3, 0, { index: "ContentField", name: "ContentField", width: 60 });
}
initialSelection = (function () {
var result = [];
var itemArray = [];
$.each(initialSelection, function (index, el) {
el.ContentField = "";
result.push(el);
if (el.ContentTypeName == neededTypeName) {
itemArray.push([index, el.Path]);
findField = true;
}
});
if (findField) {
$.each(itemArray, function (itemIndex, itemElArray) {
var itemId = itemElArray[0];
var itemEl = itemElArray[1];
var thisLength = itemEl.length;
var thislastSplash = itemEl.lastIndexOf("/");
var thisPath = itemEl.substring(0, thislastSplash) + "('" + itemEl.substring(thislastSplash + 1, thisLength) + "')";
$.ajax({
url: "/oData.svc" + thisPath + "?metadata=no$select=Path," + neededFieldName,
dataType: "json",
async: false,
success: function (d) {
result[itemId].ContentField = d.d[neededFieldName];
}
});
});
if (!alreadyAdded) {
colNames.splice(3, 0, "ContentField");
colModel.splice(3, 0, { index: "ContentField", name: "ContentField", width: 100 });
}
return result;
}
return initialSelection;
})();
我希望这会有所帮助,但 SN 版本应该会有所帮助。
我创建了两个自定义内容类型,ProjectContract 和 PaymentRequest。在 PaymentRequest 下,我有一个引用字段 Contract,我想用它来引用 ProjectContract。当我 creating/changing PaymentRequest 时,我需要以下内容:
- 如何初始化内容选择器以显示可用项目合同的 ContractNumber 字段?
- 如何在 ReferenceField Grid 控件下显示选定的 ProjectContract 的 ContractNumber?
SN js代码和mvc contains/returns固定字段值。我没有找到任何可以添加要显示的自定义字段的设置。 首先,那个 SN 包的版本是多少,因为 oData.svc 请求在旧版本上不起作用。它从 6.2 开始可用。 关于oData,这里有一个link:http://wiki.sensenet.com/OData_REST_API
还有一种方法可以解决,但是需要修改已有的SN码。 您需要将 (" /Root/Global/scripts/sn/SN.Picker.js ") 文件复制到具有相同结构的皮肤文件夹中。 (" /Root/Skins/[你的皮肤文件夹]/scripts/sn/SN.ReferenceGrid.js ") 您还需要将 (" /Root/Global/scripts/sn/SN.ReferenceGrid.js ") 文件复制到您的皮肤文件夹中。
不要修改原来的SN文件,因为SN更新后会被覆盖
下一步:将以下代码复制到第 1068 行,在 ("$grid.jqGrid({") 行之前,放入 InitGrid 函数中。
...
var neededTypeName = "ProjectContract";
var neededFieldName = "ContractNumber";
var findField = false;
o2 = (function () {
var result = [];
var itemArray = [];
$.each(o2, function (index, el) {
el.ContentField = "";
result.push(el);
if (el.ContentTypeName == neededTypeName) {
itemArray.push([index, el.Path]);
findField = true;
}
});
if (findField) {
$.each(itemArray, function (itemIndex, itemElArray) {
var itemId = itemElArray[0];
var itemEl = itemElArray[1];
var thisLength = itemEl.length;
var thislastSplash = itemEl.lastIndexOf("/");
var thisPath = itemEl.substring(0, thislastSplash) + "('" + itemEl.substring(thislastSplash + 1, thisLength) + "')";
$.ajax({
url: "/oData.svc" + thisPath + "?metadata=no$select=Path," + neededFieldName,
dataType: "json",
async: false,
success: function (d) {
result[itemId].ContentField = d.d[neededFieldName];
}
});
});
colNames.splice(6, 0, "ContentField");
colModel.splice(6, 0, { index: "ContentField", name: "ContentField", width: 100 });
return result;
}
return o2;
})();
...
$grid.jqGrid({
...
"neededTypeName"可能包含您的内容类型值,"neededFieldName"可能包含您要呈现的字段名称。 另一个将建立网格。 这将修改内容选择器 table.
您需要将此代码添加到 GetResultDataFromRow 函数中,在函数 return 之前的第 660 行。
...
if (rowdata.ContentField != undefined) {
result.ContentField = rowdata.ContentField;
}
...
这会将内容选取器中的所选项目属性添加到引用字段 table。
然后需要打开SNReferenceGrid.js在init函数中"var $grid = $("#" + displayAreaId);
之前添加如下代码 var neededTypeName = "CustomItem2";
var neededFieldName = "Custom2Num";
var findField = false;
var alreadyAdded = false;
var btnAttr = $("#"+addButtonId).attr("onClick");
if (btnAttr.indexOf(neededTypeName) > -1) {
alreadyAdded = true;
colNames[4].width = 150;
colModel[4].width = 150;
colNames.splice(3, 0, "ContentField");
colModel.splice(3, 0, { index: "ContentField", name: "ContentField", width: 60 });
}
initialSelection = (function () {
var result = [];
var itemArray = [];
$.each(initialSelection, function (index, el) {
el.ContentField = "";
result.push(el);
if (el.ContentTypeName == neededTypeName) {
itemArray.push([index, el.Path]);
findField = true;
}
});
if (findField) {
$.each(itemArray, function (itemIndex, itemElArray) {
var itemId = itemElArray[0];
var itemEl = itemElArray[1];
var thisLength = itemEl.length;
var thislastSplash = itemEl.lastIndexOf("/");
var thisPath = itemEl.substring(0, thislastSplash) + "('" + itemEl.substring(thislastSplash + 1, thisLength) + "')";
$.ajax({
url: "/oData.svc" + thisPath + "?metadata=no$select=Path," + neededFieldName,
dataType: "json",
async: false,
success: function (d) {
result[itemId].ContentField = d.d[neededFieldName];
}
});
});
if (!alreadyAdded) {
colNames.splice(3, 0, "ContentField");
colModel.splice(3, 0, { index: "ContentField", name: "ContentField", width: 100 });
}
return result;
}
return initialSelection;
})();
我希望这会有所帮助,但 SN 版本应该会有所帮助。