diff --git a/css/TableListField.css b/css/TableListField.css
index 61e3968cb..7f02872d8 100644
--- a/css/TableListField.css
+++ b/css/TableListField.css
@@ -181,6 +181,18 @@ form .TableField .message {
width: auto;
}
+.TableListField .selectOptions {
+ overflow: auto;
+ font: 1.3em;
+ margin: 0;
+ padding: 0;
+}
+
+.TableListField .selectOptions li {
+ float: left;
+ margin: 0px 5px;
+}
+
.TableListField .PageControls {
margin: 5px 0;
text-align:center;
diff --git a/forms/TableListField.php b/forms/TableListField.php
index cd66cb257..2370220a9 100755
--- a/forms/TableListField.php
+++ b/forms/TableListField.php
@@ -88,6 +88,11 @@ class TableListField extends FormField {
public $MarkableTitle = null;
+ /**
+ * @var array See {@link SelectOptions()}
+ */
+ protected $selectOptions = array();
+
/**
* @var $readOnly boolean Deprecated, please use $permssions instead
*/
@@ -1199,14 +1204,57 @@ JS
return $value;
}
- /**
- * #########################
- * Highlighting
- * #########################
- */
function setHighlightConditions($conditions) {
$this->highlightConditions = $conditions;
}
+
+ /**
+ * See {@link SelectOptions()} for introduction.
+ *
+ * @param $options array Options to add, key being a unique identifier of the action,
+ * and value a title for the rendered link element (can contain HTML).
+ * The keys for 'all' and 'none' have special behaviour associated
+ * through TableListField.js JavaScript.
+ * For any other key, the JavaScript automatically checks all checkboxes contained in
+ *
elements with a matching classname.
+ */
+ function addSelectOptions($options){
+ foreach($options as $k => $title)
+ $this->selectOptions[$k] = $title;
+ }
+
+ /**
+ * Remove one all more table's {@link $selectOptions}
+ *
+ * @param $optionsNames array
+ */
+ function removeSelectOptions($names){
+ foreach($names as $name){
+ unset($this->selectOptions[trim($name)]);
+ }
+ }
+
+ /**
+ * Return the table's {@link $selectOptions}.
+ * Used to toggle checkboxes for each table row through button elements.
+ *
+ * Requires {@link Markable()} to return TRUE.
+ * This is only functional with JavaScript enabled.
+ *
+ * @return DataObjectSet of ArrayData objects
+ */
+ function SelectOptions(){
+ if(!$this->selectOptions) return;
+
+ $selectOptionsSet = new DataObjectSet();
+ foreach($this->selectOptions as $k => $v) {
+ $selectOptionsSet->push(new ArrayData(array(
+ 'Key' => $k,
+ 'Value' => $v
+ )));
+ }
+ return $selectOptionsSet;
+ }
}
/**
@@ -1381,6 +1429,27 @@ class TableListField_Item extends ViewableData {
return "item->ID}\" />";
}
+ /**
+ * According to {@link TableListField->selectOptions}, each record will check if the options' key on the object is true,
+ * if it is true, add the key as a class to the record
+ *
+ * @return string Value for a 'class' HTML attribute.
+ */
+ function SelectOptionClasses(){
+ $tagArray = array('markingcheckbox');
+ $options = $this->parent->selectOptions;
+ if(!empty($options)){
+ foreach($options as $optionKey => $optionTitle){
+ if($optionKey !== 'all' && $optionKey !== 'none'){
+ if($this->$optionKey) {
+ $tagArray[] = $optionKey;
+ }
+ }
+ }
+ }
+ return implode(" ",$tagArray);
+ }
+
function HighlightClasses() {
$classes = array();
foreach($this->parent->highlightConditions as $condition) {
diff --git a/javascript/TableListField.js b/javascript/TableListField.js
index 0259673af..d2148e160 100755
--- a/javascript/TableListField.js
+++ b/javascript/TableListField.js
@@ -5,7 +5,7 @@ TableListField.prototype = {
initialize: function() {
var rules = {};
-
+
rules['#'+this.id+' table.data a.deletelink'] = {
onclick: this.deleteRecord.bind(this)
};
@@ -36,7 +36,12 @@ TableListField.prototype = {
// do nothing for clicks in marking box cells (e.g. if checkbox is missed)
}
};
-
+
+ // rules for selection options on click event
+ rules['#'+this.id+' .selectOptions a'] = {
+ onclick: this.markRecords.bind(this)
+ };
+
// initialize summary (if needed)
// TODO Breaks with nested divs
var summaryCols = $$('tfoot tr.summary td', this);
@@ -122,7 +127,51 @@ TableListField.prototype = {
this._summarise();
},
- refresh: function(e, params, oncomplete) {
+ /**
+ * according to the clicked element in "Select bar", mark records that have same class as the element.
+ */
+ markRecords: function(e){
+ var el = Event.element(e);
+ if(el.nodeName != "a") el = Event.findElement(e,"a");
+
+ if(el.rel == "all"){
+ this.markAll();
+ }else if(el.rel == 'none') {
+ this.unmarkAll();
+ }else{
+ this.unmarkAll();
+ var records = $$('#' + this.id + ' td.' + el.rel + ' input.checkbox');
+ var i=0;
+ for(i; i |