Sharepoint JSLink 修改文档库的菜单Callouts

Sharepoint文档库文档的菜单是一个标准的Callouts,他有标题、内容主体、和工具栏组成,我们都可以定义:

 

今天我们来定义工具栏,activebar

 

 

点击申请打印等就可实现相应功能:

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var KeyPrint = false;
var KeyDown = false;
var renderECB = false;
var webUrl;
window.onload = function () {
    webUrl = "http://" + window.location.host + "/docmentcenter";
    onGetUserSuccess();
}

function sharePointReady() {

    context = new SP.ClientContext.get_current();
    web = context.get_web();
    getUser();
}

function getUser() {
    user = web.get_currentUser();
    context.load(user);
    context.executeQueryAsync(onGetUserSuccess, onGetUserFail);
}

function onGetUserSuccess() {
    //var userID=user.get_id();
    var userID = 1;
    if (userID == 1073741823 || userID == 2) {
        renderECB = true;
    }
    $.get(webUrl + "/_layouts/15/ManagementSystem.Form/PrintData.ashx?" + Math.random(), {
            Action: "post",
            act: "getData",
            ID: userID
        },
        function (data, textStatus) {
            if (data.KeyPrint == "True") {
                KeyPrint = true;
            }
            if (data.KeyDown == "True") {
                KeyDown = true;
            }
            SP.SOD.executeOrDelayUntilScriptLoaded(registerCallout, "callout.js");
        });
}

function onGetUserFail(sender, args) {
    //alert('Failed to get user name. Error:' + args.get_message());
}
/*
 *Callout
 */

var registerCallout = function () {
    var itemCtx = {};
    itemCtx.Templates = {};
    itemCtx.BaseViewID = "Callout";
    itemCtx.ListTemplateType = 101;
    itemCtx.Templates.Footer = function (itemCtx) {
        return CalloutRenderFooterTemplate(itemCtx, AddCustomAction, renderECB);
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(itemCtx);
}
var AddCustomAction = function (renderCtx, calloutActionMenu) {
    var listItem = renderCtx.CurrentItem;
    var lookupId = listItem["FK_ID"];
    if (!lookupId) {} else {
        var lookupUrl = "/docmentcenter/Lists/ManagementSystemApproval/Item/displayifs.aspx?ID=" + lookupId[0].lookupId;
        calloutActionMenu.addAction(new CalloutAction({
            text: "审批记录",
            tooltip: "查看审批记录",
            onClickCallback: function () {
                window.open(lookupUrl);
            }
        }));
    }
    if (KeyDown || listItem["Title"] == "流程表格") {
        var fileUrl = "/docmentcenter/DocLib/Forms/newdisp.aspx?ID=" + listItem.ID;
        calloutActionMenu.addAction(new CalloutAction({
            text: "下载文档",
            tooltip: "选择相应Logo版本",
            onClickCallback: function () {
                window.open(fileUrl);
            }
        }));
    }
    if (KeyPrint) {
        var printUrl = "/docmentcenter/ManagementSystemForm/PrintAdd.aspx?ID=" + listItem.ID;
        calloutActionMenu.addAction(new CalloutAction({
            text: "申请打印",
            tooltip: "申请打印",
            onClickCallback: function () {
                window.open(printUrl);
            }
        }));
    }
}
RegisterRenderView();

function RegisterRenderView() {
    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.Fields = {
        'FK_ID': {
            'View': renderFK_ID
        }
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
}

function renderFK_ID(ctx) {
    var lookupId;
    var field = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
    if (field.length > 0) {
        lookupId = field[0].lookupId;
    }
    var url = "/docmentcenter/Lists/ManagementSystemApproval/Item/displayifs.aspx?ID=" + lookupId;
    var ret;
    if (lookupId) {
        ret = "<a href=" + url + " title='点击查看' class='btn btn-success btn-xs' target='_blank'><i class='fa fa-eye mg-r-xs'></i>查看审批记录</a>";
    } else {
        ret = "";
    }
    return ret;
}

分享

文章导航

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*