diff --git a/front/core/components/index.js b/front/core/components/index.js index 150fc2158..86ab89212 100644 --- a/front/core/components/index.js +++ b/front/core/components/index.js @@ -52,4 +52,4 @@ import './wday-picker'; import './datalist'; import './contextmenu'; import './rating'; -import './smart-table-menu'; +import './smart-table'; diff --git a/front/core/components/smart-table-menu/index.js b/front/core/components/smart-table-menu/index.js deleted file mode 100644 index 9f0d27852..000000000 --- a/front/core/components/smart-table-menu/index.js +++ /dev/null @@ -1,53 +0,0 @@ -import ngModule from '../../module'; -import Component from '../../lib/component'; -import './style.scss'; - -export default class SmartTableMenu extends Component { - constructor($element, $, $transclude) { - super($element, $); - this.$transclude = $transclude; - // stuff - } - - $onDestroy() { - if (this.$contentScope) - this.$contentScope.$destroy(); - } - - get model() { - return this._model; - } - - set model(value) { - this._model = value; - if (value) - this.transclude(); - } - - transclude() { - const body = this.element.querySelector('.body'); - this.$transclude(($clone, $scope) => { - this.$contentScope = $scope; - $scope.model = this.model; - body.appendChild($clone[0]); - }, null, 'body'); - } - - save() { - this.model.save() - .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); - } -} - -SmartTableMenu.$inject = ['$element', '$scope', '$transclude']; - -ngModule.vnComponent('smartTableMenu', { - template: require('./index.html'), - controller: SmartTableMenu, - transclude: { - body: '?slotBody' - }, - bindings: { - model: ' -
+ +
+ +
@@ -40,5 +45,5 @@
-
+
\ No newline at end of file diff --git a/front/core/components/smart-table/index.js b/front/core/components/smart-table/index.js new file mode 100644 index 000000000..fd22ac9a4 --- /dev/null +++ b/front/core/components/smart-table/index.js @@ -0,0 +1,102 @@ +import ngModule from '../../module'; +import Component from '../../lib/component'; +import './style.scss'; + +export default class SmartTable extends Component { + constructor($element, $, $transclude) { + super($element, $); + this.$transclude = $transclude; + // stuff + } + + /* $onDestroy() { + if (this.$contentScope) + this.$contentScope.$destroy(); + } + */ + get model() { + return this._model; + } + + set model(value) { + this._model = value; + if (value) { + this.$.model = value; + this.transclude(); + } + } + + registerColumns() { + const header = this.element.querySelector('thead > tr'); + if (!header) return; + const columns = header.querySelectorAll('th'); + + // TODO: Add arrow icon and so on.. + // Click handler + for (let column of columns) { + const field = column.getAttribute('field'); + if (field) + column.addEventListener('click', () => this.orderHandler(column)); + } + } + + // Creo que se puede hacer directamente desde ng-transclude + transclude() { + const slotTable = this.element.querySelector('#table'); + this.$transclude(($clone, $scope) => { + const table = $clone[0]; + $scope.hasChanges = this.hasChanges; + slotTable.appendChild(table); + this.registerColumns(); + }, null, 'table'); + } + + orderHandler(element) { + const field = element.getAttribute('field'); + console.log(`You clicked to ` + field); + } + + createRow() { + this.model.insert({ + nickname: 'New row' + }); + } + + deleteAll() { + const data = this.model.data; + const checkedRows = data.filter(row => row.checked); + for (let row of checkedRows) + this.model.remove(row); + + if (this.autoSave) + this.save(); + } + + saveAll() { + const model = this.model; + if (!model.isChanged) + return this.vnApp.showError(this.$t('No changes to save')); + + this.model.save() + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); + } + + hasChanges() { + return true; + } +} + +SmartTable.$inject = ['$element', '$scope', '$transclude']; + +ngModule.vnComponent('smartTable', { + template: require('./index.html'), + controller: SmartTable, + transclude: { + table: '?slotTable', + actions: '?slotActions' + }, + bindings: { + model: ' { +ngModule.directive('smartTable2', () => { return { controller: Controller, bindings: { diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index f3ac18c52..af59eac7d 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -1,27 +1,48 @@ - - + --> + + - - - + + + Mas iconos.. + + +
- - + + + - - + + + - + +
Column 1Column 2 + + + IDNickname
+ + + {{::ticket.id}}{{::ticket.userName}}{{::ticket.nickname}}
-
-
- + +