SharePoint 自定义按钮 ListViewWebPart header
SharePoint Custom Button ListViewWebPart header
将一个按钮添加到另一个旁边的最聪明的方法是什么:"New, Transfer, Share"?
是否有可以创建自定义操作的位置?或者我需要通过 JSLink 覆盖吗?
我至少暂时解决了。我的代码有点硬编码,但我会对其进行排序。
如果 OOTB 按钮 "Share" 被禁用或启用,我添加了一个 "mutationobserver" 来发现。
如果启用,则仅选择一项。
然后我在 JSOM 中进行额外检查以查看选择了多少项目,具体取决于我使用 JQUERY.
显示和隐藏某些按钮
window.SIMON = window.SIMON || {};
window.SIMON.Library = {
editFunction: function () {
var ctx = new SP.ClientContext.get_current();
var item = SP.ListOperation.Selection.getSelectedItems(ctx)[0];
var list = ctx.get_web().get_lists().getById(SP.ListOperation.Selection.getSelectedList(ctx));
ctx.load(list, 'DefaultEditFormUrl');
ctx.executeQueryAsync(function () {
var editFormUrl = list.get_defaultEditFormUrl() + "?ID=" + item.id;
openInDialog(800, 600, false, true, false, editFormUrl);
}, function (sender, args) {
console.log(args.get_message());
});
},
displayFunction: function () {
var ctx = new SP.ClientContext.get_current();
var item = SP.ListOperation.Selection.getSelectedItems(ctx)[0];
var list = ctx.get_web().get_lists().getById(SP.ListOperation.Selection.getSelectedList(ctx));
ctx.load(list, 'DefaultDisplayFormUrl');
ctx.executeQueryAsync(function () {
var viewFormUrl = list.get_defaultDisplayFormUrl() + "?ID=" + item.id;
openInDialog(800, 600, false, true, false, viewFormUrl);
}, function (sender, args) {
console.log(args.get_message());
});
},
PostRender: function (ctx) {
if (!$('#QCB1_Button4').length > 0) {
$('#QCB1 > ul.ms-qcb-zone.ms-qcb-leftzone').append(
'<li class="ms-qcb-item"><button class="ms-qcb-button ms-qcb-buttons-alignmentfix js-listview-qcbShareButton js-callout-body js-qcb-button ms-disabled"'
+ 'onclick="javascript:initShare();" disabled="disabled" type="button" title="Bjud in personer till markerade dokument eller mappar." id="QCB1_Button4" role="button" aira-expanded="false">'
+ '<span class="ms-qcb-glyph ms-listview-glyph-withmargin ms-core-form-heading ms-disabled"></span>Dela flera<span class="ms-qcb-glyph "></span></button></li>');
$('#QCB1 > ul.ms-qcb-zone.ms-qcb-leftzone').append(
'<li class="ms-qcb-item"><button class="ms-qcb-button ms-qcb-buttons-alignmentfix js-listview-qcbShareButton js-callout-body js-qcb-button ms-disabled"'
+ 'onclick="javascript:window.SIMON.Library.editFunction();" disabled="disabled" type="button" title="Bjud in personer till markerade dokument eller mappar." id="QCB1_Button5" role="button" aira-expanded="false">'
+ '<span class="ms-disabled"><img class="ms-disabled" border="0" alt="redigera" src="/_layouts/15/images/edititem.gif?rev=43" style="opacity: 0.3; width: 17px; vertical-align: bottom;"></span> Redigera<span class="ms-qcb-glyph "></span></button></li>');
$('#QCB1 > ul.ms-qcb-zone.ms-qcb-leftzone').append(
'<li class="ms-qcb-item"><button class="ms-qcb-button ms-qcb-buttons-alignmentfix js-listview-qcbShareButton js-callout-body js-qcb-button ms-disabled"'
+ 'onclick="javascript:window.SIMON.Library.displayFunction();" disabled="disabled" type="button" title="Bjud in personer till markerade dokument eller mappar." id="QCB1_Button6" role="button" aira-expanded="false">'
+ '<span class="ms-disabled"><span class="icon viewicon" style="opacity: 0.3; width: 17px; vertical-align: bottom;"></span></span> Visa<span class="ms-qcb-glyph "></span></button></li>');
var input = $('#QCB1_Button3');
var observer = new MutationObserver(function (mutations) {
for (var i = 0, mutation; mutation = mutations[i]; i++) {
if (mutation.attributeName == 'disabled') {
if (SP.ListOperation.Selection.getSelectedItems(new SP.ClientContext.get_current()).length > 1) {
$('#QCB1_Button4').removeAttr("disabled");
$('#QCB1_Button4').removeClass('ms-disabled');
$('#QCB1_Button4 span').removeClass('ms-disabled');
$('#QCB1_Button5').attr("disabled", 'disabled');
$('#QCB1_Button5').addClass('ms-disabled');
$('#QCB1_Button5 img').css('opacity', '0.3');
$('#QCB1_Button6').attr("disabled", 'disabled');
$('#QCB1_Button6').addClass('ms-disabled');
$('#QCB1_Button6 span').css('opacity', '0.3');
} else if (SP.ListOperation.Selection.getSelectedItems(new SP.ClientContext.get_current()).length === 1) {
$('#QCB1_Button4').attr("disabled", 'disabled');
$('#QCB1_Button4').addClass('ms-disabled');
$('#QCB1_Button4 span').addClass('ms-disabled');
$('#QCB1_Button5').removeAttr("disabled");
$('#QCB1_Button5').removeClass('ms-disabled');
$('#QCB1_Button5 img').css('opacity', '1.0');
$('#QCB1_Button6').removeAttr("disabled");
$('#QCB1_Button6').removeClass('ms-disabled');
$('#QCB1_Button6 span').css('opacity', '1.0');
}
else {
$('#QCB1_Button5').attr("disabled", 'disabled');
$('#QCB1_Button5').addClass('ms-disabled');
$('#QCB1_Button5 img').css('opacity', '0.3');
$('#QCB1_Button4').attr("disabled", 'disabled');
$('#QCB1_Button4').addClass('ms-disabled');
$('#QCB1_Button4 span').addClass('ms-disabled');
$('#QCB1_Button6').attr("disabled", 'disabled');
$('#QCB1_Button6').addClass('ms-disabled');
$('#QCB1_Button6 span').css('opacity', '0.3');
}
}
};
});
observer.observe(input[0], { attributes: true });
}
}
};
(function () {
var ctx = {};
ctx.OnPostRender = SIMON.Library.PostRender;
ctx.Templates = {};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
将一个按钮添加到另一个旁边的最聪明的方法是什么:"New, Transfer, Share"?
是否有可以创建自定义操作的位置?或者我需要通过 JSLink 覆盖吗?
我至少暂时解决了。我的代码有点硬编码,但我会对其进行排序。 如果 OOTB 按钮 "Share" 被禁用或启用,我添加了一个 "mutationobserver" 来发现。 如果启用,则仅选择一项。 然后我在 JSOM 中进行额外检查以查看选择了多少项目,具体取决于我使用 JQUERY.
显示和隐藏某些按钮window.SIMON = window.SIMON || {};
window.SIMON.Library = {
editFunction: function () {
var ctx = new SP.ClientContext.get_current();
var item = SP.ListOperation.Selection.getSelectedItems(ctx)[0];
var list = ctx.get_web().get_lists().getById(SP.ListOperation.Selection.getSelectedList(ctx));
ctx.load(list, 'DefaultEditFormUrl');
ctx.executeQueryAsync(function () {
var editFormUrl = list.get_defaultEditFormUrl() + "?ID=" + item.id;
openInDialog(800, 600, false, true, false, editFormUrl);
}, function (sender, args) {
console.log(args.get_message());
});
},
displayFunction: function () {
var ctx = new SP.ClientContext.get_current();
var item = SP.ListOperation.Selection.getSelectedItems(ctx)[0];
var list = ctx.get_web().get_lists().getById(SP.ListOperation.Selection.getSelectedList(ctx));
ctx.load(list, 'DefaultDisplayFormUrl');
ctx.executeQueryAsync(function () {
var viewFormUrl = list.get_defaultDisplayFormUrl() + "?ID=" + item.id;
openInDialog(800, 600, false, true, false, viewFormUrl);
}, function (sender, args) {
console.log(args.get_message());
});
},
PostRender: function (ctx) {
if (!$('#QCB1_Button4').length > 0) {
$('#QCB1 > ul.ms-qcb-zone.ms-qcb-leftzone').append(
'<li class="ms-qcb-item"><button class="ms-qcb-button ms-qcb-buttons-alignmentfix js-listview-qcbShareButton js-callout-body js-qcb-button ms-disabled"'
+ 'onclick="javascript:initShare();" disabled="disabled" type="button" title="Bjud in personer till markerade dokument eller mappar." id="QCB1_Button4" role="button" aira-expanded="false">'
+ '<span class="ms-qcb-glyph ms-listview-glyph-withmargin ms-core-form-heading ms-disabled"></span>Dela flera<span class="ms-qcb-glyph "></span></button></li>');
$('#QCB1 > ul.ms-qcb-zone.ms-qcb-leftzone').append(
'<li class="ms-qcb-item"><button class="ms-qcb-button ms-qcb-buttons-alignmentfix js-listview-qcbShareButton js-callout-body js-qcb-button ms-disabled"'
+ 'onclick="javascript:window.SIMON.Library.editFunction();" disabled="disabled" type="button" title="Bjud in personer till markerade dokument eller mappar." id="QCB1_Button5" role="button" aira-expanded="false">'
+ '<span class="ms-disabled"><img class="ms-disabled" border="0" alt="redigera" src="/_layouts/15/images/edititem.gif?rev=43" style="opacity: 0.3; width: 17px; vertical-align: bottom;"></span> Redigera<span class="ms-qcb-glyph "></span></button></li>');
$('#QCB1 > ul.ms-qcb-zone.ms-qcb-leftzone').append(
'<li class="ms-qcb-item"><button class="ms-qcb-button ms-qcb-buttons-alignmentfix js-listview-qcbShareButton js-callout-body js-qcb-button ms-disabled"'
+ 'onclick="javascript:window.SIMON.Library.displayFunction();" disabled="disabled" type="button" title="Bjud in personer till markerade dokument eller mappar." id="QCB1_Button6" role="button" aira-expanded="false">'
+ '<span class="ms-disabled"><span class="icon viewicon" style="opacity: 0.3; width: 17px; vertical-align: bottom;"></span></span> Visa<span class="ms-qcb-glyph "></span></button></li>');
var input = $('#QCB1_Button3');
var observer = new MutationObserver(function (mutations) {
for (var i = 0, mutation; mutation = mutations[i]; i++) {
if (mutation.attributeName == 'disabled') {
if (SP.ListOperation.Selection.getSelectedItems(new SP.ClientContext.get_current()).length > 1) {
$('#QCB1_Button4').removeAttr("disabled");
$('#QCB1_Button4').removeClass('ms-disabled');
$('#QCB1_Button4 span').removeClass('ms-disabled');
$('#QCB1_Button5').attr("disabled", 'disabled');
$('#QCB1_Button5').addClass('ms-disabled');
$('#QCB1_Button5 img').css('opacity', '0.3');
$('#QCB1_Button6').attr("disabled", 'disabled');
$('#QCB1_Button6').addClass('ms-disabled');
$('#QCB1_Button6 span').css('opacity', '0.3');
} else if (SP.ListOperation.Selection.getSelectedItems(new SP.ClientContext.get_current()).length === 1) {
$('#QCB1_Button4').attr("disabled", 'disabled');
$('#QCB1_Button4').addClass('ms-disabled');
$('#QCB1_Button4 span').addClass('ms-disabled');
$('#QCB1_Button5').removeAttr("disabled");
$('#QCB1_Button5').removeClass('ms-disabled');
$('#QCB1_Button5 img').css('opacity', '1.0');
$('#QCB1_Button6').removeAttr("disabled");
$('#QCB1_Button6').removeClass('ms-disabled');
$('#QCB1_Button6 span').css('opacity', '1.0');
}
else {
$('#QCB1_Button5').attr("disabled", 'disabled');
$('#QCB1_Button5').addClass('ms-disabled');
$('#QCB1_Button5 img').css('opacity', '0.3');
$('#QCB1_Button4').attr("disabled", 'disabled');
$('#QCB1_Button4').addClass('ms-disabled');
$('#QCB1_Button4 span').addClass('ms-disabled');
$('#QCB1_Button6').attr("disabled", 'disabled');
$('#QCB1_Button6').addClass('ms-disabled');
$('#QCB1_Button6 span').css('opacity', '0.3');
}
}
};
});
observer.observe(input[0], { attributes: true });
}
}
};
(function () {
var ctx = {};
ctx.OnPostRender = SIMON.Library.PostRender;
ctx.Templates = {};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();