2015-09-16 16:11:15 +00:00
|
|
|
/**
|
|
|
|
* Class to display or edit an image. Also it allows to show it's full version.
|
|
|
|
**/
|
|
|
|
var fullImage = null;
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
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;
|
2015-09-16 16:11:15 +00:00
|
|
|
this._basedir = Vn.Config['image_dir'] +'/'+ x;
|
2015-03-09 08:36:54 +00:00
|
|
|
this.render (false);
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._directory;
|
|
|
|
}
|
2015-09-16 16:11:15 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The directory where the images are allocated.
|
|
|
|
**/
|
|
|
|
subdir:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._subdir = x;
|
|
|
|
this.render (false);
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._subdir;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Whether to show the full image when mouse hover.
|
|
|
|
**/
|
|
|
|
showFull:
|
|
|
|
{
|
|
|
|
type: Boolean
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
if (x && !this._fullImage)
|
|
|
|
{
|
|
|
|
if (!fullImage)
|
|
|
|
fullImage = new Htk.FullImage ();
|
|
|
|
|
|
|
|
this._fullImage = fullImage;
|
|
|
|
this.node.addEventListener ('mouseover', this.onMouseOver.bind (this));
|
|
|
|
this.node.addEventListener ('mouseout', this.onMouseOut.bind (this));
|
|
|
|
}
|
|
|
|
|
|
|
|
this._showFull = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._showFull;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Subdirectory where full images are allocated.
|
|
|
|
**/
|
|
|
|
fullDir:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._fullDir = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._fullDir;
|
|
|
|
}
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_directory: null
|
2015-09-16 16:11:15 +00:00
|
|
|
,_subdir: null
|
|
|
|
,_basedir: null
|
|
|
|
,_empty: false
|
|
|
|
,_showFull: false
|
|
|
|
,_fullDir: null
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,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-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 08:36:54 +00:00
|
|
|
,onImageError: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-09-16 16:11:15 +00:00
|
|
|
if (!this._empty)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-09-16 16:11:15 +00:00
|
|
|
this._empty = true;
|
2015-01-23 13:09:30 +00:00
|
|
|
this.node.src = 'image/empty.png';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,render: function (force)
|
|
|
|
{
|
2015-03-09 08:36:54 +00:00
|
|
|
if (this._value)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-03-09 08:36:54 +00:00
|
|
|
var url = '';
|
|
|
|
|
2015-09-16 16:11:15 +00:00
|
|
|
if (this._basedir)
|
|
|
|
url += this._basedir +'/';
|
|
|
|
|
|
|
|
if (this._subdir)
|
|
|
|
url += this._subdir +'/';
|
2015-03-09 08:36:54 +00:00
|
|
|
|
|
|
|
url += this._value;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (force)
|
2015-03-09 08:36:54 +00:00
|
|
|
url += '?' + (new Date()).getTime ();
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-09-16 16:11:15 +00:00
|
|
|
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 = '';
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
else
|
2015-07-17 14:34:42 +00:00
|
|
|
{
|
|
|
|
delete this.node.src;
|
|
|
|
this.node.style.display = 'none';
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-09 08:36:54 +00:00
|
|
|
,putValue: function (value)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
this.render (false);
|
|
|
|
}
|
|
|
|
|
2015-09-16 16:11:15 +00:00
|
|
|
,onMouseOver: function (cell)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-09-16 16:11:15 +00:00
|
|
|
if (!this._showFull)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var src = this._fullDir ? this._fullDir : 'full';
|
|
|
|
src += '/'+ this._value;
|
|
|
|
|
|
|
|
if (this._stamp)
|
|
|
|
src += '?'+ this._stamp;
|
|
|
|
|
|
|
|
if (!cell.error)
|
|
|
|
this._fullImage.show (this._basedir +'/'+ src);
|
|
|
|
}
|
|
|
|
|
|
|
|
,onMouseOut: function ()
|
|
|
|
{
|
|
|
|
this._fullImage.hide ();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,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-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 08:36:54 +00:00
|
|
|
,onDoubleClick: function (event)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
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-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|