2016-10-13 15:07:48 +00:00
|
|
|
|
|
|
|
module.exports = new Class
|
|
|
|
({
|
|
|
|
Extends: Htk.Widget
|
|
|
|
,Tag: 'htk-social-bar'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
conn:
|
|
|
|
{
|
|
|
|
type: Db.Connection
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._conn = x;
|
2016-10-14 10:58:35 +00:00
|
|
|
this._refresh ();
|
2016-10-13 15:07:48 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._conn;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
priority:
|
|
|
|
{
|
|
|
|
type: Number
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._priority = x;
|
2016-10-14 10:58:35 +00:00
|
|
|
this._refresh ();
|
2016-10-13 15:07:48 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
,initialize: function ()
|
|
|
|
{
|
2016-10-16 14:16:08 +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
|
|
|
|
2016-10-13 15:07:48 +00:00
|
|
|
,_refresh: function ()
|
|
|
|
{
|
|
|
|
if (!this._conn || this._priority === null)
|
|
|
|
return;
|
|
|
|
|
2017-04-05 14:06:07 +00:00
|
|
|
var params = {priority: this._priority};
|
2016-10-13 15:07:48 +00:00
|
|
|
var query = 'SELECT title, link, icon FROM social '
|
2016-10-14 10:58:35 +00:00
|
|
|
+'WHERE priority >= #priority ORDER BY priority';
|
2017-04-05 14:06:07 +00:00
|
|
|
this._conn.execQuery (query, this._onQueryDone.bind (this), params);
|
2016-10-13 15:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,_onQueryDone: function (resultSet)
|
|
|
|
{
|
|
|
|
Vn.Node.removeChilds (this._node);
|
|
|
|
var res = resultSet.fetchResult ();
|
|
|
|
|
|
|
|
while (res.next ())
|
|
|
|
{
|
2016-10-16 14:16:08 +00:00
|
|
|
var a = this.createElement ('a');
|
2016-10-13 15:07:48 +00:00
|
|
|
a.href = res.get ('link');
|
|
|
|
a.target = '_blank';
|
2017-03-30 11:44:53 +00:00
|
|
|
a.className = 'clickable-img';
|
2016-10-13 15:07:48 +00:00
|
|
|
this._node.appendChild (a);
|
|
|
|
|
2016-10-16 14:16:08 +00:00
|
|
|
var img = this.createElement ('img');
|
2016-10-13 15:07:48 +00:00
|
|
|
img.src = 'image/social/'+ res.get ('icon');
|
|
|
|
img.alt = res.get ('title');
|
|
|
|
img.title = res.get ('title');
|
|
|
|
a.appendChild (img);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|