2022-06-06 16:19:43 +00:00
|
|
|
require('./social-bar.scss');
|
2016-10-13 15:07:48 +00:00
|
|
|
|
2022-05-30 01:30:33 +00:00
|
|
|
module.exports = new Class({
|
2022-06-06 12:49:18 +00:00
|
|
|
Extends: Vn.Component
|
2016-10-13 15:07:48 +00:00
|
|
|
,Tag: 'htk-social-bar'
|
2022-05-30 01:30:33 +00:00
|
|
|
,Properties: {
|
|
|
|
conn: {
|
2016-10-13 15:07:48 +00:00
|
|
|
type: Db.Connection
|
2022-11-16 01:46:44 +00:00
|
|
|
,set(x) {
|
2016-10-13 15:07:48 +00:00
|
|
|
this._conn = x;
|
2022-05-30 01:30:33 +00:00
|
|
|
this._refresh();
|
2016-10-13 15:07:48 +00:00
|
|
|
}
|
2022-11-16 01:46:44 +00:00
|
|
|
,get() {
|
2016-10-13 15:07:48 +00:00
|
|
|
return this._conn;
|
|
|
|
}
|
|
|
|
},
|
2022-05-30 01:30:33 +00:00
|
|
|
priority: {
|
2016-10-13 15:07:48 +00:00
|
|
|
type: Number
|
2022-11-16 01:46:44 +00:00
|
|
|
,set(x) {
|
2016-10-13 15:07:48 +00:00
|
|
|
this._priority = x;
|
2022-05-30 01:30:33 +00:00
|
|
|
this._refresh();
|
2016-10-13 15:07:48 +00:00
|
|
|
}
|
2022-11-16 01:46:44 +00:00
|
|
|
,get() {
|
2016-10-13 15:07:48 +00:00
|
|
|
return this._priority;
|
|
|
|
}
|
2016-10-14 10:58:35 +00:00
|
|
|
}
|
2016-10-13 15:07:48 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 10:58:35 +00:00
|
|
|
,_priority: 0
|
2016-10-13 15:07:48 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,initialize() {
|
2022-05-30 01:30:33 +00:00
|
|
|
var node = this.createRoot('div');
|
2016-10-14 10:58:35 +00:00
|
|
|
node.className = 'htk-social-bar';
|
2016-10-13 15:07:48 +00:00
|
|
|
}
|
2016-10-14 10:58:35 +00:00
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
,async _refresh() {
|
2016-10-13 15:07:48 +00:00
|
|
|
if (!this._conn || this._priority === null)
|
|
|
|
return;
|
|
|
|
|
2022-05-30 01:30:33 +00:00
|
|
|
const params = {priority: this._priority};
|
2016-10-14 10:58:35 +00:00
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
const query = 'SELECT title, link, icon FROM social '
|
2016-10-14 10:58:35 +00:00
|
|
|
+'WHERE priority >= #priority ORDER BY priority';
|
2022-11-28 08:51:31 +00:00
|
|
|
const resultSet = await this._conn.execQuery(query, params);
|
2016-10-13 15:07:48 +00:00
|
|
|
|
2022-05-30 01:30:33 +00:00
|
|
|
Vn.Node.removeChilds(this._node);
|
2022-11-28 08:51:31 +00:00
|
|
|
const res = resultSet.fetchResult();
|
2016-10-13 15:07:48 +00:00
|
|
|
|
2022-05-30 01:30:33 +00:00
|
|
|
while (res.next()) {
|
2022-11-28 08:51:31 +00:00
|
|
|
const a = this.createElement('a');
|
2022-05-30 01:30:33 +00:00
|
|
|
a.href = res.get('link');
|
2016-10-13 15:07:48 +00:00
|
|
|
a.target = '_blank';
|
2022-05-30 01:30:33 +00:00
|
|
|
this._node.appendChild(a);
|
2016-10-13 15:07:48 +00:00
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
const img = this.createElement('img');
|
2022-05-30 01:30:33 +00:00
|
|
|
img.src = 'image/social/'+ res.get('icon');
|
|
|
|
img.alt = res.get('title');
|
|
|
|
img.title = res.get('title');
|
|
|
|
a.appendChild(img);
|
2016-10-13 15:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|