0
1
Fork 0
hedera-web-mindshore/package/usr/share/hedera-web/js/htk/column/image.js

160 lines
2.9 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
}
}
,_directory: null
,basedir: null
,initialize: function (props)
{
this.parent (props);
this.fullImage = new Htk.FullImage ();
}
,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
};
this.setSrc (cell, true);
if (this.showFull)
{
img.addEventListener ('mouseover', this.onMouseOver.bind (this, cell));
img.addEventListener ('mouseout', this.onMouseOut.bind (this));
}
if (this.editable)
{
img.className = 'editable';
img.addEventListener ('dblclick', this.onDoubleClick.bind (this, cell));
img.addEventListener ('error', this.onImageError.bind (this, cell));
}
return td;
}
,setSrc: function (cell, useCache)
{
if (cell.value)
{
var url = this.basedir +'/';
if (this.subdir)
url += this.subdir +'/';
url += cell.value;
if (!useCache)
query = '?'+ new Date ().getTime ();
cell.img.src = url;
}
else
this.onImageError (cell);
}
,onImageError: function (cell)
{
if (!cell.error)
{
cell.error = true;
cell.img.src = 'image/empty.png';
}
}
,onMouseOver: function (cell)
{
if (!cell.error)
this.fullImage.show (this.basedir, cell.value);
}
,onMouseOut: function ()
{
this.fullImage.hide ();
}
,onDoubleClick: function (cell)
{
var editor = new Htk.ImageEditor ();
editor.setData (cell.value, this._directory);
this.nameChangedHandler = this.onNameChange.bind (this, cell);
editor.on ('name-changed', this.nameChangedHandler);
this.fileUploadedHandler = this.onFileUpload.bind (this, cell);
editor.on ('file-uploaded', this.fileUploadedHandler);
this.editorClosedHandler = this.onEditorClose.bind (this);
editor.on ('closed', this.editorClosedHandler);
editor.showPopup (cell.img);
}
,onNameChange: function (cell, editor, value)
{
cell.value = value;
this.setSrc (cell, true);
this.changed (cell.tr, value);
}
,onFileUpload: function (cell, editor)
{
this.setSrc (cell, false);
editor.hidePopup ();
}
,onEditorClose: function (editor)
{
editor.disconnect ('name-changed', this.nameChangedHandler);
editor.disconnect ('file-uploaded', this.fileUploadedHandler);
editor.disconnect ('closed', this.editorClosedHandler);
}
});