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 123 124 125 126 127 128 129 130 131 132
| <script type="text/javascript" src="/_layouts/jQuery/jquery.min.js"></script>
<script type="text/javascript">
function CreateParentInputCheckBox(webPartId)
{ return $("<th nowrap scope='col' class='ms-vh2'></th>").append(
$("<input type='checkbox' title='(de)select all items' />").attr("id", webPartId + "0").click(function()
{ var checked = $(this).attr("checked");$("[id^=" + webPartId + "_]").attr("checked", checked); })
);
}
function CreateChildInputCheckBox(webPartId, itemId)
{
return $("<td></td>").append($("<input type='checkbox' />").attr("id", webPartId + "_" + itemId).val(itemId).click(function()
{ $("#" + webPartId + "0").attr("checked", $(this).attr("checked") && $("[id^=" + webPartId + "_]:not(:checked)").length == 0); })
);
}
function AddCheckBoxesToListView(webPartId)
{
$("#" + webPartId + " table.ms-listviewtable>tbody").find(">tr.ms-viewheadertr").prepend(CreateParentInputCheckBox(webPartId)).end()
.find(">tr:not(.ms-viewheadertr)").each(function()
{ var itemId = $(this).find("td.ms-vb-title>table[id]").attr("id");
if (itemId)
{
$(this).prepend(CreateChildInputCheckBox(webPartId, itemId));
}
});
}
function IsSelectable(webPartId)
{
var selectableItems = $("#" + webPartId + " table.ms-listviewtable>tbody>tr:not(.ms-viewheadertr)>td.ms-vb-title>table[id]").length;
return selectableItems > 0;
}
function RemoveCheckBoxesFromListView(webPartId)
{
$("[id^=" + webPartId + "_], #" + webPartId + "0").parent().remove();
}
function GetSelectedItemsString(webPartId) {
return GetSelectedItemsArray(webPartId).join(",");
}
/*
function GetSelectedItemsString(webPartId)
{
var selectedIds = new Array();
$("[id^=" + webPartId + "_]:checked").each(function()
{
selectedIds.push($(this).val());
});
return selectedIds.join(",");
}
*/
function ListItemSelection_ButtonClick(senderId, webPartId)
{
//jQueryon mozilla does not work with namespaces. We have to work with plain old javascript here...
var sender = document.getElementById(senderId);
if (sender.getAttribute("remove"))
{
RemoveCheckBoxesFromListView(webPartId);
sender.setAttribute("text" ,"Enable item selection");
sender.setAttribute("description", "Enable the selection of items.");
sender.removeAttribute("remove");
}
else
{
AddCheckBoxesToListView(webPartId);
sender.setAttribute("text", "Disable item selection")
sender.setAttribute("description", "Disable the selection of items.");
sender.setAttribute("remove", true);
}
}
function ListItemSelection_Init(senderId, webPartId)
{
if (!IsSelectable(webPartId))
{
var sender = document.getElementById(senderId);
sender.parentNode.removeChild(sender);
}
}
/* Add this function */
function GetSelectedItemsArray(webPartId){
var selectedIds = new Array();
$("[id^=" + webPartId + "_]:checked")
.each(function() {
selectedIds.push($(this).val());
});
return selectedIds;
}
var wpID; // Used to identify the current webpart. We need this to find out where to apply the checkboxes
var existingMethod = ExpGroupReceiveData; // overriding ExpGroupReceiveData method to make it possible to add checkboxes to received items
ExpGroupReceiveData = function(){
existingMethod.apply(this , arguments); // apply the original properties of the function
if (!wpID){ // let's identify the webpart in question
wpID = $('tbody#titl'+arguments[1]).parents('div[id^=WebPart]').attr('id');
}
var selectedItems = GetSelectedItemsArray(wpID); // let's save state of selected checkboxes
RemoveCheckBoxesFromListView(wpID); // remove existing checkboxes
AddCheckBoxesToListView(wpID); // add checkboxes to webpart group items
$.each(selectedItems, function(i){ // reapply state to previously selected checkboxes
$('#' + wpID + '_' + selectedItems[i]).attr("checked", true);
});
}
</script>
<script type="text/javascript">
$(function(){
//Spécification à la main du qualifier qui m'intéresse
var monWP ='WebPartWPQ1';
AddCheckBoxesToListView(monWP);
$('#showSelect').click(function(){
//alert(GetSelectedItemsArray(monWP));
$('#selectedItemsList').html(GetSelectedItemsArray(monWP).join(';'));
});
});
</script>
<a href="#" id="showSelect">Cliquer ici pour voir les éléments</a>
<div id="selectedItemsList"></div> |
Partager