Manage sets of 'Post' items
!! This description needs updating for E1.0 !!
The management overview for resource-based items such as Posts uses Ditto to list them, with links to the resource containing the relevant PubKit snippet. Additional data about the ID of the item and command to be applied is added either by adding a query string to the URL (GET), or by creating a mini-form for each item with the data in hidden INPUT fields (POST). You can use Javascript to simulate hyperlinks for the Submit action in the forms.
The Ditto template chunk for each item given below (NB this is copied in from a real site, not the news page demo in the package) also demonstrates the use of the SetField and UpdateTv commands. These let you change the value of any individual document field or custom TV via the GET or POST variables. In this example, you can manually override the Published status of an item or move it to and from the archive section (by updating its pkArchive flag) just by clicking on the link. This is powerful magic, which may lead to anomalies, so use with caution! (Cue: Sorceror's Apprentice music).
Here's the content of a Manage News Items page:
<input type="submit" value="Add item" />
</form>
<form id="multiDo" action="bulk-action" method="post">
<select id="bulkAction" size="1">
<option value="" selected="selected">- Bulk action -</option>
<option value="updateTv|pkArchive|1">Archive</option>
<option value="setField|published|0">Hide</option>
<option value="setField|published|1">Show</option>
</select>
<input type="hidden" name="docId" value = "" />
<input type="hidden" name="returnId" value = "[*id*]" />
<input type="hidden" name="command" value = "" />
<input type="hidden" name="docField" value = "" />
<input type="hidden" name="tvName" value = "" />
<input type="hidden" name="myValue" value="" />
<input type="submit" id="doBulkAction" value="Apply" />
</form>
<div>
<table id="cPanel">
<thead><tr>
<th><input type="checkbox" id="selectAll" /></th>
<th colspan="2">Item & status</th><th>Date</th><th>Publish</th>
<th>To</th></tr></thead>
<tbody>
[!Ditto?parents=`940`
&tpl=`pk.news.manage.tpl`
&showPublishedOnly=`0`
&filter=`pkArchive,1,2`
&orderBy=`pkDate DESC,editedon DESC`
&extenders=`pkStatus`
&hiddenFields=`1`
!]
</tbody>
</table>
</div>
<!-- form template to be filled in and submitted by jQuery -->
<form id="commands" action="pkdemo-news-edit" method="post">
<input type="hidden" name="docId" />
<input type="hidden" name="returnId" value="[*id*]" />
<input type="hidden" name="command" />
<input type="hidden" name="docField" />
<input type="hidden" name="tvName" />
<input type="hidden" name="myValue" />
<input type="hidden" name="[+unpubdate+]" />
</form>
<!-- ===================================================== -->
<script>
// single item commands
jQuery('.cButton').click(function(event) {
oCell = jQuery(this);
commandCluster = oCell.attr('rel').split('|');
var command = commandCluster[0];
if (commandCluster[0] == 'setField') {
jQuery('input[name="docField"]').val(commandCluster[1]);
jQuery('input[name="myValue"]').val(commandCluster[2]);
} else if (commandCluster[0] == 'updateTv') {
jQuery('input[name="tvName"]').val(commandCluster[1]);
jQuery('input[name="myValue"]').val(commandCluster[2]);
}
docId = oCell.parent().attr('id');
jQuery('input[name="docId"]').val(docId);
jQuery('input[name="command"]').val(command);
jQuery('#commands').submit();
});
// bulk actions
jQuery("#doBulkAction").click(function(event) {
var actionList = [];
action = jQuery("#bulkAction").val();
if (action.length > 0) {
var commandElements = action.split('|');
jQuery('input[name="command"]').val(commandElements[0]);
jQuery('input[name="docField"]').val(commandElements[1]);
jQuery('input[name="tvName"]').val(commandElements[1]);
jQuery('input[name="myValue"]').val(commandElements[2]);
// gather values of all checked IDs
jQuery('input:checkbox[name="bulk[]"]:checked').each(function() {
actionList.push(jQuery(this).val());
});
jQuery('input[name="docId"]').val(actionList);
if (actionList.length < 1) {
event.preventDefault();
alert('No items selected');
}
} else {
event.preventDefault();
alert('No action selected');
}
});
// (de)select all box
jQuery('#selectAll').change(function(){
var bulkBoxes = jQuery('input:checkbox[name="bulk[]"]');
if (this.checked) {
bulkBoxes.attr('checked', 'checked');
} else {
bulkBoxes.removeAttr('checked');
}
})
</script>
The Ditto template chunk news.manage.tpl (the PHx modifiers that format status indicators and display dates conditionally are listed elsewhere):
<td class="flagColumn"><input type="checkbox" class="bulky" name="bulk[]" value="[+id+]" /> </td>
<td class="flagColumn [+status:statusFormat=`flag`+]">[+status+]</td>
<td class="cButton" rel="edit" title="[+pkNews+]: [+longtitle+]">[+pagetitle:limit=`32`+]</td>
<td class="dateColumn [+status:statusFormat=`start`+]">[+pkDate:date=`%d-%m-%y`+]</td>
<td class="dateColumn [+status:statusFormat=`pub`+]">[+pub_date:dateIfSet=`%d-%m-%y`+]</td>
<td class="dateColumn [+status:statusFormat=`end`+]">[+pkDateTo:dateIfSet=`%d-%m-%y`+]</td>
<td class="cButton" rel="delete"><img src="assets/images/icons/delete.png" alt="Delete" title="Delete" /></td>
<td class="cButton" rel="setField|published|[+phx:if=`[+published+]`:is=`0`:then=`1`:else=`0`+]">
[+phx:if=`[+published+]`:is=`0`:then=`<img src="assets/images/icons/flag_show.png" alt="Show" title="Show"/>`:else=`<img src="assets/images/icons/flag_hide.png" alt="Hide" title="Hide"/>`+]</td>
<td class="cButton" rel="updateTv|pkArchive|[+phx:if=`[+pkArchive+]`:is=`0`:then=`1`:else=`0`+]">
[+phx:if=`[+pkArchive+]`:ne=`1`:then=`<img src="assets/images/icons/archive.png" alt="Archive" title="Archive">`:else=`<img src="assets/images/icons/unarchive.png" alt="Unarchive" title="Unarchive">`+]</td>
<td class="viewButton"><a href="[~[+id+]~]" target="_blank" title="View"><img src="assets/images/icons/monitor.png" alt="View" />
</a></td>
</tr>