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

92 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-05-24 21:11:12 +00:00
Hedera.Queries = new Class({
2016-09-26 09:28:47 +00:00
Extends: Hedera.Form
2022-05-24 21:11:12 +00:00
,activate: function() {
2022-05-28 01:18:06 +00:00
this.$.resultIndex.value = 0;
}
2022-05-24 21:11:12 +00:00
,clean: function() {
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-05-24 21:11:12 +00:00
,onExecuteClick: function() {
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-05-24 21:11:12 +00:00
,onCleanClick: function() {
this.clean();
}
2022-05-24 21:11:12 +00:00
,onModelChange: function(model, status) {
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;
}
});