Add empty row placeholder

This commit is contained in:
Nathan Gray 2013-03-13 18:42:03 +00:00
parent 656c3f3eb5
commit 3c69b26525
6 changed files with 87 additions and 3 deletions

View File

@ -72,6 +72,7 @@
* 'select_all' => // O boolean value of select_all checkbox, reference to above value for key 'select_all'
* 'favorites' => // I boolean|array True to enable favorites, or an array of additional, app specific settings to include
* in the saved filters (eg: pm_id)
* 'placeholder' => // I String Optional text to display in the empty row placeholder. If not provided, it's "No matches found."
*/
class etemplate_widget_nextmatch extends etemplate_widget
{

View File

@ -707,11 +707,51 @@ var et2_dataview_controller = Class.extend({
this.self._mergeResult(res, this.start + order.length,
idxMap.length - order.length, _response.total);
if(_response.total == 0)
{
this.self._emptyRow();
}
else
{
var row = $j(".egwGridView_empty",this.self._grid.innerTbody).remove();
this.self._selectionMgr.unregisterRow("",0,row.get(0));
}
// Update the total element count in the grid
this.self._grid.setTotalCount(_response.total);
this.self._selectionMgr.setTotalCount(_response.total);
},
/**
* Insert an empty / placeholder row when there is no data to display
*/
_emptyRow: function()
{
$j(".egwGridView_empty",this._grid.innerTbody).remove();
if(typeof this._grid._rowProvider != "undefined" && this._grid._rowProvider.getPrototype("empty"))
{
var placeholder = this._grid._rowProvider.getPrototype("empty");
if($j("td",placeholder).length == 1)
{
$j("td",placeholder).css("width",this._grid.outerCell.width() + "px")
}
placeholder.appendTo(this._grid.innerTbody);
// Get the action links if the links callback is set
var links = null;
if (this._linkCallback)
{
links = this._linkCallback.call(
this._context,
{},
0,
""
);
}
this._selectionMgr.registerRow("",0,placeholder.get(0), links);
}
},
/**
* Callback function used by the selection manager to translate the selected
* range to uids.

View File

@ -683,6 +683,8 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], {
null,
this.options.settings.actions
);
// Need to trigger empty row the first time
if(total == 0) this.controller._emptyRow();
// Set custom data cache prefix
if(this.options.settings.dataStorePrefix)

View File

@ -180,12 +180,31 @@ var et2_nextmatch_controller = et2_dataview_controller.extend(
},
/**
* Returns the action links for a given data row -- currently these are
* Returns the names of action links for a given data row -- currently these are
* always the same links, as we controll enabled/disabled over the row
* classes.
* classes, unless the row UID is "", then it's an 'empty' row.
*
* The empty row placeholder can still have actions, but nothing that requires
* an actual UID.
*
* @TODO: Currently empty row is just add, need to actually filter somehow. Here
* might not be the right place.
*
* @param _data Object The data for the row
* @param _idx int The row index
* @param _uid String The row's ID
*
* @return Array List of action names that valid for the row
*/
_linkCallback: function (_data, _idx, _uid) {
return this._actionLinks;
if(_uid.trim() != "")
{
return this._actionLinks;
}
// No UID, so return a filtered list of actions that doesn't need a UID
var links = ["add"];
return links;
},

View File

@ -32,6 +32,8 @@ var et2_nextmatch_rowProvider = Class.extend({
this._rowProvider = _rowProvider;
this._subgridCallback = _subgridCallback;
this._context = _context;
this._createEmptyPrototype();
},
/**
@ -179,6 +181,25 @@ var et2_nextmatch_rowProvider = Class.extend({
},
/**
* Placeholder for empty row
*
* The empty row placeholder is used when there are no results to display.
* This allows the user to still have a drop target, or use actions that
* do not require a row ID, such as 'Add new'.
*/
_createEmptyPrototype: function() {
var label = this._context && this._context.options && this._context.options.settings.placeholder;
var placeholder = $j(document.createElement("td"))
.attr("colspan",this._rowProvider.getColumnCount())
.css("height","19px")
.text(typeof label != "undefined" && label ? label : egw().lang("No matches found"))
this._rowProvider._prototypes["empty"] = $j(document.createElement("tr"))
.addClass("egwGridView_empty")
.append(placeholder);
},
/** -- PRIVATE FUNCTIONS -- **/
/**

View File

@ -292,6 +292,7 @@ nextmatch sortheader etemplate en Nextmatch sort header
no column to swap with !!! etemplate en No column to swap with!
no file etemplate en No file
no filename given or selected via browse... etemplate en No filename
no filters etemplate en No filters
no matches found etemplate en No matches found.
no rights to export more than %1 entries! common en No rights to export more than %1 entries!
no row to swap with !!! etemplate en No row to swap with!