hedera-web/web/js/htk/field/image.js

119 lines
1.9 KiB
JavaScript
Raw Normal View History

Htk.Image = new Class
({
Extends: Htk.Entry
,Tag: 'htk-image'
2015-03-09 08:36:54 +00:00
,Properties:
{
/**
* The directory where the images are allocated.
**/
directory:
{
type: String
,set: function (x)
{
this._directory = x;
this.basedir = Vn.Config['image_dir'] +'/'+ x;
this.render (false);
}
,get: function ()
{
return this._directory;
}
}
}
,_directory: null
,basedir: null
,empty: false
,initialize: function (props)
{
this.parent (props);
2015-03-09 08:36:54 +00:00
this.createElement ('img');
// this.node.addEventListener ('error', this.onImageError.bind (this));
}
2015-03-09 08:36:54 +00:00
,onImageError: function ()
{
if (!this.empty)
{
this.empty = true;
this.node.src = 'image/empty.png';
}
}
,render: function (force)
{
2015-03-09 08:36:54 +00:00
if (this._value)
{
2015-03-09 08:36:54 +00:00
var url = '';
if (this.basedir)
url += this.basedir +'/';
url += this._value;
if (force)
2015-03-09 08:36:54 +00:00
url += '?' + (new Date()).getTime ();
this.empty = false;
2015-03-09 08:36:54 +00:00
this.node.src = url;
2015-07-17 14:34:42 +00:00
this.node.style.display = '';
}
else
2015-07-17 14:34:42 +00:00
{
delete this.node.src;
this.node.style.display = 'none';
}
}
2015-03-09 08:36:54 +00:00
,putValue: function (value)
{
this.render (false);
}
,setShowFull: function (show)
{
if (show)
{
2015-03-09 08:36:54 +00:00
this.fullImage = new Htk.FullImage ();
this.node.addEventListener ('mouseover', this.onMouseOver.bind (this));
this.node.addEventListener ('mouseout', this.onMouseOut.bind (this));
}
}
,setEditable: function (editable)
{
if (editable)
{
var obj = this;
this.style.cursor = 'pointer';
this.node.addEventListener ('dblclick',
2015-03-09 08:36:54 +00:00
this.onDoubleClick.bind (this));
}
}
2015-03-09 08:36:54 +00:00
,onDoubleClick: function (event)
{
2015-03-09 08:36:54 +00:00
var editor = new Htk.ImageEditor ();
editor.setData (cell.value, this._directory);
this.popup = new Htk.Popup ();
this.popup.setChild (editor);
this.popup.show (this.node);
}
2015-03-09 08:36:54 +00:00
,onMouseOver: function (cell)
{
2015-03-09 08:36:54 +00:00
if (!cell.empty)
this.fullImage.show (this.basedir, cell.value);
}
2015-03-09 08:36:54 +00:00
,onMouseOut: function ()
{
2015-03-09 08:36:54 +00:00
this.fullImage.hide ();
}
});