# j-Dashboard

> Komponent očakáva pole objektov.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: sk
Content-SHA256: 42a83e105b0cfa10278c1f4c8deba127abec8b7951a3a9bd01a8d65118fead3e
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

- Podporuje mobilné zariadenia
- Podporuje dotyky
- Pohyblivý
- Preťahovateľné
- Zmena veľkosti

Komponent očakáva `Array` objektov.

__Konfigurácia__:

- `axisX {Number}` veľkosť mriežky osi X (predvolené: `12`)
- `axisY {Number}` veľkosť mriežky osi Y (predvolené: `144`)
- `padding {Number}` výplň medzi miniaplikáciami (predvolené: `10`)
- Oneskorenie inicializácie `delay {Number}` (predvolené: `200`)
- `serviceinterval {Number}` servisný interval (predvolené: `5000`)
- `ondrop {String}` cesta k metóde `function(meta) {}`, ktorá sa vykoná, ak niekto hodí nejaký prvok do oblasti
	- `meta.x` X poloha mriežky
	- `meta.y` Y poloha mriežky
	- Ťahaný prvok `meta.el`
	- `meta.pageX`
	- `meta.pageY`
	- `meta.offsetX`
	- `meta.offsetY`
	- `meta.target`
	- `meta.d` a režim zobrazenia `xs`, `sm`, `md` alebo `lg`
- `noemitresize` zakáže spustenie metódy `resize` vo všetkých vnorených komponentoch (predvolené: `false`)
- `parent {String}` nadradený kontajner, ktorý nastavuje minimálnu výšku (predvolené: `null`)
- `margin {Number}` horný/dolný okraj pre možnosť `parent` (predvolené: `0`)
- `minsizexs {Number}` minimálna veľkosť stĺpca/riadku pre extra malé displeje (predvolené: `2`)
- `minsizesm {Number}` minimálna veľkosť stĺpca/riadku pre malé displeje (predvolené: `2`)
- `minsizemd {Number}` minimálna veľkosť stĺpca/riadku pre stredné displeje (predvolené: `1`)
- `minsizelg {Number}` minimálna veľkosť stĺpca/riadku pre veľké displeje (predvolené: `1`)
- Ikona nastavení `iconsettings {String}`
- Ikona odstránenia `iconremove {String}`
- `change {String}` cesta k metóde `function(type, id)` (vykonaná, ak dashboard zaznamená zmenu `move` alebo `remove`)
- Štýl animácie `animation {Number}`:
	- Nepriehľadnosť `1`
	- `2` stupnica od veľkej po normálnu
	- `3` mierka od malej po normálnu (__predvolená__)
	- `4` otáčanie Z
	- `5` zmena polohy X
	- `6` zmena polohy Y
- `grid {Boolean}` vykresľuje mriežku na pozadí (predvolené: `false`)
- __NEW__: `reanimate {Boolean}` umožňuje animáciu pre zmenu miniaplikácií (predvolené: `false`)

```js
// Component declaration
var component = {

	// Component ID
	id: 'COMPONENT_ID',

	// Positioning
	// You can define specific display size and if the display size is not specified then the component tries to find a size for larger display
	offset: {
		xs: { x: 1, y: 1, width: 6, height: 6 }, // Number means the position in the grid, so e.g. width "2" takes "2" columns in X axis
		lg: { x: 1, y: 1, width: 6, height: 6 }
	},

	html: 'THE CONTENT OF COMPONENT', // or can be raw HTMLElement

	// Default settings
	actions: { move: true, remove: true, resize: true, resizeX: true, resizeY: true, resizeP: false, settings: true },
	// resizeP means: resize "proportionally"

	// Can disable header (default: true)
	header: true,

	// Can delay displaying (in "ms", default: config.delay)
	delay: 0,

	// A component title
	title: 'Title for the component',

	// Custom properties which will be assigned to the instance
	template: Object,
	config: Object,
	// reset: true, // NEW: reloads the component again
	// class: String // adds a class to the item

	make: function(exports, config, el) {

		// @exports {Object}
		// @config {Object}
		// @el {jQuery} a content of the component

		// Handlers (optional):
		exports.destroy = function() {
			// @el {jQuery} a content of the component
			// @this {Instance}

			// is executed when the component is destroyed
		};

		exports.data = function(data, el) {
			// @data {Object}
			// @this {Instance}
			// @el {jQuery} a content element of the component
			// It can be executed via SETTER('dashboard/send', ....)
		};

		exports.service = function(counter, el) {
			// @counter {Number} count of calls
			// @el {jQuery} a content of the component
			// @this {Instance}
			// dashboard will execute this handler each 5 seconds
		};

		exports.focus = function() {
			// Optional, when the "window" is focused the delegate will be executed
		};

		exports.resize = function(width, height, el, display) {
			// @width {Number}
			// @height {Number}
			// @el {jQuery} a content of the component
			// @display {String} a current display size "xs", "sm", "md" or "lg"
			// @this {Instance}
			// is executed when the component is resized
			// @this {Instance}
		};

		exports.settings = function(config, el, elbtn) {
			// @config {Object}
			// @el {jQuery} a content element of the component
			// @elbtn {jQuery} button element
			// is executed when the users clicks on the settings icon
		};

		exports.remove = function(remove) {
			// remove {Function} removes that widget
			remove();
		};

		exports.configure = function() {
			// is executed when the configuration is changed
		};

		// this.meta {Object} a reference to component object
		// this.element {jQuery} a content element of the component
		// this.container {jQuery} a main content element of the component
		// this.main {Object} a reference to Dashboard component
		// this.width {Number} a width of "this.element"
		// this.height {Number} a height of "this.element"
		// this.display {String} a current display size "xs", "sm", "md" or "lg"

		// is executed when the component is making
	}
};

PUSH('components', component);
```

__Metódy__:

- `SETTER('dashboard/send', id, body)` odosiela údaje do všetkých miniaplikácií, ktoré obsahujú delegáta `data`
	- `id {String}`
		- `null` posiela do všetkých komponentov
		- `@component` odosiela konkrétnym komponentom podľa názvu komponentu
		- `string` odošle na konkrétny komponent podľa identifikátora
- `SETTER('dashboard/call', method_name, [a], [b], [c], [d])` vykoná metódu v každom widgete
- `RETURN('dashboard/pixel')` vráti veľkosť pixelu (štvorec)
- `RETURN('dashboard/display')` vráti aktuálnu šírku zobrazenia

__Je dobré vedieť__:

- komponent pridáva triedy do tela komponentu:
	- `d_colNUMBER` určuje počet odobratých stĺpcov napr. `d_col2`
	- `d_rowNUMBER` určuje počet odobratých riadkov napr. `d_row3`
	- `d_square` komponent má rovnakú šírku/výšku
	- `d_vertical` komponent má iba 1 krok šírky a viac ako 1 krok výšky
	- `d_horizontal` komponent má iba 1 krok výšky a viac ako 1 krok šírky

Použite ho so `<ui-component name="dashboard">`. Keď komponent ešte nie je načítaný, jComponent ho stiahne pri prvom použití z adresy v `DEF.fallback` (predvolene CDN Componentator). Autor: Peter Širka. Zdroj: úložisko komponentov Componentator, licencia MIT.

```html example.html
<ui-component name="dashboard" path="components"></ui-component>
<script>

	var components = [];

	components.push({
		id: 'A',
		offset: { lg: { x: 0, y: 0, width: 4, height: 4 }},
		title: 'A',
		html: '<div class="padding">Lorem ipsum dolor sit amet.</div>',
		actions: { settings: true, remove: true, move: true, resize: true },
		make: function(exports, config, el) {

			// If you change some action "exports.actions" then execute:
			// exports.refresh();

			exports.data = function(data) {

			};

			exports.configure = function() {

			};

		}
	});

	components.push({
		id: 'B',
		offset: { lg: { x: 4, y: 0, width: 4, height: 4 }},
		title: 'B',
		html: '<div class="padding">Lorem ipsum dolor sit amet.</div>',
		actions: { settings: true, remove: true, move: true, resize: true }
	});
</script>
```
