Skip to content

Commit

Permalink
feat: Add "isPrintable" option on "dxDataGrid"
Browse files Browse the repository at this point in the history
  • Loading branch information
mickjol committed Jan 22, 2018
1 parent a79ac97 commit ef0811a
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 261 deletions.
279 changes: 149 additions & 130 deletions js/cause.js
Original file line number Diff line number Diff line change
Expand Up @@ -5515,136 +5515,6 @@ cause.objects.devExtreme17.prototype.loadCSS = function () {
cause.objects.devExtreme = function () {
this.name = 'devExtreme';
this.width = 0;
this.datagrid = {
createToolbar: function (e) {
if (e.element.find('.dx-datagrid-header-panel').length == 0) {
e.element.find('.dx-datagrid-headers').prev().replaceWith('<div class="dx-datagrid-header-panel"><div class="dx-toolbar"></div></div>');
e.element.find('.dx-datagrid-header-panel .dx-toolbar').dxToolbar({
items: []
});
}
},

extractData: function (grid, key, fields) {
var total = grid.totalCount();
var store = new DevExpress.data.ArrayStore({
data: [],
onUpdated: function (key, values) {
var info = cause.extend({}, key, values);

cause.ajax({
url: '//' + myApp.config.webservice.host + '/multilang/',
method: 'POST',
data: info
});
}
});

for (var i=0; i<total; i++) {
grid.byKey(grid.cellValue(i, key)).done(function (data) {
for (var j=0, k=fields.length; j<k; j++) {
store.insert(data[fields[j]]);
}
});
}

return store;
},

languageColumns: function () {
var columns = [];

for (var i=0, j=cause.languages.available.length; i<j; i++) {
columns.push({
caption: cause.localize(cause.languages.available[i]),
dataField: cause.languages.available[i]
});
}

return columns;
},

addTranslate: function (e, key, fields, callback) {
this.createToolbar(e);

if (!$('.fa.fa-globe', e.element).length) {
var toolbar = e.element.find('.dx-datagrid-header-panel .dx-toolbar').dxToolbar('instance');
var items = toolbar.option('items');
var store = this.extractData(e.component, key, fields);
var columns = this.languageColumns();

items.push({
location: 'after',
widget: 'dxButton',
name: 'print',
options: {
icon: 'fa fa-globe',
onClick: (function (store, columns, callback) {
if ($('#popupTranslate').length) {
$('#popupTranslate').remove();
}

$('<div id="popupTranslate">').html('<div class="popupGrid" />').appendTo('body');
$('#popupTranslate').dxPopup({
visible: true,
title: cause.localize('translate'),
toolbarItems: [{
options: {
text: cause.localize('cancel'),
onClick: function() {
$('#popupTranslate').dxPopup('instance').hide();
}
},
toolbar: 'bottom',
widget: 'dxButton'
}],
onHidden: function () {
callback();
},
onShown: function (e) {
$('div.popupGrid', e.component.content()).dxDataGrid({
dataSource: store,
height: (screen.height / 1.7),
paging: {
enabled: false
},
editing: {
mode: 'cell',
allowUpdating: true
},
columns: columns
});
}
});
}).bind(this, store, columns, callback)
}
});
toolbar.option('items', items);
}
},

addPrint: function (e) {
this.createToolbar(e);

if (!$('.fa.fa-print', e.element).length) {
var toolbar = e.element.find('.dx-datagrid-header-panel .dx-toolbar').dxToolbar('instance');
var items = toolbar.option('items');

items.push({
location: 'after',
widget: 'dxButton',
name: 'print',
options: {
icon: 'fa fa-print',
onClick: function () {
cause.print(e.element);
}
}
});
toolbar.option('items', items);
}
}
};

/* Keep this function to keep fonctionnal with first version */
cause.app = this.app.bind(this);
Expand Down Expand Up @@ -5873,6 +5743,7 @@ cause.objects.devExtreme.prototype.loadDevExtreme = function (files) {
], (function (files) {
/* And we finish the application files */
cause.log('devExtreme layouts is automatically loaded');
cause.dxDataGrid = new cause.objects.dxDataGrid();
cause.dxMultiLine = new cause.objects.dxMultiLine();
cause.dxMultiLang = new cause.objects.dxMultiLang();
cause.dxSortable = new cause.objects.dxSortable();
Expand Down Expand Up @@ -5938,6 +5809,154 @@ cause.devExtreme = new cause.objects.devExtreme();/** Class to create a new DevE
* @memberOf cause.objects
* @param {object} config: Object with all config
*/
cause.objects.dxDataGrid = function () {
DevExpress.registerComponent('dxDataGrid', DevExpress.ui.dxDataGrid.inherit({
_renderContent: function () {
this.callBase();

var config = this.option();

if (config.isPrintable !== false) {
this._addPrintButton();
}
},

_createToolbar: function () {
if (this._$element.find('.dx-datagrid-header-panel').length == 0) {
this._$element.find('.dx-datagrid-headers').prev().replaceWith('<div class="dx-datagrid-header-panel"><div class="dx-toolbar"></div></div>');
this._$element.find('.dx-datagrid-header-panel .dx-toolbar').dxToolbar({
items: []
});
}
},

_addPrintButton: function() {
this._createToolbar();

if (!$('.fa.fa-print', this._$element).length) {
var toolbar = this._$element.find('.dx-datagrid-header-panel .dx-toolbar').dxToolbar('instance');
var items = toolbar.option('items');

items.push({
location: 'after',
widget: 'dxButton',
name: 'print',
options: {
icon: 'fa fa-print',
onClick: (function (e) {
cause.print(this._$element);
}).bind(this)
}
});
toolbar.option('items', items);
}
},

_extractData: function (grid, key, fields) {
var total = grid.totalCount();
var store = new DevExpress.data.ArrayStore({
data: [],
onUpdated: function (key, values) {
var info = cause.extend({}, key, values);

cause.ajax({
url: '//' + myApp.config.webservice.host + '/multilang/',
method: 'POST',
data: info
});
}
});

for (var i=0; i<total; i++) {
grid.byKey(grid.cellValue(i, key)).done(function (data) {
for (var j=0, k=fields.length; j<k; j++) {
store.insert(data[fields[j]]);
}
});
}

return store;
},

_languageColumns: function () {
var columns = [];

for (var i=0, j=cause.languages.available.length; i<j; i++) {
columns.push({
caption: cause.localize(cause.languages.available[i]),
dataField: cause.languages.available[i]
});
}

return columns;
},

_addTranslate: function (e, key, fields, callback) {
this._createToolbar(e);

if (!$('.fa.fa-globe', e.element).length) {
var toolbar = e.element.find('.dx-datagrid-header-panel .dx-toolbar').dxToolbar('instance');
var items = toolbar.option('items');
var store = this._extractData(e.component, key, fields);
var columns = this._languageColumns();

items.push({
location: 'after',
widget: 'dxButton',
name: 'print',
options: {
icon: 'fa fa-globe',
onClick: (function (store, columns, callback) {
if ($('#popupTranslate').length) {
$('#popupTranslate').remove();
}

$('<div id="popupTranslate">').html('<div class="popupGrid" />').appendTo('body');
$('#popupTranslate').dxPopup({
visible: true,
title: cause.localize('translate'),
toolbarItems: [{
options: {
text: cause.localize('cancel'),
onClick: function() {
$('#popupTranslate').dxPopup('instance').hide();
}
},
toolbar: 'bottom',
widget: 'dxButton'
}],
onHidden: function () {
callback();
},
onShown: function (e) {
$('div.popupGrid', e.component.content()).dxDataGrid({
dataSource: store,
height: (screen.height / 1.7),
paging: {
enabled: false
},
editing: {
mode: 'cell',
allowUpdating: true
},
columns: columns
});
}
});
}).bind(this, store, columns, callback)
}
});
toolbar.option('items', items);
}
},
}));
};
/** Class to create a new DevExtreme widget (dxMultiLang)
*
* @constructor
* @memberOf cause.objects
* @param {object} config: Object with all config
*/
cause.objects.dxMultiLang = function () {
DevExpress.registerComponent('dxMultiLang', (function (_super) {
cause.extends(customControl, _super);
Expand Down
2 changes: 1 addition & 1 deletion js/cause.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit ef0811a

Please sign in to comment.