2022-11-16 01:44:39 +00:00
|
|
|
import './style.scss';
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2022-11-16 01:44:39 +00:00
|
|
|
export default new Class({
|
|
|
|
Extends: Hedera.Form,
|
|
|
|
Template: require('./ui.xml')
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,activate() {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.resultIndex.value = 0;
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,clean() {
|
2022-05-24 21:11:12 +00:00
|
|
|
if (this._grid) {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.gridHolder.removeChild(this._grid.node);
|
2022-05-24 21:11:12 +00:00
|
|
|
this._grid.unref();
|
2016-01-15 12:31:08 +00:00
|
|
|
this._grid = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onExecuteClick() {
|
2022-05-24 21:11:12 +00:00
|
|
|
this.clean();
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
var model = new Db.Model({
|
2016-01-15 12:31:08 +00:00
|
|
|
conn: this.conn,
|
2022-05-28 01:18:06 +00:00
|
|
|
query: this.$.sql.value,
|
|
|
|
resultIndex: this.$.resultIndex.value,
|
|
|
|
updatable: this.$.updatable.value
|
2016-01-15 12:31:08 +00:00
|
|
|
});
|
2022-05-24 21:11:12 +00:00
|
|
|
model.on('status-changed', this.onModelChange, this);
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onCleanClick() {
|
2022-05-24 21:11:12 +00:00
|
|
|
this.clean();
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onModelChange(model, status) {
|
2022-05-24 21:11:12 +00:00
|
|
|
if (status !== Db.Model.Status.LOADING) {
|
|
|
|
model.disconnect('status-changed', this.onModelChange, this);
|
|
|
|
model.unref();
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status !== Db.Model.Status.READY)
|
|
|
|
return;
|
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
Htk.Toast.showMessage(_('Query executed!'));
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
var gridHolder = this.$.gridHolder;
|
2016-01-15 12:31:08 +00:00
|
|
|
|
|
|
|
if (gridHolder.firstChild)
|
2022-05-24 21:11:12 +00:00
|
|
|
gridHolder.removeChilds(gridHolder.firstChild);
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
var grid = new Htk.Grid();
|
2016-01-15 12:31:08 +00:00
|
|
|
|
|
|
|
var columns = model.columns;
|
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
for (var i = 0; i < columns.length; i++) {
|
2016-01-15 12:31:08 +00:00
|
|
|
var c = columns[i];
|
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
switch (c.type) {
|
2016-01-15 12:31:08 +00:00
|
|
|
case Db.Conn.Type.BOOLEAN:
|
2022-05-24 21:11:12 +00:00
|
|
|
var column = new Htk.ColumnCheck();
|
2016-01-15 12:31:08 +00:00
|
|
|
break;
|
|
|
|
case Db.Conn.Type.INTEGER:
|
2022-05-24 21:11:12 +00:00
|
|
|
var column = new Htk.ColumnSpin();
|
2016-01-15 12:31:08 +00:00
|
|
|
break;
|
|
|
|
case Db.Conn.Type.DOUBLE:
|
2022-05-24 21:11:12 +00:00
|
|
|
var column = new Htk.ColumnSpin({digits: 2});
|
2016-01-15 12:31:08 +00:00
|
|
|
break;
|
|
|
|
case Db.Conn.Type.DATE:
|
2022-05-24 21:11:12 +00:00
|
|
|
var column = new Htk.ColumnDate({format: '%a, %e %b %Y'});
|
2016-01-15 12:31:08 +00:00
|
|
|
break;
|
|
|
|
case Db.Conn.Type.DATE_TIME:
|
2022-05-24 21:11:12 +00:00
|
|
|
var column = new Htk.ColumnDate({format: '%a, %e %b %Y, %T'});
|
2016-01-15 12:31:08 +00:00
|
|
|
break;
|
|
|
|
case Db.Conn.Type.STRING:
|
|
|
|
default:
|
2022-05-24 21:11:12 +00:00
|
|
|
var column = new Htk.ColumnText();
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
column.setProperties({
|
2016-01-15 12:31:08 +00:00
|
|
|
title: c.name,
|
2022-05-28 01:18:06 +00:00
|
|
|
editable: this.$.updatable.value,
|
2016-01-15 12:31:08 +00:00
|
|
|
columnIndex: i
|
|
|
|
});
|
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
grid.appendColumn(column);
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grid.model = model;
|
2022-05-24 21:11:12 +00:00
|
|
|
gridHolder.appendChild(grid.node);
|
2016-01-15 12:31:08 +00:00
|
|
|
this._grid = grid;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|