0
1
Fork 0
hedera-web-mindshore/forms/admin/queries/index.js

94 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

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