egroupware_official/api/js/etemplate/et2_dataview_view_tile.js

89 lines
2.8 KiB
JavaScript
Raw Normal View History

2014-12-31 18:55:06 +01:00
/**
* EGroupware eTemplate2 - dataview code
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage dataview
* @link https://www.egroupware.org
2014-12-31 18:55:06 +01:00
* @author Nathan Gray
* @copyright Nathan Gray 2014
* @version $Id: et2_dataview_view_container_1.js 46338 2014-03-20 09:40:37Z ralfbecker $
*/
/*egw:uses
2020-01-31 21:07:27 +01:00
/vendor/bower-asset/jquery/dist/jquery.js;
et2_dataview_interfaces;
2014-12-31 18:55:06 +01:00
*/
import { et2_dataview_row } from "./et2_dataview_view_row";
2014-12-31 18:55:06 +01:00
/**
* Displays tiles or thumbnails (squares) instead of full rows.
*
* It's important that the template specifies a fixed width and height (via CSS)
* so that the rows and columns work out properly.
*
*/
export class et2_dataview_tile extends et2_dataview_row {
2020-01-31 21:07:27 +01:00
/**
* Creates the row container. Use the "setRow" function to load the actual
* row content.
*
* @param _parent is the row parent container.
* @memberOf et2_dataview_row
*/
constructor(_parent) {
2020-01-31 21:07:27 +01:00
// Call the inherited constructor
super(_parent);
this.columns = 4;
2020-01-31 21:07:27 +01:00
// Make sure the needed class is there to get the CSS
this.tr.addClass('tile');
2020-01-31 21:07:27 +01:00
}
makeExpandable(_expandable, _callback, _context) {
2020-01-31 21:07:27 +01:00
// Nope. It mostly works, it's just weird.
}
getAvgHeightData() {
2020-01-31 21:07:27 +01:00
var res = {
"avgHeight": this.getHeight() / this.columns,
"avgCount": this.columns
};
return res;
}
2020-01-31 21:07:27 +01:00
/**
* Returns the height for the tile.
*
* This is where we do the magic. If a new row should start, we return the proper
* height. If this should be another tile in the same row, we say it has 0 height.
* @returns {Number}
*/
getHeight() {
2020-01-31 21:07:27 +01:00
if (this._index % this.columns == 0) {
return super.getHeight();
2020-01-31 21:07:27 +01:00
}
else {
return 0;
}
}
2020-01-31 21:07:27 +01:00
/**
* Broadcasts an invalidation through the container tree. Marks the own
* height as invalid.
*/
invalidate() {
2020-01-31 21:07:27 +01:00
if (this._inTree && this.tr) {
var template_width = jQuery('.innerContainer', this.tr).children().outerWidth(true);
if (template_width) {
this.tr.css('width', template_width + (this.tr.outerWidth(true) - this.tr.width()));
}
}
this._recalculate_columns();
super.invalidate();
}
2020-01-31 21:07:27 +01:00
/**
* Recalculate how many columns we can fit in a row.
* While browser takes care of the actual layout, we need this for proper
* pagination.
*/
_recalculate_columns() {
2020-01-31 21:07:27 +01:00
if (this._inTree && this.tr && this.tr.parent()) {
this.columns = Math.max(1, parseInt(this.tr.parent().innerWidth() / this.tr.outerWidth(true)));
}
}
}
2020-01-31 21:07:27 +01:00
//# sourceMappingURL=et2_dataview_view_tile.js.map