2022-06-06 16:02:17 +00:00
|
|
|
require('./style.scss');
|
2016-09-26 09:28:47 +00:00
|
|
|
|
2018-07-02 12:54:37 +00:00
|
|
|
module.exports = new Class({
|
|
|
|
Extends: Htk.Column,
|
|
|
|
Tag: 'htk-column-button',
|
|
|
|
Properties: {
|
|
|
|
image: {
|
2015-01-23 13:09:30 +00:00
|
|
|
type: String
|
|
|
|
,value: null
|
|
|
|
},
|
2018-07-02 12:54:37 +00:00
|
|
|
icon: {
|
2016-09-26 09:28:47 +00:00
|
|
|
type: String
|
2022-05-21 21:31:56 +00:00
|
|
|
,set: function(x) {
|
2016-09-26 09:28:47 +00:00
|
|
|
this._icon = x;
|
|
|
|
}
|
2022-05-21 21:31:56 +00:00
|
|
|
,get: function() {
|
2016-09-26 09:28:47 +00:00
|
|
|
return this._icon;
|
|
|
|
}
|
|
|
|
},
|
2018-07-02 12:54:37 +00:00
|
|
|
tip: {
|
|
|
|
type: String,
|
|
|
|
value: null
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
value: false
|
|
|
|
},
|
|
|
|
href: {
|
|
|
|
type: String,
|
|
|
|
value: null
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
type: String,
|
|
|
|
value: ''
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2018-07-02 12:54:37 +00:00
|
|
|
},
|
2015-11-26 12:30:04 +00:00
|
|
|
|
2018-07-02 12:54:37 +00:00
|
|
|
initialize: function(props) {
|
2015-11-26 12:30:04 +00:00
|
|
|
this._cssClass = 'cell-button';
|
2022-06-06 16:02:17 +00:00
|
|
|
Htk.Column.prototype.initialize.call(this, props);
|
2018-07-02 12:54:37 +00:00
|
|
|
},
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-07-02 12:54:37 +00:00
|
|
|
render: function(tr) {
|
2022-06-06 16:02:17 +00:00
|
|
|
const td = Htk.Column.prototype.render.call(this, tr);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
let button;
|
2018-07-02 12:54:37 +00:00
|
|
|
|
|
|
|
if (this.href == null) {
|
|
|
|
button = this.createElement('button');
|
|
|
|
button.addEventListener('click',
|
|
|
|
this.buttonClicked.bind(this, this.value, tr, button));
|
|
|
|
} else {
|
|
|
|
button = this.createElement('a');
|
|
|
|
button.href = this.href;
|
|
|
|
button.target = this.target;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
if (this.tip)
|
|
|
|
button.title = _(this.tip);
|
|
|
|
|
2018-07-02 12:54:37 +00:00
|
|
|
button.disabled = this.disabled;
|
|
|
|
td.appendChild(button);
|
|
|
|
|
2022-05-25 18:04:16 +00:00
|
|
|
const icon = new Htk.Icon({
|
|
|
|
name: this._icon
|
|
|
|
});
|
|
|
|
button.appendChild(icon.node);
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
return td;
|
2018-07-02 12:54:37 +00:00
|
|
|
},
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2018-07-02 12:54:37 +00:00
|
|
|
buttonClicked: function(value, tr, button) {
|
2022-05-30 01:30:33 +00:00
|
|
|
this.emit('clicked', value, tr.rowIndex - 1, button);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|