在DIN Project中,我们有这样一个需求:在DIN Library ECB默认的SendTo 的子Menu中加入我们自己指定的Menu.
重点注意的是:
1.加入的位置
2.只针对DIN Library 加入.
思路:找到_layouts/1033/Core.js下面的AddSendSubMenu方法,通过在Delegate Control中Override Core.js的方法来实现我们需求。
Solution:
1.创建Delegate Control,通过feature来部署delegate control. 2.在delegate control中 ovrride Core.js AddSendSubMenu.
关键代码如下(注意注释..):
$(function() {
var spAddSendSubMenu = AddSendSubMenu;
AddSendSubMenu = function(m, ctx) {
//通过ctx的listTemplate 属性来判断是否是DIN Library.
//如果是,Copy core.js中的AddSendSubMenu函数体,修改,添加我们的需求。
//如果不是,则执行Core.js 默认的AddSendSubMenu
if (ctx.listTemplate == '100502') {
strDisplayText = L_Send_Text;
var currentItemUrl = GetAttributeFromItemTable(itemTable, "Url", "ServerUrl");
var currentItemEscapedFileUrl;
var currentItenUnescapedUrl;
var strExtension;
if (currentItemFileUrl != null) {
currentItenUnescapedUrl = unescapeProperly(currentItemFileUrl);
currentItemEscapedFileUrl = escapeProperly(currentItenUnescapedUrl);
strExtension = SzExtension(currentItenUnescapedUrl);
if (strExtension != null && strExtension != "")
strExtension = strExtension.toLowerCase();
}
var sm = CASubM(m, strDisplayText, "", "", 400);
sm.id = "ID_Send";
var menuOption;
var serverFileRedirect = itemTable.getAttribute("SRed");
if (currentItemProgId != "SharePoint.WebPartPage.Document" &&
(serverFileRedirect == null || serverFileRedirect == "" || HasRights(0x0, 0x20)) && strExtension != "aspx") {
if (typeof (ctx.SendToLocationName) != "undefined" &&
ctx.SendToLocationName != null &&
ctx.SendToLocationName != "" &&
typeof (ctx.SendToLocationUrl) != "undefined" &&
ctx.SendToLocationUrl != null &&
ctx.SendToLocationUrl != "") {
strAction = "STSNavigate('" + ctx.HttpRoot + "/_layouts/copy.aspx?" + "SourceUrl=" + currentItemEscapedFileUrl + "&Source=" + GetSource() + "&FldUrl=" + escapeProperly(ctx.SendToLocationUrl) + "')";
menuOption = CAMOpt(sm,
ctx.SendToLocationName,
strAction,
"");
}
if (typeof (itemTable.getAttribute("HCD")) != "undefined" && itemTable.getAttribute("HCD") == "1") {
strDisplayText = L_ExistingCopies_Text;
strAction = "STSNavigate('" + ctx.HttpRoot + "/_layouts/updatecopies.aspx?" + "SourceUrl=" + currentItemEscapedFileUrl + "&Source=" + GetSource() + "')";
strImagePath = ctx.imagesPath + "existingLocations.gif";
menuOption = CAMOpt(sm, strDisplayText, strAction, strImagePath);
menuOption.id = "ID_ExistingCopies";
}
strDisplayText = L_OtherLocation_Text;
strAction = "STSNavigate('" + ctx.HttpRoot + "/_layouts/copy.aspx?" + "SourceUrl=" + currentItemEscapedFileUrl + "&Source=" + GetSource() + "')";
strImagePath = ctx.imagesPath + "sendOtherLoc.gif";
menuOption = CAMOpt(sm, strDisplayText, strAction, strImagePath);
menuOption.id = "ID_OtherLocation";
if (ctx.OfficialFileName != null && ctx.OfficialFileName != "") {
strDisplayText = ctx.OfficialFileName;
strAction = "STSNavigate('" + ctx.HttpRoot + "/_layouts/SendToOfficialFile.aspx?" + "SourceUrl=" + currentItemEscapedFileUrl + "&Source=" + GetSource() + "')";
strImagePath = "";
CAMOpt(sm, strDisplayText, strAction, strImagePath);
}
CAMSep(sm);
}
if (HasRights(0x10, 0x0)) {
strDisplayText = L_SendToEmail_Text;
var currentItemUrl = GetAttributeFromItemTable(itemTable, "Url", "ServerUrl");
var httpRootWithSlash = ctx.HttpRoot.substr(0);
if (httpRootWithSlash[httpRootWithSlash.length - 1] != '/')
httpRootWithSlash += '/';
var slashLoc = -1;
var fileUrl = "";
slashLoc = httpRootWithSlash.substring(8).indexOf('/') + 8;
fileUrl = httpRootWithSlash.substr(0, slashLoc) + escapeProperlyCore(unescapeProperly(currentItemUrl), true);
var serverFileRedir = itemTable.getAttribute("SRed");
if ((serverFileRedir != null) &&
(serverFileRedir != "") &&
(serverFileRedir != "1")) {
if (serverFileRedir.substring(0, 1) != "1") {
fileUrl = serverFileRedir;
}
else {
fileUrl = serverFileRedir.substring(1);
}
}
strAction = "javascript:navigateMailToLinkNew('" + fileUrl + "')";
strImagePath = ctx.imagesPath + "gmailnew.gif";
menuOption = CAMOpt(sm, strDisplayText, strAction, strImagePath);
menuOption.id = "ID_SendToEmail";
}
//这里添加我们的DIN Logic,通过web Service 判断当前Document是否是Main document
//customize
$().SPServices({
operation: "GetListItems",
async: false,
listName: ctx.listName,
CAMLViewFields: "<ViewFields></ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Integer'>" + currentItemID + "</Value></Eq></Where></Query>",
completefunc: function(xData, Status) {
$(xData.responseXML).find("[nodeName=z:row]").each(function() {
//main document
if ($(this).attr("ows__DINMainDocument") == "1") {
CAMOpt(sm, "Download DIN Document", "window.location.href='http://icon-vpc-wss/DIN%20Document%20Template%20Gallery/Function%20Specification%20for%20QA%20Alert%20System.pdf';", "/_layouts/icondin/images/icon-dinn-dindoc.gif");
}
CAMOpt(sm, "Download Entire Bundle", "alert('" + currentItemID + "');", "/_layouts/icondin/images/icon-dinn-bundle.gif");
});
}
});
//end customize
var serverFileRedirect = itemTable.getAttribute("SRed");
if (currentItemFSObjType != 1 &&
ctx.listBaseType == 1 &&
(serverFileRedirect == null || serverFileRedirect == ""
|| HasRights(0x0, 0x20))) {
strAction = "STSNavigate('" + ctx.HttpRoot + "/_layouts/download.aspx?" + "SourceUrl=" + currentItemEscapedFileUrl + "&Source=" + GetSource() + "&FldUrl=" + escapeProperly(ctx.SendToLocationUrl) + "')"; ;
menuOption = CAMOpt(sm, L_DownloadACopy_Text, strAction, "");
menuOption.id = "ID_DownloadACopy";
if (ctx.listTemplate != 109 &&
ctx.listTemplate != 119)
AddWorkspaceMenuItem(sm, ctx);
}
}
else {
spAddSendSubMenu(m, ctx);
}
}
});