在另一个旁边添加按钮的最聪明方法是什么:"新建,转移,分享"?
是否有可以创建自定义操作的位置?或者我是否需要通过JSLink覆盖?
答案 0 :(得分:0)
至少我解决了这个问题。我的代码有点硬编码,但我会对它进行排序。 我添加了一个" mutationobserver"发现OOTB按钮"分享"被禁用或启用。 如果启用,则仅选择一个项目。 然后我在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);
})();