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

188 lines
3.4 KiB
JavaScript
Raw Normal View History

Htk.ColumnImage = new Class
({
Extends: Htk.Column
,Tag: 'htk-column-image'
,Properties:
{
/**
* The directory where the images are allocated.
**/
directory:
{
type: String
,set: function (x)
{
this._directory = x;
this._basedir = Vn.Config['image_dir'] +'/'+ x;
}
,get: function ()
{
return this._directory;
}
},
/**
* The directory where the images are allocated.
**/
subdir:
{
type: String
,value: null
},
/**
* Whether to show the full image when mouse hover.
**/
showFull:
{
type: Boolean
,value: false
},
/**
* Subdirectory where full images are allocated.
**/
fullDir:
{
type: String
,set: function (x)
{
this._fullDir = x;
}
,get: function ()
{
return this._fullDir;
}
}
}
,_directory: null
,_basedir: null
,initialize: function (props)
{
this._cssClass = 'cell-image';
this._fullImage = new Htk.FullImage ();
this.parent (props);
}
,render: function (tr)
{
var td = this.parent (tr);
var img = document.createElement ('img');
img.alt = ''
td.appendChild (img);
var cell =
{
img: img
,value: this.value
,tr: tr
,error: false
,stamp: null
};
2015-12-10 13:48:43 +00:00
this._setSrc (cell);
if (this.showFull)
{
2015-12-10 13:48:43 +00:00
img.addEventListener ('mouseover', this._onMouseOver.bind (this, cell));
img.addEventListener ('mouseout', this._onMouseOut.bind (this));
}
if (this.editable)
{
img.className = 'editable';
2015-12-10 13:48:43 +00:00
img.addEventListener ('dblclick', this._onDoubleClick.bind (this, cell));
img.addEventListener ('error', this._onImageError.bind (this, cell));
}
return td;
}
2015-12-10 13:48:43 +00:00
,_setSrc: function (cell)
{
if (cell.value)
{
var url = this._basedir +'/';
if (this.subdir)
url += this.subdir +'/';
url += cell.value;
if (cell.stamp)
url += '?'+ cell.stamp;
cell.img.src = url;
}
else
2015-12-10 13:48:43 +00:00
this._onImageError (cell);
}
2015-12-10 13:48:43 +00:00
,_onImageError: function (cell)
{
if (!cell.error)
{
cell.error = true;
2015-12-10 13:48:43 +00:00
cell.img.src = 'image/unknown.svg';
}
}
2015-12-10 13:48:43 +00:00
,_onMouseOver: function (cell)
{
2015-12-10 13:48:43 +00:00
if (cell.error)
return;
var src = this._fullDir ? this._fullDir : 'full';
src += '/'+ cell.value;
if (cell.stamp)
src += '?'+ cell.stamp;
2015-12-10 13:48:43 +00:00
this._fullImage.show (this._basedir +'/'+ src);
}
2015-12-10 13:48:43 +00:00
,_onMouseOut: function ()
{
this._fullImage.hide ();
}
2015-12-10 13:48:43 +00:00
,_onDoubleClick: function (cell)
{
var editor = new Htk.ImageEditor ();
editor.setData (cell.value, this._directory);
2015-12-10 13:48:43 +00:00
this.nameChangedHandler = this._onNameChange.bind (this, cell);
editor.on ('name-changed', this.nameChangedHandler);
2015-12-10 13:48:43 +00:00
this.fileUploadedHandler = this._onFileUpload.bind (this, cell);
editor.on ('file-uploaded', this.fileUploadedHandler);
2015-12-10 13:48:43 +00:00
this.editorClosedHandler = this._onEditorClose.bind (this);
editor.on ('closed', this.editorClosedHandler);
2015-03-06 23:33:54 +00:00
this.popup = new Htk.Popup ();
this.popup.setChild (editor);
this.popup.show (cell.img);
}
2015-12-10 13:48:43 +00:00
,_onNameChange: function (cell, editor, value)
{
cell.value = value;
2015-12-10 13:48:43 +00:00
this._setSrc (cell);
this.changed (cell.tr, value);
}
2015-12-10 13:48:43 +00:00
,_onFileUpload: function (cell, editor)
{
cell.stamp = new Date ().getTime ();
2015-12-10 13:48:43 +00:00
this._setSrc (cell);
2015-03-06 23:33:54 +00:00
this.popup.hide ();
}
2015-12-10 13:48:43 +00:00
,_onEditorClose: function (editor)
{
editor.disconnect ('name-changed', this.nameChangedHandler);
editor.disconnect ('file-uploaded', this.fileUploadedHandler);
editor.disconnect ('closed', this.editorClosedHandler);
}
});